Title: [255986] trunk
Revision
255986
Author
[email protected]
Date
2020-02-06 15:17:11 -0800 (Thu, 06 Feb 2020)

Log Message

Web Inspector: show _javascript_ Worker terminated state as an internal property
https://bugs.webkit.org/show_bug.cgi?id=207347

Reviewed by Brian Burg.

Source/WebCore:

Test: inspector/worker/worker-create-and-terminate.html

* inspector/WebInjectedScriptHost.cpp:
(WebCore::WebInjectedScriptHost::getInternalProperties):

* workers/Worker.h:
(WebCore::Worker::wasTerminated): Added.

LayoutTests:

* inspector/worker/worker-create-and-terminate.html:
Add assertions throughout the test to check that the `terminated` value matches what the
frontend knows.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (255985 => 255986)


--- trunk/LayoutTests/ChangeLog	2020-02-06 23:07:10 UTC (rev 255985)
+++ trunk/LayoutTests/ChangeLog	2020-02-06 23:17:11 UTC (rev 255986)
@@ -1,3 +1,14 @@
+2020-02-06  Devin Rousso  <[email protected]>
+
+        Web Inspector: show _javascript_ Worker terminated state as an internal property
+        https://bugs.webkit.org/show_bug.cgi?id=207347
+
+        Reviewed by Brian Burg.
+
+        * inspector/worker/worker-create-and-terminate.html:
+        Add assertions throughout the test to check that the `terminated` value matches what the
+        frontend knows.
+
 2020-02-06  Truitt Savell  <[email protected]>
 
         Regression: fast/hidpi/image-srcset-svg-canvas-2x.html is failing consistently on iOS EWS

Modified: trunk/LayoutTests/inspector/worker/worker-create-and-terminate.html (255985 => 255986)


--- trunk/LayoutTests/inspector/worker/worker-create-and-terminate.html	2020-02-06 23:07:10 UTC (rev 255985)
+++ trunk/LayoutTests/inspector/worker/worker-create-and-terminate.html	2020-02-06 23:17:11 UTC (rev 255986)
@@ -43,7 +43,34 @@
             ProtocolTest.log("No Workers");
     }
 
+    async function checkInternalProperties(_expression_, {terminated} = {}) {
+        let evaluateResult = await InspectorProtocol.awaitCommand({
+            method: "Runtime.evaluate",
+            params: {
+                _expression_,
+                objectGroup: "test",
+            },
+        });
 
+        ProtocolTest.assert(evaluateResult.result.type === "object", `Evaluate result of '${_expression_}' should have type 'object'.`);
+        ProtocolTest.assert(evaluateResult.result.className === "Worker", `Evaluate result of '${_expression_}' should have className 'Worker'.`);
+
+        let getPropertiesResult = await InspectorProtocol.awaitCommand({
+            method: "Runtime.getProperties",
+            params: {
+                objectId: evaluateResult.result.objectId,
+            },
+        });
+
+        let internalProperties = getPropertiesResult.internalProperties;
+        ProtocolTest.assert(internalProperties.length === 1, `Worker '${_expression_}' should only have one internal property.`);
+
+        ProtocolTest.assert(internalProperties[0].name === "terminated", `Worker '${_expression_}' should have 'terminated' internal property.`);
+        ProtocolTest.assert(internalProperties[0].value.type === "boolean", `Internal 'terminated' property of '${_expression_}' should be a boolean.`);
+        ProtocolTest.assert(internalProperties[0].value.value === terminated, `Internal 'terminated' property of '${_expression_}' should have value '${terminated}'.`);
+    }
+
+
     let triggerNextCreate;
     let triggerNextTerminate;
 
