Make Isolate::GetData and Isolate::SetData inlineable.

R=svenpanne@chromium.org
TEST=cctest/test-api/IsolateEmbedderData

Review URL: https://chromiumcodereview.appspot.com/10196013

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11426 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
mstarzinger@chromium.org 2012-04-24 14:37:53 +00:00
parent a139e38c0b
commit c25a92d76b
3 changed files with 45 additions and 14 deletions

View File

@ -2816,13 +2816,13 @@ class V8EXPORT Isolate {
/**
* Associate embedder-specific data with the isolate
*/
void SetData(void* data);
inline void SetData(void* data);
/**
* Retrive embedder-specific data from the isolate.
* Retrieve embedder-specific data from the isolate.
* Returns NULL if SetData has never been called.
*/
void* GetData();
inline void* GetData();
private:
Isolate();
@ -3961,6 +3961,18 @@ class Internals {
return *reinterpret_cast<int*>(addr) == 1;
}
static inline void SetEmbedderData(v8::Isolate* isolate, void* data) {
uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
kIsolateEmbedderDataOffset;
*reinterpret_cast<void**>(addr) = data;
}
static inline void* GetEmbedderData(v8::Isolate* isolate) {
uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
kIsolateEmbedderDataOffset;
return *reinterpret_cast<void**>(addr);
}
static inline internal::Object** GetRoot(v8::Isolate* isolate, int index) {
uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize);
@ -4424,6 +4436,18 @@ Handle<Boolean> False(Isolate* isolate) {
}
void Isolate::SetData(void* data) {
typedef internal::Internals I;
I::SetEmbedderData(this, data);
}
void* Isolate::GetData() {
typedef internal::Internals I;
return I::GetEmbedderData(this);
}
/**
* \example shell.cc
* A simple shell that takes a list of expressions on the

View File

@ -5396,17 +5396,6 @@ void Isolate::Exit() {
}
void Isolate::SetData(void* data) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->SetData(data);
}
void* Isolate::GetData() {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
return isolate->GetData();
}
String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj)
: str_(NULL), length_(0) {
i::Isolate* isolate = i::Isolate::Current();

View File

@ -16504,3 +16504,21 @@ TEST(StaticGettersAfterDeath) {
CHECK(v8::False(isolate).IsEmpty());
CHECK_EQ(9, fatal_error_callback_counter);
}
TEST(IsolateEmbedderData) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
CHECK_EQ(NULL, isolate->GetData());
CHECK_EQ(NULL, ISOLATE->GetData());
static void* data1 = reinterpret_cast<void*>(0xacce55ed);
isolate->SetData(data1);
CHECK_EQ(data1, isolate->GetData());
CHECK_EQ(data1, ISOLATE->GetData());
static void* data2 = reinterpret_cast<void*>(0xdecea5ed);
ISOLATE->SetData(data2);
CHECK_EQ(data2, isolate->GetData());
CHECK_EQ(data2, ISOLATE->GetData());
ISOLATE->TearDown();
CHECK_EQ(data2, isolate->GetData());
CHECK_EQ(data2, ISOLATE->GetData());
}