Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: src/api.cc

Issue 24345003: remove Isolate::GetCurrent from Context api functions (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: lint Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 i::Object** HandleScope::CreateHandle(i::HeapObject* value) { 743 i::Object** HandleScope::CreateHandle(i::HeapObject* value) {
744 ASSERT(value->IsHeapObject()); 744 ASSERT(value->IsHeapObject());
745 return reinterpret_cast<i::Object**>( 745 return reinterpret_cast<i::Object**>(
746 i::HandleScope::CreateHandle(value->GetIsolate(), value)); 746 i::HandleScope::CreateHandle(value->GetIsolate(), value));
747 } 747 }
748 748
749 749
750 void Context::Enter() { 750 void Context::Enter() {
751 i::Handle<i::Context> env = Utils::OpenHandle(this); 751 i::Handle<i::Context> env = Utils::OpenHandle(this);
752 i::Isolate* isolate = env->GetIsolate(); 752 i::Isolate* isolate = env->GetIsolate();
753 if (IsDeadCheck(isolate, "v8::Context::Enter()")) return;
754 ENTER_V8(isolate); 753 ENTER_V8(isolate);
755
756 isolate->handle_scope_implementer()->EnterContext(env); 754 isolate->handle_scope_implementer()->EnterContext(env);
757
758 isolate->handle_scope_implementer()->SaveContext(isolate->context()); 755 isolate->handle_scope_implementer()->SaveContext(isolate->context());
759 isolate->set_context(*env); 756 isolate->set_context(*env);
760 } 757 }
761 758
762 759
763 void Context::Exit() { 760 void Context::Exit() {
764 // Exit is essentially a static function and doesn't use the 761 // Exit is essentially a static function and doesn't use the
765 // receiver, so we have to get the current isolate from the thread 762 // receiver, so we have to get the current isolate from the thread
Michael Starzinger 2013/09/23 09:24:47 This comment no longer applies, let's drop it.
766 // local. 763 // local.
767 i::Isolate* isolate = i::Isolate::Current(); 764 i::Handle<i::Context> context = Utils::OpenHandle(this);
768 if (!isolate->IsInitialized()) return; 765 i::Isolate* isolate = context->GetIsolate();
769 766 ENTER_V8(isolate);
770 if (!ApiCheck(isolate->handle_scope_implementer()->LeaveLastContext(), 767 if (!ApiCheck(isolate->handle_scope_implementer()->LeaveLastContext(),
771 "v8::Context::Exit()", 768 "v8::Context::Exit()",
772 "Cannot exit non-entered context")) { 769 "Cannot exit non-entered context")) {
773 return; 770 return;
774 } 771 }
775
776 // Content of 'last_context' could be NULL. 772 // Content of 'last_context' could be NULL.
777 i::Context* last_context = 773 i::Context* last_context =
778 isolate->handle_scope_implementer()->RestoreContext(); 774 isolate->handle_scope_implementer()->RestoreContext();
779 isolate->set_context(last_context); 775 isolate->set_context(last_context);
780 } 776 }
781 777
782 778
783 static void* DecodeSmiToAligned(i::Object* value, const char* location) { 779 static void* DecodeSmiToAligned(i::Object* value, const char* location) {
784 ApiCheck(value->IsSmi(), location, "Not a Smi"); 780 ApiCheck(value->IsSmi(), location, "Not a Smi");
785 return reinterpret_cast<void*>(value); 781 return reinterpret_cast<void*>(value);
(...skipping 4701 matching lines...) Expand 10 before | Expand all | Expand 10 after
5487 i::Handle<i::Context> env = Utils::OpenHandle(this); 5483 i::Handle<i::Context> env = Utils::OpenHandle(this);
5488 return reinterpret_cast<Isolate*>(env->GetIsolate()); 5484 return reinterpret_cast<Isolate*>(env->GetIsolate());
5489 } 5485 }
5490 5486
5491 5487
5492 v8::Local<v8::Context> Context::GetEntered() { 5488 v8::Local<v8::Context> Context::GetEntered() {
5493 i::Isolate* isolate = i::Isolate::Current(); 5489 i::Isolate* isolate = i::Isolate::Current();
5494 if (!EnsureInitializedForIsolate(isolate, "v8::Context::GetEntered()")) { 5490 if (!EnsureInitializedForIsolate(isolate, "v8::Context::GetEntered()")) {
5495 return Local<Context>(); 5491 return Local<Context>();
5496 } 5492 }
5497 i::Handle<i::Object> last = 5493 return reinterpret_cast<Isolate*>(isolate)->GetEnteredContext();
5498 isolate->handle_scope_implementer()->LastEnteredContext();
5499 if (last.is_null()) return Local<Context>();
5500 i::Handle<i::Context> context = i::Handle<i::Context>::cast(last);
5501 return Utils::ToLocal(context);
5502 } 5494 }
5503 5495
5504 5496
5505 v8::Local<v8::Context> Context::GetCurrent() { 5497 v8::Local<v8::Context> Context::GetCurrent() {
5506 i::Isolate* isolate = i::Isolate::Current(); 5498 i::Isolate* isolate = i::Isolate::Current();
5507 if (IsDeadCheck(isolate, "v8::Context::GetCurrent()")) { 5499 if (IsDeadCheck(isolate, "v8::Context::GetCurrent()")) {
5508 return Local<Context>(); 5500 return Local<Context>();
5509 } 5501 }
5510 return reinterpret_cast<Isolate*>(isolate)->GetCurrentContext(); 5502 return reinterpret_cast<Isolate*>(isolate)->GetCurrentContext();
5511 } 5503 }
5512 5504
5513 5505
5514 v8::Local<v8::Context> Context::GetCalling() { 5506 v8::Local<v8::Context> Context::GetCalling() {
5515 i::Isolate* isolate = i::Isolate::Current(); 5507 i::Isolate* isolate = i::Isolate::Current();
5516 if (IsDeadCheck(isolate, "v8::Context::GetCalling()")) { 5508 if (IsDeadCheck(isolate, "v8::Context::GetCalling()")) {
5517 return Local<Context>(); 5509 return Local<Context>();
5518 } 5510 }
5519 i::Handle<i::Object> calling = 5511 return reinterpret_cast<Isolate*>(isolate)->GetCallingContext();
5520 isolate->GetCallingNativeContext();
5521 if (calling.is_null()) return Local<Context>();
5522 i::Handle<i::Context> context = i::Handle<i::Context>::cast(calling);
5523 return Utils::ToLocal(context);
5524 } 5512 }
5525 5513
5526 5514
5527 v8::Local<v8::Object> Context::Global() { 5515 v8::Local<v8::Object> Context::Global() {
5528 i::Isolate* isolate = i::Isolate::Current(); 5516 i::Handle<i::Context> context = Utils::OpenHandle(this);
5529 if (IsDeadCheck(isolate, "v8::Context::Global()")) { 5517 i::Isolate* isolate = context->GetIsolate();
5530 return Local<v8::Object>();
5531 }
5532 i::Object** ctx = reinterpret_cast<i::Object**>(this);
5533 i::Handle<i::Context> context =
5534 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx));
5535 i::Handle<i::Object> global(context->global_proxy(), isolate); 5518 i::Handle<i::Object> global(context->global_proxy(), isolate);
5536 return Utils::ToLocal(i::Handle<i::JSObject>::cast(global)); 5519 return Utils::ToLocal(i::Handle<i::JSObject>::cast(global));
5537 } 5520 }
5538 5521
5539 5522
5540 void Context::DetachGlobal() { 5523 void Context::DetachGlobal() {
5541 i::Isolate* isolate = i::Isolate::Current(); 5524 i::Handle<i::Context> context = Utils::OpenHandle(this);
5542 if (IsDeadCheck(isolate, "v8::Context::DetachGlobal()")) return; 5525 i::Isolate* isolate = context->GetIsolate();
5543 ENTER_V8(isolate); 5526 ENTER_V8(isolate);
5544 i::Object** ctx = reinterpret_cast<i::Object**>(this);
5545 i::Handle<i::Context> context =
5546 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx));
5547 isolate->bootstrapper()->DetachGlobal(context); 5527 isolate->bootstrapper()->DetachGlobal(context);
5548 } 5528 }
5549 5529
5550 5530
5551 void Context::ReattachGlobal(Handle<Object> global_object) { 5531 void Context::ReattachGlobal(Handle<Object> global_object) {
5552 i::Isolate* isolate = i::Isolate::Current(); 5532 i::Handle<i::Context> context = Utils::OpenHandle(this);
5553 if (IsDeadCheck(isolate, "v8::Context::ReattachGlobal()")) return; 5533 i::Isolate* isolate = context->GetIsolate();
5554 ENTER_V8(isolate); 5534 ENTER_V8(isolate);
5555 i::Object** ctx = reinterpret_cast<i::Object**>(this);
5556 i::Handle<i::Context> context =
5557 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx));
5558 i::Handle<i::JSGlobalProxy> global_proxy = 5535 i::Handle<i::JSGlobalProxy> global_proxy =
5559 i::Handle<i::JSGlobalProxy>::cast(Utils::OpenHandle(*global_object)); 5536 i::Handle<i::JSGlobalProxy>::cast(Utils::OpenHandle(*global_object));
5560 isolate->bootstrapper()->ReattachGlobal(context, global_proxy); 5537 isolate->bootstrapper()->ReattachGlobal(context, global_proxy);
5561 } 5538 }
5562 5539
5563 5540
5564 void Context::AllowCodeGenerationFromStrings(bool allow) { 5541 void Context::AllowCodeGenerationFromStrings(bool allow) {
5565 i::Isolate* isolate = i::Isolate::Current(); 5542 i::Handle<i::Context> context = Utils::OpenHandle(this);
5566 if (IsDeadCheck(isolate, "v8::Context::AllowCodeGenerationFromStrings()")) { 5543 i::Isolate* isolate = context->GetIsolate();
5567 return;
5568 }
5569 ENTER_V8(isolate); 5544 ENTER_V8(isolate);
5570 i::Object** ctx = reinterpret_cast<i::Object**>(this);
5571 i::Handle<i::Context> context =
5572 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx));
5573 context->set_allow_code_gen_from_strings( 5545 context->set_allow_code_gen_from_strings(
5574 allow ? isolate->heap()->true_value() : isolate->heap()->false_value()); 5546 allow ? isolate->heap()->true_value() : isolate->heap()->false_value());
5575 } 5547 }
5576 5548
5577 5549
5578 bool Context::IsCodeGenerationFromStringsAllowed() { 5550 bool Context::IsCodeGenerationFromStringsAllowed() {
5579 i::Isolate* isolate = i::Isolate::Current(); 5551 i::Handle<i::Context> context = Utils::OpenHandle(this);
5580 if (IsDeadCheck(isolate,
5581 "v8::Context::IsCodeGenerationFromStringsAllowed()")) {
5582 return false;
5583 }
5584 ENTER_V8(isolate);
5585 i::Object** ctx = reinterpret_cast<i::Object**>(this);
5586 i::Handle<i::Context> context =
5587 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx));
5588 return !context->allow_code_gen_from_strings()->IsFalse(); 5552 return !context->allow_code_gen_from_strings()->IsFalse();
5589 } 5553 }
5590 5554
5591 5555
5592 void Context::SetErrorMessageForCodeGenerationFromStrings( 5556 void Context::SetErrorMessageForCodeGenerationFromStrings(
5593 Handle<String> error) { 5557 Handle<String> error) {
5594 i::Isolate* isolate = i::Isolate::Current(); 5558 i::Handle<i::Context> context = Utils::OpenHandle(this);
5595 if (IsDeadCheck(isolate,
5596 "v8::Context::SetErrorMessageForCodeGenerationFromStrings()")) {
5597 return;
5598 }
5599 ENTER_V8(isolate);
5600 i::Object** ctx = reinterpret_cast<i::Object**>(this);
5601 i::Handle<i::Context> context =
5602 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx));
5603 i::Handle<i::String> error_handle = Utils::OpenHandle(*error); 5559 i::Handle<i::String> error_handle = Utils::OpenHandle(*error);
5604 context->set_error_message_for_code_gen_from_strings(*error_handle); 5560 context->set_error_message_for_code_gen_from_strings(*error_handle);
5605 } 5561 }
5606 5562
5607 5563
5608 Local<v8::Object> ObjectTemplate::NewInstance() { 5564 Local<v8::Object> ObjectTemplate::NewInstance() {
5609 i::Isolate* isolate = i::Isolate::Current(); 5565 i::Isolate* isolate = i::Isolate::Current();
5610 ON_BAILOUT(isolate, "v8::ObjectTemplate::NewInstance()", 5566 ON_BAILOUT(isolate, "v8::ObjectTemplate::NewInstance()",
5611 return Local<v8::Object>()); 5567 return Local<v8::Object>());
5612 LOG_API(isolate, "ObjectTemplate::NewInstance"); 5568 LOG_API(isolate, "ObjectTemplate::NewInstance");
(...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after
6640 } 6596 }
6641 6597
6642 6598
6643 CpuProfiler* Isolate::GetCpuProfiler() { 6599 CpuProfiler* Isolate::GetCpuProfiler() {
6644 i::CpuProfiler* cpu_profiler = 6600 i::CpuProfiler* cpu_profiler =
6645 reinterpret_cast<i::Isolate*>(this)->cpu_profiler(); 6601 reinterpret_cast<i::Isolate*>(this)->cpu_profiler();
6646 return reinterpret_cast<CpuProfiler*>(cpu_profiler); 6602 return reinterpret_cast<CpuProfiler*>(cpu_profiler);
6647 } 6603 }
6648 6604
6649 6605
6606 bool Isolate::InContext() {
6607 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6608 return isolate->context() != NULL;
6609 }
6610
6611
6650 v8::Local<v8::Context> Isolate::GetCurrentContext() { 6612 v8::Local<v8::Context> Isolate::GetCurrentContext() {
6651 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this); 6613 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6652 i::Context* context = internal_isolate->context(); 6614 i::Context* context = isolate->context();
6653 if (context == NULL) return Local<Context>(); 6615 if (context == NULL) return Local<Context>();
6654 i::Context* native_context = context->global_object()->native_context(); 6616 i::Context* native_context = context->global_object()->native_context();
6655 if (native_context == NULL) return Local<Context>(); 6617 if (native_context == NULL) return Local<Context>();
6656 return Utils::ToLocal(i::Handle<i::Context>(native_context)); 6618 return Utils::ToLocal(i::Handle<i::Context>(native_context));
6657 } 6619 }
6658 6620
6659 6621
6622 v8::Local<v8::Context> Isolate::GetCallingContext() {
6623 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6624 i::Handle<i::Object> calling = isolate->GetCallingNativeContext();
6625 if (calling.is_null()) return Local<Context>();
6626 return Utils::ToLocal(i::Handle<i::Context>::cast(calling));
6627 }
6628
6629
6630 v8::Local<v8::Context> Isolate::GetEnteredContext() {
6631 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6632 i::Handle<i::Object> last =
6633 isolate->handle_scope_implementer()->LastEnteredContext();
6634 if (last.is_null()) return Local<Context>();
6635 return Utils::ToLocal(i::Handle<i::Context>::cast(last));
6636 }
6637
6638
6660 void Isolate::SetObjectGroupId(const Persistent<Value>& object, 6639 void Isolate::SetObjectGroupId(const Persistent<Value>& object,
6661 UniqueId id) { 6640 UniqueId id) {
6662 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this); 6641 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this);
6663 internal_isolate->global_handles()->SetObjectGroupId( 6642 internal_isolate->global_handles()->SetObjectGroupId(
6664 Utils::OpenPersistent(object).location(), 6643 Utils::OpenPersistent(object).location(),
6665 id); 6644 id);
6666 } 6645 }
6667 6646
6668 6647
6669 void Isolate::SetReferenceFromGroup(UniqueId id, 6648 void Isolate::SetReferenceFromGroup(UniqueId id,
(...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after
7892 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7871 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7893 Address callback_address = 7872 Address callback_address =
7894 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7873 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7895 VMState<EXTERNAL> state(isolate); 7874 VMState<EXTERNAL> state(isolate);
7896 ExternalCallbackScope call_scope(isolate, callback_address); 7875 ExternalCallbackScope call_scope(isolate, callback_address);
7897 callback(info); 7876 callback(info);
7898 } 7877 }
7899 7878
7900 7879
7901 } } // namespace v8::internal 7880 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « samples/lineprocessor.cc ('k') | src/d8.cc » ('j') | test/cctest/test-heap.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698