Revision: 11426
Author:   [email protected]
Date:     Tue Apr 24 07:37:53 2012
Log:      Make Isolate::GetData and Isolate::SetData inlineable.

[email protected]
TEST=cctest/test-api/IsolateEmbedderData

Review URL: https://chromiumcodereview.appspot.com/10196013
http://code.google.com/p/v8/source/detail?r=11426

Modified:
 /branches/bleeding_edge/include/v8.h
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/include/v8.h        Mon Apr 23 08:09:59 2012
+++ /branches/bleeding_edge/include/v8.h        Tue Apr 24 07:37:53 2012
@@ -2816,13 +2816,13 @@
   /**
    * 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();
@@ -3960,6 +3960,18 @@
uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset;
     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;
@@ -4422,6 +4434,18 @@
   S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
   return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
 }
+
+
+void Isolate::SetData(void* data) {
+  typedef internal::Internals I;
+  I::SetEmbedderData(this, data);
+}
+
+
+void* Isolate::GetData() {
+  typedef internal::Internals I;
+  return I::GetEmbedderData(this);
+}


 /**
=======================================
--- /branches/bleeding_edge/src/api.cc  Fri Apr 20 03:42:12 2012
+++ /branches/bleeding_edge/src/api.cc  Tue Apr 24 07:37:53 2012
@@ -5394,17 +5394,6 @@
   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
   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)
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Mon Apr 23 08:09:59 2012
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Tue Apr 24 07:37:53 2012
@@ -16504,3 +16504,21 @@
   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());
+}

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to