Skip to content

Commit f02a509

Browse files
domfarolinomoz-wptsync-bot
authored andcommitted
Bug 1987362 [wpt PR 54725] - WPT: Snapshot internal observers before Subscriber iterates over them, a=testonly
Automatic update from web-platform-tests WPT: Snapshot internal observers before Subscriber iterates over them This behavior was already implemented in https://crrev.com/c/6311209, which was a follow-up bug fix to https://crrev.com/c/6221901. It was only recently spec'ed in WICG/observable#214, and this CL adds a WPT for it. This behavior was obliquely tested by: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/dom/observable/tentative/observable-from.any.js;l=675-740;drc=5f8643cf150e97b694f2214ee092c34cc0ccf5fe, as discovered in keithamus/observable-polyfill#38, however this CL adds a simpler, more direct test for this behavior. R=jarhar Bug: 40282760 Change-Id: I43748a09a2f5a235c25ffdbd807e630c187ef2b3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6915657 Reviewed-by: Joey Arhar <jarhar@chromium.org> Commit-Queue: Dominic Farolino <dom@chromium.org> Cr-Commit-Position: refs/heads/main@{#1511774} -- wpt-commits: 826a9b6061c2541d55b9f04d45b8deb102283b4c wpt-pr: 54725
1 parent fe049fb commit f02a509

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

testing/web-platform/tests/dom/observable/tentative/observable-constructor.any.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,3 +1199,33 @@ test(() => {
11991199
'after final abort'
12001200
]);
12011201
}, "Teardown runs after last unsubscribe regardless of unsubscription order");
1202+
1203+
test(() => {
1204+
const results = [];
1205+
const source = new Observable(subscriber => {
1206+
subscriber.next(1);
1207+
subscriber.next(2);
1208+
subscriber.complete();
1209+
});
1210+
1211+
source.subscribe(v => {
1212+
results.push(`${v}-first-sub`);
1213+
if (v === 1) {
1214+
// This new subscription adds a new internal observer to the subscriber's
1215+
// internal observer list, but it does not get the value `1` that the
1216+
// subscriber is currently pushing. This is because the Subscriber
1217+
// iterates over a snapshot of its internal observers to push values to.
1218+
// The first value that this new subscription will see is `2`.
1219+
//
1220+
// See https://github.com/WICG/observable/pull/214.
1221+
source.subscribe(v => results.push(`${v}-second-sub`));
1222+
}
1223+
});
1224+
1225+
assert_array_equals(results, [
1226+
"1-first-sub",
1227+
1228+
"2-first-sub",
1229+
"2-second-sub",
1230+
]);
1231+
}, "Subscriber iterates over a snapshot of its internal observers");

0 commit comments

Comments
 (0)