Debugger has unexpected effect on program correctness
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Jun 2017 23:57:55 +0000 (23:57 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Jun 2017 23:57:55 +0000 (23:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=172683

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2017-06-13
Reviewed by Saam Barati.

Source/JavaScriptCore:

* inspector/InjectedScriptSource.js:
(InjectedScript.RemoteObject.prototype._appendPropertyPreviews):
(InjectedScript.RemoteObject.prototype._isPreviewableObjectInternal):
(BasicCommandLineAPI):
Eliminate for..of use with Arrays from InjectedScriptSource as it can be observable.
We still use it for Set / Map iteration which we can eliminate when moving to builtins.

LayoutTests:

* inspector/injected-script/observable-expected.txt: Added.
* inspector/injected-script/observable.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/inspector/injected-script/observable-expected.txt [new file with mode: 0644]
LayoutTests/inspector/injected-script/observable.html [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/InjectedScriptSource.js

index 628376f..212fc98 100644 (file)
@@ -1,3 +1,13 @@
+2017-06-13  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Debugger has unexpected effect on program correctness
+        https://bugs.webkit.org/show_bug.cgi?id=172683
+
+        Reviewed by Saam Barati.
+
+        * inspector/injected-script/observable-expected.txt: Added.
+        * inspector/injected-script/observable.html: Added.
+
 2017-06-13  Matt Lewis  <jlewis3@apple.com>
 
         Updated test expectations for imported/w3c/web-platform-tests/dom/nodes/Document-constructor-svg.svg.
diff --git a/LayoutTests/inspector/injected-script/observable-expected.txt b/LayoutTests/inspector/injected-script/observable-expected.txt
new file mode 100644 (file)
index 0000000..9e92952
--- /dev/null
@@ -0,0 +1,10 @@
+CONSOLE MESSAGE: line 25: [object Object]
+Test that certain InjectedScriptSource operations are not observable by user code.
+
+
+== Running test suite: InjectedScript.Observable
+-- Running test case: InjectedScript.Observable:Array.prototype[Symbol.iterator]
+PASS: Paused.
+PASS: Resumed.
+PASS: 1
+
diff --git a/LayoutTests/inspector/injected-script/observable.html b/LayoutTests/inspector/injected-script/observable.html
new file mode 100644 (file)
index 0000000..463fe16
--- /dev/null
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
+<script>
+// NOTE: More cases should be tested and addressed by:
+// <https://webkit.org/b/152294> Web Inspector: Parse InjectedScriptSource as a built-in to get guaranteed non-user-overriden built-ins
+
+function triggerIteration() {
+    let callCount = 0;
+
+    const originalIterator = Object.getOwnPropertyDescriptor(Array.prototype, Symbol.iterator);
+    Object.defineProperty(Array.prototype, Symbol.iterator, {
+        get() {
+            ++callCount;
+            return originalIterator.value;
+        }
+    });
+
+    let array = [];
+
+    debugger;
+
+    // Preview an object.
+    console.log({a:1, b:2, c:{}});
+
+    // Use Array Iterator at least once.
+    for (let x of array) { }
+
+    Object.defineProperty(Array.prototype, Symbol.iterator, originalIterator);
+
+    return callCount;
+}
+
+function test()
+{
+    let suite = InspectorTest.createAsyncSuite("InjectedScript.Observable");
+
+    suite.addTestCase({
+        name: "InjectedScript.Observable:Array.prototype[Symbol.iterator]",
+        description: "Array iteration in Injected Script should not be observable",
+        test(resolve, reject) {
+            InspectorTest.evaluateInPage(`triggerIteration()`, (error, result) => {
+                InspectorTest.expectThat(result.value, 1, "Array.prototype[Symbol.iterator] call count should be 1.");
+                resolve();
+            });
+
+            WebInspector.debuggerManager.singleFireEventListener(WebInspector.DebuggerManager.Event.Paused, (event) => {
+                InspectorTest.pass("Paused.");
+                WebInspector.debuggerManager.resume().catch(reject);
+            });
+            WebInspector.debuggerManager.singleFireEventListener(WebInspector.DebuggerManager.Event.Resumed, (event) => {
+                InspectorTest.pass("Resumed.");
+            });
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body onload="runTest()">
+<p>Test that certain InjectedScriptSource operations are not observable by user code.</p>
+</body>
+</html>
index 9562cc7..380c58d 100644 (file)
@@ -1,3 +1,17 @@
+2017-06-13  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Debugger has unexpected effect on program correctness
+        https://bugs.webkit.org/show_bug.cgi?id=172683
+
+        Reviewed by Saam Barati.
+
+        * inspector/InjectedScriptSource.js:
+        (InjectedScript.RemoteObject.prototype._appendPropertyPreviews):
+        (InjectedScript.RemoteObject.prototype._isPreviewableObjectInternal):
+        (BasicCommandLineAPI):
+        Eliminate for..of use with Arrays from InjectedScriptSource as it can be observable.
+        We still use it for Set / Map iteration which we can eliminate when moving to builtins.
+
 2017-06-13  JF Bastien  <jfbastien@apple.com>
 
         WebAssembly: fix erroneous signature comment
index aaea8a6..29ebfcc 100644 (file)
@@ -1066,7 +1066,9 @@ InjectedScript.RemoteObject.prototype = {
 
     _appendPropertyPreviews: function(object, preview, descriptors, internal, propertiesThreshold, firstLevelKeys, secondLevelKeys)
     {
-        for (var descriptor of descriptors) {
+        for (let i = 0; i < descriptors.length; ++i) {
+            let descriptor = descriptors[i];
+
             // Seen enough.
             if (propertiesThreshold.indexes < 0 || propertiesThreshold.properties < 0)
                 break;
@@ -1234,7 +1236,10 @@ InjectedScript.RemoteObject.prototype = {
 
     _isPreviewableObject: function(value, object)
     {
-        return this._isPreviewableObjectInternal(value, new Set([object]), 1);
+        let set = new Set;
+        set.add(object);
+
+        return this._isPreviewableObjectInternal(value, set, 1);
     },
 
     _isPreviewableObjectInternal: function(object, knownObjects, depth)
@@ -1276,10 +1281,11 @@ InjectedScript.RemoteObject.prototype = {
             return false;
 
         // Objects are simple if they have 3 or less simple properties.
-        var ownPropertyNames = Object.getOwnPropertyNames(object);
+        let ownPropertyNames = Object.getOwnPropertyNames(object);
         if (ownPropertyNames.length > 3)
             return false;
-        for (var propertyName of ownPropertyNames) {
+        for (let i = 0; i < ownPropertyNames.length; ++i) {
+            let propertyName = ownPropertyNames[i];
             if (!this._isPreviewableObjectInternal(object[propertyName], knownObjects, depth))
                 return false;
         }
@@ -1372,8 +1378,10 @@ function BasicCommandLineAPI(callFrame)
         this.__defineGetter__("$" + i, bind(injectedScript._savedResult, injectedScript, i));
 
     // Command Line API methods.
-    for (let method of BasicCommandLineAPI.methods)
+    for (let i = 0; i < BasicCommandLineAPI.methods.length; ++i) {
+        let method = BasicCommandLineAPI.methods[i];
         this[method.name] = method;
+    }
 }
 
 BasicCommandLineAPI.methods = [
@@ -1392,8 +1400,10 @@ BasicCommandLineAPI.methods = [
     },
 ];
 
-for (let method of BasicCommandLineAPI.methods)
+for (let i = 0; i < BasicCommandLineAPI.methods.length; ++i) {
+    let method = BasicCommandLineAPI.methods[i];
     method.toString = function() { return "function " + method.name + "() { [Command Line API] }"; };
+}
 
 return injectedScript;
 })