| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 #define EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, value) \ | 112 #define EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, value) \ |
| 113 EXCEPTION_BAILOUT_CHECK_GENERIC( \ | 113 EXCEPTION_BAILOUT_CHECK_GENERIC( \ |
| 114 isolate, value, i::V8::FireCallCompletedCallback(isolate);) | 114 isolate, value, i::V8::FireCallCompletedCallback(isolate);) |
| 115 | 115 |
| 116 | 116 |
| 117 #define EXCEPTION_BAILOUT_CHECK(isolate, value) \ | 117 #define EXCEPTION_BAILOUT_CHECK(isolate, value) \ |
| 118 EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, ;) | 118 EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, ;) |
| 119 | 119 |
| 120 | 120 |
| 121 #define API_ENTRY_CHECK(isolate, msg) \ | |
| 122 do { \ | |
| 123 if (v8::Locker::IsActive()) { \ | |
| 124 Utils::ApiCheck(isolate->thread_manager()->IsLockedByCurrentThread(), \ | |
| 125 msg, \ | |
| 126 "Entering the V8 API without proper locking in place"); \ | |
| 127 } \ | |
| 128 } while (false) | |
| 129 | |
| 130 | |
| 131 // --- E x c e p t i o n B e h a v i o r --- | 121 // --- E x c e p t i o n B e h a v i o r --- |
| 132 | 122 |
| 133 | 123 |
| 134 static void DefaultFatalErrorHandler(const char* location, | |
| 135 const char* message) { | |
| 136 i::Isolate* isolate = i::Isolate::Current(); | |
| 137 if (isolate->IsInitialized()) { | |
| 138 i::VMState<i::OTHER> state(isolate); | |
| 139 API_Fatal(location, message); | |
| 140 } else { | |
| 141 API_Fatal(location, message); | |
| 142 } | |
| 143 } | |
| 144 | |
| 145 | |
| 146 void i::FatalProcessOutOfMemory(const char* location) { | 124 void i::FatalProcessOutOfMemory(const char* location) { |
| 147 i::V8::FatalProcessOutOfMemory(location, false); | 125 i::V8::FatalProcessOutOfMemory(location, false); |
| 148 } | 126 } |
| 149 | 127 |
| 150 | 128 |
| 151 // When V8 cannot allocated memory FatalProcessOutOfMemory is called. | 129 // When V8 cannot allocated memory FatalProcessOutOfMemory is called. |
| 152 // The default fatal error handler is called and execution is stopped. | 130 // The default fatal error handler is called and execution is stopped. |
| 153 void i::V8::FatalProcessOutOfMemory(const char* location, bool take_snapshot) { | 131 void i::V8::FatalProcessOutOfMemory(const char* location, bool take_snapshot) { |
| 154 i::HeapStats heap_stats; | 132 i::HeapStats heap_stats; |
| 155 int start_marker; | 133 int start_marker; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 isolate->heap()->RecordStats(&heap_stats, false); | 191 isolate->heap()->RecordStats(&heap_stats, false); |
| 214 } | 192 } |
| 215 Utils::ApiCheck(false, location, "Allocation failed - process out of memory"); | 193 Utils::ApiCheck(false, location, "Allocation failed - process out of memory"); |
| 216 // If the fatal error handler returns, we stop execution. | 194 // If the fatal error handler returns, we stop execution. |
| 217 FATAL("API fatal error handler returned after process out of memory"); | 195 FATAL("API fatal error handler returned after process out of memory"); |
| 218 } | 196 } |
| 219 | 197 |
| 220 | 198 |
| 221 void Utils::ReportApiFailure(const char* location, const char* message) { | 199 void Utils::ReportApiFailure(const char* location, const char* message) { |
| 222 i::Isolate* isolate = i::Isolate::Current(); | 200 i::Isolate* isolate = i::Isolate::Current(); |
| 223 FatalErrorCallback callback = isolate->exception_behavior() == NULL | 201 FatalErrorCallback callback = isolate->exception_behavior(); |
| 224 ? DefaultFatalErrorHandler | 202 if (callback == NULL) { |
| 225 : isolate->exception_behavior(); | 203 i::OS::PrintError("\n#\n# Fatal error in %s\n# %s\n#\n\n", |
| 226 callback(location, message); | 204 location, message); |
| 205 i::OS::Abort(); |
| 206 } else { |
| 207 callback(location, message); |
| 208 } |
| 227 isolate->SignalFatalError(); | 209 isolate->SignalFatalError(); |
| 228 } | 210 } |
| 229 | 211 |
| 230 | 212 |
| 231 bool V8::IsDead() { | 213 bool V8::IsDead() { |
| 232 i::Isolate* isolate = i::Isolate::Current(); | 214 i::Isolate* isolate = i::Isolate::Current(); |
| 233 return isolate->IsDead(); | 215 return isolate->IsDead(); |
| 234 } | 216 } |
| 235 | 217 |
| 236 | 218 |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 // --- H a n d l e s --- | 586 // --- H a n d l e s --- |
| 605 | 587 |
| 606 | 588 |
| 607 HandleScope::HandleScope(Isolate* isolate) { | 589 HandleScope::HandleScope(Isolate* isolate) { |
| 608 Initialize(isolate); | 590 Initialize(isolate); |
| 609 } | 591 } |
| 610 | 592 |
| 611 | 593 |
| 612 void HandleScope::Initialize(Isolate* isolate) { | 594 void HandleScope::Initialize(Isolate* isolate) { |
| 613 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); | 595 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 614 API_ENTRY_CHECK(internal_isolate, "HandleScope::HandleScope"); | 596 // We do not want to check the correct usage of the Locker class all over the |
| 597 // place, so we do it only here: Without a HandleScope, an embedder can do |
| 598 // almost nothing, so it is enough to check in this central place. |
| 599 Utils::ApiCheck(!v8::Locker::IsActive() || |
| 600 internal_isolate->thread_manager()->IsLockedByCurrentThread(), |
| 601 "HandleScope::HandleScope", |
| 602 "Entering the V8 API without proper locking in place"); |
| 615 v8::ImplementationUtilities::HandleScopeData* current = | 603 v8::ImplementationUtilities::HandleScopeData* current = |
| 616 internal_isolate->handle_scope_data(); | 604 internal_isolate->handle_scope_data(); |
| 617 isolate_ = internal_isolate; | 605 isolate_ = internal_isolate; |
| 618 prev_next_ = current->next; | 606 prev_next_ = current->next; |
| 619 prev_limit_ = current->limit; | 607 prev_limit_ = current->limit; |
| 620 current->level++; | 608 current->level++; |
| 621 } | 609 } |
| 622 | 610 |
| 623 | 611 |
| 624 HandleScope::~HandleScope() { | 612 HandleScope::~HandleScope() { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 } | 649 } |
| 662 *escape_slot_ = *escape_value; | 650 *escape_slot_ = *escape_value; |
| 663 return escape_slot_; | 651 return escape_slot_; |
| 664 } | 652 } |
| 665 | 653 |
| 666 | 654 |
| 667 void Context::Enter() { | 655 void Context::Enter() { |
| 668 i::Handle<i::Context> env = Utils::OpenHandle(this); | 656 i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 669 i::Isolate* isolate = env->GetIsolate(); | 657 i::Isolate* isolate = env->GetIsolate(); |
| 670 ENTER_V8(isolate); | 658 ENTER_V8(isolate); |
| 671 isolate->handle_scope_implementer()->EnterContext(env); | 659 i::HandleScopeImplementer* impl = isolate->handle_scope_implementer(); |
| 672 isolate->handle_scope_implementer()->SaveContext(isolate->context()); | 660 impl->EnterContext(env); |
| 661 impl->SaveContext(isolate->context()); |
| 673 isolate->set_context(*env); | 662 isolate->set_context(*env); |
| 674 } | 663 } |
| 675 | 664 |
| 676 | 665 |
| 677 void Context::Exit() { | 666 void Context::Exit() { |
| 678 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 667 i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 679 i::Handle<i::Context> context = i::Handle<i::Context>::null(); | 668 i::Isolate* isolate = env->GetIsolate(); |
| 680 ENTER_V8(isolate); | 669 ENTER_V8(isolate); |
| 681 i::HandleScopeImplementer* impl = isolate->handle_scope_implementer(); | 670 i::HandleScopeImplementer* impl = isolate->handle_scope_implementer(); |
| 682 if (!Utils::ApiCheck(impl->LeaveContext(context), | 671 if (!Utils::ApiCheck(impl->LastEnteredContextWas(env), |
| 683 "v8::Context::Exit()", | 672 "v8::Context::Exit()", |
| 684 "Cannot exit non-entered context")) { | 673 "Cannot exit non-entered context")) { |
| 685 return; | 674 return; |
| 686 } | 675 } |
| 676 impl->LeaveContext(); |
| 687 isolate->set_context(impl->RestoreContext()); | 677 isolate->set_context(impl->RestoreContext()); |
| 688 } | 678 } |
| 689 | 679 |
| 690 | 680 |
| 691 static void* DecodeSmiToAligned(i::Object* value, const char* location) { | 681 static void* DecodeSmiToAligned(i::Object* value, const char* location) { |
| 692 Utils::ApiCheck(value->IsSmi(), location, "Not a Smi"); | 682 Utils::ApiCheck(value->IsSmi(), location, "Not a Smi"); |
| 693 return reinterpret_cast<void*>(value); | 683 return reinterpret_cast<void*>(value); |
| 694 } | 684 } |
| 695 | 685 |
| 696 | 686 |
| (...skipping 6736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7433 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7423 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 7434 Address callback_address = | 7424 Address callback_address = |
| 7435 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7425 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 7436 VMState<EXTERNAL> state(isolate); | 7426 VMState<EXTERNAL> state(isolate); |
| 7437 ExternalCallbackScope call_scope(isolate, callback_address); | 7427 ExternalCallbackScope call_scope(isolate, callback_address); |
| 7438 callback(info); | 7428 callback(info); |
| 7439 } | 7429 } |
| 7440 | 7430 |
| 7441 | 7431 |
| 7442 } } // namespace v8::internal | 7432 } } // namespace v8::internal |
| OLD | NEW |