Bug 826947: Convert HTMLScriptElement to WebIDL r=bz
authorDavid Zbarsky <dzbarsky@gmail.com>
Sat, 05 Jan 2013 04:41:28 -0500
changeset 126830 bb0411cda329c6a5f4843150e8d3b47e4d54e498
parent 126829 8101b0c28d50448d9f647e115645115a23cce65a
child 126831 9d028fec83186f151b7ba084095fbef05f2cb310
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs826947
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 826947: Convert HTMLScriptElement to WebIDL r=bz
content/html/content/src/HTMLScriptElement.cpp
content/html/content/src/HTMLScriptElement.h
content/html/content/test/reflect.js
content/html/content/test/test_bug389797.html
dom/base/nsDOMClassInfo.cpp
dom/bindings/Bindings.conf
dom/webidl/HTMLScriptElement.webidl
dom/webidl/WebIDL.mk
--- a/content/html/content/src/HTMLScriptElement.cpp
+++ b/content/html/content/src/HTMLScriptElement.cpp
@@ -1,47 +1,53 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 sw=2 et tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "nsIDOMHTMLScriptElement.h"
 #include "nsIDOMEventTarget.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsIDocument.h"
-#include "nsScriptElement.h"
 #include "nsIURI.h"
 #include "nsNetUtil.h"
 #include "nsContentUtils.h"
 #include "nsUnicharUtils.h"  // for nsCaseInsensitiveStringComparator()
 #include "jsapi.h"
 #include "nsIScriptContext.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIXPConnect.h"
 #include "nsServiceManagerUtils.h"
 #include "nsError.h"
 #include "nsIArray.h"
 #include "nsTArray.h"
 #include "nsDOMJSUtils.h"
 #include "mozilla/dom/HTMLScriptElement.h"
