Reviewers: adamk_chromiunm.org, arv,

Message:
PTAL. Sad panda.

Description:
Use C runtime functions for ThrowNewXXError desugarings.

JS runtime function calls cause Hydrogen to bail out.

R=ad...@chromiunm.org,a...@chromium.org

Please review this at https://codereview.chromium.org/1210533003/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+45, -11 lines):
  M src/parser.h
  M src/parser.cc
  M src/runtime/runtime.h
  M src/runtime/runtime-internal.cc


Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 61385929bc5962d2955d32788a117ce2cc88670a..c87dffca8f4d9336de62a7810e30c83e2a4c59ab 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -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);
 }

Index: src/parser.h
diff --git a/src/parser.h b/src/parser.h
index 103bafea3341595f4d08ef58d425567ce037da99..e061ce0f78aff801b5b920204b6f31e0401f0709 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -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);

Index: src/runtime/runtime-internal.cc
diff --git a/src/runtime/runtime-internal.cc b/src/runtime/runtime-internal.cc index 294e4fb138ea92769546a1270931a80d406e5839..becd2f0e4fa7b265278bfc67824e8ed6b863b1ae 100644
--- a/src/runtime/runtime-internal.cc
+++ b/src/runtime/runtime-internal.cc
@@ -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);
Index: src/runtime/runtime.h
diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h
index c9db4e74cf3ebed728a4c0873462c22f5c09829e..2b51e072e74fc0468038403e5e04e7fa73574e93 100644
--- a/src/runtime/runtime.h
+++ b/src/runtime/runtime.h
@@ -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)                \


--
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to