<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[218223] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/218223">218223</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2017-06-13 16:57:55 -0700 (Tue, 13 Jun 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Debugger has unexpected effect on program correctness
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.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorInjectedScriptSourcejs">trunk/Source/JavaScriptCore/inspector/InjectedScriptSource.js</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>trunk/LayoutTests/inspector/injected-script/</li>
<li><a href="#trunkLayoutTestsinspectorinjectedscriptobservableexpectedtxt">trunk/LayoutTests/inspector/injected-script/observable-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectorinjectedscriptobservablehtml">trunk/LayoutTests/inspector/injected-script/observable.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (218222 => 218223)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2017-06-13 23:51:35 UTC (rev 218222)
+++ trunk/LayoutTests/ChangeLog 2017-06-13 23:57:55 UTC (rev 218223)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+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.
+
</ins><span class="cx"> 2017-06-13  Matt Lewis  <jlewis3@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Updated test expectations for imported/w3c/web-platform-tests/dom/nodes/Document-constructor-svg.svg.
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorinjectedscriptobservableexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/injected-script/observable-expected.txt (0 => 218223)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+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
+
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorinjectedscriptobservablehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/injected-script/observable.html (0 => 218223)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,65 @@
</span><ins>+<!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>
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (218222 => 218223)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog    2017-06-13 23:51:35 UTC (rev 218222)
+++ trunk/Source/JavaScriptCore/ChangeLog       2017-06-13 23:57:55 UTC (rev 218223)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+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.
+
</ins><span class="cx"> 2017-06-13  JF Bastien  <jfbastien@apple.com>
</span><span class="cx"> 
</span><span class="cx">         WebAssembly: fix erroneous signature comment
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorInjectedScriptSourcejs"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/InjectedScriptSource.js (218222 => 218223)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/InjectedScriptSource.js    2017-06-13 23:51:35 UTC (rev 218222)
+++ trunk/Source/JavaScriptCore/inspector/InjectedScriptSource.js       2017-06-13 23:57:55 UTC (rev 218223)
</span><span class="lines">@@ -1066,7 +1066,9 @@
</span><span class="cx"> 
</span><span class="cx">     _appendPropertyPreviews: function(object, preview, descriptors, internal, propertiesThreshold, firstLevelKeys, secondLevelKeys)
</span><span class="cx">     {
</span><del>-        for (var descriptor of descriptors) {
</del><ins>+        for (let i = 0; i < descriptors.length; ++i) {
+            let descriptor = descriptors[i];
+
</ins><span class="cx">             // Seen enough.
</span><span class="cx">             if (propertiesThreshold.indexes < 0 || propertiesThreshold.properties < 0)
</span><span class="cx">                 break;
</span><span class="lines">@@ -1234,7 +1236,10 @@
</span><span class="cx"> 
</span><span class="cx">     _isPreviewableObject: function(value, object)
</span><span class="cx">     {
</span><del>-        return this._isPreviewableObjectInternal(value, new Set([object]), 1);
</del><ins>+        let set = new Set;
+        set.add(object);
+
+        return this._isPreviewableObjectInternal(value, set, 1);
</ins><span class="cx">     },
</span><span class="cx"> 
</span><span class="cx">     _isPreviewableObjectInternal: function(object, knownObjects, depth)
</span><span class="lines">@@ -1276,10 +1281,11 @@
</span><span class="cx">             return false;
</span><span class="cx"> 
</span><span class="cx">         // Objects are simple if they have 3 or less simple properties.
</span><del>-        var ownPropertyNames = Object.getOwnPropertyNames(object);
</del><ins>+        let ownPropertyNames = Object.getOwnPropertyNames(object);
</ins><span class="cx">         if (ownPropertyNames.length > 3)
</span><span class="cx">             return false;
</span><del>-        for (var propertyName of ownPropertyNames) {
</del><ins>+        for (let i = 0; i < ownPropertyNames.length; ++i) {
+            let propertyName = ownPropertyNames[i];
</ins><span class="cx">             if (!this._isPreviewableObjectInternal(object[propertyName], knownObjects, depth))
</span><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="lines">@@ -1372,8 +1378,10 @@
</span><span class="cx">         this.__defineGetter__("$" + i, bind(injectedScript._savedResult, injectedScript, i));
</span><span class="cx"> 
</span><span class="cx">     // Command Line API methods.
</span><del>-    for (let method of BasicCommandLineAPI.methods)
</del><ins>+    for (let i = 0; i < BasicCommandLineAPI.methods.length; ++i) {
+        let method = BasicCommandLineAPI.methods[i];
</ins><span class="cx">         this[method.name] = method;
</span><ins>+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> BasicCommandLineAPI.methods = [
</span><span class="lines">@@ -1392,8 +1400,10 @@
</span><span class="cx">     },
</span><span class="cx"> ];
</span><span class="cx"> 
</span><del>-for (let method of BasicCommandLineAPI.methods)
</del><ins>+for (let i = 0; i < BasicCommandLineAPI.methods.length; ++i) {
+    let method = BasicCommandLineAPI.methods[i];
</ins><span class="cx">     method.toString = function() { return "function " + method.name + "() { [Command Line API] }"; };
</span><ins>+}
</ins><span class="cx"> 
</span><span class="cx"> return injectedScript;
</span><span class="cx"> })
</span></span></pre>
</div>
</div>

</body>
</html>