@@ -78,13 +105,16 @@
     suite.addTestCase({
         name: "Worker.enable",
         description: "Worker.enable informs the frontend of the two existing Workers",
-        test(resolve, reject) {
-            InspectorProtocol.awaitCommand({method: "Worker.enable", params: {}})
-                .then(() => {
-                    ProtocolTest.expectEqual(workers.length, 2, "Should be informed of two existing Workers.");
-                    dumpWorkers();
-                    resolve();
-                }).catch(reject);
+        async test() {
+            await InspectorProtocol.awaitCommand({method: "Worker.enable", params: {}});
+
+            ProtocolTest.expectEqual(workers.length, 2, "Should be informed of two existing Workers.");
+            dumpWorkers();
+
+            await Promise.all([
+                checkInternalProperties(`worker1`, {terminated: false}),
+                checkInternalProperties(`worker2`, {terminated: false}),
+            ]);
         }
     });
 
@@ -91,14 +121,20 @@
     suite.addTestCase({
         name: "Worker.workerCreated",
         description: "Should receive a Worker.workerCreated event when creating a Worker.",
-        test(resolve, reject) {
-            ProtocolTest.evaluateInPage("createWorker3()");
-            waitForWorkerCreatedEvent()
-                .then(() => {
-                    ProtocolTest.pass("Worker.workerCreated");
-                    dumpWorkers();
-                    resolve();
-                }).catch(reject);
+        async test() {
+            await Promise.all([
+                waitForWorkerCreatedEvent(),
+                ProtocolTest.evaluateInPage("createWorker3()"),
+            ]);
+
+            ProtocolTest.pass("Worker.workerCreated");
+            dumpWorkers();
+
+            await Promise.all([
+                checkInternalProperties(`worker1`, {terminated: false}),
+                checkInternalProperties(`worker2`, {terminated: false}),
+                checkInternalProperties(`worker3`, {terminated: false}),
+            ]);
         }
     });
 
@@ -105,14 +141,20 @@
     suite.addTestCase({
         name: "Worker.workerTerminated.Page",
         description: "Should receive a Worker.workerTerminated event when terminating a Worker from the Page.",
-        test(resolve, reject) {
-            ProtocolTest.evaluateInPage("terminateWorker2FromPage()");
-            waitForWorkerTerminatedEvent()
-                .then(() => {
-                    ProtocolTest.pass("Worker.workerTerminated");
-                    dumpWorkers();
-                    resolve();
-                }).catch(reject);
+        async test() {
+            await Promise.all([
+                waitForWorkerTerminatedEvent(),
+                ProtocolTest.evaluateInPage("terminateWorker2FromPage()"),
+            ]);
+
+            ProtocolTest.pass("Worker.workerTerminated");
+            dumpWorkers();
+
+            await Promise.all([
+                checkInternalProperties(`worker1`, {terminated: false}),
+                checkInternalProperties(`worker2`, {terminated: true}),
+                checkInternalProperties(`worker3`, {terminated: false}),
+            ]);
         }
     });
 
@@ -119,14 +161,19 @@
     suite.addTestCase({
         name: "Worker.workerTerminated.Worker",
         description: "Should receive a Worker.workerTerminated event when terminating a Worker from the Worker.",
-        test(resolve, reject) {
-            ProtocolTest.evaluateInPage("terminateWorker3FromWorker()");
-            waitForWorkerTerminatedEvent()
-                .then(() => {
-                    ProtocolTest.pass("Worker.workerTerminated");
-                    dumpWorkers();
-                    resolve();
-                }).catch(reject);
+        async test() {
+            await Promise.all([
+                waitForWorkerTerminatedEvent(),
+                ProtocolTest.evaluateInPage("terminateWorker3FromWorker()"),
+            ]);
+
+            ProtocolTest.pass("Worker.workerTerminated");
+            dumpWorkers();
+
+            await Promise.all([
+                checkInternalProperties(`worker1`, {terminated: false}),
+                checkInternalProperties(`worker2`, {terminated: true}),
+            ]);
         }
     });
 
@@ -133,15 +180,17 @@
     suite.addTestCase({
         name: "Worker.workerTerminated.GC",
         description: "Should receive a Worker.workerTerminated event when terminating a Worker via Garbage Collection.",
-        test(resolve, reject) {
-            ProtocolTest.evaluateInPage("terminateWorker1ViaCollection()");
-            InspectorProtocol.sendCommand("Heap.gc", {});
-            waitForWorkerTerminatedEvent()
-                .then(() => {
-                    ProtocolTest.pass("Worker.workerTerminated");
-                    dumpWorkers();
-                    resolve();
-                }).catch(reject);
+        async test() {
+            let workerTerminatedPromise = waitForWorkerTerminatedEvent();
+            await ProtocolTest.evaluateInPage("terminateWorker1ViaCollection()");
+            await InspectorProtocol.awaitCommand({method: "Runtime.releaseObjectGroup", params: {objectGroup: "test"}});
+            await InspectorProtocol.awaitCommand({method: "Heap.gc", params: {}});
+            await workerTerminatedPromise;
+
+            ProtocolTest.pass("Worker.workerTerminated");
+            dumpWorkers();
+
+            await checkInternalProperties(`worker2`, {terminated: true});
         }
     });
 

Modified: trunk/Source/WebCore/ChangeLog (255985 => 255986)


--- trunk/Source/WebCore/ChangeLog	2020-02-06 23:07:10 UTC (rev 255985)
+++ trunk/Source/WebCore/ChangeLog	2020-02-06 23:17:11 UTC (rev 255986)
@@ -1,3 +1,18 @@
+2020-02-06  Devin Rousso  <[email protected]>
+
+        Web Inspector: show _javascript_ Worker terminated state as an internal property
+        https://bugs.webkit.org/show_bug.cgi?id=207347
+
+        Reviewed by Brian Burg.
+
+        Test: inspector/worker/worker-create-and-terminate.html
+
+        * inspector/WebInjectedScriptHost.cpp:
+        (WebCore::WebInjectedScriptHost::getInternalProperties):
+
+        * workers/Worker.h:
+        (WebCore::Worker::wasTerminated): Added.
+
 2020-02-06  Christopher Reid  <[email protected]>
 
         [curl] PublicSuffixCurl should skip leading dots

Modified: trunk/Source/WebCore/inspector/WebInjectedScriptHost.cpp (255985 => 255986)


--- trunk/Source/WebCore/inspector/WebInjectedScriptHost.cpp	2020-02-06 23:07:10 UTC (rev 255985)
+++ trunk/Source/WebCore/inspector/WebInjectedScriptHost.cpp	2020-02-06 23:17:11 UTC (rev 255986)
@@ -32,6 +32,8 @@
 #include "JSHTMLCollection.h"
 #include "JSNode.h"
 #include "JSNodeList.h"
+#include "JSWorker.h"
+#include "Worker.h"
 
 #if ENABLE(PAYMENT_REQUEST)
 #include "JSPaymentRequest.h"
@@ -59,7 +61,6 @@
     return jsUndefined();
 }
 
-#if ENABLE(PAYMENT_REQUEST)
 static JSObject* constructInternalProperty(VM& vm, JSGlobalObject* exec, const String& name, JSValue value)
 {
     auto* object = constructEmptyObject(exec);
@@ -68,6 +69,7 @@
     return object;
 }
 
+#if ENABLE(PAYMENT_REQUEST)
 static JSObject* objectForPaymentOptions(VM& vm, JSGlobalObject* exec, const PaymentOptions& paymentOptions)
 {
     auto* object = constructEmptyObject(exec);
@@ -161,9 +163,17 @@
 
 JSValue WebInjectedScriptHost::getInternalProperties(VM& vm, JSGlobalObject* exec, JSC::JSValue value)
 {
-#if ENABLE(PAYMENT_REQUEST)
     auto scope = DECLARE_THROW_SCOPE(vm);
 
+    if (auto* worker = JSWorker::toWrapped(vm, value)) {
+        unsigned index = 0;
+        auto* array = constructEmptyArray(exec, nullptr);
+        array->putDirectIndex(exec, index++, constructInternalProperty(vm, exec, "terminated"_s, jsBoolean(worker->wasTerminated())));
+        RETURN_IF_EXCEPTION(scope, { });
+        return array;
+    }
+
+#if ENABLE(PAYMENT_REQUEST)
     if (PaymentRequest* paymentRequest = JSPaymentRequest::toWrapped(vm, value)) {
         unsigned index = 0;
         auto* array = constructEmptyArray(exec, nullptr);
@@ -173,10 +183,6 @@
         RETURN_IF_EXCEPTION(scope, { });
         return array;
     }
-#else
-    UNUSED_PARAM(vm);
-    UNUSED_PARAM(exec);
-    UNUSED_PARAM(value);
 #endif
 
     return { };

Modified: trunk/Source/WebCore/workers/Worker.h (255985 => 255986)


--- trunk/Source/WebCore/workers/Worker.h	2020-02-06 23:07:10 UTC (rev 255985)
+++ trunk/Source/WebCore/workers/Worker.h	2020-02-06 23:17:11 UTC (rev 255986)
@@ -61,6 +61,7 @@
     ExceptionOr<void> postMessage(JSC::JSGlobalObject&, JSC::JSValue message, PostMessageOptions&&);
 
     void terminate();
+    bool wasTerminated() const { return m_wasTerminated; }
 
     bool hasPendingActivity() const final;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to