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

View File

@ -79,6 +79,23 @@ assertThrows(function() {
}, 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() {
var builder = new WasmModuleBuilder();