Skip to content

Commit 4d36383

Browse files
Alexey Shvaykawebkit-commit-queue
authored andcommitted
Some WebIDL operations / attributes incorrectly use _current_ realm instead of _relevant_
https://bugs.webkit.org/show_bug.cgi?id=230941 Patch by Alexey Shvayka <[email protected]> on 2021-12-10 Reviewed by Sam Weinig. LayoutTests/imported/w3c: Import WPT tests from web-platform-tests/wpt#32012. * web-platform-tests/dom/events/Event-timestamp-cross-realm-getter-expected.txt: Added. * web-platform-tests/dom/events/Event-timestamp-cross-realm-getter.html: Added. * web-platform-tests/html/browsers/history/the-history-interface/history_back_cross_realm_method-expected.txt: Added. * web-platform-tests/html/browsers/history/the-history-interface/history_back_cross_realm_method.html: Added. * web-platform-tests/html/browsers/history/the-history-interface/history_forward_cross_realm_method-expected.txt: Added. * web-platform-tests/html/browsers/history/the-history-interface/history_forward_cross_realm_method.html: Added. * web-platform-tests/html/browsers/history/the-history-interface/history_go_cross_realm_method-expected.txt: Added. * web-platform-tests/html/browsers/history/the-history-interface/history_go_cross_realm_method.html: Added. * web-platform-tests/html/webappapis/scripting/reporterror-cross-realm-method-expected.txt: Added. * web-platform-tests/html/webappapis/scripting/reporterror-cross-realm-method.html: Added. * web-platform-tests/html/webappapis/structured-clone/structured-clone-cross-realm-method-expected.txt: Added. * web-platform-tests/html/webappapis/structured-clone/structured-clone-cross-realm-method.html: Added. * web-platform-tests/requestidlecallback/callback-timeRemaining-cross-realm-method-expected.txt: Added. * web-platform-tests/requestidlecallback/callback-timeRemaining-cross-realm-method.html: Added. Source/WebCore: This patch replaces _current_ global object with _relevant_, as per recommendation for spec authors [1], for select WebIDL operations / attributes that satisfy all the following conditions: 1) it's an instance member: static ones and constructors can't use _relevant_; 2) it's on standards track (not deprecated / WebKit-only / internal); 3) the change is directly observable: global object is used for something beyond lifecycle / event loop / parsing CSS etc; 4) the change either aligns WebKit with both Blink and Gecko, or the spec explicitly requires _relevant_ realm / settings object. Most of the remaining [CallWith=GlobalObject] instances are correctly used for converting JS arguments to WebIDL values; the rest, along with _current_ Document and ScriptExecutionContext, either match the spec or replacing them with _relevant_ global object is not directly observable (see condition #3). This change is aimed at fixing web-exposed APIs rather than performing a global cleanup. [1] https://html.spec.whatwg.org/multipage/webappapis.html#concept-current-everything Tests: imported/w3c/web-platform-tests/dom/events/Event-timestamp-cross-realm-getter.html imported/w3c/web-platform-tests/html/browsers/history/the-history-interface/history_back_cross_realm_method.html imported/w3c/web-platform-tests/html/browsers/history/the-history-interface/history_forward_cross_realm_method.html imported/w3c/web-platform-tests/html/browsers/history/the-history-interface/history_go_cross_realm_method.html imported/w3c/web-platform-tests/html/webappapis/scripting/reporterror-cross-realm-method.html imported/w3c/web-platform-tests/html/webappapis/structured-clone/structured-clone-cross-realm-method.html imported/w3c/web-platform-tests/requestidlecallback/callback-timeRemaining-cross-realm-method.html * Modules/indexeddb/IDBFactory.idl: https://www.w3.org/TR/IndexedDB/#dom-idbfactory-open (step 2) https://www.w3.org/TR/IndexedDB/#dom-idbfactory-deletedatabase (step 1) https://www.w3.org/TR/IndexedDB/#dom-idbfactory-databases (step 1) * Modules/paymentrequest/PaymentRequest.idl: https://www.w3.org/TR/payment-request/#show-method (steps 2-4) https://www.w3.org/TR/payment-request/#can-make-payment-algorithm (before step 1) * bindings/scripts/CodeGeneratorJS.pm: (GenerateCallWith): * bindings/scripts/IDLAttributes.json: * bindings/scripts/test/JS/JSTestObj.cpp: * bindings/scripts/test/TestObj.idl: * dom/Event.idl: https://dom.spec.whatwg.org/#inner-event-creation-steps (step 3) * dom/IdleDeadline.idl: https://w3c.github.io/requestidlecallback/#the-requestidlecallback-method (step 1) * page/History.idl: https://html.spec.whatwg.org/multipage/history.html#dom-history-go (step 1) https://html.spec.whatwg.org/multipage/history.html#dom-history-back (step 1) https://html.spec.whatwg.org/multipage/history.html#dom-history-forward (step 1) * page/DOMWindow.cpp: (WebCore::DOMWindow::setTimeout): (WebCore::DOMWindow::setInterval): * page/DOMWindow.h: * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::setTimeout): (WebCore::WorkerGlobalScope::setInterval): * workers/WorkerGlobalScope.h: Although condition #4 isn't satisfied for setTimeout() / setInterval() because _current_ global object is used only for logging, replacing it with _relevant_ nicely cleans up method signatures. * page/WindowOrWorkerGlobalScope.cpp: (WebCore::WindowOrWorkerGlobalScope::structuredClone): * page/WindowOrWorkerGlobalScope.h: * page/WindowOrWorkerGlobalScope.idl: https://html.spec.whatwg.org/multipage/webappapis.html#report-the-exception https://html.spec.whatwg.org/multipage/structured-data.html#structured-cloning (step 2) Canonical link: https://commits.webkit.org/245123@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@286895 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 131cc3c commit 4d36383

