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

Side by Side Diff: test/mjsunit/wasm/ffi.js

Issue 2345593003: [wasm] Master CL for Binary 0xC changes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix test failures and TSAN races. Created 4 years, 2 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 --allow-natives-syntax 5 // Flags: --expose-wasm --allow-natives-syntax
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 testCallFFI(func, check) { 10 function testCallFFI(func, check) {
11 var builder = new WasmModuleBuilder(); 11 var builder = new WasmModuleBuilder();
12 12
13 var sig_index = builder.addType(kSig_i_dd); 13 var sig_index = builder.addType(kSig_i_dd);
14 builder.addImport("func", sig_index); 14 builder.addImport("func", sig_index);
15 builder.addFunction("main", sig_index) 15 builder.addFunction("main", sig_index)
16 .addBody([ 16 .addBody([
17 kExprGetLocal, 0, // -- 17 kExprGetLocal, 0, // --
18 kExprGetLocal, 1, // -- 18 kExprGetLocal, 1, // --
19 kExprCallImport, kArity2, 0 // -- 19 kExprCallFunction, 0 // --
20 ]) // -- 20 ]) // --
21 .exportFunc(); 21 .exportFunc();
22 22
23 var main = builder.instantiate({func: func}).exports.main; 23 var main = builder.instantiate({func: func}).exports.main;
24 24
25 for (var i = 0; i < 100000; i += 10003) { 25 for (var i = 0; i < 100000; i += 10003) {
26 var a = 22.5 + i, b = 10.5 + i; 26 var a = 22.5 + i, b = 10.5 + i;
27 var r = main(a, b); 27 var r = main(a, b);
28 if (check) { 28 if (check) {
29 check(r, a, b); 29 check(r, a, b);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 (function testCallConstructor() { 73 (function testCallConstructor() {
74 class C {} 74 class C {}
75 var builder = new WasmModuleBuilder(); 75 var builder = new WasmModuleBuilder();
76 76
77 var sig_index = builder.addType(kSig_i_dd); 77 var sig_index = builder.addType(kSig_i_dd);
78 builder.addImport("func", sig_index); 78 builder.addImport("func", sig_index);
79 builder.addFunction("main", sig_index) 79 builder.addFunction("main", sig_index)
80 .addBody([ 80 .addBody([
81 kExprGetLocal, 0, // -- 81 kExprGetLocal, 0, // --
82 kExprGetLocal, 1, // -- 82 kExprGetLocal, 1, // --
83 kExprCallImport, kArity2, 0 // -- 83 kExprCallFunction, 0 // --
84 ]) // -- 84 ]) // --
85 .exportFunc(); 85 .exportFunc();
86 86
87 main_for_constructor_test = builder.instantiate({func: C}).exports.main; 87 main_for_constructor_test = builder.instantiate({func: C}).exports.main;
88 88
89 assertThrows("main_for_constructor_test(12, 43)", TypeError); 89 assertThrows("main_for_constructor_test(12, 43)", TypeError);
90 }) (); 90 }) ();
91 91
92 print("Native function"); 92 print("Native function");
93 (function test_ffi_call_to_native() { 93 (function test_ffi_call_to_native() {
94 94
95 var builder = new WasmModuleBuilder(); 95 var builder = new WasmModuleBuilder();
96 96
97 var sig_index = builder.addType(kSig_d); 97 var sig_index = builder.addType(kSig_d);
98 builder.addImport("func", sig_index); 98 builder.addImport("func", sig_index);
99 builder.addFunction("main", sig_index) 99 builder.addFunction("main", sig_index)
100 .addBody([ 100 .addBody([
101 kExprCallImport, kArity0, 0 // -- 101 kExprCallFunction, 0 // --
102 ]) // -- 102 ]) // --
103 .exportFunc(); 103 .exportFunc();
104 104
105 var main = builder.instantiate({func: Object.prototype.toString}).exports.main ; 105 var main = builder.instantiate({func: Object.prototype.toString}).exports.main ;
106 // The result of the call to Object.prototype.toString should be 106 // The result of the call to Object.prototype.toString should be
107 // [object Undefined]. However, we cannot test for this result because wasm 107 // [object Undefined]. However, we cannot test for this result because wasm
108 // cannot return objects but converts them to float64 in this test. 108 // cannot return objects but converts them to float64 in this test.
109 assertEquals(NaN, main()); 109 assertEquals(NaN, main());
110 })(); 110 })();
111 111
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 args_b = arguments[1]; 240 args_b = arguments[1];
241 }}; 241 }};
242 242
243 var builder = new WasmModuleBuilder(); 243 var builder = new WasmModuleBuilder();
244 244
245 builder.addImport("func", makeSig_v_xx(type)); 245 builder.addImport("func", makeSig_v_xx(type));
246 builder.addFunction("main", makeSig_r_xx(kAstI32, type)) 246 builder.addFunction("main", makeSig_r_xx(kAstI32, type))
247 .addBody([ 247 .addBody([
248 kExprGetLocal, 0, // -- 248 kExprGetLocal, 0, // --
249 kExprGetLocal, 1, // -- 249 kExprGetLocal, 1, // --
250 kExprCallImport, kArity2, 0, // -- 250 kExprCallFunction, 0, // --
251 kExprI8Const, 99 // -- 251 kExprI8Const, 99 // --
252 ]) // -- 252 ]) // --
253 .exportFunc() 253 .exportFunc()
254 254
255 var main = builder.instantiate(ffi).exports.main; 255 var main = builder.instantiate(ffi).exports.main;
256 256
257 print("testCallBinopVoid", type); 257 print("testCallBinopVoid", type);
258 258
259 for (var i = 0; i < 100000; i += 10003.1) { 259 for (var i = 0; i < 100000; i += 10003.1) {
260 var a = 22.5 + i, b = 10.5 + i; 260 var a = 22.5 + i, b = 10.5 + i;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 295
296 296
297 297
298 function testCallPrint() { 298 function testCallPrint() {
299 var builder = new WasmModuleBuilder(); 299 var builder = new WasmModuleBuilder();
300 300
301 builder.addImport("print", makeSig_v_x(kAstI32)); 301 builder.addImport("print", makeSig_v_x(kAstI32));
302 builder.addImport("print", makeSig_v_x(kAstF64)); 302 builder.addImport("print", makeSig_v_x(kAstF64));
303 builder.addFunction("main", makeSig_v_x(kAstF64)) 303 builder.addFunction("main", makeSig_v_x(kAstF64))
304 .addBody([ 304 .addBody([
305 kExprI8Const, 97, // -- 305 kExprI8Const, 97, // --
306 kExprCallImport, kArity1, 0, // -- 306 kExprCallFunction, 0, // --
307 kExprGetLocal, 0, // -- 307 kExprGetLocal, 0, // --
308 kExprCallImport, kArity1, 1 // -- 308 kExprCallFunction, 1 // --
309 ]) // -- 309 ]) // --
310 .exportFunc() 310 .exportFunc()
311 311
312 var main = builder.instantiate({print: print}).exports.main; 312 var main = builder.instantiate({print: print}).exports.main;
313 for (var i = -9; i < 900; i += 6.125) main(i); 313 for (var i = -9; i < 900; i += 6.125) main(i);
314 } 314 }
315 315
316 testCallPrint(); 316 testCallPrint();
317 testCallPrint(); 317 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