Reviewers: ,

Message:
Add a GetIsolate() method to v8::FunctionTemplate and v8::ObjectTemplate to make
life a little easier for embedders.

Description:
api: add {Function,Object}Template::GetIsolate()

Please review this at https://codereview.chromium.org/64643008/

Affected files (+13, -1 lines):
  M include/v8.h
  M src/api.cc
  M test/cctest/test-api.cc


Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 1f8cbfd83b0e0986336b9b0bcef6985d0659a4ef..8b4b00a1c9b7a2cc6cfb5fc93280ba042157573c 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -3115,6 +3115,9 @@ class V8_EXPORT Template : public Data {
                                Local<AccessorSignature>(),
                            AccessControl settings = DEFAULT);

+  /** Returns the isolate associated with the template. */
+  v8::Isolate* GetIsolate();
+
  private:
   Template();

Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 401007b4359b6c86c4184dd9183c561adb37a58f..fa2f37206715b98e227c1f19de1f7cfa671072be 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -977,6 +977,12 @@ void Template::SetAccessorProperty(
 }


+Isolate* Template::GetIsolate() {
+  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
+  return reinterpret_cast<Isolate*>(isolate);
+}
+
+
 // --- F u n c t i o n   T e m p l a t e ---
 static void InitializeFunctionTemplate(
       i::Handle<i::FunctionTemplateInfo> info) {
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index f33d02b729abdee20c0669ee2e0ecc46099b7966..c5932c0905db5297343d42e9f4020666df995eab 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -1015,6 +1015,7 @@ static void TestFunctionTemplateInitializer(Handler handler,

     Local<v8::FunctionTemplate> fun_templ =
         v8::FunctionTemplate::New(handler);
+    ASSERT_EQ(fun_templ->GetIsolate(), env->GetIsolate());
     Local<Function> fun = fun_templ->GetFunction();
     env->Global()->Set(v8_str("obj"), fun);
     Local<Script> script = v8_compile("obj()");
@@ -1761,8 +1762,10 @@ THREADED_TEST(GlobalPrototype) {


 THREADED_TEST(ObjectTemplate) {
-  v8::HandleScope scope(CcTest::isolate());
+  v8::Isolate* isolate = CcTest::isolate();
+  v8::HandleScope scope(isolate);
   Local<ObjectTemplate> templ1 = ObjectTemplate::New();
+  ASSERT_EQ(templ1->GetIsolate(), isolate);
   templ1->Set("x", v8_num(10));
   templ1->Set("y", v8_num(13));
   LocalContext env;


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to