Title: [218223] trunk
Revision
218223
Author
commit-qu...@webkit.org
Date
2017-06-13 16:57:55 -0700 (Tue, 13 Jun 2017)

Log Message

Debugger has unexpected effect on program correctness
https://bugs.webkit.org/show_bug.cgi?id=172683

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

Source/_javascript_Core:

* 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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (218222 => 218223)


--- trunk/LayoutTests/ChangeLog	2017-06-13 23:51:35 UTC (rev 218222)
+++ trunk/LayoutTests/ChangeLog	2017-06-13 23:57:55 UTC (rev 218223)
@@ -1,3 +1,13 @@
+2017-06-13  Joseph Pecoraro  <pecor...@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  <jlew...@apple.com>
 
         Updated test expectations for imported/w3c/web-platform-tests/dom/nodes/Document-constructor-svg.svg.

Added: trunk/LayoutTests/inspector/injected-script/observable-expected.txt (0 => 218223)


--- trunk/LayoutTests/inspector/injected-script/observable-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/injected-script/observable-expected.txt	2017-06-13 23:57:55 UTC (rev 218223)
@@ -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
+

Added: trunk/LayoutTests/inspector/injected-script/observable.html (0 => 218223)


--- trunk/LayoutTests/inspector/injected-script/observable.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/injected-script/observable.html	2017-06-13 23:57:55 UTC (rev 218223)
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<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>

Modified: trunk/Source/_javascript_Core/ChangeLog (218222 => 218223)


--- trunk/Source/_javascript_Core/ChangeLog	2017-06-13 23:51:35 UTC (rev 218222)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-06-13 23:57:55 UTC (rev 218223)
@@ -1,3 +1,17 @@
+2017-06-13  Joseph Pecoraro  <pecor...@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  <jfbast...@apple.com>
 
         WebAssembly: fix erroneous signature comment

Modified: trunk/Source/_javascript_Core/inspector/InjectedScriptSource.js (218222 => 218223)


--- trunk/Source/_javascript_Core/inspector/InjectedScriptSource.js	2017-06-13 23:51:35 UTC (rev 218222)
+++ trunk/Source/_javascript_Core/inspector/InjectedScriptSource.js	2017-06-13 23:57:55 UTC (rev 218223)
@@ -1066,7 +1066,9 @@
 
     _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 @@
 
     _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 @@
             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 @@
         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 @@
     },
 ];
 
-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;
 })
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to