Web Inspector: show JavaScript Worker name as an internal property
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 May 2020 22:42:18 +0000 (22:42 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 May 2020 22:42:18 +0000 (22:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=211708

Reviewed by Timothy Hatcher.

Source/WebCore:

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

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

* workers/Worker.h:
(WebCore::Worker::name const): Added.

LayoutTests:

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

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

LayoutTests/ChangeLog
LayoutTests/inspector/worker/worker-create-and-terminate.html
Source/WebCore/ChangeLog
Source/WebCore/inspector/WebInjectedScriptHost.cpp
Source/WebCore/workers/Worker.h

index 6447389..ec50e0e 100644 (file)
@@ -1,3 +1,12 @@
+2020-05-11  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: show JavaScript Worker name as an internal property
+        https://bugs.webkit.org/show_bug.cgi?id=211708
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/worker/worker-create-and-terminate.html:
+
 2020-05-11  Peng Liu  <peng.liu6@apple.com>
 
         Enable the mock video presentation mode in related layout tests and fix test failures
index 2701b22..b0f5ca4 100644 (file)
@@ -3,12 +3,12 @@
 <head>
 <script src="../../http/tests/inspector/resources/protocol-test.js"></script>
 <script>
-let worker1 = new Worker("resources/worker-1.js");
-let worker2 = new Worker("resources/worker-2.js");
+let worker1 = new Worker("resources/worker-1.js", {name: "Worker 1"});
+let worker2 = new Worker("resources/worker-2.js", {name: "Worker 2"});
 let worker3 = null;
 
 function createWorker3() {
-    worker3 = new Worker("resources/worker-3.js");
+    worker3 = new Worker("resources/worker-3.js", {name: "Worker 3"});
 }
 
 function terminateWorker2FromPage() {
@@ -43,7 +43,7 @@ function test()
             ProtocolTest.log("No Workers");
     }
 
-    async function checkInternalProperties(expression, {terminated} = {}) {
+    async function checkInternalProperties(expression, internalPropertiesToCheck) {
         let evaluateResult = await InspectorProtocol.awaitCommand({
             method: "Runtime.evaluate",
             params: {
@@ -55,19 +55,25 @@ function 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({
+        let {internalProperties} = await InspectorProtocol.awaitCommand({
             method: "Runtime.getProperties",
             params: {
                 objectId: evaluateResult.result.objectId,
             },
         });
+        ProtocolTest.assert(internalProperties.length === 2, `Worker '${expression}' should only have one internal property.`);
 
-        let internalProperties = getPropertiesResult.internalProperties;
-        ProtocolTest.assert(internalProperties.length === 1, `Worker '${expression}' should only have one internal property.`);
+        function checkInternalProperty(propertyName, type) {
+            let internalProperty = internalProperties.find((item) => item.name === propertyName);
 
-        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}'.`);
+            ProtocolTest.assert(internalProperty, `Worker '${expression}' should have '${propertyName}' internal property.`);
+            ProtocolTest.assert(internalProperty.value.type === type, `Internal '${propertyName}' property of '${expression}' should be a boolean.`);
+            ProtocolTest.assert(internalProperty.value.value === internalPropertiesToCheck[propertyName], `Internal '${propertyName}' property of '${expression}' should have value '${internalPropertiesToCheck[propertyName]}'.`);
+        }
+        if ("name" in internalPropertiesToCheck)
+            checkInternalProperty("name", "string");
+        if ("terminated" in internalPropertiesToCheck)
+            checkInternalProperty("terminated", "boolean");
     }
 
 
@@ -112,8 +118,8 @@ function test()
             dumpWorkers();
 
             await Promise.all([
-                checkInternalProperties(`worker1`, {terminated: false}),
-                checkInternalProperties(`worker2`, {terminated: false}),
+                checkInternalProperties(`worker1`, {name: "Worker 1", terminated: false}),
+                checkInternalProperties(`worker2`, {name: "Worker 2", terminated: false}),
             ]);
         }
     });
@@ -131,9 +137,9 @@ function test()
             dumpWorkers();
 
             await Promise.all([
-                checkInternalProperties(`worker1`, {terminated: false}),
-                checkInternalProperties(`worker2`, {terminated: false}),
-                checkInternalProperties(`worker3`, {terminated: false}),
+                checkInternalProperties(`worker1`, {name: "Worker 1", terminated: false}),
+                checkInternalProperties(`worker2`, {name: "Worker 2", terminated: false}),
+                checkInternalProperties(`worker3`, {name: "Worker 3", terminated: false}),
             ]);
         }
     });
@@ -151,9 +157,9 @@ function test()
             dumpWorkers();
 
             await Promise.all([
-                checkInternalProperties(`worker1`, {terminated: false}),
-                checkInternalProperties(`worker2`, {terminated: true}),
-                checkInternalProperties(`worker3`, {terminated: false}),
+                checkInternalProperties(`worker1`, {name: "Worker 1", terminated: false}),
+                checkInternalProperties(`worker2`, {name: "Worker 2", terminated: true}),
+                checkInternalProperties(`worker3`, {name: "Worker 3", terminated: false}),
             ]);
         }
     });
@@ -171,8 +177,8 @@ function test()
             dumpWorkers();
 
             await Promise.all([
-                checkInternalProperties(`worker1`, {terminated: false}),
-                checkInternalProperties(`worker2`, {terminated: true}),
+                checkInternalProperties(`worker1`, {name: "Worker 1", terminated: false}),
+                checkInternalProperties(`worker2`, {name: "Worker 2", terminated: true}),
             ]);
         }
     });
@@ -190,7 +196,9 @@ function test()
             ProtocolTest.pass("Worker.workerTerminated");
             dumpWorkers();
 
-            await checkInternalProperties(`worker2`, {terminated: true});
+            await Promise.all([
+                checkInternalProperties(`worker2`, {name: "Worker 2", terminated: true}),
+            ]);
         }
     });
 
index 59ff488..e8147c4 100644 (file)
@@ -1,3 +1,18 @@
+2020-05-11  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: show JavaScript Worker name as an internal property
+        https://bugs.webkit.org/show_bug.cgi?id=211708
+
+        Reviewed by Timothy Hatcher.
+
+        Test: inspector/worker/worker-create-and-terminate.html
+
+        * inspector/WebInjectedScriptHost.cpp:
+        (WebCore::WebInjectedScriptHost::getInternalProperties):
+
+        * workers/Worker.h:
+        (WebCore::Worker::name const): Added.
+
 2020-05-11  Simon Fraser  <simon.fraser@apple.com>
 
         Have ScrollingThread use a RunLoop rather than rolling its own
index d76a470..09901d0 100644 (file)
@@ -168,6 +168,7 @@ JSValue WebInjectedScriptHost::getInternalProperties(VM& vm, JSGlobalObject* exe
     if (auto* worker = JSWorker::toWrapped(vm, value)) {
         unsigned index = 0;
         auto* array = constructEmptyArray(exec, nullptr);
+        array->putDirectIndex(exec, index++, constructInternalProperty(vm, exec, "name"_s, jsString(vm, worker->name())));
         array->putDirectIndex(exec, index++, constructInternalProperty(vm, exec, "terminated"_s, jsBoolean(worker->wasTerminated())));
         RETURN_IF_EXCEPTION(scope, { });
         return array;
index ffb69c5..67f4b2b 100644 (file)
@@ -64,6 +64,7 @@ public:
     bool wasTerminated() const { return m_wasTerminated; }
 
     String identifier() const { return m_identifier; }
+    const String& name() const { return m_name; }
 
     ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); }