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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 } | 172 } |
173 | 173 |
174 addFunction(name, type) { | 174 addFunction(name, type) { |
175 let type_index = (typeof type) == "number" ? type : this.addType(type); | 175 let type_index = (typeof type) == "number" ? type : this.addType(type); |
176 let func = new WasmFunctionBuilder(this, name, type_index); | 176 let func = new WasmFunctionBuilder(this, name, type_index); |
177 func.index = this.functions.length + this.num_imported_funcs; | 177 func.index = this.functions.length + this.num_imported_funcs; |
178 this.functions.push(func); | 178 this.functions.push(func); |
179 return func; | 179 return func; |
180 } | 180 } |
181 | 181 |
182 addImportWithModule(module, name, type) { | 182 addImport(module = "", name, type) { |
183 let type_index = (typeof type) == "number" ? type : this.addType(type); | 183 let type_index = (typeof type) == "number" ? type : this.addType(type); |
184 this.imports.push({module: module, name: name, kind: kExternalFunction, | 184 this.imports.push({module: module, name: name, kind: kExternalFunction, |
185 type: type_index}); | 185 type: type_index}); |
186 return this.num_imported_funcs++; | 186 return this.num_imported_funcs++; |
187 } | 187 } |
188 | 188 |
189 addImport(name, type) { | 189 addImportedGlobal(module = "", name, type) { |
190 return this.addImportWithModule(name, undefined, type); | |
191 } | |
192 | |
193 addImportedGlobal(module, name, type) { | |
194 let o = {module: module, name: name, kind: kExternalGlobal, type: type, | 190 let o = {module: module, name: name, kind: kExternalGlobal, type: type, |
195 mutable: false} | 191 mutable: false} |
196 this.imports.push(o); | 192 this.imports.push(o); |
197 return this.num_imported_globals++; | 193 return this.num_imported_globals++; |
198 } | 194 } |
199 | 195 |
200 addImportedMemory(module, name, initial = 0, maximum) { | 196 addImportedMemory(module = "", name, initial = 0, maximum) { |
201 let o = {module: module, name: name, kind: kExternalMemory, | 197 let o = {module: module, name: name, kind: kExternalMemory, |
202 initial: initial, maximum: maximum}; | 198 initial: initial, maximum: maximum}; |
203 this.imports.push(o); | 199 this.imports.push(o); |
204 return this; | 200 return this; |
205 } | 201 } |
206 | 202 |
207 addImportedTable(module, name, initial, maximum) { | 203 addImportedTable(module = "", name, initial, maximum) { |
208 let o = {module: module, name: name, kind: kExternalTable, initial: initial, | 204 let o = {module: module, name: name, kind: kExternalTable, initial: initial, |
209 maximum: maximum}; | 205 maximum: maximum}; |
210 this.imports.push(o); | 206 this.imports.push(o); |
211 } | 207 } |
212 | 208 |
213 addExport(name, index) { | 209 addExport(name, index) { |
214 this.exports.push({name: name, kind: kExternalFunction, index: index}); | 210 this.exports.push({name: name, kind: kExternalFunction, index: index}); |
215 return this; | 211 return this; |
216 } | 212 } |
217 | 213 |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 } | 546 } |
551 return buffer; | 547 return buffer; |
552 } | 548 } |
553 | 549 |
554 instantiate(...args) { | 550 instantiate(...args) { |
555 let module = new WebAssembly.Module(this.toBuffer()); | 551 let module = new WebAssembly.Module(this.toBuffer()); |
556 let instance = new WebAssembly.Instance(module, ...args); | 552 let instance = new WebAssembly.Instance(module, ...args); |
557 return instance; | 553 return instance; |
558 } | 554 } |
559 } | 555 } |
OLD | NEW |