Commit 71eb30bc authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Fix unicode names occuring in error messages

If a String object contains unicode, the returned {ToCString()} may
actually longer than the {length()} of the String.
But it's always null-terminated, so we can just print it without
explicitly passing a length.

R=ahaas@chromium.org

Change-Id: I3398f151d70ed459ecd8093ea18409670a7374c7
Reviewed-on: https://chromium-review.googlesource.com/548058
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46225}
parent acf49293
......@@ -193,17 +193,15 @@ class InstanceBuilder {
#define ERROR_THROWER_WITH_MESSAGE(TYPE) \
void Report##TYPE(const char* error, uint32_t index, \
Handle<String> module_name, Handle<String> import_name) { \
thrower_->TYPE("Import #%d module=\"%.*s\" function=\"%.*s\" error: %s", \
index, module_name->length(), \
module_name->ToCString().get(), import_name->length(), \
thrower_->TYPE("Import #%d module=\"%s\" function=\"%s\" error: %s", \
index, module_name->ToCString().get(), \
import_name->ToCString().get(), error); \
} \
\
MaybeHandle<Object> Report##TYPE(const char* error, uint32_t index, \
Handle<String> module_name) { \
thrower_->TYPE("Import #%d module=\"%.*s\" error: %s", index, \
module_name->length(), module_name->ToCString().get(), \
error); \
thrower_->TYPE("Import #%d module=\"%s\" error: %s", index, \
module_name->ToCString().get(), error); \
return MaybeHandle<Object>(); \
}
......
......@@ -54,3 +54,32 @@ checkExports('☺☺mul☺☺', '☺☺mul☺☺', '☺☺add☺☺', '☺☺add
() => builder.instantiate(), WebAssembly.CompileError,
/Compiling wasm function #0:three snowmen: ☃☃☃ failed: /);
})();
(function errorMessageUnicodeInImportModuleName() {
var builder = new WasmModuleBuilder();
builder.addImport('three snowmen: ☃☃☃', 'foo', kSig_i_v);
assertThrows(
() => builder.instantiate({}), TypeError,
/WebAssembly Instantiation: Import #0 module="three snowmen: ☃☃☃" error: /);
})();
(function errorMessageUnicodeInImportElemName() {
var builder = new WasmModuleBuilder();
builder.addImport('mod', 'three snowmen: ☃☃☃', kSig_i_v);
assertThrows(
() => builder.instantiate({mod: {}}), WebAssembly.LinkError,
'WebAssembly Instantiation: Import #0 module="mod" function="three ' +
'snowmen: ☃☃☃" error: function import requires a callable');
})();
(function errorMessageUnicodeInImportModAndElemName() {
var builder = new WasmModuleBuilder();
let mod_name = '☮▁▂▃▄☾ ♛ ◡ ♛ ☽▄▃▂▁☮';
let func_name = '☾˙❀‿❀˙☽';
builder.addImport(mod_name, func_name, kSig_i_v);
assertThrows(
() => builder.instantiate({[mod_name]: {}}), WebAssembly.LinkError,
'WebAssembly Instantiation: Import #0 module="' + mod_name +
'" function="' + func_name +
'" error: function import requires a callable');
})();
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