char/avril

(wip) why'd you have to go and make things so complicaaaaated?

git clone https://git.t4t.associates/char/avril

Charlotte Somsnapshot: embed shared main and worker startup in the CLI688e96e

main
3.0 KiB60 linesraw
1mod common;
2
3use common::run;
4
5#[test]
6fn ecma429_required_global_exposures_exist() {
7    let output = run(
8        r#"
9        const interfaces = [
10            'AbortController', 'AbortSignal', 'Event', 'EventTarget',
11            'CustomEvent', 'ErrorEvent', 'MessageChannel', 'MessageEvent',
12            'MessagePort', 'PromiseRejectionEvent', 'DOMException',
13            'Headers', 'Request', 'Response', 'FormData', 'Blob', 'File',
14            'CompressionStream', 'DecompressionStream',
15            'ByteLengthQueuingStrategy', 'CountQueuingStrategy',
16            'ReadableByteStreamController', 'ReadableStream',
17            'ReadableStreamBYOBReader', 'ReadableStreamBYOBRequest',
18            'ReadableStreamDefaultController', 'ReadableStreamDefaultReader',
19            'TransformStream', 'TransformStreamDefaultController', 'WritableStream',
20            'WritableStreamDefaultController', 'WritableStreamDefaultWriter',
21            'TextDecoder', 'TextDecoderStream', 'TextEncoder', 'TextEncoderStream',
22            'URL', 'URLSearchParams', 'URLPattern', 'Crypto', 'CryptoKey',
23            'SubtleCrypto', 'Performance',
24        ];
25        for (const name of interfaces) {
26            if (typeof globalThis[name] !== 'function') throw Error(`Missing interface ${name}`);
27        }
28        const wasmInterfaces = [
29            'Global', 'Instance', 'Memory', 'Module', 'Table', 'Tag',
30            'Exception', 'CompileError', 'LinkError', 'RuntimeError',
31        ];
32        for (const name of wasmInterfaces) {
33            if (typeof WebAssembly[name] !== 'function') throw Error(`Missing WebAssembly.${name}`);
34        }
35        const methods = [
36            'atob', 'btoa', 'clearTimeout', 'clearInterval', 'queueMicrotask',
37            'reportError', 'setTimeout', 'setInterval', 'structuredClone', 'fetch',
38        ];
39        for (const name of methods) {
40            if (typeof globalThis[name] !== 'function') throw Error(`Missing globalThis.${name}`);
41        }
42        if (globalThis.globalThis !== globalThis || self !== globalThis) throw Error('Global aliases');
43        if (!(globalThis instanceof EventTarget)) throw Error('Global EventTarget branding');
44        if (typeof navigator.userAgent !== 'string' || !navigator.userAgent) throw Error('navigator.userAgent');
45        if (typeof console !== 'object' || typeof crypto !== 'object' || typeof performance !== 'object') {
46            throw Error('Required global objects');
47        }
48        for (const name of ['onerror', 'onunhandledrejection', 'onrejectionhandled']) {
49            if (!(name in globalThis)) throw Error(`Missing global handler ${name}`);
50        }
51        for (const name of ['compile', 'compileStreaming', 'instantiate', 'instantiateStreaming', 'validate']) {
52            if (typeof WebAssembly[name] !== 'function') throw Error(`Missing WebAssembly.${name}`);
53        }
54        if (!('JSTag' in WebAssembly)) throw Error('Missing WebAssembly.JSTag');
55        console.log('ECMA-429 exposure smoke');
56        "#,
57        &[],
58    );
59    assert_eq!(output.stdout, b"ECMA-429 exposure smoke\n");
60}