summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/observable/tentative/observable-map.window.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/dom/observable/tentative/observable-map.window.js')
-rw-r--r--testing/web-platform/tests/dom/observable/tentative/observable-map.window.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/testing/web-platform/tests/dom/observable/tentative/observable-map.window.js b/testing/web-platform/tests/dom/observable/tentative/observable-map.window.js
new file mode 100644
index 0000000000..06bf2e26b5
--- /dev/null
+++ b/testing/web-platform/tests/dom/observable/tentative/observable-map.window.js
@@ -0,0 +1,40 @@
+async function loadIframeAndReturnContentWindow() {
+ // Create and attach an iframe.
+ const iframe = document.createElement('iframe');
+ const iframeLoadPromise = new Promise((resolve, reject) => {
+ iframe.onload = resolve;
+ iframe.onerror = reject;
+ });
+ document.body.append(iframe);
+ await iframeLoadPromise;
+ return iframe.contentWindow;
+}
+
+promise_test(async t => {
+ const contentWin = await loadIframeAndReturnContentWindow();
+
+ window.results = [];
+
+ contentWin.eval(`
+ const parentResults = parent.results;
+
+ const source = new Observable(subscriber => {
+ // Detach the document before calling next().
+ window.frameElement.remove();
+
+ // This invokes the map() operator's internal observer's next steps,
+ // which at least in Chromium, must have a special "context is detached"
+ // check to early-return, so as to not crash before invoking the "mapper"
+ // callback supplied to the map() operator.
+ subscriber.next(1);
+ });
+
+ source.map(value => {
+ parentResults.push(value);
+ }).subscribe(v => parentResults.push(v));
+ `);
+
+ // If we got here, we didn't crash! Let's also check that `results` is empty.
+ assert_array_equals(results, []);
+}, "map()'s internal observer's next steps do not crash in a detached document");
+