⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 211309 in webkit


Ignore:
Timestamp:
Jan 27, 2017, 4:03:36 PM (10 years ago)
Author:
msaboff@apple.com
Message:

JSCustomElementInterface::invokeCallback can be called with a null callback because Weak<>
​https://bugs.webkit.org/show_bug.cgi?id=167522

Reviewed by Filip Pizlo.

Added all provided callbacks to the global object with a private name the same way
that the constructor was added. This will keep these callbacks from being GC'ed.

  • bindings/js/JSCustomElementRegistryCustom.cpp:

(WebCore::JSCustomElementRegistry::define):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r211308 r211309  
     12017-01-27  Michael Saboff  <msaboff@apple.com>
     2
     3        JSCustomElementInterface::invokeCallback can be called with a null callback because Weak<>
     4        https://bugs.webkit.org/show_bug.cgi?id=167522
     5
     6        Reviewed by Filip Pizlo.
     7
     8        Added all provided callbacks to the global object with a private name the same way
     9        that the constructor was added.  This will keep these callbacks from being GC'ed.
     10
     11        * bindings/js/JSCustomElementRegistryCustom.cpp:
     12        (WebCore::JSCustomElementRegistry::define):
     13
    1142017-01-27  Myles C. Maxfield  <mmaxfield@apple.com>
    215
  • trunk/Source/WebCore/bindings/js/JSCustomElementRegistryCustom.cpp

    r209390 r211309  
    123123    auto elementInterface = JSCustomElementInterface::create(name, constructor, globalObject());
    124124
    125     if (auto* connectedCallback = getCustomElementCallback(state, prototypeObject, Identifier::fromString(&vm, "connectedCallback")))
     125    auto* connectedCallback = getCustomElementCallback(state, prototypeObject, Identifier::fromString(&vm, "connectedCallback"));
     126    if (connectedCallback)
    126127        elementInterface->setConnectedCallback(connectedCallback);
    127128    RETURN_IF_EXCEPTION(scope, JSValue());
    128129
    129     if (auto* disconnectedCallback = getCustomElementCallback(state, prototypeObject, Identifier::fromString(&vm, "disconnectedCallback")))
     130    auto* disconnectedCallback = getCustomElementCallback(state, prototypeObject, Identifier::fromString(&vm, "disconnectedCallback"));
     131    if (disconnectedCallback)
    130132        elementInterface->setDisconnectedCallback(disconnectedCallback);
    131133    RETURN_IF_EXCEPTION(scope, JSValue());
    132134
    133     if (auto* adoptedCallback = getCustomElementCallback(state, prototypeObject, Identifier::fromString(&vm, "adoptedCallback")))
     135    auto* adoptedCallback = getCustomElementCallback(state, prototypeObject, Identifier::fromString(&vm, "adoptedCallback"));
     136    if (adoptedCallback)
    134137        elementInterface->setAdoptedCallback(adoptedCallback);
    135138    RETURN_IF_EXCEPTION(scope, JSValue());
    … …  
    147150    }
    148151
    149     PrivateName uniquePrivateName;
    150     globalObject()->putDirect(vm, uniquePrivateName, constructor);
     152    auto addToGlobalObjectWithPrivateName = [&] (JSObject* objectToAdd) {
     153        if (objectToAdd) {
     154            PrivateName uniquePrivateName;
     155            globalObject()->putDirect(vm, uniquePrivateName, objectToAdd);
     156        }
     157    };
     158
     159    addToGlobalObjectWithPrivateName(constructor);
     160    addToGlobalObjectWithPrivateName(connectedCallback);
     161    addToGlobalObjectWithPrivateName(disconnectedCallback);
     162    addToGlobalObjectWithPrivateName(adoptedCallback);
     163    addToGlobalObjectWithPrivateName(attributeChangedCallback);
    151164
    152165    registry.addElementDefinition(WTFMove(elementInterface));
Note: See TracChangeset for help on using the changeset viewer.