Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: test/mjsunit/wasm/start-function.js

Issue 2483193002: [wasm] Wrap start function in a JS->WASM wrapper before calling it during initialization. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 var func = builder.addFunction("", kSig_v_v) 55 var func = builder.addFunction("", kSig_v_v)
56 .addBody([kExprNop]); 56 .addBody([kExprNop]);
57 57
58 builder.addExplicitSection([kStartSectionCode, 0]); 58 builder.addExplicitSection([kStartSectionCode, 0]);
59 builder.addExplicitSection([kStartSectionCode, 0]); 59 builder.addExplicitSection([kStartSectionCode, 0]);
60 60
61 assertThrows(builder.instantiate); 61 assertThrows(builder.instantiate);
62 })(); 62 })();
63 63
64 64
65 (function testRun() { 65 (function testRun1() {
66 print("testRun"); 66 print("testRun1");
67 var builder = new WasmModuleBuilder(); 67 var builder = new WasmModuleBuilder();
68 68
69 builder.addMemory(12, 12, true); 69 builder.addMemory(12, 12, true);
70 70
71 var func = builder.addFunction("", kSig_v_v) 71 var func = builder.addFunction("", kSig_v_v)
72 .addBody([kExprI8Const, 0, kExprI8Const, 77, kExprI32StoreMem, 0, 0]); 72 .addBody([kExprI8Const, 0, kExprI8Const, 66, kExprI32StoreMem, 0, 0]);
73 73
74 builder.addStart(func.index); 74 builder.addStart(func.index);
75 75
76 var module = builder.instantiate();
77 var memory = module.exports.memory.buffer;
78 var view = new Int8Array(memory);
79 assertEquals(66, view[0]);
80 })();
81
82 (function testRun2() {
83 print("testRun2");
84 var builder = new WasmModuleBuilder();
85
86 builder.addMemory(12, 12, true);
87
88 var func = builder.addFunction("", kSig_v_v)
89 .addBody([kExprI8Const, 0, kExprI8Const, 22, kExprI8Const, 55, kExprI32Add, kExprI32StoreMem, 0, 0]);
90
91 builder.addStart(func.index);
92
76 var module = builder.instantiate(); 93 var module = builder.instantiate();
77 var memory = module.exports.memory.buffer; 94 var memory = module.exports.memory.buffer;
78 var view = new Int8Array(memory); 95 var view = new Int8Array(memory);
79 assertEquals(77, view[0]); 96 assertEquals(77, view[0]);
80 })(); 97 })();
81 98
82 (function testStartFFI() { 99 (function testStartFFI() {
83 print("testStartFFI"); 100 print("testStartFFI");
84 var ranned = false; 101 var ranned = false;
85 var ffi = { foo : function() { 102 var ffi = { foo : function() {
86 print("we ranned at stert!"); 103 print("we ranned at stert!");
87 ranned = true; 104 ranned = true;
88 }}; 105 }};
89 106
90 var builder = new WasmModuleBuilder(); 107 var builder = new WasmModuleBuilder();
91 var sig_index = builder.addType(kSig_v_v); 108 var sig_index = builder.addType(kSig_v_v);
92 109
93 builder.addImport("foo", sig_index); 110 builder.addImport("foo", sig_index);
94 var func = builder.addFunction("", sig_index) 111 var func = builder.addFunction("", sig_index)
95 .addBody([kExprCallFunction, 0]); 112 .addBody([kExprCallFunction, 0]);
96 113
97 builder.addStart(func.index); 114 builder.addStart(func.index);
98 115
99 var module = builder.instantiate(ffi); 116 var module = builder.instantiate(ffi);
100 assertTrue(ranned); 117 assertTrue(ranned);
101 })(); 118 })();
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698