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 23 matching lines...) Expand all Loading... | |
34 .exportAs("f"); | 34 .exportAs("f"); |
35 return new Int8Array(builder.toBuffer()); | 35 return new Int8Array(builder.toBuffer()); |
36 })(); | 36 })(); |
37 | 37 |
38 let importingModuleBinary = (() => { | 38 let importingModuleBinary = (() => { |
39 var builder = new WasmModuleBuilder(); | 39 var builder = new WasmModuleBuilder(); |
40 builder.addImport("", "f", kSig_i_v); | 40 builder.addImport("", "f", kSig_i_v); |
41 return new Int8Array(builder.toBuffer()); | 41 return new Int8Array(builder.toBuffer()); |
42 })(); | 42 })(); |
43 | 43 |
44 let memoryImportingModuleBinary = (() => { | |
45 var builder = new WasmModuleBuilder(); | |
46 builder.addImportedMemory("", "my_memory"); | |
47 return new Int8Array(builder.toBuffer()); | |
48 })(); | |
49 | |
44 let moduleBinaryImporting2Memories = (() => { | 50 let moduleBinaryImporting2Memories = (() => { |
45 var builder = new WasmModuleBuilder(); | 51 var builder = new WasmModuleBuilder(); |
46 builder.addImportedMemory("", "memory1"); | 52 builder.addImportedMemory("", "memory1"); |
47 builder.addImportedMemory("", "memory2"); | 53 builder.addImportedMemory("", "memory2"); |
48 return new Int8Array(builder.toBuffer()); | 54 return new Int8Array(builder.toBuffer()); |
49 })(); | 55 })(); |
50 | 56 |
51 let moduleBinaryWithMemSectionAndMemImport = (() => { | 57 let moduleBinaryWithMemSectionAndMemImport = (() => { |
52 var builder = new WasmModuleBuilder(); | 58 var builder = new WasmModuleBuilder(); |
53 builder.addMemory(1, 1, false); | 59 builder.addMemory(1, 1, false); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 assertEq(typeof instanceDesc.value, "function"); | 255 assertEq(typeof instanceDesc.value, "function"); |
250 assertEq(instanceDesc.writable, true); | 256 assertEq(instanceDesc.writable, true); |
251 assertEq(instanceDesc.enumerable, false); | 257 assertEq(instanceDesc.enumerable, false); |
252 assertEq(instanceDesc.configurable, true); | 258 assertEq(instanceDesc.configurable, true); |
253 | 259 |
254 // 'WebAssembly.Instance' constructor function | 260 // 'WebAssembly.Instance' constructor function |
255 let Instance = WebAssembly.Instance; | 261 let Instance = WebAssembly.Instance; |
256 assertEq(Instance, instanceDesc.value); | 262 assertEq(Instance, instanceDesc.value); |
257 assertEq(Instance.length, 1); | 263 assertEq(Instance.length, 1); |
258 assertEq(Instance.name, "Instance"); | 264 assertEq(Instance.name, "Instance"); |
265 | |
259 assertErrorMessage(() => Instance(), TypeError, /constructor without new is forb idden/); | 266 assertErrorMessage(() => Instance(), TypeError, /constructor without new is forb idden/); |
260 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"); |
261 assertErrorMessage(() => new Instance({}), TypeError, "first argument must be a WebAssembly.Module"); | 268 assertErrorMessage(() => new Instance({}), TypeError, "first argument must be a WebAssembly.Module"); |
262 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, ""); | |
271 assertErrorMessage(() => new Instance(importingModule, undefined), TypeError, "" ); | |
272 assertErrorMessage(() => new Instance(importingModule, {"":{g:()=>{}}}), LinkErr or, ""); | |
273 assertErrorMessage(() => new Instance(importingModule, {t:{f:()=>{}}}), LinkErro r, ""); | |
274 | |
263 assertEq(new Instance(emptyModule) instanceof Instance, true); | 275 assertEq(new Instance(emptyModule) instanceof Instance, true); |
264 assertEq(new Instance(emptyModule, {}) instanceof Instance, true); | 276 assertEq(new Instance(emptyModule, {}) instanceof Instance, true); |
265 | 277 |
266 // 'WebAssembly.Instance.prototype' data property | 278 // 'WebAssembly.Instance.prototype' data property |
267 let instanceProtoDesc = Object.getOwnPropertyDescriptor(Instance, 'prototype'); | 279 let instanceProtoDesc = Object.getOwnPropertyDescriptor(Instance, 'prototype'); |
268 assertEq(typeof instanceProtoDesc.value, "object"); | 280 assertEq(typeof instanceProtoDesc.value, "object"); |
269 assertEq(instanceProtoDesc.writable, false); | 281 assertEq(instanceProtoDesc.writable, false); |
270 assertEq(instanceProtoDesc.enumerable, false); | 282 assertEq(instanceProtoDesc.enumerable, false); |
271 assertEq(instanceProtoDesc.configurable, false); | 283 assertEq(instanceProtoDesc.configurable, false); |
272 | 284 |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 //TODO assertCompileError([new ArrayBuffer()], CompileError, /failed to match ma gic number/); | 565 //TODO assertCompileError([new ArrayBuffer()], CompileError, /failed to match ma gic number/); |
554 function assertCompileSuccess(bytes) { | 566 function assertCompileSuccess(bytes) { |
555 var module = null; | 567 var module = null; |
556 compile(bytes).then(m => module = m); | 568 compile(bytes).then(m => module = m); |
557 drainJobQueue(); | 569 drainJobQueue(); |
558 assertEq(module instanceof Module, true); | 570 assertEq(module instanceof Module, true); |
559 } | 571 } |
560 assertCompileSuccess(emptyModuleBinary); | 572 assertCompileSuccess(emptyModuleBinary); |
561 assertCompileSuccess(emptyModuleBinary.buffer); | 573 assertCompileSuccess(emptyModuleBinary.buffer); |
562 | 574 |
563 if (false) { // TODO: implement WebAssembly.instantiate | 575 // 'WebAssembly.instantiate' data property |
564 // 'WebAssembly.instantiate' data property | 576 let instantiateDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'instantiate' ); |
565 let instantiateDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'instantiat e'); | 577 assertEq(typeof instantiateDesc.value, "function"); |
566 assertEq(typeof instantiateDesc.value, "function"); | 578 assertEq(instantiateDesc.writable, true); |
567 assertEq(instantiateDesc.writable, true); | 579 assertEq(instantiateDesc.enumerable, false); |
568 assertEq(instantiateDesc.enumerable, false); | 580 assertEq(instantiateDesc.configurable, true); |
569 assertEq(instantiateDesc.configurable, true); | |
570 | 581 |
571 // 'WebAssembly.instantiate' function | 582 // 'WebAssembly.instantiate' function |
572 let instantiate = WebAssembly.instantiate; | 583 let instantiate = WebAssembly.instantiate; |
573 assertEq(instantiate, instantiateDesc.value); | 584 assertEq(instantiate, instantiateDesc.value); |
574 assertEq(instantiate.length, 2); | 585 assertEq(instantiate.length, 1); |
575 assertEq(instantiate.name, "instantiate"); | 586 assertEq(instantiate.name, "instantiate"); |
576 function assertInstantiateError(args, err, msg) { | 587 function assertInstantiateError(args, err, msg) { |
577 var error = null; | 588 var error = null; |
578 try { | 589 try { |
579 instantiate(...args).catch(e => error = e); | 590 instantiate(...args).catch(e => error = e); |
580 } catch(e) { | 591 } catch(e) { |
581 error = e; | 592 error = e; |
582 } | |
583 drainJobQueue(); | |
584 assertEq(error instanceof err, true); | |
585 assertEq(Boolean(error.stack.match("jsapi.js")), true); | |
586 assertEq(Boolean(error.message.match(msg)), true); | |
587 } | 593 } |
588 assertInstantiateError([], TypeError, /requires more than 0 arguments/); | 594 drainJobQueue(); |
589 assertInstantiateError([undefined], TypeError, /first argument must be a WebAs sembly.Module, ArrayBuffer or typed array object/); | 595 assertEq(error instanceof err, true); |
590 assertInstantiateError([1], TypeError, /first argument must be a WebAssembly.M odule, ArrayBuffer or typed array object/); | 596 assertEq(Boolean(error.stack.match("js-api.js")), true); |
591 assertInstantiateError([{}], TypeError, /first argument must be a WebAssembly. Module, ArrayBuffer or typed array object/); | 597 //TOassertEq(Boolean(error.message.match(msg)), true); |
592 assertInstantiateError([new Uint8Array()], CompileError, /failed to match magi c number/); | |
593 assertInstantiateError([new ArrayBuffer()], CompileError, /failed to match mag ic number/); | |
594 assertInstantiateError([importingModule], TypeError, /second argument must be an object/); | |
595 assertInstantiateError([importingModule, null], TypeError, /second argument mu st be an object/); | |
596 assertInstantiateError([importingModuleBinary, null], TypeError, /second argum ent must be an object/); | |
597 function assertInstantiateSuccess(module, imports) { | |
598 var result = null; | |
599 instantiate(module, imports).then(r => result = r); | |
600 drainJobQueue(); | |
601 if (module instanceof Module) { | |
602 assertEq(result instanceof Instance, true); | |
603 } else { | |
604 assertEq(result.module instanceof Module, true); | |
605 assertEq(result.instance instanceof Instance, true); | |
606 } | |
607 } | |
608 assertInstantiateSuccess(emptyModule); | |
609 assertInstantiateSuccess(emptyModuleBinary); | |
610 assertInstantiateSuccess(emptyModuleBinary.buffer); | |
611 assertInstantiateSuccess(importingModule, {"":{f:()=>{}}}); | |
612 assertInstantiateSuccess(importingModuleBinary, {"":{f:()=>{}}}); | |
613 assertInstantiateSuccess(importingModuleBinary.buffer, {"":{f:()=>{}}}); | |
614 } | 598 } |
599 var scratch_memory = new WebAssembly.Memory(new ArrayBuffer(10)); | |
600 assertInstantiateError([], TypeError, /requires more than 0 arguments/); | |
601 assertInstantiateError([undefined], TypeError, /first argument must be a BufferS ource/); | |
602 assertInstantiateError([1], TypeError, /first argument must be a BufferSource/); | |
603 assertInstantiateError([{}], TypeError, /first argument must be a BufferSource/) ; | |
604 assertInstantiateError([new Uint8Array()], CompileError, /failed to match magic number/); | |
605 assertInstantiateError([new ArrayBuffer()], CompileError, /failed to match magic number/); | |
606 assertInstantiateError([new Uint8Array("hi!")], CompileError, /failed to match m agic number/); | |
607 assertInstantiateError([new ArrayBuffer("hi!")], CompileError, /failed to match magic number/); | |
608 assertInstantiateError([importingModule], TypeError, /second argument must be an object/); | |
609 assertInstantiateError([importingModule, null], TypeError, /second argument must be an object/); | |
610 assertInstantiateError([importingModuleBinary, null], TypeError, /second argumen t must be an object/); | |
611 assertInstantiateError([emptyModule, null], TypeError, /first argument must be a BufferSource/); | |
612 assertInstantiateError([importingModule, {"":{f:()=>{}}}], TypeError, /first arg ument must be a BufferSource/); | |
613 assertInstantiateError([importingModuleBinary, null], TypeError, /TODO: error me ssages?/); | |
614 assertInstantiateError([importingModuleBinary, undefined], TypeError, /TODO: err or messages?/); | |
615 assertInstantiateError([importingModuleBinary, {}], LinkError, /TODO: error mess ages?/); | |
616 assertInstantiateError([importingModuleBinary, {"":{g:()=>{}}}], LinkError, /TOD O: error messages?/); | |
617 assertInstantiateError([importingModuleBinary, {t:{f:()=>{}}}], LinkError, /TODO : error messages?/); | |
618 assertInstantiateError([memoryImportingModuleBinary, null], TypeError, /TODO: er ror messages?/); | |
619 assertInstantiateError([memoryImportingModuleBinary, undefined], TypeError, /TOD O: error messages?/); | |
620 assertInstantiateError([memoryImportingModuleBinary, {}], LinkError, /TODO: erro r messages?/); | |
621 assertInstantiateError([memoryImportingModuleBinary, {"mod": {"my_memory": scrat ch_memory}}], LinkError, /TODO: error messages?/); | |
622 assertInstantiateError([memoryImportingModuleBinary, {"": {"memory": scratch_mem ory}}], LinkError, /TODO: error messages?/); | |
623 | |
624 function assertInstantiateSuccess(module_bytes, imports) { | |
625 var result = null; | |
626 instantiate(module_bytes, imports).then(r => result = r).catch(e => print(e)); | |
627 drainJobQueue(); | |
628 assertEq(result instanceof Instance, true); | |
Derek Schuff
2017/01/20 01:46:19
Drive-by review! This is a change in behavior from
| |
629 } | |
630 assertInstantiateSuccess(emptyModuleBinary); | |
631 assertInstantiateSuccess(emptyModuleBinary.buffer); | |
632 assertInstantiateSuccess(importingModuleBinary, {"":{f:()=>{}}}); | |
633 assertInstantiateSuccess(importingModuleBinary.buffer, {"":{f:()=>{}}}); | |
634 assertInstantiateSuccess(memoryImportingModuleBinary, {"": {"my_memory": scratch _memory}}); | |
OLD | NEW |