+#include "mozilla/dom/HTMLScriptElementBinding.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(Script)
 
 DOMCI_NODE_DATA(HTMLScriptElement, mozilla::dom::HTMLScriptElement)
 
 namespace mozilla {
 namespace dom {
 
+JSObject*
+HTMLScriptElement::WrapNode(JSContext *aCx, JSObject *aScope, bool *aTriedToWrap)
+{
+  return HTMLScriptElementBinding::Wrap(aCx, aScope, this, aTriedToWrap);
+}
+
 HTMLScriptElement::HTMLScriptElement(already_AddRefed<nsINodeInfo> aNodeInfo,
                                      FromParser aFromParser)
   : nsGenericHTMLElement(aNodeInfo)
   , nsScriptElement(aFromParser)
 {
+  SetIsDOMBinding();
   AddMutationObserver(this);
 }
 
 HTMLScriptElement::~HTMLScriptElement()
 {
 }
 
 
@@ -122,40 +128,110 @@ HTMLScriptElement::GetText(nsAString& aV
 {
   nsContentUtils::GetNodeTextContent(this, false, aValue);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLScriptElement::SetText(const nsAString& aValue)
 {
-  return nsContentUtils::SetNodeTextContent(this, aValue, true);
+  ErrorResult rv;
+  SetText(aValue, rv);
+  return rv.ErrorCode();
+}
+
+void
+HTMLScriptElement::SetText(const nsAString& aValue, ErrorResult& rv)
+{
+  rv = nsContentUtils::SetNodeTextContent(this, aValue, true);
 }
 
 
 NS_IMPL_STRING_ATTR(HTMLScriptElement, Charset, charset)
 NS_IMPL_BOOL_ATTR(HTMLScriptElement, Defer, defer)
 NS_IMPL_URI_ATTR(HTMLScriptElement, Src, src)
 NS_IMPL_STRING_ATTR(HTMLScriptElement, Type, type)
 NS_IMPL_STRING_ATTR(HTMLScriptElement, HtmlFor, _for)
 NS_IMPL_STRING_ATTR(HTMLScriptElement, Event, event)
 NS_IMPL_STRING_ATTR(HTMLScriptElement, CrossOrigin, crossorigin)
 
+void
+HTMLScriptElement::SetCharset(const nsAString& aCharset, ErrorResult& rv)
+{
+  SetHTMLAttr(nsGkAtoms::charset, aCharset, rv);
+}
+
+void
+HTMLScriptElement::SetDefer(bool aDefer, ErrorResult& rv)
+{
+  SetHTMLBoolAttr(nsGkAtoms::defer, aDefer, rv);
+}
+
+bool
+HTMLScriptElement::Defer()
+{
+  return GetBoolAttr(nsGkAtoms::defer);
+}
+
+void
+HTMLScriptElement::SetSrc(const nsAString& aSrc, ErrorResult& rv)
+{
+  rv = SetAttrHelper(nsGkAtoms::src, aSrc);
+}
+
+void
+HTMLScriptElement::SetType(const nsAString& aType, ErrorResult& rv)
+{
+  SetHTMLAttr(nsGkAtoms::type, aType, rv);
+}
+
+void
+HTMLScriptElement::SetHtmlFor(const nsAString& aHtmlFor, ErrorResult& rv)
+{
+  SetHTMLAttr(nsGkAtoms::_for, aHtmlFor, rv);
+}
+
+void
+HTMLScriptElement::SetEvent(const nsAString& aEvent, ErrorResult& rv)
+{
+  SetHTMLAttr(nsGkAtoms::event, aEvent, rv);
+}
+
+void
+HTMLScriptElement::SetCrossOrigin(const nsAString& aCrossOrigin, ErrorResult& rv)
+{
+  SetHTMLAttr(nsGkAtoms::crossorigin, aCrossOrigin, rv);
+}
+
 nsresult
 HTMLScriptElement::GetAsync(bool* aValue)
 {
-  *aValue = mForceAsync || GetBoolAttr(nsGkAtoms::async);
+  *aValue = Async();
   return NS_OK;
 }
 
+bool
+HTMLScriptElement::Async()
+{
+  return mForceAsync || GetBoolAttr(nsGkAtoms::async);
+}
+
 nsresult
 HTMLScriptElement::SetAsync(bool aValue)
 {
+  ErrorResult rv;
+  SetAsync(aValue, rv);
+  return rv.ErrorCode();
+}
+
+void
+HTMLScriptElement::SetAsync(bool aValue, ErrorResult& rv)
+{
   mForceAsync = false;
-  return SetBoolAttr(nsGkAtoms::async, aValue);
+  SetHTMLBoolAttr(nsGkAtoms::async, aValue, rv);
 }
 
 nsresult
 HTMLScriptElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
                                 const nsAttrValue* aValue, bool aNotify)
 {
   if (nsGkAtoms::async == aName && kNameSpaceID_None == aNamespaceID) {
     mForceAsync = false;
--- a/content/html/content/src/HTMLScriptElement.h
+++ b/content/html/content/src/HTMLScriptElement.h
@@ -2,16 +2,18 @@
 /* vim: set ts=2 sw=2 et tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_HTMLScriptElement_h
 #define mozilla_dom_HTMLScriptElement_h
 
+#include "nsIDOMHTMLScriptElement.h"
+#include "nsScriptElement.h"
 #include "nsGenericHTMLElement.h"
 #include "mozilla/Attributes.h"
 
 namespace mozilla {
 namespace dom {
 
 class HTMLScriptElement MOZ_FINAL : public nsGenericHTMLElement,
                                     public nsIDOMHTMLScriptElement,
@@ -65,17 +67,33 @@ public:
 
   // Element
   virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
                                 const nsAttrValue* aValue, bool aNotify);
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
+
+  // WebIDL
+  void SetText(const nsAString& aValue, ErrorResult& rv);
+  void SetCharset(const nsAString& aCharset, ErrorResult& rv);
+  void SetDefer(bool aDefer, ErrorResult& rv);
+  bool Defer();
+  void SetSrc(const nsAString& aSrc, ErrorResult& rv);
+  void SetType(const nsAString& aType, ErrorResult& rv);
+  void SetHtmlFor(const nsAString& aHtmlFor, ErrorResult& rv);
+  void SetEvent(const nsAString& aEvent, ErrorResult& rv);
+  void SetCrossOrigin(const nsAString& aCrossOrigin, ErrorResult& rv);
+  bool Async();
+  void SetAsync(bool aValue, ErrorResult& rv);
+
 protected:
+  virtual JSObject* WrapNode(JSContext *aCx, JSObject *aScope,
+                             bool *aTriedToWrap) MOZ_OVERRIDE;
   // nsScriptElement
   virtual bool HasScriptContent();
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_HTMLScriptElement_h
--- a/content/html/content/test/reflect.js
+++ b/content/html/content/test/reflect.js
@@ -58,17 +58,16 @@ function reflectString(aParameters)
   // TODO: remove this ugly hack when null stringification will work as expected.
   var todoAttrs = {
     col: [ "align", "vAlign", "ch" ],
     colgroup: [ "align", "vAlign", "ch" ],
     form: [ "acceptCharset", "name", "target" ],
     img: [ "align" ],
     input: [ "accept", "alt", "formTarget", "max", "min", "name", "pattern", "placeholder", "step", "defaultValue" ],
     link: [ "crossOrigin" ],
-    script: [ "crossOrigin" ],
     source: [ "media" ],
     table: [ "border", "width" ],
     tbody: [ "align", "vAlign", "ch" ],
     td: [ "align", "vAlign", "ch" ],
     textarea: [ "name", "placeholder" ],
     tfoot: [ "align", "vAlign", "ch" ],
     th: [ "align", "vAlign", "ch" ],
     thead: [ "align", "vAlign", "ch" ],
--- a/content/html/content/test/test_bug389797.html
+++ b/content/html/content/test/test_bug389797.html
@@ -190,17 +190,17 @@ HTML_TAG("optgroup", "OptGroup");
 HTML_TAG("option", "Option");
 HTML_TAG("p", "Paragraph");
 HTML_TAG("param", "Param");
 HTML_TAG("plaintext", "");
 HTML_TAG("pre", "Pre");
 HTML_TAG("q", "Quote");
 HTML_TAG("s", "");
 HTML_TAG("samp", "");
-HTML_TAG("script", "Script", [], [ "nsIScriptLoaderObserver" ]);
+HTML_TAG("script", "Script", [ "nsIScriptLoaderObserver" ], []);
 HTML_TAG("section", "")
 HTML_TAG("select", "Select", ["nsIDOMHTMLSelectElement"]);
 HTML_TAG("small", "");
 HTML_TAG("span", "Span");
 HTML_TAG("strike", "");
 HTML_TAG("strong", "");
 HTML_TAG("style", "Style", [ "nsIDOMLinkStyle" ]);
 HTML_TAG("sub", "");
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -2745,16 +2745,17 @@ nsDOMClassInfo::Init()
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(HTMLQuoteElement, nsIDOMHTMLQuoteElement)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMHTMLQuoteElement)
     DOM_CLASSINFO_GENERIC_HTML_MAP_ENTRIES
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(HTMLScriptElement, nsIDOMHTMLScriptElement)
+    DOM_CLASSINFO_MAP_ENTRY(nsIScriptLoaderObserver)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMHTMLScriptElement)
     DOM_CLASSINFO_GENERIC_HTML_MAP_ENTRIES
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(HTMLSelectElement, nsIDOMHTMLSelectElement)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMHTMLSelectElement)
     DOM_CLASSINFO_GENERIC_HTML_MAP_ENTRIES
   DOM_CLASSINFO_MAP_END
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -413,16 +413,20 @@ DOMInterfaces = {
     'hasInstanceInterface': 'nsIDOMHTMLPreElement',
 },
 
 'HTMLPropertiesCollection': {
     'headerFile': 'HTMLPropertiesCollection.h',
     'resultNotAddRefed': [ 'item', 'namedItem', 'names' ]
 },
 
+'HTMLScriptElement': {
+  'hasInstanceInterface': 'nsIDOMHTMLScriptElement',
+},
+
 'HTMLUListElement': {
     'headerFile' : 'mozilla/dom/HTMLSharedListElement.h'
 },
 
 'IID': [
 {
     'nativeType': 'nsIJSID',
     'headerFile': 'xpcjsid.h',
new file mode 100644
--- /dev/null
+++ b/dom/webidl/HTMLScriptElement.webidl
@@ -0,0 +1,37 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * The origin of this IDL file is
+ * http://www.whatwg.org/specs/web-apps/current-work/#the-script-element
+ * http://www.whatwg.org/specs/web-apps/current-work/#other-elements,-attributes-and-apis
+ */
+
+interface HTMLScriptElement : HTMLElement {
+  [SetterThrows]
+  attribute DOMString src;
+  [SetterThrows]
+  attribute DOMString type;
+  [SetterThrows]
+  attribute DOMString charset;
+  [SetterThrows]
+  attribute boolean async;
+  [SetterThrows]
+  attribute boolean defer;
+  [SetterThrows]
+  attribute DOMString crossOrigin;
+  [SetterThrows]
+  attribute DOMString text;
+/*
+};
+
+// http://www.whatwg.org/specs/web-apps/current-work/#other-elements,-attributes-and-apis
+partial interface HTMLScriptElement {
+*/
+  [SetterThrows]
+  attribute DOMString event;
+  [SetterThrows]
+  attribute DOMString htmlFor;
+};
+
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -66,16 +66,17 @@ webidl_files = \
   HTMLImageElement.webidl \
   HTMLLabelElement.webidl \
   HTMLLIElement.webidl \
   HTMLOListElement.webidl \
   HTMLOptionsCollection.webidl \
   HTMLParagraphElement.webidl \
   HTMLPreElement.webidl \
   HTMLPropertiesCollection.webidl \
+  HTMLScriptElement.webidl \
   HTMLSpanElement.webidl \
   HTMLTitleElement.webidl \
   HTMLUListElement.webidl \
   ImageData.webidl \
   Location.webidl \
   MutationObserver.webidl \
   Node.webidl \
   NodeFilter.webidl \