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 1140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Handle<Object> result; |
1162 Handle<Object> result = Execution::TryCall(fun, | 1162 Handle<Object> exception; |
1163 isolate()->js_builtins_object(), | 1163 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
1164 ARRAY_SIZE(argv), | 1164 isolate, result, |
1165 argv, | 1165 Execution::TryCall(fun, |
1166 &caught_exception); | 1166 isolate()->js_builtins_object(), |
| 1167 ARRAY_SIZE(argv), |
| 1168 argv, |
| 1169 &exception), |
| 1170 exception); |
1167 return result; | 1171 return result; |
1168 } | 1172 } |
1169 | 1173 |
1170 | 1174 |
1171 Handle<Object> Factory::NewError(Handle<String> message) { | 1175 Handle<Object> Factory::NewError(Handle<String> message) { |
1172 return NewError("$Error", message); | 1176 return NewError("$Error", message); |
1173 } | 1177 } |
1174 | 1178 |
1175 | 1179 |
1176 Handle<Object> Factory::NewError(const char* constructor, | 1180 Handle<Object> Factory::NewError(const char* constructor, |
1177 Handle<String> message) { | 1181 Handle<String> message) { |
1178 Handle<String> constr = InternalizeUtf8String(constructor); | 1182 Handle<String> constr = InternalizeUtf8String(constructor); |
1179 Handle<JSFunction> fun = Handle<JSFunction>::cast( | 1183 Handle<JSFunction> fun = Handle<JSFunction>::cast( |
1180 GlobalObject::GetPropertyNoExceptionThrown( | 1184 GlobalObject::GetPropertyNoExceptionThrown( |
1181 isolate()->js_builtins_object(), constr)); | 1185 isolate()->js_builtins_object(), constr)); |
1182 Handle<Object> argv[] = { message }; | 1186 Handle<Object> argv[] = { message }; |
1183 | 1187 |
1184 // Invoke the JavaScript factory method. If an exception is thrown while | 1188 // Invoke the JavaScript factory method. If an exception is thrown while |
1185 // running the factory method, use the exception as the result. | 1189 // running the factory method, use the exception as the result. |
1186 bool caught_exception; | 1190 Handle<Object> result; |
1187 Handle<Object> result = Execution::TryCall(fun, | 1191 Handle<Object> exception; |
1188 isolate()->js_builtins_object(), | 1192 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
1189 ARRAY_SIZE(argv), | 1193 isolate, result, |
1190 argv, | 1194 Execution::TryCall(fun, |
1191 &caught_exception); | 1195 isolate()->js_builtins_object(), |
| 1196 ARRAY_SIZE(argv), |
| 1197 argv, |
| 1198 &exception), |
| 1199 exception); |
1192 return result; | 1200 return result; |
1193 } | 1201 } |
1194 | 1202 |
1195 | 1203 |
1196 Handle<JSFunction> Factory::NewFunction(Handle<String> name, | 1204 Handle<JSFunction> Factory::NewFunction(Handle<String> name, |
1197 InstanceType type, | 1205 InstanceType type, |
1198 int instance_size, | 1206 int instance_size, |
1199 Handle<Code> code, | 1207 Handle<Code> code, |
1200 bool force_initial_map) { | 1208 bool force_initial_map) { |
1201 // Allocate the function | 1209 // Allocate the function |
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1984 store->set(JSRegExp::kIrregexpASCIICodeSavedIndex, uninitialized); | 1992 store->set(JSRegExp::kIrregexpASCIICodeSavedIndex, uninitialized); |
1985 store->set(JSRegExp::kIrregexpUC16CodeSavedIndex, uninitialized); | 1993 store->set(JSRegExp::kIrregexpUC16CodeSavedIndex, uninitialized); |
1986 store->set(JSRegExp::kIrregexpMaxRegisterCountIndex, Smi::FromInt(0)); | 1994 store->set(JSRegExp::kIrregexpMaxRegisterCountIndex, Smi::FromInt(0)); |
1987 store->set(JSRegExp::kIrregexpCaptureCountIndex, | 1995 store->set(JSRegExp::kIrregexpCaptureCountIndex, |
1988 Smi::FromInt(capture_count)); | 1996 Smi::FromInt(capture_count)); |
1989 regexp->set_data(*store); | 1997 regexp->set_data(*store); |
1990 } | 1998 } |
1991 | 1999 |
1992 | 2000 |
1993 | 2001 |
1994 void Factory::ConfigureInstance(Handle<FunctionTemplateInfo> desc, | 2002 MaybeHandle<FunctionTemplateInfo> Factory::ConfigureInstance( |
1995 Handle<JSObject> instance, | 2003 Handle<FunctionTemplateInfo> desc, Handle<JSObject> instance) { |
1996 bool* pending_exception) { | |
1997 // Configure the instance by adding the properties specified by the | 2004 // Configure the instance by adding the properties specified by the |
1998 // instance template. | 2005 // instance template. |
1999 Handle<Object> instance_template(desc->instance_template(), isolate()); | 2006 Handle<Object> instance_template(desc->instance_template(), isolate()); |
2000 if (!instance_template->IsUndefined()) { | 2007 if (!instance_template->IsUndefined()) { |
2001 Execution::ConfigureInstance(isolate(), | 2008 RETURN_ON_EXCEPTION( |
2002 instance, | 2009 isolate(), |
2003 instance_template, | 2010 Execution::ConfigureInstance(isolate(), instance, instance_template), |
2004 pending_exception); | 2011 FunctionTemplateInfo); |
2005 } else { | |
2006 *pending_exception = false; | |
2007 } | 2012 } |
| 2013 return desc; |
2008 } | 2014 } |
2009 | 2015 |
2010 | 2016 |
2011 Handle<Object> Factory::GlobalConstantFor(Handle<String> name) { | 2017 Handle<Object> Factory::GlobalConstantFor(Handle<String> name) { |
2012 Heap* h = isolate()->heap(); | 2018 Heap* h = isolate()->heap(); |
2013 if (name->Equals(h->undefined_string())) return undefined_value(); | 2019 if (name->Equals(h->undefined_string())) return undefined_value(); |
2014 if (name->Equals(h->nan_string())) return nan_value(); | 2020 if (name->Equals(h->nan_string())) return nan_value(); |
2015 if (name->Equals(h->infinity_string())) return infinity_value(); | 2021 if (name->Equals(h->infinity_string())) return infinity_value(); |
2016 return Handle<Object>::null(); | 2022 return Handle<Object>::null(); |
2017 } | 2023 } |
2018 | 2024 |
2019 | 2025 |
2020 Handle<Object> Factory::ToBoolean(bool value) { | 2026 Handle<Object> Factory::ToBoolean(bool value) { |
2021 return value ? true_value() : false_value(); | 2027 return value ? true_value() : false_value(); |
2022 } | 2028 } |
2023 | 2029 |
2024 } } // namespace v8::internal | 2030 } } // namespace v8::internal |
OLD | NEW |