OLD | NEW |
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 assertEq(arr[1].kind, "memory"); | 187 assertEq(arr[1].kind, "memory"); |
188 assertEq(arr[1].module, "c"); | 188 assertEq(arr[1].module, "c"); |
189 assertEq(arr[1].name, "d"); | 189 assertEq(arr[1].name, "d"); |
190 assertEq(arr[2].kind, "table"); | 190 assertEq(arr[2].kind, "table"); |
191 assertEq(arr[2].module, "e"); | 191 assertEq(arr[2].module, "e"); |
192 assertEq(arr[2].name, "f"); | 192 assertEq(arr[2].name, "f"); |
193 assertEq(arr[3].kind, "global"); | 193 assertEq(arr[3].kind, "global"); |
194 assertEq(arr[3].module, "g"); | 194 assertEq(arr[3].module, "g"); |
195 assertEq(arr[3].name, "x"); | 195 assertEq(arr[3].name, "x"); |
196 | 196 |
197 if (false) { // TODO: Module.exports property | |
198 // 'WebAssembly.Module.exports' data property | 197 // 'WebAssembly.Module.exports' data property |
199 let moduleExportsDesc = Object.getOwnPropertyDescriptor(Module, 'exports'); | 198 let moduleExportsDesc = Object.getOwnPropertyDescriptor(Module, 'exports'); |
200 assertEq(typeof moduleExportsDesc.value, "function"); | 199 assertEq(typeof moduleExportsDesc.value, "function"); |
201 assertEq(moduleExportsDesc.writable, true); | 200 assertEq(moduleExportsDesc.writable, true); |
202 assertEq(moduleExportsDesc.enumerable, false); | 201 assertEq(moduleExportsDesc.enumerable, false); |
203 assertEq(moduleExportsDesc.configurable, true); | 202 assertEq(moduleExportsDesc.configurable, true); |
204 | 203 |
205 // 'WebAssembly.Module.exports' method | 204 // 'WebAssembly.Module.exports' method |
206 let moduleExports = moduleExportsDesc.value; | 205 let moduleExports = moduleExportsDesc.value; |
207 assertEq(moduleExports.length, 1); | 206 assertEq(moduleExports.length, 1); |
208 assertErrorMessage(() => moduleExports(), TypeError, /requires more than 0 argum
ents/); | 207 assertErrorMessage(() => moduleExports(), TypeError, /requires more than 0 argum
ents/); |
209 assertErrorMessage(() => moduleExports(undefined), TypeError, /first argument mu
st be a WebAssembly.Module/); | 208 assertErrorMessage(() => moduleExports(undefined), TypeError, /first argument mu
st be a WebAssembly.Module/); |
210 assertErrorMessage(() => moduleExports({}), TypeError, /first argument must be a
WebAssembly.Module/); | 209 assertErrorMessage(() => moduleExports({}), TypeError, /first argument must be a
WebAssembly.Module/); |
211 var arr = moduleExports(emptyModule); | 210 var arr = moduleExports(emptyModule); |
212 assertEq(arr instanceof Array, true); | 211 assertEq(arr instanceof Array, true); |
213 assertEq(arr.length, 0); | 212 assertEq(arr.length, 0); |
214 var arr = moduleExports(new Module(wasmTextToBinary('(module (func (export "a"))
(memory (export "b") 1) (table (export "c") 1 anyfunc) (global (export "⚡") i32
(i32.const 0)))'))); | 213 let exportingModuleBinary2 = (() => { |
| 214 var text = |
| 215 '(module (func (export "a")) (memory (export "b") 1) (table (export "c") 1 any
func) (global (export "⚡") i32 (i32.const 0)))'; |
| 216 let builder = new WasmModuleBuilder(); |
| 217 builder.addFunction("foo", kSig_v_v) |
| 218 .addBody([]) |
| 219 .exportAs("a"); |
| 220 builder.addMemory(1, 1, false); |
| 221 builder.exportMemoryAs("b"); |
| 222 builder.setFunctionTableLength(1); |
| 223 builder.addExportOfKind("c", kExternalTable, 0); |
| 224 var o = builder.addGlobal(kWasmI32, false) |
| 225 .exportAs("x"); |
| 226 return new Int8Array(builder.toBuffer()); |
| 227 })(); |
| 228 var arr = moduleExports(new Module(exportingModuleBinary2)); |
215 assertEq(arr instanceof Array, true); | 229 assertEq(arr instanceof Array, true); |
216 assertEq(arr.length, 4); | 230 assertEq(arr.length, 4); |
217 assertEq(arr[0].kind, "function"); | 231 assertEq(arr[0].kind, "function"); |
218 assertEq(arr[0].name, "a"); | 232 assertEq(arr[0].name, "a"); |
219 assertEq(arr[1].kind, "memory"); | 233 assertEq(arr[1].kind, "memory"); |
220 assertEq(arr[1].name, "b"); | 234 assertEq(arr[1].name, "b"); |
221 assertEq(arr[2].kind, "table"); | 235 assertEq(arr[2].kind, "table"); |
222 assertEq(arr[2].name, "c"); | 236 assertEq(arr[2].name, "c"); |
223 assertEq(arr[3].kind, "global"); | 237 assertEq(arr[3].kind, "global"); |
224 assertEq(arr[3].name, "⚡"); | 238 assertEq(arr[3].name, "x"); |
225 } | |
226 | 239 |
227 // 'WebAssembly.Instance' data property | 240 // 'WebAssembly.Instance' data property |
228 let instanceDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Instance'); | 241 let instanceDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Instance'); |
229 assertEq(typeof instanceDesc.value, "function"); | 242 assertEq(typeof instanceDesc.value, "function"); |
230 assertEq(instanceDesc.writable, true); | 243 assertEq(instanceDesc.writable, true); |
231 assertEq(instanceDesc.enumerable, false); | 244 assertEq(instanceDesc.enumerable, false); |
232 assertEq(instanceDesc.configurable, true); | 245 assertEq(instanceDesc.configurable, true); |
233 | 246 |
234 // 'WebAssembly.Instance' constructor function | 247 // 'WebAssembly.Instance' constructor function |
235 let Instance = WebAssembly.Instance; | 248 let Instance = WebAssembly.Instance; |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 assertEq(result.instance instanceof Instance, true); | 597 assertEq(result.instance instanceof Instance, true); |
585 } | 598 } |
586 } | 599 } |
587 assertInstantiateSuccess(emptyModule); | 600 assertInstantiateSuccess(emptyModule); |
588 assertInstantiateSuccess(emptyModuleBinary); | 601 assertInstantiateSuccess(emptyModuleBinary); |
589 assertInstantiateSuccess(emptyModuleBinary.buffer); | 602 assertInstantiateSuccess(emptyModuleBinary.buffer); |
590 assertInstantiateSuccess(importingModule, {"":{f:()=>{}}}); | 603 assertInstantiateSuccess(importingModule, {"":{f:()=>{}}}); |
591 assertInstantiateSuccess(importingModuleBinary, {"":{f:()=>{}}}); | 604 assertInstantiateSuccess(importingModuleBinary, {"":{f:()=>{}}}); |
592 assertInstantiateSuccess(importingModuleBinary.buffer, {"":{f:()=>{}}}); | 605 assertInstantiateSuccess(importingModuleBinary.buffer, {"":{f:()=>{}}}); |
593 } | 606 } |
OLD | NEW |