OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --expose-wasm | 5 // Flags: --expose-wasm |
6 | 6 |
7 load("test/mjsunit/wasm/wasm-constants.js"); | 7 load("test/mjsunit/wasm/wasm-constants.js"); |
8 load("test/mjsunit/wasm/wasm-module-builder.js"); | 8 load("test/mjsunit/wasm/wasm-module-builder.js"); |
9 | 9 |
10 function instantiate(sig, body) { | 10 function instantiate(sig, body) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 })(); | 58 })(); |
59 | 59 |
60 | 60 |
61 (function testTwoStartFuncs() { | 61 (function testTwoStartFuncs() { |
62 print("testTwoStartFuncs"); | 62 print("testTwoStartFuncs"); |
63 var builder = new WasmModuleBuilder(); | 63 var builder = new WasmModuleBuilder(); |
64 | 64 |
65 var func = builder.addFunction("", kSig_v_v) | 65 var func = builder.addFunction("", kSig_v_v) |
66 .addBody([kExprNop]); | 66 .addBody([kExprNop]); |
67 | 67 |
68 builder.addExplicitSection([kDeclStart, 0]); | 68 builder.addExplicitSection([kStartSectionCode, 0]); |
69 builder.addExplicitSection([kDeclStart, 0]); | 69 builder.addExplicitSection([kStartSectionCode, 0]); |
70 | 70 |
71 assertThrows(builder.instantiate); | 71 assertThrows(builder.instantiate); |
72 })(); | 72 })(); |
73 | 73 |
74 | 74 |
75 (function testRun() { | 75 (function testRun() { |
76 print("testRun"); | 76 print("testRun"); |
77 var builder = new WasmModuleBuilder(); | 77 var builder = new WasmModuleBuilder(); |
78 | 78 |
79 builder.addMemory(12, 12, true); | 79 builder.addMemory(12, 12, true); |
80 | 80 |
81 var func = builder.addFunction("", kSig_v_v) | 81 var func = builder.addFunction("", kSig_v_v) |
82 .addBody([kExprI8Const, 0, kExprI8Const, 77, kExprI32StoreMem, 0, 0]); | 82 .addBody([kExprI8Const, 0, kExprI8Const, 77, kExprI32StoreMem, 0, 0]); |
83 | 83 |
84 builder.addStart(func.index); | 84 builder.addStart(func.index); |
85 | 85 |
86 var module = builder.instantiate(); | 86 var module = builder.instantiate(); |
87 var memory = module.exports.memory; | 87 var memory = module.exports.memory.buffer; |
88 var view = new Int8Array(memory); | 88 var view = new Int8Array(memory); |
89 assertEquals(77, view[0]); | 89 assertEquals(77, view[0]); |
90 })(); | 90 })(); |
91 | 91 |
92 (function testStartFFI() { | 92 (function testStartFFI() { |
93 print("testStartFFI"); | 93 print("testStartFFI"); |
94 var ranned = false; | 94 var ranned = false; |
95 var ffi = { foo : function() { | 95 var ffi = { foo : function() { |
96 print("we ranned at stert!"); | 96 print("we ranned at stert!"); |
97 ranned = true; | 97 ranned = true; |
98 }}; | 98 }}; |
99 | 99 |
100 var builder = new WasmModuleBuilder(); | 100 var builder = new WasmModuleBuilder(); |
101 var sig_index = builder.addType(kSig_v_v); | 101 var sig_index = builder.addType(kSig_v_v); |
102 | 102 |
103 builder.addImport("foo", sig_index); | 103 builder.addImport("foo", sig_index); |
104 var func = builder.addFunction("", sig_index) | 104 var func = builder.addFunction("", sig_index) |
105 .addBody([kExprCallImport, kArity0, 0]); | 105 .addBody([kExprCallFunction, 0]); |
106 | 106 |
107 builder.addStart(func.index); | 107 builder.addStart(func.index); |
108 | 108 |
109 var module = builder.instantiate(ffi); | 109 var module = builder.instantiate(ffi); |
110 assertTrue(ranned); | 110 assertTrue(ranned); |
111 })(); | 111 })(); |
OLD | NEW |