OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 static Handle<Object> Invoke(bool construct, | 43 static Handle<Object> Invoke(bool construct, |
44 Handle<JSFunction> func, | 44 Handle<JSFunction> func, |
45 Handle<Object> receiver, | 45 Handle<Object> receiver, |
46 int argc, | 46 int argc, |
47 Object*** args, | 47 Object*** args, |
48 bool* has_pending_exception) { | 48 bool* has_pending_exception) { |
49 // Entering JavaScript. | 49 // Entering JavaScript. |
50 VMState state(JS); | 50 VMState state(JS); |
51 | 51 |
52 // Placeholder for return value. | 52 // Placeholder for return value. |
53 Object* value = reinterpret_cast<Object*>(kZapValue); | 53 MaybeObject* value = reinterpret_cast<Object*>(kZapValue); |
54 | 54 |
55 typedef Object* (*JSEntryFunction)( | 55 typedef Object* (*JSEntryFunction)( |
56 byte* entry, | 56 byte* entry, |
57 Object* function, | 57 Object* function, |
58 Object* receiver, | 58 Object* receiver, |
59 int argc, | 59 int argc, |
60 Object*** args); | 60 Object*** args); |
61 | 61 |
62 Handle<Code> code; | 62 Handle<Code> code; |
63 if (construct) { | 63 if (construct) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // Update the pending exception flag and return the value. | 102 // Update the pending exception flag and return the value. |
103 *has_pending_exception = value->IsException(); | 103 *has_pending_exception = value->IsException(); |
104 ASSERT(*has_pending_exception == Top::has_pending_exception()); | 104 ASSERT(*has_pending_exception == Top::has_pending_exception()); |
105 if (*has_pending_exception) { | 105 if (*has_pending_exception) { |
106 Top::ReportPendingMessages(); | 106 Top::ReportPendingMessages(); |
107 return Handle<Object>(); | 107 return Handle<Object>(); |
108 } else { | 108 } else { |
109 Top::clear_pending_message(); | 109 Top::clear_pending_message(); |
110 } | 110 } |
111 | 111 |
112 return Handle<Object>(value); | 112 return Handle<Object>(value->ToObjectUnchecked()); |
113 } | 113 } |
114 | 114 |
115 | 115 |
116 Handle<Object> Execution::Call(Handle<JSFunction> func, | 116 Handle<Object> Execution::Call(Handle<JSFunction> func, |
117 Handle<Object> receiver, | 117 Handle<Object> receiver, |
118 int argc, | 118 int argc, |
119 Object*** args, | 119 Object*** args, |
120 bool* pending_exception) { | 120 bool* pending_exception) { |
121 return Invoke(false, func, receiver, argc, args, pending_exception); | 121 return Invoke(false, func, receiver, argc, args, pending_exception); |
122 } | 122 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) { | 165 Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) { |
166 ASSERT(!object->IsJSFunction()); | 166 ASSERT(!object->IsJSFunction()); |
167 | 167 |
168 // If you return a function from here, it will be called when an | 168 // If you return a function from here, it will be called when an |
169 // attempt is made to call the given object as a function. | 169 // attempt is made to call the given object as a function. |
170 | 170 |
171 // Regular expressions can be called as functions in both Firefox | 171 // Regular expressions can be called as functions in both Firefox |
172 // and Safari so we allow it too. | 172 // and Safari so we allow it too. |
173 if (object->IsJSRegExp()) { | 173 if (object->IsJSRegExp()) { |
174 Handle<String> exec = Factory::exec_symbol(); | 174 Handle<String> exec = Factory::exec_symbol(); |
175 return Handle<Object>(object->GetProperty(*exec)); | 175 // TODO(lrn): Bug 617. We should use the default function here, not the |
| 176 // one on the RegExp object. |
| 177 Object* exec_function; |
| 178 { MaybeObject* maybe_exec_function = object->GetProperty(*exec); |
| 179 // This can lose an exception, but the alternative is to put a failure |
| 180 // object in a handle, which is not GC safe. |
| 181 if (!maybe_exec_function->ToObject(&exec_function)) { |
| 182 return Factory::undefined_value(); |
| 183 } |
| 184 } |
| 185 return Handle<Object>(exec_function); |
176 } | 186 } |
177 | 187 |
178 // Objects created through the API can have an instance-call handler | 188 // Objects created through the API can have an instance-call handler |
179 // that should be used when calling the object as a function. | 189 // that should be used when calling the object as a function. |
180 if (object->IsHeapObject() && | 190 if (object->IsHeapObject() && |
181 HeapObject::cast(*object)->map()->has_instance_call_handler()) { | 191 HeapObject::cast(*object)->map()->has_instance_call_handler()) { |
182 return Handle<JSFunction>( | 192 return Handle<JSFunction>( |
183 Top::global_context()->call_as_function_delegate()); | 193 Top::global_context()->call_as_function_delegate()); |
184 } | 194 } |
185 | 195 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 return Factory::undefined_value(); | 520 return Factory::undefined_value(); |
511 } | 521 } |
512 return result; | 522 return result; |
513 } | 523 } |
514 | 524 |
515 | 525 |
516 Handle<JSFunction> Execution::InstantiateFunction( | 526 Handle<JSFunction> Execution::InstantiateFunction( |
517 Handle<FunctionTemplateInfo> data, bool* exc) { | 527 Handle<FunctionTemplateInfo> data, bool* exc) { |
518 // Fast case: see if the function has already been instantiated | 528 // Fast case: see if the function has already been instantiated |
519 int serial_number = Smi::cast(data->serial_number())->value(); | 529 int serial_number = Smi::cast(data->serial_number())->value(); |
520 Object* elm = | 530 Object* elm = Top::global_context()->function_cache()-> |
521 Top::global_context()->function_cache()->GetElement(serial_number); | 531 GetElementNoExceptionThrown(serial_number); |
522 if (elm->IsJSFunction()) return Handle<JSFunction>(JSFunction::cast(elm)); | 532 if (elm->IsJSFunction()) return Handle<JSFunction>(JSFunction::cast(elm)); |
523 // The function has not yet been instantiated in this context; do it. | 533 // The function has not yet been instantiated in this context; do it. |
524 Object** args[1] = { Handle<Object>::cast(data).location() }; | 534 Object** args[1] = { Handle<Object>::cast(data).location() }; |
525 Handle<Object> result = | 535 Handle<Object> result = |
526 Call(Top::instantiate_fun(), Top::builtins(), 1, args, exc); | 536 Call(Top::instantiate_fun(), Top::builtins(), 1, args, exc); |
527 if (*exc) return Handle<JSFunction>::null(); | 537 if (*exc) return Handle<JSFunction>::null(); |
528 return Handle<JSFunction>::cast(result); | 538 return Handle<JSFunction>::cast(result); |
529 } | 539 } |
530 | 540 |
531 | 541 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 } | 674 } |
665 | 675 |
666 // Notify the debug event listeners. Indicate auto continue if the break was | 676 // Notify the debug event listeners. Indicate auto continue if the break was |
667 // a debug command break. | 677 // a debug command break. |
668 Debugger::OnDebugBreak(Factory::undefined_value(), debug_command_only); | 678 Debugger::OnDebugBreak(Factory::undefined_value(), debug_command_only); |
669 } | 679 } |
670 | 680 |
671 | 681 |
672 #endif | 682 #endif |
673 | 683 |
674 Object* Execution::HandleStackGuardInterrupt() { | 684 MaybeObject* Execution::HandleStackGuardInterrupt() { |
675 #ifdef ENABLE_DEBUGGER_SUPPORT | 685 #ifdef ENABLE_DEBUGGER_SUPPORT |
676 if (StackGuard::IsDebugBreak() || StackGuard::IsDebugCommand()) { | 686 if (StackGuard::IsDebugBreak() || StackGuard::IsDebugCommand()) { |
677 DebugBreakHelper(); | 687 DebugBreakHelper(); |
678 } | 688 } |
679 #endif | 689 #endif |
680 if (StackGuard::IsPreempted()) RuntimePreempt(); | 690 if (StackGuard::IsPreempted()) RuntimePreempt(); |
681 if (StackGuard::IsTerminateExecution()) { | 691 if (StackGuard::IsTerminateExecution()) { |
682 StackGuard::Continue(TERMINATE); | 692 StackGuard::Continue(TERMINATE); |
683 return Top::TerminateExecution(); | 693 return Top::TerminateExecution(); |
684 } | 694 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 return Utils::OpenHandle(*args[0].As<v8::String>())->IsAsciiRepresentation() ? | 823 return Utils::OpenHandle(*args[0].As<v8::String>())->IsAsciiRepresentation() ? |
814 v8::True() : v8::False(); | 824 v8::True() : v8::False(); |
815 } | 825 } |
816 | 826 |
817 | 827 |
818 static ExternalizeStringExtension externalize_extension; | 828 static ExternalizeStringExtension externalize_extension; |
819 static v8::DeclareExtension externalize_extension_declaration( | 829 static v8::DeclareExtension externalize_extension_declaration( |
820 &externalize_extension); | 830 &externalize_extension); |
821 | 831 |
822 } } // namespace v8::internal | 832 } } // namespace v8::internal |
OLD | NEW |