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 20783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20794 "setAge(100);" | 20794 "setAge(100);" |
20795 "setAge(101);" | 20795 "setAge(101);" |
20796 "setAge(102);" | 20796 "setAge(102);" |
20797 "%OptimizeFunctionOnNextCall(setAge);" | 20797 "%OptimizeFunctionOnNextCall(setAge);" |
20798 "setAge(103);"); | 20798 "setAge(103);"); |
20799 ExpectInt32("obj.age", 100000); | 20799 ExpectInt32("obj.age", 100000); |
20800 ExpectInt32("obj.interceptor_age", 103); | 20800 ExpectInt32("obj.interceptor_age", 103); |
20801 } | 20801 } |
20802 | 20802 |
20803 | 20803 |
20804 class RequestInterruptTestBase { | |
20805 public: | |
20806 RequestInterruptTestBase() | |
20807 : env_(), | |
20808 isolate_(env_->GetIsolate()), | |
20809 sem_(0), | |
20810 warmup_(20000), | |
20811 should_continue_(true) { | |
20812 } | |
20813 | |
20814 virtual ~RequestInterruptTestBase() { } | |
20815 | |
20816 virtual void TestBody() = 0; | |
20817 | |
20818 void RunTest() { | |
20819 i::FLAG_print_opt_code = true; | |
20820 i::FLAG_code_comments = true; | |
20821 i::FLAG_print_code_stubs = true; | |
20822 InterruptThread i_thread(this); | |
20823 i_thread.Start(); | |
20824 | |
20825 v8::HandleScope handle_scope(isolate_); | |
20826 | |
20827 TestBody(); | |
20828 | |
20829 isolate_->ClearInterrupt(); | |
20830 } | |
20831 | |
20832 void WakeUpInterruptor() { | |
20833 sem_.Signal(); | |
20834 } | |
20835 | |
20836 bool should_continue() const { return should_continue_; } | |
20837 | |
20838 bool ShouldContinue() { | |
20839 if (warmup_ > 0) { | |
20840 if (--warmup_ == 0) { | |
20841 WakeUpInterruptor(); | |
20842 } | |
20843 } | |
20844 | |
20845 return should_continue_; | |
20846 } | |
20847 | |
20848 protected: | |
20849 static void ShouldContinueCallback( | |
20850 const v8::FunctionCallbackInfo<Value>& info) { | |
20851 RequestInterruptTestBase* test = | |
20852 reinterpret_cast<RequestInterruptTestBase*>( | |
20853 info.Data().As<v8::External>()->Value()); | |
20854 info.GetReturnValue().Set(test->ShouldContinue()); | |
20855 } | |
20856 | |
20857 class InterruptThread : public i::Thread { | |
20858 public: | |
20859 explicit InterruptThread(RequestInterruptTestBase* test) | |
20860 : Thread("RequestInterruptTest"), test_(test) {} | |
20861 | |
20862 virtual void Run() { | |
20863 test_->sem_.Wait(); | |
20864 test_->isolate_->RequestInterrupt(&OnInterrupt, test_); | |
20865 } | |
20866 | |
20867 static void OnInterrupt(v8::Isolate* isolate, void* data) { | |
20868 reinterpret_cast<RequestInterruptTestBase*>(data)-> | |
20869 should_continue_ = false; | |
20870 } | |
20871 | |
20872 private: | |
20873 RequestInterruptTestBase* test_; | |
20874 }; | |
20875 | |
20876 LocalContext env_; | |
20877 v8::Isolate* isolate_; | |
20878 i::Semaphore sem_; | |
20879 int warmup_; | |
20880 bool should_continue_; | |
20881 }; | |
20882 | |
20883 | |
20884 class RequestInterruptTestWithFunctionCall : public RequestInterruptTestBase { | |
20885 public: | |
20886 virtual void TestBody() { | |
20887 Local<Function> func = Function::New( | |
20888 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)); | |
20889 env_->Global()->Set(v8_str("ShouldContinue"), func); | |
20890 | |
20891 CompileRun("while (ShouldContinue()) { }"); | |
20892 } | |
20893 }; | |
20894 | |
20895 | |
20896 class RequestInterruptTestWithMethodCall : public RequestInterruptTestBase { | |
20897 public: | |
20898 virtual void TestBody() { | |
20899 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); | |
20900 v8::Local<v8::Template> proto = t->PrototypeTemplate(); | |
20901 proto->Set(v8_str("shouldContinue"), Function::New( | |
20902 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); | |
20903 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); | |
20904 | |
20905 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); | |
20906 } | |
20907 }; | |
20908 | |
20909 | |
20910 class RequestInterruptTestWithAccessor : public RequestInterruptTestBase { | |
20911 public: | |
20912 virtual void TestBody() { | |
20913 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); | |
20914 v8::Local<v8::Template> proto = t->PrototypeTemplate(); | |
20915 proto->SetAccessorProperty(v8_str("shouldContinue"), FunctionTemplate::New( | |
20916 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); | |
20917 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); | |
20918 | |
20919 CompileRun("var obj = new Klass; while (obj.shouldContinue) { }"); | |
20920 } | |
20921 }; | |
20922 | |
20923 | |
20924 class RequestInterruptTestWithNativeAccessor : public RequestInterruptTestBase { | |
20925 public: | |
20926 virtual void TestBody() { | |
20927 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); | |
20928 v8::Local<v8::Template> proto = t->PrototypeTemplate(); | |
20929 proto->SetNativeDataProperty(v8_str("shouldContinue"), | |
20930 &ShouldContinueNativeGetter, | |
20931 NULL, | |
20932 v8::External::New(isolate_, this)); | |
20933 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); | |
20934 | |
20935 CompileRun("var obj = new Klass; while (obj.shouldContinue) { }"); | |
20936 } | |
20937 | |
20938 private: | |
20939 static void ShouldContinueNativeGetter( | |
20940 Local<String> property, | |
20941 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
20942 RequestInterruptTestBase* test = | |
20943 reinterpret_cast<RequestInterruptTestBase*>( | |
20944 info.Data().As<v8::External>()->Value()); | |
20945 info.GetReturnValue().Set(test->ShouldContinue()); | |
20946 } | |
20947 }; | |
20948 | |
20949 | |
20950 class RequestInterruptTestWithMethodCallAndInterceptor | |
20951 : public RequestInterruptTestBase { | |
20952 public: | |
20953 virtual void TestBody() { | |
20954 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); | |
20955 v8::Local<v8::Template> proto = t->PrototypeTemplate(); | |
20956 proto->Set(v8_str("shouldContinue"), Function::New( | |
20957 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); | |
20958 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate(); | |
20959 instance_template->SetNamedPropertyHandler(EmptyInterceptor); | |
20960 | |
20961 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); | |
20962 | |
20963 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); | |
20964 } | |
20965 | |
20966 private: | |
20967 static void EmptyInterceptor( | |
20968 Local<String> property, | |
20969 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
20970 } | |
20971 }; | |
20972 | |
20973 | |
20974 class RequestInterruptTestWithMathAbs : public RequestInterruptTestBase { | |
20975 public: | |
20976 virtual void TestBody() { | |
20977 env_->Global()->Set(v8_str("WakeUpInterruptor"), Function::New( | |
20978 isolate_, | |
20979 WakeUpInterruptorCallback, | |
20980 v8::External::New(isolate_, this))); | |
20981 | |
20982 env_->Global()->Set(v8_str("ShouldContinue"), Function::New( | |
20983 isolate_, | |
20984 ShouldContinueCallback, | |
20985 v8::External::New(isolate_, this))); | |
20986 | |
20987 i::FLAG_allow_natives_syntax = true; | |
20988 CompileRun("function loopish(o) {" | |
20989 " var pre = 10;" | |
20990 " while (o.abs(1) > 0) {" | |
20991 " if (o.abs(1) >= 0 && !ShouldContinue()) break;" | |
20992 " if (pre > 0) {" | |
20993 " if (--pre === 0) WakeUpInterruptor(o === Math);" | |
20994 " }" | |
20995 " }" | |
20996 "}" | |
20997 "var i = 50;" | |
20998 "var obj = {abs: function () { return i-- }, x: null};" | |
20999 "delete obj.x;" | |
21000 "loopish(obj);" | |
21001 "%OptimizeFunctionOnNextCall(loopish);" | |
21002 "loopish(Math);"); | |
21003 | |
21004 i::FLAG_allow_natives_syntax = false; | |
21005 } | |
21006 | |
21007 private: | |
21008 static void WakeUpInterruptorCallback( | |
21009 const v8::FunctionCallbackInfo<Value>& info) { | |
21010 if (!info[0]->BooleanValue()) return; | |
21011 | |
21012 RequestInterruptTestBase* test = | |
21013 reinterpret_cast<RequestInterruptTestBase*>( | |
21014 info.Data().As<v8::External>()->Value()); | |
21015 test->WakeUpInterruptor(); | |
21016 } | |
21017 | |
21018 static void ShouldContinueCallback( | |
21019 const v8::FunctionCallbackInfo<Value>& info) { | |
21020 RequestInterruptTestBase* test = | |
21021 reinterpret_cast<RequestInterruptTestBase*>( | |
21022 info.Data().As<v8::External>()->Value()); | |
21023 info.GetReturnValue().Set(test->should_continue()); | |
21024 } | |
21025 }; | |
21026 | |
21027 | |
21028 THREADED_TEST(RequestInterruptTestWithFunctionCall) { | |
21029 RequestInterruptTestWithFunctionCall().RunTest(); | |
21030 } | |
21031 | |
21032 | |
21033 THREADED_TEST(RequestInterruptTestWithMethodCall) { | |
21034 RequestInterruptTestWithMethodCall().RunTest(); | |
21035 } | |
21036 | |
21037 | |
21038 THREADED_TEST(RequestInterruptTestWithAccessor) { | |
21039 RequestInterruptTestWithAccessor().RunTest(); | |
21040 } | |
21041 | |
21042 | |
21043 THREADED_TEST(RequestInterruptTestWithNativeAccessor) { | |
21044 RequestInterruptTestWithNativeAccessor().RunTest(); | |
21045 } | |
21046 | |
21047 | |
21048 THREADED_TEST(RequestInterruptTestWithMethodCallAndInterceptor) { | |
21049 RequestInterruptTestWithMethodCallAndInterceptor().RunTest(); | |
21050 } | |
21051 | |
21052 | |
21053 THREADED_TEST(RequestInterruptTestWithMathAbs) { | |
21054 RequestInterruptTestWithMathAbs().RunTest(); | |
21055 } | |
21056 | |
20804 #endif // V8_OS_POSIX | 21057 #endif // V8_OS_POSIX |
dcarney
2013/12/05 08:06:28
you've got this inside the V8_OS_POSIX ifdef, whic
Vyacheslav Egorov (Chromium)
2013/12/05 12:08:20
Thanks! Copy&paste mistake. Fixed.
| |
20805 | 21058 |
20806 | 21059 |
20807 static Local<Value> function_new_expected_env; | 21060 static Local<Value> function_new_expected_env; |
20808 static void FunctionNewCallback(const v8::FunctionCallbackInfo<Value>& info) { | 21061 static void FunctionNewCallback(const v8::FunctionCallbackInfo<Value>& info) { |
20809 CHECK_EQ(function_new_expected_env, info.Data()); | 21062 CHECK_EQ(function_new_expected_env, info.Data()); |
20810 info.GetReturnValue().Set(17); | 21063 info.GetReturnValue().Set(17); |
20811 } | 21064 } |
20812 | 21065 |
20813 | 21066 |
20814 THREADED_TEST(FunctionNew) { | 21067 THREADED_TEST(FunctionNew) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20854 } | 21107 } |
20855 for (int i = 0; i < runs; i++) { | 21108 for (int i = 0; i < runs; i++) { |
20856 Local<String> expected; | 21109 Local<String> expected; |
20857 if (i != 0) { | 21110 if (i != 0) { |
20858 CHECK_EQ(v8_str("escape value"), values[i]); | 21111 CHECK_EQ(v8_str("escape value"), values[i]); |
20859 } else { | 21112 } else { |
20860 CHECK(values[i].IsEmpty()); | 21113 CHECK(values[i].IsEmpty()); |
20861 } | 21114 } |
20862 } | 21115 } |
20863 } | 21116 } |
OLD | NEW |