From c25a92d76b4b07657fddd472c21e73881259164a Mon Sep 17 00:00:00 2001 From: "mstarzinger@chromium.org" Date: Tue, 24 Apr 2012 14:37:53 +0000 Subject: [PATCH] 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 --- include/v8.h | 30 +++++++++++++++++++++++++++--- src/api.cc | 11 ----------- test/cctest/test-api.cc | 18 ++++++++++++++++++ 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/include/v8.h b/include/v8.h index e4fffadc81..7b94a59a29 100644 --- a/include/v8.h +++ b/include/v8.h @@ -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(addr) == 1; } + static inline void SetEmbedderData(v8::Isolate* isolate, void* data) { + uint8_t* addr = reinterpret_cast(isolate) + + kIsolateEmbedderDataOffset; + *reinterpret_cast(addr) = data; + } + + static inline void* GetEmbedderData(v8::Isolate* isolate) { + uint8_t* addr = reinterpret_cast(isolate) + + kIsolateEmbedderDataOffset; + return *reinterpret_cast(addr); + } + static inline internal::Object** GetRoot(v8::Isolate* isolate, int index) { uint8_t* addr = reinterpret_cast(isolate) + kIsolateRootsOffset; return reinterpret_cast(addr + index * kApiPointerSize); @@ -4424,6 +4436,18 @@ Handle 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 diff --git a/src/api.cc b/src/api.cc index 124875a769..8cdd391239 100644 --- a/src/api.cc +++ b/src/api.cc @@ -5396,17 +5396,6 @@ void Isolate::Exit() { } -void Isolate::SetData(void* data) { - i::Isolate* isolate = reinterpret_cast(this); - isolate->SetData(data); -} - -void* Isolate::GetData() { - i::Isolate* isolate = reinterpret_cast(this); - return isolate->GetData(); -} - - String::Utf8Value::Utf8Value(v8::Handle obj) : str_(NULL), length_(0) { i::Isolate* isolate = i::Isolate::Current(); diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index ba83647910..6a5e6f89ca 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -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(0xacce55ed); + isolate->SetData(data1); + CHECK_EQ(data1, isolate->GetData()); + CHECK_EQ(data1, ISOLATE->GetData()); + static void* data2 = reinterpret_cast(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()); +}