Skip to content

Commit 43fbc39

Browse files
targosMylesBorins
authored andcommitted
deps: cherry-pick 50f7455 from upstream V8
Original commit message: [inspector] added Runtime.globalLexicalScopeNames method The method returns names for all available top-level scope variables in giving context. [email protected],[email protected] Bug: chromium:681333 Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel Change-Id: I2d0b600e1afbfef9087f53ea9c26abe1e112047c Reviewed-on: https://chromium-review.googlesource.com/719409 Commit-Queue: Aleksey Kozyatinskiy <[email protected]> Reviewed-by: Yang Guo <[email protected]> Reviewed-by: Jakob Gruber <[email protected]> Reviewed-by: Dmitry Gozman <[email protected]> Cr-Commit-Position: refs/heads/master@{#48618} Refs: v8/v8@50f7455 PR-URL: #16591 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent ffc2659 commit 43fbc39

9 files changed

+181
-2
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
# Reset this number to 0 on major V8 upgrades.
2929
# Increment by one for each non-official patch applied to deps/v8.
30-
'v8_embedder_string': '-node.16',
30+
'v8_embedder_string': '-node.17',
3131

3232
# Enable disassembler for `--print-code` v8 options
3333
'v8_enable_disassembler': 1,

deps/v8/src/api.cc

+19
Original file line numberDiff line numberDiff line change
@@ -10011,6 +10011,25 @@ void debug::QueryObjects(v8::Local<v8::Context> v8_context,
1001110011
predicate, objects);
1001210012
}
1001310013

10014+
void debug::GlobalLexicalScopeNames(
10015+
v8::Local<v8::Context> v8_context,
10016+
v8::PersistentValueVector<v8::String>* names) {
10017+
i::Handle<i::Context> context = Utils::OpenHandle(*v8_context);
10018+
i::Handle<i::ScriptContextTable> table(
10019+
context->global_object()->native_context()->script_context_table());
10020+
for (int i = 0; i < table->used(); i++) {
10021+
i::Handle<i::Context> context = i::ScriptContextTable::GetContext(table, i);
10022+
DCHECK(context->IsScriptContext());
10023+
i::Handle<i::ScopeInfo> scope_info(context->scope_info());
10024+
int local_count = scope_info->ContextLocalCount();
10025+
for (int j = 0; j < local_count; ++j) {
10026+
i::String* name = scope_info->ContextLocalName(j);
10027+
if (i::ScopeInfo::VariableIsSynthetic(name)) continue;
10028+
names->Append(Utils::ToLocal(handle(name)));
10029+
}
10030+
}
10031+
}
10032+
1001410033
Local<String> CpuProfileNode::GetFunctionName() const {
1001510034
const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
1001610035
i::Isolate* isolate = node->isolate();

deps/v8/src/debug/debug-interface.h

+3
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ void QueryObjects(v8::Local<v8::Context> context,
401401
QueryObjectPredicate* predicate,
402402
v8::PersistentValueVector<v8::Object>* objects);
403403

404+
void GlobalLexicalScopeNames(v8::Local<v8::Context> context,
405+
v8::PersistentValueVector<v8::String>* names);
406+
404407
} // namespace debug
405408
} // namespace v8
406409

deps/v8/src/inspector/js_protocol.json

+11
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,17 @@
353353
{ "name": "objects", "$ref": "RemoteObject", "description": "Array with objects." }
354354
],
355355
"experimental": true
356+
},
357+
{
358+
"name": "globalLexicalScopeNames",
359+
"parameters": [
360+
{ "name": "executionContextId", "$ref": "ExecutionContextId", "optional": true, "description": "Specifies in which execution context to lookup global scope variables." }
361+
],
362+
"returns": [
363+
{ "name": "names", "type": "array", "items": { "type": "string" } }
364+
],
365+
"description": "Returns all let, const and class variables from global scope.",
366+
"experimental": true
356367
}
357368
],
358369
"events": [

deps/v8/src/inspector/v8-runtime-agent-impl.cc

+21
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,27 @@ Response V8RuntimeAgentImpl::queryObjects(
537537
resultArray, scope.objectGroupName(), false, false, objects);
538538
}
539539

