OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 15 matching lines...) Expand all Loading... |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include <limits.h> | 28 #include <limits.h> |
29 | 29 |
30 #include "v8.h" | 30 #include "v8.h" |
31 | 31 |
32 #include "api.h" | 32 #include "api.h" |
33 #include "isolate.h" | 33 #include "isolate.h" |
34 #include "compilation-cache.h" | 34 #include "compilation-cache.h" |
35 #include "execution.h" | 35 #include "execution.h" |
| 36 #include "objects.h" |
36 #include "snapshot.h" | 37 #include "snapshot.h" |
37 #include "platform.h" | 38 #include "platform.h" |
38 #include "utils.h" | 39 #include "utils.h" |
39 #include "cctest.h" | 40 #include "cctest.h" |
40 #include "parser.h" | 41 #include "parser.h" |
41 #include "unicode-inl.h" | 42 #include "unicode-inl.h" |
42 | 43 |
43 static const bool kLogThreading = false; | 44 static const bool kLogThreading = false; |
44 | 45 |
45 static bool IsNaN(double x) { | 46 static bool IsNaN(double x) { |
(...skipping 10820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10866 v8::Persistent<Context> env = Context::New(); | 10867 v8::Persistent<Context> env = Context::New(); |
10867 env->Enter(); | 10868 env->Enter(); |
10868 v8::Handle<Value> value = NestedScope(env); | 10869 v8::Handle<Value> value = NestedScope(env); |
10869 v8::Handle<String> str(value->ToString()); | 10870 v8::Handle<String> str(value->ToString()); |
10870 CHECK(!str.IsEmpty()); | 10871 CHECK(!str.IsEmpty()); |
10871 env->Exit(); | 10872 env->Exit(); |
10872 env.Dispose(); | 10873 env.Dispose(); |
10873 } | 10874 } |
10874 | 10875 |
10875 | 10876 |
| 10877 static i::Handle<i::JSFunction>* foo_ptr = NULL; |
| 10878 static int foo_count = 0; |
| 10879 static i::Handle<i::JSFunction>* bar_ptr = NULL; |
| 10880 static int bar_count = 0; |
| 10881 |
| 10882 |
| 10883 static void entry_hook(uintptr_t function, |
| 10884 uintptr_t return_addr_location) { |
| 10885 i::Code* code = i::Code::GetCodeFromTargetAddress( |
| 10886 reinterpret_cast<i::Address>(function)); |
| 10887 CHECK(code != NULL); |
| 10888 |
| 10889 if (bar_ptr != NULL && code == (*bar_ptr)->code()) |
| 10890 ++bar_count; |
| 10891 |
| 10892 if (foo_ptr != NULL && code == (*foo_ptr)->code()) |
| 10893 ++foo_count; |
| 10894 |
| 10895 // TODO(siggi): Verify return_addr_location. |
| 10896 } |
| 10897 |
| 10898 |
| 10899 static void RunLoopInNewEnv() { |
| 10900 bar_ptr = NULL; |
| 10901 foo_ptr = NULL; |
| 10902 |
| 10903 v8::HandleScope outer; |
| 10904 v8::Persistent<Context> env = Context::New(); |
| 10905 env->Enter(); |
| 10906 |
| 10907 const char* script = |
| 10908 "function bar() {" |
| 10909 " var sum = 0;" |
| 10910 " for (i = 0; i < 100; ++i)" |
| 10911 " sum = foo(i);" |
| 10912 " return sum;" |
| 10913 "}" |
| 10914 "function foo(i) { return i * i; }"; |
| 10915 CompileRun(script); |
| 10916 i::Handle<i::JSFunction> bar = |
| 10917 i::Handle<i::JSFunction>::cast( |
| 10918 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("bar")))); |
| 10919 ASSERT(*bar); |
| 10920 |
| 10921 i::Handle<i::JSFunction> foo = |
| 10922 i::Handle<i::JSFunction>::cast( |
| 10923 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("foo")))); |
| 10924 ASSERT(*foo); |
| 10925 |
| 10926 bar_ptr = &bar; |
| 10927 foo_ptr = &foo; |
| 10928 |
| 10929 v8::Handle<v8::Value> value = CompileRun("bar();"); |
| 10930 CHECK(value->IsNumber()); |
| 10931 CHECK_EQ(9801.0, v8::Number::Cast(*value)->Value()); |
| 10932 |
| 10933 // Test the optimized codegen path. |
| 10934 value = CompileRun("%OptimizeFunctionOnNextCall(foo);" |
| 10935 "bar();"); |
| 10936 CHECK(value->IsNumber()); |
| 10937 CHECK_EQ(9801.0, v8::Number::Cast(*value)->Value()); |
| 10938 |
| 10939 env->Exit(); |
| 10940 } |
| 10941 |
| 10942 |
| 10943 TEST(SetFunctionEntryHook) { |
| 10944 i::FLAG_allow_natives_syntax = true; |
| 10945 |
| 10946 // Test setting and resetting the entry hook. |
| 10947 // Nulling it should always succeed. |
| 10948 CHECK(v8::V8::SetFunctionEntryHook(NULL)); |
| 10949 |
| 10950 CHECK(v8::V8::SetFunctionEntryHook(entry_hook)); |
| 10951 // Setting a hook while one's active should fail. |
| 10952 CHECK_EQ(false, v8::V8::SetFunctionEntryHook(entry_hook)); |
| 10953 |
| 10954 CHECK(v8::V8::SetFunctionEntryHook(NULL)); |
| 10955 |
| 10956 // Reset the entry count to zero and set the entry hook. |
| 10957 bar_count = 0; |
| 10958 foo_count = 0; |
| 10959 CHECK(v8::V8::SetFunctionEntryHook(entry_hook)); |
| 10960 RunLoopInNewEnv(); |
| 10961 |
| 10962 CHECK_EQ(2, bar_count); |
| 10963 CHECK_EQ(200, foo_count); |
| 10964 |
| 10965 // Clear the entry hook and count. |
| 10966 bar_count = 0; |
| 10967 foo_count = 0; |
| 10968 v8::V8::SetFunctionEntryHook(NULL); |
| 10969 |
| 10970 // Clear the compilation cache to make sure we don't reuse the |
| 10971 // functions from the previous invocation. |
| 10972 v8::internal::Isolate::Current()->compilation_cache()->Clear(); |
| 10973 |
| 10974 // Verify that entry hooking is now disabled. |
| 10975 RunLoopInNewEnv(); |
| 10976 CHECK(0u == bar_count); |
| 10977 CHECK(0u == foo_count); |
| 10978 } |
| 10979 |
| 10980 |
10876 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); } | 10981 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); } |
10877 | 10982 |
10878 | 10983 |
10879 THREADED_TEST(ExternalAllocatedMemory) { | 10984 THREADED_TEST(ExternalAllocatedMemory) { |
10880 v8::HandleScope outer; | 10985 v8::HandleScope outer; |
10881 v8::Persistent<Context> env(Context::New()); | 10986 v8::Persistent<Context> env(Context::New()); |
10882 CHECK(!env.IsEmpty()); | 10987 CHECK(!env.IsEmpty()); |
10883 const intptr_t kSize = 1024*1024; | 10988 const intptr_t kSize = 1024*1024; |
10884 CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(kSize)), | 10989 CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(kSize)), |
10885 cast(kSize)); | 10990 cast(kSize)); |
(...skipping 5920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16806 " x++; \n" | 16911 " x++; \n" |
16807 " throw new Error('again'); \n" // This is the new uncaught error. | 16912 " throw new Error('again'); \n" // This is the new uncaught error. |
16808 "} \n"; | 16913 "} \n"; |
16809 CompileRun(throw_again); | 16914 CompileRun(throw_again); |
16810 CHECK(try_catch.HasCaught()); | 16915 CHECK(try_catch.HasCaught()); |
16811 Local<Message> message = try_catch.Message(); | 16916 Local<Message> message = try_catch.Message(); |
16812 CHECK(!message.IsEmpty()); | 16917 CHECK(!message.IsEmpty()); |
16813 CHECK_EQ(6, message->GetLineNumber()); | 16918 CHECK_EQ(6, message->GetLineNumber()); |
16814 } | 16919 } |
16815 } | 16920 } |
OLD | NEW |