Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: src/factory.cc

Issue 1087633005: Start migrating error message templates to the runtime. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix windows build Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/factory.h ('k') | src/messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/factory.h" 5 #include "src/factory.h"
6 6
7 #include "src/allocation-site-scopes.h" 7 #include "src/allocation-site-scopes.h"
8 #include "src/base/bits.h" 8 #include "src/base/bits.h"
9 #include "src/bootstrapper.h" 9 #include "src/bootstrapper.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 HeapNumber); 1073 HeapNumber);
1074 } 1074 }
1075 1075
1076 1076
1077 Handle<Object> Factory::NewTypeError(const char* message, 1077 Handle<Object> Factory::NewTypeError(const char* message,
1078 Vector<Handle<Object> > args) { 1078 Vector<Handle<Object> > args) {
1079 return NewError("MakeTypeError", message, args); 1079 return NewError("MakeTypeError", message, args);
1080 } 1080 }
1081 1081
1082 1082
1083 Handle<Object> Factory::NewTypeError(MessageTemplate::Template template_index,
1084 Handle<Object> arg0, Handle<Object> arg1,
1085 Handle<Object> arg2) {
1086 return NewError("MakeTypeError2", template_index, arg0, arg1, arg2);
1087 }
1088
1089
1083 Handle<Object> Factory::NewTypeError(Handle<String> message) { 1090 Handle<Object> Factory::NewTypeError(Handle<String> message) {
1084 return NewError("$TypeError", message); 1091 return NewError("$TypeError", message);
1085 } 1092 }
1086 1093
1087 1094
1088 Handle<Object> Factory::NewRangeError(const char* message, 1095 Handle<Object> Factory::NewRangeError(const char* message,
1089 Vector<Handle<Object> > args) { 1096 Vector<Handle<Object> > args) {
1090 return NewError("MakeRangeError", message, args); 1097 return NewError("MakeRangeError", message, args);
1091 } 1098 }
1092 1099
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 Handle<FixedArray> array = NewFixedArray(args.length()); 1138 Handle<FixedArray> array = NewFixedArray(args.length());
1132 for (int i = 0; i < args.length(); i++) { 1139 for (int i = 0; i < args.length(); i++) {
1133 array->set(i, *args[i]); 1140 array->set(i, *args[i]);
1134 } 1141 }
1135 Handle<JSArray> object = NewJSArrayWithElements(array); 1142 Handle<JSArray> object = NewJSArrayWithElements(array);
1136 Handle<Object> result = NewError(maker, message, object); 1143 Handle<Object> result = NewError(maker, message, object);
1137 return result.EscapeFrom(&scope); 1144 return result.EscapeFrom(&scope);
1138 } 1145 }
1139 1146
1140 1147
1148 Handle<Object> Factory::NewError(const char* maker,
1149 MessageTemplate::Template template_index,
1150 Handle<Object> arg0, Handle<Object> arg1,
1151 Handle<Object> arg2) {
1152 HandleScope scope(isolate());
1153 Handle<String> error_maker = InternalizeUtf8String(maker);
1154 Handle<Object> fun_obj = Object::GetProperty(isolate()->js_builtins_object(),
1155 error_maker).ToHandleChecked();
1156
1157 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj);
1158 Handle<Object> message_type(Smi::FromInt(template_index), isolate());
1159 if (arg0.is_null()) arg0 = undefined_value();
1160 if (arg1.is_null()) arg1 = undefined_value();
1161 if (arg2.is_null()) arg2 = undefined_value();
1162 Handle<Object> argv[] = {message_type, arg0, arg1, arg2};
1163
1164 // Invoke the JavaScript factory method. If an exception is thrown while
1165 // running the factory method, use the exception as the result.
1166 Handle<Object> result;
1167 MaybeHandle<Object> exception;
1168 if (!Execution::TryCall(fun, isolate()->js_builtins_object(), arraysize(argv),
1169 argv, &exception).ToHandle(&result)) {
1170 Handle<Object> exception_obj;
1171 if (exception.ToHandle(&exception_obj)) {
1172 result = exception_obj;
1173 } else {
1174 result = undefined_value();
1175 }
1176 }
1177 return scope.CloseAndEscape(result);
1178 }
1179
1180
1141 Handle<Object> Factory::NewEvalError(const char* message, 1181 Handle<Object> Factory::NewEvalError(const char* message,
1142 Vector<Handle<Object> > args) { 1182 Vector<Handle<Object> > args) {
1143 return NewError("MakeEvalError", message, args); 1183 return NewError("MakeEvalError", message, args);
1144 } 1184 }
1145 1185
1146 1186
1147 Handle<Object> Factory::NewError(const char* message, 1187 Handle<Object> Factory::NewError(const char* message,
1148 Vector<Handle<Object> > args) { 1188 Vector<Handle<Object> > args) {
1149 return NewError("MakeError", message, args); 1189 return NewError("MakeError", message, args);
1150 } 1190 }
(...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after
2349 return Handle<Object>::null(); 2389 return Handle<Object>::null();
2350 } 2390 }
2351 2391
2352 2392
2353 Handle<Object> Factory::ToBoolean(bool value) { 2393 Handle<Object> Factory::ToBoolean(bool value) {
2354 return value ? true_value() : false_value(); 2394 return value ? true_value() : false_value();
2355 } 2395 }
2356 2396
2357 2397
2358 } } // namespace v8::internal 2398 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698