Commit 3a9e4d80 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[asm.js] Cleanup asm.js instantiation API.

This refactors the {AsmJs} methods used for instantiating an asm.js
module to only use one single entry point. It is in preparation to
validate the "memory" argument as well.

R=clemensh@chromium.org
BUG=chromium:715505

Change-Id: I5e26fcf46f98c053080c70b26c0f562afc7f794a
Reviewed-on: https://chromium-review.googlesource.com/488226
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44922}
parent 216e677a
......@@ -63,12 +63,8 @@ Handle<Object> StdlibMathMember(Isolate* isolate, Handle<JSReceiver> stdlib,
}
bool IsStdlibMemberValid(Isolate* isolate, Handle<JSReceiver> stdlib,
Handle<Object> member_id) {
int32_t member_kind;
if (!member_id->ToInt32(&member_kind)) {
UNREACHABLE();
}
switch (static_cast<wasm::AsmTyper::StandardMember>(member_kind)) {
wasm::AsmTyper::StandardMember member) {
switch (member) {
case wasm::AsmTyper::StandardMember::kNone:
case wasm::AsmTyper::StandardMember::kModule:
case wasm::AsmTyper::StandardMember::kStdlib:
......@@ -286,29 +282,30 @@ MaybeHandle<FixedArray> AsmJs::CompileAsmViaWasm(CompilationInfo* info) {
return result;
}
bool AsmJs::IsStdlibValid(Isolate* isolate, Handle<FixedArray> wasm_data,
Handle<JSReceiver> stdlib) {
Handle<FixedArray> uses(FixedArray::cast(wasm_data->get(kWasmDataUsesArray)));
for (int i = 0; i < uses->length(); ++i) {
if (!IsStdlibMemberValid(isolate, stdlib,
uses->GetValueChecked<Object>(isolate, i))) {
return false;
}
}
return true;
}
MaybeHandle<Object> AsmJs::InstantiateAsmWasm(Isolate* isolate,
Handle<FixedArray> wasm_data,
Handle<JSArrayBuffer> memory,
Handle<JSReceiver> foreign) {
Handle<JSReceiver> stdlib,
Handle<JSReceiver> foreign,
Handle<JSArrayBuffer> memory) {
base::ElapsedTimer instantiate_timer;
instantiate_timer.Start();
Handle<FixedArray> stdlib_uses(
FixedArray::cast(wasm_data->get(kWasmDataUsesArray)));
Handle<WasmModuleObject> module(
WasmModuleObject::cast(wasm_data->get(kWasmDataCompiledModule)));
Handle<FixedArray> foreign_globals(
FixedArray::cast(wasm_data->get(kWasmDataForeignGlobals)));
// Check that all used stdlib members are valid.
for (int i = 0; i < stdlib_uses->length(); ++i) {
int member_id = Smi::cast(stdlib_uses->get(i))->value();
wasm::AsmTyper::StandardMember member =
static_cast<wasm::AsmTyper::StandardMember>(member_id);
if (!IsStdlibMemberValid(isolate, stdlib, member)) {
return MaybeHandle<Object>();
}
}
// Create the ffi object for foreign functions {"": foreign}.
Handle<JSObject> ffi_object;
if (!foreign.is_null()) {
......
......@@ -13,18 +13,18 @@ namespace internal {
class CompilationInfo;
class JSArrayBuffer;
// Interface to compile and instantiate for asmjs.
// Interface to compile and instantiate for asm.js modules.
class AsmJs {
public:
static MaybeHandle<FixedArray> CompileAsmViaWasm(CompilationInfo* info);
static bool IsStdlibValid(Isolate* isolate, Handle<FixedArray> wasm_data,
Handle<JSReceiver> stdlib);
static MaybeHandle<Object> InstantiateAsmWasm(Isolate* isolate,
Handle<FixedArray> wasm_data,
Handle<JSArrayBuffer> memory,
Handle<JSReceiver> foreign);
Handle<JSReceiver> stdlib,
Handle<JSReceiver> foreign,
Handle<JSArrayBuffer> memory);
};
} // namespace internal
} // namespace v8
#endif
#endif // V8_ASMJS_ASM_JS_H_
......@@ -85,12 +85,10 @@ RUNTIME_FUNCTION(Runtime_InstantiateAsmJs) {
if (args[3]->IsJSArrayBuffer()) {
memory = args.at<JSArrayBuffer>(3);
}
if (function->shared()->HasAsmWasmData() &&
AsmJs::IsStdlibValid(isolate, handle(function->shared()->asm_wasm_data()),
stdlib)) {
MaybeHandle<Object> result;
result = AsmJs::InstantiateAsmWasm(
isolate, handle(function->shared()->asm_wasm_data()), memory, foreign);
if (function->shared()->HasAsmWasmData()) {
Handle<FixedArray> data(function->shared()->asm_wasm_data());
MaybeHandle<Object> result =
AsmJs::InstantiateAsmWasm(isolate, data, stdlib, foreign, memory);
if (!result.is_null()) {
return *result.ToHandleChecked();
}
......
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