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

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

Issue 2501873003: [wasm] Be more lenient on the names section. (Closed)
Patch Set: Fix builders to add empty import names. Created 4 years, 1 month 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 | « src/wasm/wasm-module-builder.cc ('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 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 for (let exp of wasm.explicit) { 515 for (let exp of wasm.explicit) {
516 if (debug) print("emitting explicit @ " + binary.length); 516 if (debug) print("emitting explicit @ " + binary.length);
517 binary.emit_bytes(exp); 517 binary.emit_bytes(exp);
518 } 518 }
519 519
520 // Add function names. 520 // Add function names.
521 if (has_names) { 521 if (has_names) {
522 if (debug) print("emitting names @ " + binary.length); 522 if (debug) print("emitting names @ " + binary.length);
523 binary.emit_section(kUnknownSectionCode, section => { 523 binary.emit_section(kUnknownSectionCode, section => {
524 section.emit_string("name"); 524 section.emit_string("name");
525 section.emit_u32v(wasm.functions.length); 525 var count = wasm.functions.length + wasm.num_imported_funcs;
526 section.emit_u32v(count);
527 for (var i = 0; i < wasm.num_imported_funcs; i++) {
528 section.emit_u8(0); // empty string
529 section.emit_u8(0); // local names count == 0
530 }
526 for (let func of wasm.functions) { 531 for (let func of wasm.functions) {
527 var name = func.name == undefined ? "" : func.name; 532 var name = func.name == undefined ? "" : func.name;
528 section.emit_string(name); 533 section.emit_string(name);
529 section.emit_u8(0); // local names count == 0 534 section.emit_u8(0); // local names count == 0
530 } 535 }
531 }); 536 });
532 } 537 }
533 538
534 return binary; 539 return binary;
535 } 540 }
536 541
537 toBuffer(debug = false) { 542 toBuffer(debug = false) {
538 let bytes = this.toArray(debug); 543 let bytes = this.toArray(debug);
539 let buffer = new ArrayBuffer(bytes.length); 544 let buffer = new ArrayBuffer(bytes.length);
540 let view = new Uint8Array(buffer); 545 let view = new Uint8Array(buffer);
541 for (let i = 0; i < bytes.length; i++) { 546 for (let i = 0; i < bytes.length; i++) {
542 let val = bytes[i]; 547 let val = bytes[i];
543 if ((typeof val) == "string") val = val.charCodeAt(0); 548 if ((typeof val) == "string") val = val.charCodeAt(0);
544 view[i] = val | 0; 549 view[i] = val | 0;
545 } 550 }
546 return buffer; 551 return buffer;
547 } 552 }
548 553
549 instantiate(...args) { 554 instantiate(...args) {
550 let module = new WebAssembly.Module(this.toBuffer()); 555 let module = new WebAssembly.Module(this.toBuffer());
551 let instance = new WebAssembly.Instance(module, ...args); 556 let instance = new WebAssembly.Instance(module, ...args);
552 return instance; 557 return instance;
553 } 558 }
554 } 559 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-module-builder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698