[wasm] Move ScheduledErrorThrower to wasm-api.h

The ScheduledErrorThrower is also needed in the wasm-async fuzzer so I
moved the implementation from wasm-js.cc to wasm-api.[h|cc].

R=clemensh@chromium.org

Bug: chromium:749838
Change-Id: I49d7438d1ec0281285ce0c64ba462c22001be08e
Reviewed-on: https://chromium-review.googlesource.com/591447
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47112}
This commit is contained in:
Andreas Haas 2017-08-02 14:48:04 +02:00 committed by Commit Bot
parent 808e90a9ea
commit 859ee8443d
7 changed files with 98 additions and 48 deletions

View File

@ -1997,6 +1997,8 @@ v8_source_set("v8_base") {
"src/wasm/signature-map.h",
"src/wasm/streaming-decoder.cc",
"src/wasm/streaming-decoder.h",
"src/wasm/wasm-api.cc",
"src/wasm/wasm-api.h",
"src/wasm/wasm-code-specialization.cc",
"src/wasm/wasm-code-specialization.h",
"src/wasm/wasm-debug.cc",

View File

@ -1440,6 +1440,8 @@
'wasm/signature-map.h',
'wasm/streaming-decoder.cc',
'wasm/streaming-decoder.h',
'wasm/wasm-api.cc',
'wasm/wasm-api.h',
'wasm/wasm-code-specialization.h',
'wasm/wasm-code-specialization.cc',
'wasm/wasm-debug.cc',

31
src/wasm/wasm-api.cc Normal file
View File

@ -0,0 +1,31 @@
// 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.
#include "src/wasm/wasm-api.h"
#include "src/isolate-inl.h"
#include "src/isolate.h"
namespace v8 {
namespace internal {
namespace wasm {
ScheduledErrorThrower::~ScheduledErrorThrower() {
// There should never be both a pending and a scheduled exception.
DCHECK(!isolate()->has_scheduled_exception() ||
!isolate()->has_pending_exception());
// Don't throw another error if there is already a scheduled error.
if (isolate()->has_scheduled_exception()) {
Reset();
} else if (isolate()->has_pending_exception()) {
Reset();
isolate()->OptionalRescheduleException(false);
} else if (error()) {
isolate()->ScheduleThrow(*Reify());
}
}
} // namespace wasm
} // namespace internal
} // namespace v8

35
src/wasm/wasm-api.h Normal file
View File

@ -0,0 +1,35 @@
// 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.
#ifndef V8_WASM_API_H_
#define V8_WASM_API_H_
#include "src/wasm/wasm-result.h"
namespace v8 {
namespace internal {
namespace wasm {
// Like an ErrorThrower, but turns all pending exceptions into scheduled
// exceptions when going out of scope. Use this in API methods.
// Note that pending exceptions are not necessarily created by the ErrorThrower,
// but e.g. by the wasm start function. There might also be a scheduled
// exception, created by another API call (e.g. v8::Object::Get). But there
// should never be both pending and scheduled exceptions.
class V8_EXPORT_PRIVATE ScheduledErrorThrower : public ErrorThrower {
public:
ScheduledErrorThrower(v8::Isolate* isolate, const char* context)
: ScheduledErrorThrower(reinterpret_cast<Isolate*>(isolate), context) {}
ScheduledErrorThrower(Isolate* isolate, const char* context)
: ErrorThrower(isolate, context) {}
~ScheduledErrorThrower();
};
} // namespace wasm
} // namespace internal
} // namespace v8
#endif // V8_WASM_API_H_

View File

@ -15,6 +15,7 @@
#include "src/parsing/parse-info.h"
#include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-api.h"
#include "src/wasm/wasm-js.h"
#include "src/wasm/wasm-limits.h"
#include "src/wasm/wasm-module.h"
@ -40,35 +41,6 @@ namespace {
} \
} while (false)
// Like an ErrorThrower, but turns all pending exceptions into scheduled
// exceptions when going out of scope. Use this in API methods.
// Note that pending exceptions are not necessarily created by the ErrorThrower,
// but e.g. by the wasm start function. There might also be a scheduled
// exception, created by another API call (e.g. v8::Object::Get). But there
// should never be both pending and scheduled exceptions.
class ScheduledErrorThrower : public ErrorThrower {
public:
ScheduledErrorThrower(v8::Isolate* isolate, const char* context)
: ScheduledErrorThrower(reinterpret_cast<i::Isolate*>(isolate), context) {
}
ScheduledErrorThrower(i::Isolate* isolate, const char* context)
: ErrorThrower(isolate, context) {}
~ScheduledErrorThrower() {
// There should never be both a pending and a scheduled exception.
DCHECK(!isolate()->has_scheduled_exception() ||
!isolate()->has_pending_exception());
// Don't throw another error if there is already a scheduled error.
if (isolate()->has_scheduled_exception()) {
Reset();
} else if (isolate()->has_pending_exception()) {
Reset();
isolate()->OptionalRescheduleException(false);
} else if (error()) {
isolate()->ScheduleThrow(*Reify());
}
}
};
i::Handle<i::String> v8_str(i::Isolate* isolate, const char* str) {
return isolate->factory()->NewStringFromAsciiChecked(str);
}
@ -164,7 +136,7 @@ void WebAssemblyCompile(const v8::FunctionCallbackInfo<v8::Value>& args) {
MicrotasksScope runs_microtasks(isolate, MicrotasksScope::kRunMicrotasks);
HandleScope scope(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.compile()");
i::wasm::ScheduledErrorThrower thrower(i_isolate, "WebAssembly.compile()");
Local<Context> context = isolate->GetCurrentContext();
ASSIGN(Promise::Resolver, resolver, Promise::Resolver::New(context));
@ -187,7 +159,7 @@ void WebAssemblyValidate(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
HandleScope scope(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.validate()");
i::wasm::ScheduledErrorThrower thrower(i_isolate, "WebAssembly.validate()");
auto bytes = GetFirstArgumentAsBytes(args, &thrower);
@ -208,7 +180,7 @@ void WebAssemblyModule(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (i_isolate->wasm_module_callback()(args)) return;
HandleScope scope(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Module()");
i::wasm::ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Module()");
auto bytes = GetFirstArgumentAsBytes(args, &thrower);
@ -228,7 +200,8 @@ void WebAssemblyModuleImports(const v8::FunctionCallbackInfo<v8::Value>& args) {
HandleScope scope(args.GetIsolate());
v8::Isolate* isolate = args.GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Module.imports()");
i::wasm::ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Module.imports()");
auto maybe_module = GetFirstArgumentAsModule(args, &thrower);
if (thrower.error()) return;
@ -241,7 +214,8 @@ void WebAssemblyModuleExports(const v8::FunctionCallbackInfo<v8::Value>& args) {
HandleScope scope(args.GetIsolate());
v8::Isolate* isolate = args.GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Module.exports()");
i::wasm::ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Module.exports()");
auto maybe_module = GetFirstArgumentAsModule(args, &thrower);
if (thrower.error()) return;
@ -255,7 +229,7 @@ void WebAssemblyModuleCustomSections(
HandleScope scope(args.GetIsolate());
v8::Isolate* isolate = args.GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ScheduledErrorThrower thrower(i_isolate,
i::wasm::ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Module.customSections()");
auto maybe_module = GetFirstArgumentAsModule(args, &thrower);
@ -286,7 +260,8 @@ MaybeLocal<Value> WebAssemblyInstantiateImpl(Isolate* isolate,
i::MaybeHandle<i::Object> instance_object;
{
ScheduledErrorThrower thrower(i_isolate, "WebAssembly Instantiation");
i::wasm::ScheduledErrorThrower thrower(i_isolate,
"WebAssembly Instantiation");
i::MaybeHandle<i::JSReceiver> maybe_imports =
GetValueAsImports(ffi, &thrower);
if (thrower.error()) return {};
@ -366,7 +341,7 @@ void WebAssemblyInstance(const v8::FunctionCallbackInfo<v8::Value>& args) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
if (i_isolate->wasm_instance_callback()(args)) return;
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Instance()");
i::wasm::ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Instance()");
GetFirstArgumentAsModule(args, &thrower);
if (thrower.error()) return;
@ -416,7 +391,8 @@ void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
MicrotasksScope runs_microtasks(isolate, MicrotasksScope::kRunMicrotasks);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.instantiate()");
i::wasm::ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.instantiate()");
HandleScope scope(isolate);
@ -502,7 +478,7 @@ void WebAssemblyTable(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
HandleScope scope(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Module()");
i::wasm::ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Module()");
if (args.Length() < 1 || !args[0]->IsObject()) {
thrower.TypeError("Argument 0 must be a table descriptor");
return;
@ -555,7 +531,7 @@ void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
HandleScope scope(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Memory()");
i::wasm::ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Memory()");
if (args.Length() < 1 || !args[0]->IsObject()) {
thrower.TypeError("Argument 0 must be a memory descriptor");
return;
@ -644,7 +620,8 @@ void WebAssemblyTableGetLength(
v8::Isolate* isolate = args.GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
HandleScope scope(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Table.length()");
i::wasm::ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Table.length()");
EXTRACT_THIS(receiver, WasmTableObject);
args.GetReturnValue().Set(
v8::Number::New(isolate, receiver->current_length()));
@ -655,7 +632,7 @@ void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
HandleScope scope(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Table.grow()");
i::wasm::ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Table.grow()");
Local<Context> context = isolate->GetCurrentContext();
EXTRACT_THIS(receiver, WasmTableObject);
@ -700,7 +677,7 @@ void WebAssemblyTableGet(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
HandleScope scope(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Table.get()");
i::wasm::ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Table.get()");
Local<Context> context = isolate->GetCurrentContext();
EXTRACT_THIS(receiver, WasmTableObject);
i::Handle<i::FixedArray> array(receiver->functions(), i_isolate);
@ -721,7 +698,7 @@ void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
HandleScope scope(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Table.set()");
i::wasm::ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Table.set()");
Local<Context> context = isolate->GetCurrentContext();
EXTRACT_THIS(receiver, WasmTableObject);
@ -755,7 +732,8 @@ void WebAssemblyMemoryGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
HandleScope scope(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Memory.grow()");
i::wasm::ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Memory.grow()");
Local<Context> context = isolate->GetCurrentContext();
EXTRACT_THIS(receiver, WasmMemoryObject);
@ -798,7 +776,8 @@ void WebAssemblyMemoryGetBuffer(
v8::Isolate* isolate = args.GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
HandleScope scope(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Memory.buffer");
i::wasm::ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.Memory.buffer");
EXTRACT_THIS(receiver, WasmMemoryObject);
i::Handle<i::Object> buffer_obj(receiver->array_buffer(), i_isolate);

View File

@ -12,6 +12,7 @@
#include "src/isolate.h"
#include "src/objects-inl.h"
#include "src/objects.h"
#include "src/wasm/wasm-api.h"
#include "src/wasm/wasm-module.h"
#include "test/common/wasm/flag-utils.h"
#include "test/common/wasm/wasm-module-runner.h"
@ -59,7 +60,7 @@ void InstantiateCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ErrorThrower thrower(i_isolate, "WebAssembly Instantiation");
ScheduledErrorThrower thrower(i_isolate, "WebAssembly Instantiation");
i::Handle<i::WasmModuleObject> module_obj = ToWasmModuleObjectUnchecked(
v8::Utils::OpenHandle(v8::Object::Cast(*module)));

Binary file not shown.