1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
|
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
function async_iframe_test(f, name) {
async_test(t => {
const iframe = document.createElement("iframe");
iframe.src = "resources/empty.html";
document.body.append(iframe);
iframe.onload = () => {
f(t, iframe);
};
}, name);
}
async_iframe_test((t, iframe) => {
// A promise reaction job is created with the iframe's realm, retrieved
// from the onFulfilled callback function.
const { p, result } = iframe.contentWindow.eval(`
const result = { called: false };
const p = Promise.resolve(1).then(function onFulfilled() {
result.called = true;
});
({ p, result });
`);
// The global becomes not-fully-active before the next microtask checkpoint.
iframe.remove();
// Verify the result after the next microtask checkpoint.
t.step_timeout(() => {
assert_equals(result.called, false);
t.done();
}, 0);
}, "Reaction job should be skipped if onFulfilled handler belongs to detached iframe");
async_iframe_test((t, iframe) => {
// A promise reaction job is created with the iframe's realm, retrieved
// from the onRejected callback function.
const { p, result } = iframe.contentWindow.eval(`
const result = { called: false };
const p = Promise.reject(1).then(() => {}, function onRejected() {
result.called = true;
});
({ p, result });
`);
// The global becomes not-fully-active before the next microtask checkpoint.
iframe.remove();
t.step_timeout(() => {
assert_equals(result.called, false);
t.done();
}, 0);
}, "Reaction job should be skipped if onRejected handler belongs to detached iframe");
async_iframe_test((t, iframe) => {
const p = iframe.contentWindow.eval(`Promise.resolve(1);`);
iframe.remove();
let called = false;
// A promise reaction job is created with the current realm, retrieved
// from the onFulfilled callback function.
p.then(function onFulfilled() {
called = true;
});
t.step_timeout(() => {
assert_equals(called, true);
t.done();
}, 0);
}, "Reaction job should not be skipped if onFulfilled handler belongs to fully active global");
async_iframe_test((t, iframe) => {
const p = iframe.contentWindow.eval(`Promise.reject(1);`);
iframe.remove();
let called = false;
// A promise reaction job is created with the current realm, retrieved
// from the onRejected callback function.
p.then(() => {}, function onRejected() {
called = true;
});
t.step_timeout(() => {
assert_equals(called, true);
t.done();
}, 0);
}, "Reaction job should not be skipped if onRejected handler belongs to fully active global");
async_iframe_test((t, iframe) => {
const p = iframe.contentWindow.eval(`Promise.resolve(1);`);
iframe.remove();
let called = false;
// A thenable job is created with the iframe's realm, retrieved from p.then
// function.
const p2 = Promise.resolve(p);
p2.then(function onFulfilled() {
called = true;
});
t.step_timeout(() => {
assert_equals(called, false);
t.done();
}, 0);
}, "Thenable job for fulfilled promise should be skipped if it belongs to detached iframe");
async_iframe_test((t, iframe) => {
const p = iframe.contentWindow.eval(`Promise.reject(1);`);
iframe.remove();
let called = false;
// A thenable job is created with the iframe's realm, retrieved from p.then
// function.
const p2 = Promise.resolve(p);
p2.then(() => {}, function onRejected() {
called = true;
});
t.step_timeout(() => {
assert_equals(called, false);
t.done();
}, 0);
}, "Thenable job for rejected promise should be skipped if it belongs to detached iframe");
async_iframe_test((t, iframe) => {
const p = iframe.contentWindow.eval(`Promise.resolve(1);`);
iframe.remove();
let called = false;
// In contrast to Promise.resolve, Promise.reject doesn't create a thenable
// job.
const p2 = Promise.reject(p);
p2.then(() => {}, function onRejected() {
called = true;
});
t.step_timeout(() => {
assert_equals(called, true);
t.done();
}, 0);
}, "No job with detached iframe's realm should be used for Promise.reject on fulfilled promise");
async_iframe_test((t, iframe) => {
const p = iframe.contentWindow.eval(`Promise.reject(1);`);
iframe.remove();
let called = false;
// In contrast to Promise.resolve, Promise.reject doesn't create a thenable
// job.
const p2 = Promise.reject(p);
p2.then(() => {}, function onRejected() {
called = true;
});
t.step_timeout(() => {
assert_equals(called, true);
t.done();
}, 0);
}, "No job with detached iframe's realm should be used for Promise.reject on rejected promise");
async_iframe_test((t, iframe) => {
const p = iframe.contentWindow.eval(`Promise.resolve(1);`);
iframe.remove();
let called = false;
// Promise.prototype.then resolves the result capability's promise with the
// handler's return value, and a thenable job is created with the iframe's
// realm, retrieved from p.then function.
const p2 = Promise.resolve(1).then(() => p);
p2.then(function onFulfilled() {
called = true;
});
t.step_timeout(() => {
assert_equals(called, false);
t.done();
}, 0);
}, "Thenable job created by reaction job for fulfillment should be skipped if it belongs to detached iframe");
async_iframe_test((t, iframe) => {
const p = iframe.contentWindow.eval(`Promise.resolve(1);`);
iframe.remove();
let called = false;
// Promise.prototype.then resolves the result capability's promise with the
// handler's return value, and a thenable job is created with the iframe's
// realm, retrieved from p.then function.
const p2 = Promise.reject(1).then(() => {}, () => p);
p2.then(function onFulfilled() {
called = true;
});
t.step_timeout(() => {
assert_equals(called, false);
t.done();
}, 0);
}, "Thenable job created by reaction job for rejection should be skipped if it belongs to detached iframe");
async_iframe_test((t, iframe) => {
const p = iframe.contentWindow.eval(`Promise.resolve(1);`);
iframe.remove();
let called = false;
// Promise.all internally performs Promise.resolve, and a thenable job
// is created with the iframe's realm, retrieved from p.then function.
const p2 = Promise.all([p]);
p2.then(function onFulfilled() {
called = true;
});
t.step_timeout(() => {
assert_equals(called, false);
t.done();
}, 0);
}, "Thenable job created by Promise.all should be skipped if it belongs to detached iframe");
async_iframe_test((t, iframe) => {
const p = iframe.contentWindow.eval(`Promise.resolve(1);`);
iframe.remove();
let called = false;
// Promise.allSettled internally performs Promise.resolve, and a thenable job
// is created with the iframe's realm, retrieved from p.then function.
const p2 = Promise.allSettled([p]);
p2.then(function onFulfilled() {
called = true;
});
t.step_timeout(() => {
assert_equals(called, false);
t.done();
}, 0);
}, "Thenable job created by Promise.allSettled should be skipped if it belongs to detached iframe");
async_iframe_test((t, iframe) => {
const p = iframe.contentWindow.eval(`Promise.resolve(1);`);
iframe.remove();
let called = false;
// Promise.any internally performs Promise.resolve, and a thenable job
// is created with the iframe's realm, retrieved from p.then function.
const p2 = Promise.any([p]);
p2.then(function onFulfilled() {
called = true;
});
t.step_timeout(() => {
assert_equals(called, false);
t.done();
}, 0);
}, "Thenable job created by Promise.any should be skipped if it belongs to detached iframe");
async_iframe_test((t, iframe) => {
const p = iframe.contentWindow.eval(`Promise.resolve(1);`);
iframe.remove();
let called = false;
// Promise.race internally performs Promise.resolve, and a thenable job
// is created with the iframe's realm, retrieved from p.then function.
const p2 = Promise.race([p]);
p2.then(function onFulfilled() {
called = true;
});
t.step_timeout(() => {
assert_equals(called, false);
t.done();
}, 0);
}, "Thenable job created by Promise.race should be skipped if it belongs to detached iframe");
</script>
</body>
|