Reviewers: Sven Panne,

Description:
Deprecate SetFunctionEntryHook and use Isolate ctor parameter instead

This will allow for initializing the Isolate at creation time in the
future.

Users of V8::SetFunctionEntryHook should pass the entry hook to
Isolate::New instead

LOG=y
[email protected]
BUG=none

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

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+32, -27 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 7a2215e5484fa9e367428ba28aacaffed7e22a68..e6ea40c63483d3daf8fa02c99ea9e2de65765b88 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -4243,6 +4243,21 @@ class V8_EXPORT HeapStatistics {

 class RetainedObjectInfo;

+
+/**
+ * FunctionEntryHook is the type of the profile entry hook called at entry to
+ * any generated function when function-level profiling is enabled.
+ *
+ * \param function the address of the function that's being entered.
+ * \param return_addr_location points to a location on stack where the machine
+ *    return address resides. This can be used to identify the caller of
+ * \p function, and/or modified to divert execution when \p function exits.
+ *
+ * \note the entry hook must not cause garbage collection.
+ */
+typedef void (*FunctionEntryHook)(uintptr_t function,
+                                  uintptr_t return_addr_location);
+
 /**
  * Isolate represents an isolated instance of the V8 engine.  V8
  * isolates have completely separate states.  Objects from one isolate
@@ -4361,8 +4376,17 @@ class V8_EXPORT Isolate {
    *
    * When an isolate is no longer used its resources should be freed
    * by calling Dispose().  Using the delete operator is not allowed.
+   *
+   * The optional parameter \p entry_hook allows the host application to
+   * provide the address of a function that's invoked on entry to every
+   * V8-generated function.  Note that \p entry_hook is invoked at the very
+   * start of each generated function. Furthermore, if an \p entry_hook is
+   * given, V8 will always run without a context snapshot.
+   *
+   * \param entry_hook a function that will be invoked on entry to every
+   *   V8-generated function.
    */
-  static Isolate* New();
+  static Isolate* New(FunctionEntryHook entry_hook = NULL);

   /**
    * Returns the entered isolate for the current thread or NULL in
@@ -4751,21 +4775,6 @@ typedef uintptr_t (*ReturnAddressLocationResolver)(


 /**
- * FunctionEntryHook is the type of the profile entry hook called at entry to
- * any generated function when function-level profiling is enabled.
- *
- * \param function the address of the function that's being entered.
- * \param return_addr_location points to a location on stack where the machine
- *    return address resides. This can be used to identify the caller of
- * \p function, and/or modified to divert execution when \p function exits.
- *
- * \note the entry hook must not cause garbage collection.
- */
-typedef void (*FunctionEntryHook)(uintptr_t function,
-                                  uintptr_t return_addr_location);
-
-
-/**
  * A JIT code event is issued each time code is added, moved or removed.
  *
  * \note removal events are not currently issued.
@@ -5069,6 +5078,8 @@ class V8_EXPORT V8 {
    * \returns true on success on supported platforms, false on failure.
    * \note Setting an entry hook can only be done very early in an isolates
    *   lifetime, and once set, the entry hook cannot be revoked.
+   *
+   * Deprecated, will be removed. Use Isolate::New(entry_hook) instead.
    */
   static bool SetFunctionEntryHook(Isolate* isolate,
                                    FunctionEntryHook entry_hook);
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index e4a00658c5cf3843b572924afe9d426b6a3039f7..6f3b1126a3f663364c9dd7a974b791ac51c3e811 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -6662,8 +6662,11 @@ Isolate* Isolate::GetCurrent() {
 }


-Isolate* Isolate::New() {
+Isolate* Isolate::New(FunctionEntryHook entry_hook) {
   i::Isolate* isolate = new i::Isolate();
+  if (entry_hook) {
+    isolate->set_function_entry_hook(entry_hook);
+  }
   return reinterpret_cast<Isolate*>(isolate);
 }

Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 0c65e674c9135fc5dbda8d95443a904d2debfe00..5aa87079435ca33ae3d6cad3ac24c9acc3ebb134 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -14171,13 +14171,7 @@ void SetFunctionEntryHookTest::RunLoopInNewEnv(v8::Isolate* isolate) {

 void SetFunctionEntryHookTest::RunTest() {
   // Work in a new isolate throughout.
-  v8::Isolate* isolate = v8::Isolate::New();
-
-  // Test setting the entry hook on the new isolate.
-  CHECK(v8::V8::SetFunctionEntryHook(isolate, EntryHook));
-
-  // Replacing the hook, once set should fail.
-  CHECK_EQ(false, v8::V8::SetFunctionEntryHook(isolate, EntryHook));
+  v8::Isolate* isolate = v8::Isolate::New(EntryHook);

   {
     v8::Isolate::Scope scope(isolate);
@@ -14211,9 +14205,6 @@ void SetFunctionEntryHookTest::RunTest() {
     // We should record no invocations in this isolate.
     CHECK_EQ(0, static_cast<int>(invocations_.size()));
   }
-  // Since the isolate has been used, we shouldn't be able to set an entry
-  // hook anymore.
-  CHECK_EQ(false, v8::V8::SetFunctionEntryHook(isolate, EntryHook));

   isolate->Dispose();
 }


--
--
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/d/optout.

Reply via email to