| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 class WasmFunctionBuilder { | 81 class WasmFunctionBuilder { |
| 82 constructor(module, name, type_index) { | 82 constructor(module, name, type_index) { |
| 83 this.module = module; | 83 this.module = module; |
| 84 this.name = name; | 84 this.name = name; |
| 85 this.type_index = type_index; | 85 this.type_index = type_index; |
| 86 this.body = []; | 86 this.body = []; |
| 87 } | 87 } |
| 88 | 88 |
| 89 exportAs(name) { | 89 exportAs(name) { |
| 90 this.module.exports.push({name: name, kind: kExternalFunction, index: this.i
ndex}); | 90 this.module.addExport(name, this.index); |
| 91 return this; | 91 return this; |
| 92 } | 92 } |
| 93 | 93 |
| 94 exportFunc() { | 94 exportFunc() { |
| 95 this.exportAs(this.name); | 95 this.exportAs(this.name); |
| 96 return this; | 96 return this; |
| 97 } | 97 } |
| 98 | 98 |
| 99 addBody(body) { | 99 addBody(body) { |
| 100 this.body = body; | 100 this.body = body; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 this.imports.push(o); | 199 this.imports.push(o); |
| 200 return this.num_imported_globals++; | 200 return this.num_imported_globals++; |
| 201 } | 201 } |
| 202 | 202 |
| 203 addImportedMemory(module, name, initial = 0, maximum) { | 203 addImportedMemory(module, name, initial = 0, maximum) { |
| 204 let o = {module: module, name: name, kind: kExternalMemory, initial: initial
, maximum: maximum}; | 204 let o = {module: module, name: name, kind: kExternalMemory, initial: initial
, maximum: maximum}; |
| 205 this.imports.push(o); | 205 this.imports.push(o); |
| 206 return this; | 206 return this; |
| 207 } | 207 } |
| 208 | 208 |
| 209 addExport(name, index) { |
| 210 this.exports.push({name: name, kind: kExternalFunction, index: index}); |
| 211 return this; |
| 212 } |
| 213 |
| 209 addDataSegment(addr, data, is_global = false) { | 214 addDataSegment(addr, data, is_global = false) { |
| 210 this.segments.push({addr: addr, data: data, is_global: is_global}); | 215 this.segments.push({addr: addr, data: data, is_global: is_global}); |
| 211 return this.segments.length - 1; | 216 return this.segments.length - 1; |
| 212 } | 217 } |
| 213 | 218 |
| 214 exportMemoryAs(name) { | 219 exportMemoryAs(name) { |
| 215 this.exports.push({name: name, kind: kExternalMemory, index: 0}); | 220 this.exports.push({name: name, kind: kExternalMemory, index: 0}); |
| 216 } | 221 } |
| 217 | 222 |
| 218 appendToTable(array) { | 223 appendToTable(array) { |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 } | 506 } |
| 502 return buffer; | 507 return buffer; |
| 503 } | 508 } |
| 504 | 509 |
| 505 instantiate(...args) { | 510 instantiate(...args) { |
| 506 let module = new WebAssembly.Module(this.toBuffer()); | 511 let module = new WebAssembly.Module(this.toBuffer()); |
| 507 let instance = new WebAssembly.Instance(module, ...args); | 512 let instance = new WebAssembly.Instance(module, ...args); |
| 508 return instance; | 513 return instance; |
| 509 } | 514 } |
| 510 } | 515 } |
| OLD | NEW |