Commit 4d75ea60 authored by ahaas's avatar ahaas Committed by Commit bot

[wasm] Move wasm runtime functions to runtime-wasm.cc

I removed {IsWasmInstance} because it is not used anywhere, and I moved
ThrowWasmError to runtime-wasm.cc

R=titzer@chromium.org

Review-Url: https://codereview.chromium.org/2541633003
Cr-Commit-Position: refs/heads/master@{#41382}
parent a0c51862
......@@ -117,60 +117,6 @@ RUNTIME_FUNCTION(Runtime_ThrowTypeError) {
NewTypeError(message_id, arg0, arg1, arg2));
}
RUNTIME_FUNCTION(Runtime_ThrowWasmError) {
HandleScope scope(isolate);
DCHECK_EQ(2, args.length());
CONVERT_SMI_ARG_CHECKED(message_id, 0);
CONVERT_SMI_ARG_CHECKED(byte_offset, 1);
Handle<Object> error_obj = isolate->factory()->NewWasmRuntimeError(
static_cast<MessageTemplate::Template>(message_id));
// For wasm traps, the byte offset (a.k.a source position) can not be
// determined from relocation info, since the explicit checks for traps
// converge in one singe block which calls this runtime function.
// We hence pass the byte offset explicitely, and patch it into the top-most
// frame (a wasm frame) on the collected stack trace.
// TODO(wasm): This implementation is temporary, see bug #5007:
// https://bugs.chromium.org/p/v8/issues/detail?id=5007
Handle<JSObject> error = Handle<JSObject>::cast(error_obj);
Handle<Object> stack_trace_obj = JSReceiver::GetDataProperty(
error, isolate->factory()->stack_trace_symbol());
// Patch the stack trace (array of <receiver, function, code, position>).
if (stack_trace_obj->IsJSArray()) {
Handle<FrameArray> stack_elements(
FrameArray::cast(JSArray::cast(*stack_trace_obj)->elements()));
DCHECK(stack_elements->Code(0)->kind() == AbstractCode::WASM_FUNCTION);
DCHECK(stack_elements->Offset(0)->value() >= 0);
stack_elements->SetOffset(0, Smi::FromInt(-1 - byte_offset));
}
// Patch the detailed stack trace (array of JSObjects with various
// properties).
Handle<Object> detailed_stack_trace_obj = JSReceiver::GetDataProperty(
error, isolate->factory()->detailed_stack_trace_symbol());
if (detailed_stack_trace_obj->IsJSArray()) {
Handle<FixedArray> stack_elements(
FixedArray::cast(JSArray::cast(*detailed_stack_trace_obj)->elements()));
DCHECK_GE(stack_elements->length(), 1);
Handle<JSObject> top_frame(JSObject::cast(stack_elements->get(0)));
Handle<String> wasm_offset_key =
isolate->factory()->InternalizeOneByteString(
STATIC_CHAR_VECTOR("column"));
LookupIterator it(top_frame, wasm_offset_key, top_frame,
LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
if (it.IsFound()) {
DCHECK(JSReceiver::GetDataProperty(&it)->IsSmi());
// Make column number 1-based here.
Maybe<bool> data_set = JSReceiver::SetDataProperty(
&it, handle(Smi::FromInt(byte_offset + 1), isolate));
DCHECK(data_set.IsJust() && data_set.FromJust() == true);
USE(data_set);
}
}
return isolate->Throw(*error_obj);
}
RUNTIME_FUNCTION(Runtime_UnwindAndFindExceptionHandler) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 0);
......@@ -522,15 +468,6 @@ RUNTIME_FUNCTION(Runtime_OrdinaryHasInstance) {
isolate, Object::OrdinaryHasInstance(isolate, callable, object));
}
RUNTIME_FUNCTION(Runtime_IsWasmInstance) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
CONVERT_ARG_CHECKED(Object, object, 0);
bool is_wasm_instance =
object->IsJSObject() && wasm::IsWasmInstance(JSObject::cast(object));
return *isolate->factory()->ToBoolean(is_wasm_instance);
}
RUNTIME_FUNCTION(Runtime_Typeof) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
......
......@@ -61,6 +61,60 @@ RUNTIME_FUNCTION(Runtime_WasmGrowMemory) {
wasm::GrowMemory(isolate, instance, delta_pages));
}
RUNTIME_FUNCTION(Runtime_ThrowWasmError) {
HandleScope scope(isolate);
DCHECK_EQ(2, args.length());
CONVERT_SMI_ARG_CHECKED(message_id, 0);
CONVERT_SMI_ARG_CHECKED(byte_offset, 1);
Handle<Object> error_obj = isolate->factory()->NewWasmRuntimeError(
static_cast<MessageTemplate::Template>(message_id));
// For wasm traps, the byte offset (a.k.a source position) can not be
// determined from relocation info, since the explicit checks for traps
// converge in one singe block which calls this runtime function.
// We hence pass the byte offset explicitely, and patch it into the top-most
// frame (a wasm frame) on the collected stack trace.
// TODO(wasm): This implementation is temporary, see bug #5007:
// https://bugs.chromium.org/p/v8/issues/detail?id=5007
Handle<JSObject> error = Handle<JSObject>::cast(error_obj);
Handle<Object> stack_trace_obj = JSReceiver::GetDataProperty(
error, isolate->factory()->stack_trace_symbol());
// Patch the stack trace (array of <receiver, function, code, position>).
if (stack_trace_obj->IsJSArray()) {
Handle<FrameArray> stack_elements(
FrameArray::cast(JSArray::cast(*stack_trace_obj)->elements()));
DCHECK(stack_elements->Code(0)->kind() == AbstractCode::WASM_FUNCTION);
DCHECK(stack_elements->Offset(0)->value() >= 0);
stack_elements->SetOffset(0, Smi::FromInt(-1 - byte_offset));
}
// Patch the detailed stack trace (array of JSObjects with various
// properties).
Handle<Object> detailed_stack_trace_obj = JSReceiver::GetDataProperty(
error, isolate->factory()->detailed_stack_trace_symbol());
if (detailed_stack_trace_obj->IsJSArray()) {
Handle<FixedArray> stack_elements(
FixedArray::cast(JSArray::cast(*detailed_stack_trace_obj)->elements()));
DCHECK_GE(stack_elements->length(), 1);
Handle<JSObject> top_frame(JSObject::cast(stack_elements->get(0)));
Handle<String> wasm_offset_key =
isolate->factory()->InternalizeOneByteString(
STATIC_CHAR_VECTOR("column"));
LookupIterator it(top_frame, wasm_offset_key, top_frame,
LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
if (it.IsFound()) {
DCHECK(JSReceiver::GetDataProperty(&it)->IsSmi());
// Make column number 1-based here.
Maybe<bool> data_set = JSReceiver::SetDataProperty(
&it, handle(Smi::FromInt(byte_offset + 1), isolate));
DCHECK(data_set.IsJust() && data_set.FromJust() == true);
USE(data_set);
}
}
return isolate->Throw(*error_obj);
}
RUNTIME_FUNCTION(Runtime_WasmThrowTypeError) {
HandleScope scope(isolate);
DCHECK_EQ(0, args.length());
......
......@@ -298,7 +298,6 @@ namespace internal {
F(InstallToContext, 1, 1) \
F(Interrupt, 0, 1) \
F(IS_VAR, 1, 1) \
F(IsWasmInstance, 1, 1) \
F(NewReferenceError, 2, 1) \
F(NewSyntaxError, 2, 1) \
F(NewTypeError, 2, 1) \
......@@ -327,7 +326,6 @@ namespace internal {
F(ThrowReferenceError, 1, 1) \
F(ThrowStackOverflow, 0, 1) \
F(ThrowTypeError, -1 /* >= 1 */, 1) \
F(ThrowWasmError, 2, 1) \
F(ThrowUndefinedOrNullToObject, 1, 1) \
F(Typeof, 1, 1) \
F(UnwindAndFindExceptionHandler, 0, 1)
......@@ -920,6 +918,7 @@ namespace internal {
#define FOR_EACH_INTRINSIC_WASM(F) \
F(WasmGrowMemory, 1, 1) \
F(WasmMemorySize, 0, 1) \
F(ThrowWasmError, 2, 1) \
F(WasmThrowTypeError, 0, 1) \
F(WasmThrow, 2, 1) \
F(WasmGetCaughtExceptionValue, 1, 1)
......
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