<!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>[225296] 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/225296">225296</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2017-11-29 14:19:23 -0800 (Wed, 29 Nov 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Start exposing self.registration inside service workers
https://bugs.webkit.org/show_bug.cgi?id=180162

Reviewed by Brady Eidson.

LayoutTests/imported/w3c:

* web-platform-tests/service-workers/service-worker/redirected-response.https-expected.txt:

Source/WebCore:

Start exposing self.registration inside service workers as per:
- https://w3c.github.io/ServiceWorker/#serviceworkerglobalscope-interface

This is very initial support:
- The operations on the registration (such as update) will reject the promise for now.
- The registration's service workers are not yet populated.

This will be implemented in a follow-up.

Tests: http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject.html
       http/tests/workers/service/self_registration.html

* bindings/js/JSServiceWorkerGlobalScopeCustom.cpp:
(WebCore::JSServiceWorkerGlobalScope::visitAdditionalChildren):
* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::addRegistration):
* workers/service/ServiceWorkerContextData.cpp:
(WebCore::ServiceWorkerContextData::isolatedCopy const):
* workers/service/ServiceWorkerContextData.h:
(WebCore::ServiceWorkerContextData::encode const):
(WebCore::ServiceWorkerContextData::decode):
* workers/service/ServiceWorkerGlobalScope.cpp:
(WebCore::ServiceWorkerGlobalScope::ServiceWorkerGlobalScope):
* workers/service/ServiceWorkerGlobalScope.h:
(WebCore::ServiceWorkerGlobalScope::registration):
* workers/service/server/SWServer.cpp:
(WebCore::SWServer::updateWorker):
(WebCore::SWServer::installContextData):
* workers/service/server/SWServer.h:
* workers/service/server/SWServerJobQueue.cpp:
(WebCore::SWServerJobQueue::scriptFetchFinished):

LayoutTests:

Add layout test coverage.

* TestExpectations:
Skip test that covers self.registration.update() because it now times out. We do not support update()
on registrations inside service workers yet so the test times out waiting for the updatefound event
on the registration.