540+
Response V8RuntimeAgentImpl::globalLexicalScopeNames(
541+
Maybe<int> executionContextId,
542+
std::unique_ptr<protocol::Array<String16>>* outNames) {
543+
int contextId = 0;
544+
Response response = ensureContext(m_inspector, m_session->contextGroupId(),
545+
std::move(executionContextId), &contextId);
546+
if (!response.isSuccess()) return response;
547+
548+
InjectedScript::ContextScope scope(m_session, contextId);
549+
response = scope.initialize();
550+
if (!response.isSuccess()) return response;
551+
552+
v8::PersistentValueVector<v8::String> names(m_inspector->isolate());
553+
v8::debug::GlobalLexicalScopeNames(scope.context(), &names);
554+
*outNames = protocol::Array<String16>::create();
555+
for (size_t i = 0; i < names.Size(); ++i) {
556+
(*outNames)->addItem(toProtocolString(names.Get(i)));
557+
}
558+
return Response::OK();
559+
}
560+
540561
void V8RuntimeAgentImpl::restore() {
541562
if (!m_state->booleanProperty(V8RuntimeAgentImplState::runtimeEnabled, false))
542563
return;

deps/v8/src/inspector/v8-runtime-agent-impl.h

+3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ class V8RuntimeAgentImpl : public protocol::Runtime::Backend {
100100
Response queryObjects(
101101
const String16& prototypeObjectId,
102102
std::unique_ptr<protocol::Runtime::RemoteObject>* objects) override;
103+
Response globalLexicalScopeNames(
104+
Maybe<int> executionContextId,
105+
std::unique_ptr<protocol::Array<String16>>* outNames) override;
103106

104107
void reset();
105108
void reportExecutionContextCreated(InspectedContext*);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
Test for Runtime.globalLexicalScopeVariablesNames
2+
Running 'let a = 1'
3+
Values:
4+
a = 1
5+
6+
Running 'let b = 2'
7+
Values:
8+
a = 1
9+
b = 2
10+
11+
Running 'let b = 3'
12+
Values:
13+
a = 1
14+
b = 2
15+
16+
Running 'const c = 4'
17+
Values:
18+
a = 1
19+
b = 2
20+
c = 4
21+
22+
Running 'var d = 5'
23+
(should not be in list of scoped variables)
24+
Values:
25+
a = 1
26+
b = 2
27+
c = 4
28+
29+
Running 'class Foo{}'
30+
Values:
31+
a = 1
32+
b = 2
33+
c = 4
34+
Foo =
35+
{
36+
className : Function
37+
description : class Foo{}
38+
objectId : <objectId>
39+
type : function
40+
}
41+
42+
Adding script with scope variables
43+
Values:
44+
a = 1
45+
b = 2
46+
c = 4
47+
Foo =
48+
{
49+
className : Function
50+
description : class Foo{}
51+
objectId : <objectId>
52+
type : function
53+
}
54+
e = 1
55+
f = 2
56+
g = 3
57+
Boo =
58+
{
59+
className : Function
60+
description : class Boo {}
61+
objectId : <objectId>
62+
type : function
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2017 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
let {session, contextGroup, Protocol} =
6+
InspectorTest.start('Test for Runtime.globalLexicalScopeVariablesNames');
7+
8+
(async function test() {
9+
InspectorTest.log('Running \'let a = 1\'');
10+
Protocol.Runtime.evaluate({expression: 'let a = 1'});
11+
await dumpGlobalScopeVariables();
12+
13+
InspectorTest.log('Running \'let b = 2\'');
14+
Protocol.Runtime.evaluate({expression: 'let b = 2'});
15+
await dumpGlobalScopeVariables();
16+
17+
InspectorTest.log('Running \'let b = 3\'');
18+
Protocol.Runtime.evaluate({expression: 'let b = 3'});
19+
await dumpGlobalScopeVariables();
20+
21+
InspectorTest.log('Running \'const c = 4\'');
22+
Protocol.Runtime.evaluate({expression: 'const c = 4'});
23+
await dumpGlobalScopeVariables();
24+
25+
InspectorTest.log('Running \'var d = 5\'');
26+
InspectorTest.log('(should not be in list of scoped variables)');
27+
Protocol.Runtime.evaluate({expression: 'var d = 5'});
28+
await dumpGlobalScopeVariables();
29+
30+
InspectorTest.log('Running \'class Foo{}\'');
31+
Protocol.Runtime.evaluate({expression: 'class Foo{}'});
32+
await dumpGlobalScopeVariables();
33+
34+
InspectorTest.log('Adding script with scope variables');
35+
contextGroup.addScript(`
36+
let e = 1;
37+
const f = 2;
38+
const g = 3;
39+
class Boo {};
40+
`);
41+
await dumpGlobalScopeVariables();
42+
InspectorTest.completeTest();
43+
})();
44+
45+
async function dumpGlobalScopeVariables() {
46+
let {result:{names}} =
47+
await Protocol.Runtime.globalLexicalScopeNames();
48+
InspectorTest.log('Values:');
49+
for (let name of names) {
50+
let {result:{result}} = await Protocol.Runtime.evaluate({expression: name});
51+
if (result.value) {
52+
InspectorTest.log(`${name} = ${result.value}`);
53+
} else {
54+
InspectorTest.log(`${name} =`);
55+
InspectorTest.logMessage(result);
56+
}
57+
}
58+
InspectorTest.log('');
59+
}

deps/v8/test/inspector/runtime/runtime-restore.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright 2017 the V8 project authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
3-
// found in the LICENSE file.v8
3+
// found in the LICENSE file.
44

55
let {session, contextGroup, Protocol} = InspectorTest.start('Checks that Runtime agent correctly restore its state.');
66

0 commit comments

Comments
 (0)