Skip to content
Permalink
Browse files
JSCustomElementInterface::invokeCallback can be called with a null ca…
…llback 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):


Canonical link: https://commits.webkit.org/184558@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@211309 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
msaboff committed Jan 28, 2017
1 parent 39d919b commit f4bcb95134d5c88ef0b5aff12bc1155ad7c84ec5
Showing 2 changed files with 31 additions and 5 deletions.
@@ -1,3 +1,16 @@
2017-01-27 Michael Saboff <msaboff@apple.com>

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):

2017-01-27 Myles C. Maxfield <mmaxfield@apple.com>

[Cocoa] Prepare ComplexTextController for unit testing
@@ -122,15 +122,18 @@ JSValue JSCustomElementRegistry::define(ExecState& state)
QualifiedName name(nullAtom, localName, HTMLNames::xhtmlNamespaceURI);
auto elementInterface = JSCustomElementInterface::create(name, constructor, globalObject());

if (auto* connectedCallback = getCustomElementCallback(state, prototypeObject, Identifier::fromString(&vm, "connectedCallback")))
auto* connectedCallback = getCustomElementCallback(state, prototypeObject, Identifier::fromString(&vm, "connectedCallback"));
if (connectedCallback)
elementInterface->setConnectedCallback(connectedCallback);
RETURN_IF_EXCEPTION(scope, JSValue());

if (auto* disconnectedCallback = getCustomElementCallback(state, prototypeObject, Identifier::fromString(&vm, "disconnectedCallback")))
auto* disconnectedCallback = getCustomElementCallback(state, prototypeObject, Identifier::fromString(&vm, "disconnectedCallback"));
if (disconnectedCallback)
elementInterface->setDisconnectedCallback(disconnectedCallback);
RETURN_IF_EXCEPTION(scope, JSValue());

if (auto* adoptedCallback = getCustomElementCallback(state, prototypeObject, Identifier::fromString(&vm, "adoptedCallback")))
auto* adoptedCallback = getCustomElementCallback(state, prototypeObject, Identifier::fromString(&vm, "adoptedCallback"));
if (adoptedCallback)
elementInterface->setAdoptedCallback(adoptedCallback);
RETURN_IF_EXCEPTION(scope, JSValue());

@@ -146,8 +149,18 @@ JSValue JSCustomElementRegistry::define(ExecState& state)
}
}

PrivateName uniquePrivateName;
globalObject()->putDirect(vm, uniquePrivateName, constructor);
auto addToGlobalObjectWithPrivateName = [&] (JSObject* objectToAdd) {
if (objectToAdd) {
PrivateName uniquePrivateName;
globalObject()->putDirect(vm, uniquePrivateName, objectToAdd);
}
};

addToGlobalObjectWithPrivateName(constructor);
addToGlobalObjectWithPrivateName(connectedCallback);
addToGlobalObjectWithPrivateName(disconnectedCallback);
addToGlobalObjectWithPrivateName(adoptedCallback);
addToGlobalObjectWithPrivateName(attributeChangedCallback);

registry.addElementDefinition(WTFMove(elementInterface));

0 comments on commit f4bcb95

Please sign in to comment.