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

Side by Side Diff: test/mjsunit/wasm/wasm-module-builder.js

Issue 2443353002: [wasm] Add support for exporting WebAssembly.Table instances. (Closed)
Patch Set: Fix identity of exported JSFunctions Created 4 years, 1 month 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 | « test/mjsunit/wasm/indirect-tables.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 // Used for encoding f32 and double constants to bits. 5 // Used for encoding f32 and double constants to bits.
6 let __buffer = new ArrayBuffer(8); 6 let __buffer = new ArrayBuffer(8);
7 let byte_view = new Int8Array(__buffer); 7 let byte_view = new Int8Array(__buffer);
8 let f32_view = new Float32Array(__buffer); 8 let f32_view = new Float32Array(__buffer);
9 let f64_view = new Float64Array(__buffer); 9 let f64_view = new Float64Array(__buffer);
10 10
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 class WasmGlobalBuilder { 114 class WasmGlobalBuilder {
115 constructor(module, type, mutable) { 115 constructor(module, type, mutable) {
116 this.module = module; 116 this.module = module;
117 this.type = type; 117 this.type = type;
118 this.mutable = mutable; 118 this.mutable = mutable;
119 this.init = 0; 119 this.init = 0;
120 } 120 }
121 121
122 exportAs(name) { 122 exportAs(name) {
123 this.module.exports.push({name: name, kind: kExternalGlobal, index: this.ind ex}); 123 this.module.exports.push({name: name, kind: kExternalGlobal,
124 index: this.index});
124 return this; 125 return this;
125 } 126 }
126 } 127 }
127 128
128 class WasmModuleBuilder { 129 class WasmModuleBuilder {
129 constructor() { 130 constructor() {
130 this.types = []; 131 this.types = [];
131 this.imports = []; 132 this.imports = [];
132 this.exports = []; 133 this.exports = [];
133 this.globals = []; 134 this.globals = [];
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 191 }
191 192
192 addImportedGlobal(module, name, type) { 193 addImportedGlobal(module, name, type) {
193 let o = {module: module, name: name, kind: kExternalGlobal, type: type, 194 let o = {module: module, name: name, kind: kExternalGlobal, type: type,
194 mutable: false} 195 mutable: false}
195 this.imports.push(o); 196 this.imports.push(o);
196 return this.num_imported_globals++; 197 return this.num_imported_globals++;
197 } 198 }
198 199
199 addImportedMemory(module, name, initial = 0, maximum) { 200 addImportedMemory(module, name, initial = 0, maximum) {
200 let o = {module: module, name: name, kind: kExternalMemory, initial: initial , maximum: maximum}; 201 let o = {module: module, name: name, kind: kExternalMemory,
202 initial: initial, maximum: maximum};
201 this.imports.push(o); 203 this.imports.push(o);
202 return this; 204 return this;
203 } 205 }
204 206
205 addExport(name, index) { 207 addExport(name, index) {
206 this.exports.push({name: name, kind: kExternalFunction, index: index}); 208 this.exports.push({name: name, kind: kExternalFunction, index: index});
207 return this; 209 return this;
208 } 210 }
209 211
212 addExportOfKind(name, kind, index) {
213 this.exports.push({name: name, kind: kind, index: index});
214 return this;
215 }
216
210 addDataSegment(addr, data, is_global = false) { 217 addDataSegment(addr, data, is_global = false) {
211 this.segments.push({addr: addr, data: data, is_global: is_global}); 218 this.segments.push({addr: addr, data: data, is_global: is_global});
212 return this.segments.length - 1; 219 return this.segments.length - 1;
213 } 220 }
214 221
215 exportMemoryAs(name) { 222 exportMemoryAs(name) {
216 this.exports.push({name: name, kind: kExternalMemory, index: 0}); 223 this.exports.push({name: name, kind: kExternalMemory, index: 0});
217 } 224 }
218 225
219 addFunctionTableInit(base, is_global, array) { 226 addFunctionTableInit(base, is_global, array) {
220 this.function_table_inits.push({base: base, is_global: is_global, array: arr ay}); 227 this.function_table_inits.push({base: base, is_global: is_global,
228 array: array});
221 if (!is_global) { 229 if (!is_global) {
222 var length = base + array.length; 230 var length = base + array.length;
223 if (length > this.function_table_length) this.function_table_length = leng th; 231 if (length > this.function_table_length) {
232 this.function_table_length = length;
233 }
224 } 234 }
225 return this; 235 return this;
226 } 236 }
227 237
228 appendToTable(array) { 238 appendToTable(array) {
229 return this.addFunctionTableInit(this.function_table.length, false, array); 239 return this.addFunctionTableInit(this.function_table.length, false, array);
230 } 240 }
231 241
232 setFunctionTableLength(length) { 242 setFunctionTableLength(length) {
233 this.function_table_length = length; 243 this.function_table_length = length;
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 } 533 }
524 return buffer; 534 return buffer;
525 } 535 }
526 536
527 instantiate(...args) { 537 instantiate(...args) {
528 let module = new WebAssembly.Module(this.toBuffer()); 538 let module = new WebAssembly.Module(this.toBuffer());
529 let instance = new WebAssembly.Instance(module, ...args); 539 let instance = new WebAssembly.Instance(module, ...args);
530 return instance; 540 return instance;
531 } 541 }
532 } 542 }
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/indirect-tables.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698