regress-709684.js 2.17 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2017 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: --expose-wasm --allow-natives-syntax

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

9 10
let importingModuleBinary1 = (() => {
  var builder = new WasmModuleBuilder();
11 12 13 14
  builder.addImport('', 'f', kSig_i_v);
  return new Int8Array(builder.toBuffer());
})();

15 16
let importingModuleBinary2 = (() => {
  var builder = new WasmModuleBuilder();
17 18 19 20 21 22
  builder.addImport('', 'f', kSig_i_v);
  builder.addFunction('g', kSig_v_v)
    .addBody([kExprNop]);
  return new Int8Array(builder.toBuffer());
})();

23 24
let importingModuleBinary3 = (() => {
  var builder = new WasmModuleBuilder();
25 26 27 28 29 30 31
  builder.addImport('', 'f', kSig_i_v);
  builder.addImport('', 'f2', kSig_i_v);
  builder.addFunction('g', kSig_v_v)
    .addBody([kExprNop]);
  return new Int8Array(builder.toBuffer());
})();

32 33
let importingModuleBinary4 = (() => {
  var builder = new WasmModuleBuilder();
34 35 36 37 38 39
  builder.addFunction('g', kSig_v_v)
    .addBody([kExprNop]);
  return new Int8Array(builder.toBuffer());
})();

const complexImportingModuleBinary1 = (() => {
40
  let builder = new WasmModuleBuilder();
41 42 43 44 45 46 47 48 49 50 51

  builder.addImport('a', 'b', kSig_v_v);
  builder.addImportedMemory('c', 'd', 1);
  builder.addImportedTable('e', 'f', 1);
  builder.addImportedGlobal('g', '⚡', kWasmI32);
  builder.addFunction('g', kSig_v_v)
    .addBody([kExprNop]);
  return builder.toBuffer();
})();

const complexImportingModuleBinary2 = (() => {
52
  let builder = new WasmModuleBuilder();
53 54 55 56 57 58 59 60 61 62

  builder.addImport('a', 'b', kSig_v_v);
  builder.addImportedMemory('c', 'd', 1);
  builder.addImportedTable('e', 'f', 1);
  builder.addImportedGlobal('g', '⚡', kWasmI32);
  builder.addFunction('g', kSig_v_v)
    .addBody([kExprNop]);
  return builder.toBuffer();
})();

63
var tests = [
64 65 66 67 68 69 70 71
  importingModuleBinary1,
  importingModuleBinary2,
  importingModuleBinary3,
  importingModuleBinary4,
  complexImportingModuleBinary1,
  complexImportingModuleBinary2
];

72 73 74 75 76
for (var index in tests) {
  assertPromiseResult(
    WebAssembly.compile(tests[index]),
    m => assertTrue(m instanceof WebAssembly.Module),
    assertUnreachable);
77
}