* http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject-expected.txt: Added.
* http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject.html: Added.
* http/tests/workers/service/resources/ServiceWorkerGlobalScope_registration_SameObject-worker.js: Added.
* http/tests/workers/service/resources/self_registration-worker.js: Added.
* http/tests/workers/service/self_registration-expected.txt: Added.
* http/tests/workers/service/self_registration.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsTestExpectations">trunk/LayoutTests/TestExpectations</a></li>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerServiceWorkerGlobalScoperegistrationattributehttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/registration-attribute.https-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerServiceWorkerGlobalScopeunregisterhttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/unregister.https-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerServiceWorkerGlobalScopeupdatehttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/update.https-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkernavigationredirecthttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/navigation-redirect.https-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerredirectedresponsehttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/redirected-response.https-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerregisterforeignfetcherrorshttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/register-foreign-fetch-errors.https-expected.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSServiceWorkerGlobalScopeCustomcpp">trunk/Source/WebCore/bindings/js/JSServiceWorkerGlobalScopeCustom.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerContainercpp">trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerContextDatacpp">trunk/Source/WebCore/workers/service/ServiceWorkerContextData.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerContextDatah">trunk/Source/WebCore/workers/service/ServiceWorkerContextData.h</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerGlobalScopecpp">trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerGlobalScopeh">trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.h</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWServercpp">trunk/Source/WebCore/workers/service/server/SWServer.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWServerh">trunk/Source/WebCore/workers/service/server/SWServer.h</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWServerJobQueuecpp">trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestshttptestsworkersserviceServiceWorkerGlobalScope_registration_SameObjectexpectedtxt">trunk/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestsworkersserviceServiceWorkerGlobalScope_registration_SameObjecthtml">trunk/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject.html</a></li>
<li><a href="#trunkLayoutTestshttptestsworkersserviceresourcesServiceWorkerGlobalScope_registration_SameObjectworkerjs">trunk/LayoutTests/http/tests/workers/service/resources/ServiceWorkerGlobalScope_registration_SameObject-worker.js</a></li>
<li><a href="#trunkLayoutTestshttptestsworkersserviceresourcesself_registrationworkerjs">trunk/LayoutTests/http/tests/workers/service/resources/self_registration-worker.js</a></li>
<li><a href="#trunkLayoutTestshttptestsworkersserviceself_registrationexpectedtxt">trunk/LayoutTests/http/tests/workers/service/self_registration-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestsworkersserviceself_registrationhtml">trunk/LayoutTests/http/tests/workers/service/self_registration.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/LayoutTests/ChangeLog 2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2017-11-29  Chris Dumez  <cdumez@apple.com>
+
+        Start exposing self.registration inside service workers
+        https://bugs.webkit.org/show_bug.cgi?id=180162
+
+        Reviewed by Brady Eidson.
+
+        Add layout test coverage.
+
+        * TestExpectations:
+        Skip test that covers self.registration.update() because it now times out. We do not support update()
+        on registrations inside service workers yet so the test times out waiting for the updatefound event
+        on the registration.
+
+        * http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject-expected.txt: Added.
+        * http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject.html: Added.
+        * http/tests/workers/service/resources/ServiceWorkerGlobalScope_registration_SameObject-worker.js: Added.
+        * http/tests/workers/service/resources/self_registration-worker.js: Added.
+        * http/tests/workers/service/self_registration-expected.txt: Added.
+        * http/tests/workers/service/self_registration.html: Added.
+
</ins><span class="cx"> 2017-11-29  Javier M. Mellid  <jmunhoz@igalia.com>
</span><span class="cx"> 
</span><span class="cx">         [GTK] Test gardening
</span></span></pre></div>
<a id="trunkLayoutTestsTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/TestExpectations (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/TestExpectations       2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/LayoutTests/TestExpectations  2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -146,8 +146,8 @@
</span><span class="cx"> # Skip service worker tests that are timing out.
</span><span class="cx"> imported/w3c/web-platform-tests/fetch/api/abort/general-serviceworker.https.html [ Skip ]
</span><span class="cx"> imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/extendable-message-event.https.html [ Skip ]
</span><del>-imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/registration-attribute.https.html [ Skip ]
</del><span class="cx"> imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/unregister.https.html [ Skip ]
</span><ins>+imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/update.https.html [ Skip ]
</ins><span class="cx"> imported/w3c/web-platform-tests/service-workers/service-worker/clients-matchall-on-evaluation.https.html [ Skip ]
</span><span class="cx"> imported/w3c/web-platform-tests/service-workers/service-worker/detached-context.https.html [ Skip ]
</span><span class="cx"> imported/w3c/web-platform-tests/service-workers/service-worker/extendable-event-waituntil.https.html [ Skip ]
</span><span class="lines">@@ -168,6 +168,7 @@
</span><span class="cx"> imported/w3c/web-platform-tests/service-workers/service-worker/navigation-preload/get-state.https.html [ Skip ]
</span><span class="cx"> imported/w3c/web-platform-tests/service-workers/service-worker/navigation-preload/redirect.https.html [ Skip ]
</span><span class="cx"> imported/w3c/web-platform-tests/service-workers/service-worker/navigation-preload/request-headers.https.html [ Skip ]
</span><ins>+imported/w3c/web-platform-tests/service-workers/service-worker/navigation-redirect.https.html [ Skip ]
</ins><span class="cx"> imported/w3c/web-platform-tests/service-workers/service-worker/postmessage.https.html [ Skip ]
</span><span class="cx"> imported/w3c/web-platform-tests/service-workers/service-worker/postmessage-msgport-to-client.https.html [ Skip ]
</span><span class="cx"> imported/w3c/web-platform-tests/service-workers/service-worker/postmessage-to-client.https.html [ Skip ]
</span><span class="lines">@@ -194,7 +195,6 @@
</span><span class="cx"> imported/w3c/web-platform-tests/service-workers/service-worker/invalid-header.https.html [ Pass Failure ]
</span><span class="cx"> imported/w3c/web-platform-tests/service-workers/service-worker/multiple-update.https.html [ Pass Failure ]
</span><span class="cx"> imported/w3c/web-platform-tests/service-workers/service-worker/performance-timeline.https.html [ Pass Failure ]
</span><del>-imported/w3c/web-platform-tests/service-workers/service-worker/navigation-redirect.https.html [ Pass Failure ]
</del><span class="cx"> webkit.org/b/179452 imported/w3c/web-platform-tests/service-workers/service-worker/register-same-scope-different-script-url.https.html [ Pass Failure ]
</span><span class="cx"> webkit.org/b/179194 imported/w3c/web-platform-tests/service-workers/service-worker/registration-mime-types.https.html [ Pass Failure ]
</span><span class="cx"> imported/w3c/web-platform-tests/service-workers/service-worker/registration-script.https.html [ Pass Failure ]
</span></span></pre></div>
<a id="trunkLayoutTestshttptestsworkersserviceServiceWorkerGlobalScope_registration_SameObjectexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject-expected.txt (0 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject-expected.txt                               (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject-expected.txt  2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -0,0 +1,4 @@
</span><ins>+* Tests that self.registration always returns the same object
+
+PASS: returned object was the same
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsworkersserviceServiceWorkerGlobalScope_registration_SameObjecthtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject.html (0 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject.html                               (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject.html  2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -0,0 +1,19 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<body>
+<script src="resources/sw-test-pre.js"></script>
+<script>
+log("* Tests that self.registration always returns the same object");
+log("");
+
+navigator.serviceWorker.addEventListener("message", function(event) {
+    log(event.data);
+    finishSWTest();
+});
+
+navigator.serviceWorker.register("resources/ServiceWorkerGlobalScope_registration_SameObject-worker.js", { }).then(function(registration) {
+    registration.installing.postMessage("runTest");
+});
+</script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsworkersserviceresourcesServiceWorkerGlobalScope_registration_SameObjectworkerjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/workers/service/resources/ServiceWorkerGlobalScope_registration_SameObject-worker.js (0 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/workers/service/resources/ServiceWorkerGlobalScope_registration_SameObject-worker.js                                (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/resources/ServiceWorkerGlobalScope_registration_SameObject-worker.js   2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -0,0 +1,30 @@
</span><ins>+function gc() {
+    if (typeof GCController !== "undefined")
+        GCController.collect();
+    else {
+        var gcRec = function (n) {
+            if (n < 1)
+                return {};
+            var temp = {i: "ab" + i + (i / 100000)};
+            temp += "foo";
+            gcRec(n-1);
+        };
+        for (var i = 0; i < 1000; i++)
+            gcRec(10);
+    }
+}
+
+let client = null;
+
+self.addEventListener("message", (event) => {
+    client = event.source;
+    self.registration.foo = 1;
+    gc();
+    setTimeout(function() {
+        gc();
+        if (self.registration.foo === 1)
+            client.postMessage("PASS: returned object was the same");
+        else
+            client.postMessage("FAIL: returned object was not the same");
+    }, 0);
+});
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsworkersserviceresourcesself_registrationworkerjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/workers/service/resources/self_registration-worker.js (0 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/workers/service/resources/self_registration-worker.js                               (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/resources/self_registration-worker.js  2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -0,0 +1,26 @@
</span><ins>+let results = [];
+
+function log(msg)
+{
+    results.push(msg);
+}
+
+function dumpRegistration()
+{
+    log("* self.registration");
+    log("scope: " + self.registration.scope);
+    log("updateViaCache: " + self.registration.updateViaCache);
+    log("");
+}
+
+self.addEventListener("install", function() {
+    log("Received install event");
+    dumpRegistration();
+});
+
+self.addEventListener("message", (event) => {
+    for (let result of results)
+        event.source.postMessage(result);
+    event.source.postMessage("DONE");
+});
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsworkersserviceself_registrationexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/workers/service/self_registration-expected.txt (0 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/workers/service/self_registration-expected.txt                              (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/self_registration-expected.txt 2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -0,0 +1,8 @@
</span><ins>+* Add basic testing for ServiceWorkerGlobalScope.registration
+
+Received install event
+* self.registration
+scope: http://127.0.0.1:8000/workers/service/
+updateViaCache: imports
+
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsworkersserviceself_registrationhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/workers/service/self_registration.html (0 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/workers/service/self_registration.html                              (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/self_registration.html 2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -0,0 +1,25 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<body>
+<script src="resources/sw-test-pre.js"></script>
+<script>
+log("* Add basic testing for ServiceWorkerGlobalScope.registration");
+log("");
+
+navigator.serviceWorker.addEventListener("message", function(event) {
+    if (event.data === "DONE") {
+        finishSWTest();
+        return;
+    }
+    log(event.data);
+});
+
+navigator.serviceWorker.register("resources/self_registration-worker.js", { }).then(function(registration) {
+    worker = registration.installing;
+    waitForState(worker, "activated").then(function() {
+        worker.postMessage("DUMP_RESULTS");
+    });
+});
+</script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/ChangeLog 2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/LayoutTests/imported/w3c/ChangeLog    2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -1,3 +1,12 @@
</span><ins>+2017-11-29  Chris Dumez  <cdumez@apple.com>
+
+        Start exposing self.registration inside service workers
+        https://bugs.webkit.org/show_bug.cgi?id=180162
+
+        Reviewed by Brady Eidson.
+
+        * web-platform-tests/service-workers/service-worker/redirected-response.https-expected.txt:
+
</ins><span class="cx"> 2017-11-29  Youenn Fablet  <youenn@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Add support for FetchEvent.clientId
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerServiceWorkerGlobalScoperegistrationattributehttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/registration-attribute.https-expected.txt (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/registration-attribute.https-expected.txt      2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/registration-attribute.https-expected.txt 2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -1,6 +1,5 @@
</span><span class="cx"> 
</span><del>-Harness Error (TIMEOUT), message = null
</del><span class="cx"> 
</span><del>-FAIL Verify registration attributes on ServiceWorkerGlobalScope assert_unreached: unregister and register should not fail: TypeError: null is not an object (evaluating 'self.registration.scope') Reached unreachable code
-FAIL Verify registration attributes on ServiceWorkerGlobalScope of the newer worker assert_unreached: unregister and register should not fail: TypeError: null is not an object (evaluating 'self.registration.scope') Reached unreachable code
</del><ins>+FAIL Verify registration attributes on ServiceWorkerGlobalScope assert_equals: Service Worker should respond to fetch expected "updatefound,install,statechange(installed),statechange(activating),activate,statechange(activated),fetch" but got "{\"error\": {\"message\": \"\", \"code\": 404}}"
+FAIL Verify registration attributes on ServiceWorkerGlobalScope of the newer worker promise_test: Unhandled rejection with value: object "Error: wait_for_state must be passed a ServiceWorker"
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerServiceWorkerGlobalScopeunregisterhttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/unregister.https-expected.txt (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/unregister.https-expected.txt  2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/unregister.https-expected.txt     2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -1,8 +1,8 @@
</span><span class="cx"> 
</span><span class="cx"> Harness Error (TIMEOUT), message = null
</span><span class="cx"> 
</span><del>-FAIL Unregister on script evaluation assert_unreached: unregister and register should not fail: TypeError: null is not an object (evaluating 'self.registration.unregister') Reached unreachable code
-TIMEOUT Unregister on installing event Test timed out
</del><ins>+TIMEOUT Unregister on script evaluation Test timed out
+NOTRUN Unregister on installing event 
</ins><span class="cx"> NOTRUN Unregister on activate event 
</span><span class="cx"> NOTRUN Unregister controlling service worker 
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerServiceWorkerGlobalScopeupdatehttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/update.https-expected.txt (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/update.https-expected.txt      2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/update.https-expected.txt 2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -1,3 +1,6 @@
</span><span class="cx"> 
</span><del>-FAIL Update a registration on ServiceWorkerGlobalScope assert_unreached: unregister and register should not fail: TypeError: null is not an object (evaluating 'self.registration.addEventListener') Reached unreachable code
</del><span class="cx"> 
</span><ins>+Harness Error (TIMEOUT), message = null
+
+TIMEOUT Update a registration on ServiceWorkerGlobalScope Test timed out
+
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkernavigationredirecthttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/navigation-redirect.https-expected.txt (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/navigation-redirect.https-expected.txt  2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/navigation-redirect.https-expected.txt     2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -1,34 +1,34 @@
</span><del>-CONSOLE MESSAGE: Unhandled Promise Rejection: TypeError: TypeError: null is not an object (evaluating 'self.registration.scope')
-CONSOLE MESSAGE: line 50: Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'registrations[0].unregister')
</del><ins>+  
</ins><span class="cx"> 
</span><ins>+Harness Error (TIMEOUT), message = null
</ins><span class="cx"> 
</span><del>-FAIL Normal redirect to same-origin scope. assert_unreached: unregister and register should not fail: TypeError: null is not an object (evaluating 'self.registration.scope') Reached unreachable code
-FAIL Normal redirect to other-origin scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fallbacked redirect to same-origin out-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fallbacked redirect to same-origin same-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fallbacked redirect to same-origin other-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fallbacked redirect to other-origin out-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fallbacked redirect to other-origin in-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-generated redirect to same-origin out-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-generated redirect to same-origin same-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-generated redirect to same-origin other-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-generated redirect to other-origin out-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-generated redirect to other-origin in-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fetched redirect to same-origin out-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fetched redirect to same-origin same-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fetched redirect to same-origin other-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fetched redirect to other-origin out-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL SW-fetched redirect to other-origin in-scope. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to same-origin out-scope with opaque redirect response. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to same-origin same-scope with opaque redirect response. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to same-origin other-scope with opaque redirect response. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to other-origin out-scope with opaque redirect response. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to other-origin in-scope with opaque redirect response. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL No location redirect response. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to same-origin out-scope with opaque redirect response which is passed through Cache. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to same-origin same-scope with opaque redirect response which is passed through Cache. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to same-origin other-scope with opaque redirect response which is passed through Cache. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to other-origin out-scope with opaque redirect response which is passed through Cache. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL Redirect to other-origin in-scope with opaque redirect response which is passed through Cache. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
-FAIL No location redirect response via Cache. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.active')"
</del><ins>+FAIL Normal redirect to same-origin scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL Normal redirect to other-origin scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL SW-fallbacked redirect to same-origin out-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL SW-fallbacked redirect to same-origin same-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL SW-fallbacked redirect to same-origin other-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL SW-fallbacked redirect to other-origin out-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL SW-fallbacked redirect to other-origin in-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+TIMEOUT SW-generated redirect to same-origin out-scope. Test timed out
+NOTRUN SW-generated redirect to same-origin same-scope. 
+NOTRUN SW-generated redirect to same-origin other-scope. 
+NOTRUN SW-generated redirect to other-origin out-scope. 
+NOTRUN SW-generated redirect to other-origin in-scope. 
+NOTRUN SW-fetched redirect to same-origin out-scope. 
+NOTRUN SW-fetched redirect to same-origin same-scope. 
+NOTRUN SW-fetched redirect to same-origin other-scope. 
+NOTRUN SW-fetched redirect to other-origin out-scope. 
+NOTRUN SW-fetched redirect to other-origin in-scope. 
+NOTRUN Redirect to same-origin out-scope with opaque redirect response. 
+NOTRUN Redirect to same-origin same-scope with opaque redirect response. 
+NOTRUN Redirect to same-origin other-scope with opaque redirect response. 
+NOTRUN Redirect to other-origin out-scope with opaque redirect response. 
+NOTRUN Redirect to other-origin in-scope with opaque redirect response. 
+NOTRUN No location redirect response. 
+NOTRUN Redirect to same-origin out-scope with opaque redirect response which is passed through Cache. 
+NOTRUN Redirect to same-origin same-scope with opaque redirect response which is passed through Cache. 
+NOTRUN Redirect to same-origin other-scope with opaque redirect response which is passed through Cache. 
+NOTRUN Redirect to other-origin out-scope with opaque redirect response which is passed through Cache. 
+NOTRUN Redirect to other-origin in-scope with opaque redirect response which is passed through Cache. 
+NOTRUN No location redirect response via Cache. 
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerredirectedresponsehttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/redirected-response.https-expected.txt (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/redirected-response.https-expected.txt  2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/redirected-response.https-expected.txt     2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -1,20 +1,21 @@
</span><span class="cx"> 
</span><del>-FAIL initialize global state (service worker registration and caches) assert_unreached: unregister and register should not fail: TypeError: null is not an object (evaluating 'self.registration.scope') Reached unreachable code
-FAIL mode: "follow", non-intercepted request, no server redirect promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "follow", non-intercepted request promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "manual", non-intercepted request promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "error", non-intercepted request promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "follow", no mode change, no server redirect promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "follow", no mode change promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "error", mode change: "follow" promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "manual", mode change: "follow" promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "follow", mode change: "manual" promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "error", mode change: "manual" promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "manual", no mode change promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "follow", generated redirect response promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "error", generated redirect response promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL mode: "manual", generated redirect response promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL Fetch should follow the redirect response 20 times promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL Fetch should not follow the redirect response 21 times. promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'registration.installing')"
-FAIL restore global state (service worker registration) undefined is not an object (evaluating 'registration.unregister')
</del><ins>+FAIL initialize global state (service worker registration and caches) promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "follow", non-intercepted request, no server redirect promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "follow", non-intercepted request promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "manual", non-intercepted request promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "error", non-intercepted request promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "follow", no mode change, no server redirect promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "follow", no mode change promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "error", mode change: "follow" promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "manual", mode change: "follow" promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "follow", mode change: "manual" promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "error", mode change: "manual" promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "manual", no mode change promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "follow", generated redirect response promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "error", generated redirect response promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL mode: "manual", generated redirect response promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL Fetch should follow the redirect response 20 times promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL Fetch should not follow the redirect response 21 times. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+PASS restore global state (service worker registration) 
+PASS restore global state (caches) 
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerregisterforeignfetcherrorshttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/register-foreign-fetch-errors.https-expected.txt (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/register-foreign-fetch-errors.https-expected.txt        2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/register-foreign-fetch-errors.https-expected.txt   2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -1,4 +1,26 @@
</span><span class="cx"> 
</span><span class="cx"> PASS foreign fetch registration 
</span><del>-FAIL Untitled TypeError: null is not an object (evaluating 'registration.scope')
</del><ins>+PASS Invalid options 
+PASS Scopes not an array 
+PASS Scopes not a string in array 
+PASS Relative url not under scope 
+PASS Absolute url not under scope 
+PASS Empty scope array 
+FAIL Call after event returned assert_throws: function "function () {
+                event.registerForeignFetch({scopes: [scope], origins: ['*']});
+              }" threw object "TypeError: event.registerForeignFetch is not a function. (In 'event.registerForeignFetch({scopes: [scope], origins: ['*']})', 'event.registerForeignFetch' is undefined)" that is not a DOMException InvalidStateError: property "code" is equal to undefined, expected 11
+FAIL Valid scopes with wildcard origin string event.registerForeignFetch is not a function. (In 'event.registerForeignFetch({scopes: [scope], origins: ['*']})', 'event.registerForeignFetch' is undefined)
+FAIL Absolute urls event.registerForeignFetch is not a function. (In 'event.registerForeignFetch({scopes: [scope, scope + '/foo'], origins: ['*']})', 'event.registerForeignFetch' is undefined)
+FAIL Relative urls undefined is not a function (near '...event.registerForeignFetch...')
+PASS No origins specified 
+PASS Origins not a string or array 
+PASS Origins contains something not a string 
+PASS Origin not an absolute URL 
+FAIL Wildcard origin string in array event.registerForeignFetch is not a function. (In 'event.registerForeignFetch({scopes: [scope], origins: ['*']})', 'event.registerForeignFetch' is undefined)
+PASS Origin string 
+FAIL Origin string in array event.registerForeignFetch is not a function. (In 'event.registerForeignFetch({scopes: [scope], origins: ['https://example.com/']})', 'event.registerForeignFetch' is undefined)
+FAIL Array with multiple origins event.registerForeignFetch is not a function. (In 'event.registerForeignFetch({
+            scopes: [scope], origins: ['https://example.com/', 'https://chromium.org']})', 'event.registerForeignFetch' is undefined)
+PASS Origins includes wildcard and other strings 
+PASS Origins includes other strings and wildcard 
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/ChangeLog      2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -1,3 +1,42 @@
</span><ins>+2017-11-29  Chris Dumez  <cdumez@apple.com>
+
+        Start exposing self.registration inside service workers
+        https://bugs.webkit.org/show_bug.cgi?id=180162
+
+        Reviewed by Brady Eidson.
+
+        Start exposing self.registration inside service workers as per:
+        - https://w3c.github.io/ServiceWorker/#serviceworkerglobalscope-interface
+
+        This is very initial support:
+        - The operations on the registration (such as update) will reject the promise for now.
+        - The registration's service workers are not yet populated.
+
+        This will be implemented in a follow-up.
+
+        Tests: http/tests/workers/service/ServiceWorkerGlobalScope_registration_SameObject.html
+               http/tests/workers/service/self_registration.html
+
+        * bindings/js/JSServiceWorkerGlobalScopeCustom.cpp:
+        (WebCore::JSServiceWorkerGlobalScope::visitAdditionalChildren):
+        * workers/service/ServiceWorkerContainer.cpp:
+        (WebCore::ServiceWorkerContainer::addRegistration):
+        * workers/service/ServiceWorkerContextData.cpp:
+        (WebCore::ServiceWorkerContextData::isolatedCopy const):
+        * workers/service/ServiceWorkerContextData.h:
+        (WebCore::ServiceWorkerContextData::encode const):
+        (WebCore::ServiceWorkerContextData::decode):
+        * workers/service/ServiceWorkerGlobalScope.cpp:
+        (WebCore::ServiceWorkerGlobalScope::ServiceWorkerGlobalScope):
+        * workers/service/ServiceWorkerGlobalScope.h:
+        (WebCore::ServiceWorkerGlobalScope::registration):
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::updateWorker):
+        (WebCore::SWServer::installContextData):
+        * workers/service/server/SWServer.h:
+        * workers/service/server/SWServerJobQueue.cpp:
+        (WebCore::SWServerJobQueue::scriptFetchFinished):
+
</ins><span class="cx"> 2017-11-29  Youenn Fablet  <youenn@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Add support for FetchEvent.clientId
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSServiceWorkerGlobalScopeCustomcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSServiceWorkerGlobalScopeCustom.cpp (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSServiceWorkerGlobalScopeCustom.cpp    2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/bindings/js/JSServiceWorkerGlobalScopeCustom.cpp       2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -37,7 +37,7 @@
</span><span class="cx"> void JSServiceWorkerGlobalScope::visitAdditionalChildren(SlotVisitor& visitor)
</span><span class="cx"> {
</span><span class="cx">     visitor.addOpaqueRoot(&wrapped().clients());
</span><del>-    visitor.addOpaqueRoot(wrapped().registration());
</del><ins>+    visitor.addOpaqueRoot(&wrapped().registration());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerContainercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp  2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp     2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -422,7 +422,7 @@
</span><span class="cx"> 
</span><span class="cx"> void ServiceWorkerContainer::addRegistration(ServiceWorkerRegistration& registration)
</span><span class="cx"> {
</span><del>-    m_swConnection->addServiceWorkerRegistrationInServer(registration.identifier());
</del><ins>+    ensureSWClientConnection().addServiceWorkerRegistrationInServer(registration.identifier());
</ins><span class="cx">     m_registrations.add(registration.identifier(), &registration);
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerContextDatacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContextData.cpp (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerContextData.cpp        2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContextData.cpp   2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -32,7 +32,7 @@
</span><span class="cx"> 
</span><span class="cx"> ServiceWorkerContextData ServiceWorkerContextData::isolatedCopy() const
</span><span class="cx"> {
</span><del>-    return { jobDataIdentifier, registrationKey.isolatedCopy(), serviceWorkerIdentifier, script.isolatedCopy(), scriptURL.isolatedCopy(), workerType };
</del><ins>+    return { jobDataIdentifier, registration.isolatedCopy(), serviceWorkerIdentifier, script.isolatedCopy(), scriptURL.isolatedCopy(), workerType };
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerContextDatah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContextData.h (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerContextData.h  2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContextData.h     2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -27,7 +27,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include "ServiceWorkerIdentifier.h"
</span><span class="cx"> #include "ServiceWorkerJobDataIdentifier.h"
</span><del>-#include "ServiceWorkerRegistrationKey.h"
</del><ins>+#include "ServiceWorkerRegistrationData.h"
</ins><span class="cx"> #include "URL.h"
</span><span class="cx"> #include "WorkerType.h"
</span><span class="cx"> 
</span><span class="lines">@@ -37,7 +37,7 @@
</span><span class="cx"> 
</span><span class="cx"> struct ServiceWorkerContextData {
</span><span class="cx">     ServiceWorkerJobDataIdentifier jobDataIdentifier;
</span><del>-    ServiceWorkerRegistrationKey registrationKey;
</del><ins>+    ServiceWorkerRegistrationData registration;
</ins><span class="cx">     ServiceWorkerIdentifier serviceWorkerIdentifier;
</span><span class="cx">     String script;
</span><span class="cx">     URL scriptURL;
</span><span class="lines">@@ -52,7 +52,7 @@
</span><span class="cx"> template<class Encoder>
</span><span class="cx"> void ServiceWorkerContextData::encode(Encoder& encoder) const
</span><span class="cx"> {
</span><del>-    encoder << jobDataIdentifier << registrationKey << serviceWorkerIdentifier << script << scriptURL << workerType;
</del><ins>+    encoder << jobDataIdentifier << registration << serviceWorkerIdentifier << script << scriptURL << workerType;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template<class Decoder>
</span><span class="lines">@@ -63,8 +63,9 @@
</span><span class="cx">     if (!jobDataIdentifier)
</span><span class="cx">         return std::nullopt;
</span><span class="cx"> 
</span><del>-    auto registrationKey = ServiceWorkerRegistrationKey::decode(decoder);
-    if (!registrationKey)
</del><ins>+    std::optional<ServiceWorkerRegistrationData> registration;
+    decoder >> registration;
+    if (!registration)
</ins><span class="cx">         return std::nullopt;
</span><span class="cx"> 
</span><span class="cx">     auto serviceWorkerIdentifier = ServiceWorkerIdentifier::decode(decoder);
</span><span class="lines">@@ -83,7 +84,7 @@
</span><span class="cx">     if (!decoder.decodeEnum(workerType))
</span><span class="cx">         return std::nullopt;
</span><span class="cx">     
</span><del>-    return {{ WTFMove(*jobDataIdentifier), WTFMove(*registrationKey), WTFMove(*serviceWorkerIdentifier), WTFMove(script), WTFMove(scriptURL), workerType }};
</del><ins>+    return {{ WTFMove(*jobDataIdentifier), WTFMove(*registration), WTFMove(*serviceWorkerIdentifier), WTFMove(script), WTFMove(scriptURL), workerType }};
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerGlobalScopecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp        2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp   2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include "ServiceWorkerClients.h"
</span><span class="cx"> #include "ServiceWorkerThread.h"
</span><ins>+#include "WorkerNavigator.h"
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -36,6 +37,7 @@
</span><span class="cx"> ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(const ServiceWorkerContextData& data, const URL& url, const String& identifier, const String& userAgent, bool isOnline, ServiceWorkerThread& thread, bool shouldBypassMainWorldContentSecurityPolicy, Ref<SecurityOrigin>&& topOrigin, MonotonicTime timeOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider, PAL::SessionID sessionID)
</span><span class="cx">     : WorkerGlobalScope(url, identifier, userAgent, isOnline, thread, shouldBypassMainWorldContentSecurityPolicy, WTFMove(topOrigin), timeOrigin, connectionProxy, socketProvider, sessionID)
</span><span class="cx">     , m_contextData(crossThreadCopy(data))
</span><ins>+    , m_registration(ServiceWorkerRegistration::getOrCreate(*this, navigator().serviceWorker(), WTFMove(m_contextData.registration)))
</ins><span class="cx">     , m_clients(ServiceWorkerClients::create(*this))
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="lines">@@ -42,12 +44,6 @@
</span><span class="cx"> 
</span><span class="cx"> ServiceWorkerGlobalScope::~ServiceWorkerGlobalScope() = default;
</span><span class="cx"> 
</span><del>-ServiceWorkerRegistration* ServiceWorkerGlobalScope::registration()
-{
-    // FIXME: implement this.
-    return nullptr;
-}
-
</del><span class="cx"> void ServiceWorkerGlobalScope::skipWaiting(Ref<DeferredPromise>&&)
</span><span class="cx"> {
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerGlobalScopeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.h (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.h  2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.h     2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -49,7 +49,7 @@
</span><span class="cx">     bool isServiceWorkerGlobalScope() const final { return true; }
</span><span class="cx"> 
</span><span class="cx">     ServiceWorkerClients& clients() { return m_clients.get(); }
</span><del>-    ServiceWorkerRegistration* registration();
</del><ins>+    ServiceWorkerRegistration& registration() { return m_registration.get(); }
</ins><span class="cx">     
</span><span class="cx">     void skipWaiting(Ref<DeferredPromise>&&);
</span><span class="cx"> 
</span><span class="lines">@@ -61,6 +61,7 @@
</span><span class="cx">     ServiceWorkerGlobalScope(const ServiceWorkerContextData&, const URL&, const String& identifier, const String& userAgent, bool isOnline, ServiceWorkerThread&, bool shouldBypassMainWorldContentSecurityPolicy, Ref<SecurityOrigin>&& topOrigin, MonotonicTime timeOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*, PAL::SessionID);
</span><span class="cx"> 
</span><span class="cx">     ServiceWorkerContextData m_contextData;
</span><ins>+    Ref<ServiceWorkerRegistration> m_registration;
</ins><span class="cx">     Ref<ServiceWorkerClients> m_clients;
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServer.cpp 2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp    2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -344,11 +344,11 @@
</span><span class="cx">     registration->removeClientUsingRegistration({ connection.identifier(), contextIdentifier });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void SWServer::updateWorker(Connection&, const ServiceWorkerJobDataIdentifier& jobDataIdentifier, const ServiceWorkerRegistrationKey& registrationKey, const URL& url, const String& script, WorkerType type)
</del><ins>+void SWServer::updateWorker(Connection&, const ServiceWorkerJobDataIdentifier& jobDataIdentifier, SWServerRegistration& registration, const URL& url, const String& script, WorkerType type)
</ins><span class="cx"> {
</span><span class="cx">     auto serviceWorkerIdentifier = generateServiceWorkerIdentifier();
</span><span class="cx"> 
</span><del>-    ServiceWorkerContextData data = { jobDataIdentifier, registrationKey, serviceWorkerIdentifier, script, url, type };
</del><ins>+    ServiceWorkerContextData data = { jobDataIdentifier, registration.data(), serviceWorkerIdentifier, script, url, type };
</ins><span class="cx"> 
</span><span class="cx">     // Right now we only ever keep up to one connection to one SW context process.
</span><span class="cx">     // And it should always exist if we're calling updateWorker
</span><span class="lines">@@ -375,7 +375,7 @@
</span><span class="cx">     auto* connection = SWServerToContextConnection::globalServerToContextConnection();
</span><span class="cx">     ASSERT(connection);
</span><span class="cx"> 
</span><del>-    auto* registration = m_registrations.get(data.registrationKey);
</del><ins>+    auto* registration = m_registrations.get(data.registration.key);
</ins><span class="cx">     RELEASE_ASSERT(registration);
</span><span class="cx"> 
</span><span class="cx">     auto result = m_workersByID.add(data.serviceWorkerIdentifier, SWServerWorker::create(*this, *registration, connection->identifier(), data.scriptURL, data.script, data.workerType, data.serviceWorkerIdentifier));
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServer.h (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServer.h   2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h      2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -121,7 +121,7 @@
</span><span class="cx">     void postTask(CrossThreadTask&&);
</span><span class="cx">     void postTaskReply(CrossThreadTask&&);
</span><span class="cx"> 
</span><del>-    void updateWorker(Connection&, const ServiceWorkerJobDataIdentifier&, const ServiceWorkerRegistrationKey&, const URL&, const String& script, WorkerType);
</del><ins>+    void updateWorker(Connection&, const ServiceWorkerJobDataIdentifier&, SWServerRegistration&, const URL&, const String& script, WorkerType);
</ins><span class="cx">     void terminateWorker(SWServerWorker&);
</span><span class="cx">     void fireInstallEvent(SWServerWorker&);
</span><span class="cx">     void fireActivateEvent(SWServerWorker&);
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServerJobQueuecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp (225295 => 225296)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp 2017-11-29 21:53:28 UTC (rev 225295)
+++ trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp    2017-11-29 22:19:23 UTC (rev 225296)
</span><span class="lines">@@ -87,7 +87,7 @@
</span><span class="cx">     // - Invoke Finish Job with job and abort these steps.
</span><span class="cx"> 
</span><span class="cx">     // FIXME: Support the proper worker type (classic vs module)
</span><del>-    m_server.updateWorker(connection, job.identifier(), m_registrationKey, job.scriptURL, result.script, WorkerType::Classic);
</del><ins>+    m_server.updateWorker(connection, job.identifier(), *registration, job.scriptURL, result.script, WorkerType::Classic);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // https://w3c.github.io/ServiceWorker/#update-algorithm
</span></span></pre>
</div>
</div>

</body>
</html>