Pass Document instead of ScriptExecutionContext to non-worker constructors
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Jan 2015 18:18:40 +0000 (18:18 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Jan 2015 18:18:40 +0000 (18:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=140040

Reviewed by Sam Weinig.

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateConstructorDefinition):
Generate code passing the document when ConstructorCallWith=Document is used.
Later, we could base this on whether the constructor is exposed to workers
or not, instead, but for now this seems a clean way to do it.

* bindings/scripts/IDLAttributes.txt: Allow ConstructorCallWith=Document.

* Modules/notifications/Notification.cpp:
(WebCore::Notification::create):
* Modules/notifications/Notification.h:
* Modules/notifications/Notification.idl:
* dom/Comment.cpp:
* dom/Comment.h:
* dom/Comment.idl:
* dom/DocumentFragment.cpp:
(WebCore::DocumentFragment::nodeName): Use ASCIILiteral (just something
I noticed in passing).
* dom/DocumentFragment.h:
* dom/DocumentFragment.idl:
* dom/Range.cpp:
* dom/Range.h:
* dom/Range.idl:
* dom/Text.cpp:
* dom/Text.h:
* dom/Text.idl:
Change from ScriptExecutionContext to Document, and remove unneeded
overloads that were just casting. It's better to have the bindings
layer, which knows these are not ScriptExecutionContext, do the cast
than to have create functions that cast that are not in any position
to know the cast is safe.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@177864 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/notifications/Notification.cpp
Source/WebCore/Modules/notifications/Notification.h
Source/WebCore/Modules/notifications/Notification.idl
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/IDLAttributes.txt
Source/WebCore/dom/Comment.cpp
Source/WebCore/dom/Comment.h
Source/WebCore/dom/Comment.idl
Source/WebCore/dom/DocumentFragment.cpp
Source/WebCore/dom/DocumentFragment.h
Source/WebCore/dom/DocumentFragment.idl
Source/WebCore/dom/Range.cpp
Source/WebCore/dom/Range.h
Source/WebCore/dom/Range.idl
Source/WebCore/dom/Text.cpp
Source/WebCore/dom/Text.h
Source/WebCore/dom/Text.idl

index 0a53b146219bf6977ba1c63f6160f6c481bf653b..aad799d7a587933bd1c161d25b4147b2868b3e26 100644 (file)
@@ -1,3 +1,42 @@
+2015-01-02  Darin Adler  <darin@apple.com>
+
+        Pass Document instead of ScriptExecutionContext to non-worker constructors
+        https://bugs.webkit.org/show_bug.cgi?id=140040
+
+        Reviewed by Sam Weinig.
+
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateConstructorDefinition):
+        Generate code passing the document when ConstructorCallWith=Document is used.
+        Later, we could base this on whether the constructor is exposed to workers
+        or not, instead, but for now this seems a clean way to do it.
+
+        * bindings/scripts/IDLAttributes.txt: Allow ConstructorCallWith=Document.
+
+        * Modules/notifications/Notification.cpp:
+        (WebCore::Notification::create):
+        * Modules/notifications/Notification.h:
+        * Modules/notifications/Notification.idl:
+        * dom/Comment.cpp:
+        * dom/Comment.h:
+        * dom/Comment.idl:
+        * dom/DocumentFragment.cpp:
+        (WebCore::DocumentFragment::nodeName): Use ASCIILiteral (just something
+        I noticed in passing).
+        * dom/DocumentFragment.h:
+        * dom/DocumentFragment.idl:
+        * dom/Range.cpp:
+        * dom/Range.h:
+        * dom/Range.idl:
+        * dom/Text.cpp:
+        * dom/Text.h:
+        * dom/Text.idl:
+        Change from ScriptExecutionContext to Document, and remove unneeded
+        overloads that were just casting. It's better to have the bindings
+        layer, which knows these are not ScriptExecutionContext, do the cast
+        than to have create functions that cast that are not in any position
+        to know the cast is safe.
+
 2015-01-02  Darin Adler  <darin@apple.com>
 
         Re-land the HTMLTreeBuilder change with the assertion fixed.
