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

Side by Side Diff: test/mjsunit/wasm/js-api.js

Issue 2644993002: [wasm] WebAssembly.instantiate has a pair-returning overload (Closed)
Patch Set: feedback Created 3 years, 11 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-js.cc ('k') | no next file » | 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 --allow-natives-syntax 5 // Flags: --expose-wasm --allow-natives-syntax
6 6
7 if ((typeof drainJobQueue) != "function") { 7 if ((typeof drainJobQueue) != "function") {
8 drainJobQueue = () => { %RunMicrotasks() }; 8 drainJobQueue = () => { %RunMicrotasks() };
9 } 9 }
10 10
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 let moduleBinaryWithMemSectionAndMemImport = (() => { 57 let moduleBinaryWithMemSectionAndMemImport = (() => {
58 var builder = new WasmModuleBuilder(); 58 var builder = new WasmModuleBuilder();
59 builder.addMemory(1, 1, false); 59 builder.addMemory(1, 1, false);
60 builder.addImportedMemory("", "memory1"); 60 builder.addImportedMemory("", "memory1");
61 return new Int8Array(builder.toBuffer()); 61 return new Int8Array(builder.toBuffer());
62 })(); 62 })();
63 63
64 // 'WebAssembly' data property on global object 64 // 'WebAssembly' data property on global object
65 let wasmDesc = Object.getOwnPropertyDescriptor(this, 'WebAssembly'); 65 let wasmDesc = Object.getOwnPropertyDescriptor(this, 'WebAssembly');
66 assertEq(typeof wasmDesc.value, "object"); 66 assertEq(typeof wasmDesc.value, "object");
67 assertEq(wasmDesc.writable, true); 67 assertTrue(wasmDesc.writable);
68 assertEq(wasmDesc.enumerable, false); 68 assertFalse(wasmDesc.enumerable);
69 assertEq(wasmDesc.configurable, true); 69 assertTrue(wasmDesc.configurable);
70 70
71 // 'WebAssembly' object 71 // 'WebAssembly' object
72 assertEq(WebAssembly, wasmDesc.value); 72 assertEq(WebAssembly, wasmDesc.value);
73 assertEq(String(WebAssembly), "[object WebAssembly]"); 73 assertEq(String(WebAssembly), "[object WebAssembly]");
74 74
75 // 'WebAssembly.CompileError' 75 // 'WebAssembly.CompileError'
76 let compileErrorDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'CompileErro r'); 76 let compileErrorDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'CompileErro r');
77 assertEq(typeof compileErrorDesc.value, "function"); 77 assertEq(typeof compileErrorDesc.value, "function");
78 assertEq(compileErrorDesc.writable, true); 78 assertTrue(compileErrorDesc.writable);
79 assertEq(compileErrorDesc.enumerable, false); 79 assertFalse(compileErrorDesc.enumerable);
80 assertEq(compileErrorDesc.configurable, true); 80 assertTrue(compileErrorDesc.configurable);
81 let CompileError = WebAssembly.CompileError; 81 let CompileError = WebAssembly.CompileError;
82 assertEq(CompileError, compileErrorDesc.value); 82 assertEq(CompileError, compileErrorDesc.value);
83 assertEq(CompileError.length, 1); 83 assertEq(CompileError.length, 1);
84 assertEq(CompileError.name, "CompileError"); 84 assertEq(CompileError.name, "CompileError");
85 let compileError = new CompileError; 85 let compileError = new CompileError;
86 assertEq(compileError instanceof CompileError, true); 86 assertTrue(compileError instanceof CompileError);
87 assertEq(compileError instanceof Error, true); 87 assertTrue(compileError instanceof Error);
88 assertEq(compileError instanceof TypeError, false); 88 assertFalse(compileError instanceof TypeError);
89 assertEq(compileError.message, ""); 89 assertEq(compileError.message, "");
90 assertEq(new CompileError("hi").message, "hi"); 90 assertEq(new CompileError("hi").message, "hi");
91 91
92 // 'WebAssembly.RuntimeError' 92 // 'WebAssembly.RuntimeError'
93 let runtimeErrorDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'RuntimeErro r'); 93 let runtimeErrorDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'RuntimeErro r');
94 assertEq(typeof runtimeErrorDesc.value, "function"); 94 assertEq(typeof runtimeErrorDesc.value, "function");
95 assertEq(runtimeErrorDesc.writable, true); 95 assertTrue(runtimeErrorDesc.writable);
96 assertEq(runtimeErrorDesc.enumerable, false); 96 assertFalse(runtimeErrorDesc.enumerable);
97 assertEq(runtimeErrorDesc.configurable, true); 97 assertTrue(runtimeErrorDesc.configurable);
98 let RuntimeError = WebAssembly.RuntimeError; 98 let RuntimeError = WebAssembly.RuntimeError;
99 assertEq(RuntimeError, runtimeErrorDesc.value); 99 assertEq(RuntimeError, runtimeErrorDesc.value);
100 assertEq(RuntimeError.length, 1); 100 assertEq(RuntimeError.length, 1);
101 assertEq(RuntimeError.name, "RuntimeError"); 101 assertEq(RuntimeError.name, "RuntimeError");
102 let runtimeError = new RuntimeError; 102 let runtimeError = new RuntimeError;
103 assertEq(runtimeError instanceof RuntimeError, true); 103 assertTrue(runtimeError instanceof RuntimeError);
104 assertEq(runtimeError instanceof Error, true); 104 assertTrue(runtimeError instanceof Error);
105 assertEq(runtimeError instanceof TypeError, false); 105 assertFalse(runtimeError instanceof TypeError);
106 assertEq(runtimeError.message, ""); 106 assertEq(runtimeError.message, "");
107 assertEq(new RuntimeError("hi").message, "hi"); 107 assertEq(new RuntimeError("hi").message, "hi");
108 108
109 // 'WebAssembly.LinkError' 109 // 'WebAssembly.LinkError'
110 let linkErrorDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'LinkError'); 110 let linkErrorDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'LinkError');
111 assertEq(typeof linkErrorDesc.value, "function"); 111 assertEq(typeof linkErrorDesc.value, "function");
112 assertEq(linkErrorDesc.writable, true); 112 assertTrue(linkErrorDesc.writable);
113 assertEq(linkErrorDesc.enumerable, false); 113 assertFalse(linkErrorDesc.enumerable);
114 assertEq(linkErrorDesc.configurable, true); 114 assertTrue(linkErrorDesc.configurable);
115 let LinkError = WebAssembly.LinkError; 115 let LinkError = WebAssembly.LinkError;
116 assertEq(LinkError, linkErrorDesc.value); 116 assertEq(LinkError, linkErrorDesc.value);
117 assertEq(LinkError.length, 1); 117 assertEq(LinkError.length, 1);
118 assertEq(LinkError.name, "LinkError"); 118 assertEq(LinkError.name, "LinkError");
119 let linkError = new LinkError; 119 let linkError = new LinkError;
120 assertEq(linkError instanceof LinkError, true); 120 assertTrue(linkError instanceof LinkError);
121 assertEq(linkError instanceof Error, true); 121 assertTrue(linkError instanceof Error);
122 assertEq(linkError instanceof TypeError, false); 122 assertFalse(linkError instanceof TypeError);
123 assertEq(linkError.message, ""); 123 assertEq(linkError.message, "");
124 assertEq(new LinkError("hi").message, "hi"); 124 assertEq(new LinkError("hi").message, "hi");
125 125
126 // 'WebAssembly.Module' data property 126 // 'WebAssembly.Module' data property
127 let moduleDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Module'); 127 let moduleDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Module');
128 assertEq(typeof moduleDesc.value, "function"); 128 assertEq(typeof moduleDesc.value, "function");
129 assertEq(moduleDesc.writable, true); 129 assertTrue(moduleDesc.writable);
130 assertEq(moduleDesc.enumerable, false); 130 assertFalse(moduleDesc.enumerable);
131 assertEq(moduleDesc.configurable, true); 131 assertTrue(moduleDesc.configurable);
132 132
133 // 'WebAssembly.Module' constructor function 133 // 'WebAssembly.Module' constructor function
134 let Module = WebAssembly.Module; 134 let Module = WebAssembly.Module;
135 assertEq(Module, moduleDesc.value); 135 assertEq(Module, moduleDesc.value);
136 assertEq(Module.length, 1); 136 assertEq(Module.length, 1);
137 assertEq(Module.name, "Module"); 137 assertEq(Module.name, "Module");
138 assertErrorMessage(() => Module(), TypeError, /constructor without new is forbid den/); 138 assertErrorMessage(() => Module(), TypeError, /constructor without new is forbid den/);
139 assertErrorMessage(() => new Module(), TypeError, /requires more than 0 argument s/); 139 assertErrorMessage(() => new Module(), TypeError, /requires more than 0 argument s/);
140 assertErrorMessage(() => new Module(undefined), TypeError, "first argument must be an ArrayBuffer or typed array object"); 140 assertErrorMessage(() => new Module(undefined), TypeError, "first argument must be an ArrayBuffer or typed array object");
141 assertErrorMessage(() => new Module(1), TypeError, "first argument must be an Ar rayBuffer or typed array object"); 141 assertErrorMessage(() => new Module(1), TypeError, "first argument must be an Ar rayBuffer or typed array object");
142 assertErrorMessage(() => new Module({}), TypeError, "first argument must be an A rrayBuffer or typed array object"); 142 assertErrorMessage(() => new Module({}), TypeError, "first argument must be an A rrayBuffer or typed array object");
143 assertErrorMessage(() => new Module(new Uint8Array()), CompileError, /failed to match magic number/); 143 assertErrorMessage(() => new Module(new Uint8Array()), CompileError, /failed to match magic number/);
144 assertErrorMessage(() => new Module(new ArrayBuffer()), CompileError, /failed to match magic number/); 144 assertErrorMessage(() => new Module(new ArrayBuffer()), CompileError, /failed to match magic number/);
145 assertEq(new Module(emptyModuleBinary) instanceof Module, true); 145 assertTrue(new Module(emptyModuleBinary) instanceof Module);
146 assertEq(new Module(emptyModuleBinary.buffer) instanceof Module, true); 146 assertTrue(new Module(emptyModuleBinary.buffer) instanceof Module);
147 147
148 // 'WebAssembly.Module.prototype' data property 148 // 'WebAssembly.Module.prototype' data property
149 let moduleProtoDesc = Object.getOwnPropertyDescriptor(Module, 'prototype'); 149 let moduleProtoDesc = Object.getOwnPropertyDescriptor(Module, 'prototype');
150 assertEq(typeof moduleProtoDesc.value, "object"); 150 assertEq(typeof moduleProtoDesc.value, "object");
151 assertEq(moduleProtoDesc.writable, false); 151 assertFalse(moduleProtoDesc.writable);
152 assertEq(moduleProtoDesc.enumerable, false); 152 assertFalse(moduleProtoDesc.enumerable);
153 assertEq(moduleProtoDesc.configurable, false); 153 assertFalse(moduleProtoDesc.configurable);
154 154
155 // 'WebAssembly.Module.prototype' object 155 // 'WebAssembly.Module.prototype' object
156 let moduleProto = Module.prototype; 156 let moduleProto = Module.prototype;
157 assertEq(moduleProto, moduleProtoDesc.value); 157 assertEq(moduleProto, moduleProtoDesc.value);
158 assertEq(String(moduleProto), "[object WebAssembly.Module]"); 158 assertEq(String(moduleProto), "[object WebAssembly.Module]");
159 assertEq(Object.getPrototypeOf(moduleProto), Object.prototype); 159 assertEq(Object.getPrototypeOf(moduleProto), Object.prototype);
160 160
161 // 'WebAssembly.Module' instance objects 161 // 'WebAssembly.Module' instance objects
162 let emptyModule = new Module(emptyModuleBinary); 162 let emptyModule = new Module(emptyModuleBinary);
163 let importingModule = new Module(importingModuleBinary); 163 let importingModule = new Module(importingModuleBinary);
164 let exportingModule = new Module(exportingModuleBinary); 164 let exportingModule = new Module(exportingModuleBinary);
165 assertEq(typeof emptyModule, "object"); 165 assertEq(typeof emptyModule, "object");
166 assertEq(String(emptyModule), "[object WebAssembly.Module]"); 166 assertEq(String(emptyModule), "[object WebAssembly.Module]");
167 assertEq(Object.getPrototypeOf(emptyModule), moduleProto); 167 assertEq(Object.getPrototypeOf(emptyModule), moduleProto);
168 168
169 // 'WebAssembly.Module.imports' data property 169 // 'WebAssembly.Module.imports' data property
170 let moduleImportsDesc = Object.getOwnPropertyDescriptor(Module, 'imports'); 170 let moduleImportsDesc = Object.getOwnPropertyDescriptor(Module, 'imports');
171 assertEq(typeof moduleImportsDesc.value, "function"); 171 assertEq(typeof moduleImportsDesc.value, "function");
172 assertEq(moduleImportsDesc.writable, true); 172 assertTrue(moduleImportsDesc.writable);
173 assertEq(moduleImportsDesc.enumerable, false); 173 assertFalse(moduleImportsDesc.enumerable);
174 assertEq(moduleImportsDesc.configurable, true); 174 assertTrue(moduleImportsDesc.configurable);
175 175
176 // 'WebAssembly.Module.imports' method 176 // 'WebAssembly.Module.imports' method
177 let moduleImports = moduleImportsDesc.value; 177 let moduleImports = moduleImportsDesc.value;
178 assertEq(moduleImports.length, 1); 178 assertEq(moduleImports.length, 1);
179 assertErrorMessage(() => moduleImports(), TypeError, /requires more than 0 argum ents/); 179 assertErrorMessage(() => moduleImports(), TypeError, /requires more than 0 argum ents/);
180 assertErrorMessage(() => moduleImports(undefined), TypeError, /first argument mu st be a WebAssembly.Module/); 180 assertErrorMessage(() => moduleImports(undefined), TypeError, /first argument mu st be a WebAssembly.Module/);
181 assertErrorMessage(() => moduleImports({}), TypeError, /first argument must be a WebAssembly.Module/); 181 assertErrorMessage(() => moduleImports({}), TypeError, /first argument must be a WebAssembly.Module/);
182 var arr = moduleImports(new Module(emptyModuleBinary)); 182 var arr = moduleImports(new Module(emptyModuleBinary));
183 assertEq(arr instanceof Array, true); 183 assertTrue(arr instanceof Array);
184 assertEq(arr.length, 0); 184 assertEq(arr.length, 0);
185 let importingModuleBinary2 = (() => { 185 let importingModuleBinary2 = (() => {
186 var text = '(module (func (import "a" "b")) (memory (import "c" "d") 1) (table (import "e" "f") 1 anyfunc) (global (import "g" "⚡") i32))' 186 var text = '(module (func (import "a" "b")) (memory (import "c" "d") 1) (table (import "e" "f") 1 anyfunc) (global (import "g" "⚡") i32))'
187 let builder = new WasmModuleBuilder(); 187 let builder = new WasmModuleBuilder();
188 builder.addImport("a", "b", kSig_i_i); 188 builder.addImport("a", "b", kSig_i_i);
189 builder.addImportedMemory("c", "d"); 189 builder.addImportedMemory("c", "d");
190 builder.addImportedTable("e", "f"); 190 builder.addImportedTable("e", "f");
191 builder.addImportedGlobal("g", "x", kWasmI32); 191 builder.addImportedGlobal("g", "x", kWasmI32);
192 return new Int8Array(builder.toBuffer()); 192 return new Int8Array(builder.toBuffer());
193 })(); 193 })();
194 var arr = moduleImports(new Module(importingModuleBinary2)); 194 var arr = moduleImports(new Module(importingModuleBinary2));
195 assertEq(arr instanceof Array, true); 195 assertTrue(arr instanceof Array);
196 assertEq(arr.length, 4); 196 assertEq(arr.length, 4);
197 assertEq(arr[0].kind, "function"); 197 assertEq(arr[0].kind, "function");
198 assertEq(arr[0].module, "a"); 198 assertEq(arr[0].module, "a");
199 assertEq(arr[0].name, "b"); 199 assertEq(arr[0].name, "b");
200 assertEq(arr[1].kind, "memory"); 200 assertEq(arr[1].kind, "memory");
201 assertEq(arr[1].module, "c"); 201 assertEq(arr[1].module, "c");
202 assertEq(arr[1].name, "d"); 202 assertEq(arr[1].name, "d");
203 assertEq(arr[2].kind, "table"); 203 assertEq(arr[2].kind, "table");
204 assertEq(arr[2].module, "e"); 204 assertEq(arr[2].module, "e");
205 assertEq(arr[2].name, "f"); 205 assertEq(arr[2].name, "f");
206 assertEq(arr[3].kind, "global"); 206 assertEq(arr[3].kind, "global");
207 assertEq(arr[3].module, "g"); 207 assertEq(arr[3].module, "g");
208 assertEq(arr[3].name, "x"); 208 assertEq(arr[3].name, "x");
209 209
210 // 'WebAssembly.Module.exports' data property 210 // 'WebAssembly.Module.exports' data property
211 let moduleExportsDesc = Object.getOwnPropertyDescriptor(Module, 'exports'); 211 let moduleExportsDesc = Object.getOwnPropertyDescriptor(Module, 'exports');
212 assertEq(typeof moduleExportsDesc.value, "function"); 212 assertEq(typeof moduleExportsDesc.value, "function");
213 assertEq(moduleExportsDesc.writable, true); 213 assertTrue(moduleExportsDesc.writable);
214 assertEq(moduleExportsDesc.enumerable, false); 214 assertFalse(moduleExportsDesc.enumerable);
215 assertEq(moduleExportsDesc.configurable, true); 215 assertTrue(moduleExportsDesc.configurable);
216 216
217 // 'WebAssembly.Module.exports' method 217 // 'WebAssembly.Module.exports' method
218 let moduleExports = moduleExportsDesc.value; 218 let moduleExports = moduleExportsDesc.value;
219 assertEq(moduleExports.length, 1); 219 assertEq(moduleExports.length, 1);
220 assertErrorMessage(() => moduleExports(), TypeError, /requires more than 0 argum ents/); 220 assertErrorMessage(() => moduleExports(), TypeError, /requires more than 0 argum ents/);
221 assertErrorMessage(() => moduleExports(undefined), TypeError, /first argument mu st be a WebAssembly.Module/); 221 assertErrorMessage(() => moduleExports(undefined), TypeError, /first argument mu st be a WebAssembly.Module/);
222 assertErrorMessage(() => moduleExports({}), TypeError, /first argument must be a WebAssembly.Module/); 222 assertErrorMessage(() => moduleExports({}), TypeError, /first argument must be a WebAssembly.Module/);
223 var arr = moduleExports(emptyModule); 223 var arr = moduleExports(emptyModule);
224 assertEq(arr instanceof Array, true); 224 assertTrue(arr instanceof Array);
225 assertEq(arr.length, 0); 225 assertEq(arr.length, 0);
226 let exportingModuleBinary2 = (() => { 226 let exportingModuleBinary2 = (() => {
227 var text = 227 var text =
228 '(module (func (export "a")) (memory (export "b") 1) (table (export "c") 1 any func) (global (export "⚡") i32 (i32.const 0)))'; 228 '(module (func (export "a")) (memory (export "b") 1) (table (export "c") 1 any func) (global (export "⚡") i32 (i32.const 0)))';
229 let builder = new WasmModuleBuilder(); 229 let builder = new WasmModuleBuilder();
230 builder.addFunction("foo", kSig_v_v) 230 builder.addFunction("foo", kSig_v_v)
231 .addBody([]) 231 .addBody([])
232 .exportAs("a"); 232 .exportAs("a");
233 builder.addMemory(1, 1, false); 233 builder.addMemory(1, 1, false);
234 builder.exportMemoryAs("b"); 234 builder.exportMemoryAs("b");
235 builder.setFunctionTableLength(1); 235 builder.setFunctionTableLength(1);
236 builder.addExportOfKind("c", kExternalTable, 0); 236 builder.addExportOfKind("c", kExternalTable, 0);
237 var o = builder.addGlobal(kWasmI32, false) 237 var o = builder.addGlobal(kWasmI32, false)
238 .exportAs("x"); 238 .exportAs("x");
239 return new Int8Array(builder.toBuffer()); 239 return new Int8Array(builder.toBuffer());
240 })(); 240 })();
241 var arr = moduleExports(new Module(exportingModuleBinary2)); 241 var arr = moduleExports(new Module(exportingModuleBinary2));
242 assertEq(arr instanceof Array, true); 242 assertTrue(arr instanceof Array);
243 assertEq(arr.length, 4); 243 assertEq(arr.length, 4);
244 assertEq(arr[0].kind, "function"); 244 assertEq(arr[0].kind, "function");
245 assertEq(arr[0].name, "a"); 245 assertEq(arr[0].name, "a");
246 assertEq(arr[1].kind, "memory"); 246 assertEq(arr[1].kind, "memory");
247 assertEq(arr[1].name, "b"); 247 assertEq(arr[1].name, "b");
248 assertEq(arr[2].kind, "table"); 248 assertEq(arr[2].kind, "table");
249 assertEq(arr[2].name, "c"); 249 assertEq(arr[2].name, "c");
250 assertEq(arr[3].kind, "global"); 250 assertEq(arr[3].kind, "global");
251 assertEq(arr[3].name, "x"); 251 assertEq(arr[3].name, "x");
252 252
253 // 'WebAssembly.Instance' data property 253 // 'WebAssembly.Instance' data property
254 let instanceDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Instance'); 254 let instanceDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Instance');
255 assertEq(typeof instanceDesc.value, "function"); 255 assertEq(typeof instanceDesc.value, "function");
256 assertEq(instanceDesc.writable, true); 256 assertTrue(instanceDesc.writable);
257 assertEq(instanceDesc.enumerable, false); 257 assertFalse(instanceDesc.enumerable);
258 assertEq(instanceDesc.configurable, true); 258 assertTrue(instanceDesc.configurable);
259 259
260 // 'WebAssembly.Instance' constructor function 260 // 'WebAssembly.Instance' constructor function
261 let Instance = WebAssembly.Instance; 261 let Instance = WebAssembly.Instance;
262 assertEq(Instance, instanceDesc.value); 262 assertEq(Instance, instanceDesc.value);
263 assertEq(Instance.length, 1); 263 assertEq(Instance.length, 1);
264 assertEq(Instance.name, "Instance"); 264 assertEq(Instance.name, "Instance");
265 265
266 assertErrorMessage(() => Instance(), TypeError, /constructor without new is forb idden/); 266 assertErrorMessage(() => Instance(), TypeError, /constructor without new is forb idden/);
267 assertErrorMessage(() => new Instance(1), TypeError, "first argument must be a W ebAssembly.Module"); 267 assertErrorMessage(() => new Instance(1), TypeError, "first argument must be a W ebAssembly.Module");
268 assertErrorMessage(() => new Instance({}), TypeError, "first argument must be a WebAssembly.Module"); 268 assertErrorMessage(() => new Instance({}), TypeError, "first argument must be a WebAssembly.Module");
269 assertErrorMessage(() => new Instance(emptyModule, null), TypeError, "second arg ument must be an object"); 269 assertErrorMessage(() => new Instance(emptyModule, null), TypeError, "second arg ument must be an object");
270 assertErrorMessage(() => new Instance(importingModule, null), TypeError, ""); 270 assertErrorMessage(() => new Instance(importingModule, null), TypeError, "");
271 assertErrorMessage(() => new Instance(importingModule, undefined), TypeError, "" ); 271 assertErrorMessage(() => new Instance(importingModule, undefined), TypeError, "" );
272 assertErrorMessage(() => new Instance(importingModule, {"":{g:()=>{}}}), LinkErr or, ""); 272 assertErrorMessage(() => new Instance(importingModule, {"":{g:()=>{}}}), LinkErr or, "");
273 assertErrorMessage(() => new Instance(importingModule, {t:{f:()=>{}}}), LinkErro r, ""); 273 assertErrorMessage(() => new Instance(importingModule, {t:{f:()=>{}}}), LinkErro r, "");
274 274
275 assertEq(new Instance(emptyModule) instanceof Instance, true); 275 assertTrue(new Instance(emptyModule) instanceof Instance);
276 assertEq(new Instance(emptyModule, {}) instanceof Instance, true); 276 assertTrue(new Instance(emptyModule, {}) instanceof Instance);
277 277
278 // 'WebAssembly.Instance.prototype' data property 278 // 'WebAssembly.Instance.prototype' data property
279 let instanceProtoDesc = Object.getOwnPropertyDescriptor(Instance, 'prototype'); 279 let instanceProtoDesc = Object.getOwnPropertyDescriptor(Instance, 'prototype');
280 assertEq(typeof instanceProtoDesc.value, "object"); 280 assertEq(typeof instanceProtoDesc.value, "object");
281 assertEq(instanceProtoDesc.writable, false); 281 assertFalse(instanceProtoDesc.writable);
282 assertEq(instanceProtoDesc.enumerable, false); 282 assertFalse(instanceProtoDesc.enumerable);
283 assertEq(instanceProtoDesc.configurable, false); 283 assertFalse(instanceProtoDesc.configurable);
284 284
285 // 'WebAssembly.Instance.prototype' object 285 // 'WebAssembly.Instance.prototype' object
286 let instanceProto = Instance.prototype; 286 let instanceProto = Instance.prototype;
287 assertEq(instanceProto, instanceProtoDesc.value); 287 assertEq(instanceProto, instanceProtoDesc.value);
288 assertEq(String(instanceProto), "[object WebAssembly.Instance]"); 288 assertEq(String(instanceProto), "[object WebAssembly.Instance]");
289 assertEq(Object.getPrototypeOf(instanceProto), Object.prototype); 289 assertEq(Object.getPrototypeOf(instanceProto), Object.prototype);
290 290
291 // 'WebAssembly.Instance' instance objects 291 // 'WebAssembly.Instance' instance objects
292 let exportingInstance = new Instance(exportingModule); 292 let exportingInstance = new Instance(exportingModule);
293 assertEq(typeof exportingInstance, "object"); 293 assertEq(typeof exportingInstance, "object");
294 assertEq(String(exportingInstance), "[object WebAssembly.Instance]"); 294 assertEq(String(exportingInstance), "[object WebAssembly.Instance]");
295 assertEq(Object.getPrototypeOf(exportingInstance), instanceProto); 295 assertEq(Object.getPrototypeOf(exportingInstance), instanceProto);
296 296
297 // 'WebAssembly.Instance' 'exports' data property 297 // 'WebAssembly.Instance' 'exports' data property
298 let instanceExportsDesc = Object.getOwnPropertyDescriptor(exportingInstance, 'ex ports'); 298 let instanceExportsDesc = Object.getOwnPropertyDescriptor(exportingInstance, 'ex ports');
299 assertEq(typeof instanceExportsDesc.value, "object"); 299 assertEq(typeof instanceExportsDesc.value, "object");
300 assertEq(instanceExportsDesc.writable, true); 300 assertTrue(instanceExportsDesc.writable);
301 assertEq(instanceExportsDesc.enumerable, true); 301 assertTrue(instanceExportsDesc.enumerable);
302 assertEq(instanceExportsDesc.configurable, true); 302 assertTrue(instanceExportsDesc.configurable);
303 303
304 // Exported WebAssembly functions 304 // Exported WebAssembly functions
305 let f = exportingInstance.exports.f; 305 let f = exportingInstance.exports.f;
306 assertEq(f instanceof Function, true); 306 assertTrue(f instanceof Function);
307 assertEq(f.length, 0); 307 assertEq(f.length, 0);
308 assertEq('name' in f, true); 308 assertTrue('name' in f);
309 assertEq(Function.prototype.call.call(f), 42); 309 assertEq(Function.prototype.call.call(f), 42);
310 assertErrorMessage(() => new f(), TypeError, /is not a constructor/); 310 assertErrorMessage(() => new f(), TypeError, /is not a constructor/);
311 311
312 // 'WebAssembly.Memory' data property 312 // 'WebAssembly.Memory' data property
313 let memoryDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Memory'); 313 let memoryDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Memory');
314 assertEq(typeof memoryDesc.value, "function"); 314 assertEq(typeof memoryDesc.value, "function");
315 assertEq(memoryDesc.writable, true); 315 assertTrue(memoryDesc.writable);
316 assertEq(memoryDesc.enumerable, false); 316 assertFalse(memoryDesc.enumerable);
317 assertEq(memoryDesc.configurable, true); 317 assertTrue(memoryDesc.configurable);
318 318
319 // 'WebAssembly.Memory' constructor function 319 // 'WebAssembly.Memory' constructor function
320 let Memory = WebAssembly.Memory; 320 let Memory = WebAssembly.Memory;
321 assertEq(Memory, memoryDesc.value); 321 assertEq(Memory, memoryDesc.value);
322 assertEq(Memory.length, 1); 322 assertEq(Memory.length, 1);
323 assertEq(Memory.name, "Memory"); 323 assertEq(Memory.name, "Memory");
324 assertErrorMessage(() => Memory(), TypeError, /constructor without new is forbid den/); 324 assertErrorMessage(() => Memory(), TypeError, /constructor without new is forbid den/);
325 assertErrorMessage(() => new Memory(1), TypeError, "first argument must be a mem ory descriptor"); 325 assertErrorMessage(() => new Memory(1), TypeError, "first argument must be a mem ory descriptor");
326 assertErrorMessage(() => new Memory({initial:{valueOf() { throw new Error("here" )}}}), Error, "here"); 326 assertErrorMessage(() => new Memory({initial:{valueOf() { throw new Error("here" )}}}), Error, "here");
327 assertErrorMessage(() => new Memory({initial:-1}), RangeError, /bad Memory initi al size/); 327 assertErrorMessage(() => new Memory({initial:-1}), RangeError, /bad Memory initi al size/);
328 assertErrorMessage(() => new Memory({initial:Math.pow(2,32)}), RangeError, /bad Memory initial size/); 328 assertErrorMessage(() => new Memory({initial:Math.pow(2,32)}), RangeError, /bad Memory initial size/);
329 assertErrorMessage(() => new Memory({initial:1, maximum: Math.pow(2,32)/Math.pow (2,14) }), RangeError, /bad Memory maximum size/); 329 assertErrorMessage(() => new Memory({initial:1, maximum: Math.pow(2,32)/Math.pow (2,14) }), RangeError, /bad Memory maximum size/);
330 assertErrorMessage(() => new Memory({initial:2, maximum:1 }), RangeError, /bad M emory maximum size/); 330 assertErrorMessage(() => new Memory({initial:2, maximum:1 }), RangeError, /bad M emory maximum size/);
331 assertErrorMessage(() => new Memory({maximum: -1 }), RangeError, /bad Memory max imum size/); 331 assertErrorMessage(() => new Memory({maximum: -1 }), RangeError, /bad Memory max imum size/);
332 assertEq(new Memory({initial:1}) instanceof Memory, true); 332 assertTrue(new Memory({initial: 1}) instanceof Memory);
333 assertEq(new Memory({initial:1.5}).buffer.byteLength, kPageSize); 333 assertEq(new Memory({initial:1.5}).buffer.byteLength, kPageSize);
334 334
335 // 'WebAssembly.Memory.prototype' data property 335 // 'WebAssembly.Memory.prototype' data property
336 let memoryProtoDesc = Object.getOwnPropertyDescriptor(Memory, 'prototype'); 336 let memoryProtoDesc = Object.getOwnPropertyDescriptor(Memory, 'prototype');
337 assertEq(typeof memoryProtoDesc.value, "object"); 337 assertEq(typeof memoryProtoDesc.value, "object");
338 assertEq(memoryProtoDesc.writable, false); 338 assertFalse(memoryProtoDesc.writable);
339 assertEq(memoryProtoDesc.enumerable, false); 339 assertFalse(memoryProtoDesc.enumerable);
340 assertEq(memoryProtoDesc.configurable, false); 340 assertFalse(memoryProtoDesc.configurable);
341 341
342 // 'WebAssembly.Memory.prototype' object 342 // 'WebAssembly.Memory.prototype' object
343 let memoryProto = Memory.prototype; 343 let memoryProto = Memory.prototype;
344 assertEq(memoryProto, memoryProtoDesc.value); 344 assertEq(memoryProto, memoryProtoDesc.value);
345 assertEq(String(memoryProto), "[object WebAssembly.Memory]"); 345 assertEq(String(memoryProto), "[object WebAssembly.Memory]");
346 assertEq(Object.getPrototypeOf(memoryProto), Object.prototype); 346 assertEq(Object.getPrototypeOf(memoryProto), Object.prototype);
347 347
348 // 'WebAssembly.Memory' instance objects 348 // 'WebAssembly.Memory' instance objects
349 let mem1 = new Memory({initial:1}); 349 let mem1 = new Memory({initial:1});
350 assertEq(typeof mem1, "object"); 350 assertEq(typeof mem1, "object");
351 assertEq(String(mem1), "[object WebAssembly.Memory]"); 351 assertEq(String(mem1), "[object WebAssembly.Memory]");
352 assertEq(Object.getPrototypeOf(mem1), memoryProto); 352 assertEq(Object.getPrototypeOf(mem1), memoryProto);
353 353
354 // 'WebAssembly.Memory.prototype.buffer' accessor property 354 // 'WebAssembly.Memory.prototype.buffer' accessor property
355 let bufferDesc = Object.getOwnPropertyDescriptor(memoryProto, 'buffer'); 355 let bufferDesc = Object.getOwnPropertyDescriptor(memoryProto, 'buffer');
356 assertEq(typeof bufferDesc.get, "function"); 356 assertEq(typeof bufferDesc.get, "function");
357 assertEq(bufferDesc.set, undefined); 357 assertEq(bufferDesc.set, undefined);
358 assertEq(bufferDesc.enumerable, false); 358 assertFalse(bufferDesc.enumerable);
359 assertEq(bufferDesc.configurable, true); 359 assertTrue(bufferDesc.configurable);
360 360
361 // 'WebAssembly.Memory.prototype.buffer' getter 361 // 'WebAssembly.Memory.prototype.buffer' getter
362 let bufferGetter = bufferDesc.get; 362 let bufferGetter = bufferDesc.get;
363 assertErrorMessage(() => bufferGetter.call(), TypeError, /called on incompatible undefined/); 363 assertErrorMessage(() => bufferGetter.call(), TypeError, /called on incompatible undefined/);
364 assertErrorMessage(() => bufferGetter.call({}), TypeError, /called on incompatib le Object/); 364 assertErrorMessage(() => bufferGetter.call({}), TypeError, /called on incompatib le Object/);
365 assertEq(bufferGetter.call(mem1) instanceof ArrayBuffer, true); 365 assertTrue(bufferGetter.call(mem1) instanceof ArrayBuffer);
366 assertEq(bufferGetter.call(mem1).byteLength, kPageSize); 366 assertEq(bufferGetter.call(mem1).byteLength, kPageSize);
367 367
368 // 'WebAssembly.Memory.prototype.grow' data property 368 // 'WebAssembly.Memory.prototype.grow' data property
369 let memGrowDesc = Object.getOwnPropertyDescriptor(memoryProto, 'grow'); 369 let memGrowDesc = Object.getOwnPropertyDescriptor(memoryProto, 'grow');
370 assertEq(typeof memGrowDesc.value, "function"); 370 assertEq(typeof memGrowDesc.value, "function");
371 assertEq(memGrowDesc.enumerable, false); 371 assertFalse(memGrowDesc.enumerable);
372 assertEq(memGrowDesc.configurable, true); 372 assertTrue(memGrowDesc.configurable);
373 373
374 // 'WebAssembly.Memory.prototype.grow' method 374 // 'WebAssembly.Memory.prototype.grow' method
375 375
376 let memGrow = memGrowDesc.value; 376 let memGrow = memGrowDesc.value;
377 assertEq(memGrow.length, 1); 377 assertEq(memGrow.length, 1);
378 assertErrorMessage(() => memGrow.call(), TypeError, 378 assertErrorMessage(() => memGrow.call(), TypeError,
379 /called on incompatible undefined/); 379 /called on incompatible undefined/);
380 assertErrorMessage(() => memGrow.call({}), TypeError, 380 assertErrorMessage(() => memGrow.call({}), TypeError,
381 /called on incompatible Object/); 381 /called on incompatible Object/);
382 assertErrorMessage(() => memGrow.call(mem1, -1), RangeError, 382 assertErrorMessage(() => memGrow.call(mem1, -1), RangeError,
383 /bad Memory grow delta/); 383 /bad Memory grow delta/);
384 assertErrorMessage(() => memGrow.call(mem1, Math.pow(2,32)), RangeError, 384 assertErrorMessage(() => memGrow.call(mem1, Math.pow(2,32)), RangeError,
385 /bad Memory grow delta/); 385 /bad Memory grow delta/);
386 var mem = new Memory({initial:1, maximum:2}); 386 var mem = new Memory({initial:1, maximum:2});
387 var buf = mem.buffer; 387 var buf = mem.buffer;
388 assertEq(buf.byteLength, kPageSize); 388 assertEq(buf.byteLength, kPageSize);
389 assertEq(mem.grow(0), 1); 389 assertEq(mem.grow(0), 1);
390 // TODO(gdeepti): Pending spec clarification 390 // TODO(gdeepti): Pending spec clarification
391 // assertEq(buf !== mem.buffer, true); 391 // assertTrue(buf !== mem.buffer);
392 // assertEq(buf.byteLength, 0); 392 // assertEq(buf.byteLength, 0);
393 buf = mem.buffer; 393 buf = mem.buffer;
394 assertEq(buf.byteLength, kPageSize); 394 assertEq(buf.byteLength, kPageSize);
395 assertEq(mem.grow(1), 1); 395 assertEq(mem.grow(1), 1);
396 // TODO(gdeepti): assertEq(buf !== mem.buffer, true); 396 // TODO(gdeepti): assertTrue(buf !== mem.buffer);
397 // TODO(gdeepti): assertEq(buf.byteLength, 0); 397 // TODO(gdeepti): assertEq(buf.byteLength, 0);
398 buf = mem.buffer; 398 buf = mem.buffer;
399 assertEq(buf.byteLength, 2 * kPageSize); 399 assertEq(buf.byteLength, 2 * kPageSize);
400 assertErrorMessage(() => mem.grow(1), Error, /failed to grow memory/); 400 assertErrorMessage(() => mem.grow(1), Error, /failed to grow memory/);
401 assertEq(buf, mem.buffer); 401 assertEq(buf, mem.buffer);
402 402
403 // 'WebAssembly.Table' data property 403 // 'WebAssembly.Table' data property
404 let tableDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Table'); 404 let tableDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Table');
405 assertEq(typeof tableDesc.value, "function"); 405 assertEq(typeof tableDesc.value, "function");
406 assertEq(tableDesc.writable, true); 406 assertTrue(tableDesc.writable);
407 assertEq(tableDesc.enumerable, false); 407 assertFalse(tableDesc.enumerable);
408 assertEq(tableDesc.configurable, true); 408 assertTrue(tableDesc.configurable);
409 409
410 // 'WebAssembly.Table' constructor function 410 // 'WebAssembly.Table' constructor function
411 let Table = WebAssembly.Table; 411 let Table = WebAssembly.Table;
412 assertEq(Table, tableDesc.value); 412 assertEq(Table, tableDesc.value);
413 assertEq(Table.length, 1); 413 assertEq(Table.length, 1);
414 assertEq(Table.name, "Table"); 414 assertEq(Table.name, "Table");
415 assertErrorMessage(() => Table(), TypeError, /constructor without new is forbidd en/); 415 assertErrorMessage(() => Table(), TypeError, /constructor without new is forbidd en/);
416 assertErrorMessage(() => new Table(1), TypeError, "first argument must be a tabl e descriptor"); 416 assertErrorMessage(() => new Table(1), TypeError, "first argument must be a tabl e descriptor");
417 assertErrorMessage(() => new Table({initial:1, element:1}), TypeError, /must be "anyfunc"/); 417 assertErrorMessage(() => new Table({initial:1, element:1}), TypeError, /must be "anyfunc"/);
418 assertErrorMessage(() => new Table({initial:1, element:"any"}), TypeError, /must be "anyfunc"/); 418 assertErrorMessage(() => new Table({initial:1, element:"any"}), TypeError, /must be "anyfunc"/);
419 assertErrorMessage(() => new Table({initial:1, element:{valueOf() { return "anyf unc" }}}), TypeError, /must be "anyfunc"/); 419 assertErrorMessage(() => new Table({initial:1, element:{valueOf() { return "anyf unc" }}}), TypeError, /must be "anyfunc"/);
420 assertErrorMessage(() => new Table({initial:{valueOf() { throw new Error("here") }}, element:"anyfunc"}), Error, "here"); 420 assertErrorMessage(() => new Table({initial:{valueOf() { throw new Error("here") }}, element:"anyfunc"}), Error, "here");
421 assertErrorMessage(() => new Table({initial:-1, element:"anyfunc"}), RangeError, /bad Table initial size/); 421 assertErrorMessage(() => new Table({initial:-1, element:"anyfunc"}), RangeError, /bad Table initial size/);
422 assertErrorMessage(() => new Table({initial:Math.pow(2,32), element:"anyfunc"}), RangeError, /bad Table initial size/); 422 assertErrorMessage(() => new Table({initial:Math.pow(2,32), element:"anyfunc"}), RangeError, /bad Table initial size/);
423 assertErrorMessage(() => new Table({initial:2, maximum:1, element:"anyfunc"}), R angeError, /bad Table maximum size/); 423 assertErrorMessage(() => new Table({initial:2, maximum:1, element:"anyfunc"}), R angeError, /bad Table maximum size/);
424 assertErrorMessage(() => new Table({initial:2, maximum:Math.pow(2,32), element:" anyfunc"}), RangeError, /bad Table maximum size/); 424 assertErrorMessage(() => new Table({initial:2, maximum:Math.pow(2,32), element:" anyfunc"}), RangeError, /bad Table maximum size/);
425 assertEq(new Table({initial:1, element:"anyfunc"}) instanceof Table, true); 425 assertTrue(new Table({initial: 1, element: 'anyfunc'}) instanceof Table);
426 assertEq(new Table({initial:1.5, element:"anyfunc"}) instanceof Table, true); 426 assertTrue(new Table({initial: 1.5, element: 'anyfunc'}) instanceof Table);
427 assertEq(new Table({initial:1, maximum:1.5, element:"anyfunc"}) instanceof Table , true); 427 assertTrue(
428 //TODO:maximum assertEq(new Table({initial:1, maximum:Math.pow(2,32)-1, element: "anyfunc"}) instanceof Table, true); 428 new Table({initial: 1, maximum: 1.5, element: 'anyfunc'}) instanceof Table);
429 // TODO:maximum assertTrue(new Table({initial:1, maximum:Math.pow(2,32)-1,
430 // element:"anyfunc"}) instanceof Table);
429 431
430 // 'WebAssembly.Table.prototype' data property 432 // 'WebAssembly.Table.prototype' data property
431 let tableProtoDesc = Object.getOwnPropertyDescriptor(Table, 'prototype'); 433 let tableProtoDesc = Object.getOwnPropertyDescriptor(Table, 'prototype');
432 assertEq(typeof tableProtoDesc.value, "object"); 434 assertEq(typeof tableProtoDesc.value, "object");
433 assertEq(tableProtoDesc.writable, false); 435 assertFalse(tableProtoDesc.writable);
434 assertEq(tableProtoDesc.enumerable, false); 436 assertFalse(tableProtoDesc.enumerable);
435 assertEq(tableProtoDesc.configurable, false); 437 assertFalse(tableProtoDesc.configurable);
436 438
437 // 'WebAssembly.Table.prototype' object 439 // 'WebAssembly.Table.prototype' object
438 let tableProto = Table.prototype; 440 let tableProto = Table.prototype;
439 assertEq(tableProto, tableProtoDesc.value); 441 assertEq(tableProto, tableProtoDesc.value);
440 assertEq(String(tableProto), "[object WebAssembly.Table]"); 442 assertEq(String(tableProto), "[object WebAssembly.Table]");
441 assertEq(Object.getPrototypeOf(tableProto), Object.prototype); 443 assertEq(Object.getPrototypeOf(tableProto), Object.prototype);
442 444
443 // 'WebAssembly.Table' instance objects 445 // 'WebAssembly.Table' instance objects
444 let tbl1 = new Table({initial:2, element:"anyfunc"}); 446 let tbl1 = new Table({initial:2, element:"anyfunc"});
445 assertEq(typeof tbl1, "object"); 447 assertEq(typeof tbl1, "object");
446 assertEq(String(tbl1), "[object WebAssembly.Table]"); 448 assertEq(String(tbl1), "[object WebAssembly.Table]");
447 assertEq(Object.getPrototypeOf(tbl1), tableProto); 449 assertEq(Object.getPrototypeOf(tbl1), tableProto);
448 450
449 // 'WebAssembly.Table.prototype.length' accessor data property 451 // 'WebAssembly.Table.prototype.length' accessor data property
450 let lengthDesc = Object.getOwnPropertyDescriptor(tableProto, 'length'); 452 let lengthDesc = Object.getOwnPropertyDescriptor(tableProto, 'length');
451 assertEq(typeof lengthDesc.get, "function"); 453 assertEq(typeof lengthDesc.get, "function");
452 assertEq(lengthDesc.set, undefined); 454 assertEq(lengthDesc.set, undefined);
453 assertEq(lengthDesc.enumerable, false); 455 assertFalse(lengthDesc.enumerable);
454 assertEq(lengthDesc.configurable, true); 456 assertTrue(lengthDesc.configurable);
455 457
456 // 'WebAssembly.Table.prototype.length' getter 458 // 'WebAssembly.Table.prototype.length' getter
457 let lengthGetter = lengthDesc.get; 459 let lengthGetter = lengthDesc.get;
458 assertEq(lengthGetter.length, 0); 460 assertEq(lengthGetter.length, 0);
459 assertErrorMessage(() => lengthGetter.call(), TypeError, /called on incompatible undefined/); 461 assertErrorMessage(() => lengthGetter.call(), TypeError, /called on incompatible undefined/);
460 assertErrorMessage(() => lengthGetter.call({}), TypeError, /called on incompatib le Object/); 462 assertErrorMessage(() => lengthGetter.call({}), TypeError, /called on incompatib le Object/);
461 assertEq(typeof lengthGetter.call(tbl1), "number"); 463 assertEq(typeof lengthGetter.call(tbl1), "number");
462 assertEq(lengthGetter.call(tbl1), 2); 464 assertEq(lengthGetter.call(tbl1), 2);
463 465
464 // 'WebAssembly.Table.prototype.get' data property 466 // 'WebAssembly.Table.prototype.get' data property
465 let getDesc = Object.getOwnPropertyDescriptor(tableProto, 'get'); 467 let getDesc = Object.getOwnPropertyDescriptor(tableProto, 'get');
466 assertEq(typeof getDesc.value, "function"); 468 assertEq(typeof getDesc.value, "function");
467 assertEq(getDesc.enumerable, false); 469 assertFalse(getDesc.enumerable);
468 assertEq(getDesc.configurable, true); 470 assertTrue(getDesc.configurable);
469 471
470 // 'WebAssembly.Table.prototype.get' method 472 // 'WebAssembly.Table.prototype.get' method
471 let get = getDesc.value; 473 let get = getDesc.value;
472 assertEq(get.length, 1); 474 assertEq(get.length, 1);
473 assertErrorMessage(() => get.call(), TypeError, /called on incompatible undefine d/); 475 assertErrorMessage(() => get.call(), TypeError, /called on incompatible undefine d/);
474 assertErrorMessage(() => get.call({}), TypeError, /called on incompatible Object /); 476 assertErrorMessage(() => get.call({}), TypeError, /called on incompatible Object /);
475 assertEq(get.call(tbl1, 0), null); 477 assertEq(get.call(tbl1, 0), null);
476 assertEq(get.call(tbl1, 1), null); 478 assertEq(get.call(tbl1, 1), null);
477 assertEq(get.call(tbl1, 1.5), null); 479 assertEq(get.call(tbl1, 1.5), null);
478 assertErrorMessage(() => get.call(tbl1, 2), RangeError, /bad Table get index/); 480 assertErrorMessage(() => get.call(tbl1, 2), RangeError, /bad Table get index/);
479 assertErrorMessage(() => get.call(tbl1, 2.5), RangeError, /bad Table get index/) ; 481 assertErrorMessage(() => get.call(tbl1, 2.5), RangeError, /bad Table get index/) ;
480 assertErrorMessage(() => get.call(tbl1, -1), RangeError, /bad Table get index/); 482 assertErrorMessage(() => get.call(tbl1, -1), RangeError, /bad Table get index/);
481 //TODO assertErrorMessage(() => get.call(tbl1, Math.pow(2,33)), RangeError, /bad Table get index/); 483 //TODO assertErrorMessage(() => get.call(tbl1, Math.pow(2,33)), RangeError, /bad Table get index/);
482 assertErrorMessage(() => get.call(tbl1, {valueOf() { throw new Error("hi") }}), Error, "hi"); 484 assertErrorMessage(() => get.call(tbl1, {valueOf() { throw new Error("hi") }}), Error, "hi");
483 485
484 // 'WebAssembly.Table.prototype.set' data property 486 // 'WebAssembly.Table.prototype.set' data property
485 let setDesc = Object.getOwnPropertyDescriptor(tableProto, 'set'); 487 let setDesc = Object.getOwnPropertyDescriptor(tableProto, 'set');
486 assertEq(typeof setDesc.value, "function"); 488 assertEq(typeof setDesc.value, "function");
487 assertEq(setDesc.enumerable, false); 489 assertFalse(setDesc.enumerable);
488 assertEq(setDesc.configurable, true); 490 assertTrue(setDesc.configurable);
489 491
490 // 'WebAssembly.Table.prototype.set' method 492 // 'WebAssembly.Table.prototype.set' method
491 let set = setDesc.value; 493 let set = setDesc.value;
492 assertEq(set.length, 2); 494 assertEq(set.length, 2);
493 assertErrorMessage(() => set.call(), TypeError, /called on incompatible undefine d/); 495 assertErrorMessage(() => set.call(), TypeError, /called on incompatible undefine d/);
494 assertErrorMessage(() => set.call({}), TypeError, /called on incompatible Object /); 496 assertErrorMessage(() => set.call({}), TypeError, /called on incompatible Object /);
495 assertErrorMessage(() => set.call(tbl1, 0), TypeError, /requires more than 1 arg ument/); 497 assertErrorMessage(() => set.call(tbl1, 0), TypeError, /requires more than 1 arg ument/);
496 assertErrorMessage(() => set.call(tbl1, 2, null), RangeError, /bad Table set ind ex/); 498 assertErrorMessage(() => set.call(tbl1, 2, null), RangeError, /bad Table set ind ex/);
497 assertErrorMessage(() => set.call(tbl1, -1, null), RangeError, /bad Table set in dex/); 499 assertErrorMessage(() => set.call(tbl1, -1, null), RangeError, /bad Table set in dex/);
498 //TODO assertErrorMessage(() => set.call(tbl1, Math.pow(2,33), null), RangeError , /bad Table set index/); 500 //TODO assertErrorMessage(() => set.call(tbl1, Math.pow(2,33), null), RangeError , /bad Table set index/);
499 assertErrorMessage(() => set.call(tbl1, 0, undefined), TypeError, /can only assi gn WebAssembly exported functions to Table/); 501 assertErrorMessage(() => set.call(tbl1, 0, undefined), TypeError, /can only assi gn WebAssembly exported functions to Table/);
500 assertErrorMessage(() => set.call(tbl1, 0, {}), TypeError, /can only assign WebA ssembly exported functions to Table/); 502 assertErrorMessage(() => set.call(tbl1, 0, {}), TypeError, /can only assign WebA ssembly exported functions to Table/);
501 assertErrorMessage(() => set.call(tbl1, 0, function() {}), TypeError, /can only assign WebAssembly exported functions to Table/); 503 assertErrorMessage(() => set.call(tbl1, 0, function() {}), TypeError, /can only assign WebAssembly exported functions to Table/);
502 assertErrorMessage(() => set.call(tbl1, 0, Math.sin), TypeError, /can only assig n WebAssembly exported functions to Table/); 504 assertErrorMessage(() => set.call(tbl1, 0, Math.sin), TypeError, /can only assig n WebAssembly exported functions to Table/);
503 assertErrorMessage(() => set.call(tbl1, {valueOf() { throw Error("hai") }}, null ), Error, "hai"); 505 assertErrorMessage(() => set.call(tbl1, {valueOf() { throw Error("hai") }}, null ), Error, "hai");
504 assertEq(set.call(tbl1, 0, null), undefined); 506 assertEq(set.call(tbl1, 0, null), undefined);
505 assertEq(set.call(tbl1, 1, null), undefined); 507 assertEq(set.call(tbl1, 1, null), undefined);
506 508
507 // 'WebAssembly.Table.prototype.grow' data property 509 // 'WebAssembly.Table.prototype.grow' data property
508 let tblGrowDesc = Object.getOwnPropertyDescriptor(tableProto, 'grow'); 510 let tblGrowDesc = Object.getOwnPropertyDescriptor(tableProto, 'grow');
509 assertEq(typeof tblGrowDesc.value, "function"); 511 assertEq(typeof tblGrowDesc.value, "function");
510 assertEq(tblGrowDesc.enumerable, false); 512 assertFalse(tblGrowDesc.enumerable);
511 assertEq(tblGrowDesc.configurable, true); 513 assertTrue(tblGrowDesc.configurable);
512 514
513 // 'WebAssembly.Table.prototype.grow' method 515 // 'WebAssembly.Table.prototype.grow' method
514 let tblGrow = tblGrowDesc.value; 516 let tblGrow = tblGrowDesc.value;
515 assertEq(tblGrow.length, 1); 517 assertEq(tblGrow.length, 1);
516 assertErrorMessage(() => tblGrow.call(), TypeError, /called on incompatible unde fined/); 518 assertErrorMessage(() => tblGrow.call(), TypeError, /called on incompatible unde fined/);
517 assertErrorMessage(() => tblGrow.call({}), TypeError, /called on incompatible Ob ject/); 519 assertErrorMessage(() => tblGrow.call({}), TypeError, /called on incompatible Ob ject/);
518 assertErrorMessage(() => tblGrow.call(tbl1, -1), RangeError, /bad Table grow del ta/); 520 assertErrorMessage(() => tblGrow.call(tbl1, -1), RangeError, /bad Table grow del ta/);
519 assertErrorMessage(() => tblGrow.call(tbl1, Math.pow(2,32)), RangeError, /bad Ta ble grow delta/); 521 assertErrorMessage(() => tblGrow.call(tbl1, Math.pow(2,32)), RangeError, /bad Ta ble grow delta/);
520 var tbl = new Table({element:"anyfunc", initial:1, maximum:2}); 522 var tbl = new Table({element:"anyfunc", initial:1, maximum:2});
521 assertEq(tbl.length, 1); 523 assertEq(tbl.length, 1);
522 assertEq(tbl.grow(0), 1); 524 assertEq(tbl.grow(0), 1);
523 assertEq(tbl.length, 1); 525 assertEq(tbl.length, 1);
524 assertEq(tbl.grow(1), 1); 526 assertEq(tbl.grow(1), 1);
525 assertEq(tbl.length, 2); 527 assertEq(tbl.length, 2);
526 assertErrorMessage(() => tbl.grow(1), Error, /failed to grow table/); 528 assertErrorMessage(() => tbl.grow(1), Error, /failed to grow table/);
527 529
528 // 'WebAssembly.validate' function 530 // 'WebAssembly.validate' function
529 assertErrorMessage(() => WebAssembly.validate(), TypeError); 531 assertErrorMessage(() => WebAssembly.validate(), TypeError);
530 assertErrorMessage(() => WebAssembly.validate("hi"), TypeError); 532 assertErrorMessage(() => WebAssembly.validate("hi"), TypeError);
531 assertEq(WebAssembly.validate(emptyModuleBinary), true); 533 assertTrue(WebAssembly.validate(emptyModuleBinary));
532 // TODO: other ways for validate to return false. 534 // TODO: other ways for validate to return false.
533 assertEq(WebAssembly.validate(moduleBinaryImporting2Memories), false); 535 assertFalse(WebAssembly.validate(moduleBinaryImporting2Memories));
534 assertEq(WebAssembly.validate(moduleBinaryWithMemSectionAndMemImport), false); 536 assertFalse(WebAssembly.validate(moduleBinaryWithMemSectionAndMemImport));
535 537
536 // 'WebAssembly.compile' data property 538 // 'WebAssembly.compile' data property
537 let compileDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'compile'); 539 let compileDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'compile');
538 assertEq(typeof compileDesc.value, "function"); 540 assertEq(typeof compileDesc.value, "function");
539 assertEq(compileDesc.writable, true); 541 assertTrue(compileDesc.writable);
540 assertEq(compileDesc.enumerable, false); 542 assertFalse(compileDesc.enumerable);
541 assertEq(compileDesc.configurable, true); 543 assertTrue(compileDesc.configurable);
542 544
543 // 'WebAssembly.compile' function 545 // 'WebAssembly.compile' function
544 let compile = WebAssembly.compile; 546 let compile = WebAssembly.compile;
545 assertEq(compile, compileDesc.value); 547 assertEq(compile, compileDesc.value);
546 assertEq(compile.length, 1); 548 assertEq(compile.length, 1);
547 assertEq(compile.name, "compile"); 549 assertEq(compile.name, "compile");
548 function assertCompileError(args, err, msg) { 550 function assertCompileError(args, err, msg) {
549 var error = null; 551 var error = null;
550 compile(...args).catch(e => error = e); 552 compile(...args).catch(e => error = e);
551 drainJobQueue(); 553 drainJobQueue();
552 assertEq(error instanceof err, true); 554 assertTrue(error instanceof err);
553 assertEq(Boolean(error.stack.match("js-api.js")), true); 555 assertTrue(Boolean(error.stack.match('js-api.js')));
554 //TODO assertEq(Boolean(error.message.match(msg)), true); 556 // TODO assertTrue(Boolean(error.message.match(msg)));
555 } 557 }
556 assertCompileError([], TypeError, /requires more than 0 arguments/); 558 assertCompileError([], TypeError, /requires more than 0 arguments/);
557 assertCompileError([undefined], TypeError, /first argument must be an ArrayBuffe r or typed array object/); 559 assertCompileError([undefined], TypeError, /first argument must be an ArrayBuffe r or typed array object/);
558 assertCompileError([1], TypeError, /first argument must be an ArrayBuffer or typ ed array object/); 560 assertCompileError([1], TypeError, /first argument must be an ArrayBuffer or typ ed array object/);
559 assertCompileError([{}], TypeError, /first argument must be an ArrayBuffer or ty ped array object/); 561 assertCompileError([{}], TypeError, /first argument must be an ArrayBuffer or ty ped array object/);
560 assertCompileError([new Uint8Array()], CompileError, /BufferSource argument is e mpty/); 562 assertCompileError([new Uint8Array()], CompileError, /BufferSource argument is e mpty/);
561 assertCompileError([new ArrayBuffer()], CompileError, /BufferSource argument is empty/); 563 assertCompileError([new ArrayBuffer()], CompileError, /BufferSource argument is empty/);
562 assertCompileError([new Uint8Array("hi!")], CompileError, /failed to match magic number/); 564 assertCompileError([new Uint8Array("hi!")], CompileError, /failed to match magic number/);
563 assertCompileError([new ArrayBuffer("hi!")], CompileError, /failed to match magi c number/); 565 assertCompileError([new ArrayBuffer("hi!")], CompileError, /failed to match magi c number/);
564 566
565 function assertCompileSuccess(bytes) { 567 function assertCompileSuccess(bytes) {
566 var module = null; 568 var module = null;
567 compile(bytes).then(m => module = m); 569 compile(bytes).then(m => module = m);
568 drainJobQueue(); 570 drainJobQueue();
569 assertEq(module instanceof Module, true); 571 assertTrue(module instanceof Module);
570 } 572 }
571 assertCompileSuccess(emptyModuleBinary); 573 assertCompileSuccess(emptyModuleBinary);
572 assertCompileSuccess(emptyModuleBinary.buffer); 574 assertCompileSuccess(emptyModuleBinary.buffer);
573 575
574 // 'WebAssembly.instantiate' data property 576 // 'WebAssembly.instantiate' data property
575 let instantiateDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'instantiate' ); 577 let instantiateDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'instantiate' );
576 assertEq(typeof instantiateDesc.value, "function"); 578 assertEq(typeof instantiateDesc.value, "function");
577 assertEq(instantiateDesc.writable, true); 579 assertTrue(instantiateDesc.writable);
578 assertEq(instantiateDesc.enumerable, false); 580 assertFalse(instantiateDesc.enumerable);
579 assertEq(instantiateDesc.configurable, true); 581 assertTrue(instantiateDesc.configurable);
580 582
581 // 'WebAssembly.instantiate' function 583 // 'WebAssembly.instantiate' function
582 let instantiate = WebAssembly.instantiate; 584 let instantiate = WebAssembly.instantiate;
583 assertEq(instantiate, instantiateDesc.value); 585 assertEq(instantiate, instantiateDesc.value);
584 assertEq(instantiate.length, 1); 586 assertEq(instantiate.length, 1);
585 assertEq(instantiate.name, "instantiate"); 587 assertEq(instantiate.name, "instantiate");
586 function assertInstantiateError(args, err, msg) { 588 function assertInstantiateError(args, err, msg) {
587 var error = null; 589 var error = null;
588 instantiate(...args).catch(e => error = e); 590 instantiate(...args).catch(e => error = e);
589 drainJobQueue(); 591 drainJobQueue();
590 assertEq(error instanceof err, true); 592 assertTrue(error instanceof err);
591 assertEq(Boolean(error.stack.match("js-api.js")), true); 593 assertTrue(Boolean(error.stack.match('js-api.js')));
592 //TODO assertEq(Boolean(error.message.match(msg)), true); 594 // TODO assertTrue(Boolean(error.message.match(msg)));
593 } 595 }
594 var scratch_memory = new WebAssembly.Memory(new ArrayBuffer(10)); 596 var scratch_memory = new WebAssembly.Memory(new ArrayBuffer(10));
595 assertInstantiateError([], TypeError, /requires more than 0 arguments/); 597 assertInstantiateError([], TypeError, /requires more than 0 arguments/);
596 assertInstantiateError([undefined], TypeError, /first argument must be a BufferS ource/); 598 assertInstantiateError([undefined], TypeError, /first argument must be a BufferS ource/);
597 assertInstantiateError([1], TypeError, /first argument must be a BufferSource/); 599 assertInstantiateError([1], TypeError, /first argument must be a BufferSource/);
598 assertInstantiateError([{}], TypeError, /first argument must be a BufferSource/) ; 600 assertInstantiateError([{}], TypeError, /first argument must be a BufferSource/) ;
599 assertInstantiateError([new Uint8Array()], CompileError, /failed to match magic number/); 601 assertInstantiateError([new Uint8Array()], CompileError, /failed to match magic number/);
600 assertInstantiateError([new ArrayBuffer()], CompileError, /failed to match magic number/); 602 assertInstantiateError([new ArrayBuffer()], CompileError, /failed to match magic number/);
601 assertInstantiateError([new Uint8Array("hi!")], CompileError, /failed to match m agic number/); 603 assertInstantiateError([new Uint8Array("hi!")], CompileError, /failed to match m agic number/);
602 assertInstantiateError([new ArrayBuffer("hi!")], CompileError, /failed to match magic number/); 604 assertInstantiateError([new ArrayBuffer("hi!")], CompileError, /failed to match magic number/);
603 assertInstantiateError([importingModule], TypeError, /second argument must be an object/); 605 assertInstantiateError([importingModule], TypeError, /second argument must be an object/);
604 assertInstantiateError([importingModule, null], TypeError, /second argument must be an object/); 606 assertInstantiateError([importingModule, null], TypeError, /second argument must be an object/);
605 assertInstantiateError([importingModuleBinary, null], TypeError, /second argumen t must be an object/); 607 assertInstantiateError([importingModuleBinary, null], TypeError, /second argumen t must be an object/);
606 assertInstantiateError([emptyModule, null], TypeError, /first argument must be a BufferSource/); 608 assertInstantiateError([emptyModule, null], TypeError, /first argument must be a BufferSource/);
607 assertInstantiateError([importingModule, {"":{f:()=>{}}}], TypeError, /first arg ument must be a BufferSource/);
608 assertInstantiateError([importingModuleBinary, null], TypeError, /TODO: error me ssages?/); 609 assertInstantiateError([importingModuleBinary, null], TypeError, /TODO: error me ssages?/);
609 assertInstantiateError([importingModuleBinary, undefined], TypeError, /TODO: err or messages?/); 610 assertInstantiateError([importingModuleBinary, undefined], TypeError, /TODO: err or messages?/);
610 assertInstantiateError([importingModuleBinary, {}], LinkError, /TODO: error mess ages?/); 611 assertInstantiateError([importingModuleBinary, {}], LinkError, /TODO: error mess ages?/);
611 assertInstantiateError([importingModuleBinary, {"":{g:()=>{}}}], LinkError, /TOD O: error messages?/); 612 assertInstantiateError([importingModuleBinary, {"":{g:()=>{}}}], LinkError, /TOD O: error messages?/);
612 assertInstantiateError([importingModuleBinary, {t:{f:()=>{}}}], LinkError, /TODO : error messages?/); 613 assertInstantiateError([importingModuleBinary, {t:{f:()=>{}}}], LinkError, /TODO : error messages?/);
613 assertInstantiateError([memoryImportingModuleBinary, null], TypeError, /TODO: er ror messages?/); 614 assertInstantiateError([memoryImportingModuleBinary, null], TypeError, /TODO: er ror messages?/);
614 assertInstantiateError([memoryImportingModuleBinary, undefined], TypeError, /TOD O: error messages?/); 615 assertInstantiateError([memoryImportingModuleBinary, undefined], TypeError, /TOD O: error messages?/);
615 assertInstantiateError([memoryImportingModuleBinary, {}], LinkError, /TODO: erro r messages?/); 616 assertInstantiateError([memoryImportingModuleBinary, {}], LinkError, /TODO: erro r messages?/);
616 assertInstantiateError([memoryImportingModuleBinary, {"mod": {"my_memory": scrat ch_memory}}], LinkError, /TODO: error messages?/); 617 assertInstantiateError([memoryImportingModuleBinary, {"mod": {"my_memory": scrat ch_memory}}], LinkError, /TODO: error messages?/);
617 assertInstantiateError([memoryImportingModuleBinary, {"": {"memory": scratch_mem ory}}], LinkError, /TODO: error messages?/); 618 assertInstantiateError([memoryImportingModuleBinary, {"": {"memory": scratch_mem ory}}], LinkError, /TODO: error messages?/);
618 619
619 function assertInstantiateSuccess(module_bytes, imports) { 620 function assertInstantiateSuccess(module_or_bytes, imports) {
620 var result = null; 621 var result = null;
621 instantiate(module_bytes, imports).then(r => result = r).catch(e => print(e)); 622 instantiate(module_or_bytes, imports)
623 .then(r => result = r)
624 .catch(e => print(e));
622 drainJobQueue(); 625 drainJobQueue();
623 assertEq(result instanceof Instance, true); 626 if (module_or_bytes instanceof Module) {
627 assertTrue(result instanceof Instance);
628 } else {
629 assertTrue(result.module instanceof Module);
630 assertTrue(result.instance instanceof Instance);
631 }
624 } 632 }
633 assertInstantiateSuccess(emptyModule);
625 assertInstantiateSuccess(emptyModuleBinary); 634 assertInstantiateSuccess(emptyModuleBinary);
626 assertInstantiateSuccess(emptyModuleBinary.buffer); 635 assertInstantiateSuccess(emptyModuleBinary.buffer);
636 assertInstantiateSuccess(importingModule, {'': {f: () => {}}});
627 assertInstantiateSuccess(importingModuleBinary, {"":{f:()=>{}}}); 637 assertInstantiateSuccess(importingModuleBinary, {"":{f:()=>{}}});
628 assertInstantiateSuccess(importingModuleBinary.buffer, {"":{f:()=>{}}}); 638 assertInstantiateSuccess(importingModuleBinary.buffer, {"":{f:()=>{}}});
629 assertInstantiateSuccess(memoryImportingModuleBinary, {"": {"my_memory": scratch _memory}}); 639 assertInstantiateSuccess(memoryImportingModuleBinary, {"": {"my_memory": scratch _memory}});
OLDNEW
« no previous file with comments | « src/wasm/wasm-js.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698