OLD | NEW |
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 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 Handle<HeapNumber> Factory::NewHeapNumber(double value, | 1069 Handle<HeapNumber> Factory::NewHeapNumber(double value, |
1070 MutableMode mode, | 1070 MutableMode mode, |
1071 PretenureFlag pretenure) { | 1071 PretenureFlag pretenure) { |
1072 CALL_HEAP_FUNCTION( | 1072 CALL_HEAP_FUNCTION( |
1073 isolate(), | 1073 isolate(), |
1074 isolate()->heap()->AllocateHeapNumber(value, mode, pretenure), | 1074 isolate()->heap()->AllocateHeapNumber(value, mode, pretenure), |
1075 HeapNumber); | 1075 HeapNumber); |
1076 } | 1076 } |
1077 | 1077 |
1078 | 1078 |
1079 Handle<Object> Factory::NewTypeError(Handle<String> message) { | |
1080 return NewError("$TypeError", message); | |
1081 } | |
1082 | |
1083 | |
1084 Handle<Object> Factory::NewRangeError(Handle<String> message) { | |
1085 return NewError("$RangeError", message); | |
1086 } | |
1087 | |
1088 | |
1089 Handle<Object> Factory::NewSyntaxError(const char* message, | |
1090 Handle<JSArray> args) { | |
1091 return NewError("MakeSyntaxError", message, args); | |
1092 } | |
1093 | |
1094 | |
1095 Handle<Object> Factory::NewSyntaxError(Handle<String> message) { | |
1096 return NewError("$SyntaxError", message); | |
1097 } | |
1098 | |
1099 | |
1100 Handle<Object> Factory::NewReferenceError(const char* message, | |
1101 Handle<JSArray> args) { | |
1102 return NewError("MakeReferenceError", message, args); | |
1103 } | |
1104 | |
1105 | |
1106 Handle<Object> Factory::NewReferenceError(Handle<String> message) { | |
1107 return NewError("$ReferenceError", message); | |
1108 } | |
1109 | |
1110 | |
1111 Handle<Object> Factory::NewError(const char* maker, const char* message, | |
1112 Vector<Handle<Object> > args) { | |
1113 // Instantiate a closeable HandleScope for EscapeFrom. | |
1114 v8::EscapableHandleScope scope(reinterpret_cast<v8::Isolate*>(isolate())); | |
1115 Handle<FixedArray> array = NewFixedArray(args.length()); | |
1116 for (int i = 0; i < args.length(); i++) { | |
1117 array->set(i, *args[i]); | |
1118 } | |
1119 Handle<JSArray> object = NewJSArrayWithElements(array); | |
1120 Handle<Object> result = NewError(maker, message, object); | |
1121 return result.EscapeFrom(&scope); | |
1122 } | |
1123 | |
1124 | |
1125 Handle<Object> Factory::NewError(const char* maker, | 1079 Handle<Object> Factory::NewError(const char* maker, |
1126 MessageTemplate::Template template_index, | 1080 MessageTemplate::Template template_index, |
1127 Handle<Object> arg0, Handle<Object> arg1, | 1081 Handle<Object> arg0, Handle<Object> arg1, |
1128 Handle<Object> arg2) { | 1082 Handle<Object> arg2) { |
1129 HandleScope scope(isolate()); | 1083 HandleScope scope(isolate()); |
1130 Handle<String> error_maker = InternalizeUtf8String(maker); | 1084 Handle<String> error_maker = InternalizeUtf8String(maker); |
1131 Handle<Object> fun_obj = Object::GetProperty(isolate()->js_builtins_object(), | 1085 Handle<Object> fun_obj = Object::GetProperty(isolate()->js_builtins_object(), |
1132 error_maker).ToHandleChecked(); | 1086 error_maker).ToHandleChecked(); |
1133 | 1087 |
1134 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); | 1088 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); |
(...skipping 27 matching lines...) Expand all Loading... |
1162 } | 1116 } |
1163 | 1117 |
1164 | 1118 |
1165 Handle<Object> Factory::NewTypeError(MessageTemplate::Template template_index, | 1119 Handle<Object> Factory::NewTypeError(MessageTemplate::Template template_index, |
1166 Handle<Object> arg0, Handle<Object> arg1, | 1120 Handle<Object> arg0, Handle<Object> arg1, |
1167 Handle<Object> arg2) { | 1121 Handle<Object> arg2) { |
1168 return NewError("MakeTypeError", template_index, arg0, arg1, arg2); | 1122 return NewError("MakeTypeError", template_index, arg0, arg1, arg2); |
1169 } | 1123 } |
1170 | 1124 |
1171 | 1125 |
| 1126 Handle<Object> Factory::NewSyntaxError(MessageTemplate::Template template_index, |
| 1127 Handle<Object> arg0, Handle<Object> arg1, |
| 1128 Handle<Object> arg2) { |
| 1129 return NewError("MakeSyntaxError", template_index, arg0, arg1, arg2); |
| 1130 } |
| 1131 |
| 1132 |
1172 Handle<Object> Factory::NewReferenceError( | 1133 Handle<Object> Factory::NewReferenceError( |
1173 MessageTemplate::Template template_index, Handle<Object> arg0, | 1134 MessageTemplate::Template template_index, Handle<Object> arg0, |
1174 Handle<Object> arg1, Handle<Object> arg2) { | 1135 Handle<Object> arg1, Handle<Object> arg2) { |
1175 return NewError("MakeReferenceError", template_index, arg0, arg1, arg2); | 1136 return NewError("MakeReferenceError", template_index, arg0, arg1, arg2); |
1176 } | 1137 } |
1177 | 1138 |
1178 | 1139 |
1179 Handle<Object> Factory::NewRangeError(MessageTemplate::Template template_index, | 1140 Handle<Object> Factory::NewRangeError(MessageTemplate::Template template_index, |
1180 Handle<Object> arg0, Handle<Object> arg1, | 1141 Handle<Object> arg0, Handle<Object> arg1, |
1181 Handle<Object> arg2) { | 1142 Handle<Object> arg2) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1250 argv, | 1211 argv, |
1251 &exception).ToHandle(&result)) { | 1212 &exception).ToHandle(&result)) { |
1252 Handle<Object> exception_obj; | 1213 Handle<Object> exception_obj; |
1253 if (exception.ToHandle(&exception_obj)) return exception_obj; | 1214 if (exception.ToHandle(&exception_obj)) return exception_obj; |
1254 return undefined_value(); | 1215 return undefined_value(); |
1255 } | 1216 } |
1256 return result; | 1217 return result; |
1257 } | 1218 } |
1258 | 1219 |
1259 | 1220 |
1260 Handle<Object> Factory::NewError(Handle<String> message) { | |
1261 return NewError("$Error", message); | |
1262 } | |
1263 | |
1264 | |
1265 Handle<Object> Factory::NewError(const char* constructor, | 1221 Handle<Object> Factory::NewError(const char* constructor, |
1266 Handle<String> message) { | 1222 Handle<String> message) { |
1267 Handle<String> constr = InternalizeUtf8String(constructor); | 1223 Handle<String> constr = InternalizeUtf8String(constructor); |
1268 Handle<JSFunction> fun = Handle<JSFunction>::cast(Object::GetProperty( | 1224 Handle<JSFunction> fun = Handle<JSFunction>::cast(Object::GetProperty( |
1269 isolate()->js_builtins_object(), constr).ToHandleChecked()); | 1225 isolate()->js_builtins_object(), constr).ToHandleChecked()); |
1270 Handle<Object> argv[] = { message }; | 1226 Handle<Object> argv[] = { message }; |
1271 | 1227 |
1272 // Invoke the JavaScript factory method. If an exception is thrown while | 1228 // Invoke the JavaScript factory method. If an exception is thrown while |
1273 // running the factory method, use the exception as the result. | 1229 // running the factory method, use the exception as the result. |
1274 Handle<Object> result; | 1230 Handle<Object> result; |
(...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2469 return Handle<Object>::null(); | 2425 return Handle<Object>::null(); |
2470 } | 2426 } |
2471 | 2427 |
2472 | 2428 |
2473 Handle<Object> Factory::ToBoolean(bool value) { | 2429 Handle<Object> Factory::ToBoolean(bool value) { |
2474 return value ? true_value() : false_value(); | 2430 return value ? true_value() : false_value(); |
2475 } | 2431 } |
2476 | 2432 |
2477 | 2433 |
2478 } } // namespace v8::internal | 2434 } } // namespace v8::internal |
OLD | NEW |