<!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>[200533] 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/200533">200533</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-05-06 16:32:28 -0700 (Fri, 06 May 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Web Inspector: Console: Variables defined with let/const aren't accessible outside of console's scope
https://bugs.webkit.org/show_bug.cgi?id=150752
<rdar://problem/23343385>
Patch by Joseph Pecoraro <pecoraro@apple.com> on 2016-05-06
Reviewed by Mark Lam.
Source/JavaScriptCore:
This approach allows Web Inspector to hang a "Scope Extension", a
WithObjectScope, off the GlobalObject. When resolving identifiers
in fails to resolve anything in the normal scope chain, consult
the scope extension.
This allows us to eliminate the `with (commandLineAPI) { ... }`
block in global console evaluations, and instead makes it a full
program evaluation, with the commandLineAPI available and safely
shadowed by actual variables as expected.
* inspector/InjectedScriptSource.js:
(InjectedScript.prototype._evaluateOn):
Use the new evaluateWithScopeExtension and provide the CommandLineAPI
object as the scope extension object.
(BasicCommandLineAPI):
(BasicCommandLineAPI.inScopeVariables): Deleted.
Simplify now that we don't need to check for variable shadowing ourselves.
* inspector/JSInjectedScriptHost.cpp:
(Inspector::JSInjectedScriptHost::evaluateWithScopeExtension):
* inspector/JSInjectedScriptHost.h:
* inspector/JSInjectedScriptHostPrototype.cpp:
(Inspector::JSInjectedScriptHostPrototype::finishCreation):
(Inspector::jsInjectedScriptHostPrototypeFunctionEvaluateWithScopeExtension):
Provide a new InjectedScriptHost method to evaluate a program
with a scope extension.
* runtime/Completion.cpp:
(JSC::evaluateWithScopeExtension):
* runtime/Completion.h:
General JSC::evaluate function to evaluate a program with a scope extension.
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::setGlobalScopeExtension):
(JSC::JSGlobalObject::clearGlobalScopeExtension):
(JSC::JSGlobalObject::visitChildren):
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::globalScopeExtension):
Hang a scope extension off the global object.
* runtime/JSScope.cpp:
(JSC::JSScope::resolve):
Consult the scope extension when resolve fails to find anything normally.
Source/WebCore:
Test: inspector/runtime/evaluate-CommandLineAPI.html
* inspector/CommandLineAPIModuleSource.js:
(bind):
(this.member.toString):
(CommandLineAPI):
(CommandLineAPIImpl.prototype):
(slice): Deleted.
(bound): Deleted.
(bound.toString): Deleted.
(inScopeVariables): Deleted.
(customToStringMethod): Deleted.
Simplify now that we don't need to do our own variable shadow checking.
LayoutTests:
* inspector/runtime/evaluate-CommandLineAPI-expected.txt: Added.
* inspector/runtime/evaluate-CommandLineAPI.html: Added.
New test covering the different cases of global evaluation with the
CommandLineAPI as a scope extension.
* http/tests/inspector/console/cross-domain-inspected-node-access-expected.txt:
* inspector/console/command-line-api-expected.txt:
* inspector/debugger/js-stacktrace-expected.txt:
* inspector/debugger/js-stacktrace.html:
* inspector/model/stack-trace-expected.txt:
* platform/mac/inspector/model/remote-object-expected.txt:
Update expectations now that global evaluations are treated as
program's [global code] and not evals [eval code]. Also some
line number changes.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestshttptestsinspectorconsolecrossdomaininspectednodeaccessexpectedtxt">trunk/LayoutTests/http/tests/inspector/console/cross-domain-inspected-node-access-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectorconsolecommandlineapiexpectedtxt">trunk/LayoutTests/inspector/console/command-line-api-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectordebuggerjsstacktraceexpectedtxt">trunk/LayoutTests/inspector/debugger/js-stacktrace-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectordebuggerjsstacktracehtml">trunk/LayoutTests/inspector/debugger/js-stacktrace.html</a></li>
<li><a href="#trunkLayoutTestsinspectormodelstacktraceexpectedtxt">trunk/LayoutTests/inspector/model/stack-trace-expected.txt</a></li>
<li><a href="#trunkLayoutTestsplatformmacinspectormodelremoteobjectexpectedtxt">trunk/LayoutTests/platform/mac/inspector/model/remote-object-expected.txt</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorInjectedScriptSourcejs">trunk/Source/JavaScriptCore/inspector/InjectedScriptSource.js</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorJSInjectedScriptHostcpp">trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorJSInjectedScriptHosth">trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHost.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorJSInjectedScriptHostPrototypecpp">trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHostPrototype.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeCompletioncpp">trunk/Source/JavaScriptCore/runtime/Completion.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeCompletionh">trunk/Source/JavaScriptCore/runtime/Completion.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGlobalObjectcpp">trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGlobalObjecth">trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSScopecpp">trunk/Source/JavaScriptCore/runtime/JSScope.cpp</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreinspectorCommandLineAPIModuleSourcejs">trunk/Source/WebCore/inspector/CommandLineAPIModuleSource.js</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsinspectorruntimeevaluateCommandLineAPIexpectedtxt">trunk/LayoutTests/inspector/runtime/evaluate-CommandLineAPI-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectorruntimeevaluateCommandLineAPIhtml">trunk/LayoutTests/inspector/runtime/evaluate-CommandLineAPI.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/LayoutTests/ChangeLog        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2016-05-06 Joseph Pecoraro <pecoraro@apple.com>
+
+ Web Inspector: Console: Variables defined with let/const aren't accessible outside of console's scope
+ https://bugs.webkit.org/show_bug.cgi?id=150752
+ <rdar://problem/23343385>
+
+ Reviewed by Mark Lam.
+
+ * inspector/runtime/evaluate-CommandLineAPI-expected.txt: Added.
+ * inspector/runtime/evaluate-CommandLineAPI.html: Added.
+ New test covering the different cases of global evaluation with the
+ CommandLineAPI as a scope extension.
+
+ * http/tests/inspector/console/cross-domain-inspected-node-access-expected.txt:
+ * inspector/console/command-line-api-expected.txt:
+ * inspector/debugger/js-stacktrace-expected.txt:
+ * inspector/debugger/js-stacktrace.html:
+ * inspector/model/stack-trace-expected.txt:
+ * platform/mac/inspector/model/remote-object-expected.txt:
+ Update expectations now that global evaluations are treated as
+ program's [global code] and not evals [eval code]. Also some
+ line number changes.
+
</ins><span class="cx"> 2016-05-06 Tim Horton <timothy_horton@apple.com>
</span><span class="cx">
</span><span class="cx"> <attachment> element should understand UTIs
</span></span></pre></div>
<a id="trunkLayoutTestshttptestsinspectorconsolecrossdomaininspectednodeaccessexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/inspector/console/cross-domain-inspected-node-access-expected.txt (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/inspector/console/cross-domain-inspected-node-access-expected.txt        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/LayoutTests/http/tests/inspector/console/cross-domain-inspected-node-access-expected.txt        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><del>-CONSOLE MESSAGE: line 57: Blocked a frame with origin "http://127.0.0.1:8000" from accessing a frame with origin "http://localhost:8000". Protocols, domains, and ports must match.
-CONSOLE MESSAGE: line 57: Blocked a frame with origin "http://localhost:8000" from accessing a frame with origin "http://127.0.0.1:8000". Protocols, domains, and ports must match.
</del><ins>+CONSOLE MESSAGE: line 42: Blocked a frame with origin "http://127.0.0.1:8000" from accessing a frame with origin "http://localhost:8000". Protocols, domains, and ports must match.
+CONSOLE MESSAGE: line 42: Blocked a frame with origin "http://localhost:8000" from accessing a frame with origin "http://127.0.0.1:8000". Protocols, domains, and ports must match.
</ins><span class="cx"> Test that code evaluated in the main frame cannot access $0 that resolves to a node in a frame from a different domain. Bug 105423.
</span><span class="cx">
</span><span class="cx">
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorconsolecommandlineapiexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/console/command-line-api-expected.txt (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/console/command-line-api-expected.txt        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/LayoutTests/inspector/console/command-line-api-expected.txt        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -1,4 +1,4 @@
</span><del>-CONSOLE MESSAGE: line 27: The console function $() has changed from $=getElementById(id) to $=querySelector(selector). You might try $("#%s")
</del><ins>+CONSOLE MESSAGE: line 12: The console function $() has changed from $=getElementById(id) to $=querySelector(selector). You might try $("#%s")
</ins><span class="cx"> Tests that command line api works.
</span><span class="cx">
</span><span class="cx">
</span></span></pre></div>
<a id="trunkLayoutTestsinspectordebuggerjsstacktraceexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/debugger/js-stacktrace-expected.txt (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/debugger/js-stacktrace-expected.txt        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/LayoutTests/inspector/debugger/js-stacktrace-expected.txt        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -19,7 +19,7 @@
</span><span class="cx"> {
</span><span class="cx"> "lineNumber": 0,
</span><span class="cx"> "columnNumber": 14,
</span><del>- "functionName": "Eval Code",
</del><ins>+ "functionName": "Global Code",
</ins><span class="cx"> "nativeCode": false,
</span><span class="cx"> "programCode": true
</span><span class="cx"> }
</span><span class="lines">@@ -40,7 +40,7 @@
</span><span class="cx"> "columnNumber": 21
</span><span class="cx"> },
</span><span class="cx"> {
</span><del>- "functionName": "eval code",
</del><ins>+ "functionName": "global code",
</ins><span class="cx"> "url": "",
</span><span class="cx"> "lineNumber": 0,
</span><span class="cx"> "columnNumber": 0
</span><span class="lines">@@ -73,7 +73,7 @@
</span><span class="cx"> {
</span><span class="cx"> "lineNumber": 0,
</span><span class="cx"> "columnNumber": 28,
</span><del>- "functionName": "Eval Code",
</del><ins>+ "functionName": "Global Code",
</ins><span class="cx"> "nativeCode": false,
</span><span class="cx"> "programCode": true
</span><span class="cx"> }
</span><span class="lines">@@ -100,7 +100,7 @@
</span><span class="cx"> "columnNumber": 20
</span><span class="cx"> },
</span><span class="cx"> {
</span><del>- "functionName": "eval code",
</del><ins>+ "functionName": "global code",
</ins><span class="cx"> "url": "",
</span><span class="cx"> "lineNumber": 0,
</span><span class="cx"> "columnNumber": 0
</span></span></pre></div>
<a id="trunkLayoutTestsinspectordebuggerjsstacktracehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/debugger/js-stacktrace.html (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/debugger/js-stacktrace.html        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/LayoutTests/inspector/debugger/js-stacktrace.html        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -67,7 +67,7 @@
</span><span class="cx"> if (error)
</span><span class="cx"> InspectorTest.log(error);
</span><span class="cx">
</span><del>- var stackTrace = stripPayloadAfterEval(WebInspector.StackTrace._parseStackTrace(result.value));
</del><ins>+ var stackTrace = stripPayloadAfterGlobalCode(WebInspector.StackTrace._parseStackTrace(result.value));
</ins><span class="cx"> stackTrace = stripFilePaths(stackTrace);
</span><span class="cx">
</span><span class="cx"> InspectorTest.log(JSON.stringify(stackTrace, null, 4));
</span><span class="lines">@@ -80,7 +80,7 @@
</span><span class="cx"> if (error)
</span><span class="cx"> InspectorTest.log(error);
</span><span class="cx">
</span><del>- var stackTrace = stripPayloadAfterEval(WebInspector.StackTrace._parseStackTrace(result.value));
</del><ins>+ var stackTrace = stripPayloadAfterGlobalCode(WebInspector.StackTrace._parseStackTrace(result.value));
</ins><span class="cx"> stackTrace = stripFilePaths(stackTrace);
</span><span class="cx">
</span><span class="cx"> InspectorTest.log(JSON.stringify(stackTrace, null, 4));
</span><span class="lines">@@ -93,7 +93,7 @@
</span><span class="cx"> if (error)
</span><span class="cx"> InspectorTest.log(error);
</span><span class="cx">
</span><del>- var stackTrace = stripPayloadAfterEval(WebInspector.StackTrace._parseStackTrace(result.value));
</del><ins>+ var stackTrace = stripPayloadAfterGlobalCode(WebInspector.StackTrace._parseStackTrace(result.value));
</ins><span class="cx"> stackTrace = stripFilePaths(stackTrace);
</span><span class="cx">
</span><span class="cx"> InspectorTest.log(JSON.stringify(stackTrace, null, 4));
</span><span class="lines">@@ -120,12 +120,12 @@
</span><span class="cx"> return stackTrace.slice(0, index);
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function stripPayloadAfterEval(payload)
</del><ins>+ function stripPayloadAfterGlobalCode(payload)
</ins><span class="cx"> {
</span><span class="cx"> var index = 0;
</span><span class="cx"> for (var frame of payload) {
</span><span class="cx"> index++;
</span><del>- if (frame.functionName === "eval code")
</del><ins>+ if (frame.functionName === "global code")
</ins><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx"> return payload.slice(0, index);
</span></span></pre></div>
<a id="trunkLayoutTestsinspectormodelstacktraceexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/model/stack-trace-expected.txt (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/model/stack-trace-expected.txt        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/LayoutTests/inspector/model/stack-trace-expected.txt        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -15,8 +15,8 @@
</span><span class="cx"> 4: Global Code (inline-script.js:2) - nativeCode (false) programCode (true)
</span><span class="cx"> 5: appendChild - nativeCode (true) programCode (false)
</span><span class="cx"> 6: triggerConsoleMessage (stack-trace.html:9) - nativeCode (false) programCode (false)
</span><del>- 7: Eval Code (Anonymous Script 2 (line 1)) - nativeCode (false) programCode (true)
- 8: eval - nativeCode (true) programCode (false)
</del><ins>+ 7: Global Code (Anonymous Script 2 (line 1)) - nativeCode (false) programCode (true)
+ 8: evaluateWithScopeExtension - nativeCode (true) programCode (false)
</ins><span class="cx"> 9: _evaluateOn - nativeCode (true) programCode (false)
</span><span class="cx"> 10: _evaluateAndWrap - nativeCode (true) programCode (false)
</span><span class="cx"> 11: evaluate - nativeCode (true) programCode (false)
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorruntimeevaluateCommandLineAPIexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/runtime/evaluate-CommandLineAPI-expected.txt (0 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/runtime/evaluate-CommandLineAPI-expected.txt         (rev 0)
+++ trunk/LayoutTests/inspector/runtime/evaluate-CommandLineAPI-expected.txt        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -0,0 +1,36 @@
</span><ins>+Tests for the Runtime.evaluate with the Command Line API.
+
+
+== Running test suite: Runtime.evaluate.CommandLineAPI
+-- Running test case: AccessCommandLineAPI
+PASS: CommandLineAPI `keys` can be accessed.
+PASS: CommandLineAPI `keys` should work with a simple object.
+
+-- Running test case: AccessGlobalVariable
+PASS: Should be able to access var in global scope.
+PASS: Should be able to access let in global scope.
+PASS: Should be able to access const in global scope.
+
+-- Running test case: CreateGlobalVariable
+PASS: Should be able to access created var in global scope.
+PASS: Should be able to access created let in global scope.
+PASS: Should be able to access created const in global scope.
+
+-- Running test case: CreateGlobalClass
+PASS: Should be able to access class created in earlier evaluation.
+
+-- Running test case: ExpectedExceptionCreatingDuplicateLexicalGlobalVariables
+PASS: Should be an exception defining a lexical global multiple times.
+
+-- Running test case: NonStrictAndStrictEvaluations
+PASS: Non-strict evaluation. Should be able to access arguments.callee.
+PASS: Script evaluation. Should not be able to access arguments.callee.
+
+-- Running test case: CommandLineAPIDoesNotShadowVariables
+PASS: `keys` is currently CommandLineAPI function.
+PASS: Creating global `keys` variable should be okay.
+PASS: Global `keys` variable should not be shadowed by CommandLineAPI function.
+
+-- Running test case: CommandLineAPIDoesNotShadowGlobalObjectProperties
+PASS: `values` should be `window.values` and not shadowed by CommandLineAPI `values` function.
+
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorruntimeevaluateCommandLineAPIhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/runtime/evaluate-CommandLineAPI.html (0 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/runtime/evaluate-CommandLineAPI.html         (rev 0)
+++ trunk/LayoutTests/inspector/runtime/evaluate-CommandLineAPI.html        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -0,0 +1,179 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
+<script>
+var varGlobalVariable = 1;
+let letGlobalVariable = 2;
+const constGlobalVariable = 3;
+
+function test()
+{
+ const objectGroup = "test";
+ const includeCommandLineAPI = true;
+ const returnByValue = true;
+
+ function testEvaluate(expression, callback) {
+ RuntimeAgent.evaluate.invoke({expression, objectGroup, includeCommandLineAPI, returnByValue}, (error, resultValue, wasThrown) => {
+ InspectorTest.assert(!error, "Should not be a protocol error.");
+ InspectorTest.assert(!wasThrown, "Should not be a runtime error.");
+ if (callback)
+ callback(resultValue.value);
+ });
+ }
+
+ function testEvaluateThrow(expression, callback) {
+ RuntimeAgent.evaluate.invoke({expression, objectGroup, includeCommandLineAPI, returnByValue}, (error, resultValue, wasThrown) => {
+ InspectorTest.assert(!error, "Should not be a protocol error.");
+ InspectorTest.assert(wasThrown, "Should be a runtime error.");
+ if (callback)
+ callback(wasThrown);
+ });
+ }
+
+ let suite = InspectorTest.createAsyncSuite("Runtime.evaluate.CommandLineAPI");
+
+ suite.addTestCase({
+ name: "AccessCommandLineAPI",
+ description: "Test evaluate can access CommandLineAPI methods.",
+ test: (resolve, reject) => {
+ testEvaluate("keys.toString()", (resultValue) => {
+ InspectorTest.expectThat(resultValue.includes("[Command Line API]"), "CommandLineAPI `keys` can be accessed.");
+ });
+ testEvaluate("keys({a:1, b:2})", (resultValue) => {
+ InspectorTest.expectThat(resultValue.length === 2 && resultValue[0] === "a" && resultValue[1] === "b", "CommandLineAPI `keys` should work with a simple object.");
+ resolve();
+ });
+ }
+ });
+
+ suite.addTestCase({
+ name: "AccessGlobalVariable",
+ description: "Test evaluate can access global variables.",
+ test: (resolve, reject) => {
+ testEvaluate("varGlobalVariable", (resultValue) => {
+ InspectorTest.expectThat(resultValue === 1, "Should be able to access var in global scope.");
+ });
+ testEvaluate("letGlobalVariable", (resultValue) => {
+ InspectorTest.expectThat(resultValue === 2, "Should be able to access let in global scope.");
+ });
+ testEvaluate("constGlobalVariable", (resultValue) => {
+ InspectorTest.expectThat(resultValue === 3, "Should be able to access const in global scope.");
+ resolve();
+ });
+ }
+ });
+
+ suite.addTestCase({
+ name: "CreateGlobalVariable",
+ description: "Test evaluate can create global variables.",
+ test: (resolve, reject) => {
+ testEvaluate(`
+ var createdVarGlobalVariable = 1;
+ let createdLetGlobalVariable = 2;
+ const createdConstGlobalVariable = 3;
+ `);
+ testEvaluate("createdVarGlobalVariable", (resultValue) => {
+ InspectorTest.expectThat(resultValue === 1, "Should be able to access created var in global scope.");
+ });
+ testEvaluate("createdLetGlobalVariable", (resultValue) => {
+ InspectorTest.expectThat(resultValue === 2, "Should be able to access created let in global scope.");
+ });
+ testEvaluate("createdConstGlobalVariable", (resultValue) => {
+ InspectorTest.expectThat(resultValue === 3, "Should be able to access created const in global scope.");
+ resolve();
+ });
+ }
+ });
+
+ suite.addTestCase({
+ name: "CreateGlobalClass",
+ description: "Test evaluate can create a class.",
+ test: (resolve, reject) => {
+ testEvaluate(`
+ class Foo {
+ static staticMethod() {
+ return 42;
+ }
+ }
+ `);
+ testEvaluate("Foo.staticMethod()", (resultValue) => {
+ InspectorTest.expectThat(resultValue === 42, "Should be able to access class created in earlier evaluation.");
+ resolve();
+ });
+ }
+ });
+
+ suite.addTestCase({
+ name: "ExpectedExceptionCreatingDuplicateLexicalGlobalVariables",
+ description: "Test evaluate produces expected exception creating duplicate lexical global variables across evaluations.",
+ test: (resolve, reject) => {
+ testEvaluate(`let duplicateGlobalVariable = 1`);
+ testEvaluateThrow(`let duplicateGlobalVariable = 1`, (wasThrown) => {
+ InspectorTest.expectThat(wasThrown, "Should be an exception defining a lexical global multiple times.");
+ resolve();
+ });
+ }
+ });
+
+ suite.addTestCase({
+ name: "NonStrictAndStrictEvaluations",
+ description: "Test evaluate can run strict and non-strict programs.",
+ test: (resolve, reject) => {
+ testEvaluate(`
+ // Not strict, this is okay.
+ (function f() {
+ return arguments.callee.name;
+ })();
+ `, (resultValue) => {
+ InspectorTest.expectThat(resultValue === "f", "Non-strict evaluation. Should be able to access arguments.callee.");
+ });
+ testEvaluateThrow(`"use strict";
+ // Strict, this throw an exception.
+ (function() {
+ return arguments.callee;
+ })();`
+ , (wasThrown) => {
+ InspectorTest.expectThat(wasThrown, "Script evaluation. Should not be able to access arguments.callee.");
+ resolve();
+ });
+ }
+ });
+
+ suite.addTestCase({
+ name: "CommandLineAPIDoesNotShadowVariables",
+ description: "Test CommandLineAPI does not shadow global variables.",
+ test: (resolve, reject) => {
+ testEvaluate("keys.toString()", (resultValue) => {
+ InspectorTest.expectThat(resultValue.includes("[Command Line API]"), "`keys` is currently CommandLineAPI function.");
+ });
+ testEvaluate("var keys = 123; keys", (resultValue) => {
+ InspectorTest.expectThat(resultValue === 123, "Creating global `keys` variable should be okay.");
+ });
+ testEvaluate("keys", (resultValue) => {
+ InspectorTest.expectThat(resultValue === 123, "Global `keys` variable should not be shadowed by CommandLineAPI function.");
+ resolve();
+ });
+ }
+ });
+
+ suite.addTestCase({
+ name: "CommandLineAPIDoesNotShadowGlobalObjectProperties",
+ description: "Test CommandLineAPI does not shadow global object properties.",
+ test: (resolve, reject) => {
+ testEvaluate("values.toString()", (resultValue) => {
+ InspectorTest.expectThat(resultValue === "[object HTMLDivElement]", "`values` should be `window.values` and not shadowed by CommandLineAPI `values` function.");
+ resolve();
+ });
+ }
+ });
+
+ suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body onload="runTest()">
+<div id="values"></div> <!-- This introduces the named property `window.values` on the window global object. -->
+<p>Tests for the Runtime.evaluate with the Command Line API.</p>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformmacinspectormodelremoteobjectexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac/inspector/model/remote-object-expected.txt (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac/inspector/model/remote-object-expected.txt        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/LayoutTests/platform/mac/inspector/model/remote-object-expected.txt        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -2328,7 +2328,7 @@
</span><span class="cx"> "_listeners": null,
</span><span class="cx"> "_name": "stack",
</span><span class="cx"> "_type": "string",
</span><del>- "_value": "eval code\neval@[native code]\n_evaluateOn\n_evaluateAndWrap\nevaluate"
</del><ins>+ "_value": "global code\nevaluateWithScopeExtension@[native code]\n_evaluateOn\n_evaluateAndWrap\nevaluate"
</ins><span class="cx"> }
</span><span class="cx"> ],
</span><span class="cx"> "_entries": null
</span><span class="lines">@@ -2372,7 +2372,7 @@
</span><span class="cx"> "_listeners": null,
</span><span class="cx"> "_name": "stack",
</span><span class="cx"> "_type": "string",
</span><del>- "_value": "eval@[native code]\neval code\neval@[native code]\n_evaluateOn\n_evaluateAndWrap\nevaluate"
</del><ins>+ "_value": "eval@[native code]\nglobal code\nevaluateWithScopeEx…ative code]\n_evaluateOn\n_evaluateAndWrap\nevaluate"
</ins><span class="cx"> }
</span><span class="cx"> ],
</span><span class="cx"> "_entries": null
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -1,3 +1,56 @@
</span><ins>+2016-05-06 Joseph Pecoraro <pecoraro@apple.com>
+
+ Web Inspector: Console: Variables defined with let/const aren't accessible outside of console's scope
+ https://bugs.webkit.org/show_bug.cgi?id=150752
+ <rdar://problem/23343385>
+
+ Reviewed by Mark Lam.
+
+ This approach allows Web Inspector to hang a "Scope Extension", a
+ WithObjectScope, off the GlobalObject. When resolving identifiers
+ in fails to resolve anything in the normal scope chain, consult
+ the scope extension.
+
+ This allows us to eliminate the `with (commandLineAPI) { ... }`
+ block in global console evaluations, and instead makes it a full
+ program evaluation, with the commandLineAPI available and safely
+ shadowed by actual variables as expected.
+
+ * inspector/InjectedScriptSource.js:
+ (InjectedScript.prototype._evaluateOn):
+ Use the new evaluateWithScopeExtension and provide the CommandLineAPI
+ object as the scope extension object.
+
+ (BasicCommandLineAPI):
+ (BasicCommandLineAPI.inScopeVariables): Deleted.
+ Simplify now that we don't need to check for variable shadowing ourselves.
+
+ * inspector/JSInjectedScriptHost.cpp:
+ (Inspector::JSInjectedScriptHost::evaluateWithScopeExtension):
+ * inspector/JSInjectedScriptHost.h:
+ * inspector/JSInjectedScriptHostPrototype.cpp:
+ (Inspector::JSInjectedScriptHostPrototype::finishCreation):
+ (Inspector::jsInjectedScriptHostPrototypeFunctionEvaluateWithScopeExtension):
+ Provide a new InjectedScriptHost method to evaluate a program
+ with a scope extension.
+
+ * runtime/Completion.cpp:
+ (JSC::evaluateWithScopeExtension):
+ * runtime/Completion.h:
+ General JSC::evaluate function to evaluate a program with a scope extension.
+
+ * runtime/JSGlobalObject.cpp:
+ (JSC::JSGlobalObject::setGlobalScopeExtension):
+ (JSC::JSGlobalObject::clearGlobalScopeExtension):
+ (JSC::JSGlobalObject::visitChildren):
+ * runtime/JSGlobalObject.h:
+ (JSC::JSGlobalObject::globalScopeExtension):
+ Hang a scope extension off the global object.
+
+ * runtime/JSScope.cpp:
+ (JSC::JSScope::resolve):
+ Consult the scope extension when resolve fails to find anything normally.
+
</ins><span class="cx"> 2016-05-06 Mark Lam <mark.lam@apple.com>
</span><span class="cx">
</span><span class="cx"> Add JSC options reportBaselineCompileTimes and reportDFGCompileTimes.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorInjectedScriptSourcejs"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/InjectedScriptSource.js (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/InjectedScriptSource.js        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/Source/JavaScriptCore/inspector/InjectedScriptSource.js        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -31,7 +31,8 @@
</span><span class="cx">
</span><span class="cx"> (function (InjectedScriptHost, inspectedGlobalObject, injectedScriptId) {
</span><span class="cx">
</span><del>-// Protect against Object overwritten by the user code.
</del><ins>+// FIXME: <https://webkit.org/b/152294> Web Inspector: Parse InjectedScriptSource as a built-in to get guaranteed non-user-overriden built-ins
+
</ins><span class="cx"> var Object = {}.constructor;
</span><span class="cx">
</span><span class="cx"> function toString(obj)
</span><span class="lines">@@ -519,32 +520,12 @@
</span><span class="cx"> return result;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- // When not evaluating on a call frame we use a 'with' statement to allow var and function statements to leak
- // into the global scope. This allow them to stick around between evaluations.
-
- try {
- if (commandLineAPI) {
- if (inspectedGlobalObject.console)
- inspectedGlobalObject.console.__commandLineAPI = commandLineAPI;
- else
- inspectedGlobalObject.__commandLineAPI = commandLineAPI;
- expression = "with ((this && (this.console ? this.console.__commandLineAPI : this.__commandLineAPI)) || {}) { " + expression + "\n}";
- }
-
- var result = evalFunction.call(inspectedGlobalObject, expression);
-
- if (saveResult)
- this._saveResult(result);
-
- return result;
- } finally {
- if (commandLineAPI) {
- if (inspectedGlobalObject.console)
- delete inspectedGlobalObject.console.__commandLineAPI;
- else
- delete inspectedGlobalObject.__commandLineAPI;
- }
- }
</del><ins>+ // When not evaluating on a call frame, we evaluate as a program
+ // with the Command Line API as a scope extension object.
+ var result = InjectedScriptHost.evaluateWithScopeExtension(expression, commandLineAPI);
+ if (saveResult)
+ this._saveResult(result);
+ return result;
</ins><span class="cx"> },
</span><span class="cx">
</span><span class="cx"> wrapCallFrames: function(callFrame)
</span><span class="lines">@@ -1411,38 +1392,16 @@
</span><span class="cx">
</span><span class="cx"> function BasicCommandLineAPI(callFrame)
</span><span class="cx"> {
</span><del>- function inScopeVariables(member)
- {
- if (!callFrame)
- return false;
-
- var scopeChain = callFrame.scopeChain;
- for (var i = 0; i < scopeChain.length; ++i) {
- if (member in scopeChain[i])
- return true;
- }
- return false;
- }
-
</del><span class="cx"> this.$_ = injectedScript._lastResult;
</span><span class="cx"> this.$exception = injectedScript._exceptionValue;
</span><span class="cx">
</span><span class="cx"> // $1-$99
</span><del>- for (var i = 1; i <= injectedScript._savedResults.length; ++i) {
- var member = "$" + i;
- if (member in inspectedGlobalObject)
- continue;
</del><ins>+ for (var i = 1; i <= injectedScript._savedResults.length; ++i)
</ins><span class="cx"> this.__defineGetter__("$" + i, bind(injectedScript._savedResult, injectedScript, i));
</span><del>- }
</del><span class="cx">
</span><span class="cx"> // Command Line API methods.
</span><del>- for (var i = 0; i < BasicCommandLineAPI.methods.length; ++i) {
- var method = BasicCommandLineAPI.methods[i];
- var name = method.name;
- if (name in inspectedGlobalObject || inScopeVariables(name))
- continue;
- this[name] = method;
- }
</del><ins>+ for (var i = 0; i < BasicCommandLineAPI.methods.length; ++i)
+ this[method.name] = method;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> BasicCommandLineAPI.methods = [
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorJSInjectedScriptHostcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> #include "JSInjectedScriptHost.h"
</span><span class="cx">
</span><span class="cx"> #include "BuiltinNames.h"
</span><ins>+#include "Completion.h"
</ins><span class="cx"> #include "DateInstance.h"
</span><span class="cx"> #include "DirectArguments.h"
</span><span class="cx"> #include "Error.h"
</span><span class="lines">@@ -37,6 +38,7 @@
</span><span class="cx"> #include "JSBoundFunction.h"
</span><span class="cx"> #include "JSCInlines.h"
</span><span class="cx"> #include "JSFunction.h"
</span><ins>+#include "JSGlobalObjectFunctions.h"
</ins><span class="cx"> #include "JSInjectedScriptHostPrototype.h"
</span><span class="cx"> #include "JSMap.h"
</span><span class="cx"> #include "JSMapIterator.h"
</span><span class="lines">@@ -48,6 +50,7 @@
</span><span class="cx"> #include "JSTypedArrays.h"
</span><span class="cx"> #include "JSWeakMap.h"
</span><span class="cx"> #include "JSWeakSet.h"
</span><ins>+#include "JSWithScope.h"
</ins><span class="cx"> #include "ObjectConstructor.h"
</span><span class="cx"> #include "ProxyObject.h"
</span><span class="cx"> #include "RegExpObject.h"
</span><span class="lines">@@ -91,6 +94,20 @@
</span><span class="cx"> return globalObject->evalFunction();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+JSValue JSInjectedScriptHost::evaluateWithScopeExtension(ExecState* exec)
+{
+ JSValue scriptValue = exec->argument(0);
+ if (!scriptValue.isString())
+ return throwTypeError(exec, "InjectedScriptHost.evaluateWithScopeExtension first argument must be a string.");
+
+ String program = scriptValue.toString(exec)->value(exec);
+ if (exec->hadException())
+ return jsUndefined();
+
+ JSObject* scopeExtension = exec->argument(1).getObject();
+ return JSC::evaluateWithScopeExtension(exec, makeSource(program), scopeExtension);
+}
+
</ins><span class="cx"> JSValue JSInjectedScriptHost::internalConstructorName(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx"> if (exec->argumentCount() < 1)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorJSInjectedScriptHosth"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHost.h (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHost.h        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHost.h        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -60,6 +60,7 @@
</span><span class="cx"> JSC::JSValue evaluate(JSC::ExecState*) const;
</span><span class="cx">
</span><span class="cx"> // Functions.
</span><ins>+ JSC::JSValue evaluateWithScopeExtension(JSC::ExecState*);
</ins><span class="cx"> JSC::JSValue internalConstructorName(JSC::ExecState*);
</span><span class="cx"> JSC::JSValue isHTMLAllCollection(JSC::ExecState*);
</span><span class="cx"> JSC::JSValue subtype(JSC::ExecState*);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorJSInjectedScriptHostPrototypecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHostPrototype.cpp (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHostPrototype.cpp        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHostPrototype.cpp        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -48,6 +48,7 @@
</span><span class="cx"> static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionWeakSetSize(ExecState*);
</span><span class="cx"> static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionWeakSetEntries(ExecState*);
</span><span class="cx"> static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionIteratorEntries(ExecState*);
</span><ins>+static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionEvaluateWithScopeExtension(ExecState*);
</ins><span class="cx">
</span><span class="cx"> static EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeAttributeEvaluate(ExecState*);
</span><span class="cx">
</span><span class="lines">@@ -69,6 +70,7 @@
</span><span class="cx"> JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("weakSetSize", jsInjectedScriptHostPrototypeFunctionWeakSetSize, DontEnum, 1);
</span><span class="cx"> JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("weakSetEntries", jsInjectedScriptHostPrototypeFunctionWeakSetEntries, DontEnum, 1);
</span><span class="cx"> JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("iteratorEntries", jsInjectedScriptHostPrototypeFunctionIteratorEntries, DontEnum, 1);
</span><ins>+ JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("evaluateWithScopeExtension", jsInjectedScriptHostPrototypeFunctionEvaluateWithScopeExtension, DontEnum, 1);
</ins><span class="cx">
</span><span class="cx"> JSC_NATIVE_GETTER("evaluate", jsInjectedScriptHostPrototypeAttributeEvaluate, DontEnum | Accessor);
</span><span class="cx"> }
</span><span class="lines">@@ -80,7 +82,6 @@
</span><span class="cx"> if (!castedThis)
</span><span class="cx"> return throwVMTypeError(exec);
</span><span class="cx">
</span><del>- ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
</del><span class="cx"> return JSValue::encode(castedThis->evaluate(exec));
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -91,7 +92,6 @@
</span><span class="cx"> if (!castedThis)
</span><span class="cx"> return throwVMTypeError(exec);
</span><span class="cx">
</span><del>- ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
</del><span class="cx"> return JSValue::encode(castedThis->internalConstructorName(exec));
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -102,7 +102,6 @@
</span><span class="cx"> if (!castedThis)
</span><span class="cx"> return throwVMTypeError(exec);
</span><span class="cx">
</span><del>- ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
</del><span class="cx"> return JSValue::encode(castedThis->isHTMLAllCollection(exec));
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -113,7 +112,6 @@
</span><span class="cx"> if (!castedThis)
</span><span class="cx"> return throwVMTypeError(exec);
</span><span class="cx">
</span><del>- ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
</del><span class="cx"> return JSValue::encode(castedThis->weakMapSize(exec));
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -124,7 +122,6 @@
</span><span class="cx"> if (!castedThis)
</span><span class="cx"> return throwVMTypeError(exec);
</span><span class="cx">
</span><del>- ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
</del><span class="cx"> return JSValue::encode(castedThis->weakMapEntries(exec));
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -135,7 +132,6 @@
</span><span class="cx"> if (!castedThis)
</span><span class="cx"> return throwVMTypeError(exec);
</span><span class="cx">
</span><del>- ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
</del><span class="cx"> return JSValue::encode(castedThis->weakSetSize(exec));
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -146,7 +142,6 @@
</span><span class="cx"> if (!castedThis)
</span><span class="cx"> return throwVMTypeError(exec);
</span><span class="cx">
</span><del>- ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
</del><span class="cx"> return JSValue::encode(castedThis->weakSetEntries(exec));
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -157,10 +152,19 @@
</span><span class="cx"> if (!castedThis)
</span><span class="cx"> return throwVMTypeError(exec);
</span><span class="cx">
</span><del>- ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
</del><span class="cx"> return JSValue::encode(castedThis->iteratorEntries(exec));
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionEvaluateWithScopeExtension(ExecState* exec)
+{
+ JSValue thisValue = exec->thisValue();
+ JSInjectedScriptHost* castedThis = jsDynamicCast<JSInjectedScriptHost*>(thisValue);
+ if (!castedThis)
+ return throwVMTypeError(exec);
+
+ return JSValue::encode(castedThis->evaluateWithScopeExtension(exec));
+}
+
</ins><span class="cx"> EncodedJSValue JSC_HOST_CALL jsInjectedScriptHostPrototypeFunctionSubtype(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx"> JSValue thisValue = exec->thisValue();
</span><span class="lines">@@ -168,7 +172,6 @@
</span><span class="cx"> if (!castedThis)
</span><span class="cx"> return throwVMTypeError(exec);
</span><span class="cx">
</span><del>- ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
</del><span class="cx"> return JSValue::encode(castedThis->subtype(exec));
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -179,7 +182,6 @@
</span><span class="cx"> if (!castedThis)
</span><span class="cx"> return throwVMTypeError(exec);
</span><span class="cx">
</span><del>- ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
</del><span class="cx"> return JSValue::encode(castedThis->functionDetails(exec));
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -190,7 +192,6 @@
</span><span class="cx"> if (!castedThis)
</span><span class="cx"> return throwVMTypeError(exec);
</span><span class="cx">
</span><del>- ASSERT_GC_OBJECT_INHERITS(castedThis, JSInjectedScriptHost::info());
</del><span class="cx"> return JSValue::encode(castedThis->getInternalProperties(exec));
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeCompletioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/Completion.cpp (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/Completion.cpp        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/Source/JavaScriptCore/runtime/Completion.cpp        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> #include "JSInternalPromiseDeferred.h"
</span><span class="cx"> #include "JSLock.h"
</span><span class="cx"> #include "JSModuleRecord.h"
</span><ins>+#include "JSWithScope.h"
</ins><span class="cx"> #include "ModuleAnalyzer.h"
</span><span class="cx"> #include "ModuleLoaderObject.h"
</span><span class="cx"> #include "Parser.h"
</span><span class="lines">@@ -121,6 +122,28 @@
</span><span class="cx"> return evaluate(exec, source, thisValue, returnedException);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+JSValue evaluateWithScopeExtension(ExecState* exec, const SourceCode& source, JSObject* scopeExtensionObject)
+{
+ JSGlobalObject* globalObject = exec->vmEntryGlobalObject();
+
+ if (scopeExtensionObject) {
+ JSScope* ignoredPreviousScope = globalObject->globalScope();
+ globalObject->setGlobalScopeExtension(JSWithScope::create(exec->vm(), globalObject, scopeExtensionObject, ignoredPreviousScope));
+ }
+
+ NakedPtr<Exception> exception;
+ JSValue returnValue = JSC::evaluate(globalObject->globalExec(), source, globalObject, exception);
+
+ // Don't swallow the exception.
+ if (exception)
+ globalObject->vm().restorePreviousException(exception);
+
+ if (scopeExtensionObject)
+ globalObject->clearGlobalScopeExtension();
+
+ return returnValue;
+}
+
</ins><span class="cx"> static Symbol* createSymbolForEntryPointModule(VM& vm)
</span><span class="cx"> {
</span><span class="cx"> // Generate the unique key for the source-provided module.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeCompletionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/Completion.h (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/Completion.h        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/Source/JavaScriptCore/runtime/Completion.h        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -31,7 +31,7 @@
</span><span class="cx">
</span><span class="cx"> class Exception;
</span><span class="cx"> class ExecState;
</span><del>-class JSScope;
</del><ins>+class JSObject;
</ins><span class="cx"> class ParserError;
</span><span class="cx"> class SourceCode;
</span><span class="cx"> class VM;
</span><span class="lines">@@ -55,6 +55,8 @@
</span><span class="cx"> return profiledEvaluate(exec, reason, sourceCode, thisValue, unused);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+JS_EXPORT_PRIVATE JSValue evaluateWithScopeExtension(ExecState*, const SourceCode&, JSObject* scopeExtension);
+
</ins><span class="cx"> // Load the module source and evaluate it.
</span><span class="cx"> JS_EXPORT_PRIVATE JSInternalPromise* loadAndEvaluateModule(ExecState*, const String& moduleName);
</span><span class="cx"> JS_EXPORT_PRIVATE JSInternalPromise* loadAndEvaluateModule(ExecState*, const SourceCode&);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGlobalObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -875,6 +875,16 @@
</span><span class="cx"> addGlobalVar(propertyName);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void JSGlobalObject::setGlobalScopeExtension(JSScope* scope)
+{
+ m_globalScopeExtension.set(vm(), this, scope);
+}
+
+void JSGlobalObject::clearGlobalScopeExtension()
+{
+ m_globalScopeExtension.clear();
+}
+
</ins><span class="cx"> static inline JSObject* lastInPrototypeChain(JSObject* object)
</span><span class="cx"> {
</span><span class="cx"> JSObject* o = object;
</span><span class="lines">@@ -1034,6 +1044,7 @@
</span><span class="cx"> visitor.append(&thisObject->m_globalThis);
</span><span class="cx">
</span><span class="cx"> visitor.append(&thisObject->m_globalLexicalEnvironment);
</span><ins>+ visitor.append(&thisObject->m_globalScopeExtension);
</ins><span class="cx"> visitor.append(&thisObject->m_globalCallee);
</span><span class="cx"> visitor.append(&thisObject->m_regExpConstructor);
</span><span class="cx"> visitor.append(&thisObject->m_errorConstructor);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGlobalObjecth"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -217,6 +217,7 @@
</span><span class="cx"> WriteBarrier<JSObject> m_globalThis;
</span><span class="cx">
</span><span class="cx"> WriteBarrier<JSGlobalLexicalEnvironment> m_globalLexicalEnvironment;
</span><ins>+ WriteBarrier<JSScope> m_globalScopeExtension;
</ins><span class="cx"> WriteBarrier<JSObject> m_globalCallee;
</span><span class="cx"> WriteBarrier<RegExpConstructor> m_regExpConstructor;
</span><span class="cx"> WriteBarrier<ErrorConstructor> m_errorConstructor;
</span><span class="lines">@@ -455,6 +456,10 @@
</span><span class="cx"> JSScope* globalScope() { return m_globalLexicalEnvironment.get(); }
</span><span class="cx"> JSGlobalLexicalEnvironment* globalLexicalEnvironment() { return m_globalLexicalEnvironment.get(); }
</span><span class="cx">
</span><ins>+ JSScope* globalScopeExtension() { return m_globalScopeExtension.get(); }
+ void setGlobalScopeExtension(JSScope*);
+ void clearGlobalScopeExtension();
+
</ins><span class="cx"> // The following accessors return pristine values, even if a script
</span><span class="cx"> // replaces the global object's associated property.
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSScopecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSScope.cpp (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSScope.cpp        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/Source/JavaScriptCore/runtime/JSScope.cpp        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -203,8 +203,18 @@
</span><span class="cx"> JSScope* scope = it.scope();
</span><span class="cx"> JSObject* object = it.get();
</span><span class="cx">
</span><del>- if (++it == end) // Global scope.
</del><ins>+ // Global scope.
+ if (++it == end) {
+ JSScope* globalScopeExtension = scope->globalObject()->globalScopeExtension();
+ if (UNLIKELY(globalScopeExtension)) {
+ if (object->hasProperty(exec, ident))
+ return object;
+ JSObject* extensionScopeObject = JSScope::objectAtScope(globalScopeExtension);
+ if (extensionScopeObject->hasProperty(exec, ident))
+ return extensionScopeObject;
+ }
</ins><span class="cx"> return object;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> if (object->hasProperty(exec, ident)) {
</span><span class="cx"> if (!isUnscopable(exec, scope, object, ident))
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/Source/WebCore/ChangeLog        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2016-05-06 Joseph Pecoraro <pecoraro@apple.com>
+
+ Web Inspector: Console: Variables defined with let/const aren't accessible outside of console's scope
+ https://bugs.webkit.org/show_bug.cgi?id=150752
+ <rdar://problem/23343385>
+
+ Reviewed by Mark Lam.
+
+ Test: inspector/runtime/evaluate-CommandLineAPI.html
+
+ * inspector/CommandLineAPIModuleSource.js:
+ (bind):
+ (this.member.toString):
+ (CommandLineAPI):
+ (CommandLineAPIImpl.prototype):
+ (slice): Deleted.
+ (bound): Deleted.
+ (bound.toString): Deleted.
+ (inScopeVariables): Deleted.
+ (customToStringMethod): Deleted.
+ Simplify now that we don't need to do our own variable shadow checking.
+
</ins><span class="cx"> 2016-05-06 Tim Horton <timothy_horton@apple.com>
</span><span class="cx">
</span><span class="cx"> <attachment> element should understand UTIs
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorCommandLineAPIModuleSourcejs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/CommandLineAPIModuleSource.js (200532 => 200533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/CommandLineAPIModuleSource.js        2016-05-06 23:21:16 UTC (rev 200532)
+++ trunk/Source/WebCore/inspector/CommandLineAPIModuleSource.js        2016-05-06 23:32:28 UTC (rev 200533)
</span><span class="lines">@@ -37,40 +37,13 @@
</span><span class="cx"> */
</span><span class="cx"> (function (InjectedScriptHost, inspectedWindow, injectedScriptId, injectedScript, CommandLineAPIHost) {
</span><span class="cx">
</span><del>-/**
- * @param {Arguments} array
- * @param {number=} index
- * @return {Array.<*>}
- */
-function slice(array, index)
-{
- var result = [];
- for (var i = index || 0; i < array.length; ++i)
- result.push(array[i]);
- return result;
-}
</del><ins>+// FIXME: <https://webkit.org/b/152294> Web Inspector: Parse InjectedScriptSource as a built-in to get guaranteed non-user-overriden built-ins
</ins><span class="cx">
</span><del>-/**
- * Please use this bind, not the one from Function.prototype
- * @param {function(...)} func
- * @param {Object} thisObject
- * @param {...number} var_args
- */
-function bind(func, thisObject, var_args)
</del><ins>+function bind(func, thisObject, ...outerArgs)
</ins><span class="cx"> {
</span><del>- var args = slice(arguments, 2);
-
- /**
- * @param {...number} var_args
- */
- function bound(var_args)
- {
- return func.apply(thisObject, args.concat(slice(arguments)));
</del><ins>+ return function(...innerArgs) {
+ return func.apply(thisObject, outerArgs.concat(innerArgs));
</ins><span class="cx"> }
</span><del>- bound.toString = function() {
- return "bound: " + func;
- };
- return bound;
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -80,55 +53,21 @@
</span><span class="cx"> */
</span><span class="cx"> function CommandLineAPI(commandLineAPIImpl, callFrame)
</span><span class="cx"> {
</span><del>- /**
- * @param {string} member
- * @return {boolean}
- */
- function inScopeVariables(member)
- {
- if (!callFrame)
- return false;
</del><ins>+ this.$_ = injectedScript._lastResult;
+ this.$exception = injectedScript._exceptionValue;
</ins><span class="cx">
</span><del>- var scopeChain = callFrame.scopeChain;
- for (var i = 0; i < scopeChain.length; ++i) {
- if (member in scopeChain[i])
- return true;
- }
- return false;
- }
-
- /**
- * @param {string} name The name of the method for which a toString method should be generated.
- * @return {function():string}
- */
- function customToStringMethod(name)
- {
- return function () { return "function " + name + "() { [Command Line API] }"; };
- }
-
- for (var i = 0; i < CommandLineAPI.members_.length; ++i) {
- var member = CommandLineAPI.members_[i];
- if (member in inspectedWindow || inScopeVariables(member))
- continue;
-
- this[member] = bind(commandLineAPIImpl[member], commandLineAPIImpl);
- this[member].toString = customToStringMethod(member);
- }
-
</del><span class="cx"> // $0
</span><span class="cx"> this.__defineGetter__("$0", bind(commandLineAPIImpl._inspectedObject, commandLineAPIImpl));
</span><span class="cx">
</span><span class="cx"> // $1-$99
</span><del>- for (var i = 1; i <= injectedScript._savedResults.length; ++i) {
- var member = "$" + i;
- if (member in inspectedWindow || inScopeVariables(member))
- continue;
-
</del><ins>+ for (var i = 1; i <= injectedScript._savedResults.length; ++i)
</ins><span class="cx"> this.__defineGetter__("$" + i, bind(injectedScript._savedResult, injectedScript, i));
</span><del>- }
</del><span class="cx">
</span><del>- this.$_ = injectedScript._lastResult;
- this.$exception = injectedScript._exceptionValue;
</del><ins>+ // Command Line API methods.
+ for (let member of CommandLineAPI.members_) {
+ this[member] = bind(commandLineAPIImpl[member], commandLineAPIImpl);
+ this[member].toString = function() { return "function " + member + "() { [Command Line API] }" };
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -177,8 +116,8 @@
</span><span class="cx"> $$: function (selector, start)
</span><span class="cx"> {
</span><span class="cx"> if (this._canQuerySelectorOnNode(start))
</span><del>- return slice(start.querySelectorAll(selector));
- return slice(inspectedWindow.document.querySelectorAll(selector));
</del><ins>+ return Array.from(start.querySelectorAll(selector));
+ return Array.from(inspectedWindow.document.querySelectorAll(selector));
</ins><span class="cx"> },
</span><span class="cx">
</span><span class="cx"> /**
</span></span></pre>
</div>
</div>
</body>
</html>