Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: test/mjsunit/wasm/wasm-module-builder.js

Issue 2650053005: [wasm-test] WasmModuleBuilder.addCustomSection in the JS builder API. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/wasm/js-api.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 addMemory(min, max, exp) { 153 addMemory(min, max, exp) {
154 this.memory = {min: min, max: max, exp: exp}; 154 this.memory = {min: min, max: max, exp: exp};
155 return this; 155 return this;
156 } 156 }
157 157
158 addExplicitSection(bytes) { 158 addExplicitSection(bytes) {
159 this.explicit.push(bytes); 159 this.explicit.push(bytes);
160 return this; 160 return this;
161 } 161 }
162 162
163 stringToBytes(name) {
164 var result = new Binary();
165 result.emit_u32v(name.length);
166 for (var i = 0; i < name.length; i++) {
167 result.emit_u8(name.charCodeAt(i));
168 }
169 return result;
170 }
171
172 addCustomSection(name, bytes) {
173 name = this.stringToBytes(name);
174 var length = new Binary();
175 length.emit_u32v(name.length + bytes.length);
176 this.explicit.push([0, ...length, ...name, ...bytes]);
177 }
178
163 addType(type) { 179 addType(type) {
164 // TODO: canonicalize types? 180 // TODO: canonicalize types?
165 this.types.push(type); 181 this.types.push(type);
166 return this.types.length - 1; 182 return this.types.length - 1;
167 } 183 }
168 184
169 addGlobal(local_type, mutable) { 185 addGlobal(local_type, mutable) {
170 let glob = new WasmGlobalBuilder(this, local_type, mutable); 186 let glob = new WasmGlobalBuilder(this, local_type, mutable);
171 glob.index = this.globals.length + this.num_imported_globals; 187 glob.index = this.globals.length + this.num_imported_globals;
172 this.globals.push(glob); 188 this.globals.push(glob);
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 } 564 }
549 return buffer; 565 return buffer;
550 } 566 }
551 567
552 instantiate(ffi) { 568 instantiate(ffi) {
553 let module = new WebAssembly.Module(this.toBuffer()); 569 let module = new WebAssembly.Module(this.toBuffer());
554 let instance = new WebAssembly.Instance(module, ffi); 570 let instance = new WebAssembly.Instance(module, ffi);
555 return instance; 571 return instance;
556 } 572 }
557 } 573 }
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/js-api.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698