tor-browser

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

exported-object.tentative.any.js (6379B)


      1 // META: global=window,dedicatedworker,jsshell
      2 // META: script=/wasm/jsapi/wasm-module-builder.js
      3 
      4 let functions = {};
      5 setup(() => {
      6  const builder = new WasmModuleBuilder();
      7 
      8  const structIndex = builder.addStruct([makeField(kWasmI32, true)]);
      9  const arrayIndex = builder.addArray(kWasmI32, true);
     10  const structRef = wasmRefType(structIndex);
     11  const arrayRef = wasmRefType(arrayIndex);
     12 
     13  builder
     14    .addFunction("makeStruct", makeSig_r_v(structRef))
     15    .addBody([...wasmI32Const(42),
     16              ...GCInstr(kExprStructNew), structIndex])
     17    .exportFunc();
     18 
     19  builder
     20    .addFunction("makeArray", makeSig_r_v(arrayRef))
     21    .addBody([...wasmI32Const(5), ...wasmI32Const(42),
     22              ...GCInstr(kExprArrayNew), arrayIndex])
     23    .exportFunc();
     24 
     25  const buffer = builder.toBuffer();
     26  const module = new WebAssembly.Module(buffer);
     27  const instance = new WebAssembly.Instance(module, {});
     28  functions = instance.exports;
     29 });
     30 
     31 test(() => {
     32  const struct = functions.makeStruct();
     33  const array = functions.makeArray();
     34  assert_equals(struct.foo, undefined);
     35  assert_equals(struct[0], undefined);
     36  assert_equals(array.foo, undefined);
     37  assert_equals(array[0], undefined);
     38 }, "property access");
     39 
     40 test(() => {
     41  "use strict";
     42  const struct = functions.makeStruct();
     43  const array = functions.makeArray();
     44  assert_throws_js(TypeError, () => { struct.foo = 5; });
     45  assert_throws_js(TypeError, () => { array.foo = 5; });
     46  assert_throws_js(TypeError, () => { struct[0] = 5; });
     47  assert_throws_js(TypeError, () => { array[0] = 5; });
     48 }, "property assignment (strict mode)");
     49 
     50 test(() => {
     51  const struct = functions.makeStruct();
     52  const array = functions.makeArray();
     53  assert_throws_js(TypeError, () => { struct.foo = 5; });
     54  assert_throws_js(TypeError, () => { array.foo = 5; });
     55  assert_throws_js(TypeError, () => { struct[0] = 5; });
     56  assert_throws_js(TypeError, () => { array[0] = 5; });
     57 }, "property assignment (non-strict mode)");
     58 
     59 test(() => {
     60  const struct = functions.makeStruct();
     61  const array = functions.makeArray();
     62  assert_equals(Object.getOwnPropertyNames(struct).length, 0);
     63  assert_equals(Object.getOwnPropertyNames(array).length, 0);
     64 }, "ownPropertyNames");
     65 
     66 test(() => {
     67  const struct = functions.makeStruct();
     68  const array = functions.makeArray();
     69  assert_throws_js(TypeError, () => Object.defineProperty(struct, "foo", { value: 1 }));
     70  assert_throws_js(TypeError, () => Object.defineProperty(array, "foo", { value: 1 }));
     71 }, "defineProperty");
     72 
     73 test(() => {
     74  "use strict";
     75  const struct = functions.makeStruct();
     76  const array = functions.makeArray();
     77  assert_throws_js(TypeError, () => delete struct.foo);
     78  assert_throws_js(TypeError, () => delete struct[0]);
     79  assert_throws_js(TypeError, () => delete array.foo);
     80  assert_throws_js(TypeError, () => delete array[0]);
     81 }, "delete (strict mode)");
     82 
     83 test(() => {
     84  const struct = functions.makeStruct();
     85  const array = functions.makeArray();
     86  assert_throws_js(TypeError, () => delete struct.foo);
     87  assert_throws_js(TypeError, () => delete struct[0]);
     88  assert_throws_js(TypeError, () => delete array.foo);
     89  assert_throws_js(TypeError, () => delete array[0]);
     90 }, "delete (non-strict mode)");
     91 
     92 test(() => {
     93  const struct = functions.makeStruct();
     94  const array = functions.makeArray();
     95  assert_equals(Object.getPrototypeOf(struct), null);
     96  assert_equals(Object.getPrototypeOf(array), null);
     97 }, "getPrototypeOf");
     98 
     99 test(() => {
    100  const struct = functions.makeStruct();
    101  const array = functions.makeArray();
    102  assert_throws_js(TypeError, () => Object.setPrototypeOf(struct, {}));
    103  assert_throws_js(TypeError, () => Object.setPrototypeOf(array, {}));
    104 }, "setPrototypeOf");
    105 
    106 test(() => {
    107  const struct = functions.makeStruct();
    108  const array = functions.makeArray();
    109  assert_false(Object.isExtensible(struct));
    110  assert_false(Object.isExtensible(array));
    111 }, "isExtensible");
    112 
    113 test(() => {
    114  const struct = functions.makeStruct();
    115  const array = functions.makeArray();
    116  assert_throws_js(TypeError, () => Object.preventExtensions(struct));
    117  assert_throws_js(TypeError, () => Object.preventExtensions(array));
    118 }, "preventExtensions");
    119 
    120 test(() => {
    121  const struct = functions.makeStruct();
    122  const array = functions.makeArray();
    123  assert_throws_js(TypeError, () => Object.seal(struct));
    124  assert_throws_js(TypeError, () => Object.seal(array));
    125 }, "sealing");
    126 
    127 test(() => {
    128  const struct = functions.makeStruct();
    129  const array = functions.makeArray();
    130  assert_equals(typeof struct, "object");
    131  assert_equals(typeof array, "object");
    132 }, "typeof");
    133 
    134 test(() => {
    135  const struct = functions.makeStruct();
    136  const array = functions.makeArray();
    137  assert_throws_js(TypeError, () => struct.toString());
    138  assert_equals(Object.prototype.toString.call(struct), "[object Object]");
    139  assert_throws_js(TypeError, () => array.toString());
    140  assert_equals(Object.prototype.toString.call(array), "[object Object]");
    141 }, "toString");
    142 
    143 test(() => {
    144  const struct = functions.makeStruct();
    145  const array = functions.makeArray();
    146  assert_throws_js(TypeError, () => struct.valueOf());
    147  assert_equals(Object.prototype.valueOf.call(struct), struct);
    148  assert_throws_js(TypeError, () => array.valueOf());
    149  assert_equals(Object.prototype.valueOf.call(array), array);
    150 }, "valueOf");
    151 
    152 test(() => {
    153  const struct = functions.makeStruct();
    154  const array = functions.makeArray();
    155  const map = new Map();
    156  map.set(struct, "struct");
    157  map.set(array, "array");
    158  assert_equals(map.get(struct), "struct");
    159  assert_equals(map.get(array), "array");
    160 }, "GC objects as map keys");
    161 
    162 test(() => {
    163  const struct = functions.makeStruct();
    164  const array = functions.makeArray();
    165  const set = new Set();
    166  set.add(struct);
    167  set.add(array);
    168  assert_true(set.has(struct));
    169  assert_true(set.has(array));
    170 }, "GC objects as set element");
    171 
    172 test(() => {
    173  const struct = functions.makeStruct();
    174  const array = functions.makeArray();
    175  const map = new WeakMap();
    176  map.set(struct, "struct");
    177  map.set(array, "array");
    178  assert_equals(map.get(struct), "struct");
    179  assert_equals(map.get(array), "array");
    180 }, "GC objects as weak map keys");
    181 
    182 test(() => {
    183  const struct = functions.makeStruct();
    184  const array = functions.makeArray();
    185  const set = new WeakSet();
    186  set.add(struct);
    187  set.add(array);
    188  assert_true(set.has(struct));
    189  assert_true(set.has(array));
    190 }, "GC objects as weak set element");