Runtime.callFunctionOn supports uniqueContextId
Bug: v8:13620 Change-Id: I802deb3325a5c8ac9e7e378d60be591af66e6fee Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4126215 Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Commit-Queue: Vladimir Nechaev <nechaev@chromium.org> Cr-Commit-Position: refs/heads/main@{#85027}
This commit is contained in:
parent
dff5fc1b23
commit
28cb67cdec
@ -1402,6 +1402,13 @@ domain Runtime
|
|||||||
optional string objectGroup
|
optional string objectGroup
|
||||||
# Whether to throw an exception if side effect cannot be ruled out during evaluation.
|
# Whether to throw an exception if side effect cannot be ruled out during evaluation.
|
||||||
experimental optional boolean throwOnSideEffect
|
experimental optional boolean throwOnSideEffect
|
||||||
|
# An alternative way to specify the execution context to call function on.
|
||||||
|
# Compared to contextId that may be reused across processes, this is guaranteed to be
|
||||||
|
# system-unique, so it can be used to prevent accidental function call
|
||||||
|
# in context different than intended (e.g. as a result of navigation across process
|
||||||
|
# boundaries).
|
||||||
|
# This is mutually exclusive with `executionContextId`.
|
||||||
|
experimental optional string uniqueContextId
|
||||||
# Whether the result should contain `webDriverValue`, serialized according to
|
# Whether the result should contain `webDriverValue`, serialized according to
|
||||||
# https://w3c.github.io/webdriver-bidi. This is mutually exclusive with `returnByValue`, but
|
# https://w3c.github.io/webdriver-bidi. This is mutually exclusive with `returnByValue`, but
|
||||||
# resulting `objectId` is still provided.
|
# resulting `objectId` is still provided.
|
||||||
|
@ -375,16 +375,22 @@ void V8RuntimeAgentImpl::callFunctionOn(
|
|||||||
Maybe<bool> silent, Maybe<bool> returnByValue, Maybe<bool> generatePreview,
|
Maybe<bool> silent, Maybe<bool> returnByValue, Maybe<bool> generatePreview,
|
||||||
Maybe<bool> userGesture, Maybe<bool> awaitPromise,
|
Maybe<bool> userGesture, Maybe<bool> awaitPromise,
|
||||||
Maybe<int> executionContextId, Maybe<String16> objectGroup,
|
Maybe<int> executionContextId, Maybe<String16> objectGroup,
|
||||||
Maybe<bool> throwOnSideEffect, Maybe<bool> generateWebDriverValue,
|
Maybe<bool> throwOnSideEffect, Maybe<String16> uniqueContextId,
|
||||||
|
Maybe<bool> generateWebDriverValue,
|
||||||
std::unique_ptr<CallFunctionOnCallback> callback) {
|
std::unique_ptr<CallFunctionOnCallback> callback) {
|
||||||
if (objectId.isJust() && executionContextId.isJust()) {
|
int justCount = (objectId.isJust() ? 1 : 0) +
|
||||||
callback->sendFailure(Response::ServerError(
|
(executionContextId.isJust() ? 1 : 0) +
|
||||||
"ObjectId must not be specified together with executionContextId"));
|
(uniqueContextId.isJust() ? 1 : 0);
|
||||||
|
if (justCount > 1) {
|
||||||
|
callback->sendFailure(Response::InvalidParams(
|
||||||
|
"ObjectId, executionContextId and uniqueContextId must mutually "
|
||||||
|
"exclude each other"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!objectId.isJust() && !executionContextId.isJust()) {
|
if (justCount < 1) {
|
||||||
callback->sendFailure(Response::ServerError(
|
callback->sendFailure(
|
||||||
"Either ObjectId or executionContextId must be specified"));
|
Response::InvalidParams("Either objectId or executionContextId or "
|
||||||
|
"uniqueContextId must be specified"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
WrapMode wrap_mode = generatePreview.fromMaybe(false) ? WrapMode::kWithPreview
|
WrapMode wrap_mode = generatePreview.fromMaybe(false) ? WrapMode::kWithPreview
|
||||||
@ -409,8 +415,8 @@ void V8RuntimeAgentImpl::callFunctionOn(
|
|||||||
} else {
|
} else {
|
||||||
int contextId = 0;
|
int contextId = 0;
|
||||||
Response response = ensureContext(m_inspector, m_session->contextGroupId(),
|
Response response = ensureContext(m_inspector, m_session->contextGroupId(),
|
||||||
std::move(executionContextId.fromJust()),
|
std::move(executionContextId),
|
||||||
/* uniqueContextId */ {}, &contextId);
|
std::move(uniqueContextId), &contextId);
|
||||||
if (!response.IsSuccess()) {
|
if (!response.IsSuccess()) {
|
||||||
callback->sendFailure(response);
|
callback->sendFailure(response);
|
||||||
return;
|
return;
|
||||||
|
@ -89,7 +89,7 @@ class V8RuntimeAgentImpl : public protocol::Runtime::Backend {
|
|||||||
Maybe<bool> generatePreview, Maybe<bool> userGesture,
|
Maybe<bool> generatePreview, Maybe<bool> userGesture,
|
||||||
Maybe<bool> awaitPromise, Maybe<int> executionContextId,
|
Maybe<bool> awaitPromise, Maybe<int> executionContextId,
|
||||||
Maybe<String16> objectGroup, Maybe<bool> throwOnSideEffect,
|
Maybe<String16> objectGroup, Maybe<bool> throwOnSideEffect,
|
||||||
Maybe<bool> generateWebDriverValue,
|
Maybe<String16> uniqueContextId, Maybe<bool> generateWebDriverValue,
|
||||||
std::unique_ptr<CallFunctionOnCallback>) override;
|
std::unique_ptr<CallFunctionOnCallback>) override;
|
||||||
Response releaseObject(const String16& objectId) override;
|
Response releaseObject(const String16& objectId) override;
|
||||||
Response getProperties(
|
Response getProperties(
|
||||||
|
@ -208,11 +208,50 @@ Running test: testEvaluateOnExecutionContext
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Running test: testEvaluateOnUniqueExecutionContext
|
||||||
|
{
|
||||||
|
id : <messageId>
|
||||||
|
result : {
|
||||||
|
result : {
|
||||||
|
description : 70
|
||||||
|
type : number
|
||||||
|
value : 70
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Running test: testPassingBothObjectIdAndExecutionContextId
|
Running test: testPassingBothObjectIdAndExecutionContextId
|
||||||
{
|
{
|
||||||
error : {
|
error : {
|
||||||
code : -32000
|
code : -32602
|
||||||
message : ObjectId must not be specified together with executionContextId
|
message : ObjectId, executionContextId and uniqueContextId must mutually exclude each other
|
||||||
|
}
|
||||||
|
id : <messageId>
|
||||||
|
}
|
||||||
|
|
||||||
|
Running test: testPassingBothObjectIdAndExecutionContextUniqueId
|
||||||
|
{
|
||||||
|
error : {
|
||||||
|
code : -32602
|
||||||
|
message : ObjectId, executionContextId and uniqueContextId must mutually exclude each other
|
||||||
|
}
|
||||||
|
id : <messageId>
|
||||||
|
}
|
||||||
|
|
||||||
|
Running test: testPassingTwoExecutionContextIds
|
||||||
|
{
|
||||||
|
error : {
|
||||||
|
code : -32602
|
||||||
|
message : ObjectId, executionContextId and uniqueContextId must mutually exclude each other
|
||||||
|
}
|
||||||
|
id : <messageId>
|
||||||
|
}
|
||||||
|
|
||||||
|
Running test: testPassingNeitherContextIdNorObjectId
|
||||||
|
{
|
||||||
|
error : {
|
||||||
|
code : -32602
|
||||||
|
message : Either objectId or executionContextId or uniqueContextId must be specified
|
||||||
}
|
}
|
||||||
id : <messageId>
|
id : <messageId>
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,12 @@ let callFunctionOn = Protocol.Runtime.callFunctionOn.bind(Protocol.Runtime);
|
|||||||
let remoteObject1;
|
let remoteObject1;
|
||||||
let remoteObject2;
|
let remoteObject2;
|
||||||
let executionContextId;
|
let executionContextId;
|
||||||
|
let executionContextUniqueId;
|
||||||
|
|
||||||
Protocol.Runtime.enable();
|
Protocol.Runtime.enable();
|
||||||
Protocol.Runtime.onExecutionContextCreated(messageObject => {
|
Protocol.Runtime.onExecutionContextCreated(messageObject => {
|
||||||
executionContextId = messageObject.params.context.id;
|
executionContextId = messageObject.params.context.id;
|
||||||
|
executionContextUniqueId = messageObject.params.context.uniqueId;
|
||||||
InspectorTest.runAsyncTestSuite(testSuite);
|
InspectorTest.runAsyncTestSuite(testSuite);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -135,15 +137,52 @@ let testSuite = [
|
|||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async function testEvaluateOnUniqueExecutionContext() {
|
||||||
|
InspectorTest.logMessage(await callFunctionOn({
|
||||||
|
uniqueContextId: executionContextUniqueId,
|
||||||
|
functionDeclaration: '(function(arg) { return this.globalObjectProperty + arg; })',
|
||||||
|
arguments: prepareArguments([ 28 ]),
|
||||||
|
returnByValue: true,
|
||||||
|
generatePreview: false,
|
||||||
|
awaitPromise: false
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
|
||||||
async function testPassingBothObjectIdAndExecutionContextId() {
|
async function testPassingBothObjectIdAndExecutionContextId() {
|
||||||
InspectorTest.logMessage(await callFunctionOn({
|
InspectorTest.logMessage(await callFunctionOn({
|
||||||
executionContextId,
|
executionContextId,
|
||||||
objectId: remoteObject1.objectId,
|
objectId: remoteObject1.objectId,
|
||||||
functionDeclaration: '(function() { return 42; })',
|
functionDeclaration: '(function() { return 42; })',
|
||||||
arguments: prepareArguments([]),
|
arguments: prepareArguments([]),
|
||||||
returnByValue: true,
|
returnByValue: true
|
||||||
generatePreview: false,
|
}));
|
||||||
awaitPromise: false
|
},
|
||||||
|
|
||||||
|
async function testPassingBothObjectIdAndExecutionContextUniqueId() {
|
||||||
|
InspectorTest.logMessage(await callFunctionOn({
|
||||||
|
uniqueContextId: executionContextUniqueId,
|
||||||
|
objectId: remoteObject1.objectId,
|
||||||
|
functionDeclaration: '(function() { return 42; })',
|
||||||
|
arguments: prepareArguments([]),
|
||||||
|
returnByValue: true
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
|
||||||
|
async function testPassingTwoExecutionContextIds() {
|
||||||
|
InspectorTest.logMessage(await callFunctionOn({
|
||||||
|
executionContextId,
|
||||||
|
uniqueContextId: executionContextUniqueId,
|
||||||
|
functionDeclaration: '(function() { return 42; })',
|
||||||
|
arguments: prepareArguments([]),
|
||||||
|
returnByValue: true
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
|
||||||
|
async function testPassingNeitherContextIdNorObjectId() {
|
||||||
|
InspectorTest.logMessage(await callFunctionOn({
|
||||||
|
functionDeclaration: '(function() { return 42; })',
|
||||||
|
arguments: prepareArguments([]),
|
||||||
|
returnByValue: true
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user