| 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 20772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20783 .FromJust()); | 20783 .FromJust()); |
| 20784 | 20784 |
| 20785 // Calling with environment record as base. | 20785 // Calling with environment record as base. |
| 20786 TestReceiver(i, foreign_context->Global(), "func()"); | 20786 TestReceiver(i, foreign_context->Global(), "func()"); |
| 20787 // Calling with no base. | 20787 // Calling with no base. |
| 20788 TestReceiver(i, foreign_context->Global(), "(1,func)()"); | 20788 TestReceiver(i, foreign_context->Global(), "(1,func)()"); |
| 20789 } | 20789 } |
| 20790 | 20790 |
| 20791 | 20791 |
| 20792 uint8_t callback_fired = 0; | 20792 uint8_t callback_fired = 0; |
| 20793 uint8_t before_call_entered_callback_count1 = 0; |
| 20794 uint8_t before_call_entered_callback_count2 = 0; |
| 20793 | 20795 |
| 20794 | 20796 |
| 20795 void CallCompletedCallback1() { | 20797 void CallCompletedCallback1(v8::Isolate*) { |
| 20796 v8::base::OS::Print("Firing callback 1.\n"); | 20798 v8::base::OS::Print("Firing callback 1.\n"); |
| 20797 callback_fired ^= 1; // Toggle first bit. | 20799 callback_fired ^= 1; // Toggle first bit. |
| 20798 } | 20800 } |
| 20799 | 20801 |
| 20800 | 20802 |
| 20801 void CallCompletedCallback2() { | 20803 void CallCompletedCallback2(v8::Isolate*) { |
| 20802 v8::base::OS::Print("Firing callback 2.\n"); | 20804 v8::base::OS::Print("Firing callback 2.\n"); |
| 20803 callback_fired ^= 2; // Toggle second bit. | 20805 callback_fired ^= 2; // Toggle second bit. |
| 20804 } | 20806 } |
| 20805 | 20807 |
| 20806 | 20808 |
| 20809 void BeforeCallEnteredCallback1(v8::Isolate*) { |
| 20810 v8::base::OS::Print("Firing before call entered callback 1.\n"); |
| 20811 before_call_entered_callback_count1++; |
| 20812 } |
| 20813 |
| 20814 |
| 20815 void BeforeCallEnteredCallback2(v8::Isolate*) { |
| 20816 v8::base::OS::Print("Firing before call entered callback 2.\n"); |
| 20817 before_call_entered_callback_count2++; |
| 20818 } |
| 20819 |
| 20820 |
| 20807 void RecursiveCall(const v8::FunctionCallbackInfo<v8::Value>& args) { | 20821 void RecursiveCall(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 20808 int32_t level = | 20822 int32_t level = |
| 20809 args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromJust(); | 20823 args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromJust(); |
| 20810 if (level < 3) { | 20824 if (level < 3) { |
| 20811 level++; | 20825 level++; |
| 20812 v8::base::OS::Print("Entering recursion level %d.\n", level); | 20826 v8::base::OS::Print("Entering recursion level %d.\n", level); |
| 20813 char script[64]; | 20827 char script[64]; |
| 20814 i::Vector<char> script_vector(script, sizeof(script)); | 20828 i::Vector<char> script_vector(script, sizeof(script)); |
| 20815 i::SNPrintF(script_vector, "recursion(%d)", level); | 20829 i::SNPrintF(script_vector, "recursion(%d)", level); |
| 20816 CompileRun(script_vector.start()); | 20830 CompileRun(script_vector.start()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 20829 v8::Local<v8::FunctionTemplate> recursive_runtime = | 20843 v8::Local<v8::FunctionTemplate> recursive_runtime = |
| 20830 v8::FunctionTemplate::New(env->GetIsolate(), RecursiveCall); | 20844 v8::FunctionTemplate::New(env->GetIsolate(), RecursiveCall); |
| 20831 env->Global() | 20845 env->Global() |
| 20832 ->Set(env.local(), v8_str("recursion"), | 20846 ->Set(env.local(), v8_str("recursion"), |
| 20833 recursive_runtime->GetFunction(env.local()).ToLocalChecked()) | 20847 recursive_runtime->GetFunction(env.local()).ToLocalChecked()) |
| 20834 .FromJust(); | 20848 .FromJust(); |
| 20835 // Adding the same callback a second time has no effect. | 20849 // Adding the same callback a second time has no effect. |
| 20836 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1); | 20850 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1); |
| 20837 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1); | 20851 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1); |
| 20838 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback2); | 20852 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback2); |
| 20853 env->GetIsolate()->AddBeforeCallEnteredCallback(BeforeCallEnteredCallback1); |
| 20854 env->GetIsolate()->AddBeforeCallEnteredCallback(BeforeCallEnteredCallback2); |
| 20855 env->GetIsolate()->AddBeforeCallEnteredCallback(BeforeCallEnteredCallback1); |
| 20839 v8::base::OS::Print("--- Script (1) ---\n"); | 20856 v8::base::OS::Print("--- Script (1) ---\n"); |
| 20857 callback_fired = 0; |
| 20858 before_call_entered_callback_count1 = 0; |
| 20859 before_call_entered_callback_count2 = 0; |
| 20840 Local<Script> script = | 20860 Local<Script> script = |
| 20841 v8::Script::Compile(env.local(), v8_str("recursion(0)")).ToLocalChecked(); | 20861 v8::Script::Compile(env.local(), v8_str("recursion(0)")).ToLocalChecked(); |
| 20842 script->Run(env.local()).ToLocalChecked(); | 20862 script->Run(env.local()).ToLocalChecked(); |
| 20843 CHECK_EQ(3, callback_fired); | 20863 CHECK_EQ(3, callback_fired); |
| 20864 CHECK_EQ(4, before_call_entered_callback_count1); |
| 20865 CHECK_EQ(4, before_call_entered_callback_count2); |
| 20844 | 20866 |
| 20845 v8::base::OS::Print("\n--- Script (2) ---\n"); | 20867 v8::base::OS::Print("\n--- Script (2) ---\n"); |
| 20846 callback_fired = 0; | 20868 callback_fired = 0; |
| 20869 before_call_entered_callback_count1 = 0; |
| 20870 before_call_entered_callback_count2 = 0; |
| 20847 env->GetIsolate()->RemoveCallCompletedCallback(CallCompletedCallback1); | 20871 env->GetIsolate()->RemoveCallCompletedCallback(CallCompletedCallback1); |
| 20872 env->GetIsolate()->RemoveBeforeCallEnteredCallback( |
| 20873 BeforeCallEnteredCallback1); |
| 20848 script->Run(env.local()).ToLocalChecked(); | 20874 script->Run(env.local()).ToLocalChecked(); |
| 20849 CHECK_EQ(2, callback_fired); | 20875 CHECK_EQ(2, callback_fired); |
| 20876 CHECK_EQ(0, before_call_entered_callback_count1); |
| 20877 CHECK_EQ(4, before_call_entered_callback_count2); |
| 20850 | 20878 |
| 20851 v8::base::OS::Print("\n--- Function ---\n"); | 20879 v8::base::OS::Print("\n--- Function ---\n"); |
| 20852 callback_fired = 0; | 20880 callback_fired = 0; |
| 20881 before_call_entered_callback_count1 = 0; |
| 20882 before_call_entered_callback_count2 = 0; |
| 20853 Local<Function> recursive_function = Local<Function>::Cast( | 20883 Local<Function> recursive_function = Local<Function>::Cast( |
| 20854 env->Global()->Get(env.local(), v8_str("recursion")).ToLocalChecked()); | 20884 env->Global()->Get(env.local(), v8_str("recursion")).ToLocalChecked()); |
| 20855 v8::Local<Value> args[] = {v8_num(0)}; | 20885 v8::Local<Value> args[] = {v8_num(0)}; |
| 20856 recursive_function->Call(env.local(), env->Global(), 1, args) | 20886 recursive_function->Call(env.local(), env->Global(), 1, args) |
| 20857 .ToLocalChecked(); | 20887 .ToLocalChecked(); |
| 20858 CHECK_EQ(2, callback_fired); | 20888 CHECK_EQ(2, callback_fired); |
| 20889 CHECK_EQ(0, before_call_entered_callback_count1); |
| 20890 CHECK_EQ(4, before_call_entered_callback_count2); |
| 20859 } | 20891 } |
| 20860 | 20892 |
| 20861 | 20893 |
| 20862 void CallCompletedCallbackNoException() { | 20894 void CallCompletedCallbackNoException(v8::Isolate*) { |
| 20863 v8::HandleScope scope(CcTest::isolate()); | 20895 v8::HandleScope scope(CcTest::isolate()); |
| 20864 CompileRun("1+1;"); | 20896 CompileRun("1+1;"); |
| 20865 } | 20897 } |
| 20866 | 20898 |
| 20867 | 20899 |
| 20868 void CallCompletedCallbackException() { | 20900 void CallCompletedCallbackException(v8::Isolate*) { |
| 20869 v8::HandleScope scope(CcTest::isolate()); | 20901 v8::HandleScope scope(CcTest::isolate()); |
| 20870 CompileRun("throw 'second exception';"); | 20902 CompileRun("throw 'second exception';"); |
| 20871 } | 20903 } |
| 20872 | 20904 |
| 20873 | 20905 |
| 20874 TEST(CallCompletedCallbackOneException) { | 20906 TEST(CallCompletedCallbackOneException) { |
| 20875 LocalContext env; | 20907 LocalContext env; |
| 20876 v8::HandleScope scope(env->GetIsolate()); | 20908 v8::HandleScope scope(env->GetIsolate()); |
| 20877 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallbackNoException); | 20909 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallbackNoException); |
| 20878 CompileRun("throw 'exception';"); | 20910 CompileRun("throw 'exception';"); |
| (...skipping 4056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 24935 CHECK(proxy->GetTarget()->SameValue(target)); | 24967 CHECK(proxy->GetTarget()->SameValue(target)); |
| 24936 CHECK(proxy->GetHandler()->SameValue(handler)); | 24968 CHECK(proxy->GetHandler()->SameValue(handler)); |
| 24937 | 24969 |
| 24938 proxy->Revoke(); | 24970 proxy->Revoke(); |
| 24939 CHECK(proxy->IsProxy()); | 24971 CHECK(proxy->IsProxy()); |
| 24940 CHECK(!target->IsProxy()); | 24972 CHECK(!target->IsProxy()); |
| 24941 CHECK(proxy->IsRevoked()); | 24973 CHECK(proxy->IsRevoked()); |
| 24942 CHECK(proxy->GetTarget()->SameValue(target)); | 24974 CHECK(proxy->GetTarget()->SameValue(target)); |
| 24943 CHECK(proxy->GetHandler()->IsNull()); | 24975 CHECK(proxy->GetHandler()->IsNull()); |
| 24944 } | 24976 } |
| OLD | NEW |