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

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

Issue 2591753002: [wasm] Implement correct 2-level namespace for imports. (Closed)
Patch Set: Fix debug tests Created 4 years 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/gc-stress.js ('k') | test/mjsunit/wasm/import-memory.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 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 TestImported(type, val, expected) { 10 function TestImported(type, val, expected) {
11 print("TestImported " + type + "(" + val +")" + " = " + expected); 11 print("TestImported " + type + "(" + val +")" + " = " + expected);
12 var builder = new WasmModuleBuilder(); 12 var builder = new WasmModuleBuilder();
13 var sig = makeSig([], [type]); 13 var sig = makeSig([], [type]);
14 var g = builder.addImportedGlobal("foo", undefined, type); 14 var g = builder.addImportedGlobal("uuu", "foo", type);
15 builder.addFunction("main", sig) 15 builder.addFunction("main", sig)
16 .addBody([kExprGetGlobal, g.index]) 16 .addBody([kExprGetGlobal, g.index])
17 .exportAs("main"); 17 .exportAs("main");
18 builder.addGlobal(kAstI32); // pad 18 builder.addGlobal(kAstI32); // pad
19 19
20 var instance = builder.instantiate({foo: val}); 20 var instance = builder.instantiate({uuu: {foo: val}});
21 assertEquals(expected, instance.exports.main()); 21 assertEquals(expected, instance.exports.main());
22 } 22 }
23 23
24 TestImported(kAstI32, 300.1, 300); 24 TestImported(kAstI32, 300.1, 300);
25 TestImported(kAstF32, 87234.87238, Math.fround(87234.87238)); 25 TestImported(kAstF32, 87234.87238, Math.fround(87234.87238));
26 TestImported(kAstF64, 77777.88888, 77777.88888); 26 TestImported(kAstF64, 77777.88888, 77777.88888);
27 27
28 28
29 function TestExported(type, val, expected) { 29 function TestExported(type, val, expected) {
30 print("TestExported " + type + "(" + val +")" + " = " + expected); 30 print("TestExported " + type + "(" + val +")" + " = " + expected);
(...skipping 11 matching lines...) Expand all
42 42
43 TestExported(kAstI32, 455.5, 455); 43 TestExported(kAstI32, 455.5, 455);
44 TestExported(kAstF32, -999.34343, Math.fround(-999.34343)); 44 TestExported(kAstF32, -999.34343, Math.fround(-999.34343));
45 TestExported(kAstF64, 87347.66666, 87347.66666); 45 TestExported(kAstF64, 87347.66666, 87347.66666);
46 46
47 47
48 function TestImportedExported(type, val, expected) { 48 function TestImportedExported(type, val, expected) {
49 print("TestImportedExported " + type + "(" + val +")" + " = " + expected); 49 print("TestImportedExported " + type + "(" + val +")" + " = " + expected);
50 var builder = new WasmModuleBuilder(); 50 var builder = new WasmModuleBuilder();
51 var sig = makeSig([type], []); 51 var sig = makeSig([type], []);
52 var i = builder.addImportedGlobal("foo", undefined, type); 52 var i = builder.addImportedGlobal("ttt", "foo", type);
53 builder.addGlobal(kAstI32); // pad 53 builder.addGlobal(kAstI32); // pad
54 var o = builder.addGlobal(type, false) 54 var o = builder.addGlobal(type, false)
55 .exportAs("bar"); 55 .exportAs("bar");
56 o.init_index = i; 56 o.init_index = i;
57 builder.addGlobal(kAstI32); // pad 57 builder.addGlobal(kAstI32); // pad
58 58
59 var instance = builder.instantiate({foo: val}); 59 var instance = builder.instantiate({ttt: {foo: val}});
60 assertEquals(expected, instance.exports.bar); 60 assertEquals(expected, instance.exports.bar);
61 } 61 }
62 62
63 TestImportedExported(kAstI32, 415.5, 415); 63 TestImportedExported(kAstI32, 415.5, 415);
64 TestImportedExported(kAstF32, -979.34343, Math.fround(-979.34343)); 64 TestImportedExported(kAstF32, -979.34343, Math.fround(-979.34343));
65 TestImportedExported(kAstF64, 81347.66666, 81347.66666); 65 TestImportedExported(kAstF64, 81347.66666, 81347.66666);
66 66
67 function TestGlobalIndexSpace(type, val) { 67 function TestGlobalIndexSpace(type, val) {
68 print("TestGlobalIndexSpace(" + val + ") = " + val); 68 print("TestGlobalIndexSpace(" + val + ") = " + val);
69 var builder = new WasmModuleBuilder(); 69 var builder = new WasmModuleBuilder();
70 var im = builder.addImportedGlobal("foo", undefined, type); 70 var im = builder.addImportedGlobal("nnn", "foo", type);
71 assertEquals(0, im); 71 assertEquals(0, im);
72 var def = builder.addGlobal(type, false); 72 var def = builder.addGlobal(type, false);
73 assertEquals(1, def.index); 73 assertEquals(1, def.index);
74 def.init_index = im; 74 def.init_index = im;
75 75
76 var sig = makeSig([], [type]); 76 var sig = makeSig([], [type]);
77 builder.addFunction("main", sig) 77 builder.addFunction("main", sig)
78 .addBody([kExprGetGlobal, def.index]) 78 .addBody([kExprGetGlobal, def.index])
79 .exportAs("main"); 79 .exportAs("main");
80 80
81 var instance = builder.instantiate({foo: val}); 81 var instance = builder.instantiate({nnn: {foo: val}});
82 assertEquals(val, instance.exports.main()); 82 assertEquals(val, instance.exports.main());
83 } 83 }
84 84
85 TestGlobalIndexSpace(kAstI32, 123); 85 TestGlobalIndexSpace(kAstI32, 123);
86 TestGlobalIndexSpace(kAstF32, 54321.125); 86 TestGlobalIndexSpace(kAstF32, 54321.125);
87 TestGlobalIndexSpace(kAstF64, 12345.678); 87 TestGlobalIndexSpace(kAstF64, 12345.678);
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/gc-stress.js ('k') | test/mjsunit/wasm/import-memory.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698