tor-browser

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

constructor.tentative.any.js (2877B)


      1 // META: global=window,dedicatedworker,jsshell,shadowrealm
      2 // META: script=/wasm/jsapi/assertions.js
      3 
      4 function addxy(x, y) {
      5    return x + y
      6 }
      7 
      8 test(() => {
      9    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
     10    assert_function_name(WebAssembly.Function, "Function", "WebAssembly.Function");
     11 }, "name");
     12 
     13 test(() => {
     14    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
     15    assert_function_length(WebAssembly.Function, 2, "WebAssembly.Function");
     16 }, "length");
     17 
     18 test(() => {
     19    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
     20    assert_throws_js(TypeError, () => new WebAssembly.Function());
     21    const argument = {parameters: [], results: []};
     22    assert_throws_js(TypeError, () => new WebAssembly.Function(argument));
     23 }, "Too few arguments");
     24 
     25 test(() => {
     26    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
     27    const arguments = [{parameters: ["i32", "i32"], results: ["i32"]}, addxy];
     28    assert_throws_js(TypeError, () => WebAssembly.Function(...arguments));
     29 }, "Calling");
     30 
     31 test(() => {
     32    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
     33    var fun = new WebAssembly.Function({parameters: ["i32", "i32"], results: ["i32"]}, addxy);
     34    assert_true(fun instanceof WebAssembly.Function)
     35 }, "construct with JS function")
     36 
     37 test(() => {
     38    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
     39    assert_throws_js(TypeError, () => new WebAssembly.Function({parameters: []}, addxy))
     40 }, "fail with missing results")
     41 
     42 test(() => {
     43    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
     44    assert_throws_js(TypeError, () => new WebAssembly.Function({results: []}, addxy))
     45 }, "fail with missing parameters")
     46 
     47 test(() => {
     48    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
     49    assert_throws_js(TypeError, () => new WebAssembly.Function({parameters: [1], results: [true]}, addxy))
     50 }, "fail with non-string parameters & results")
     51 
     52 test(() => {
     53    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
     54    assert_throws_js(TypeError, () => new WebAssembly.Function({parameters: ["invalid"], results: ["invalid"]}, addxy))
     55 }, "fail with non-existent parameter and result type")
     56 
     57 test(() => {
     58    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
     59    assert_throws_js(TypeError, () => new WebAssembly.Function({parameters: [], results: []}, 72))
     60 }, "fail with non-function object")
     61 
     62 test(() => {
     63    assert_implements(WebAssembly.Function, "WebAssembly.Function is not implemented");
     64    assert_throws_js(TypeError, () => new WebAssembly.Function({parameters: [], results: []}, {}))
     65 }, "fail to construct with non-callable object")