Changeset 201852 in webkit


Ignore:
Timestamp:
Jun 8, 2016 10:18:38 PM (8 years ago)
Author:
Chris Dumez
Message:

DedicatedWorkerGlobalScope prototype chain is incorrect
https://bugs.webkit.org/show_bug.cgi?id=158544

Reviewed by Brady Eidson.

Source/WebCore:

There were several issues with the prototype chain of DedicatedWorkerGlobalScope:

  1. Object.getPrototypeOf(DedicatedWorkerGlobalScope.prototype) was not WorkerGlobalScope.prototype.
  2. WorkerGlobalScope.prototype was a DedicatedWorkerGlobalScopePrototype object and was equal to DedicatedWorkerGlobalScope.prototype.
  3. Object.getPrototypeOf(WorkerGlobalScope.prototype) was not EventTarget.prototype.

Those issues were identified by the following W3C web-platform-test:
http://w3c-test.org/workers/interfaces.worker

This patch fixes the issue so that the prototype chain is now as per the
specification.

Test: fast/workers/DedicatedWorkerGlobalScope-prototype-chain.html

  • bindings/js/WorkerScriptController.cpp:

(WebCore::WorkerScriptController::initScript):

  • Stop creating the WorkerGlobalScopePrototype and let JSWorkerGlobalScope create it.
  • Set DedicatedWorkerGlobalScopePrototype's prototype to JSWorkerGlobalScope's prototype after creating the JSDedicatedWorkerGlobalScope object.
  • bindings/scripts/CodeGeneratorJS.pm:

(ShouldUseGlobalObjectPrototype):
(GenerateHeader):
(GenerateImplementation):
(GenerateConstructorHelperMethods):

  • Do not use globalObject.getPrototypeDirect() as 'prototype' property for WorkerGlobalScope. The globalObject is a DedicatedWorkerGlobalScope, not a WorkerGlobalScope.
  • Generate the code to create / get a prototype object for WorkerGlobalScope.

LayoutTests:

