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

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

Issue 2620203005: [wasm] Implement the WebAssembly.Module.imports function. (Closed)
Patch Set: 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-module.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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 assertEq(Object.getPrototypeOf(moduleProto), Object.prototype); 146 assertEq(Object.getPrototypeOf(moduleProto), Object.prototype);
147 147
148 // 'WebAssembly.Module' instance objects 148 // 'WebAssembly.Module' instance objects
149 let emptyModule = new Module(emptyModuleBinary); 149 let emptyModule = new Module(emptyModuleBinary);
150 let importingModule = new Module(importingModuleBinary); 150 let importingModule = new Module(importingModuleBinary);
151 let exportingModule = new Module(exportingModuleBinary); 151 let exportingModule = new Module(exportingModuleBinary);
152 assertEq(typeof emptyModule, "object"); 152 assertEq(typeof emptyModule, "object");
153 //TODO assertEq(String(emptyModule), "[object WebAssembly.Module]"); 153 //TODO assertEq(String(emptyModule), "[object WebAssembly.Module]");
154 assertEq(Object.getPrototypeOf(emptyModule), moduleProto); 154 assertEq(Object.getPrototypeOf(emptyModule), moduleProto);
155 155
156 if (false) { // TODO: Module.imports support
157 // 'WebAssembly.Module.imports' data property 156 // 'WebAssembly.Module.imports' data property
158 let moduleImportsDesc = Object.getOwnPropertyDescriptor(Module, 'imports'); 157 let moduleImportsDesc = Object.getOwnPropertyDescriptor(Module, 'imports');
159 assertEq(typeof moduleImportsDesc.value, "function"); 158 assertEq(typeof moduleImportsDesc.value, "function");
160 assertEq(moduleImportsDesc.writable, true); 159 assertEq(moduleImportsDesc.writable, true);
161 assertEq(moduleImportsDesc.enumerable, false); 160 assertEq(moduleImportsDesc.enumerable, false);
162 assertEq(moduleImportsDesc.configurable, true); 161 assertEq(moduleImportsDesc.configurable, true);
163 162
164 // 'WebAssembly.Module.imports' method 163 // 'WebAssembly.Module.imports' method
165 let moduleImports = moduleImportsDesc.value; 164 let moduleImports = moduleImportsDesc.value;
166 assertEq(moduleImports.length, 1); 165 assertEq(moduleImports.length, 1);
167 assertErrorMessage(() => moduleImports(), TypeError, /requires more than 0 argum ents/); 166 assertErrorMessage(() => moduleImports(), TypeError, /requires more than 0 argum ents/);
168 assertErrorMessage(() => moduleImports(undefined), TypeError, /first argument mu st be a WebAssembly.Module/); 167 assertErrorMessage(() => moduleImports(undefined), TypeError, /first argument mu st be a WebAssembly.Module/);
169 assertErrorMessage(() => moduleImports({}), TypeError, /first argument must be a WebAssembly.Module/); 168 assertErrorMessage(() => moduleImports({}), TypeError, /first argument must be a WebAssembly.Module/);
170 var arr = moduleImports(new Module(wasmTextToBinary('(module)'))); 169 var arr = moduleImports(new Module(emptyModuleBinary));
171 assertEq(arr instanceof Array, true); 170 assertEq(arr instanceof Array, true);
172 assertEq(arr.length, 0); 171 assertEq(arr.length, 0);
173 var arr = moduleImports(new Module(wasmTextToBinary('(module (func (import "a" " b")) (memory (import "c" "d") 1) (table (import "e" "f") 1 anyfunc) (global (imp ort "g" "⚡") i32))'))); 172 let importingModuleBinary2 = (() => {
173 var text = '(module (func (import "a" "b")) (memory (import "c" "d") 1) (table (import "e" "f") 1 anyfunc) (global (import "g" "⚡") i32))'
174 let builder = new WasmModuleBuilder();
175 builder.addImport("a", "b", kSig_i_i);
176 builder.addImportedMemory("c", "d");
177 builder.addImportedTable("e", "f");
178 builder.addImportedGlobal("g", "x", kWasmI32);
179 return new Int8Array(builder.toBuffer());
180 })();
181 var arr = moduleImports(new Module(importingModuleBinary2));
174 assertEq(arr instanceof Array, true); 182 assertEq(arr instanceof Array, true);
175 assertEq(arr.length, 4); 183 assertEq(arr.length, 4);
176 assertEq(arr[0].kind, "function"); 184 assertEq(arr[0].kind, "function");
177 assertEq(arr[0].module, "a"); 185 assertEq(arr[0].module, "a");
178 assertEq(arr[0].name, "b"); 186 assertEq(arr[0].name, "b");
179 assertEq(arr[1].kind, "memory"); 187 assertEq(arr[1].kind, "memory");
180 assertEq(arr[1].module, "c"); 188 assertEq(arr[1].module, "c");
181 assertEq(arr[1].name, "d"); 189 assertEq(arr[1].name, "d");
182 assertEq(arr[2].kind, "table"); 190 assertEq(arr[2].kind, "table");
183 assertEq(arr[2].module, "e"); 191 assertEq(arr[2].module, "e");
184 assertEq(arr[2].name, "f"); 192 assertEq(arr[2].name, "f");
185 assertEq(arr[3].kind, "global"); 193 assertEq(arr[3].kind, "global");
186 assertEq(arr[3].module, "g"); 194 assertEq(arr[3].module, "g");
187 assertEq(arr[3].name, ""); 195 assertEq(arr[3].name, "x");
188 }
189 196
190 if (false) { // TODO: Module.exports property 197 if (false) { // TODO: Module.exports property
191 // 'WebAssembly.Module.exports' data property 198 // 'WebAssembly.Module.exports' data property
192 let moduleExportsDesc = Object.getOwnPropertyDescriptor(Module, 'exports'); 199 let moduleExportsDesc = Object.getOwnPropertyDescriptor(Module, 'exports');
193 assertEq(typeof moduleExportsDesc.value, "function"); 200 assertEq(typeof moduleExportsDesc.value, "function");
194 assertEq(moduleExportsDesc.writable, true); 201 assertEq(moduleExportsDesc.writable, true);
195 assertEq(moduleExportsDesc.enumerable, false); 202 assertEq(moduleExportsDesc.enumerable, false);
196 assertEq(moduleExportsDesc.configurable, true); 203 assertEq(moduleExportsDesc.configurable, true);
197 204
198 // 'WebAssembly.Module.exports' method 205 // 'WebAssembly.Module.exports' method
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 assertEq(result.instance instanceof Instance, true); 584 assertEq(result.instance instanceof Instance, true);
578 } 585 }
579 } 586 }
580 assertInstantiateSuccess(emptyModule); 587 assertInstantiateSuccess(emptyModule);
581 assertInstantiateSuccess(emptyModuleBinary); 588 assertInstantiateSuccess(emptyModuleBinary);
582 assertInstantiateSuccess(emptyModuleBinary.buffer); 589 assertInstantiateSuccess(emptyModuleBinary.buffer);
583 assertInstantiateSuccess(importingModule, {"":{f:()=>{}}}); 590 assertInstantiateSuccess(importingModule, {"":{f:()=>{}}});
584 assertInstantiateSuccess(importingModuleBinary, {"":{f:()=>{}}}); 591 assertInstantiateSuccess(importingModuleBinary, {"":{f:()=>{}}});
585 assertInstantiateSuccess(importingModuleBinary.buffer, {"":{f:()=>{}}}); 592 assertInstantiateSuccess(importingModuleBinary.buffer, {"":{f:()=>{}}});
586 } 593 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698