1 Services.prefs.setBoolPref("javascript.options.wasm_js_promise_integration", true);
2 registerCleanupFunction(() => {
3 Services.prefs.clearUserPref("javascript.options.wasm_js_promise_integration");
6 // The tests runs code in tight loop with the profiler enabled. It is testing
7 // behavior of JS PI specific methods and generated code.
8 // It is not guarantee 100% hit since the profiler probes stacks every 1ms,
9 // but it will happen often enough.
10 add_task(async () => {
11 if (!WebAssembly.promising) {
15 await Services.profiler.StartProfiler(10, 1, ["js"], ["GeckoMain"]);
16 Assert.ok(Services.profiler.IsActive());
18 /* Wasm module that is tested:
20 (import "js" "compute_delta"
21 (func $compute_delta (param i32) (result f64)))
23 (func (export "update_state_export") (param i32) (result f64)
24 (call $compute_delta (local.get 0))
29 var compute_delta = (i) => i / 100;
30 const b = new Uint8Array([
31 0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 1, 127, 1, 124, 2, 20, 1, 2, 106,
32 115, 13, 99, 111, 109, 112, 117, 116, 101, 95, 100, 101, 108, 116, 97,
33 0, 0, 3, 2, 1, 0, 7, 23, 1, 19, 117, 112, 100, 97, 116, 101, 95, 115, 116,
34 97, 116, 101, 95, 101, 120, 112, 111, 114, 116, 0, 1, 10, 8, 1, 6, 0, 32,
35 0, 16, 0, 11, 0, 23, 4, 110, 97, 109, 101, 1, 16, 1, 0, 13, 99, 111, 109,
36 112, 117, 116, 101, 95, 100, 101, 108, 116, 97
38 const ins = new WebAssembly.Instance(new WebAssembly.Module(b), {
39 js: { compute_delta, },
41 var update_state = WebAssembly.promising(
42 ins.exports.update_state_export
45 for (var i = 0; i < 1000; i++) {
46 var r = await update_state(4);
52 Assert.ok(true, "Done");
53 await Services.profiler.StopProfiler();
56 add_task(async () => {
57 if (!WebAssembly.promising) {
61 await Services.profiler.StartProfiler(10, 1, ["js"], ["GeckoMain"]);
62 Assert.ok(Services.profiler.IsActive());
64 /* Wasm module that is tested:
66 (import "js" "compute_delta"
67 (func $compute_delta (param i32) (result f64)))
69 (func (export "update_state_export") (param i32) (result f64)
70 (call $compute_delta (local.get 0))
75 var compute_delta = async (i) => i / 100;
76 var suspending_compute_delta = new WebAssembly.Suspending(
79 const b = new Uint8Array([
80 0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 1, 127, 1, 124, 2, 20, 1, 2, 106,
81 115, 13, 99, 111, 109, 112, 117, 116, 101, 95, 100, 101, 108, 116, 97, 0,
82 0, 3, 2, 1, 0, 7, 23, 1, 19, 117, 112, 100, 97, 116, 101, 95, 115, 116, 97,
83 116, 101, 95, 101, 120, 112, 111, 114, 116, 0, 1, 10, 8, 1, 6, 0, 32, 0,
84 16, 0, 11, 0, 23, 4, 110, 97, 109, 101, 1, 16, 1, 0, 13, 99, 111, 109, 112,
85 117, 116, 101, 95, 100, 101, 108, 116, 97
87 const ins = new WebAssembly.Instance(new WebAssembly.Module(b), {
88 js: { compute_delta: suspending_compute_delta, },
90 var update_state = WebAssembly.promising(
91 ins.exports.update_state_export
94 for (var i = 0; i < 1000; i++) {
95 var r = await update_state(4);
101 Assert.ok(true, "Done");
102 await Services.profiler.StopProfiler();
106 * All the tests are implemented with add_task, this starts them automatically.
108 function run_test() {