Changeset 177864 in webkit


Ignore:
Timestamp:
Jan 2, 2015, 10:18:40 AM (11 years ago)
Author:
Darin Adler
Message:

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.

Location:
trunk/Source/WebCore
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r177863 r177864  
     12015-01-02  Darin Adler  <darin@apple.com>
     2
     3        Pass Document instead of ScriptExecutionContext to non-worker constructors
     4        https://bugs.webkit.org/show_bug.cgi?id=140040
     5
     6        Reviewed by Sam Weinig.
     7
     8        * bindings/scripts/CodeGeneratorJS.pm:
     9        (GenerateConstructorDefinition):
     10        Generate code passing the document when ConstructorCallWith=Document is used.
     11        Later, we could base this on whether the constructor is exposed to workers
     12        or not, instead, but for now this seems a clean way to do it.
     13
     14        * bindings/scripts/IDLAttributes.txt: Allow ConstructorCallWith=Document.
     15
     16        * Modules/notifications/Notification.cpp:
     17        (WebCore::Notification::create):
     18        * Modules/notifications/Notification.h:
     19        * Modules/notifications/Notification.idl:
     20        * dom/Comment.cpp:
     21        * dom/Comment.h:
     22        * dom/Comment.idl:
     23        * dom/DocumentFragment.cpp:
     24        (WebCore::DocumentFragment::nodeName): Use ASCIILiteral (just something
     25        I noticed in passing).
     26        * dom/DocumentFragment.h:
     27        * dom/DocumentFragment.idl:
     28        * dom/Range.cpp:
     29        * dom/Range.h:
     30        * dom/Range.idl:
     31        * dom/Text.cpp:
     32        * dom/Text.h:
     33        * dom/Text.idl:
     34        Change from ScriptExecutionContext to Document, and remove unneeded
     35        overloads that were just casting. It's better to have the bindings
     36        layer, which knows these are not ScriptExecutionContext, do the cast
     37        than to have create functions that cast that are not in any position
     38        to know the cast is safe.
     39
    1402015-01-02  Darin Adler  <darin@apple.com>
    241
  • trunk/Source/WebCore/Modules/notifications/Notification.cpp

    r177259 r177864  
    108108
    109109#if ENABLE(NOTIFICATIONS)
    110 Ref<Notification> Notification::create(ScriptExecutionContext& context, const String& title, const Dictionary& options)
     110Ref<Notification> Notification::create(Document& context, const String& title, const Dictionary& options)
    111111{
    112112    auto notification = adoptRef(*new Notification(context, title));
  • trunk/Source/WebCore/Modules/notifications/Notification.h

    r177259 r177864  
    7070#endif
    7171#if ENABLE(NOTIFICATIONS)
    72     static Ref<Notification> create(ScriptExecutionContext&, const String& title, const Dictionary& options);
     72    static Ref<Notification> create(Document&, const String& title, const Dictionary& options);
    7373#endif
    7474   
  • trunk/Source/WebCore/Modules/notifications/Notification.idl

    r159061 r177864  
    3636#if defined(ENABLE_NOTIFICATIONS) && ENABLE_NOTIFICATIONS
    3737    Constructor(DOMString title, [Default=Undefined] optional Dictionary options),
    38     ConstructorCallWith=ScriptExecutionContext,
     38    ConstructorCallWith=Document,
    3939#endif
    4040] interface Notification {
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r177744 r177864  
    46004600            my ($dummy, $paramIndex) = GenerateParametersCheck($outputArray, $function, $interface, $numParameters, $interfaceName, "constructorCallback", undef, undef, undef);
    46014601
    4602             if ($codeGenerator->ExtendedAttributeContains($interface->extendedAttributes->{"ConstructorCallWith"}, "ScriptExecutionContext") ) {
     4602            if ($codeGenerator->ExtendedAttributeContains($interface->extendedAttributes->{"ConstructorCallWith"}, "ScriptExecutionContext")) {
    46034603                push(@constructorArgList, "*context");
    46044604                push(@$outputArray, "    ScriptExecutionContext* context = castedThis->scriptExecutionContext();\n");
    46054605                push(@$outputArray, "    if (!context)\n");
    46064606                push(@$outputArray, "        return throwConstructorDocumentUnavailableError(*exec, \"${interfaceName}\");\n");
     4607            }
     4608            if ($codeGenerator->ExtendedAttributeContains($interface->extendedAttributes->{"ConstructorCallWith"}, "Document")) {
     4609                $implIncludes{"Document.h"} = 1;
     4610                push(@constructorArgList, "document");
     4611                push(@$outputArray, "    ScriptExecutionContext* context = castedThis->scriptExecutionContext();\n");
     4612                push(@$outputArray, "    if (!context)\n");
     4613                push(@$outputArray, "        return throwConstructorDocumentUnavailableError(*exec, \"${interfaceName}\");\n");
     4614                push(@$outputArray, "    Document& document = downcast<Document>(*context);\n");
    46074615            }
    46084616            if ($generatingNamedConstructor) {
  • trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt

    r172540 r177864  
    3030Conditional=*
    3131Constructor
    32 ConstructorCallWith=ScriptExecutionContext
     32ConstructorCallWith=Document|ScriptExecutionContext
    3333ConstructorConditional=*
    3434ConstructorRaisesException
  • trunk/Source/WebCore/dom/Comment.cpp

    r177559 r177864  
    3737}
    3838
    39 Ref<Comment> Comment::create(ScriptExecutionContext& context, const String& text)
    40 {
    41     return adoptRef(*new Comment(downcast<Document>(context), text));
    42 }
    43 
    4439String Comment::nodeName() const
    4540{
  • trunk/Source/WebCore/dom/Comment.h

    r177559 r177864  
    3131public:
    3232    static Ref<Comment> create(Document&, const String&);
    33     static Ref<Comment> create(ScriptExecutionContext&, const String&);
    3433
    3534private:
  • trunk/Source/WebCore/dom/Comment.idl

    r161867 r177864  
    2020[
    2121    Constructor([Default=NullString] optional DOMString data),
    22     ConstructorCallWith=ScriptExecutionContext
     22    ConstructorCallWith=Document
    2323] interface Comment : CharacterData {
    2424};
  • trunk/Source/WebCore/dom/DocumentFragment.cpp

    r177559 r177864  
    4242}
    4343
    44 Ref<DocumentFragment> DocumentFragment::create(ScriptExecutionContext& context)
    45 {
    46     return adoptRef(*new DocumentFragment(downcast<Document>(context), Node::CreateDocumentFragment));
    47 }
    48 
    4944String DocumentFragment::nodeName() const
    5045{
    51     return "#document-fragment";
     46    return ASCIILiteral("#document-fragment");
    5247}
    5348
  • trunk/Source/WebCore/dom/DocumentFragment.h

    r177559 r177864  
    3030namespace WebCore {
    3131
    32 class ScriptExecutionContext;
    33 
    3432class DocumentFragment : public ContainerNode {
    3533public:
    3634    static Ref<DocumentFragment> create(Document&);
    37     static Ref<DocumentFragment> create(ScriptExecutionContext&);
    3835
    3936    void parseHTML(const String&, Element* contextElement, ParserContentPolicy = AllowScriptingContent);
  • trunk/Source/WebCore/dom/DocumentFragment.idl

    r162062 r177864  
    2020 [
    2121    Constructor,
    22     ConstructorCallWith=ScriptExecutionContext
     22    ConstructorCallWith=Document
    2323 ] interface DocumentFragment : Node {
    2424    // NodeSelector - Selector API
  • trunk/Source/WebCore/dom/Range.cpp

    r177513 r177864  
    103103{
    104104    return adoptRef(*new Range(ownerDocument, start.containerNode(), start.computeOffsetInContainerNode(), end.containerNode(), end.computeOffsetInContainerNode()));
    105 }
    106 
    107 Ref<Range> Range::create(ScriptExecutionContext& context)
    108 {
    109     return adoptRef(*new Range(downcast<Document>(context)));
    110105}
    111106
  • trunk/Source/WebCore/dom/Range.h

    r177739 r177864  
    4545class Node;
    4646class NodeWithIndex;
     47class SelectionRect;
    4748class Text;
    4849class VisiblePosition;
    49 #if PLATFORM(IOS)
    50 class SelectionRect;
    51 #endif
    5250
    5351class Range : public RefCounted<Range> {
     
    5654    WEBCORE_EXPORT static Ref<Range> create(Document&, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset);
    5755    WEBCORE_EXPORT static Ref<Range> create(Document&, const Position&, const Position&);
    58     WEBCORE_EXPORT static Ref<Range> create(ScriptExecutionContext&);
    5956    WEBCORE_EXPORT static Ref<Range> create(Document&, const VisiblePosition&, const VisiblePosition&);
    6057    WEBCORE_EXPORT ~Range();
  • trunk/Source/WebCore/dom/Range.idl

    r165676 r177864  
    2222[
    2323    Constructor,
    24     ConstructorCallWith=ScriptExecutionContext,
     24    ConstructorCallWith=Document,
    2525    ImplementationLacksVTable
    2626] interface Range {
  • trunk/Source/WebCore/dom/Text.cpp

    r177559 r177864  
    4444}
    4545
    46 Ref<Text> Text::create(ScriptExecutionContext& context, const String& data)
    47 {
    48     return adoptRef(*new Text(downcast<Document>(context), data, CreateText));
    49 }
    50 
    5146Ref<Text> Text::createEditingText(Document& document, const String& data)
    5247{
  • trunk/Source/WebCore/dom/Text.h

    r177559 r177864  
    3030
    3131class RenderText;
    32 class ScriptExecutionContext;
    3332
    3433class Text : public CharacterData {
     
    3736
    3837    static Ref<Text> create(Document&, const String&);
    39     static Ref<Text> create(ScriptExecutionContext&, const String&);
    4038    static Ref<Text> createWithLengthLimit(Document&, const String&, unsigned positionInString, unsigned lengthLimit = defaultLengthLimit);
    4139    static Ref<Text> createEditingText(Document&, const String&);
  • trunk/Source/WebCore/dom/Text.idl

    r175688 r177864  
    1919[
    2020    Constructor([Default=NullString] optional DOMString data),
    21     ConstructorCallWith=ScriptExecutionContext
     21    ConstructorCallWith=Document
    2222] interface Text : CharacterData {
    2323
Note: See TracChangeset for help on using the changeset viewer.