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

Side by Side Diff: test/mjsunit/wasm/import-table.js

Issue 1740373002: [wasm] Add a magic word and a version number to the binary. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « test/mjsunit/wasm/ffi-error.js ('k') | test/mjsunit/wasm/indirect-calls.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8
9 function testCallImport(func, check) { 9 function testCallImport(func, check) {
10 var kBodySize = 6; 10 var kBodySize = 6;
11 var kNameFunOffset = 29 + kBodySize + 1; 11 var kNameFunOffset = kHeaderSize + 29 + kBodySize + 1;
12 var kNameMainOffset = kNameFunOffset + 4; 12 var kNameMainOffset = kNameFunOffset + 4;
13 13
14 var ffi = new Object(); 14 var ffi = new Object();
15 ffi.fun = func; 15 ffi.fun = func;
16 16
17 var data = bytes( 17 var data = bytesWithHeader(
18 // signatures 18 // signatures
19 kDeclSignatures, 1, 19 kDeclSignatures, 1,
20 2, kAstI32, kAstF64, kAstF64, // (f64,f64) -> int 20 2, kAstI32, kAstF64, kAstF64, // (f64,f64) -> int
21 // -- main function 21 // -- main function
22 kDeclFunctions, 22 kDeclFunctions,
23 1, 23 1,
24 kDeclFunctionName | kDeclFunctionExport, 24 kDeclFunctionName | kDeclFunctionExport,
25 0, 0, 25 0, 0,
26 kNameMainOffset, 0, 0, 0, // name offset 26 kNameMainOffset, 0, 0, 0, // name offset
27 kBodySize, 0, 27 kBodySize, 0,
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 testCallImport(returnValue("0"), checkReturn(0)); 186 testCallImport(returnValue("0"), checkReturn(0));
187 testCallImport(returnValue("-77"), checkReturn(-77)); 187 testCallImport(returnValue("-77"), checkReturn(-77));
188 188
189 var objWithValueOf = {valueOf: function() { return 198; }} 189 var objWithValueOf = {valueOf: function() { return 198; }}
190 190
191 testCallImport(returnValue(objWithValueOf), checkReturn(198)); 191 testCallImport(returnValue(objWithValueOf), checkReturn(198));
192 192
193 193
194 function testCallBinopVoid(type, func, check) { 194 function testCallBinopVoid(type, func, check) {
195 var kBodySize = 10; 195 var kBodySize = 10;
196 var kNameFunOffset = 28 + kBodySize + 1; 196 var kNameFunOffset = kHeaderSize + 28 + kBodySize + 1;
197 var kNameMainOffset = kNameFunOffset + 4; 197 var kNameMainOffset = kNameFunOffset + 4;
198 198
199 var ffi = new Object(); 199 var ffi = new Object();
200 200
201 var passed_length = -1; 201 var passed_length = -1;
202 var passed_a = -1; 202 var passed_a = -1;
203 var passed_b = -1; 203 var passed_b = -1;
204 var args_a = -1; 204 var args_a = -1;
205 var args_b = -1; 205 var args_b = -1;
206 206
207 ffi.fun = function(a, b) { 207 ffi.fun = function(a, b) {
208 passed_length = arguments.length; 208 passed_length = arguments.length;
209 passed_a = a; 209 passed_a = a;
210 passed_b = b; 210 passed_b = b;
211 args_a = arguments[0]; 211 args_a = arguments[0];
212 args_b = arguments[1]; 212 args_b = arguments[1];
213 } 213 }
214 214
215 var data = bytes( 215 var data = bytesWithHeader(
216 // -- signatures 216 // -- signatures
217 kDeclSignatures, 2, 217 kDeclSignatures, 2,
218 2, kAstStmt, type, type, // (type,type)->void 218 2, kAstStmt, type, type, // (type,type)->void
219 2, kAstI32, type, type, // (type,type)->int 219 2, kAstI32, type, type, // (type,type)->int
220 // -- foreign function 220 // -- foreign function
221 kDeclFunctions, 2, 221 kDeclFunctions, 2,
222 kDeclFunctionName | kDeclFunctionImport, 222 kDeclFunctionName | kDeclFunctionImport,
223 0, 0, // signature index 223 0, 0, // signature index
224 kNameFunOffset, 0, 0, 0, // name offset 224 kNameFunOffset, 0, 0, 0, // name offset
225 // -- main function 225 // -- main function
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 279
280 testCallBinopVoid(kAstI32); 280 testCallBinopVoid(kAstI32);
281 // TODO testCallBinopVoid(kAstI64); 281 // TODO testCallBinopVoid(kAstI64);
282 testCallBinopVoid(kAstF32); 282 testCallBinopVoid(kAstF32);
283 testCallBinopVoid(kAstF64); 283 testCallBinopVoid(kAstF64);
284 284
285 285
286 286
287 function testCallPrint() { 287 function testCallPrint() {
288 var kBodySize = 10; 288 var kBodySize = 10;
289 var kNamePrintOffset = 10 + 7 + 7 + 9 + kBodySize + 1; 289 var kNamePrintOffset = kHeaderSize + 10 + 7 + 7 + 9 + kBodySize + 1;
290 var kNameMainOffset = kNamePrintOffset + 6; 290 var kNameMainOffset = kNamePrintOffset + 6;
291 291
292 var ffi = new Object(); 292 var ffi = new Object();
293 ffi.print = print; 293 ffi.print = print;
294 294
295 var data = bytes( 295 var data = bytesWithHeader(
296 // -- signatures 296 // -- signatures
297 kDeclSignatures, 2, 297 kDeclSignatures, 2,
298 1, kAstStmt, kAstI32, // i32->void 298 1, kAstStmt, kAstI32, // i32->void
299 1, kAstStmt, kAstF64, // f64->int 299 1, kAstStmt, kAstF64, // f64->int
300 kDeclFunctions, 3, 300 kDeclFunctions, 3,
301 // -- import print i32 301 // -- import print i32
302 kDeclFunctionName | kDeclFunctionImport, 302 kDeclFunctionName | kDeclFunctionImport,
303 0, 0, // signature index 303 0, 0, // signature index
304 kNamePrintOffset, 0, 0, 0, // name offset 304 kNamePrintOffset, 0, 0, 0, // name offset
305 // -- import print f64 305 // -- import print f64
(...skipping 25 matching lines...) Expand all
331 module.main(i); 331 module.main(i);
332 } 332 }
333 } 333 }
334 334
335 testCallPrint(); 335 testCallPrint();
336 testCallPrint(); 336 testCallPrint();
337 337
338 338
339 function testCallImport2(foo, bar, expected) { 339 function testCallImport2(foo, bar, expected) {
340 var kBodySize = 5; 340 var kBodySize = 5;
341 var kNameFooOffset = 37 + kBodySize + 1; 341 var kNameFooOffset = kHeaderSize + 37 + kBodySize + 1;
342 var kNameBarOffset = kNameFooOffset + 4; 342 var kNameBarOffset = kNameFooOffset + 4;
343 var kNameMainOffset = kNameBarOffset + 4; 343 var kNameMainOffset = kNameBarOffset + 4;
344 344
345 var ffi = new Object(); 345 var ffi = new Object();
346 ffi.foo = foo; 346 ffi.foo = foo;
347 ffi.bar = bar; 347 ffi.bar = bar;
348 348
349 var data = bytes( 349 var data = bytesWithHeader(
350 // signatures 350 // signatures
351 kDeclSignatures, 1, 351 kDeclSignatures, 1,
352 0, kAstI32, // void -> i32 352 0, kAstI32, // void -> i32
353 // -- main function 353 // -- main function
354 kDeclFunctions, 354 kDeclFunctions,
355 1, 355 1,
356 kDeclFunctionName | kDeclFunctionExport, 356 kDeclFunctionName | kDeclFunctionExport,
357 0, 0, 357 0, 0,
358 kNameMainOffset, 0, 0, 0, // name offset 358 kNameMainOffset, 0, 0, 0, // name offset
359 kBodySize, 0, 359 kBodySize, 0,
(...skipping 18 matching lines...) Expand all
378 ); 378 );
379 379
380 var module = _WASMEXP_.instantiateModule(data, ffi); 380 var module = _WASMEXP_.instantiateModule(data, ffi);
381 381
382 assertEquals("function", typeof module.main); 382 assertEquals("function", typeof module.main);
383 383
384 assertEquals(expected, module.main()); 384 assertEquals(expected, module.main());
385 } 385 }
386 386
387 testCallImport2(function() { return 33; }, function () { return 44; }, 77); 387 testCallImport2(function() { return 33; }, function () { return 44; }, 77);
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/ffi-error.js ('k') | test/mjsunit/wasm/indirect-calls.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698