[wasm] Throw real Error on wasm trap
Before, just a string was thrown, so no stack trace was attached there. Generated code from wasm does not grow by this change, we just pass a message id to the respective (new) runtime function. R=mstarzinger@chromium.org, titzer@chromium.org BUG= Review URL: https://codereview.chromium.org/1874383002 Cr-Commit-Position: refs/heads/master@{#35664}
This commit is contained in:
parent
965e6bdc0a
commit
b1434ac460
@ -193,12 +193,13 @@ class WasmTrapHelper : public ZoneObject {
|
||||
}
|
||||
|
||||
void BuildTrapCode(wasm::TrapReason reason) {
|
||||
Node* exception =
|
||||
builder_->String(wasm::WasmOpcodes::TrapReasonMessage(reason));
|
||||
Node* message_id = builder_->NumberConstant(
|
||||
wasm::WasmOpcodes::TrapReasonToMessageId(reason));
|
||||
Node* end;
|
||||
Node** control_ptr = builder_->control_;
|
||||
Node** effect_ptr = builder_->effect_;
|
||||
wasm::ModuleEnv* module = builder_->module_;
|
||||
DCHECK(traps_[reason] == NULL);
|
||||
*control_ptr = traps_[reason] =
|
||||
graph()->NewNode(common()->Merge(1), *control_ptr);
|
||||
*effect_ptr = effects_[reason] =
|
||||
@ -206,14 +207,14 @@ class WasmTrapHelper : public ZoneObject {
|
||||
|
||||
if (module && !module->instance->context.is_null()) {
|
||||
// Use the module context to call the runtime to throw an exception.
|
||||
Runtime::FunctionId f = Runtime::kThrow;
|
||||
Runtime::FunctionId f = Runtime::kThrowWasmError;
|
||||
const Runtime::Function* fun = Runtime::FunctionForId(f);
|
||||
CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
|
||||
jsgraph()->zone(), f, fun->nargs, Operator::kNoProperties,
|
||||
CallDescriptor::kNoFlags);
|
||||
Node* inputs[] = {
|
||||
jsgraph()->CEntryStubConstant(fun->result_size), // C entry
|
||||
exception, // exception
|
||||
message_id, // message id
|
||||
jsgraph()->ExternalConstant(
|
||||
ExternalReference(f, jsgraph()->isolate())), // ref
|
||||
jsgraph()->Int32Constant(fun->nargs), // arity
|
||||
@ -344,6 +345,9 @@ Node* WasmGraphBuilder::EffectPhi(unsigned count, Node** effects,
|
||||
buf);
|
||||
}
|
||||
|
||||
Node* WasmGraphBuilder::NumberConstant(int32_t value) {
|
||||
return jsgraph()->Constant(value);
|
||||
}
|
||||
|
||||
Node* WasmGraphBuilder::Int32Constant(int32_t value) {
|
||||
return jsgraph()->Int32Constant(value);
|
||||
|
@ -79,6 +79,7 @@ class WasmGraphBuilder {
|
||||
Node* Merge(unsigned count, Node** controls);
|
||||
Node* Phi(wasm::LocalType type, unsigned count, Node** vals, Node* control);
|
||||
Node* EffectPhi(unsigned count, Node** effects, Node* control);
|
||||
Node* NumberConstant(int32_t value);
|
||||
Node* Int32Constant(int32_t value);
|
||||
Node* Int64Constant(int64_t value);
|
||||
Node* Float32Constant(float value);
|
||||
|
@ -96,6 +96,13 @@ RUNTIME_FUNCTION(Runtime_ThrowStackOverflow) {
|
||||
return isolate->StackOverflow();
|
||||
}
|
||||
|
||||
RUNTIME_FUNCTION(Runtime_ThrowWasmError) {
|
||||
HandleScope scope(isolate);
|
||||
DCHECK_EQ(1, args.length());
|
||||
CONVERT_SMI_ARG_CHECKED(message_id, 0);
|
||||
THROW_NEW_ERROR_RETURN_FAILURE(
|
||||
isolate, NewError(static_cast<MessageTemplate::Template>(message_id)));
|
||||
}
|
||||
|
||||
RUNTIME_FUNCTION(Runtime_UnwindAndFindExceptionHandler) {
|
||||
SealHandleScope shs(isolate);
|
||||
|
@ -290,6 +290,7 @@ namespace internal {
|
||||
F(ThrowIteratorResultNotAnObject, 1, 1) \
|
||||
F(ThrowGeneratorRunning, 0, 1) \
|
||||
F(ThrowStackOverflow, 0, 1) \
|
||||
F(ThrowWasmError, 1, 1) \
|
||||
F(PromiseRejectEvent, 3, 1) \
|
||||
F(PromiseRevokeReject, 1, 1) \
|
||||
F(StackGuard, 0, 1) \
|
||||
|
@ -23,4 +23,4 @@ try {
|
||||
print("correctly caught: " + e);
|
||||
exception = e;
|
||||
}
|
||||
assertEquals("unreachable", exception);
|
||||
assertEquals("unreachable", exception.message);
|
||||
|
@ -290,8 +290,8 @@ function assertTraps(trap, code) {
|
||||
}
|
||||
threwException = false;
|
||||
} catch (e) {
|
||||
assertEquals("string", typeof e);
|
||||
assertEquals(kTrapMsgs[trap], e);
|
||||
assertEquals("object", typeof e);
|
||||
assertEquals(kTrapMsgs[trap], e.message);
|
||||
// Success.
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user