index b9576a477ff94eb922f7a7b6bc928f080ba44c94..9bd044686e1cf77faebb6969c5fc6460017f1fd6 100644 (file)
@@ -107,7 +107,7 @@ Ref<Notification> Notification::create(const String& title, const String& body,
 #endif
 
 #if ENABLE(NOTIFICATIONS)
-Ref<Notification> Notification::create(ScriptExecutionContext& context, const String& title, const Dictionary& options)
+Ref<Notification> Notification::create(Document& context, const String& title, const Dictionary& options)
 {
     auto notification = adoptRef(*new Notification(context, title));
     String argument;
index 6b6940e4fa749762f90fc5c60f08e04eaba91154..d55561191a0f14565b0b1581f47dd23a65b71a49 100644 (file)
@@ -69,7 +69,7 @@ public:
     static Ref<Notification> create(const String& title, const String& body, const String& iconURI, ScriptExecutionContext*, ExceptionCode&, PassRefPtr<NotificationCenter> provider);
 #endif
 #if ENABLE(NOTIFICATIONS)
-    static Ref<Notification> create(ScriptExecutionContext&, const String& title, const Dictionary& options);
+    static Ref<Notification> create(Document&, const String& title, const Dictionary& options);
 #endif
     
     WEBCORE_EXPORT virtual ~Notification();
index 6b0e14021699911adbc15898e6566225b307fcf3..1ddf5b340ae5856a80edb4adf4dfb3de07440416 100644 (file)
@@ -35,7 +35,7 @@
     EventTarget,
 #if defined(ENABLE_NOTIFICATIONS) && ENABLE_NOTIFICATIONS
     Constructor(DOMString title, [Default=Undefined] optional Dictionary options),
-    ConstructorCallWith=ScriptExecutionContext,
+    ConstructorCallWith=Document,
 #endif
 ] interface Notification {
     void show();
index a50c53563c662d2e6968def60b27e42bab139d3c..f85699829d8bfad5eb34ef2a9271cf07a8824c36 100644 (file)
@@ -4599,12 +4599,20 @@ END
             my $numParameters = @{$function->parameters};
             my ($dummy, $paramIndex) = GenerateParametersCheck($outputArray, $function, $interface, $numParameters, $interfaceName, "constructorCallback", undef, undef, undef);
 
-            if ($codeGenerator->ExtendedAttributeContains($interface->extendedAttributes->{"ConstructorCallWith"}, "ScriptExecutionContext") ) {
+            if ($codeGenerator->ExtendedAttributeContains($interface->extendedAttributes->{"ConstructorCallWith"}, "ScriptExecutionContext")) {
                 push(@constructorArgList, "*context");
                 push(@$outputArray, "    ScriptExecutionContext* context = castedThis->scriptExecutionContext();\n");
                 push(@$outputArray, "    if (!context)\n");
                 push(@$outputArray, "        return throwConstructorDocumentUnavailableError(*exec, \"${interfaceName}\");\n");
             }
+            if ($codeGenerator->ExtendedAttributeContains($interface->extendedAttributes->{"ConstructorCallWith"}, "Document")) {
+                $implIncludes{"Document.h"} = 1;
+                push(@constructorArgList, "document");
+                push(@$outputArray, "    ScriptExecutionContext* context = castedThis->scriptExecutionContext();\n");
+                push(@$outputArray, "    if (!context)\n");
+                push(@$outputArray, "        return throwConstructorDocumentUnavailableError(*exec, \"${interfaceName}\");\n");
+                push(@$outputArray, "    Document& document = downcast<Document>(*context);\n");
+            }
             if ($generatingNamedConstructor) {
                 push(@constructorArgList, "*castedThis->document()");
             }
index 1e4590f97716aed0e75dc7e434ae267376660f80..aa047a5fde28b091cdcdd9679115669cd02af4f9 100644 (file)
@@ -29,7 +29,7 @@ CheckSecurityForNode
 Clamp
 Conditional=*
 Constructor
-ConstructorCallWith=ScriptExecutionContext
+ConstructorCallWith=Document|ScriptExecutionContext
 ConstructorConditional=*
 ConstructorRaisesException
 ConstructorTemplate=Event|TypedArray
index 49f54056b7efc22bce8dad66809912ed781efcf0..4c74aaf63ad9053c6abe5955623185d27d989d6b 100644 (file)
@@ -36,11 +36,6 @@ Ref<Comment> Comment::create(Document& document, const String& text)
     return adoptRef(*new Comment(document, text));
 }
 
-Ref<Comment> Comment::create(ScriptExecutionContext& context, const String& text)
-{
-    return adoptRef(*new Comment(downcast<Document>(context), text));
-}
-
 String Comment::nodeName() const
 {
     return commentAtom.string();
index 3f44e5619432fbcdf3551d8b3c9236340a799d89..fcac60a33e5e30a1e59c1dc9ef3b6394ade7b759 100644 (file)
@@ -30,7 +30,6 @@ namespace WebCore {
 class Comment final : public CharacterData {
 public:
     static Ref<Comment> create(Document&, const String&);
-    static Ref<Comment> create(ScriptExecutionContext&, const String&);
 
 private:
     Comment(Document&, const String&);
index d928c6ef11a8d1ab9ad255f6d68961b1f9c39a3d..0503d63153b2b7dfde006ff08794926635e7c844 100644 (file)
@@ -19,7 +19,7 @@
 
 [
     Constructor([Default=NullString] optional DOMString data),
-    ConstructorCallWith=ScriptExecutionContext
+    ConstructorCallWith=Document
 ] interface Comment : CharacterData {
 };
 
index a0190e46c861ac9332e4d3b03de5279deaab94b3..d600812cefe717e3f6ea6f87a07855097d0b04e5 100644 (file)
@@ -41,14 +41,9 @@ Ref<DocumentFragment> DocumentFragment::create(Document& document)
     return adoptRef(*new DocumentFragment(document, Node::CreateDocumentFragment));
 }
 
-Ref<DocumentFragment> DocumentFragment::create(ScriptExecutionContext& context)
-{
-    return adoptRef(*new DocumentFragment(downcast<Document>(context), Node::CreateDocumentFragment));
-}
-
 String DocumentFragment::nodeName() const
 {
-    return "#document-fragment";
+    return ASCIILiteral("#document-fragment");
 }
 
 Node::NodeType DocumentFragment::nodeType() const
index 11998ff0a78573d83f7bb5915e2b0d4e76703fd8..a7c27912f142ed859481eb077e4ddd8a456737ba 100644 (file)
 
 namespace WebCore {
 
-class ScriptExecutionContext;
-
 class DocumentFragment : public ContainerNode {
 public:
     static Ref<DocumentFragment> create(Document&);
-    static Ref<DocumentFragment> create(ScriptExecutionContext&);
 
     void parseHTML(const String&, Element* contextElement, ParserContentPolicy = AllowScriptingContent);
     bool parseXML(const String&, Element* contextElement, ParserContentPolicy = AllowScriptingContent);
index 6c47ad9115e95b1b3ed237911b84213596599af9..2b8e21456c1293edb7f46ed0a818f78492e82a94 100644 (file)
@@ -19,7 +19,7 @@
 
  [
     Constructor,
-    ConstructorCallWith=ScriptExecutionContext
+    ConstructorCallWith=Document
  ] interface DocumentFragment : Node {
     // NodeSelector - Selector API
     [RaisesException] Element querySelector(DOMString selectors);
index 358807be6d83979b280bcfaaacce768a090f6780..ef63c9db941a63b1acfb64f140b9e7e08fc41e1d 100644 (file)
@@ -104,11 +104,6 @@ Ref<Range> Range::create(Document& ownerDocument, const Position& start, const P
     return adoptRef(*new Range(ownerDocument, start.containerNode(), start.computeOffsetInContainerNode(), end.containerNode(), end.computeOffsetInContainerNode()));
 }
 
-Ref<Range> Range::create(ScriptExecutionContext& context)
-{
-    return adoptRef(*new Range(downcast<Document>(context)));
-}
-
 Ref<Range> Range::create(Document& ownerDocument, const VisiblePosition& visibleStart, const VisiblePosition& visibleEnd)
 {
     Position start = visibleStart.deepEquivalent().parentAnchoredEquivalent();
index 793d35b5c45e28bbd7b414bf266389776a3d3659..edf828e52bfccb2ffd508a95337e194f0e0b7e4c 100644 (file)
@@ -44,18 +44,15 @@ class DocumentFragment;
 class FloatQuad;
 class Node;
 class NodeWithIndex;
+class SelectionRect;
 class Text;
 class VisiblePosition;
-#if PLATFORM(IOS)
-class SelectionRect;
-#endif
 
 class Range : public RefCounted<Range> {
 public:
     WEBCORE_EXPORT static Ref<Range> create(Document&);
     WEBCORE_EXPORT static Ref<Range> create(Document&, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset);
     WEBCORE_EXPORT static Ref<Range> create(Document&, const Position&, const Position&);
-    WEBCORE_EXPORT static Ref<Range> create(ScriptExecutionContext&);
     WEBCORE_EXPORT static Ref<Range> create(Document&, const VisiblePosition&, const VisiblePosition&);
     WEBCORE_EXPORT ~Range();
 
index c9cda433533bb95ffe718fbefb7dce48e4b0d946..cfed94f744add9082bbeaa8d7fb8865e73e747e3 100644 (file)
@@ -21,7 +21,7 @@
 // Introduced in DOM Level 2:
 [
     Constructor,
-    ConstructorCallWith=ScriptExecutionContext,
+    ConstructorCallWith=Document,
     ImplementationLacksVTable
 ] interface Range {
 
index 2b5e9641108296280a153fefd67a124aa75cf2f1..1a864caec10cfe609e26dd9288dd8e96c9852d5d 100644 (file)
@@ -43,11 +43,6 @@ Ref<Text> Text::create(Document& document, const String& data)
     return adoptRef(*new Text(document, data, CreateText));
 }
 
-Ref<Text> Text::create(ScriptExecutionContext& context, const String& data)
-{
-    return adoptRef(*new Text(downcast<Document>(context), data, CreateText));
-}
-
 Ref<Text> Text::createEditingText(Document& document, const String& data)
 {
     return adoptRef(*new Text(document, data, CreateEditingText));
index 91cdef739565e044b157e042e4d7dca98425df34..b2df340dc115bfdee2b2ca3ae5b22892bd726abc 100644 (file)
 namespace WebCore {
 
 class RenderText;
-class ScriptExecutionContext;
 
 class Text : public CharacterData {
 public:
     static const unsigned defaultLengthLimit = 1 << 16;
 
     static Ref<Text> create(Document&, const String&);
-    static Ref<Text> create(ScriptExecutionContext&, const String&);
     static Ref<Text> createWithLengthLimit(Document&, const String&, unsigned positionInString, unsigned lengthLimit = defaultLengthLimit);
     static Ref<Text> createEditingText(Document&, const String&);
 
index 16b71e247ca5da1499afa8c83f7d04cdbf0d3b0e..9df82a2a634773745a7ffae00e58f7e6f52b3196 100644 (file)
@@ -18,7 +18,7 @@
  */
 [
     Constructor([Default=NullString] optional DOMString data),
-    ConstructorCallWith=ScriptExecutionContext
+    ConstructorCallWith=Document
 ] interface Text : CharacterData {
 
     // DOM Level 1