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

Side by Side Diff: test/mjsunit/wasm/start-function.js

Issue 1692173002: [wasm] Add support for a start function. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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 | « src/wasm/wasm-module.cc ('k') | test/mjsunit/wasm/wasm-constants.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 // Flags: --expose-wasm
6
7 load("test/mjsunit/wasm/wasm-constants.js");
8
bradnelson 2016/02/12 17:29:55 Maybe add a test that two start sections fail?
9 function instantiate(sig, body) {
10 var module = new Array();
11 module = module.concat([
12 // -- signatures
13 kDeclSignatures, 1,
14 ]);
15 module = module.concat(sig);
16 module = module.concat([
17 // -- functions
18 kDeclFunctions, 1,
19 0, // decl flags
20 0, 0, // signature
21 body.length, 0, // body size
22 ]);
23 module = module.concat(body);
24 module = module.concat([
25 // -- declare start function
26 kDeclStartFunction,
27 0
28 ]);
29
30 var data = bytes.apply(this, module);
31 print(module);
32 print(data instanceof ArrayBuffer);
33 print(data.byteLength);
34 return _WASMEXP_.instantiateModule(data);
35 }
36
37 function assertFails(sig, body) {
38 try {
39 var module = instantiate(sig, body);
40 print("expected failure, but passes");
41 assertFalse(true);
42 } catch (expected) {
43 print("ok: " + expected);
44 }
45 }
46
47 function assertVerifies(sig, body) {
48 var module = instantiate(sig, body);
49 assertFalse(module === undefined);
50 assertFalse(module === null);
51 assertFalse(module === 0);
52 assertEquals("object", typeof module);
53 return module;
54 }
55
56 assertVerifies([0, kAstStmt], [kExprNop]);
57 assertVerifies([0, kAstI32], [kExprI8Const, 0]);
58 assertFails([1, kAstI32, kAstI32], [kExprGetLocal, 0]);
bradnelson 2016/02/12 17:29:55 Maybe either comment the goal is to confirm functi
59 assertFails([2, kAstI32, kAstI32, kAstF32], [kExprGetLocal, 0]);
60 assertFails([3, kAstI32, kAstI32, kAstF32, kAstF64], [kExprGetLocal, 0]);
61
62 (function testInvalidIndex() {
63 var kBodySize = 1;
64 var data = bytes(
65 // -- signatures
66 kDeclSignatures, 1,
67 0, kAstStmt,
68 // -- functions
69 kDeclFunctions, 1,
70 0, // decl flags
71 0, 0, // signature
72 kBodySize, 0, // body size
73 kExprNop, // body
74 // -- declare start function
75 kDeclStartFunction,
76 1
77 );
78
79 assertThrows(function() { _WASMEXP_.instantiateModule(data); });
80 })();
81
82
83 (function testRun() {
84 var kBodySize = 6;
85
86 var data = bytes(
87 kDeclMemory,
88 12, 12, 1, // memory
89 // -- signatures
90 kDeclSignatures, 1,
91 0, kAstStmt,
92 // -- start function
93 kDeclFunctions, 1,
94 0, // decl flags
95 0, 0, // signature
96 kBodySize, 0, // code size
97 // -- start body
98 kExprI32StoreMem, 0, kExprI8Const, 0, kExprI8Const, 77,
99 // -- declare start function
100 kDeclStartFunction,
101 0
102 );
103
104 var module = _WASMEXP_.instantiateModule(data);
105 var memory = module.memory;
106 var view = new Int8Array(memory);
107 assertEquals(77, view[0]);
108 })();
109
110 (function testStartFFI() {
111 var kBodySize = 2;
112 var kNameOffset = 4 + 9 + 7 + 3;
113
114 var data = bytes(
115 // -- signatures
116 kDeclSignatures, 1,
117 0, kAstStmt,
118 // -- imported function
119 kDeclFunctions, 2,
120 kDeclFunctionImport | kDeclFunctionName, // decl flags
121 0, 0, // signature
122 kNameOffset, 0, 0, 0,
123 // -- start function
124 0, // decl flags
125 0, 0, // signature
126 kBodySize, 0, // code size
127 // -- start body
128 kExprCallFunction, 0,
129 // -- declare start function
130 kDeclStartFunction,
131 1,
132 kDeclEnd,
133 'f', 'o', 'o', 0
134 );
135
136 var ranned = false;
137 var ffi = new Object();
138 ffi.foo = function() {
139 print("we ranned at stert!");
bradnelson 2016/02/12 17:29:55 This was totally done at 1am yeah? :-)
140 ranned = true;
141 }
142 var module = _WASMEXP_.instantiateModule(data, ffi);
143 var memory = module.memory;
144 var view = new Int8Array(memory);
145 assertTrue(ranned);
146 })();
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | test/mjsunit/wasm/wasm-constants.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698