Skip to content

Commit

Permalink
Move context retrieval method around. Use delegation for implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
svenpanne@chromium.org committed Apr 9, 2013
1 parent 741ce3b commit d04de1f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
7 changes: 5 additions & 2 deletions include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -3036,6 +3036,9 @@ class V8EXPORT Isolate {
*/
CpuProfiler* GetCpuProfiler();

/** Returns the context that is on the top of the stack. */
Local<Context> GetCurrentContext();

private:
Isolate();
Isolate(const Isolate&);
Expand Down Expand Up @@ -3890,9 +3893,9 @@ class V8EXPORT Context {
/** Returns the last entered context. */
static Local<Context> GetEntered();

/** Returns the context that is on the top of the stack. */
// TODO(svenpanne) Actually deprecate this.
/** Deprecated. Use Isolate::GetCurrentContext instead. */
static Local<Context> GetCurrent();
static Local<Context> GetCurrent(Isolate* isolate);

/**
* Returns the context of the calling JavaScript code. That is the
Expand Down
24 changes: 10 additions & 14 deletions src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5007,20 +5007,7 @@ v8::Local<v8::Context> Context::GetCurrent() {
if (IsDeadCheck(isolate, "v8::Context::GetCurrent()")) {
return Local<Context>();
}
i::Handle<i::Object> current = isolate->native_context();
if (current.is_null()) return Local<Context>();
i::Handle<i::Context> context = i::Handle<i::Context>::cast(current);
return Utils::ToLocal(context);
}


v8::Local<v8::Context> Context::GetCurrent(Isolate* exported_isolate) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(exported_isolate);
ASSERT(isolate == i::Isolate::Current());
i::Handle<i::Object> current = isolate->native_context();
if (current.is_null()) return Local<Context>();
i::Handle<i::Context> context = i::Handle<i::Context>::cast(current);
return Utils::ToLocal(context);
return reinterpret_cast<Isolate*>(isolate)->GetCurrentContext();
}


Expand Down Expand Up @@ -5825,6 +5812,15 @@ CpuProfiler* Isolate::GetCpuProfiler() {
}


v8::Local<v8::Context> Isolate::GetCurrentContext() {
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this);
i::Handle<i::Object> current = internal_isolate->native_context();
if (current.is_null()) return Local<Context>();
i::Handle<i::Context> context = i::Handle<i::Context>::cast(current);
return Utils::ToLocal(context);
}


void V8::SetGlobalGCPrologueCallback(GCCallback callback) {
i::Isolate* isolate = i::Isolate::Current();
if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCPrologueCallback()")) return;
Expand Down
2 changes: 1 addition & 1 deletion test/cctest/test-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13410,7 +13410,7 @@ v8::Persistent<Context> calling_context2;
static v8::Handle<Value> GetCallingContextCallback(const v8::Arguments& args) {
ApiTestFuzzer::Fuzz();
CHECK(Context::GetCurrent() == calling_context0);
CHECK(Context::GetCurrent(args.GetIsolate()) == calling_context0);
CHECK(args.GetIsolate()->GetCurrentContext() == calling_context0);
CHECK(Context::GetCalling() == calling_context1);
CHECK(Context::GetEntered() == calling_context2);
return v8::Integer::New(42);
Expand Down

0 comments on commit d04de1f

Please sign in to comment.