| 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 | 461 |
| 479 char* StackGuard::RestoreStackGuard(char* from) { | 462 char* StackGuard::RestoreStackGuard(char* from) { |
| 480 ExecutionAccess access(isolate_); | 463 ExecutionAccess access(isolate_); |
| 481 memcpy(reinterpret_cast<char*>(&thread_local_), from, sizeof(ThreadLocal)); | 464 memcpy(reinterpret_cast<char*>(&thread_local_), from, sizeof(ThreadLocal)); |
| 482 isolate_->heap()->SetStackLimits(); | 465 isolate_->heap()->SetStackLimits(); |
| 483 return from + sizeof(ThreadLocal); | 466 return from + sizeof(ThreadLocal); |
| 484 } | 467 } |
| 485 | 468 |
| 486 | 469 |
| 487 void StackGuard::FreeThreadResources() { | 470 void StackGuard::FreeThreadResources() { |
| 488 Isolate::CurrentPerIsolateThreadData()->set_stack_limit( | 471 Isolate::PerIsolateThreadData* per_thread = |
| 489 thread_local_.real_climit_); | 472 isolate_->FindOrAllocatePerThreadDataForThisThread(); |
| 473 per_thread->set_stack_limit(thread_local_.real_climit_); |
| 490 } | 474 } |
| 491 | 475 |
| 492 | 476 |
| 493 void StackGuard::ThreadLocal::Clear() { | 477 void StackGuard::ThreadLocal::Clear() { |
| 494 real_jslimit_ = kIllegalLimit; | 478 real_jslimit_ = kIllegalLimit; |
| 495 jslimit_ = kIllegalLimit; | 479 jslimit_ = kIllegalLimit; |
| 496 real_climit_ = kIllegalLimit; | 480 real_climit_ = kIllegalLimit; |
| 497 climit_ = kIllegalLimit; | 481 climit_ = kIllegalLimit; |
| 498 nesting_ = 0; | 482 nesting_ = 0; |
| 499 postpone_interrupts_nesting_ = 0; | 483 postpone_interrupts_nesting_ = 0; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 528 } | 512 } |
| 529 | 513 |
| 530 | 514 |
| 531 void StackGuard::InitThread(const ExecutionAccess& lock) { | 515 void StackGuard::InitThread(const ExecutionAccess& lock) { |
| 532 if (thread_local_.Initialize(isolate_)) isolate_->heap()->SetStackLimits(); | 516 if (thread_local_.Initialize(isolate_)) isolate_->heap()->SetStackLimits(); |
| 533 Isolate::PerIsolateThreadData* per_thread = | 517 Isolate::PerIsolateThreadData* per_thread = |
| 534 isolate_->FindOrAllocatePerThreadDataForThisThread(); | 518 isolate_->FindOrAllocatePerThreadDataForThisThread(); |
| 535 uintptr_t stored_limit = per_thread->stack_limit(); | 519 uintptr_t stored_limit = per_thread->stack_limit(); |
| 536 // You should hold the ExecutionAccess lock when you call this. | 520 // You should hold the ExecutionAccess lock when you call this. |
| 537 if (stored_limit != 0) { | 521 if (stored_limit != 0) { |
| 538 StackGuard::SetStackLimit(stored_limit); | 522 SetStackLimit(stored_limit); |
| 539 } | 523 } |
| 540 } | 524 } |
| 541 | 525 |
| 542 | 526 |
| 543 // --- C a l l s t o n a t i v e s --- | 527 // --- C a l l s t o n a t i v e s --- |
| 544 | 528 |
| 545 #define RETURN_NATIVE_CALL(name, argc, argv, has_pending_exception) \ | 529 #define RETURN_NATIVE_CALL(name, argc, argv, has_pending_exception) \ |
| 546 do { \ | 530 do { \ |
| 547 Isolate* isolate = Isolate::Current(); \ | 531 Isolate* isolate = Isolate::Current(); \ |
| 548 Object** args[argc] = argv; \ | 532 Object** args[argc] = argv; \ |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 return isolate->TerminateExecution(); | 846 return isolate->TerminateExecution(); |
| 863 } | 847 } |
| 864 if (stack_guard->IsInterrupted()) { | 848 if (stack_guard->IsInterrupted()) { |
| 865 stack_guard->Continue(INTERRUPT); | 849 stack_guard->Continue(INTERRUPT); |
| 866 return isolate->StackOverflow(); | 850 return isolate->StackOverflow(); |
| 867 } | 851 } |
| 868 return isolate->heap()->undefined_value(); | 852 return isolate->heap()->undefined_value(); |
| 869 } | 853 } |
| 870 | 854 |
| 871 } } // namespace v8::internal | 855 } } // namespace v8::internal |
| OLD | NEW |