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