Index: src/factory.cc |
diff --git a/src/factory.cc b/src/factory.cc |
index a33f288ccbe7dfd2457f4350e2815930c5784a0e..57e5da77bd2b500b272ad18fb53ba196d9468026 100644 |
--- a/src/factory.cc |
+++ b/src/factory.cc |
@@ -1080,6 +1080,13 @@ Handle<Object> Factory::NewTypeError(const char* message, |
} |
+Handle<Object> Factory::NewTypeError(MessageTemplate::Template template_index, |
+ Handle<Object> arg0, Handle<Object> arg1, |
+ Handle<Object> arg2) { |
+ return NewError("MakeTypeError2", template_index, arg0, arg1, arg2); |
+} |
+ |
+ |
Handle<Object> Factory::NewTypeError(Handle<String> message) { |
return NewError("$TypeError", message); |
} |
@@ -1138,6 +1145,39 @@ Handle<Object> Factory::NewError(const char* maker, const char* message, |
} |
+Handle<Object> Factory::NewError(const char* maker, |
+ MessageTemplate::Template template_index, |
+ Handle<Object> arg0, Handle<Object> arg1, |
+ Handle<Object> arg2) { |
+ HandleScope scope(isolate()); |
+ Handle<String> error_maker = InternalizeUtf8String(maker); |
+ Handle<Object> fun_obj = Object::GetProperty(isolate()->js_builtins_object(), |
+ error_maker).ToHandleChecked(); |
+ |
+ Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); |
+ Handle<Object> message_type(Smi::FromInt(template_index), isolate()); |
+ if (arg0.is_null()) arg0 = undefined_value(); |
+ if (arg1.is_null()) arg1 = undefined_value(); |
+ if (arg2.is_null()) arg2 = undefined_value(); |
+ Handle<Object> argv[] = {message_type, arg0, arg1, arg2}; |
+ |
+ // Invoke the JavaScript factory method. If an exception is thrown while |
+ // running the factory method, use the exception as the result. |
+ Handle<Object> result; |
+ MaybeHandle<Object> exception; |
+ if (!Execution::TryCall(fun, isolate()->js_builtins_object(), arraysize(argv), |
+ argv, &exception).ToHandle(&result)) { |
+ Handle<Object> exception_obj; |
+ if (exception.ToHandle(&exception_obj)) { |
+ result = exception_obj; |
+ } else { |
+ result = undefined_value(); |
+ } |
+ } |
+ return scope.CloseAndEscape(result); |
+} |
+ |
+ |
Handle<Object> Factory::NewEvalError(const char* message, |
Vector<Handle<Object> > args) { |
return NewError("MakeEvalError", message, args); |