exceptions-type-reflection.js 1.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --experimental-wasm-eh --experimental-wasm-type-reflection

load("test/mjsunit/wasm/wasm-module-builder.js");

let testcases = [
{types: {parameters:[]}, sig: kSig_v_v},
{types: {parameters:["i32"]}, sig: kSig_v_i},
{types: {parameters:["i64"]}, sig: kSig_v_l},
{types: {parameters:["f64", "f64", "i32"]}, sig: kSig_v_ddi},
{types: {parameters:["f32"]}, sig: kSig_v_f},
];

(function TestExport() {
  print(arguments.callee.name);
  let builder = new WasmModuleBuilder();

  testcases.forEach(function(expected, i) {
22 23
    let except = builder.addTag(expected.sig);
    builder.addExportOfKind("ex" + i, kExternalTag, except);
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
  });

  let instance = builder.instantiate();
  testcases.forEach(function(expected, i) {
    assertEquals(instance.exports["ex" + i].type(), expected.types);
  });
})();

(function TestImportExport() {
  print(arguments.callee.name);

  let builder = new WasmModuleBuilder();
  let imports = {m: {}};

  testcases.forEach(function(expected, i) {
    let t = new WebAssembly.Tag(expected.types);
40 41
    let index = builder.addImportedTag("m", "ex" + i, expected.sig);
    builder.addExportOfKind("ex" + i, kExternalTag, index);
42 43 44 45 46 47 48 49
    imports.m["ex" + i] = t;
  });

  let instance = builder.instantiate(imports);
  testcases.forEach(function(expected, i) {
    assertEquals(instance.exports["ex" + i].type(), expected.types);
  })
})();