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.
R=dgozman@chromium.org,jgruber@chromium.org
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 <kozyatinskiy@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48618}
Refs: 50f7455cd9
PR-URL: https://github.com/nodejs/node/pull/16591
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
d50e1a2916
commit
d1d6b54b69
@ -27,7 +27,7 @@
|
||||
|
||||
# Reset this number to 0 on major V8 upgrades.
|
||||
# Increment by one for each non-official patch applied to deps/v8.
|
||||
'v8_embedder_string': '-node.3',
|
||||
'v8_embedder_string': '-node.4',
|
||||
|
||||
# Enable disassembler for `--print-code` v8 options
|
||||
'v8_enable_disassembler': 1,
|
||||
|
19
deps/v8/src/api.cc
vendored
19
deps/v8/src/api.cc
vendored
@ -10172,6 +10172,25 @@ void debug::QueryObjects(v8::Local<v8::Context> v8_context,
|
||||
predicate, objects);
|
||||
}
|
||||
|
||||
void debug::GlobalLexicalScopeNames(
|
||||
v8::Local<v8::Context> v8_context,
|
||||
v8::PersistentValueVector<v8::String>* names) {
|
||||
i::Handle<i::Context> context = Utils::OpenHandle(*v8_context);
|
||||
i::Handle<i::ScriptContextTable> table(
|
||||
context->global_object()->native_context()->script_context_table());
|
||||
for (int i = 0; i < table->used(); i++) {
|
||||
i::Handle<i::Context> context = i::ScriptContextTable::GetContext(table, i);
|
||||
DCHECK(context->IsScriptContext());
|
||||
i::Handle<i::ScopeInfo> scope_info(context->scope_info());
|
||||
int local_count = scope_info->ContextLocalCount();
|
||||
for (int j = 0; j < local_count; ++j) {
|
||||
i::String* name = scope_info->ContextLocalName(j);
|
||||
if (i::ScopeInfo::VariableIsSynthetic(name)) continue;
|
||||
names->Append(Utils::ToLocal(handle(name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Local<String> CpuProfileNode::GetFunctionName() const {
|
||||
const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
|
||||
i::Isolate* isolate = node->isolate();
|
||||
|
3
deps/v8/src/debug/debug-interface.h
vendored
3
deps/v8/src/debug/debug-interface.h
vendored
@ -482,6 +482,9 @@ void QueryObjects(v8::Local<v8::Context> context,
|
||||
QueryObjectPredicate* predicate,
|
||||
v8::PersistentValueVector<v8::Object>* objects);
|
||||
|
||||
void GlobalLexicalScopeNames(v8::Local<v8::Context> context,
|
||||
v8::PersistentValueVector<v8::String>* names);
|
||||
|
||||
} // namespace debug
|
||||
} // namespace v8
|
||||
|
||||
|
11
deps/v8/src/inspector/js_protocol.json
vendored
11
deps/v8/src/inspector/js_protocol.json
vendored
@ -355,6 +355,17 @@
|
||||
{ "name": "objects", "$ref": "RemoteObject", "description": "Array with objects." }
|
||||
],
|
||||
"experimental": true
|
||||
},
|
||||
{
|
||||
"name": "globalLexicalScopeNames",
|
||||
"parameters": [
|
||||
{ "name": "executionContextId", "$ref": "ExecutionContextId", "optional": true, "description": "Specifies in which execution context to lookup global scope variables." }
|
||||
],
|
||||
"returns": [
|
||||
{ "name": "names", "type": "array", "items": { "type": "string" } }
|
||||
],
|
||||
"description": "Returns all let, const and class variables from global scope.",
|
||||
"experimental": true
|
||||
}
|
||||
],
|
||||
"events": [
|
||||
|
21
deps/v8/src/inspector/v8-runtime-agent-impl.cc
vendored
21
deps/v8/src/inspector/v8-runtime-agent-impl.cc
vendored
@ -586,6 +586,27 @@ Response V8RuntimeAgentImpl::queryObjects(
|
||||
resultArray, scope.objectGroupName(), false, false, objects);
|
||||
}
|
||||
|
||||
Response V8RuntimeAgentImpl::globalLexicalScopeNames(
|
||||
Maybe<int> executionContextId,
|
||||
std::unique_ptr<protocol::Array<String16>>* outNames) {
|
||||
int contextId = 0;
|
||||
Response response = ensureContext(m_inspector, m_session->contextGroupId(),
|
||||
std::move(executionContextId), &contextId);
|
||||
if (!response.isSuccess()) return response;
|
||||
|
||||
InjectedScript::ContextScope scope(m_session, contextId);
|
||||
response = scope.initialize();
|
||||
if (!response.isSuccess()) return response;
|
||||
|
||||
v8::PersistentValueVector<v8::String> names(m_inspector->isolate());
|
||||
v8::debug::GlobalLexicalScopeNames(scope.context(), &names);
|
||||
*outNames = protocol::Array<String16>::create();
|
||||
for (size_t i = 0; i < names.Size(); ++i) {
|
||||
(*outNames)->addItem(toProtocolString(names.Get(i)));
|
||||
}
|
||||
return Response::OK();
|
||||
}
|
||||
|
||||
void V8RuntimeAgentImpl::restore() {
|
||||
if (!m_state->booleanProperty(V8RuntimeAgentImplState::runtimeEnabled, false))
|
||||
return;
|
||||
|
@ -101,6 +101,9 @@ class V8RuntimeAgentImpl : public protocol::Runtime::Backend {
|
||||
Response queryObjects(
|
||||
const String16& prototypeObjectId,
|
||||
std::unique_ptr<protocol::Runtime::RemoteObject>* objects) override;
|
||||
Response globalLexicalScopeNames(
|
||||
Maybe<int> executionContextId,
|
||||
std::unique_ptr<protocol::Array<String16>>* outNames) override;
|
||||
|
||||
void reset();
|
||||
void reportExecutionContextCreated(InspectedContext*);
|
||||
|
64
deps/v8/test/inspector/runtime/runtime-global-lexical-scope-names-expected.txt
vendored
Normal file
64
deps/v8/test/inspector/runtime/runtime-global-lexical-scope-names-expected.txt
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
Test for Runtime.globalLexicalScopeVariablesNames
|
||||
Running 'let a = 1'
|
||||
Values:
|
||||
a = 1
|
||||
|
||||
Running 'let b = 2'
|
||||
Values:
|
||||
a = 1
|
||||
b = 2
|
||||
|
||||
Running 'let b = 3'
|
||||
Values:
|
||||
a = 1
|
||||
b = 2
|
||||
|
||||
Running 'const c = 4'
|
||||
Values:
|
||||
a = 1
|
||||
b = 2
|
||||
c = 4
|
||||
|
||||
Running 'var d = 5'
|
||||
(should not be in list of scoped variables)
|
||||
Values:
|
||||
a = 1
|
||||
b = 2
|
||||
c = 4
|
||||
|
||||
Running 'class Foo{}'
|
||||
Values:
|
||||
a = 1
|
||||
b = 2
|
||||
c = 4
|
||||
Foo =
|
||||
{
|
||||
className : Function
|
||||
description : class Foo{}
|
||||
objectId : <objectId>
|
||||
type : function
|
||||
}
|
||||
|
||||
Adding script with scope variables
|
||||
Values:
|
||||
a = 1
|
||||
b = 2
|
||||
c = 4
|
||||
Foo =
|
||||
{
|
||||
className : Function
|
||||
description : class Foo{}
|
||||
objectId : <objectId>
|
||||
type : function
|
||||
}
|
||||
e = 1
|
||||
f = 2
|
||||
g = 3
|
||||
Boo =
|
||||
{
|
||||
className : Function
|
||||
description : class Boo {}
|
||||
objectId : <objectId>
|
||||
type : function
|
||||
}
|
||||
|
59
deps/v8/test/inspector/runtime/runtime-global-lexical-scope-names.js
vendored
Normal file
59
deps/v8/test/inspector/runtime/runtime-global-lexical-scope-names.js
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
// Copyright 2017 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
let {session, contextGroup, Protocol} =
|
||||
InspectorTest.start('Test for Runtime.globalLexicalScopeVariablesNames');
|
||||
|
||||
(async function test() {
|
||||
InspectorTest.log('Running \'let a = 1\'');
|
||||
Protocol.Runtime.evaluate({expression: 'let a = 1'});
|
||||
await dumpGlobalScopeVariables();
|
||||
|
||||
InspectorTest.log('Running \'let b = 2\'');
|
||||
Protocol.Runtime.evaluate({expression: 'let b = 2'});
|
||||
await dumpGlobalScopeVariables();
|
||||
|
||||
InspectorTest.log('Running \'let b = 3\'');
|
||||
Protocol.Runtime.evaluate({expression: 'let b = 3'});
|
||||
await dumpGlobalScopeVariables();
|
||||
|
||||
InspectorTest.log('Running \'const c = 4\'');
|
||||
Protocol.Runtime.evaluate({expression: 'const c = 4'});
|
||||
await dumpGlobalScopeVariables();
|
||||
|
||||
InspectorTest.log('Running \'var d = 5\'');
|
||||
InspectorTest.log('(should not be in list of scoped variables)');
|
||||
Protocol.Runtime.evaluate({expression: 'var d = 5'});
|
||||
await dumpGlobalScopeVariables();
|
||||
|
||||
InspectorTest.log('Running \'class Foo{}\'');
|
||||
Protocol.Runtime.evaluate({expression: 'class Foo{}'});
|
||||
await dumpGlobalScopeVariables();
|
||||
|
||||
InspectorTest.log('Adding script with scope variables');
|
||||
contextGroup.addScript(`
|
||||
let e = 1;
|
||||
const f = 2;
|
||||
const g = 3;
|
||||
class Boo {};
|
||||
`);
|
||||
await dumpGlobalScopeVariables();
|
||||
InspectorTest.completeTest();
|
||||
})();
|
||||
|
||||
async function dumpGlobalScopeVariables() {
|
||||
let {result:{names}} =
|
||||
await Protocol.Runtime.globalLexicalScopeNames();
|
||||
InspectorTest.log('Values:');
|
||||
for (let name of names) {
|
||||
let {result:{result}} = await Protocol.Runtime.evaluate({expression: name});
|
||||
if (result.value) {
|
||||
InspectorTest.log(`${name} = ${result.value}`);
|
||||
} else {
|
||||
InspectorTest.log(`${name} =`);
|
||||
InspectorTest.logMessage(result);
|
||||
}
|
||||
}
|
||||
InspectorTest.log('');
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
// Copyright 2017 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.v8
|
||||
// found in the LICENSE file.
|
||||
|
||||
let {session, contextGroup, Protocol} = InspectorTest.start('Checks that Runtime agent correctly restore its state.');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user