ServiceWorkerGlobalScope.clients should always return the same object
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Nov 2017 01:33:29 +0000 (01:33 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Nov 2017 01:33:29 +0000 (01:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180116

Reviewed by Geoffrey Garen.

Source/WebCore:

ServiceWorkerGlobalScope.clients should always return the same object, as per the specification:
- https://w3c.github.io/ServiceWorker/#serviceworkerglobalscope-interface

Test: http/tests/workers/service/ServiceWorkerGlobalScope_clients_SameObject.html

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSServiceWorkerGlobalScopeCustom.cpp: Added.
(WebCore::JSServiceWorkerGlobalScope::visitAdditionalChildren):
* workers/service/ServiceWorkerClients.idl:
* workers/service/ServiceWorkerGlobalScope.idl:

LayoutTests:

Add layout test coverage.

* http/tests/workers/service/ServiceWorkerGlobalScope_clients_SameObject-expected.txt: Added.
* http/tests/workers/service/ServiceWorkerGlobalScope_clients_SameObject.html: Added.
* http/tests/workers/service/resources/ServiceWorkerGlobalScope_clients_SameObject-worker.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225249 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_clients_SameObject-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_clients_SameObject.html [new file with mode: 0644]
LayoutTests/http/tests/workers/service/resources/ServiceWorkerGlobalScope_clients_SameObject-worker.js [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSServiceWorkerGlobalScopeCustom.cpp [new file with mode: 0644]
Source/WebCore/workers/service/ServiceWorkerClients.idl
Source/WebCore/workers/service/ServiceWorkerGlobalScope.idl
Source/WebCore/workers/service/ServiceWorkerRegistration.idl

index 838b35b..719004d 100644 (file)
@@ -1,3 +1,16 @@
+2017-11-28  Chris Dumez  <cdumez@apple.com>
+
+        ServiceWorkerGlobalScope.clients should always return the same object
+        https://bugs.webkit.org/show_bug.cgi?id=180116
+
+        Reviewed by Geoffrey Garen.
+
+        Add layout test coverage.
+
+        * http/tests/workers/service/ServiceWorkerGlobalScope_clients_SameObject-expected.txt: Added.
+        * http/tests/workers/service/ServiceWorkerGlobalScope_clients_SameObject.html: Added.
+        * http/tests/workers/service/resources/ServiceWorkerGlobalScope_clients_SameObject-worker.js: Added.
+
 2017-11-28  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, correct the location for an expected result file.
diff --git a/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_clients_SameObject-expected.txt b/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_clients_SameObject-expected.txt
new file mode 100644 (file)
index 0000000..c9fef80
--- /dev/null
@@ -0,0 +1,4 @@
+* Tests that self.clients always returns the same object
+
+PASS: returned object was the same
+
diff --git a/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_clients_SameObject.html b/LayoutTests/http/tests/workers/service/ServiceWorkerGlobalScope_clients_SameObject.html
new file mode 100644 (file)
index 0000000..77cab07
--- /dev/null
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="resources/sw-test-pre.js"></script>
+<script>
+log("* Tests that self.clients always returns the same object");
+log("");
+
+navigator.serviceWorker.addEventListener("message", function(event) {
+    log(event.data);
+    finishSWTest();
+});
+
+navigator.serviceWorker.register("resources/ServiceWorkerGlobalScope_clients_SameObject-worker.js", { }).then(function(registration) {
+    registration.installing.postMessage("runTest");
+});
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/workers/service/resources/ServiceWorkerGlobalScope_clients_SameObject-worker.js b/LayoutTests/http/tests/workers/service/resources/ServiceWorkerGlobalScope_clients_SameObject-worker.js
new file mode 100644 (file)
index 0000000..a1889f9
--- /dev/null
@@ -0,0 +1,30 @@
+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.clients.foo = 1;
+    gc();
+    setTimeout(function() {
+        gc();
+        if (self.clients.foo === 1)
+            client.postMessage("PASS: returned object was the same");
+        else
+            client.postMessage("FAIL: returned object was not the same");
+    }, 0);
+});
index 0c6483f..ca39e6a 100644 (file)
@@ -1,5 +1,24 @@
 2017-11-28  Chris Dumez  <cdumez@apple.com>
 
+        ServiceWorkerGlobalScope.clients should always return the same object
+        https://bugs.webkit.org/show_bug.cgi?id=180116
+
+        Reviewed by Geoffrey Garen.
+
+        ServiceWorkerGlobalScope.clients should always return the same object, as per the specification:
+        - https://w3c.github.io/ServiceWorker/#serviceworkerglobalscope-interface
+
+        Test: http/tests/workers/service/ServiceWorkerGlobalScope_clients_SameObject.html
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSServiceWorkerGlobalScopeCustom.cpp: Added.
+        (WebCore::JSServiceWorkerGlobalScope::visitAdditionalChildren):
+        * workers/service/ServiceWorkerClients.idl:
+        * workers/service/ServiceWorkerGlobalScope.idl:
+
+2017-11-28  Chris Dumez  <cdumez@apple.com>
+
         Get rid of ServiceWorker::allWorkers() hashmap
         https://bugs.webkit.org/show_bug.cgi?id=180111
 
index 1bdd782..433b808 100644 (file)
@@ -404,6 +404,7 @@ bindings/js/JSReadableStreamSourceCustom.cpp
 bindings/js/JSSVGPathSegCustom.cpp
 bindings/js/JSStyleSheetCustom.cpp
 bindings/js/JSServiceWorkerClientCustom.cpp
+bindings/js/JSServiceWorkerGlobalScopeCustom.cpp
 bindings/js/JSTextCustom.cpp
 bindings/js/JSTextTrackCueCustom.cpp
 bindings/js/JSTextTrackCustom.cpp
index 942c670..018ac8f 100644 (file)
                460BB6141D0A1BEC00221812 /* Base64Utilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Base64Utilities.h; sourceTree = "<group>"; };
                460CBF331D4BCCFE0092E88E /* JSDOMWindowProperties.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMWindowProperties.cpp; sourceTree = "<group>"; };
                460CBF341D4BCCFE0092E88E /* JSDOMWindowProperties.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMWindowProperties.h; sourceTree = "<group>"; };
+               460D19441FCE21DD00C3DB85 /* JSServiceWorkerGlobalScopeCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSServiceWorkerGlobalScopeCustom.cpp; sourceTree = "<group>"; };
                4634592B1AC2271000ECB71C /* PowerObserverMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PowerObserverMac.cpp; sourceTree = "<group>"; };
                463EB6201B8789CB0096ED51 /* TagCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TagCollection.cpp; sourceTree = "<group>"; };
                463EB6211B8789CB0096ED51 /* TagCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TagCollection.h; sourceTree = "<group>"; };
                                AD20B18C18E9D216005A8083 /* JSNodeListCustom.h */,
                                CB38FD551CD21D5B00592A3F /* JSPerformanceEntryCustom.cpp */,
                                83F572941FA1066F003837BE /* JSServiceWorkerClientCustom.cpp */,
+                               460D19441FCE21DD00C3DB85 /* JSServiceWorkerGlobalScopeCustom.cpp */,
                                BC98A27C0C0C9950004BEBF7 /* JSStyleSheetCustom.cpp */,
                                AD726FEC16D9F4B9003A4E6D /* JSStyleSheetCustom.h */,
                                B2C96D8C0B3AF2B7005E80EC /* JSSVGPathSegCustom.cpp */,
diff --git a/Source/WebCore/bindings/js/JSServiceWorkerGlobalScopeCustom.cpp b/Source/WebCore/bindings/js/JSServiceWorkerGlobalScopeCustom.cpp
new file mode 100644 (file)
index 0000000..d529e4a
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(SERVICE_WORKER)
+#include "JSServiceWorkerGlobalScope.h"
+
+#include "ServiceWorkerGlobalScope.h"
+
+namespace WebCore {
+
+using namespace JSC;
+
+void JSServiceWorkerGlobalScope::visitAdditionalChildren(SlotVisitor& visitor)
+{
+    visitor.addOpaqueRoot(&wrapped().clients());
+    visitor.addOpaqueRoot(wrapped().registration());
+}
+
+} // namespace WebCore
+
+#endif
index 7d4c570..65293a0 100644 (file)
@@ -27,6 +27,7 @@
     Conditional=SERVICE_WORKER,
     EnabledAtRuntime=ServiceWorker,
     Exposed=ServiceWorker,
+    GenerateIsReachable=Impl,
     InterfaceName=Clients,
 ] interface ServiceWorkerClients {
     // The objects returned will be new instances every time
index b0b0cc8..437f6b6 100644 (file)
@@ -29,6 +29,7 @@
     Exposed=ServiceWorker,
     Conditional=SERVICE_WORKER,
     EnabledAtRuntime=ServiceWorker,
+    JSCustomMarkFunction,
 ] interface ServiceWorkerGlobalScope : WorkerGlobalScope {
     [SameObject] readonly attribute ServiceWorkerClients clients;
     [SameObject] readonly attribute ServiceWorkerRegistration registration;
index a9beab6..d112ccf 100644 (file)
@@ -31,7 +31,8 @@
     SecureContext,
     Exposed=(Window,ServiceWorker),
     Conditional=SERVICE_WORKER,
-    EnabledAtRuntime=ServiceWorker
+    EnabledAtRuntime=ServiceWorker,
+    GenerateIsReachable=Impl,
 ] interface ServiceWorkerRegistration : EventTarget {
     readonly attribute ServiceWorker? installing;
     readonly attribute ServiceWorker? waiting;