32 files changed

+434
-33
lines changed

LayoutTests/imported/w3c/ChangeLog

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
2021-12-10 Alexey Shvayka <[email protected]>
2+
3+
Some WebIDL operations / attributes incorrectly use _current_ realm instead of _relevant_
4+
https://bugs.webkit.org/show_bug.cgi?id=230941
5+
6+
Reviewed by Sam Weinig.
7+
8+
Import WPT tests from https://github.com/web-platform-tests/wpt/pull/32012.
9+
10+
* web-platform-tests/dom/events/Event-timestamp-cross-realm-getter-expected.txt: Added.
11+
* web-platform-tests/dom/events/Event-timestamp-cross-realm-getter.html: Added.
12+
* web-platform-tests/html/browsers/history/the-history-interface/history_back_cross_realm_method-expected.txt: Added.
13+
* web-platform-tests/html/browsers/history/the-history-interface/history_back_cross_realm_method.html: Added.
14+
* web-platform-tests/html/browsers/history/the-history-interface/history_forward_cross_realm_method-expected.txt: Added.
15+
* web-platform-tests/html/browsers/history/the-history-interface/history_forward_cross_realm_method.html: Added.
16+
* web-platform-tests/html/browsers/history/the-history-interface/history_go_cross_realm_method-expected.txt: Added.
17+
* web-platform-tests/html/browsers/history/the-history-interface/history_go_cross_realm_method.html: Added.
18+
* web-platform-tests/html/webappapis/scripting/reporterror-cross-realm-method-expected.txt: Added.
19+
* web-platform-tests/html/webappapis/scripting/reporterror-cross-realm-method.html: Added.
20+
* web-platform-tests/html/webappapis/structured-clone/structured-clone-cross-realm-method-expected.txt: Added.
21+
* web-platform-tests/html/webappapis/structured-clone/structured-clone-cross-realm-method.html: Added.
22+
* web-platform-tests/requestidlecallback/callback-timeRemaining-cross-realm-method-expected.txt: Added.
23+
* web-platform-tests/requestidlecallback/callback-timeRemaining-cross-realm-method.html: Added.
24+
125
2021-12-10 Alexey Shvayka <[email protected]>
226

