Index: src/runtime/runtime-wasm.cc |
diff --git a/src/runtime/runtime-wasm.cc b/src/runtime/runtime-wasm.cc |
index e840eb464e9797325d5a89514ff82c3a94b3d3c0..161f7f4d52331fc0a371b20c14593ff773c84f41 100644 |
--- a/src/runtime/runtime-wasm.cc |
+++ b/src/runtime/runtime-wasm.cc |
@@ -15,6 +15,7 @@ |
#include "src/v8memory.h" |
#include "src/wasm/wasm-module.h" |
#include "src/wasm/wasm-objects.h" |
+#include "src/wasm/wasm-opcodes.h" |
namespace v8 { |
namespace internal { |
@@ -61,14 +62,14 @@ 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); |
+Object* ThrowRuntimeError(Isolate* isolate, int message_id, int byte_offset) { |
Handle<Object> error_obj = isolate->factory()->NewWasmRuntimeError( |
static_cast<MessageTemplate::Template>(message_id)); |
+ if (FLAG_wasm_trap_if) { |
+ return isolate->Throw(*error_obj); |
+ } |
+ |
// 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. |
@@ -115,6 +116,26 @@ RUNTIME_FUNCTION(Runtime_ThrowWasmError) { |
return isolate->Throw(*error_obj); |
} |
+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); |
+ return ThrowRuntimeError(isolate, message_id, byte_offset); |
+} |
+ |
+#define DECLARE_ENUM(name) \ |
+ RUNTIME_FUNCTION(Runtime_ThrowWasm##name) { \ |
titzer
2016/12/12 14:21:34
Can you factor the common code out of this macro i
ahaas
2016/12/13 12:38:59
Done.
|
+ HandleScope scope(isolate); \ |
+ int message_id = wasm::WasmOpcodes::TrapReasonToMessageId(wasm::k##name); \ |
+ printf("Throw trap %s\n", \ |
+ wasm::WasmOpcodes::TrapReasonMessage(wasm::k##name)); \ |
+ int byte_offset = 1; \ |
+ return ThrowRuntimeError(isolate, message_id, byte_offset); \ |
+ } |
+FOREACH_WASM_TRAPREASON(DECLARE_ENUM) |
+#undef DECLARE_ENUM |
+ |
RUNTIME_FUNCTION(Runtime_WasmThrowTypeError) { |
HandleScope scope(isolate); |
DCHECK_EQ(0, args.length()); |