Add test coverage for the DedicatedWorkerGlobalScope prototype chain.

  • fast/workers/DedicatedWorkerGlobalScope-prototype-chain-expected.txt: Added.
  • fast/workers/DedicatedWorkerGlobalScope-prototype-chain.html: Added.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r201851 r201852  
     12016-06-08  Chris Dumez  <cdumez@apple.com>
     2
     3        DedicatedWorkerGlobalScope prototype chain is incorrect
     4        https://bugs.webkit.org/show_bug.cgi?id=158544
     5
     6        Reviewed by Brady Eidson.
     7
     8        Add test coverage for the DedicatedWorkerGlobalScope prototype chain.
     9
     10        * fast/workers/DedicatedWorkerGlobalScope-prototype-chain-expected.txt: Added.
     11        * fast/workers/DedicatedWorkerGlobalScope-prototype-chain.html: Added.
     12
    1132016-06-08  Adam Bergkvist  <adam.bergkvist@ericsson.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r201851 r201852  
     12016-06-08  Chris Dumez  <cdumez@apple.com>
     2
     3        DedicatedWorkerGlobalScope prototype chain is incorrect
     4        https://bugs.webkit.org/show_bug.cgi?id=158544
     5
     6        Reviewed by Brady Eidson.
     7
     8        There were several issues with the prototype chain of DedicatedWorkerGlobalScope:
     9        1. Object.getPrototypeOf(DedicatedWorkerGlobalScope.prototype) was not
     10           WorkerGlobalScope.prototype.
     11        2. WorkerGlobalScope.prototype was a DedicatedWorkerGlobalScopePrototype
     12           object and was equal to DedicatedWorkerGlobalScope.prototype.
     13        3. Object.getPrototypeOf(WorkerGlobalScope.prototype) was not EventTarget.prototype.
     14
     15        Those issues were identified by the following W3C web-platform-test:
     16        http://w3c-test.org/workers/interfaces.worker
     17
     18        This patch fixes the issue so that the prototype chain is now as per the
     19        specification.
     20
     21        Test: fast/workers/DedicatedWorkerGlobalScope-prototype-chain.html
     22
     23        * bindings/js/WorkerScriptController.cpp:
     24        (WebCore::WorkerScriptController::initScript):
     25        - Stop creating the WorkerGlobalScopePrototype and let JSWorkerGlobalScope
     26          create it.
     27        - Set DedicatedWorkerGlobalScopePrototype's prototype to JSWorkerGlobalScope's
     28          prototype after creating the JSDedicatedWorkerGlobalScope object.
     29
     30        * bindings/scripts/CodeGeneratorJS.pm:
     31        (ShouldUseGlobalObjectPrototype):
     32        (GenerateHeader):
     33        (GenerateImplementation):
     34        (GenerateConstructorHelperMethods):
     35        - Do not use globalObject.getPrototypeDirect() as 'prototype' property for
     36          WorkerGlobalScope. The globalObject is a DedicatedWorkerGlobalScope, not
     37          a WorkerGlobalScope.
     38        - Generate the code to create / get a prototype object for WorkerGlobalScope.
     39
     40
    1412016-06-08  Adam Bergkvist  <adam.bergkvist@ericsson.com>
    242
  • trunk/Source/WebCore/bindings/js/WorkerScriptController.cpp

    r201808 r201852  
    8282    // when we allocate the global object. (Once the global object is fully
    8383    // constructed, it can mark its own prototype.)
    84     Structure* workerGlobalScopePrototypeStructure = JSWorkerGlobalScopePrototype::createStructure(*m_vm, 0, jsNull());
    85     Strong<JSWorkerGlobalScopePrototype> workerGlobalScopePrototype(*m_vm, JSWorkerGlobalScopePrototype::create(*m_vm, 0, workerGlobalScopePrototypeStructure));
    86 
    8784    if (m_workerGlobalScope->isDedicatedWorkerGlobalScope()) {
    88         Structure* dedicatedContextPrototypeStructure = JSDedicatedWorkerGlobalScopePrototype::createStructure(*m_vm, 0, workerGlobalScopePrototype.get());
     85        Structure* dedicatedContextPrototypeStructure = JSDedicatedWorkerGlobalScopePrototype::createStructure(*m_vm, 0, jsNull());
    8986        Strong<JSDedicatedWorkerGlobalScopePrototype> dedicatedContextPrototype(*m_vm, JSDedicatedWorkerGlobalScopePrototype::create(*m_vm, 0, dedicatedContextPrototypeStructure));
    9087        Structure* structure = JSDedicatedWorkerGlobalScope::createStructure(*m_vm, 0, dedicatedContextPrototype.get());
     
    9390
    9491        m_workerGlobalScopeWrapper.set(*m_vm, JSDedicatedWorkerGlobalScope::create(*m_vm, structure, static_cast<DedicatedWorkerGlobalScope&>(*m_workerGlobalScope), proxy));
    95         workerGlobalScopePrototypeStructure->setGlobalObject(*m_vm, m_workerGlobalScopeWrapper.get());
    9692        dedicatedContextPrototypeStructure->setGlobalObject(*m_vm, m_workerGlobalScopeWrapper.get());
    9793        ASSERT(structure->globalObject() == m_workerGlobalScopeWrapper);
    9894        ASSERT(m_workerGlobalScopeWrapper->structure()->globalObject() == m_workerGlobalScopeWrapper);
    99         workerGlobalScopePrototype->structure()->setGlobalObject(*m_vm, m_workerGlobalScopeWrapper.get());
    100         workerGlobalScopePrototype->structure()->setPrototypeWithoutTransition(*m_vm, JSEventTarget::prototype(*m_vm, m_workerGlobalScopeWrapper.get()));
    10195        dedicatedContextPrototype->structure()->setGlobalObject(*m_vm, m_workerGlobalScopeWrapper.get());
     96        dedicatedContextPrototype->structure()->setPrototypeWithoutTransition(*m_vm, JSWorkerGlobalScope::prototype(*m_vm, m_workerGlobalScopeWrapper.get()));
    10297
    10398        proxy->setTarget(*m_vm, m_workerGlobalScopeWrapper.get());
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r201834 r201852  
    269269    my $interface = shift;
    270270    return $interface->name eq "DOMWindow" || $codeGenerator->InheritsInterface($interface, "WorkerGlobalScope") || $interface->name eq "TestGlobalObject";
     271}
     272
     273sub ShouldUseGlobalObjectPrototype
     274{
     275    my $interface = shift;
     276
     277    # For workers, the global object is a DedicatedWorkerGlobalScope.
     278    return 0 if $interface->name eq "WorkerGlobalScope";
     279
     280    return IsDOMGlobalObject($interface);
    271281}
    272282
     
    11471157
    11481158    # Prototype
    1149     unless (IsDOMGlobalObject($interface)) {
     1159    unless (ShouldUseGlobalObjectPrototype($interface)) {
    11501160        push(@headerContent, "    static JSC::JSObject* createPrototype(JSC::VM&, JSC::JSGlobalObject*);\n");
    11511161        push(@headerContent, "    static JSC::JSObject* prototype(JSC::VM&, JSC::JSGlobalObject*);\n");
     
    24012411        }
    24022412        push(@implContent, "}\n\n");
    2403     } else {
     2413    }
     2414   
     2415    unless (ShouldUseGlobalObjectPrototype($interface)) {
    24042416        push(@implContent, "JSObject* ${className}::createPrototype(VM& vm, JSGlobalObject* globalObject)\n");
    24052417        push(@implContent, "{\n");
    2406         if ($hasParent && $parentClassName ne "JSC::DOMNodeFilter") {
    2407             push(@implContent, "    return ${className}Prototype::create(vm, globalObject, ${className}Prototype::createStructure(vm, globalObject, ${parentClassName}::prototype(vm, globalObject)));\n");
     2418        if ($interface->parent) {
     2419            my $parentClassNameForPrototype = "JS" . $interface->parent;
     2420            push(@implContent, "    return ${className}Prototype::create(vm, globalObject, ${className}Prototype::createStructure(vm, globalObject, ${parentClassNameForPrototype}::prototype(vm, globalObject)));\n");
    24082421        } else {
    24092422            my $prototype = $interface->isException ? "errorPrototype" : "objectPrototype";
     
    51835196    # of whether the interface was declared with the [NoInterfaceObject] extended attribute.
    51845197    # https://heycam.github.io/webidl/#interface-prototype-object
    5185     if (IsDOMGlobalObject($interface)) {
     5198    if (ShouldUseGlobalObjectPrototype($interface)) {
    51865199        push(@$outputArray, "    putDirect(vm, vm.propertyNames->prototype, globalObject.getPrototypeDirect(), DontDelete | ReadOnly | DontEnum);\n");
    51875200    } elsif ($interface->isCallback) {
Note: See TracChangeset for help on using the changeset viewer.