| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // Copy the temporary buffer. | 76 // Copy the temporary buffer. |
| 77 this.push(...section); | 77 this.push(...section); |
| 78 } | 78 } |
| 79 } | 79 } |
| 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 } | 87 } |
| 87 | 88 |
| 88 exportAs(name) { | 89 exportAs(name) { |
| 89 this.module.exports.push({name: name, kind: kExternalFunction, index: this.i
ndex}); | 90 this.module.addExport(name, this.index); |
| 90 return this; | 91 return this; |
| 91 } | 92 } |
| 92 | 93 |
| 93 exportFunc() { | 94 exportFunc() { |
| 94 this.exportAs(this.name); | 95 this.exportAs(this.name); |
| 95 return this; | 96 return this; |
| 96 } | 97 } |
| 97 | 98 |
| 98 addBody(body) { | 99 addBody(body) { |
| 99 this.body = body; | 100 this.body = body; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 mutable: false} | 193 mutable: false} |
| 193 this.imports.push(o); | 194 this.imports.push(o); |
| 194 return this.num_imported_globals++; | 195 return this.num_imported_globals++; |
| 195 } | 196 } |
| 196 | 197 |
| 197 addImportedMemory(module, name, initial = 0, maximum) { | 198 addImportedMemory(module, name, initial = 0, maximum) { |
| 198 let o = {module: module, name: name, kind: kExternalMemory, initial: initial
, maximum: maximum}; | 199 let o = {module: module, name: name, kind: kExternalMemory, initial: initial
, maximum: maximum}; |
| 199 this.imports.push(o); | 200 this.imports.push(o); |
| 200 } | 201 } |
| 201 | 202 |
| 203 addExport(name, index) { |
| 204 this.exports.push({name: name, kind: kExternalFunction, index: index}); |
| 205 return this; |
| 206 } |
| 207 |
| 202 addDataSegment(addr, data, is_global = false) { | 208 addDataSegment(addr, data, is_global = false) { |
| 203 this.segments.push({addr: addr, data: data, is_global: is_global}); | 209 this.segments.push({addr: addr, data: data, is_global: is_global}); |
| 204 return this.segments.length - 1; | 210 return this.segments.length - 1; |
| 205 } | 211 } |
| 206 | 212 |
| 207 exportMemoryAs(name) { | 213 exportMemoryAs(name) { |
| 208 this.exports.push({name: name, kind: kExternalMemory, index: 0}); | 214 this.exports.push({name: name, kind: kExternalMemory, index: 0}); |
| 209 } | 215 } |
| 210 | 216 |
| 211 appendToTable(array) { | 217 appendToTable(array) { |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 } | 500 } |
| 495 return buffer; | 501 return buffer; |
| 496 } | 502 } |
| 497 | 503 |
| 498 instantiate(...args) { | 504 instantiate(...args) { |
| 499 let module = new WebAssembly.Module(this.toBuffer()); | 505 let module = new WebAssembly.Module(this.toBuffer()); |
| 500 let instance = new WebAssembly.Instance(module, ...args); | 506 let instance = new WebAssembly.Instance(module, ...args); |
| 501 return instance; | 507 return instance; |
| 502 } | 508 } |
| 503 } | 509 } |
| OLD | NEW |