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