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

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

Issue 2629523007: [wasm] JS-API: enable WebAssembly.instantiate tests; fix LinkError (Closed)
Patch Set: fix errors.js 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
« test/mjsunit/wasm/errors.js ('K') | « test/mjsunit/wasm/errors.js ('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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 assertEq(typeof instanceDesc.value, "function"); 249 assertEq(typeof instanceDesc.value, "function");
250 assertEq(instanceDesc.writable, true); 250 assertEq(instanceDesc.writable, true);
251 assertEq(instanceDesc.enumerable, false); 251 assertEq(instanceDesc.enumerable, false);
252 assertEq(instanceDesc.configurable, true); 252 assertEq(instanceDesc.configurable, true);
253 253
254 // 'WebAssembly.Instance' constructor function 254 // 'WebAssembly.Instance' constructor function
255 let Instance = WebAssembly.Instance; 255 let Instance = WebAssembly.Instance;
256 assertEq(Instance, instanceDesc.value); 256 assertEq(Instance, instanceDesc.value);
257 assertEq(Instance.length, 1); 257 assertEq(Instance.length, 1);
258 assertEq(Instance.name, "Instance"); 258 assertEq(Instance.name, "Instance");
259
259 assertErrorMessage(() => Instance(), TypeError, /constructor without new is forb idden/); 260 assertErrorMessage(() => Instance(), TypeError, /constructor without new is forb idden/);
260 assertErrorMessage(() => new Instance(1), TypeError, "first argument must be a W ebAssembly.Module"); 261 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"); 262 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"); 263 assertErrorMessage(() => new Instance(emptyModule, null), TypeError, "second arg ument must be an object");
264 assertErrorMessage(() => new Instance(importingModule, null), TypeError, "");
265 assertErrorMessage(() => new Instance(importingModule, undefined), LinkError, "" );
rossberg 2017/01/12 23:59:53 This seems incorrect, undefined should cause the s
Mircea Trofin 2017/01/13 03:57:47 Ah. Yes, in all cases when the type isn't an objec
266 assertErrorMessage(() => new Instance(importingModule, {"":{g:()=>{}}}), LinkErr or, "");
267 assertErrorMessage(() => new Instance(importingModule, {t:{f:()=>{}}}), LinkErro r, "");
268
263 assertEq(new Instance(emptyModule) instanceof Instance, true); 269 assertEq(new Instance(emptyModule) instanceof Instance, true);
264 assertEq(new Instance(emptyModule, {}) instanceof Instance, true); 270 assertEq(new Instance(emptyModule, {}) instanceof Instance, true);
265 271
266 // 'WebAssembly.Instance.prototype' data property 272 // 'WebAssembly.Instance.prototype' data property
267 let instanceProtoDesc = Object.getOwnPropertyDescriptor(Instance, 'prototype'); 273 let instanceProtoDesc = Object.getOwnPropertyDescriptor(Instance, 'prototype');
268 assertEq(typeof instanceProtoDesc.value, "object"); 274 assertEq(typeof instanceProtoDesc.value, "object");
269 assertEq(instanceProtoDesc.writable, false); 275 assertEq(instanceProtoDesc.writable, false);
270 assertEq(instanceProtoDesc.enumerable, false); 276 assertEq(instanceProtoDesc.enumerable, false);
271 assertEq(instanceProtoDesc.configurable, false); 277 assertEq(instanceProtoDesc.configurable, false);
272 278
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 //TODO assertCompileError([new ArrayBuffer()], CompileError, /failed to match ma gic number/); 559 //TODO assertCompileError([new ArrayBuffer()], CompileError, /failed to match ma gic number/);
554 function assertCompileSuccess(bytes) { 560 function assertCompileSuccess(bytes) {
555 var module = null; 561 var module = null;
556 compile(bytes).then(m => module = m); 562 compile(bytes).then(m => module = m);
557 drainJobQueue(); 563 drainJobQueue();
558 assertEq(module instanceof Module, true); 564 assertEq(module instanceof Module, true);
559 } 565 }
560 assertCompileSuccess(emptyModuleBinary); 566 assertCompileSuccess(emptyModuleBinary);
561 assertCompileSuccess(emptyModuleBinary.buffer); 567 assertCompileSuccess(emptyModuleBinary.buffer);
562 568
563 if (false) { // TODO: implement WebAssembly.instantiate 569 // 'WebAssembly.instantiate' data property
564 // 'WebAssembly.instantiate' data property 570 let instantiateDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'instantiate' );
565 let instantiateDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'instantiat e'); 571 assertEq(typeof instantiateDesc.value, "function");
566 assertEq(typeof instantiateDesc.value, "function"); 572 assertEq(instantiateDesc.writable, true);
567 assertEq(instantiateDesc.writable, true); 573 assertEq(instantiateDesc.enumerable, false);
568 assertEq(instantiateDesc.enumerable, false); 574 assertEq(instantiateDesc.configurable, true);
569 assertEq(instantiateDesc.configurable, true);
570 575
571 // 'WebAssembly.instantiate' function 576 // 'WebAssembly.instantiate' function
572 let instantiate = WebAssembly.instantiate; 577 let instantiate = WebAssembly.instantiate;
573 assertEq(instantiate, instantiateDesc.value); 578 assertEq(instantiate, instantiateDesc.value);
574 assertEq(instantiate.length, 2); 579 assertEq(instantiate.length, 1);
575 assertEq(instantiate.name, "instantiate"); 580 assertEq(instantiate.name, "instantiate");
576 function assertInstantiateError(args, err, msg) { 581 function assertInstantiateError(args, err, msg) {
577 var error = null; 582 var error = null;
578 try { 583 try {
579 instantiate(...args).catch(e => error = e); 584 instantiate(...args).catch(e => error = e);
580 } catch(e) { 585 } catch(e) {
581 error = e; 586 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 } 587 }
588 assertInstantiateError([], TypeError, /requires more than 0 arguments/); 588 drainJobQueue();
589 assertInstantiateError([undefined], TypeError, /first argument must be a WebAs sembly.Module, ArrayBuffer or typed array object/); 589 assertEq(error instanceof err, true);
590 assertInstantiateError([1], TypeError, /first argument must be a WebAssembly.M odule, ArrayBuffer or typed array object/); 590 assertEq(Boolean(error.stack.match("js-api.js")), true);
591 assertInstantiateError([{}], TypeError, /first argument must be a WebAssembly. Module, ArrayBuffer or typed array object/); 591 //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 } 592 }
593 assertInstantiateError([], TypeError, /requires more than 0 arguments/);
594 assertInstantiateError([undefined], TypeError, /first argument must be a BufferS ource/);
595 assertInstantiateError([1], TypeError, /first argument must be a BufferSource/);
596 assertInstantiateError([{}], TypeError, /first argument must be a BufferSource/) ;
597 assertInstantiateError([new Uint8Array()], CompileError, /failed to match magic number/);
598 assertInstantiateError([new ArrayBuffer()], CompileError, /failed to match magic number/);
599 assertInstantiateError([new Uint8Array("hi!")], CompileError, /failed to match m agic number/);
600 assertInstantiateError([new ArrayBuffer("hi!")], CompileError, /failed to match magic number/);
601 assertInstantiateError([importingModule], TypeError, /second argument must be an object/);
602 assertInstantiateError([importingModule, null], TypeError, /second argument must be an object/);
603 assertInstantiateError([importingModuleBinary, null], TypeError, /second argumen t must be an object/);
604 assertInstantiateError([emptyModule, null], TypeError, /first argument must be a BufferSource/);
605 assertInstantiateError([importingModule, {"":{f:()=>{}}}], TypeError, /first arg ument must be a BufferSource/);
606 assertInstantiateError([importingModuleBinary, null], TypeError, /TODO: error me ssages?/);
607 assertInstantiateError([importingModuleBinary, undefined], LinkError, /TODO: err or messages?/);
rossberg 2017/01/12 23:59:53 Same here.
Mircea Trofin 2017/01/13 03:57:47 Acknowledged.
608 assertInstantiateError([importingModuleBinary, {}], LinkError, /TODO: error mess ages?/);
609 assertInstantiateError([importingModuleBinary, {"":{g:()=>{}}}], LinkError, /TOD O: error messages?/);
610 assertInstantiateError([importingModuleBinary, {t:{f:()=>{}}}], LinkError, /TODO : error messages?/);
611
612 function assertInstantiateSuccess(module_bytes, imports) {
613 var result = null;
614 instantiate(module_bytes, imports).then(r => result = r);
615 drainJobQueue();
616 assertEq(result instanceof Instance, true);
617 }
618 assertInstantiateSuccess(emptyModuleBinary);
619 assertInstantiateSuccess(emptyModuleBinary.buffer);
620 assertInstantiateSuccess(importingModuleBinary, {"":{f:()=>{}}});
621 assertInstantiateSuccess(importingModuleBinary.buffer, {"":{f:()=>{}}});
OLDNEW
« test/mjsunit/wasm/errors.js ('K') | « test/mjsunit/wasm/errors.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698