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

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

Issue 1967023004: [wasm] Add UTF-8 validation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase on parallel compilation Created 4 years, 7 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/unicode-validation.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 2e8c23ee2ed7b87de359827fb42ca95b55b2764f..bfc4460d91b899d4ca640502cbfd625ef35ea1b4 100644
--- a/test/mjsunit/wasm/wasm-module-builder.js
+++ b/test/mjsunit/wasm/wasm-module-builder.js
@@ -75,9 +75,7 @@ WasmModuleBuilder.prototype.addImportWithModule = function(module, name, sig) {
}
WasmModuleBuilder.prototype.addImport = function(name, sig) {
- var sig_index = (typeof sig) == "number" ? sig : this.addSignature(sig);
- this.imports.push({module: name, name: undefined, sig_index: sig_index});
- return this.imports.length - 1;
+ this.addImportWithModule(name, undefined, sig);
}
WasmModuleBuilder.prototype.addDataSegment = function(addr, data, init) {
@@ -107,9 +105,19 @@ function emit_u32(bytes, val) {
}
function emit_string(bytes, string) {
- emit_varint(bytes, string.length);
- for (var i = 0; i < string.length; i++) {
- emit_u8(bytes, string.charCodeAt(i));
+ // When testing illegal names, we pass a byte array directly.
+ if (string instanceof Array) {
+ emit_varint(bytes, string.length);
+ emit_bytes(bytes, string);
+ return;
+ }
+
+ // This is the hacky way to convert a JavaScript scring to a UTF8 encoded
+ // string only containing single-byte characters.
+ var string_utf8 = unescape(encodeURIComponent(string));
+ emit_varint(bytes, string_utf8.length);
+ for (var i = 0; i < string_utf8.length; i++) {
+ emit_u8(bytes, string_utf8.charCodeAt(i));
}
}
@@ -309,8 +317,8 @@ WasmModuleBuilder.prototype.toArray = function(debug) {
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
+ emit_string(bytes, name);
+ emit_u8(bytes, 0); // local names count == 0
}
});
}
« no previous file with comments | « test/mjsunit/wasm/unicode-validation.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698