Commit f82b3378 authored by titzer's avatar titzer Committed by Commit bot

[wasm] Fix for 608630: allow proxies as FFI.

R=ahaas@chromium.org,bradnelson@chromium.org
BUG=chromium:608630
LOG=Y

Review-Url: https://codereview.chromium.org/1943313002
Cr-Commit-Position: refs/heads/master@{#36008}
parent 30f6dfb7
......@@ -185,10 +185,10 @@ void InstantiateModuleCommon(const v8::FunctionCallbackInfo<v8::Value>& args,
thrower->Failed("", result);
} else {
// Success. Instantiate the module and return the object.
i::Handle<i::JSObject> ffi = i::Handle<i::JSObject>::null();
i::Handle<i::JSReceiver> ffi = i::Handle<i::JSObject>::null();
if (args.Length() > 1 && args[1]->IsObject()) {
Local<Object> obj = Local<Object>::Cast(args[1]);
ffi = i::Handle<i::JSObject>::cast(v8::Utils::OpenHandle(*obj));
ffi = i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj));
}
i::MaybeHandle<i::JSObject> object =
......
......@@ -353,7 +353,7 @@ static MaybeHandle<JSFunction> ReportFFIError(ErrorThrower& thrower,
}
static MaybeHandle<JSFunction> LookupFunction(
ErrorThrower& thrower, Factory* factory, Handle<JSObject> ffi,
ErrorThrower& thrower, Factory* factory, Handle<JSReceiver> ffi,
uint32_t index, wasm::WasmName module_name, wasm::WasmName function_name) {
if (ffi.is_null()) {
return ReportFFIError(thrower, "FFI is not an object", index, module_name,
......@@ -404,7 +404,7 @@ static MaybeHandle<JSFunction> LookupFunction(
// * installs named properties on the object for exported functions
// * compiles wasm code to machine code
MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
Handle<JSObject> ffi,
Handle<JSReceiver> ffi,
Handle<JSArrayBuffer> memory) {
HistogramTimerScope wasm_instantiate_module_time_scope(
isolate->counters()->wasm_instantiate_module_time());
......
......@@ -221,7 +221,7 @@ struct WasmModule {
}
// Creates a new instantiation of the module in the given isolate.
MaybeHandle<JSObject> Instantiate(Isolate* isolate, Handle<JSObject> ffi,
MaybeHandle<JSObject> Instantiate(Isolate* isolate, Handle<JSReceiver> ffi,
Handle<JSArrayBuffer> memory);
};
......
// Copyright 2016 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.
// Flags: --expose-wasm
var __v_5 = {};
var __v_35 = {};
var __v_44 = {};
var __v_43 = {};
try {
__v_1 = 1;
__v_2 = {
get: function() { return function() {} },
has() { return true },
getOwnPropertyDescriptor: function() {
if (__v_1-- == 0) throw "please die";
return {value: function() {}, configurable: true};
}
};
__v_3 = new Proxy({}, __v_2);
__v_30 = Object.create(__v_35);
with (__v_5) { f() }
} catch(e) { print("Caught: " + e); }
function __f_1(asmfunc, expect) {
var __v_1 = asmfunc.toString();
var __v_2 = __v_1.replace(new RegExp("use asm"), "");
var __v_39 = {Math: Math};
var __v_4 = eval("(" + __v_2 + ")")(__v_3);
print("Testing " + asmfunc.name + " (js)...");
__v_44.valueOf = __v_43;
expect(__v_4);
print("Testing " + asmfunc.name + " (asm.js)...");
var __v_5 = asmfunc(__v_3);
expect(__v_5);
print("Testing " + asmfunc.name + " (wasm)...");
var __v_6 = Wasm.instantiateModuleFromAsm(__v_1, __v_3);
expect(__v_6);
}
function __f_2() {
"use asm";
function __f_3() { return 0; }
function __f_4() { return 1; }
function __f_5() { return 4; }
function __f_6() { return 64; }
function __f_7() { return 137; }
function __f_8() { return 128; }
function __f_9() { return -1; }
function __f_10() { return 1000; }
function __f_11() { return 2000000; }
function __f_12() { return 2147483647; }
return {__f_3: __f_3, __f_4: __f_4, __f_5: __f_5, __f_6: __f_6, __f_7: __f_7, __f_8: __f_8,
__f_9: __f_9, __f_10: __f_10, __f_11, __f_12: __f_12};
}
try {
__f_1(__f_2, function(module) {
assertEquals(0, module.__f_3());
assertEquals(1, module.__f_4());
assertEquals(4, module.__f_5());
assertEquals(64, module.__f_6());
assertEquals(128, module.__f_8());
assertEquals(-1, module.__f_9());
assertEquals(1000, module.__f_10());
assertEquals(2000000, module.__f_11());
assertEquals(2147483647, module.__f_12());
});
} catch(e) { print("Caught: " + e); }
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