Commit c09268f2 authored by dslomov's avatar dslomov Committed by Commit bot

Use C runtime functions for ThrowNewXXError desugarings.

JS runtime function calls cause Hydrogen to bail out.

R=adamk@chromiunm.org,arv@chromium.org

Review URL: https://codereview.chromium.org/1210533003

Cr-Commit-Position: refs/heads/master@{#29260}
parent 3c5f0db3
......@@ -645,36 +645,34 @@ Expression* ParserTraits::BuildUnaryExpression(Expression* expression,
Expression* ParserTraits::NewThrowReferenceError(
MessageTemplate::Template message, int pos) {
return NewThrowError(
parser_->ast_value_factory()->make_reference_error_string(), message,
parser_->ast_value_factory()->empty_string(), pos);
return NewThrowError(Runtime::kNewReferenceError, message,
parser_->ast_value_factory()->empty_string(), pos);
}
Expression* ParserTraits::NewThrowSyntaxError(MessageTemplate::Template message,
const AstRawString* arg,
int pos) {
return NewThrowError(parser_->ast_value_factory()->make_syntax_error_string(),
message, arg, pos);
return NewThrowError(Runtime::kNewSyntaxError, message, arg, pos);
}
Expression* ParserTraits::NewThrowTypeError(MessageTemplate::Template message,
const AstRawString* arg, int pos) {
return NewThrowError(parser_->ast_value_factory()->make_type_error_string(),
message, arg, pos);
return NewThrowError(Runtime::kNewTypeError, message, arg, pos);
}
Expression* ParserTraits::NewThrowError(const AstRawString* constructor,
Expression* ParserTraits::NewThrowError(Runtime::FunctionId id,
MessageTemplate::Template message,
const AstRawString* arg, int pos) {
Zone* zone = parser_->zone();
ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(2, zone);
args->Add(parser_->factory()->NewSmiLiteral(message, pos), zone);
args->Add(parser_->factory()->NewStringLiteral(arg, pos), zone);
CallRuntime* call_constructor =
parser_->factory()->NewCallRuntime(constructor, NULL, args, pos);
CallRuntime* call_constructor = parser_->factory()->NewCallRuntime(
parser_->ast_value_factory()->empty_string(), Runtime::FunctionForId(id),
args, pos);
return parser_->factory()->NewThrow(call_constructor, pos);
}
......
......@@ -697,7 +697,7 @@ class ParserTraits {
const AstRawString* arg, int pos);
// Generic AST generator for throwing errors from compiled code.
Expression* NewThrowError(const AstRawString* constructor,
Expression* NewThrowError(Runtime::FunctionId function_id,
MessageTemplate::Template message,
const AstRawString* arg, int pos);
......
......@@ -60,6 +60,39 @@ RUNTIME_FUNCTION(Runtime_ThrowReferenceError) {
}
RUNTIME_FUNCTION(Runtime_NewTypeError) {
HandleScope scope(isolate);
DCHECK(args.length() == 2);
CONVERT_INT32_ARG_CHECKED(template_index, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1);
auto message_template =
static_cast<MessageTemplate::Template>(template_index);
return *isolate->factory()->NewTypeError(message_template, arg0);
}
RUNTIME_FUNCTION(Runtime_NewReferenceError) {
HandleScope scope(isolate);
DCHECK(args.length() == 2);
CONVERT_INT32_ARG_CHECKED(template_index, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1);
auto message_template =
static_cast<MessageTemplate::Template>(template_index);
return *isolate->factory()->NewReferenceError(message_template, arg0);
}
RUNTIME_FUNCTION(Runtime_NewSyntaxError) {
HandleScope scope(isolate);
DCHECK(args.length() == 2);
CONVERT_INT32_ARG_CHECKED(template_index, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1);
auto message_template =
static_cast<MessageTemplate::Template>(template_index);
return *isolate->factory()->NewSyntaxError(message_template, arg0);
}
RUNTIME_FUNCTION(Runtime_ThrowIteratorResultNotAnObject) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
......
......@@ -296,6 +296,9 @@ namespace internal {
F(UnwindAndFindExceptionHandler, 0, 1) \
F(PromoteScheduledException, 0, 1) \
F(ThrowReferenceError, 1, 1) \
F(NewTypeError, 2, 1) \
F(NewSyntaxError, 2, 1) \
F(NewReferenceError, 2, 1) \
F(ThrowIteratorResultNotAnObject, 1, 1) \
F(PromiseRejectEvent, 3, 1) \
F(PromiseRevokeReject, 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