Index: test/mjsunit/wasm/wasm-module-builder.js |
diff --git a/test/mjsunit/wasm/wasm-module-builder.js b/test/mjsunit/wasm/wasm-module-builder.js |
index 0aae6d9eaec08a0dd636cc8c401a49929ba38706..e51d4425fdaf04ab0279a0be3c9aa08fb182f4b0 100644 |
--- a/test/mjsunit/wasm/wasm-module-builder.js |
+++ b/test/mjsunit/wasm/wasm-module-builder.js |
@@ -23,6 +23,11 @@ WasmFunctionBuilder.prototype.exportAs = function(name) { |
return this; |
} |
+WasmFunctionBuilder.prototype.exportFunc = function() { |
+ this.exports.push(this.name); |
+ return this; |
+} |
+ |
WasmFunctionBuilder.prototype.addBody = function(body) { |
this.body = body; |
return this; |
@@ -40,14 +45,24 @@ function WasmModuleBuilder() { |
this.exports = []; |
this.function_table = []; |
this.data_segments = []; |
+ this.explicit = []; |
return this; |
} |
+WasmModuleBuilder.prototype.addStart = function(start_index) { |
+ this.start_index = start_index; |
+} |
+ |
WasmModuleBuilder.prototype.addMemory = function(min, max, exp) { |
this.memory = {min: min, max: max, exp: exp}; |
return this; |
} |
+WasmModuleBuilder.prototype.addExplicitSection = function(bytes) { |
+ this.explicit.push(bytes); |
+ return this; |
+} |
+ |
// Add a signature; format is [rettype, param0, param1, ...] |
WasmModuleBuilder.prototype.addSignature = function(sig) { |
// TODO: canonicalize signatures? |
@@ -199,6 +214,13 @@ WasmModuleBuilder.prototype.toArray = function(debug) { |
} |
} |
+ // Add start function section. |
+ if (this.start_index != undefined) { |
+ if (debug) print("emitting start function @ " + bytes.length); |
+ emit_u8(bytes, kDeclStartFunction); |
+ emit_varint(bytes, this.start_index); |
+ } |
+ |
if (this.function_table.length > 0) { |
if (debug) print("emitting function table @ " + bytes.length); |
emit_u8(bytes, kDeclFunctionTable); |
@@ -232,6 +254,14 @@ WasmModuleBuilder.prototype.toArray = function(debug) { |
} |
} |
+ // Emit any explicitly added sections |
+ for (exp of this.explicit) { |
+ if (debug) print("emitting explicit @ " + bytes.length); |
+ for (var i = 0; i < exp.length; i++) { |
+ emit_u8(bytes, exp[i]); |
+ } |
+ } |
+ |
// End the module. |
if (debug) print("emitting end @ " + bytes.length); |
emit_u8(bytes, kDeclEnd); |
@@ -305,7 +335,11 @@ WasmModuleBuilder.prototype.toBuffer = function(debug) { |
return buffer; |
} |
-WasmModuleBuilder.prototype.instantiate = function(ffi) { |
+WasmModuleBuilder.prototype.instantiate = function(ffi, memory) { |
var buffer = this.toBuffer(); |
- return _WASMEXP_.instantiateModule(buffer, ffi); |
+ if (memory != undefined) { |
+ return _WASMEXP_.instantiateModule(buffer, ffi, memory); |
+ } else { |
+ return _WASMEXP_.instantiateModule(buffer, ffi); |
+ } |
} |