Commit f51a5f73 authored by titzer's avatar titzer Committed by Commit bot

[wasm-test] WasmModuleBuilder.addCustomSection in the JS builder API.

R=rossberg@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2650053005
Cr-Commit-Position: refs/heads/master@{#42655}
parent 0ec3a264
......@@ -292,19 +292,10 @@ assertErrorMessage(
let customSectionModuleBinary2 = (() => {
let builder = new WasmModuleBuilder();
builder.addExplicitSection([kUnknownSectionCode, 3, 1, 'x'.charCodeAt(0), 2]);
builder.addExplicitSection([
kUnknownSectionCode, 6, 3, 'f'.charCodeAt(0), 'o'.charCodeAt(0),
'o'.charCodeAt(0), 66, 77
]);
builder.addExplicitSection([
kUnknownSectionCode, 7, 3, 'f'.charCodeAt(0), 'o'.charCodeAt(0),
'o'.charCodeAt(0), 91, 92, 93
]);
builder.addExplicitSection([
kUnknownSectionCode, 7, 3, 'f'.charCodeAt(0), 'o'.charCodeAt(0),
'x'.charCodeAt(0), 99, 99, 99
]);
builder.addCustomSection('x', [2]);
builder.addCustomSection('foo', [66, 77]);
builder.addCustomSection('foo', [91, 92, 93]);
builder.addCustomSection('fox', [99, 99, 99]);
return new Int8Array(builder.toBuffer());
})();
var arr = moduleCustomSections(new Module(customSectionModuleBinary2), 'x');
......
......@@ -160,6 +160,22 @@ class WasmModuleBuilder {
return this;
}
stringToBytes(name) {
var result = new Binary();
result.emit_u32v(name.length);
for (var i = 0; i < name.length; i++) {
result.emit_u8(name.charCodeAt(i));
}
return result;
}
addCustomSection(name, bytes) {
name = this.stringToBytes(name);
var length = new Binary();
length.emit_u32v(name.length + bytes.length);
this.explicit.push([0, ...length, ...name, ...bytes]);
}
addType(type) {
// TODO: canonicalize types?
this.types.push(type);
......
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