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

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

Issue 1900153002: [wasm] Enforce strict ordering of WASM module sections. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 8 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 | « src/wasm/wasm-module.cc ('k') | test/unittests/wasm/module-decoder-unittest.cc » ('j') | 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 e1d996338c2b5a7d0525a20b090f271f8a523a80..1c138909209e74db55ded549f151c984d7585405 100644
--- a/test/mjsunit/wasm/wasm-module-builder.js
+++ b/test/mjsunit/wasm/wasm-module-builder.js
@@ -149,16 +149,6 @@ WasmModuleBuilder.prototype.toArray = function(debug) {
var wasm = this;
- // Add memory section
- if (wasm.memory != undefined) {
- if (debug) print("emitting memory @ " + bytes.length);
- emit_section(bytes, kDeclMemory, function(bytes) {
- emit_varint(bytes, wasm.memory.min);
- emit_varint(bytes, wasm.memory.max);
- emit_u8(bytes, wasm.memory.exp ? 1 : 0);
- });
- }
-
// Add signatures section
if (wasm.signatures.length > 0) {
if (debug) print("emitting signatures @ " + bytes.length);
@@ -187,7 +177,7 @@ WasmModuleBuilder.prototype.toArray = function(debug) {
});
}
- // Add functions section
+ // Add functions declarations
var names = false;
var exports = 0;
if (wasm.functions.length > 0) {
@@ -206,6 +196,54 @@ WasmModuleBuilder.prototype.toArray = function(debug) {
}
});
+ }
+
+ // Add function table.
+ if (wasm.function_table.length > 0) {
+ if (debug) print("emitting function table @ " + bytes.length);
+ emit_section(bytes, kDeclFunctionTable, function(bytes) {
+ emit_varint(bytes, wasm.function_table.length);
+ for (index of wasm.function_table) {
+ emit_varint(bytes, index);
+ }
+ });
+ }
+
+ // Add memory section
+ if (wasm.memory != undefined) {
+ if (debug) print("emitting memory @ " + bytes.length);
+ emit_section(bytes, kDeclMemory, function(bytes) {
+ emit_varint(bytes, wasm.memory.min);
+ emit_varint(bytes, wasm.memory.max);
+ emit_u8(bytes, wasm.memory.exp ? 1 : 0);
+ });
+ }
+
+
+ // Add export table.
+ if (exports > 0) {
+ if (debug) print("emitting exports @ " + bytes.length);
+ emit_section(bytes, kDeclExportTable, function(bytes) {
+ emit_varint(bytes, exports);
+ for (func of wasm.functions) {
+ for (exp of func.exports) {
+ emit_varint(bytes, func.index);
+ emit_string(bytes, exp);
+ }
+ }
+ });
+ }
+
+ // Add start function section.
+ if (wasm.start_index != undefined) {
+ if (debug) print("emitting start function @ " + bytes.length);
+ emit_section(bytes, kDeclStartFunction, function(bytes) {
+ emit_varint(bytes, wasm.start_index);
+ });
+ }
+
+ // Add function bodies.
+ if (wasm.functions.length > 0) {
// emit function bodies
if (debug) print("emitting function bodies @ " + bytes.length);
emit_section(bytes, kDeclFunctionBodies, function(bytes) {
@@ -244,50 +282,7 @@ WasmModuleBuilder.prototype.toArray = function(debug) {
});
}
- // emit function names
- if (has_names) {
- if (debug) print("emitting names @ " + bytes.length);
- emit_section(bytes, kDeclNames, function(bytes) {
- emit_varint(bytes, wasm.functions.length);
- for (func of wasm.functions) {
- var name = func.name == undefined ? "" : func.name;
- emit_string(bytes, name);
- emit_u8(bytes, 0); // local names count == 0
- }
- });
- }
-
- // Add start function section.
- if (wasm.start_index != undefined) {
- if (debug) print("emitting start function @ " + bytes.length);
- emit_section(bytes, kDeclStartFunction, function(bytes) {
- emit_varint(bytes, wasm.start_index);
- });
- }
-
- if (wasm.function_table.length > 0) {
- if (debug) print("emitting function table @ " + bytes.length);
- emit_section(bytes, kDeclFunctionTable, function(bytes) {
- emit_varint(bytes, wasm.function_table.length);
- for (index of wasm.function_table) {
- emit_varint(bytes, index);
- }
- });
- }
-
- if (exports > 0) {
- if (debug) print("emitting exports @ " + bytes.length);
- emit_section(bytes, kDeclExportTable, function(bytes) {
- emit_varint(bytes, exports);
- for (func of wasm.functions) {
- for (exp of func.exports) {
- emit_varint(bytes, func.index);
- emit_string(bytes, exp);
- }
- }
- });
- }
-
+ // Add data segments.
if (wasm.data_segments.length > 0) {
if (debug) print("emitting data segments @ " + bytes.length);
emit_section(bytes, kDeclDataSegments, function(bytes) {
@@ -300,12 +295,25 @@ WasmModuleBuilder.prototype.toArray = function(debug) {
});
}
- // Emit any explicitly added sections
+ // Add any explicitly added sections
for (exp of wasm.explicit) {
if (debug) print("emitting explicit @ " + bytes.length);
emit_bytes(bytes, exp);
}
+ // Add function names.
+ if (has_names) {
+ if (debug) print("emitting names @ " + bytes.length);
+ emit_section(bytes, kDeclNames, function(bytes) {
+ emit_varint(bytes, wasm.functions.length);
+ for (func of wasm.functions) {
+ var name = func.name == undefined ? "" : func.name;
+ emit_string(bytes, name);
+ emit_u8(bytes, 0); // local names count == 0
+ }
+ });
+ }
+
// End the module.
if (debug) print("emitting end @ " + bytes.length);
emit_section(bytes, kDeclEnd, function(bytes) {});
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | test/unittests/wasm/module-decoder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698