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

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

Issue 1763433002: [wasm] Rework encoding of local declarations. (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
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 8
9 (function testExportedMain() { 9 (function testExportedMain() {
10 var kBodySize = 3; 10 var kBodySize = 4;
11 var kReturnValue = 99; 11 var kReturnValue = 99;
12 var kNameMainOffset = kHeaderSize + 4 + 7 + kBodySize + 8 + 1; 12 var kNameMainOffset = kHeaderSize + 4 + 7 + kBodySize + 8 + 1;
13 13
14 var data = bytesWithHeader( 14 var data = bytesWithHeader(
15 // signatures 15 // signatures
16 kDeclSignatures, 1, 16 kDeclSignatures, 1,
17 0, kAstI32, // void -> i32 17 0, kAstI32, // void -> i32
18 // -- main function 18 // -- main function
19 kDeclFunctions, 19 kDeclFunctions,
20 1, 20 1,
21 0, // decl flags 21 0, // decl flags
22 0, 0, // signature index 22 0, 0, // signature index
23 kBodySize, 0, 23 kBodySize, 0,
24 // main body 24 // main body
25 kDeclNoLocals,
25 kExprReturn, 26 kExprReturn,
26 kExprI8Const, 27 kExprI8Const,
27 kReturnValue, 28 kReturnValue,
28 // exports 29 // exports
29 kDeclExportTable, 30 kDeclExportTable,
30 1, 31 1,
31 0, 0, // func index index 32 0, 0, // func index index
32 kNameMainOffset, 0, 0, 0, // function name offset 33 kNameMainOffset, 0, 0, 0, // function name offset
33 // names 34 // names
34 kDeclEnd, 35 kDeclEnd,
35 'm', 'a', 'i', 'n', 0 // -- 36 'm', 'a', 'i', 'n', 0 // --
36 ); 37 );
37 38
38 var ffi = new Object(); 39 var ffi = new Object();
39 var module = _WASMEXP_.instantiateModule(data, ffi); 40 var module = _WASMEXP_.instantiateModule(data, ffi);
40 41
41 assertEquals("object", typeof module.exports); 42 assertEquals("object", typeof module.exports);
42 assertEquals("function", typeof module.exports.main); 43 assertEquals("function", typeof module.exports.main);
43 44
44 assertEquals(kReturnValue, module.exports.main()); 45 assertEquals(kReturnValue, module.exports.main());
45 })(); 46 })();
46 47
47 (function testExportedTwice() { 48 (function testExportedTwice() {
48 var kBodySize = 3; 49 var kBodySize = 4;
49 var kReturnValue = 99; 50 var kReturnValue = 99;
50 var kNameMainOffset = kHeaderSize + 4 + 7 + kBodySize + 14 + 1; 51 var kNameMainOffset = kHeaderSize + 4 + 7 + kBodySize + 14 + 1;
51 var kNameFooOffset = kNameMainOffset + 5; 52 var kNameFooOffset = kNameMainOffset + 5;
52 53
53 var data = bytesWithHeader( 54 var data = bytesWithHeader(
54 // signatures 55 // signatures
55 kDeclSignatures, 1, 56 kDeclSignatures, 1,
56 0, kAstI32, // void -> i32 57 0, kAstI32, // void -> i32
57 // -- main function 58 // -- main function
58 kDeclFunctions, 59 kDeclFunctions,
59 1, 60 1,
60 0, // decl flags 61 0, // decl flags
61 0, 0, // signature index 62 0, 0, // signature index
62 kBodySize, 0, 63 kBodySize, 0,
63 // main body 64 // main body
65 kDeclNoLocals,
64 kExprReturn, 66 kExprReturn,
65 kExprI8Const, 67 kExprI8Const,
66 kReturnValue, 68 kReturnValue,
67 // exports 69 // exports
68 kDeclExportTable, 70 kDeclExportTable,
69 2, 71 2,
70 0, 0, // func index index 72 0, 0, // func index index
71 kNameMainOffset, 0, 0, 0, // function name offset 73 kNameMainOffset, 0, 0, 0, // function name offset
72 0, 0, // func index index 74 0, 0, // func index index
73 kNameFooOffset, 0, 0, 0, // function name offset 75 kNameFooOffset, 0, 0, 0, // function name offset
74 // names 76 // names
75 kDeclEnd, 77 kDeclEnd,
76 'b', 'l', 'a', 'h', 0, // -- 78 'b', 'l', 'a', 'h', 0, // --
77 'f', 'o', 'o', 0 // -- 79 'f', 'o', 'o', 0 // --
78 ); 80 );
79 81
80 var ffi = new Object(); 82 var ffi = new Object();
81 var module = _WASMEXP_.instantiateModule(data, ffi); 83 var module = _WASMEXP_.instantiateModule(data, ffi);
82 84
83 assertEquals("object", typeof module.exports); 85 assertEquals("object", typeof module.exports);
84 assertEquals("function", typeof module.exports.blah); 86 assertEquals("function", typeof module.exports.blah);
85 assertEquals("function", typeof module.exports.foo); 87 assertEquals("function", typeof module.exports.foo);
86 88
87 assertEquals(kReturnValue, module.exports.blah()); 89 assertEquals(kReturnValue, module.exports.blah());
88 assertEquals(kReturnValue, module.exports.foo()); 90 assertEquals(kReturnValue, module.exports.foo());
89 })(); 91 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698