script.callFunction clones remote references after deserialization
Categories
(Remote Protocol :: WebDriver BiDi, defect, P1)
Tracking
(firefox107 fixed)
Tracking | Status | |
---|---|---|
firefox107 | --- | fixed |
People
(Reporter: jdescottes, Assigned: jdescottes)
References
Details
(Whiteboard: [webdriver:m5], [wptsync upstream])
Attachments
(2 files, 2 obsolete files)
script.callFunction uses Realm.executeInGlobalWithBindings which will force cloning "this" and "arguments" before evaluating the function declaration: https://searchfox.org/mozilla-central/rev/25ec642ed33ca83f25e88ec0f9f27e8ad8a29e24/remote/webdriver-bidi/Realm.jsm#223-240
executeInGlobalWithBindings(
functionDeclaration,
functionArguments,
thisParameter
) {
const expression = `(${functionDeclaration}).apply(__bidi_this, __bidi_args)`;
return this.#globalObjectReference.executeInGlobalWithBindings(
expression,
{
__bidi_args: this.#cloneAsDebuggerObject(functionArguments),
__bidi_this: this.#cloneAsDebuggerObject(thisParameter),
},
{
url: this.#window.document.baseURI,
}
);
}
This is a problem whenever you are trying to use remote references (ie objects coming from this Realm, identified by a handle) because you should be able to use the original objects, and not a cloned version.
The deserialization algorithm should be responsible for cloning objects "when necessary" into the realm, but should preserve original objects if they are remote references.
An example fix can be found at https://phabricator.services.mozilla.com/D156201
A small example that fails because of this is
remote_value = await bidi_session.script.evaluate(
expression="window.test = {}; window.test",
await_promise=False,
result_ownership="root",
target=ContextTarget(top_context["context"]),
)
result = await bidi_session.script.call_function(
function_declaration="obj => obj === window.test",
await_promise=False,
arguments=[remote_value],
target=ContextTarget(top_context["context"]),
)
assert result == {"type": "boolean", "value": True}
This should pass but since the remote_value gets cloned when we use call_function, the obj === window.test
check will return false.
Assignee | ||
Comment 1•2 years ago
|
||
Depends on D155635
Updated•2 years ago
|
Assignee | ||
Comment 2•2 years ago
|
||
Unassigning until triage.
Updated•2 years ago
|
Comment 3•2 years ago
|
||
We will have to get this fixed for script.callFunctionOn
so that the original object is used and not a clone.
Assignee | ||
Comment 4•2 years ago
|
||
Depends on D156201
Simple autoformatting to avoid unrelated changes in the next changeset
Assignee | ||
Comment 5•2 years ago
|
||
Depends on D156530
Add tests for deserialization of both this and arguments parameters, with various data structures (object, array, map, set) plus an additional test case nesting all
together.
Assignee | ||
Comment 6•2 years ago
|
||
Alternative to D156201
Updated•2 years ago
|
Updated•2 years ago
|
Updated•2 years ago
|
Updated•2 years ago
|
Comment 7•2 years ago
|
||
The severity field is not set for this bug.
:whimboo, could you have a look please?
For more information, please visit auto_nag documentation.
Assignee | ||
Updated•2 years ago
|
Assignee | ||
Updated•2 years ago
|
Comment 8•2 years ago
|
||
This is a M5 bug and should not block the enabling of the script commands by default.
Comment 11•2 years ago
|
||
(In reply to Web Platform Test Sync Bot (Matrix: #interop:mozilla.org) from comment #10)
Failed to create upstream wpt PR due to merge conflicts. This requires fixup
from a wpt sync admin.
This basically happened because bug 1779231 isn't on mozilla-central yet and it's open PR hasn't been merged. James could you please take a look here? Thanks.
Comment 12•2 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/83a729f1fffd
https://hg.mozilla.org/mozilla-central/rev/149ee65a5a38
Updated•2 years ago
|
Description
•