Commit e63f35bc authored by Alexey Kozyatinskiy's avatar Alexey Kozyatinskiy Committed by Commit Bot

[inspector] add optional executionContextId arg to Runtime.addBinding

If executionContextId then binding is installed only once in given
context.

R=pfeldman@chromium.org

Bug: chromium:849552
Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I474fcf9ad5e704b0a12c9aaa321cc90bb7957e2c
Reviewed-on: https://chromium-review.googlesource.com/1087489
Commit-Queue: Pavel Feldman <pfeldman@chromium.org>
Reviewed-by: 's avatarPavel Feldman <pfeldman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53538}
parent 62620a42
......@@ -2861,14 +2861,14 @@
{
"name": "setAsyncCallStackDepth",
"description": "Enables or disables async call stacks tracking.",
"redirect": "Debugger",
"parameters": [
{
"name": "maxDepth",
"description": "Maximum depth of async call stacks. Setting to `0` will effectively disable collecting async\ncall stacks (default).",
"type": "integer"
}
],
"redirect": "Debugger"
]
},
{
"name": "setCustomObjectFormatterEnabled",
......@@ -2897,12 +2897,17 @@
},
{
"name": "addBinding",
"description": "Adds binding with the given name on the global objects of all inspected\ncontexts, including those created later. Bindings survive reloads.\nBinding function takes exactly one argument, this argument should be string,\nin case of any other input, function throws an exception.\nEach binding function call produces Runtime.bindingCalled notification.",
"description": "If executionContextId is empty, adds binding with the given name on the\nglobal objects of all inspected contexts, including those created later,\nbindings survive reloads.\nIf executionContextId is specified, adds binding only on global object of\ngiven execution context.\nBinding function takes exactly one argument, this argument should be string,\nin case of any other input, function throws an exception.\nEach binding function call produces Runtime.bindingCalled notification.",
"experimental": true,
"parameters": [
{
"name": "name",
"type": "string"
},
{
"name": "executionContextId",
"optional": true,
"$ref": "ExecutionContextId"
}
]
},
......@@ -3115,4 +3120,4 @@
]
}
]
}
}
\ No newline at end of file
......@@ -1334,14 +1334,18 @@ domain Runtime
# Will cancel the termination when the outer-most script execution ends.
experimental command terminateExecution
# Adds binding with the given name on the global objects of all inspected
# contexts, including those created later. Bindings survive reloads.
# If executionContextId is empty, adds binding with the given name on the
# global objects of all inspected contexts, including those created later,
# bindings survive reloads.
# If executionContextId is specified, adds binding only on global object of
# given execution context.
# Binding function takes exactly one argument, this argument should be string,
# in case of any other input, function throws an exception.
# Each binding function call produces Runtime.bindingCalled notification.
experimental command addBinding
parameters
string name
optional ExecutionContextId executionContextId
# This method does not remove binding function from global object but
# unsubscribes current runtime agent from Runtime.bindingCalled notifications.
......
......@@ -648,13 +648,28 @@ void V8RuntimeAgentImpl::terminateExecution(
m_inspector->debugger()->terminateExecution(std::move(callback));
}
Response V8RuntimeAgentImpl::addBinding(const String16& name) {
Response V8RuntimeAgentImpl::addBinding(const String16& name,
Maybe<int> executionContextId) {
if (!m_state->getObject(V8RuntimeAgentImplState::bindings)) {
m_state->setObject(V8RuntimeAgentImplState::bindings,
protocol::DictionaryValue::create());
}
protocol::DictionaryValue* bindings =
m_state->getObject(V8RuntimeAgentImplState::bindings);
if (bindings->booleanProperty(name, false)) return Response::OK();
if (executionContextId.isJust()) {
int contextId = executionContextId.fromJust();
InspectedContext* context =
m_inspector->getContext(m_session->contextGroupId(), contextId);
if (!context) {
return Response::Error(
"Cannot find execution context with given executionContextId");
}
addBinding(context, name);
// false means that we should not add this binding later.
bindings->setBoolean(name, false);
return Response::OK();
}
bindings->setBoolean(name, true);
m_inspector->forEachContext(
m_session->contextGroupId(),
......@@ -714,7 +729,7 @@ void V8RuntimeAgentImpl::bindingCalled(const String16& name,
int executionContextId) {
protocol::DictionaryValue* bindings =
m_state->getObject(V8RuntimeAgentImplState::bindings);
if (!bindings || !bindings->booleanProperty(name, false)) return;
if (!bindings || !bindings->get(name)) return;
m_frontend.bindingCalled(name, payload, executionContextId);
}
......@@ -724,6 +739,7 @@ void V8RuntimeAgentImpl::addBindings(InspectedContext* context) {
m_state->getObject(V8RuntimeAgentImplState::bindings);
if (!bindings) return;
for (size_t i = 0; i < bindings->size(); ++i) {
if (!bindings->at(i).second) continue;
addBinding(context, bindings->at(i).first);
}
}
......
......@@ -111,7 +111,8 @@ class V8RuntimeAgentImpl : public protocol::Runtime::Backend {
void terminateExecution(
std::unique_ptr<TerminateExecutionCallback> callback) override;
Response addBinding(const String16& name) override;
Response addBinding(const String16& name,
Maybe<int> executionContextId) override;
Response removeBinding(const String16& name) override;
void addBindings(InspectedContext* context);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment