quickwin 2026.5.2-3.145209

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/README.md +6 -0
  2. package/examples/pdf_preview.js +440 -0
  3. package/examples/pdf_preview.ts +470 -0
  4. package/examples/preact_demo.js +35 -0
  5. package/examples/preact_demo.tsx +49 -0
  6. package/examples/tray_demo.js +75 -0
  7. package/examples/tray_demo.tsx +79 -0
  8. package/lib/fetch.js +746 -0
  9. package/lib/fetch.ts +811 -0
  10. package/lib/polyfill.js +500 -0
  11. package/lib/polyfill.ts +454 -0
  12. package/lib/preact/hooks.js +287 -0
  13. package/lib/preact/hooks.ts +330 -0
  14. package/lib/preact/jsx-runtime.js +1 -0
  15. package/lib/preact/jsx-runtime.ts +2 -0
  16. package/lib/preact/jsx.d.ts +36 -0
  17. package/lib/preact/layout.js +153 -0
  18. package/lib/preact/layout.ts +183 -0
  19. package/lib/preact/preact.js +54 -0
  20. package/lib/preact/preact.ts +133 -0
  21. package/lib/preact/props.js +99 -0
  22. package/lib/preact/props.ts +119 -0
  23. package/lib/preact/render.js +320 -0
  24. package/lib/preact/render.ts +353 -0
  25. package/lib/websocket.js +540 -0
  26. package/lib/websocket.ts +574 -0
  27. package/package.json +32 -0
  28. package/quickwin.d.ts +657 -0
  29. package/test/add.wasm +0 -0
  30. package/test/complex.wasm +0 -0
  31. package/test/complex_imports.wasm +0 -0
  32. package/test/global_imports.wasm +0 -0
  33. package/test/import_func.wasm +0 -0
  34. package/test/imports.wasm +0 -0
  35. package/test/run.js +86 -0
  36. package/test/run.ts +90 -0
  37. package/test/sjlj.wasm +0 -0
  38. package/test/test_basic.js +7 -0
  39. package/test/test_basic.ts +9 -0
  40. package/test/test_brotli.js +48 -0
  41. package/test/test_brotli.ts +52 -0
  42. package/test/test_fetch_cache.js +131 -0
  43. package/test/test_fetch_cache.ts +141 -0
  44. package/test/test_ffi.js +157 -0
  45. package/test/test_ffi.ts +174 -0
  46. package/test/test_frame_encoding.js +128 -0
  47. package/test/test_frame_encoding.ts +132 -0
  48. package/test/test_helper.js +84 -0
  49. package/test/test_helper.ts +80 -0
  50. package/test/test_http_import.js +78 -0
  51. package/test/test_http_import.ts +74 -0
  52. package/test/test_mupdf_render.js +69 -0
  53. package/test/test_mupdf_render.ts +74 -0
  54. package/test/test_mupdf_twice.js +77 -0
  55. package/test/test_mupdf_twice.ts +81 -0
  56. package/test/test_mupdf_wasm.js +33 -0
  57. package/test/test_mupdf_wasm.ts +30 -0
  58. package/test/test_net_event.js +63 -0
  59. package/test/test_net_event.ts +59 -0
  60. package/test/test_net_fetch.js +153 -0
  61. package/test/test_net_fetch.ts +131 -0
  62. package/test/test_net_websocket.js +158 -0
  63. package/test/test_net_websocket.ts +144 -0
  64. package/test/test_polyfill.js +58 -0
  65. package/test/test_polyfill.ts +60 -0
  66. package/test/test_url.js +173 -0
  67. package/test/test_url.ts +183 -0
  68. package/test/test_wasm_basic.js +82 -0
  69. package/test/test_wasm_basic.ts +70 -0
  70. package/test/test_wasm_import_global.js +41 -0
  71. package/test/test_wasm_import_global.ts +39 -0
  72. package/test/test_wasm_sjlj.js +153 -0
  73. package/test/test_wasm_sjlj.ts +134 -0
  74. package/test/test_wasm_types.js +96 -0
  75. package/test/test_wasm_types.ts +108 -0
  76. package/test/types.wasm +0 -0
  77. package/tsconfig.json +18 -0
  78. package/vendor/mupdf-wasm/mupdf-wasm.d.ts +571 -0
  79. package/vendor/mupdf-wasm/mupdf-wasm.js +2749 -0
  80. package/vendor/mupdf-wasm/mupdf-wasm.wasm +0 -0
  81. package/vendor/mupdf-wasm/mupdf.d.ts +939 -0
  82. package/vendor/mupdf-wasm/mupdf.js +3317 -0
  83. package/win-mingw64.exe +0 -0
