<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[201852] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/201852">201852</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2016-06-08 22:18:38 -0700 (Wed, 08 Jun 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>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.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorebindingsjsWorkerScriptControllercpp">trunk/Source/WebCore/bindings/js/WorkerScriptController.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptsCodeGeneratorJSpm">trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastworkersDedicatedWorkerGlobalScopeprototypechainexpectedtxt">trunk/LayoutTests/fast/workers/DedicatedWorkerGlobalScope-prototype-chain-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastworkersDedicatedWorkerGlobalScopeprototypechainhtml">trunk/LayoutTests/fast/workers/DedicatedWorkerGlobalScope-prototype-chain.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (201851 => 201852)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-06-09 05:09:42 UTC (rev 201851)
+++ trunk/LayoutTests/ChangeLog        2016-06-09 05:18:38 UTC (rev 201852)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-06-08 Chris Dumez <cdumez@apple.com>
+
+ DedicatedWorkerGlobalScope prototype chain is incorrect
+ https://bugs.webkit.org/show_bug.cgi?id=158544
+
+ Reviewed by Brady Eidson.
+
+ Add test coverage for the DedicatedWorkerGlobalScope prototype chain.
+
+ * fast/workers/DedicatedWorkerGlobalScope-prototype-chain-expected.txt: Added.
+ * fast/workers/DedicatedWorkerGlobalScope-prototype-chain.html: Added.
+
</ins><span class="cx"> 2016-06-08 Adam Bergkvist <adam.bergkvist@ericsson.com>
</span><span class="cx">
</span><span class="cx"> WebRTC: Imlement MediaEndpointPeerConnection::setRemoteDescription()
</span></span></pre></div>
<a id="trunkLayoutTestsfastworkersDedicatedWorkerGlobalScopeprototypechainexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/workers/DedicatedWorkerGlobalScope-prototype-chain-expected.txt (0 => 201852)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/workers/DedicatedWorkerGlobalScope-prototype-chain-expected.txt         (rev 0)
+++ trunk/LayoutTests/fast/workers/DedicatedWorkerGlobalScope-prototype-chain-expected.txt        2016-06-09 05:18:38 UTC (rev 201852)
</span><span class="lines">@@ -0,0 +1,13 @@
</span><ins>+Tests that DedicatedWorkerGlobalScope's prototype chain is correct.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+DedicatedWorkerGlobalScope.prototype.toString() === "[object DedicatedWorkerGlobalScopePrototype]": true
+Object.getPrototypeOf(DedicatedWorkerGlobalScope.prototype) === WorkerGlobalScope.prototype: true
+WorkerGlobalScope.prototype.toString() === "[object WorkerGlobalScopePrototype]": true
+Object.getPrototypeOf(WorkerGlobalScope.prototype) === EventTarget.prototype: true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastworkersDedicatedWorkerGlobalScopeprototypechainhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/workers/DedicatedWorkerGlobalScope-prototype-chain.html (0 => 201852)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/workers/DedicatedWorkerGlobalScope-prototype-chain.html         (rev 0)
+++ trunk/LayoutTests/fast/workers/DedicatedWorkerGlobalScope-prototype-chain.html        2016-06-09 05:18:38 UTC (rev 201852)
</span><span class="lines">@@ -0,0 +1,25 @@
</span><ins>+<!DOCTYPE html>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="resources/worker-create-common.js"></script>
+<script>
+
+var jsTestIsAsync = true;
+
+description("Tests that DedicatedWorkerGlobalScope's prototype chain is correct.");
+
+var worker = createWorker();
+worker.postMessage("eval DedicatedWorkerGlobalScope.prototype.toString() === \"[object DedicatedWorkerGlobalScopePrototype]\"");
+worker.postMessage("eval Object.getPrototypeOf(DedicatedWorkerGlobalScope.prototype) === WorkerGlobalScope.prototype");
+worker.postMessage("eval WorkerGlobalScope.prototype.toString() === \"[object WorkerGlobalScopePrototype]\"");
+worker.postMessage("eval Object.getPrototypeOf(WorkerGlobalScope.prototype) === EventTarget.prototype");
+worker.postMessage("eval DONE");
+
+worker.onmessage = function(evt) {
+ if (!/DONE/.test(evt.data))
+ debug(evt.data.replace(new RegExp("/.*LayoutTests"), "<...>"));
+ else
+ finishJSTest();
+};
+
+</script>
+<script src="../../resources/js-test-post.js"></script>
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (201851 => 201852)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-06-09 05:09:42 UTC (rev 201851)
+++ trunk/Source/WebCore/ChangeLog        2016-06-09 05:18:38 UTC (rev 201852)
</span><span class="lines">@@ -1,3 +1,43 @@
</span><ins>+2016-06-08 Chris Dumez <cdumez@apple.com>
+
+ DedicatedWorkerGlobalScope prototype chain is incorrect
+ https://bugs.webkit.org/show_bug.cgi?id=158544
+
+ Reviewed by Brady Eidson.
+
+ 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.
+
+
</ins><span class="cx"> 2016-06-08 Adam Bergkvist <adam.bergkvist@ericsson.com>
</span><span class="cx">
</span><span class="cx"> WebRTC: Imlement MediaEndpointPeerConnection::setRemoteDescription()
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsWorkerScriptControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/WorkerScriptController.cpp (201851 => 201852)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/WorkerScriptController.cpp        2016-06-09 05:09:42 UTC (rev 201851)
+++ trunk/Source/WebCore/bindings/js/WorkerScriptController.cpp        2016-06-09 05:18:38 UTC (rev 201852)
</span><span class="lines">@@ -81,24 +81,19 @@
</span><span class="cx"> // Explicitly protect the global object's prototype so it isn't collected
</span><span class="cx"> // when we allocate the global object. (Once the global object is fully
</span><span class="cx"> // constructed, it can mark its own prototype.)
</span><del>- Structure* workerGlobalScopePrototypeStructure = JSWorkerGlobalScopePrototype::createStructure(*m_vm, 0, jsNull());
- Strong<JSWorkerGlobalScopePrototype> workerGlobalScopePrototype(*m_vm, JSWorkerGlobalScopePrototype::create(*m_vm, 0, workerGlobalScopePrototypeStructure));
-
</del><span class="cx"> if (m_workerGlobalScope->isDedicatedWorkerGlobalScope()) {
</span><del>- Structure* dedicatedContextPrototypeStructure = JSDedicatedWorkerGlobalScopePrototype::createStructure(*m_vm, 0, workerGlobalScopePrototype.get());
</del><ins>+ Structure* dedicatedContextPrototypeStructure = JSDedicatedWorkerGlobalScopePrototype::createStructure(*m_vm, 0, jsNull());
</ins><span class="cx"> Strong<JSDedicatedWorkerGlobalScopePrototype> dedicatedContextPrototype(*m_vm, JSDedicatedWorkerGlobalScopePrototype::create(*m_vm, 0, dedicatedContextPrototypeStructure));
</span><span class="cx"> Structure* structure = JSDedicatedWorkerGlobalScope::createStructure(*m_vm, 0, dedicatedContextPrototype.get());
</span><span class="cx"> auto* proxyStructure = JSProxy::createStructure(*m_vm, nullptr, jsNull(), PureForwardingProxyType);
</span><span class="cx"> auto* proxy = JSProxy::create(*m_vm, proxyStructure);
</span><span class="cx">
</span><span class="cx"> m_workerGlobalScopeWrapper.set(*m_vm, JSDedicatedWorkerGlobalScope::create(*m_vm, structure, static_cast<DedicatedWorkerGlobalScope&>(*m_workerGlobalScope), proxy));
</span><del>- workerGlobalScopePrototypeStructure->setGlobalObject(*m_vm, m_workerGlobalScopeWrapper.get());
</del><span class="cx"> dedicatedContextPrototypeStructure->setGlobalObject(*m_vm, m_workerGlobalScopeWrapper.get());
</span><span class="cx"> ASSERT(structure->globalObject() == m_workerGlobalScopeWrapper);
</span><span class="cx"> ASSERT(m_workerGlobalScopeWrapper->structure()->globalObject() == m_workerGlobalScopeWrapper);
</span><del>- workerGlobalScopePrototype->structure()->setGlobalObject(*m_vm, m_workerGlobalScopeWrapper.get());
- workerGlobalScopePrototype->structure()->setPrototypeWithoutTransition(*m_vm, JSEventTarget::prototype(*m_vm, m_workerGlobalScopeWrapper.get()));
</del><span class="cx"> dedicatedContextPrototype->structure()->setGlobalObject(*m_vm, m_workerGlobalScopeWrapper.get());
</span><ins>+ dedicatedContextPrototype->structure()->setPrototypeWithoutTransition(*m_vm, JSWorkerGlobalScope::prototype(*m_vm, m_workerGlobalScopeWrapper.get()));
</ins><span class="cx">
</span><span class="cx"> proxy->setTarget(*m_vm, m_workerGlobalScopeWrapper.get());
</span><span class="cx"> proxy->structure()->setGlobalObject(*m_vm, m_workerGlobalScopeWrapper.get());
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptsCodeGeneratorJSpm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (201851 => 201852)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm        2016-06-09 05:09:42 UTC (rev 201851)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm        2016-06-09 05:18:38 UTC (rev 201852)
</span><span class="lines">@@ -270,6 +270,16 @@
</span><span class="cx"> return $interface->name eq "DOMWindow" || $codeGenerator->InheritsInterface($interface, "WorkerGlobalScope") || $interface->name eq "TestGlobalObject";
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+sub ShouldUseGlobalObjectPrototype
+{
+ my $interface = shift;
+
+ # For workers, the global object is a DedicatedWorkerGlobalScope.
+ return 0 if $interface->name eq "WorkerGlobalScope";
+
+ return IsDOMGlobalObject($interface);
+}
+
</ins><span class="cx"> sub GenerateGetOwnPropertySlotBody
</span><span class="cx"> {
</span><span class="cx"> my ($interface, $className, $inlined) = @_;
</span><span class="lines">@@ -1146,7 +1156,7 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> # Prototype
</span><del>- unless (IsDOMGlobalObject($interface)) {
</del><ins>+ unless (ShouldUseGlobalObjectPrototype($interface)) {
</ins><span class="cx"> push(@headerContent, " static JSC::JSObject* createPrototype(JSC::VM&, JSC::JSGlobalObject*);\n");
</span><span class="cx"> push(@headerContent, " static JSC::JSObject* prototype(JSC::VM&, JSC::JSGlobalObject*);\n");
</span><span class="cx"> }
</span><span class="lines">@@ -2400,11 +2410,14 @@
</span><span class="cx"> push(@implContent, "#endif\n") if $conditionalString;
</span><span class="cx"> }
</span><span class="cx"> push(@implContent, "}\n\n");
</span><del>- } else {
</del><ins>+ }
+
+ unless (ShouldUseGlobalObjectPrototype($interface)) {
</ins><span class="cx"> push(@implContent, "JSObject* ${className}::createPrototype(VM& vm, JSGlobalObject* globalObject)\n");
</span><span class="cx"> push(@implContent, "{\n");
</span><del>- if ($hasParent && $parentClassName ne "JSC::DOMNodeFilter") {
- push(@implContent, " return ${className}Prototype::create(vm, globalObject, ${className}Prototype::createStructure(vm, globalObject, ${parentClassName}::prototype(vm, globalObject)));\n");
</del><ins>+ if ($interface->parent) {
+ my $parentClassNameForPrototype = "JS" . $interface->parent;
+ push(@implContent, " return ${className}Prototype::create(vm, globalObject, ${className}Prototype::createStructure(vm, globalObject, ${parentClassNameForPrototype}::prototype(vm, globalObject)));\n");
</ins><span class="cx"> } else {
</span><span class="cx"> my $prototype = $interface->isException ? "errorPrototype" : "objectPrototype";
</span><span class="cx"> push(@implContent, " return ${className}Prototype::create(vm, globalObject, ${className}Prototype::createStructure(vm, globalObject, globalObject->${prototype}()));\n");
</span><span class="lines">@@ -5182,7 +5195,7 @@
</span><span class="cx"> # There must exist an interface prototype object for every non-callback interface defined, regardless
</span><span class="cx"> # of whether the interface was declared with the [NoInterfaceObject] extended attribute.
</span><span class="cx"> # https://heycam.github.io/webidl/#interface-prototype-object
</span><del>- if (IsDOMGlobalObject($interface)) {
</del><ins>+ if (ShouldUseGlobalObjectPrototype($interface)) {
</ins><span class="cx"> push(@$outputArray, " putDirect(vm, vm.propertyNames->prototype, globalObject.getPrototypeDirect(), DontDelete | ReadOnly | DontEnum);\n");
</span><span class="cx"> } elsif ($interface->isCallback) {
</span><span class="cx"> push(@$outputArray, " UNUSED_PARAM(globalObject);\n");
</span></span></pre>
</div>
</div>
</body>
</html>