Commit 48d327d0 authored by danno@chromium.org's avatar danno@chromium.org

Let the embedder store arbitrary Values via Context::SetData

In WebKit, we would like to store a void* to a data structure that contains
lots of exciting per-context data. The current API restricts us to storing only
Strings, which is less useful.

I've also cleaned up the implementation of GetData to be less convoluted.

Review URL: https://codereview.chromium.org/10907189
Patch from Adam Barth <abarth@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12520 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 204d22a5
...@@ -3718,7 +3718,7 @@ class V8EXPORT Context { ...@@ -3718,7 +3718,7 @@ class V8EXPORT Context {
* with the debugger to provide additional information on the context through * with the debugger to provide additional information on the context through
* the debugger API. * the debugger API.
*/ */
void SetData(Handle<String> data); void SetData(Handle<Value> data);
Local<Value> GetData(); Local<Value> GetData();
/** /**
......
...@@ -765,7 +765,7 @@ void Context::Exit() { ...@@ -765,7 +765,7 @@ void Context::Exit() {
} }
void Context::SetData(v8::Handle<String> data) { void Context::SetData(v8::Handle<Value> data) {
i::Handle<i::Context> env = Utils::OpenHandle(this); i::Handle<i::Context> env = Utils::OpenHandle(this);
i::Isolate* isolate = env->GetIsolate(); i::Isolate* isolate = env->GetIsolate();
if (IsDeadCheck(isolate, "v8::Context::SetData()")) return; if (IsDeadCheck(isolate, "v8::Context::SetData()")) return;
...@@ -781,16 +781,13 @@ v8::Local<v8::Value> Context::GetData() { ...@@ -781,16 +781,13 @@ v8::Local<v8::Value> Context::GetData() {
i::Handle<i::Context> env = Utils::OpenHandle(this); i::Handle<i::Context> env = Utils::OpenHandle(this);
i::Isolate* isolate = env->GetIsolate(); i::Isolate* isolate = env->GetIsolate();
if (IsDeadCheck(isolate, "v8::Context::GetData()")) { if (IsDeadCheck(isolate, "v8::Context::GetData()")) {
return v8::Local<Value>(); return Local<Value>();
} }
i::Object* raw_result = NULL;
ASSERT(env->IsNativeContext()); ASSERT(env->IsNativeContext());
if (env->IsNativeContext()) { if (!env->IsNativeContext()) {
raw_result = env->data();
} else {
return Local<Value>(); return Local<Value>();
} }
i::Handle<i::Object> result(raw_result, isolate); i::Handle<i::Object> result(env->data(), isolate);
return Utils::ToLocal(result); return Utils::ToLocal(result);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment