Chromium Code Reviews| Index: test/cctest/test-api.cc |
| diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
| index 229607266004673f87054898df272440f22105f0..e076eaa362a786932fabfde67008ca31b8b34d6f 100644 |
| --- a/test/cctest/test-api.cc |
| +++ b/test/cctest/test-api.cc |
| @@ -10873,6 +10873,62 @@ THREADED_TEST(NestedHandleScopeAndContexts) { |
| } |
| +#if defined(V8_HOST_ARCH_IA32) |
| +static size_t entry_count = 0; |
| + |
| + |
| +__declspec(naked) static void entry_hook() { |
| + __asm { |
| + inc entry_count |
| + ret |
| + } |
| +} |
| + |
| + |
| +static void RunLoopInNewEnv() { |
| + v8::HandleScope outer; |
| + v8::Persistent<Context> env = Context::New(); |
| + env->Enter(); |
| + |
| + const char* script = |
| + "function bar() {" |
| + " var sum = 0;" |
| + " for (i = 0; i < 100; ++i)" |
| + " sum = foo(i);" |
| + " return sum;" |
| + "}" |
| + "function foo(i) { return i * i; }" |
|
danno
2012/06/27 23:01:54
To test optimized code, you can for V8 to optimize
Sigurður Ásgeirsson
2012/06/28 10:35:34
Done.
|
| + "bar();"; |
| + v8::Handle<v8::Value> value = CompileRun(script); |
| + CHECK(value->IsNumber()); |
| + CHECK_EQ(9801.0, v8::Number::Cast(*value)->Value()); |
| + env->Exit(); |
| +} |
| + |
| + |
| +THREADED_TEST(SetFunctionEntryHook) { |
| + // Reset the entry count to zero and set the entry hook. |
| + entry_count = 0; |
| + v8::V8::SetFunctionEntryHook(reinterpret_cast<uintptr_t>(entry_hook)); |
| + RunLoopInNewEnv(); |
| + // TODO(siggi): This will fail if ever V8 inlines the function foo(). |
| + CHECK_LE(102, entry_count); |
| + |
| + // Clear the entry hook and count. |
| + entry_count = 0; |
| + v8::V8::SetFunctionEntryHook(0); |
| + |
| + // Clear the compilation cache to make sure we don't reuse the |
| + // functions from the previous invocation. |
| + v8::internal::Isolate::Current()->compilation_cache()->Clear(); |
| + |
| + // Verify that entry hooking is now disabled. |
| + RunLoopInNewEnv(); |
| + CHECK_EQ(0, entry_count); |
| +} |
| +#endif |
| + |
| + |
| static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); } |