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

Side by Side Diff: test/mjsunit/wasm/instantiate-module-basic.js

Issue 2345593003: [wasm] Master CL for Binary 0xC changes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: [wasm] Master CL for Binary 0xC changes. Created 4 years, 3 months 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
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 let kReturnValue = 117; 10 let kReturnValue = 117;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 // Official API 55 // Official API
56 let module = new WebAssembly.Module(buffer); 56 let module = new WebAssembly.Module(buffer);
57 CheckInstance(new WebAssembly.Instance(module)); 57 CheckInstance(new WebAssembly.Instance(module));
58 58
59 let promise = WebAssembly.compile(buffer); 59 let promise = WebAssembly.compile(buffer);
60 promise.then(module => CheckInstance(new WebAssembly.Instance(module))); 60 promise.then(module => CheckInstance(new WebAssembly.Instance(module)));
61 61
62 // Negative tests. 62 // Negative tests.
63 (function InvalidModules() { 63 (function InvalidModules() {
64 print("InvalidModules...");
64 let invalid_cases = [undefined, 1, "", "a", {some:1, obj: "b"}]; 65 let invalid_cases = [undefined, 1, "", "a", {some:1, obj: "b"}];
65 let len = invalid_cases.length; 66 let len = invalid_cases.length;
66 for (var i = 0; i < len; ++i) { 67 for (var i = 0; i < len; ++i) {
67 try { 68 try {
68 let instance = new WebAssembly.Instance(1); 69 let instance = new WebAssembly.Instance(1);
69 assertUnreachable("should not be able to instantiate invalid modules."); 70 assertUnreachable("should not be able to instantiate invalid modules.");
70 } catch (e) { 71 } catch (e) {
71 assertContains("Argument 0", e.toString()); 72 assertContains("Argument 0", e.toString());
72 } 73 }
73 } 74 }
74 })(); 75 })();
75 76
76 // Compile async an invalid blob. 77 // Compile async an invalid blob.
77 (function InvalidBinaryAsyncCompilation() { 78 (function InvalidBinaryAsyncCompilation() {
79 print("InvalidBinaryAsyncCompilation...");
78 let builder = new WasmModuleBuilder(); 80 let builder = new WasmModuleBuilder();
79 builder.addFunction("f", kSig_i_i) 81 builder.addFunction("f", kSig_i_i)
80 .addBody([kExprCallImport, kArity0, 0]); 82 .addBody([kExprCallFunction, 0]);
81 let promise = WebAssembly.compile(builder.toBuffer()); 83 let promise = WebAssembly.compile(builder.toBuffer());
82 promise 84 promise
83 .then(compiled => 85 .then(compiled =>
84 assertUnreachable("should not be able to compile invalid blob.")) 86 assertUnreachable("should not be able to compile invalid blob."))
85 .catch(e => assertContains("invalid signature index", e.toString())); 87 .catch(e => assertContains("invalid signature index", e.toString()));
86 })(); 88 })();
87 89
88 // Multiple instances tests. 90 // Multiple instances tests.
89 (function ManyInstances() { 91 (function ManyInstances() {
92 print("ManyInstances...");
90 let compiled_module = new WebAssembly.Module(buffer); 93 let compiled_module = new WebAssembly.Module(buffer);
91 let instance_1 = new WebAssembly.Instance(compiled_module); 94 let instance_1 = new WebAssembly.Instance(compiled_module);
92 let instance_2 = new WebAssembly.Instance(compiled_module); 95 let instance_2 = new WebAssembly.Instance(compiled_module);
93 assertTrue(instance_1 != instance_2); 96 assertTrue(instance_1 != instance_2);
94 })(); 97 })();
95 98
96 (function ManyInstancesAsync() { 99 (function ManyInstancesAsync() {
100 print("ManyInstancesAsync...");
97 let promise = WebAssembly.compile(buffer); 101 let promise = WebAssembly.compile(buffer);
98 promise.then(compiled_module => { 102 promise.then(compiled_module => {
99 let instance_1 = new WebAssembly.Instance(compiled_module); 103 let instance_1 = new WebAssembly.Instance(compiled_module);
100 let instance_2 = new WebAssembly.Instance(compiled_module); 104 let instance_2 = new WebAssembly.Instance(compiled_module);
101 assertTrue(instance_1 != instance_2); 105 assertTrue(instance_1 != instance_2);
102 }); 106 });
103 })(); 107 })();
104 108
105 (function InstancesAreIsolatedFromEachother() { 109 (function InstancesAreIsolatedFromEachother() {
110 print("InstancesAreIsolatedFromEachother...");
106 var builder = new WasmModuleBuilder(); 111 var builder = new WasmModuleBuilder();
107 builder.addMemory(1,1, true); 112 builder.addMemory(1,1, true);
108 var kSig_v_i = makeSig([kAstI32], []); 113 var kSig_v_i = makeSig([kAstI32], []);
109 var signature = builder.addType(kSig_v_i); 114 var signature = builder.addType(kSig_v_i);
110 builder.addImport("some_value", kSig_i); 115 builder.addImport("some_value", kSig_i);
111 builder.addImport("writer", signature); 116 builder.addImport("writer", signature);
112 117
113 builder.addFunction("main", kSig_i_i) 118 builder.addFunction("main", kSig_i_i)
114 .addBody([ 119 .addBody([
115 kExprI32Const, 1,
116 kExprGetLocal, 0, 120 kExprGetLocal, 0,
117 kExprI32LoadMem, 0, 0, 121 kExprI32LoadMem, 0, 0,
118 kExprCallIndirect, kArity1, signature, 122 kExprI32Const, 1,
123 kExprCallIndirect, signature,
119 kExprGetLocal,0, 124 kExprGetLocal,0,
120 kExprI32LoadMem,0, 0, 125 kExprI32LoadMem,0, 0,
121 kExprCallImport, kArity0, 0, 126 kExprCallFunction, 0,
122 kExprI32Add 127 kExprI32Add
123 ]).exportFunc(); 128 ]).exportFunc();
124 129
125 // writer(mem[i]); 130 // writer(mem[i]);
126 // return mem[i] + some_value(); 131 // return mem[i] + some_value();
127 builder.addFunction("_wrap_writer", signature) 132 builder.addFunction("_wrap_writer", signature)
128 .addBody([ 133 .addBody([
129 kExprGetLocal, 0, 134 kExprGetLocal, 0,
130 kExprCallImport, kArity1, 1]); 135 kExprCallFunction, 1]);
131 builder.appendToTable([0, 1]); 136 builder.appendToTable([2, 3]);
132 137
133 138
134 var module = new WebAssembly.Module(builder.toBuffer()); 139 var module = new WebAssembly.Module(builder.toBuffer());
135 var mem_1 = new ArrayBuffer(4); 140 var mem_1 = new ArrayBuffer(4);
136 var mem_2 = new ArrayBuffer(4); 141 var mem_2 = new ArrayBuffer(4);
137 var view_1 = new Int32Array(mem_1); 142 var view_1 = new Int32Array(mem_1);
138 var view_2 = new Int32Array(mem_2); 143 var view_2 = new Int32Array(mem_2);
139 144
140 view_1[0] = 42; 145 view_1[0] = 42;
141 view_2[0] = 1000; 146 view_2[0] = 1000;
142 147
143 var outval_1; 148 var outval_1;
144 var outval_2; 149 var outval_2;
145 var i1 = new WebAssembly.Instance(module, {some_value: () => 1, 150 var i1 = new WebAssembly.Instance(module, {some_value: () => 1,
146 writer: (x)=>outval_1 = x }, mem_1); 151 writer: (x)=>outval_1 = x }, mem_1);
147 var i2 = new WebAssembly.Instance(module, {some_value: () => 2, 152 var i2 = new WebAssembly.Instance(module, {some_value: () => 2,
148 writer: (x)=>outval_2 = x }, mem_2); 153 writer: (x)=>outval_2 = x }, mem_2);
149 154
150 assertEquals(43, i1.exports.main(0)); 155 assertEquals(43, i1.exports.main(0));
151 assertEquals(1002, i2.exports.main(0)); 156 assertEquals(1002, i2.exports.main(0));
152 157
153 assertEquals(42, outval_1); 158 assertEquals(42, outval_1);
154 assertEquals(1000, outval_2); 159 assertEquals(1000, outval_2);
155 })(); 160 })();
156 161
157 (function GlobalsArePrivateToTheInstance() { 162 (function GlobalsArePrivateToTheInstance() {
163 print("GlobalsArePrivateToTheInstance...");
158 var builder = new WasmModuleBuilder(); 164 var builder = new WasmModuleBuilder();
159 builder.addGlobal(kAstI32); 165 builder.addGlobal(kAstI32);
160 builder.addFunction("read", kSig_i_v) 166 builder.addFunction("read", kSig_i_v)
161 .addBody([ 167 .addBody([
162 kExprGetGlobal, 0]) 168 kExprGetGlobal, 0])
163 .exportFunc(); 169 .exportFunc();
164 170
165 builder.addFunction("write", kSig_v_i) 171 builder.addFunction("write", kSig_v_i)
166 .addBody([ 172 .addBody([
167 kExprGetLocal, 0, 173 kExprGetLocal, 0,
168 kExprSetGlobal, 0]) 174 kExprSetGlobal, 0])
169 .exportFunc(); 175 .exportFunc();
170 176
171 var module = new WebAssembly.Module(builder.toBuffer()); 177 var module = new WebAssembly.Module(builder.toBuffer());
172 var i1 = new WebAssembly.Instance(module); 178 var i1 = new WebAssembly.Instance(module);
173 var i2 = new WebAssembly.Instance(module); 179 var i2 = new WebAssembly.Instance(module);
174 i1.exports.write(1); 180 i1.exports.write(1);
175 i2.exports.write(2); 181 i2.exports.write(2);
176 assertEquals(1, i1.exports.read()); 182 assertEquals(1, i1.exports.read());
177 assertEquals(2, i2.exports.read()); 183 assertEquals(2, i2.exports.read());
178 })(); 184 })();
179 185
180 186
181 (function InstanceMemoryIsIsolated() { 187 (function InstanceMemoryIsIsolated() {
188 print("InstanceMemoryIsIsolated...");
ahaas 2016/09/19 11:02:38 I like these prints.
182 var builder = new WasmModuleBuilder(); 189 var builder = new WasmModuleBuilder();
183 builder.addMemory(1,1, true); 190 builder.addMemory(1,1, true);
184 191
185 builder.addFunction("f", kSig_i) 192 builder.addFunction("f", kSig_i)
186 .addBody([ 193 .addBody([
187 kExprI32Const, 0, 194 kExprI32Const, 0,
188 kExprI32LoadMem, 0, 0 195 kExprI32LoadMem, 0, 0
189 ]).exportFunc(); 196 ]).exportFunc();
190 197
191 var mem_1 = new ArrayBuffer(65536); 198 var mem_1 = new ArrayBuffer(65536);
192 var mem_2 = new ArrayBuffer(65536); 199 var mem_2 = new ArrayBuffer(65536);
193 var view_1 = new Int32Array(mem_1); 200 var view_1 = new Int32Array(mem_1);
194 var view_2 = new Int32Array(mem_2); 201 var view_2 = new Int32Array(mem_2);
195 view_1[0] = 1; 202 view_1[0] = 1;
196 view_2[0] = 1000; 203 view_2[0] = 1000;
197 204
198 var module = new WebAssembly.Module(builder.toBuffer()); 205 var module = new WebAssembly.Module(builder.toBuffer());
199 var i1 = new WebAssembly.Instance(module, null, mem_1); 206 var i1 = new WebAssembly.Instance(module, null, mem_1);
200 var i2 = new WebAssembly.Instance(module, null, mem_2); 207 var i2 = new WebAssembly.Instance(module, null, mem_2);
201 208
202 assertEquals(1, i1.exports.f()); 209 assertEquals(1, i1.exports.f());
203 assertEquals(1000, i2.exports.f()); 210 assertEquals(1000, i2.exports.f());
204 })(); 211 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698