327
Extend the scope where the Window's current event is set
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
3+
PASS event.timeStamp is initialized using event's relevant global object
4+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!doctype html>
2+
<meta charset="utf-8">
3+
<title>event.timeStamp is initialized using event's relevant global object</title>
4+
<link rel="help" href="https://dom.spec.whatwg.org/#ref-for-dom-event-timestamp%E2%91%A1">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
8+
<body>
9+
<script>
10+
const t = async_test();
11+
t.step_timeout(() => {
12+
const iframeDelayed = document.createElement("iframe");
13+
iframeDelayed.onload = t.step_func_done(() => {
14+
// Use eval() to eliminate false-positive test result for WebKit builds before r280256,
15+
// which invoked WebIDL accessors in context of lexical (caller) global object.
16+
const timeStampExpected = iframeDelayed.contentWindow.eval(`new Event("foo").timeStamp`);
17+
const eventDelayed = new iframeDelayed.contentWindow.Event("foo");
18+
19+
const {get} = Object.getOwnPropertyDescriptor(Event.prototype, "timeStamp");
20+
assert_approx_equals(get.call(eventDelayed), timeStampExpected, 5, "via Object.getOwnPropertyDescriptor");
21+
22+
Object.setPrototypeOf(eventDelayed, Event.prototype);
23+
assert_approx_equals(eventDelayed.timeStamp, timeStampExpected, 5, "via Object.setPrototypeOf");
24+
});
25+
document.body.append(iframeDelayed);
26+
}, 1000);
27+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
3+
PASS history.back() uses this's associated document's browsing context to determine if navigation is allowed
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!doctype html>
2+
<meta charset="utf-8">
3+
<title>history.back() uses this's associated document's browsing context to determine if navigation is allowed</title>
4+
<link rel="help" href="https://html.spec.whatwg.org/multipage/history.html#dom-history-back">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
8+
<iframe id="sandboxedIframe" srcdoc="hello" sandbox="allow-scripts allow-same-origin"></iframe>
9+
<script>
10+
const t = async_test();
11+
12+
t.step(() => {
13+
history.pushState({}, null, "?prev");
14+
history.pushState({}, null, "?current");
15+
16+
sandboxedIframe.contentWindow.history.back.call(history);
17+
});
18+
19+
window.onpopstate = t.step_func_done(() => {
20+
assert_equals(location.search, "?prev");
21+
});
22+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
3+
PASS history.forward() uses this's associated document's browsing context to determine if navigation is allowed
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!doctype html>
2+
<meta charset="utf-8">
3+
<title>history.forward() uses this's associated document's browsing context to determine if navigation is allowed</title>
4+
<link rel="help" href="https://html.spec.whatwg.org/multipage/history.html#dom-history-forward">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
8+
<iframe id="sandboxedIframe" srcdoc="hello" sandbox="allow-scripts allow-same-origin"></iframe>
9+
<script>
10+
const t = async_test();
11+
12+
t.step(() => {
13+
history.pushState({}, null, "?prev");
14+
history.pushState({}, null, "?current");
15+
history.back();
16+
});
17+
18+
let isCrossRealmForward = false;
19+
window.onpopstate = t.step_func(() => {
20+
if (isCrossRealmForward) {
21+
assert_equals(location.search, "?current");
22+
t.done();
23+
} else {
24+
sandboxedIframe.contentWindow.history.forward.call(history);
25+
isCrossRealmForward = true;
26+
}
27+
});
28+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
3+
PASS history.go() uses this's associated document's browsing context to determine if navigation is allowed
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!doctype html>
2+
<meta charset="utf-8">
3+
<title>history.go() uses this's associated document's browsing context to determine if navigation is allowed</title>
4+
<link rel="help" href="https://html.spec.whatwg.org/multipage/history.html#dom-history-go">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
8+
<iframe id="sandboxedIframe" srcdoc="hello" sandbox="allow-scripts allow-same-origin"></iframe>
9+
<script>
10+
const t = async_test();
11+
12+
t.step(() => {
13+
history.pushState({}, null, "?prev=2");
14+
history.pushState({}, null, "?prev=1");
15+
history.pushState({}, null, "?current");
16+
17+
sandboxedIframe.contentWindow.history.go.call(history, -2);
18+
});
19+
20+
window.onpopstate = t.step_func_done(() => {
21+
assert_equals(location.search, "?prev=2");
22+
});
23+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CONSOLE MESSAGE: TypeError: foo
2+
3+
4+
PASS self.reportError() dispatches an "error" event for this's relevant global object
5+

0 commit comments

Comments
 (0)