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

Unified Diff: test/mjsunit/wasm/wasm-module-builder.js

Issue 1770913002: [wasm] Use the JavaScript WasmModuleBuilder utility in JS tests. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/mjsunit/wasm/wasm-constants.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+ }
}
« no previous file with comments | « test/mjsunit/wasm/wasm-constants.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698