mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-03 21:12:08 +02:00
LibWeb: Push a temporary execution context for setTimeout
This fixes a crash seen running stream tests.
This commit is contained in:
Notes:
github-actions[bot]
2024-11-01 17:12:52 +00:00
Author: https://github.com/shannonbooth Commit: https://github.com/LadybirdBrowser/ladybird/commit/1dc1bebd2af Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2107
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
self.delay = ms => new Promise(resolve => step_timeout(resolve, ms));
|
||||
|
||||
// For tests which verify that the implementation doesn't do something it shouldn't, it's better not to use a
|
||||
// timeout. Instead, assume that any reasonable implementation is going to finish work after 2 times around the event
|
||||
// loop, and use flushAsyncEvents().then(() => assert_array_equals(...));
|
||||
// Some tests include promise resolutions which may mean the test code takes a couple of event loop visits itself. So go
|
||||
// around an extra 2 times to avoid complicating those tests.
|
||||
self.flushAsyncEvents = () => delay(0).then(() => delay(0)).then(() => delay(0)).then(() => delay(0));
|
||||
|
||||
self.assert_typed_array_equals = (actual, expected, message) => {
|
||||
const prefix = message === undefined ? '' : `${message} `;
|
||||
assert_equals(typeof actual, 'object', `${prefix}type is object`);
|
||||
assert_equals(actual.constructor, expected.constructor, `${prefix}constructor`);
|
||||
assert_equals(actual.byteOffset, expected.byteOffset, `${prefix}byteOffset`);
|
||||
assert_equals(actual.byteLength, expected.byteLength, `${prefix}byteLength`);
|
||||
assert_equals(actual.buffer.byteLength, expected.buffer.byteLength, `${prefix}buffer.byteLength`);
|
||||
assert_array_equals([...actual], [...expected], `${prefix}contents`);
|
||||
assert_array_equals([...new Uint8Array(actual.buffer)], [...new Uint8Array(expected.buffer)], `${prefix}buffer contents`);
|
||||
};
|
||||
|
||||
self.makePromiseAndResolveFunc = () => {
|
||||
let resolve;
|
||||
const promise = new Promise(r => { resolve = r; });
|
||||
return [promise, resolve];
|
||||
};
|
||||
Reference in New Issue
Block a user