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 "factory.h" | 5 #include "factory.h" |
6 | 6 |
7 #include "isolate-inl.h" | 7 #include "isolate-inl.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 OS::StrNCpy(v, message, space); | 1115 OS::StrNCpy(v, message, space); |
1116 space -= Min(space, strlen(message)); | 1116 space -= Min(space, strlen(message)); |
1117 p = &buffer[kBufferSize] - space; | 1117 p = &buffer[kBufferSize] - space; |
1118 | 1118 |
1119 for (unsigned i = 0; i < ARRAY_SIZE(args); i++) { | 1119 for (unsigned i = 0; i < ARRAY_SIZE(args); i++) { |
1120 if (space > 0) { | 1120 if (space > 0) { |
1121 *p++ = ' '; | 1121 *p++ = ' '; |
1122 space--; | 1122 space--; |
1123 if (space > 0) { | 1123 if (space > 0) { |
1124 Handle<String> arg_str = Handle<String>::cast( | 1124 Handle<String> arg_str = Handle<String>::cast( |
1125 Object::GetElementNoExceptionThrown(isolate(), args, i)); | 1125 Object::GetElement(isolate(), args, i).ToHandleChecked()); |
1126 SmartArrayPointer<char> arg = arg_str->ToCString(); | 1126 SmartArrayPointer<char> arg = arg_str->ToCString(); |
1127 Vector<char> v2(p, static_cast<int>(space)); | 1127 Vector<char> v2(p, static_cast<int>(space)); |
1128 OS::StrNCpy(v2, arg.get(), space); | 1128 OS::StrNCpy(v2, arg.get(), space); |
1129 space -= Min(space, strlen(arg.get())); | 1129 space -= Min(space, strlen(arg.get())); |
1130 p = &buffer[kBufferSize] - space; | 1130 p = &buffer[kBufferSize] - space; |
1131 } | 1131 } |
1132 } | 1132 } |
1133 } | 1133 } |
1134 if (space > 0) { | 1134 if (space > 0) { |
1135 *p = '\0'; | 1135 *p = '\0'; |
1136 } else { | 1136 } else { |
1137 buffer[kBufferSize - 1] = '\0'; | 1137 buffer[kBufferSize - 1] = '\0'; |
1138 } | 1138 } |
1139 Handle<String> error_string = NewStringFromUtf8(CStrVector(buffer), TENURED); | 1139 Handle<String> error_string = NewStringFromUtf8(CStrVector(buffer), TENURED); |
1140 return error_string; | 1140 return error_string; |
1141 } | 1141 } |
1142 | 1142 |
1143 | 1143 |
1144 Handle<Object> Factory::NewError(const char* maker, | 1144 Handle<Object> Factory::NewError(const char* maker, |
1145 const char* message, | 1145 const char* message, |
1146 Handle<JSArray> args) { | 1146 Handle<JSArray> args) { |
1147 Handle<String> make_str = InternalizeUtf8String(maker); | 1147 Handle<String> make_str = InternalizeUtf8String(maker); |
1148 Handle<Object> fun_obj = GlobalObject::GetPropertyNoExceptionThrown( | 1148 Handle<Object> fun_obj = Object::GetProperty( |
1149 isolate()->js_builtins_object(), make_str); | 1149 isolate()->js_builtins_object(), make_str).ToHandleChecked(); |
1150 // If the builtins haven't been properly configured yet this error | 1150 // If the builtins haven't been properly configured yet this error |
1151 // constructor may not have been defined. Bail out. | 1151 // constructor may not have been defined. Bail out. |
1152 if (!fun_obj->IsJSFunction()) { | 1152 if (!fun_obj->IsJSFunction()) { |
1153 return EmergencyNewError(message, args); | 1153 return EmergencyNewError(message, args); |
1154 } | 1154 } |
1155 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); | 1155 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); |
1156 Handle<Object> message_obj = InternalizeUtf8String(message); | 1156 Handle<Object> message_obj = InternalizeUtf8String(message); |
1157 Handle<Object> argv[] = { message_obj, args }; | 1157 Handle<Object> argv[] = { message_obj, args }; |
1158 | 1158 |
1159 // Invoke the JavaScript factory method. If an exception is thrown while | 1159 // Invoke the JavaScript factory method. If an exception is thrown while |
1160 // running the factory method, use the exception as the result. | 1160 // running the factory method, use the exception as the result. |
1161 bool caught_exception; | 1161 bool caught_exception; |
1162 Handle<Object> result = Execution::TryCall(fun, | 1162 Handle<Object> result = Execution::TryCall(fun, |
1163 isolate()->js_builtins_object(), | 1163 isolate()->js_builtins_object(), |
1164 ARRAY_SIZE(argv), | 1164 ARRAY_SIZE(argv), |
1165 argv, | 1165 argv, |
1166 &caught_exception); | 1166 &caught_exception); |
1167 return result; | 1167 return result; |
1168 } | 1168 } |
1169 | 1169 |
1170 | 1170 |
1171 Handle<Object> Factory::NewError(Handle<String> message) { | 1171 Handle<Object> Factory::NewError(Handle<String> message) { |
1172 return NewError("$Error", message); | 1172 return NewError("$Error", message); |
1173 } | 1173 } |
1174 | 1174 |
1175 | 1175 |
1176 Handle<Object> Factory::NewError(const char* constructor, | 1176 Handle<Object> Factory::NewError(const char* constructor, |
1177 Handle<String> message) { | 1177 Handle<String> message) { |
1178 Handle<String> constr = InternalizeUtf8String(constructor); | 1178 Handle<String> constr = InternalizeUtf8String(constructor); |
1179 Handle<JSFunction> fun = Handle<JSFunction>::cast( | 1179 Handle<JSFunction> fun = Handle<JSFunction>::cast(Object::GetProperty( |
1180 GlobalObject::GetPropertyNoExceptionThrown( | 1180 isolate()->js_builtins_object(), constr).ToHandleChecked()); |
1181 isolate()->js_builtins_object(), constr)); | |
1182 Handle<Object> argv[] = { message }; | 1181 Handle<Object> argv[] = { message }; |
1183 | 1182 |
1184 // Invoke the JavaScript factory method. If an exception is thrown while | 1183 // Invoke the JavaScript factory method. If an exception is thrown while |
1185 // running the factory method, use the exception as the result. | 1184 // running the factory method, use the exception as the result. |
1186 bool caught_exception; | 1185 bool caught_exception; |
1187 Handle<Object> result = Execution::TryCall(fun, | 1186 Handle<Object> result = Execution::TryCall(fun, |
1188 isolate()->js_builtins_object(), | 1187 isolate()->js_builtins_object(), |
1189 ARRAY_SIZE(argv), | 1188 ARRAY_SIZE(argv), |
1190 argv, | 1189 argv, |
1191 &caught_exception); | 1190 &caught_exception); |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2015 if (name->Equals(h->infinity_string())) return infinity_value(); | 2014 if (name->Equals(h->infinity_string())) return infinity_value(); |
2016 return Handle<Object>::null(); | 2015 return Handle<Object>::null(); |
2017 } | 2016 } |
2018 | 2017 |
2019 | 2018 |
2020 Handle<Object> Factory::ToBoolean(bool value) { | 2019 Handle<Object> Factory::ToBoolean(bool value) { |
2021 return value ? true_value() : false_value(); | 2020 return value ? true_value() : false_value(); |
2022 } | 2021 } |
2023 | 2022 |
2024 } } // namespace v8::internal | 2023 } } // namespace v8::internal |
OLD | NEW |