| 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 // 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 return this.num_imported_globals++; | 197 return this.num_imported_globals++; |
| 198 } | 198 } |
| 199 | 199 |
| 200 addImportedMemory(module, name, initial = 0, maximum) { | 200 addImportedMemory(module, name, initial = 0, maximum) { |
| 201 let o = {module: module, name: name, kind: kExternalMemory, | 201 let o = {module: module, name: name, kind: kExternalMemory, |
| 202 initial: initial, maximum: maximum}; | 202 initial: initial, maximum: maximum}; |
| 203 this.imports.push(o); | 203 this.imports.push(o); |
| 204 return this; | 204 return this; |
| 205 } | 205 } |
| 206 | 206 |
| 207 addImportedTable(module, name, initial, maximum) { | |
| 208 let o = {module: module, name: name, kind: kExternalTable, initial: initial, | |
| 209 maximum: maximum}; | |
| 210 this.imports.push(o); | |
| 211 } | |
| 212 | |
| 213 addExport(name, index) { | 207 addExport(name, index) { |
| 214 this.exports.push({name: name, kind: kExternalFunction, index: index}); | 208 this.exports.push({name: name, kind: kExternalFunction, index: index}); |
| 215 return this; | 209 return this; |
| 216 } | 210 } |
| 217 | 211 |
| 218 addExportOfKind(name, kind, index) { | 212 addExportOfKind(name, kind, index) { |
| 219 this.exports.push({name: name, kind: kind, index: index}); | 213 this.exports.push({name: name, kind: kind, index: index}); |
| 220 return this; | 214 return this; |
| 221 } | 215 } |
| 222 | 216 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 section.emit_u8(imp.kind); | 281 section.emit_u8(imp.kind); |
| 288 if (imp.kind == kExternalFunction) { | 282 if (imp.kind == kExternalFunction) { |
| 289 section.emit_u32v(imp.type); | 283 section.emit_u32v(imp.type); |
| 290 } else if (imp.kind == kExternalGlobal) { | 284 } else if (imp.kind == kExternalGlobal) { |
| 291 section.emit_u32v(imp.type); | 285 section.emit_u32v(imp.type); |
| 292 section.emit_u8(imp.mutable); | 286 section.emit_u8(imp.mutable); |
| 293 } else if (imp.kind == kExternalMemory) { | 287 } else if (imp.kind == kExternalMemory) { |
| 294 var has_max = (typeof imp.maximum) != "undefined"; | 288 var has_max = (typeof imp.maximum) != "undefined"; |
| 295 section.emit_u8(has_max ? 1 : 0); // flags | 289 section.emit_u8(has_max ? 1 : 0); // flags |
| 296 section.emit_u32v(imp.initial); // initial | 290 section.emit_u32v(imp.initial); // initial |
| 297 if (has_max) section.emit_u32v(imp.maximum); // maximum | |
| 298 } else if (imp.kind == kExternalTable) { | |
| 299 section.emit_u8(kWasmAnyFunctionTypeForm); | |
| 300 var has_max = (typeof imp.maximum) != "undefined"; | |
| 301 section.emit_u8(has_max ? 1 : 0); // flags | |
| 302 section.emit_u32v(imp.initial); // initial | |
| 303 if (has_max) section.emit_u32v(imp.maximum); // maximum | 291 if (has_max) section.emit_u32v(imp.maximum); // maximum |
| 304 } else { | 292 } else { |
| 305 throw new Error("unknown/unsupported import kind " + imp.kind); | 293 throw new Error("unknown/unsupported import kind " + imp.kind); |
| 306 } | 294 } |
| 307 } | 295 } |
| 308 }); | 296 }); |
| 309 } | 297 } |
| 310 | 298 |
| 311 // Add functions declarations | 299 // Add functions declarations |
| 312 let has_names = false; | 300 let has_names = false; |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 } | 533 } |
| 546 return buffer; | 534 return buffer; |
| 547 } | 535 } |
| 548 | 536 |
| 549 instantiate(...args) { | 537 instantiate(...args) { |
| 550 let module = new WebAssembly.Module(this.toBuffer()); | 538 let module = new WebAssembly.Module(this.toBuffer()); |
| 551 let instance = new WebAssembly.Instance(module, ...args); | 539 let instance = new WebAssembly.Instance(module, ...args); |
| 552 return instance; | 540 return instance; |
| 553 } | 541 } |
| 554 } | 542 } |
| OLD | NEW |