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

Side by Side Diff: test/mjsunit/wasm/ffi.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/export-table.js ('k') | test/mjsunit/wasm/ffi-error.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 testCallFFI(func, check) { 9 function testCallFFI(func, check) {
10 var kBodySize = 6; 10 var kBodySize = 6;
11 var kNameFunOffset = 24 + kBodySize + 1; 11 var kNameFunOffset = kHeaderSize + 24 + 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 // -- foreign function 21 // -- foreign function
22 kDeclFunctions, 2, 22 kDeclFunctions, 2,
23 kDeclFunctionName | kDeclFunctionImport, 23 kDeclFunctionName | kDeclFunctionImport,
24 0, 0, 24 0, 0,
25 kNameFunOffset, 0, 0, 0, // name offset 25 kNameFunOffset, 0, 0, 0, // name offset
26 // -- main function 26 // -- main function
27 kDeclFunctionName | kDeclFunctionExport, 27 kDeclFunctionName | kDeclFunctionExport,
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 testCallFFI(returnValue("0"), checkReturn(0)); 183 testCallFFI(returnValue("0"), checkReturn(0));
184 testCallFFI(returnValue("-77"), checkReturn(-77)); 184 testCallFFI(returnValue("-77"), checkReturn(-77));
185 185
186 var objWithValueOf = {valueOf: function() { return 198; }} 186 var objWithValueOf = {valueOf: function() { return 198; }}
187 187
188 testCallFFI(returnValue(objWithValueOf), checkReturn(198)); 188 testCallFFI(returnValue(objWithValueOf), checkReturn(198));
189 189
190 190
191 function testCallBinopVoid(type, func, check) { 191 function testCallBinopVoid(type, func, check) {
192 var kBodySize = 10; 192 var kBodySize = 10;
193 var kNameFunOffset = 28 + kBodySize + 1; 193 var kNameFunOffset = kHeaderSize + 28 + kBodySize + 1;
194 var kNameMainOffset = kNameFunOffset + 4; 194 var kNameMainOffset = kNameFunOffset + 4;
195 195
196 var ffi = new Object(); 196 var ffi = new Object();
197 197
198 var passed_length = -1; 198 var passed_length = -1;
199 var passed_a = -1; 199 var passed_a = -1;
200 var passed_b = -1; 200 var passed_b = -1;
201 var args_a = -1; 201 var args_a = -1;
202 var args_b = -1; 202 var args_b = -1;
203 203
204 ffi.fun = function(a, b) { 204 ffi.fun = function(a, b) {
205 passed_length = arguments.length; 205 passed_length = arguments.length;
206 passed_a = a; 206 passed_a = a;
207 passed_b = b; 207 passed_b = b;
208 args_a = arguments[0]; 208 args_a = arguments[0];
209 args_b = arguments[1]; 209 args_b = arguments[1];
210 } 210 }
211 211
212 var data = bytes( 212 var data = bytesWithHeader(
213 // -- signatures 213 // -- signatures
214 kDeclSignatures, 2, 214 kDeclSignatures, 2,
215 2, kAstStmt, type, type, // (type,type)->void 215 2, kAstStmt, type, type, // (type,type)->void
216 2, kAstI32, type, type, // (type,type)->int 216 2, kAstI32, type, type, // (type,type)->int
217 // -- foreign function 217 // -- foreign function
218 kDeclFunctions, 2, 218 kDeclFunctions, 2,
219 kDeclFunctionName | kDeclFunctionImport, 219 kDeclFunctionName | kDeclFunctionImport,
220 0, 0, // signature index 220 0, 0, // signature index
221 kNameFunOffset, 0, 0, 0, // name offset 221 kNameFunOffset, 0, 0, 0, // name offset
222 // -- main function 222 // -- main function
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 276
277 testCallBinopVoid(kAstI32); 277 testCallBinopVoid(kAstI32);
278 // TODO testCallBinopVoid(kAstI64); 278 // TODO testCallBinopVoid(kAstI64);
279 testCallBinopVoid(kAstF32); 279 testCallBinopVoid(kAstF32);
280 testCallBinopVoid(kAstF64); 280 testCallBinopVoid(kAstF64);
281 281
282 282
283 283
284 function testCallPrint() { 284 function testCallPrint() {
285 var kBodySize = 10; 285 var kBodySize = 10;
286 var kNamePrintOffset = 10 + 7 + 7 + 9 + kBodySize + 1; 286 var kNamePrintOffset = kHeaderSize + 10 + 7 + 7 + 9 + kBodySize + 1;
287 var kNameMainOffset = kNamePrintOffset + 6; 287 var kNameMainOffset = kNamePrintOffset + 6;
288 288
289 var ffi = new Object(); 289 var ffi = new Object();
290 ffi.print = print; 290 ffi.print = print;
291 291
292 var data = bytes( 292 var data = bytesWithHeader(
293 // -- signatures 293 // -- signatures
294 kDeclSignatures, 2, 294 kDeclSignatures, 2,
295 1, kAstStmt, kAstI32, // i32->void 295 1, kAstStmt, kAstI32, // i32->void
296 1, kAstStmt, kAstF64, // f64->int 296 1, kAstStmt, kAstF64, // f64->int
297 kDeclFunctions, 3, 297 kDeclFunctions, 3,
298 // -- import print i32 298 // -- import print i32
299 kDeclFunctionName | kDeclFunctionImport, 299 kDeclFunctionName | kDeclFunctionImport,
300 0, 0, // signature index 300 0, 0, // signature index
301 kNamePrintOffset, 0, 0, 0, // name offset 301 kNamePrintOffset, 0, 0, 0, // name offset
302 // -- import print f64 302 // -- import print f64
(...skipping 21 matching lines...) Expand all
324 324
325 assertEquals("function", typeof module.main); 325 assertEquals("function", typeof module.main);
326 326
327 for (var i = -9; i < 900; i += 6.125) { 327 for (var i = -9; i < 900; i += 6.125) {
328 module.main(i); 328 module.main(i);
329 } 329 }
330 } 330 }
331 331
332 testCallPrint(); 332 testCallPrint();
333 testCallPrint(); 333 testCallPrint();
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/export-table.js ('k') | test/mjsunit/wasm/ffi-error.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698