Commit 5a41b45b authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Test and fix more unicode usages

Test that unicode identifiers can be used for imports and exports, and
that unicode function names appear correctly in error messages.

R=ahaas@chromium.org

Change-Id: Ic6ac77159c275845886b2eb779cf59edb8cba9ea
Reviewed-on: https://chromium-review.googlesource.com/548315
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46220}
parent 2ec46bec
......@@ -4067,11 +4067,10 @@ Handle<Code> WasmCompilationUnit::FinishCompilation(
// Add the function as another context for the exception
ScopedVector<char> buffer(128);
if (func_name_.start() == nullptr) {
SNPrintF(buffer,
"Compiling wasm function #%d:%.*s failed:", func_index_,
func_name_.length(), func_name_.start());
SNPrintF(buffer, "Compiling wasm function #%d failed", func_index_);
} else {
SNPrintF(buffer, "Compiling wasm function #%d failed:", func_index_);
SNPrintF(buffer, "Compiling wasm function #%d:%.*s failed", func_index_,
func_name_.length(), func_name_.start());
}
thrower->CompileFailed(buffer.start(), graph_construction_result_);
}
......
......@@ -133,11 +133,9 @@ Handle<Object> ErrorThrower::Reify() {
constructor = isolate_->wasm_runtime_error_function();
break;
}
Vector<const uint8_t> msg_vec(
reinterpret_cast<const uint8_t*>(error_msg_.data()),
static_cast<int>(error_msg_.size()));
Vector<const char> msg_vec(error_msg_.data(), error_msg_.size());
Handle<String> message =
isolate_->factory()->NewStringFromOneByte(msg_vec).ToHandleChecked();
isolate_->factory()->NewStringFromUtf8(msg_vec).ToHandleChecked();
error_type_ = kNone; // Reset.
Handle<Object> exception =
isolate_->factory()->NewError(constructor, message);
......
......@@ -425,7 +425,11 @@ var failWithMessage;
'invalid use of assertThrows, maybe you want assertThrowsEquals');
}
if (arguments.length >= 3) {
assertEquals(cause_opt, e.message);
if (cause_opt instanceof RegExp) {
assertMatches(cause_opt, e.message, "Error message");
} else {
assertEquals(cause_opt, e.message, "Error message");
}
}
// Success.
return;
......
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
function checkImport(
imported_module_name, imported_function_name) {
var builder = new WasmModuleBuilder();
builder.addImport(imported_module_name, imported_function_name, kSig_i_i);
builder.addFunction('call_imp', kSig_i_i)
.addBody([kExprGetLocal, 0, kExprCallFunction, 0])
.exportFunc();
let imp = i => i + 3;
let instance = builder.instantiate(
{[imported_module_name]: {[imported_function_name]: imp}});
assertEquals(imp(0), instance.exports.call_imp(0));
assertEquals(imp(4), instance.exports.call_imp(4));
}
checkImport('mod', 'foo'); // sanity check
checkImport('mod', '☺☺happy☺☺');
checkImport('☺☺happy☺☺', 'foo');
checkImport('☺☺happy☺☺', '☼+☃=☹');
function checkExports(
internal_name_mul, exported_name_mul, internal_name_add,
exported_name_add) {
var builder = new WasmModuleBuilder();
builder.addFunction(internal_name_mul, kSig_i_ii)
.addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Mul])
.exportAs(exported_name_mul);
builder.addFunction(internal_name_add, kSig_i_ii)
.addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add])
.exportAs(exported_name_add);
let instance = builder.instantiate();
assertEquals(14, instance.exports[exported_name_add](3, 11));
assertEquals(-7, instance.exports[exported_name_add](5, -12));
assertEquals(28, instance.exports[exported_name_mul](4, 7));
assertEquals(-6, instance.exports[exported_name_mul](-3, 2));
}
checkExports('mul', 'mul', 'add', 'add'); // sanity check
checkExports('☺☺mul☺☺', 'mul', '☺☺add☺☺', 'add');
checkExports('☺☺mul☺☺', '☺☺mul☺☺', '☺☺add☺☺', '☺☺add☺☺');
(function errorMessageUnicodeInFuncName() {
var builder = new WasmModuleBuilder();
builder.addFunction('three snowmen: ☃☃☃', kSig_i_v).addBody([]).exportFunc();
assertThrows(
() => builder.instantiate(), WebAssembly.CompileError,
/Compiling wasm function #0:three snowmen: ☃☃☃ failed: /);
})();
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