Commit 6e643f04 authored by titzer's avatar titzer Committed by Commit bot

[wasm] Be more lenient on the names section.

R=clemensh@chromium.org,dschuff@chromium.org
BUG=v8:5632
LOG=Y

Review-Url: https://codereview.chromium.org/2501873003
Cr-Commit-Position: refs/heads/master@{#41011}
parent 14c6a651
......@@ -623,17 +623,16 @@ class ModuleDecoder : public Decoder {
// ===== Name section ====================================================
if (section_iter.section_code() == kNameSectionCode) {
const byte* pos = pc_;
uint32_t functions_count = consume_u32v("functions count");
if (functions_count != module->num_declared_functions) {
error(pos, pos, "function name count %u mismatch (%u expected)",
functions_count, module->num_declared_functions);
}
for (uint32_t i = 0; ok() && i < functions_count; ++i) {
WasmFunction* function =
&module->functions[i + module->num_imported_functions];
function->name_offset = consume_string(&function->name_length, false);
uint32_t function_name_length = 0;
uint32_t name_offset = consume_string(&function_name_length, false);
uint32_t func_index = i;
if (func_index < module->functions.size()) {
module->functions[func_index].name_offset = name_offset;
module->functions[func_index].name_length = function_name_length;
}
uint32_t local_names_count = consume_u32v("local names count");
for (uint32_t j = 0; ok() && j < local_names_count; j++) {
......
......@@ -509,7 +509,12 @@ void WasmModuleBuilder::WriteTo(ZoneBuffer& buffer) const {
buffer.write_size(4);
buffer.write(reinterpret_cast<const byte*>("name"), 4);
// Emit the names.
buffer.write_size(functions_.size());
size_t count = functions_.size() + imports_.size();
buffer.write_size(count);
for (size_t i = 0; i < imports_.size(); i++) {
buffer.write_u8(0); // empty name for import
buffer.write_u8(0); // no local variables
}
for (auto function : functions_) {
buffer.write_size(function->name_.size());
if (function->name_.size() > 0) {
......
......@@ -522,7 +522,12 @@ class WasmModuleBuilder {
if (debug) print("emitting names @ " + binary.length);
binary.emit_section(kUnknownSectionCode, section => {
section.emit_string("name");
section.emit_u32v(wasm.functions.length);
var count = wasm.functions.length + wasm.num_imported_funcs;
section.emit_u32v(count);
for (var i = 0; i < wasm.num_imported_funcs; i++) {
section.emit_u8(0); // empty string
section.emit_u8(0); // local names count == 0
}
for (let func of wasm.functions) {
var name = func.name == undefined ? "" : func.name;
section.emit_string(name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment