summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/wasm/export-table.js
blob: e85da9b6646ff63e927e5aa60a8c1b8076c26337 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2016 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

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

(function testExportedMain() {
  var kReturnValue = 88;
  var builder = new WasmModuleBuilder();

  builder.addFunction("main", [kAstI32])
    .addBody([
      kExprReturn,
      kExprI8Const,
      kReturnValue])
    .exportFunc();

  var module = builder.instantiate();

  assertEquals("object", typeof module.exports);
  assertEquals("function", typeof module.exports.main);

  assertEquals(kReturnValue, module.exports.main());
})();

(function testExportedTwice() {
  var kReturnValue = 99;

  var builder = new WasmModuleBuilder();

  builder.addFunction("main", [kAstI32])
    .addBody([
      kExprReturn,
      kExprI8Const,
      kReturnValue])
    .exportAs("blah")
    .exportAs("foo");

  var module = builder.instantiate();

  assertEquals("object", typeof module.exports);
  assertEquals("function", typeof module.exports.blah);
  assertEquals("function", typeof module.exports.foo);

  assertEquals(kReturnValue, module.exports.foo());
  assertEquals(kReturnValue, module.exports.blah());
})();