Changeset 234578 in webkit


Ignore:
Timestamp:
Aug 4, 2018 2:02:44 AM (6 years ago)
Author:
rniwa@webkit.org
Message:

Properties set on window.customElements can disappear due to GC
https://bugs.webkit.org/show_bug.cgi?id=172575
<rdar://problem/32440668>

Reviewed by Saam Barati.

Source/WebCore:

Fixed the bug that JS wrapper of CustomElementsRegistry can erroneously get collected during GC
by keeping it alive as long as the global object is alive.

Test: fast/custom-elements/custom-element-registry-wrapper-should-stay-alive.html

  • dom/CustomElementRegistry.cpp:

(WebCore::CustomElementRegistry::create):
(WebCore::CustomElementRegistry::CustomElementRegistry):

  • dom/CustomElementRegistry.h:

(WebCore::CustomElementRegistry): Make this inherited from ContextDestructionObserver.

  • dom/CustomElementRegistry.idl: Set GenerateIsReachable=ImplScriptExecutionContext in IDL. This will

make CustomElementRegistry reachable from the global object.

  • page/DOMWindow.cpp:

(WebCore::DOMWindow::ensureCustomElementRegistry):

LayoutTests:

Added a regression test.

  • fast/custom-elements/custom-element-registry-wrapper-should-stay-alive-expected.txt: Added.
  • fast/custom-elements/custom-element-registry-wrapper-should-stay-alive.html: Added.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r234566 r234578  
     12018-08-03  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Properties set on window.customElements can disappear due to GC
     4        https://bugs.webkit.org/show_bug.cgi?id=172575
     5        <rdar://problem/32440668>
     6
     7        Reviewed by Saam Barati.
     8
     9        Added a regression test.
     10
     11        * fast/custom-elements/custom-element-registry-wrapper-should-stay-alive-expected.txt: Added.
     12        * fast/custom-elements/custom-element-registry-wrapper-should-stay-alive.html: Added.
     13
    1142018-08-03  Justin Fan  <justin_fan@apple.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r234577 r234578  
     12018-08-04  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Properties set on window.customElements can disappear due to GC
     4        https://bugs.webkit.org/show_bug.cgi?id=172575
     5        <rdar://problem/32440668>
     6
     7        Reviewed by Saam Barati.
     8
     9        Fixed the bug that JS wrapper of CustomElementsRegistry can erroneously get collected during GC
     10        by keeping it alive as long as the global object is alive.
     11
     12        Test: fast/custom-elements/custom-element-registry-wrapper-should-stay-alive.html
     13
     14        * dom/CustomElementRegistry.cpp:
     15        (WebCore::CustomElementRegistry::create):
     16        (WebCore::CustomElementRegistry::CustomElementRegistry):
     17        * dom/CustomElementRegistry.h:
     18        (WebCore::CustomElementRegistry): Make this inherited from ContextDestructionObserver.
     19        * dom/CustomElementRegistry.idl: Set GenerateIsReachable=ImplScriptExecutionContext in IDL. This will
     20        make CustomElementRegistry reachable from the global object.
     21        * page/DOMWindow.cpp:
     22        (WebCore::DOMWindow::ensureCustomElementRegistry):
     23
    1242018-08-03  Ryosuke Niwa  <rniwa@webkit.org>
    225
  • trunk/Source/WebCore/dom/CustomElementRegistry.cpp

    r234507 r234578  
    4242namespace WebCore {
    4343
    44 Ref<CustomElementRegistry> CustomElementRegistry::create(DOMWindow& window)
     44Ref<CustomElementRegistry> CustomElementRegistry::create(DOMWindow& window, ScriptExecutionContext* scriptExecutionContext)
    4545{
    46     return adoptRef(*new CustomElementRegistry(window));
     46    return adoptRef(*new CustomElementRegistry(window, scriptExecutionContext));
    4747}
    4848
    49 CustomElementRegistry::CustomElementRegistry(DOMWindow& window)
    50     : m_window(window)
     49CustomElementRegistry::CustomElementRegistry(DOMWindow& window, ScriptExecutionContext* scriptExecutionContext)
     50    : ContextDestructionObserver(scriptExecutionContext)
     51    , m_window(window)
    5152{
    5253}
  • trunk/Source/WebCore/dom/CustomElementRegistry.h

    r234507 r234578  
    2626#pragma once
    2727
     28#include "ContextDestructionObserver.h"
    2829#include "QualifiedName.h"
    2930#include <wtf/HashMap.h>
     
    4849class QualifiedName;
    4950
    50 class CustomElementRegistry : public RefCounted<CustomElementRegistry> {
     51class CustomElementRegistry : public RefCounted<CustomElementRegistry>, public ContextDestructionObserver {
    5152public:
    52     static Ref<CustomElementRegistry> create(DOMWindow&);
     53    static Ref<CustomElementRegistry> create(DOMWindow&, ScriptExecutionContext*);
    5354    ~CustomElementRegistry();
    5455
     
    6970
    7071private:
    71     CustomElementRegistry(DOMWindow&);
     72    CustomElementRegistry(DOMWindow&, ScriptExecutionContext*);
    7273
    7374    DOMWindow& m_window;
  • trunk/Source/WebCore/dom/CustomElementRegistry.idl

    r234507 r234578  
    2626[
    2727    EnabledAtRuntime=CustomElements,
    28     ImplementationLacksVTable,
    2928    JSGenerateToNativeObject,
     29    GenerateIsReachable=ImplScriptExecutionContext
    3030] interface CustomElementRegistry {
    3131    [CEReactions, Custom] void define(DOMString name, Function constructor);
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r233668 r234578  
    611611{
    612612    if (!m_customElementRegistry)
    613         m_customElementRegistry = CustomElementRegistry::create(*this);
     613        m_customElementRegistry = CustomElementRegistry::create(*this, scriptExecutionContext());
    614614    return *m_customElementRegistry;
    615615}
Note: See TracChangeset for help on using the changeset viewer.