OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 if (object->IsHeapObject() && | 227 if (object->IsHeapObject() && |
228 HeapObject::cast(*object)->map()->has_instance_call_handler()) { | 228 HeapObject::cast(*object)->map()->has_instance_call_handler()) { |
229 return Handle<JSFunction>( | 229 return Handle<JSFunction>( |
230 isolate->global_context()->call_as_function_delegate()); | 230 isolate->global_context()->call_as_function_delegate()); |
231 } | 231 } |
232 | 232 |
233 return factory->undefined_value(); | 233 return factory->undefined_value(); |
234 } | 234 } |
235 | 235 |
236 | 236 |
237 Handle<Object> Execution::TryGetFunctionDelegate(Handle<Object> object, | |
238 bool* has_pending_exception) { | |
239 ASSERT(!object->IsJSFunction()); | |
240 Isolate* isolate = Isolate::Current(); | |
241 | |
242 // Objects created through the API can have an instance-call handler | |
243 // that should be used when calling the object as a function. | |
244 if (object->IsHeapObject() && | |
245 HeapObject::cast(*object)->map()->has_instance_call_handler()) { | |
246 return Handle<JSFunction>( | |
247 isolate->global_context()->call_as_function_delegate()); | |
248 } | |
249 | |
250 // If the Object doesn't have an instance-call handler we should | |
251 // throw a non-callable exception. | |
252 i::Handle<i::Object> error_obj = isolate->factory()->NewTypeError( | |
253 "called_non_callable", i::HandleVector<i::Object>(&object, 1)); | |
254 isolate->Throw(*error_obj); | |
255 *has_pending_exception = true; | |
256 | |
257 return isolate->factory()->undefined_value(); | |
258 } | |
259 | |
260 | |
261 Handle<Object> Execution::GetConstructorDelegate(Handle<Object> object) { | 237 Handle<Object> Execution::GetConstructorDelegate(Handle<Object> object) { |
262 ASSERT(!object->IsJSFunction()); | 238 ASSERT(!object->IsJSFunction()); |
263 Isolate* isolate = Isolate::Current(); | 239 Isolate* isolate = Isolate::Current(); |
264 | 240 |
265 // If you return a function from here, it will be called when an | 241 // If you return a function from here, it will be called when an |
266 // attempt is made to call the given object as a constructor. | 242 // attempt is made to call the given object as a constructor. |
267 | 243 |
268 // Objects created through the API can have an instance-call handler | 244 // Objects created through the API can have an instance-call handler |
269 // that should be used when calling the object as a function. | 245 // that should be used when calling the object as a function. |
270 if (object->IsHeapObject() && | 246 if (object->IsHeapObject() && |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 return isolate->TerminateExecution(); | 782 return isolate->TerminateExecution(); |
807 } | 783 } |
808 if (stack_guard->IsInterrupted()) { | 784 if (stack_guard->IsInterrupted()) { |
809 stack_guard->Continue(INTERRUPT); | 785 stack_guard->Continue(INTERRUPT); |
810 return isolate->StackOverflow(); | 786 return isolate->StackOverflow(); |
811 } | 787 } |
812 return isolate->heap()->undefined_value(); | 788 return isolate->heap()->undefined_value(); |
813 } | 789 } |
814 | 790 |
815 } } // namespace v8::internal | 791 } } // namespace v8::internal |
OLD | NEW |