tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

mutable-global-sharing.tentative.any.js (3154B)


      1 // META: global=window,dedicatedworker,jsshell,shadowrealm
      2 
      3 promise_test(async () => {
      4  const exporterModule = await import("./resources/mutable-global-export.wasm");
      5  const reexporterModule = await import(
      6    "./resources/mutable-global-reexport.wasm"
      7  );
      8 
      9  assert_equals(exporterModule.mutableValue, 100);
     10  assert_equals(reexporterModule.reexportedMutableValue, 100);
     11 }, "WebAssembly modules should export shared mutable globals with correct initial values");
     12 
     13 promise_test(async () => {
     14  const exporterModule = await import("./resources/mutable-global-export.wasm");
     15  const reexporterModule = await import(
     16    "./resources/mutable-global-reexport.wasm"
     17  );
     18 
     19  exporterModule.setGlobal(500);
     20 
     21  assert_equals(exporterModule.getGlobal(), 500, "exporter should see 500");
     22  assert_equals(reexporterModule.getImportedGlobal(), 500);
     23 
     24  reexporterModule.setImportedGlobal(600);
     25 
     26  assert_equals(exporterModule.getGlobal(), 600);
     27  assert_equals(reexporterModule.getImportedGlobal(), 600);
     28 
     29  exporterModule.setGlobal(700);
     30 
     31  assert_equals(exporterModule.getGlobal(), 700);
     32  assert_equals(reexporterModule.getImportedGlobal(), 700);
     33 }, "Wasm-to-Wasm mutable global sharing is live");
     34 
     35 promise_test(async () => {
     36  const module1 = await import("./resources/mutable-global-export.wasm");
     37  const module2 = await import("./resources/mutable-global-export.wasm");
     38 
     39  assert_equals(module1, module2);
     40 
     41  module1.setGlobal(800);
     42  assert_equals(module1.getGlobal(), 800, "module1 should see its own change");
     43  assert_equals(module2.getGlobal(), 800);
     44 }, "Multiple JavaScript imports return the same WebAssembly module instance");
     45 
     46 promise_test(async () => {
     47  const exporterModule = await import("./resources/mutable-global-export.wasm");
     48  const reexporterModule = await import(
     49    "./resources/mutable-global-reexport.wasm"
     50  );
     51 
     52  assert_equals(exporterModule.getV128Lane(0), 1);
     53  assert_equals(exporterModule.getV128Lane(1), 2);
     54  assert_equals(exporterModule.getV128Lane(2), 3);
     55  assert_equals(exporterModule.getV128Lane(3), 4);
     56 
     57  assert_equals(reexporterModule.getImportedV128Lane(0), 1);
     58  assert_equals(reexporterModule.getImportedV128Lane(1), 2);
     59  assert_equals(reexporterModule.getImportedV128Lane(2), 3);
     60  assert_equals(reexporterModule.getImportedV128Lane(3), 4);
     61 }, "v128 globals should work correctly in WebAssembly-to-WebAssembly imports");
     62 
     63 promise_test(async () => {
     64  const exporterModule = await import("./resources/mutable-global-export.wasm");
     65  const reexporterModule = await import(
     66    "./resources/mutable-global-reexport.wasm"
     67  );
     68 
     69  exporterModule.setV128Global(10, 20, 30, 40);
     70 
     71  assert_equals(exporterModule.getV128Lane(0), 10);
     72  assert_equals(exporterModule.getV128Lane(1), 20);
     73  assert_equals(exporterModule.getV128Lane(2), 30);
     74  assert_equals(exporterModule.getV128Lane(3), 40);
     75 
     76  assert_equals(reexporterModule.getImportedV128Lane(0), 10);
     77  assert_equals(reexporterModule.getImportedV128Lane(1), 20);
     78  assert_equals(reexporterModule.getImportedV128Lane(2), 30);
     79  assert_equals(reexporterModule.getImportedV128Lane(3), 40);
     80 }, "v128 global mutations should work correctly between WebAssembly modules");