| Index: src/wasm/encoder.cc
|
| diff --git a/src/wasm/encoder.cc b/src/wasm/encoder.cc
|
| index 91624782af8f85350e524dcb7e464a6937621991..4ed8e896b6252481db9f731268118deca0bfc995 100644
|
| --- a/src/wasm/encoder.cc
|
| +++ b/src/wasm/encoder.cc
|
| @@ -180,7 +180,6 @@ void WasmFunctionBuilder::SetName(const unsigned char* name, int name_length) {
|
| for (int i = 0; i < name_length; i++) {
|
| name_.push_back(*(name + i));
|
| }
|
| - name_.push_back('\0');
|
| }
|
| }
|
|
|
| @@ -287,7 +286,10 @@ WasmFunctionEncoder::WasmFunctionEncoder(Zone* zone, LocalType return_type,
|
| uint32_t WasmFunctionEncoder::HeaderSize() const {
|
| uint32_t size = 3;
|
| if (!external_) size += 2;
|
| - if (HasName()) size += 4;
|
| + if (HasName()) {
|
| + uint32_t name_size = NameSize();
|
| + size += static_cast<uint32_t>(SizeOfVarInt(name_size)) + name_size;
|
| + }
|
| return size;
|
| }
|
|
|
| @@ -320,10 +322,10 @@ void WasmFunctionEncoder::Serialize(byte* buffer, byte** header,
|
| EmitUint16(header, signature_index_);
|
|
|
| if (HasName()) {
|
| - uint32_t name_offset = static_cast<uint32_t>(*body - buffer);
|
| - EmitUint32(header, name_offset);
|
| - std::memcpy(*body, &name_[0], name_.size());
|
| - (*body) += name_.size();
|
| + EmitVarInt(header, NameSize());
|
| + for (size_t i = 0; i < name_.size(); ++i) {
|
| + EmitUint8(header, name_[i]);
|
| + }
|
| }
|
|
|
|
|
| @@ -517,7 +519,8 @@ WasmModuleIndex* WasmModuleWriter::WriteTo(Zone* zone) const {
|
|
|
| sizes.AddSection(globals_.size());
|
| if (globals_.size() > 0) {
|
| - sizes.Add(kDeclGlobalSize * globals_.size(), 0);
|
| + /* These globals never have names, so are always 3 bytes. */
|
| + sizes.Add(3 * globals_.size(), 0);
|
| }
|
|
|
| sizes.AddSection(functions_.size());
|
| @@ -564,7 +567,7 @@ WasmModuleIndex* WasmModuleWriter::WriteTo(Zone* zone) const {
|
| EmitVarInt(&header, globals_.size());
|
|
|
| for (auto global : globals_) {
|
| - EmitUint32(&header, 0);
|
| + EmitVarInt(&header, 0); // Length of the global name.
|
| EmitUint8(&header, WasmOpcodes::MemTypeCodeFor(global.first));
|
| EmitUint8(&header, global.second);
|
| }
|
|
|