[wasm] FromJS throws a TypeError for I64 values.

This behavior is required by the WebAssembly spec.

TEST=mjsunit/wasm/ffi-error.js:I64ParamsInSignatureThrows

R=titzer@chromium.org

Review-Url: https://codereview.chromium.org/2360653002
Cr-Commit-Position: refs/heads/master@{#39600}
This commit is contained in:
ahaas 2016-09-21 08:32:22 -07:00 committed by Commit bot
parent b11a8b4d41
commit 4c1d574b22
2 changed files with 22 additions and 9 deletions

View File

@ -2393,15 +2393,11 @@ Node* WasmGraphBuilder::FromJS(Node* node, Node* context,
break; break;
} }
case wasm::kAstI64: case wasm::kAstI64:
// TODO(titzer): JS->i64 has no good solution right now. Using 32 bits. // Throw a TypeError. The native context is good enough here because we
num = graph()->NewNode(jsgraph()->machine()->TruncateFloat64ToWord32(), // only throw a TypeError.
num); return BuildCallToRuntime(Runtime::kWasmThrowTypeError, jsgraph(),
if (jsgraph()->machine()->Is64()) { jsgraph()->isolate()->native_context(), nullptr,
// We cannot change an int32 to an int64 on a 32 bit platform. Instead 0, effect_, *control_);
// we will split the parameter node later.
num = graph()->NewNode(jsgraph()->machine()->ChangeInt32ToInt64(), num);
}
break;
case wasm::kAstF32: case wasm::kAstF32:
num = graph()->NewNode(jsgraph()->machine()->TruncateFloat64ToFloat32(), num = graph()->NewNode(jsgraph()->machine()->TruncateFloat64ToFloat32(),
num); num);

View File

@ -79,6 +79,23 @@ assertThrows(function() {
}, TypeError); }, TypeError);
})(); })();
(function I64ParamsInSignatureThrows() {
var builder = new WasmModuleBuilder();
builder.addMemory(1, 1, true);
builder.addFunction("function_with_invalid_signature", kSig_i_l)
.addBody([
kExprGetLocal, 0,
kExprI32ConvertI64
])
.exportFunc()
var module = builder.instantiate();
assertThrows(function() {
module.exports.function_with_invalid_signature(33);
}, TypeError);
})();
(function I64JSImportThrows() { (function I64JSImportThrows() {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();