@@ -0,0 +1,41 @@
1
+ import { readWasmFile } from './test_helper.js';
2
+ export const suite = {
3
+ name: 'wasm-import-global',
4
+ run: (t) => {
5
+ const giBuf = readWasmFile('./global_imports.wasm');
6
+ if (!giBuf) {
7
+ t.fail++;
8
+ return;
9
+ }
10
+ const giMod = new WebAssembly.Module(giBuf);
11
+ t.section('import globals');
12
+ var giInst;
13
+ try {
14
+ giInst = new WebAssembly.Instance(giMod, {
15
+ env: {
16
+ offset: new WebAssembly.Global({ value: 'i32', mutable: false }, 42),
17
+ factor: new WebAssembly.Global({ value: 'f64', mutable: false }, 3.14),
18
+ log: function (x) { }
19
+ }
20
+ });
21
+ }
22
+ catch (e) {
23
+ t.fail++;
24
+ return;
25
+ }
26
+ t.check('get_offset()', 42, giInst.exports.get_offset());
27
+ t.check('compute(10)', 31.4, giInst.exports.compute(10));
28
+ t.check('run(8)', 50, giInst.exports.run(8));
29
+ t.section('second instance');
30
+ var giInst2 = new WebAssembly.Instance(giMod, {
31
+ env: {
32
+ offset: new WebAssembly.Global({ value: 'i32', mutable: false }, 100),
33
+ factor: new WebAssembly.Global({ value: 'f64', mutable: false }, 2.0),
34
+ log: function (x) { }
35
+ }
36
+ });
37
+ t.check('instance2 get_offset()', 100, giInst2.exports.get_offset());
38
+ t.check('instance2 compute(5)', 10, giInst2.exports.compute(5));
39
+ t.check('instance1 still get_offset()', 42, giInst.exports.get_offset());
40
+ }
41
+ };
@@ -0,0 +1,39 @@
1
+ import { Tester, readWasmFile } from './test_helper.js'
2
+
3
+ export const suite = {
4
+ name: 'wasm-import-global',
5
+ run: (t: Tester) => {
6
+ const giBuf = readWasmFile('./global_imports.wasm')
7
+ if (!giBuf) { t.fail++; return }
8
+ const giMod = new WebAssembly.Module(giBuf)
9
+
10
+ t.section('import globals')
11
+ var giInst: WebAssembly.Instance
12
+ try {
13
+ giInst = new WebAssembly.Instance(giMod, {
14
+ env: {
15
+ offset: new WebAssembly.Global({ value: 'i32', mutable: false }, 42),
16
+ factor: new WebAssembly.Global({ value: 'f64', mutable: false }, 3.14),
17
+ log: function (x: number) { /* noop */ }
18
+ }
19
+ })
20
+ } catch (e) {
21
+ t.fail++; return
22
+ }
23
+ t.check('get_offset()', 42, giInst.exports.get_offset())
24
+ t.check('compute(10)', 31.4, giInst.exports.compute(10))
25
+ t.check('run(8)', 50, giInst.exports.run(8))
26
+
27
+ t.section('second instance')
28
+ var giInst2 = new WebAssembly.Instance(giMod, {
29
+ env: {
30
+ offset: new WebAssembly.Global({ value: 'i32', mutable: false }, 100),
31
+ factor: new WebAssembly.Global({ value: 'f64', mutable: false }, 2.0),
32
+ log: function (x: number) { /* noop */ }
33
+ }
34
+ })
35
+ t.check('instance2 get_offset()', 100, giInst2.exports.get_offset())
36
+ t.check('instance2 compute(5)', 10, giInst2.exports.compute(5))
37
+ t.check('instance1 still get_offset()', 42, giInst.exports.get_offset())
38
+ }
39
+ }
@@ -0,0 +1,153 @@
1
+ import { readWasmFile } from './test_helper.js';
2
+ class EmscriptenEH {
3
+ }
4
+ class EmscriptenSjLj extends EmscriptenEH {
5
+ }
6
+ export const suite = {
7
+ name: 'wasm-sjlj',
8
+ run: (t) => {
9
+ globalThis.EmscriptenEH = EmscriptenEH;
10
+ globalThis.EmscriptenSjLj = EmscriptenSjLj;
11
+ const buf = readWasmFile('./sjlj.wasm');
12
+ if (!buf) {
13
+ t.fail++;
14
+ return;
15
+ }
16
+ t.section('Module');
17
+ var mod = null;
18
+ try {
19
+ mod = new WebAssembly.Module(buf);
20
+ t.check('Module created', true, mod instanceof WebAssembly.Module);
21
+ }
22
+ catch (e) {
23
+ t.fail++;
24
+ return;
25
+ }
26
+ t.section('Instance with SjLj imports');
27
+ var inst = null;
28
+ var threwBit = 0;
29
+ var threwValue = 0;
30
+ function getWasmTableEntry(index) {
31
+ const table = inst.exports['__indirect_function_table'];
32
+ const fn = table.get(index);
33
+ return fn;
34
+ }
35
+ function _setThrew(val, v) {
36
+ if (threwBit === 0) {
37
+ threwValue = v;
38
+ threwBit = val;
39
+ }
40
+ }
41
+ function invoke_ii(index, a1) {
42
+ try {
43
+ return getWasmTableEntry(index)(a1);
44
+ }
45
+ catch (e) {
46
+ if (!(e instanceof EmscriptenEH))
47
+ throw e;
48
+ _setThrew(1, 0);
49
+ return 0;
50
+ }
51
+ }
52
+ try {
53
+ inst = new WebAssembly.Instance(mod, {
54
+ env: {
55
+ throw_longjmp: () => { throw new EmscriptenSjLj; },
56
+ invoke_ii: invoke_ii,
57
+ }
58
+ });
59
+ t.check('Instance created', true, inst instanceof WebAssembly.Instance);
60
+ }
61
+ catch (e) {
62
+ t.fail++;
63
+ return;
64
+ }
65
+ t.section('identity (no throw)');
66
+ try {
67
+ threwBit = 0;
68
+ threwValue = 0;
69
+ const result = inst.exports.identity(42);
70
+ t.check('identity(42) = 42', 42, result);
71
+ }
72
+ catch (e) {
73
+ t.fail++;
74
+ }
75
+ t.section('invoke_ii with no-throw function');
76
+ try {
77
+ threwBit = 0;
78
+ threwValue = 0;
79
+ const result = inst.exports.test_no_throw();
80
+ t.check('test_no_throw() returns 10', 10, result);
81
+ t.check('threwBit is 0', 0, threwBit);
82
+ }
83
+ catch (e) {
84
+ t.fail++;
85
+ }
86
+ t.section('invoke_ii with throwing function');
87
+ try {
88
+ threwBit = 0;
89
+ threwValue = 0;
90
+ const result = inst.exports.test_throw();
91
+ t.check('test_throw() detects threwBit', true, result !== 0);
92
+ t.check('threwBit is set', true, threwBit !== 0);
93
+ }
94
+ catch (e) {
95
+ t.fail++;
96
+ }
97
+ t.section('nested invoke (invoke_ii calls invoke_ii)');
98
+ try {
99
+ threwBit = 0;
100
+ threwValue = 0;
101
+ const result = inst.exports.test_nested_invoke();
102
+ t.check('test_nested_invoke() detects threwBit', true, result !== 0);
103
+ t.check('threwBit is set', true, threwBit !== 0);
104
+ }
105
+ catch (e) {
106
+ t.fail++;
107
+ }
108
+ t.section('setjmp_test pattern');
109
+ try {
110
+ threwBit = 0;
111
+ threwValue = 0;
112
+ const result = inst.exports.setjmp_test(0);
113
+ t.check('setjmp_test detects throw', -1, result);
114
+ t.check('threwBit is set', true, threwBit !== 0);
115
+ }
116
+ catch (e) {
117
+ t.fail++;
118
+ }
119
+ t.section('setjmp/longjmp: a(x) normal path');
120
+ try {
121
+ threwBit = 0;
122
+ threwValue = 0;
123
+ const result = inst.exports.a(5);
124
+ t.check('a(5) returns 10 (b returns x*2)', 10, result);
125
+ t.check('threwBit is 0', 0, threwBit);
126
+ }
127
+ catch (e) {
128
+ t.fail++;
129
+ }
130
+ t.section('setjmp/longjmp: a(x) longjmp path');
131
+ try {
132
+ threwBit = 0;
133
+ threwValue = 0;
134
+ const result = inst.exports.a(-1);
135
+ t.check('a(-1) returns -1 (longjmp caught)', -1, result);
136
+ t.check('threwBit is set', true, threwBit !== 0);
137
+ }
138
+ catch (e) {
139
+ t.fail++;
140
+ }
141
+ t.section('EmscriptenSjLj instanceof check');
142
+ try {
143
+ const exc = new EmscriptenSjLj();
144
+ t.check('instanceof EmscriptenEH', true, exc instanceof EmscriptenEH);
145
+ t.check('instanceof EmscriptenSjLj', true, exc instanceof EmscriptenSjLj);
146
+ const regularErr = new Error('test');
147
+ t.check('Error not instanceof EmscriptenEH', false, regularErr instanceof EmscriptenEH);
148
+ }
149
+ catch (e) {
150
+ t.fail++;
151
+ }
152
+ }
153
+ };
@@ -0,0 +1,134 @@
1
+ import { Tester, readWasmFile } from './test_helper.js'
2
+
3
+ class EmscriptenEH {}
4
+ class EmscriptenSjLj extends EmscriptenEH {}
5
+
6
+ export const suite = {
7
+ name: 'wasm-sjlj',
8
+ run: (t: Tester) => {
9
+ globalThis.EmscriptenEH = EmscriptenEH
10
+ globalThis.EmscriptenSjLj = EmscriptenSjLj
11
+
12
+ const buf = readWasmFile('./sjlj.wasm')
13
+ if (!buf) { t.fail++; return }
14
+
15
+ t.section('Module')
16
+ var mod: WebAssembly.Module | null = null
17
+ try {
18
+ mod = new WebAssembly.Module(buf)
19
+ t.check('Module created', true, mod instanceof WebAssembly.Module)
20
+ } catch (e) { t.fail++; return }
21
+
22
+ t.section('Instance with SjLj imports')
23
+ var inst: WebAssembly.Instance | null = null
24
+ var threwBit = 0
25
+ var threwValue = 0
26
+
27
+ function getWasmTableEntry(index: number): Function {
28
+ const table = inst!.exports['__indirect_function_table'] as any
29
+ const fn = table.get(index)
30
+ return fn as Function
31
+ }
32
+
33
+ function _setThrew(val: number, v: number): void {
34
+ if (threwBit === 0) {
35
+ threwValue = v
36
+ threwBit = val
37
+ }
38
+ }
39
+
40
+ function invoke_ii(index: number, a1: number): number {
41
+ try {
42
+ return getWasmTableEntry(index)(a1) as number
43
+ } catch (e) {
44
+ if (!(e instanceof EmscriptenEH)) throw e
45
+ _setThrew(1, 0)
46
+ return 0
47
+ }
48
+ }
49
+
50
+ try {
51
+ inst = new WebAssembly.Instance(mod, {
52
+ env: {
53
+ throw_longjmp: () => { throw new EmscriptenSjLj },
54
+ invoke_ii: invoke_ii,
55
+ }
56
+ })
57
+ t.check('Instance created', true, inst instanceof WebAssembly.Instance)
58
+ } catch (e) {
59
+ t.fail++
60
+ return
61
+ }
62
+
63
+ t.section('identity (no throw)')
64
+ try {
65
+ threwBit = 0
66
+ threwValue = 0
67
+ const result = (inst.exports as any).identity(42)
68
+ t.check('identity(42) = 42', 42, result)
69
+ } catch (e) { t.fail++ }
70
+
71
+ t.section('invoke_ii with no-throw function')
72
+ try {
73
+ threwBit = 0
74
+ threwValue = 0
75
+ const result = (inst.exports as any).test_no_throw()
76
+ t.check('test_no_throw() returns 10', 10, result)
77
+ t.check('threwBit is 0', 0, threwBit)
78
+ } catch (e) { t.fail++ }
79
+
80
+ t.section('invoke_ii with throwing function')
81
+ try {
82
+ threwBit = 0
83
+ threwValue = 0
84
+ const result = (inst.exports as any).test_throw()
85
+ t.check('test_throw() detects threwBit', true, result !== 0)
86
+ t.check('threwBit is set', true, threwBit !== 0)
87
+ } catch (e) { t.fail++ }
88
+
89
+ t.section('nested invoke (invoke_ii calls invoke_ii)')
90
+ try {
91
+ threwBit = 0
92
+ threwValue = 0
93
+ const result = (inst.exports as any).test_nested_invoke()
94
+ t.check('test_nested_invoke() detects threwBit', true, result !== 0)
95
+ t.check('threwBit is set', true, threwBit !== 0)
96
+ } catch (e) { t.fail++ }
97
+
98
+ t.section('setjmp_test pattern')
99
+ try {
100
+ threwBit = 0
101
+ threwValue = 0
102
+ const result = (inst.exports as any).setjmp_test(0)
103
+ t.check('setjmp_test detects throw', -1, result)
104
+ t.check('threwBit is set', true, threwBit !== 0)
105
+ } catch (e) { t.fail++ }
106
+
107
+ t.section('setjmp/longjmp: a(x) normal path')
108
+ try {
109
+ threwBit = 0
110
+ threwValue = 0
111
+ const result = (inst.exports as any).a(5)
112
+ t.check('a(5) returns 10 (b returns x*2)', 10, result)
113
+ t.check('threwBit is 0', 0, threwBit)
114
+ } catch (e) { t.fail++ }
115
+
116
+ t.section('setjmp/longjmp: a(x) longjmp path')
117
+ try {
118
+ threwBit = 0
119
+ threwValue = 0
120
+ const result = (inst.exports as any).a(-1)
121
+ t.check('a(-1) returns -1 (longjmp caught)', -1, result)
122
+ t.check('threwBit is set', true, threwBit !== 0)
123
+ } catch (e) { t.fail++ }
124
+
125
+ t.section('EmscriptenSjLj instanceof check')
126
+ try {
127
+ const exc = new EmscriptenSjLj()
128
+ t.check('instanceof EmscriptenEH', true, exc instanceof EmscriptenEH)
129
+ t.check('instanceof EmscriptenSjLj', true, exc instanceof EmscriptenSjLj)
130
+ const regularErr = new Error('test')
131
+ t.check('Error not instanceof EmscriptenEH', false, regularErr instanceof EmscriptenEH)
132
+ } catch (e) { t.fail++ }
133
+ }
134
+ }
@@ -0,0 +1,96 @@
1
+ import { readWasmFile } from './test_helper.js';
2
+ export const suite = {
3
+ name: 'wasm-types',
4
+ run: (t) => {
5
+ const buf = readWasmFile('./types.wasm');
6
+ if (!buf) {
7
+ t.fail++;
8
+ return;
9
+ }
10
+ const m = new WebAssembly.Module(buf);
11
+ const i = new WebAssembly.Instance(m);
12
+ t.section('i32');
13
+ t.check('add_i32(10, 20)', 30, i.exports.add_i32(10, 20));
14
+ t.check('add_i32(-5, 3)', -2, i.exports.add_i32(-5, 3));
15
+ t.section('i64');
16
+ t.check('add_i64(100, 200)', 300, i.exports.add_i64(100, 200));
17
+ t.check('add_i64(10000000000, 20000000000)', 30000000000, i.exports.add_i64(10000000000, 20000000000));
18
+ t.check('add_i64(-10000000000, 5000000000)', -5000000000, i.exports.add_i64(-10000000000, 5000000000));
19
+ t.check('factorial_i64(5)', 120, i.exports.factorial_i64(5));
20
+ t.check('factorial_i64(10)', 3628800, i.exports.factorial_i64(10));
21
+ t.section('f32');
22
+ t.check('add_f32(1.5, 2.5)', 4.0, i.exports.add_f32(1.5, 2.5));
23
+ t.check('add_f32(-1.0, 1.0)', 0.0, i.exports.add_f32(-1.0, 1.0));
24
+ t.section('f64');
25
+ t.check('add_f64(3.14, 2.86)', 6.0, i.exports.add_f64(3.14, 2.86));
26
+ t.check('sqrt_f64(144.0)', 12.0, i.exports.sqrt_f64(144.0));
27
+ t.section('mixed');
28
+ t.check('mixed_args(1, 2, 3.0, 4.0)', 10.0, i.exports.mixed_args(1, 2, 3.0, 4.0));
29
+ t.section('memory');
30
+ i.exports.write_memory(0, 12345678);
31
+ t.check('write/read memory', 12345678, i.exports.read_memory(0));
32
+ t.section('JS-side TypedArray');
33
+ t.check('Int32Array[0]', 12345678, new Int32Array(i.exports.memory.buffer)[0]);
34
+ i.exports.write_memory(4, 999);
35
+ t.check('Int32Array[1] after write', 999, new Int32Array(i.exports.memory.buffer)[1]);
36
+ t.section('exported globals');
37
+ t.check('const_i32.value', 42, i.exports.const_i32.value);
38
+ t.check('const_f64.value', 3.14, i.exports.const_f64.value);
39
+ t.check('mutable_i32 is Global', true, i.exports.mutable_i32 instanceof WebAssembly.Global);
40
+ t.check('mutable_i32.value', 99, i.exports.mutable_i32.value);
41
+ i.exports.mutable_i32.value = 500;
42
+ t.check('mutable_i32 after set from JS', 500, i.exports.mutable_i32.value);
43
+ t.check('mutable_i32 after set from WASM', 500, i.exports.read_mut_global());
44
+ t.section('Global constructor');
45
+ var g;
46
+ g = new WebAssembly.Global({ value: 'i32', mutable: false }, 42);
47
+ t.check('Global(i32)', 42, g.value);
48
+ g = new WebAssembly.Global({ value: 'i64' }, 10000000000);
49
+ t.check('Global(i64)', 10000000000, g.value);
50
+ g = new WebAssembly.Global({ value: 'f64' }, 3.14);
51
+ t.check('Global(f64)', 3.14, g.value);
52
+ g = new WebAssembly.Global({ value: 'f32' }, 2.5);
53
+ t.check('Global(f32)', 2.5, g.value);
54
+ t.section('Global mutable set');
55
+ g = new WebAssembly.Global({ value: 'i32', mutable: true }, 0);
56
+ t.check('initial', 0, g.value);
57
+ g.value = 77;
58
+ t.check('after set', 77, g.value);
59
+ t.section('Global immutable set throws');
60
+ g = new WebAssembly.Global({ value: 'i32', mutable: false }, 10);
61
+ try {
62
+ g.value = 999;
63
+ t.fail++;
64
+ }
65
+ catch (e) {
66
+ t.ok++;
67
+ }
68
+ t.section('Global.valueOf');
69
+ g = new WebAssembly.Global({ value: 'i32' }, 55);
70
+ t.check('valueOf()', 55, g.valueOf());
71
+ t.section('Memory constructor');
72
+ var mem;
73
+ mem = new WebAssembly.Memory({ initial: 1 });
74
+ t.check('Memory created', true, mem instanceof WebAssembly.Memory);
75
+ t.check('buffer byteLength', 65536, mem.buffer.byteLength);
76
+ mem = new WebAssembly.Memory({ initial: 2, maximum: 4 });
77
+ t.check('Memory(2,4) buffer', 131072, mem.buffer.byteLength);
78
+ t.check('grow(1) returned', 2, mem.grow(1));
79
+ t.check('after grow buffer', 196608, mem.buffer.byteLength);
80
+ t.section('instance.exports.memory');
81
+ t.check('memory is Memory', true, i.exports.memory instanceof WebAssembly.Memory);
82
+ t.check('memory.buffer.byteLength', 65536, i.exports.memory.buffer.byteLength);
83
+ t.section('standalone Memory + TypedArray');
84
+ mem = new WebAssembly.Memory({ initial: 1 });
85
+ var arr = new Int32Array(mem.buffer);
86
+ arr[0] = 42;
87
+ arr[1] = 7;
88
+ t.check('Int32Array[0]', 42, arr[0]);
89
+ t.check('Int32Array[1]', 7, arr[1]);
90
+ t.section('buffer identity');
91
+ arr[2] = 100;
92
+ t.check('old view[2]', 100, arr[2]);
93
+ t.check('new view[2]', 100, new Int32Array(mem.buffer)[2]);
94
+ t.check('buffer is same object', true, mem.buffer === mem.buffer);
95
+ }
96
+ };
@@ -0,0 +1,108 @@
1
+ import { Tester, readWasmFile } from './test_helper.js'
2
+
3
+ export const suite = {
4
+ name: 'wasm-types',
5
+ run: (t: Tester) => {
6
+ const buf = readWasmFile('./types.wasm')
7
+ if (!buf) { t.fail++; return }
8
+ const m = new WebAssembly.Module(buf)
9
+ const i = new WebAssembly.Instance(m)
10
+
11
+ t.section('i32')
12
+ t.check('add_i32(10, 20)', 30, i.exports.add_i32(10, 20))
13
+ t.check('add_i32(-5, 3)', -2, i.exports.add_i32(-5, 3))
14
+
15
+ t.section('i64')
16
+ t.check('add_i64(100, 200)', 300, i.exports.add_i64(100, 200))
17
+ t.check('add_i64(10000000000, 20000000000)', 30000000000, i.exports.add_i64(10000000000, 20000000000))
18
+ t.check('add_i64(-10000000000, 5000000000)', -5000000000, i.exports.add_i64(-10000000000, 5000000000))
19
+ t.check('factorial_i64(5)', 120, i.exports.factorial_i64(5))
20
+ t.check('factorial_i64(10)', 3628800, i.exports.factorial_i64(10))
21
+
22
+ t.section('f32')
23
+ t.check('add_f32(1.5, 2.5)', 4.0, i.exports.add_f32(1.5, 2.5))
24
+ t.check('add_f32(-1.0, 1.0)', 0.0, i.exports.add_f32(-1.0, 1.0))
25
+
26
+ t.section('f64')
27
+ t.check('add_f64(3.14, 2.86)', 6.0, i.exports.add_f64(3.14, 2.86))
28
+ t.check('sqrt_f64(144.0)', 12.0, i.exports.sqrt_f64(144.0))
29
+
30
+ t.section('mixed')
31
+ t.check('mixed_args(1, 2, 3.0, 4.0)', 10.0, i.exports.mixed_args(1, 2, 3.0, 4.0))
32
+
33
+ t.section('memory')
34
+ i.exports.write_memory(0, 12345678)
35
+ t.check('write/read memory', 12345678, i.exports.read_memory(0))
36
+
37
+ t.section('JS-side TypedArray')
38
+ t.check('Int32Array[0]', 12345678, new Int32Array(i.exports.memory.buffer)[0])
39
+ i.exports.write_memory(4, 999)
40
+ t.check('Int32Array[1] after write', 999, new Int32Array(i.exports.memory.buffer)[1])
41
+
42
+ t.section('exported globals')
43
+ t.check('const_i32.value', 42, i.exports.const_i32.value)
44
+ t.check('const_f64.value', 3.14, i.exports.const_f64.value)
45
+ t.check('mutable_i32 is Global', true, i.exports.mutable_i32 instanceof WebAssembly.Global)
46
+ t.check('mutable_i32.value', 99, i.exports.mutable_i32.value)
47
+ i.exports.mutable_i32.value = 500
48
+ t.check('mutable_i32 after set from JS', 500, i.exports.mutable_i32.value)
49
+ t.check('mutable_i32 after set from WASM', 500, i.exports.read_mut_global())
50
+
51
+ t.section('Global constructor')
52
+ var g: WebAssembly.Global
53
+ g = new WebAssembly.Global({ value: 'i32', mutable: false }, 42)
54
+ t.check('Global(i32)', 42, g.value)
55
+ g = new WebAssembly.Global({ value: 'i64' }, 10000000000)
56
+ t.check('Global(i64)', 10000000000, g.value)
57
+ g = new WebAssembly.Global({ value: 'f64' }, 3.14)
58
+ t.check('Global(f64)', 3.14, g.value)
59
+ g = new WebAssembly.Global({ value: 'f32' }, 2.5)
60
+ t.check('Global(f32)', 2.5, g.value)
61
+
62
+ t.section('Global mutable set')
63
+ g = new WebAssembly.Global({ value: 'i32', mutable: true }, 0)
64
+ t.check('initial', 0, g.value)
65
+ g.value = 77
66
+ t.check('after set', 77, g.value)
67
+
68
+ t.section('Global immutable set throws')
69
+ g = new WebAssembly.Global({ value: 'i32', mutable: false }, 10)
70
+ try {
71
+ g.value = 999
72
+ t.fail++
73
+ } catch (e) {
74
+ t.ok++
75
+ }
76
+
77
+ t.section('Global.valueOf')
78
+ g = new WebAssembly.Global({ value: 'i32' }, 55)
79
+ t.check('valueOf()', 55, g.valueOf())
80
+
81
+ t.section('Memory constructor')
82
+ var mem: WebAssembly.Memory
83
+ mem = new WebAssembly.Memory({ initial: 1 })
84
+ t.check('Memory created', true, mem instanceof WebAssembly.Memory)
85
+ t.check('buffer byteLength', 65536, mem.buffer.byteLength)
86
+ mem = new WebAssembly.Memory({ initial: 2, maximum: 4 })
87
+ t.check('Memory(2,4) buffer', 131072, mem.buffer.byteLength)
88
+ t.check('grow(1) returned', 2, mem.grow(1))
89
+ t.check('after grow buffer', 196608, mem.buffer.byteLength)
90
+
91
+ t.section('instance.exports.memory')
92
+ t.check('memory is Memory', true, i.exports.memory instanceof WebAssembly.Memory)
93
+ t.check('memory.buffer.byteLength', 65536, i.exports.memory.buffer.byteLength)
94
+
95
+ t.section('standalone Memory + TypedArray')
96
+ mem = new WebAssembly.Memory({ initial: 1 })
97
+ var arr = new Int32Array(mem.buffer)
98
+ arr[0] = 42; arr[1] = 7
99
+ t.check('Int32Array[0]', 42, arr[0])
100
+ t.check('Int32Array[1]', 7, arr[1])
101
+
102
+ t.section('buffer identity')
103
+ arr[2] = 100
104
+ t.check('old view[2]', 100, arr[2])
105
+ t.check('new view[2]', 100, new Int32Array(mem.buffer)[2])
106
+ t.check('buffer is same object', true, mem.buffer === mem.buffer)
107
+ }
108
+ }
Binary file
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "incremental": true,
4
+ "target": "es2022",
5
+ "module": "esnext",
6
+ "strict": true,
7
+ "noImplicitAny": false,
8
+ "esModuleInterop": true,
9
+ "skipLibCheck": true,
10
+ "lib": ["ES2020"],
11
+ "types": ["./quickwin.d.ts"],
12
+ "outDir": "_build",
13
+ "jsx": "react-jsx",
14
+ "jsxImportSource": "../lib/preact",
15
+ },
16
+ "include": ["test/**/*.ts", "examples/**/*.ts", "examples/**/*.tsx", "main.ts"],
17
+ "exclude": []
18
+ }