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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 203 |
204 | 204 |
205 Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) { | 205 Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) { |
206 ASSERT(!object->IsJSFunction()); | 206 ASSERT(!object->IsJSFunction()); |
207 Isolate* isolate = Isolate::Current(); | 207 Isolate* isolate = Isolate::Current(); |
208 Factory* factory = isolate->factory(); | 208 Factory* factory = isolate->factory(); |
209 | 209 |
210 // If you return a function from here, it will be called when an | 210 // If you return a function from here, it will be called when an |
211 // attempt is made to call the given object as a function. | 211 // attempt is made to call the given object as a function. |
212 | 212 |
213 // Regular expressions can be called as functions in both Firefox | |
214 // and Safari so we allow it too. | |
215 if (object->IsJSRegExp()) { | |
216 Handle<String> exec = factory->exec_symbol(); | |
217 // TODO(lrn): Bug 617. We should use the default function here, not the | |
218 // one on the RegExp object. | |
219 Object* exec_function; | |
220 { MaybeObject* maybe_exec_function = object->GetProperty(*exec); | |
221 // This can lose an exception, but the alternative is to put a failure | |
222 // object in a handle, which is not GC safe. | |
223 if (!maybe_exec_function->ToObject(&exec_function)) { | |
224 return factory->undefined_value(); | |
225 } | |
226 } | |
227 return Handle<Object>(exec_function); | |
228 } | |
229 | |
230 // Objects created through the API can have an instance-call handler | 213 // Objects created through the API can have an instance-call handler |
231 // that should be used when calling the object as a function. | 214 // that should be used when calling the object as a function. |
232 if (object->IsHeapObject() && | 215 if (object->IsHeapObject() && |
233 HeapObject::cast(*object)->map()->has_instance_call_handler()) { | 216 HeapObject::cast(*object)->map()->has_instance_call_handler()) { |
234 return Handle<JSFunction>( | 217 return Handle<JSFunction>( |
235 isolate->global_context()->call_as_function_delegate()); | 218 isolate->global_context()->call_as_function_delegate()); |
236 } | 219 } |
237 | 220 |
238 return factory->undefined_value(); | 221 return factory->undefined_value(); |
239 } | 222 } |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 return isolate->TerminateExecution(); | 823 return isolate->TerminateExecution(); |
841 } | 824 } |
842 if (stack_guard->IsInterrupted()) { | 825 if (stack_guard->IsInterrupted()) { |
843 stack_guard->Continue(INTERRUPT); | 826 stack_guard->Continue(INTERRUPT); |
844 return isolate->StackOverflow(); | 827 return isolate->StackOverflow(); |
845 } | 828 } |
846 return isolate->heap()->undefined_value(); | 829 return isolate->heap()->undefined_value(); |
847 } | 830 } |
848 | 831 |
849 } } // namespace v8::internal | 832 } } // namespace v8::internal |
OLD | NEW |