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 20718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20729 i::Semaphore sem_; | 20729 i::Semaphore sem_; |
20730 volatile int sem_value_; | 20730 volatile int sem_value_; |
20731 }; | 20731 }; |
20732 | 20732 |
20733 | 20733 |
20734 THREADED_TEST(SemaphoreInterruption) { | 20734 THREADED_TEST(SemaphoreInterruption) { |
20735 ThreadInterruptTest().RunTest(); | 20735 ThreadInterruptTest().RunTest(); |
20736 } | 20736 } |
20737 | 20737 |
20738 | 20738 |
| 20739 #endif // V8_OS_POSIX |
| 20740 |
| 20741 |
20739 static bool NamedAccessAlwaysBlocked(Local<v8::Object> global, | 20742 static bool NamedAccessAlwaysBlocked(Local<v8::Object> global, |
20740 Local<Value> name, | 20743 Local<Value> name, |
20741 v8::AccessType type, | 20744 v8::AccessType type, |
20742 Local<Value> data) { | 20745 Local<Value> data) { |
20743 i::PrintF("Named access blocked.\n"); | 20746 i::PrintF("Named access blocked.\n"); |
20744 return false; | 20747 return false; |
20745 } | 20748 } |
20746 | 20749 |
20747 | 20750 |
20748 static bool IndexAccessAlwaysBlocked(Local<v8::Object> global, | 20751 static bool IndexAccessAlwaysBlocked(Local<v8::Object> global, |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21015 "setAge(100);" | 21018 "setAge(100);" |
21016 "setAge(101);" | 21019 "setAge(101);" |
21017 "setAge(102);" | 21020 "setAge(102);" |
21018 "%OptimizeFunctionOnNextCall(setAge);" | 21021 "%OptimizeFunctionOnNextCall(setAge);" |
21019 "setAge(103);"); | 21022 "setAge(103);"); |
21020 ExpectInt32("obj.age", 100000); | 21023 ExpectInt32("obj.age", 100000); |
21021 ExpectInt32("obj.interceptor_age", 103); | 21024 ExpectInt32("obj.interceptor_age", 103); |
21022 } | 21025 } |
21023 | 21026 |
21024 | 21027 |
21025 #endif // V8_OS_POSIX | 21028 class RequestInterruptTestBase { |
| 21029 public: |
| 21030 RequestInterruptTestBase() |
| 21031 : env_(), |
| 21032 isolate_(env_->GetIsolate()), |
| 21033 sem_(0), |
| 21034 warmup_(20000), |
| 21035 should_continue_(true) { |
| 21036 } |
| 21037 |
| 21038 virtual ~RequestInterruptTestBase() { } |
| 21039 |
| 21040 virtual void TestBody() = 0; |
| 21041 |
| 21042 void RunTest() { |
| 21043 InterruptThread i_thread(this); |
| 21044 i_thread.Start(); |
| 21045 |
| 21046 v8::HandleScope handle_scope(isolate_); |
| 21047 |
| 21048 TestBody(); |
| 21049 |
| 21050 isolate_->ClearInterrupt(); |
| 21051 } |
| 21052 |
| 21053 void WakeUpInterruptor() { |
| 21054 sem_.Signal(); |
| 21055 } |
| 21056 |
| 21057 bool should_continue() const { return should_continue_; } |
| 21058 |
| 21059 bool ShouldContinue() { |
| 21060 if (warmup_ > 0) { |
| 21061 if (--warmup_ == 0) { |
| 21062 WakeUpInterruptor(); |
| 21063 } |
| 21064 } |
| 21065 |
| 21066 return should_continue_; |
| 21067 } |
| 21068 |
| 21069 protected: |
| 21070 static void ShouldContinueCallback( |
| 21071 const v8::FunctionCallbackInfo<Value>& info) { |
| 21072 RequestInterruptTestBase* test = |
| 21073 reinterpret_cast<RequestInterruptTestBase*>( |
| 21074 info.Data().As<v8::External>()->Value()); |
| 21075 info.GetReturnValue().Set(test->ShouldContinue()); |
| 21076 } |
| 21077 |
| 21078 class InterruptThread : public i::Thread { |
| 21079 public: |
| 21080 explicit InterruptThread(RequestInterruptTestBase* test) |
| 21081 : Thread("RequestInterruptTest"), test_(test) {} |
| 21082 |
| 21083 virtual void Run() { |
| 21084 test_->sem_.Wait(); |
| 21085 test_->isolate_->RequestInterrupt(&OnInterrupt, test_); |
| 21086 } |
| 21087 |
| 21088 static void OnInterrupt(v8::Isolate* isolate, void* data) { |
| 21089 reinterpret_cast<RequestInterruptTestBase*>(data)-> |
| 21090 should_continue_ = false; |
| 21091 } |
| 21092 |
| 21093 private: |
| 21094 RequestInterruptTestBase* test_; |
| 21095 }; |
| 21096 |
| 21097 LocalContext env_; |
| 21098 v8::Isolate* isolate_; |
| 21099 i::Semaphore sem_; |
| 21100 int warmup_; |
| 21101 bool should_continue_; |
| 21102 }; |
| 21103 |
| 21104 |
| 21105 class RequestInterruptTestWithFunctionCall : public RequestInterruptTestBase { |
| 21106 public: |
| 21107 virtual void TestBody() { |
| 21108 Local<Function> func = Function::New( |
| 21109 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)); |
| 21110 env_->Global()->Set(v8_str("ShouldContinue"), func); |
| 21111 |
| 21112 CompileRun("while (ShouldContinue()) { }"); |
| 21113 } |
| 21114 }; |
| 21115 |
| 21116 |
| 21117 class RequestInterruptTestWithMethodCall : public RequestInterruptTestBase { |
| 21118 public: |
| 21119 virtual void TestBody() { |
| 21120 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); |
| 21121 v8::Local<v8::Template> proto = t->PrototypeTemplate(); |
| 21122 proto->Set(v8_str("shouldContinue"), Function::New( |
| 21123 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); |
| 21124 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); |
| 21125 |
| 21126 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); |
| 21127 } |
| 21128 }; |
| 21129 |
| 21130 |
| 21131 class RequestInterruptTestWithAccessor : public RequestInterruptTestBase { |
| 21132 public: |
| 21133 virtual void TestBody() { |
| 21134 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); |
| 21135 v8::Local<v8::Template> proto = t->PrototypeTemplate(); |
| 21136 proto->SetAccessorProperty(v8_str("shouldContinue"), FunctionTemplate::New( |
| 21137 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); |
| 21138 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); |
| 21139 |
| 21140 CompileRun("var obj = new Klass; while (obj.shouldContinue) { }"); |
| 21141 } |
| 21142 }; |
| 21143 |
| 21144 |
| 21145 class RequestInterruptTestWithNativeAccessor : public RequestInterruptTestBase { |
| 21146 public: |
| 21147 virtual void TestBody() { |
| 21148 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); |
| 21149 v8::Local<v8::Template> proto = t->PrototypeTemplate(); |
| 21150 proto->SetNativeDataProperty(v8_str("shouldContinue"), |
| 21151 &ShouldContinueNativeGetter, |
| 21152 NULL, |
| 21153 v8::External::New(isolate_, this)); |
| 21154 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); |
| 21155 |
| 21156 CompileRun("var obj = new Klass; while (obj.shouldContinue) { }"); |
| 21157 } |
| 21158 |
| 21159 private: |
| 21160 static void ShouldContinueNativeGetter( |
| 21161 Local<String> property, |
| 21162 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 21163 RequestInterruptTestBase* test = |
| 21164 reinterpret_cast<RequestInterruptTestBase*>( |
| 21165 info.Data().As<v8::External>()->Value()); |
| 21166 info.GetReturnValue().Set(test->ShouldContinue()); |
| 21167 } |
| 21168 }; |
| 21169 |
| 21170 |
| 21171 class RequestInterruptTestWithMethodCallAndInterceptor |
| 21172 : public RequestInterruptTestBase { |
| 21173 public: |
| 21174 virtual void TestBody() { |
| 21175 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); |
| 21176 v8::Local<v8::Template> proto = t->PrototypeTemplate(); |
| 21177 proto->Set(v8_str("shouldContinue"), Function::New( |
| 21178 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); |
| 21179 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate(); |
| 21180 instance_template->SetNamedPropertyHandler(EmptyInterceptor); |
| 21181 |
| 21182 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); |
| 21183 |
| 21184 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); |
| 21185 } |
| 21186 |
| 21187 private: |
| 21188 static void EmptyInterceptor( |
| 21189 Local<String> property, |
| 21190 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 21191 } |
| 21192 }; |
| 21193 |
| 21194 |
| 21195 class RequestInterruptTestWithMathAbs : public RequestInterruptTestBase { |
| 21196 public: |
| 21197 virtual void TestBody() { |
| 21198 env_->Global()->Set(v8_str("WakeUpInterruptor"), Function::New( |
| 21199 isolate_, |
| 21200 WakeUpInterruptorCallback, |
| 21201 v8::External::New(isolate_, this))); |
| 21202 |
| 21203 env_->Global()->Set(v8_str("ShouldContinue"), Function::New( |
| 21204 isolate_, |
| 21205 ShouldContinueCallback, |
| 21206 v8::External::New(isolate_, this))); |
| 21207 |
| 21208 i::FLAG_allow_natives_syntax = true; |
| 21209 CompileRun("function loopish(o) {" |
| 21210 " var pre = 10;" |
| 21211 " while (o.abs(1) > 0) {" |
| 21212 " if (o.abs(1) >= 0 && !ShouldContinue()) break;" |
| 21213 " if (pre > 0) {" |
| 21214 " if (--pre === 0) WakeUpInterruptor(o === Math);" |
| 21215 " }" |
| 21216 " }" |
| 21217 "}" |
| 21218 "var i = 50;" |
| 21219 "var obj = {abs: function () { return i-- }, x: null};" |
| 21220 "delete obj.x;" |
| 21221 "loopish(obj);" |
| 21222 "%OptimizeFunctionOnNextCall(loopish);" |
| 21223 "loopish(Math);"); |
| 21224 |
| 21225 i::FLAG_allow_natives_syntax = false; |
| 21226 } |
| 21227 |
| 21228 private: |
| 21229 static void WakeUpInterruptorCallback( |
| 21230 const v8::FunctionCallbackInfo<Value>& info) { |
| 21231 if (!info[0]->BooleanValue()) return; |
| 21232 |
| 21233 RequestInterruptTestBase* test = |
| 21234 reinterpret_cast<RequestInterruptTestBase*>( |
| 21235 info.Data().As<v8::External>()->Value()); |
| 21236 test->WakeUpInterruptor(); |
| 21237 } |
| 21238 |
| 21239 static void ShouldContinueCallback( |
| 21240 const v8::FunctionCallbackInfo<Value>& info) { |
| 21241 RequestInterruptTestBase* test = |
| 21242 reinterpret_cast<RequestInterruptTestBase*>( |
| 21243 info.Data().As<v8::External>()->Value()); |
| 21244 info.GetReturnValue().Set(test->should_continue()); |
| 21245 } |
| 21246 }; |
| 21247 |
| 21248 |
| 21249 TEST(RequestInterruptTestWithFunctionCall) { |
| 21250 RequestInterruptTestWithFunctionCall().RunTest(); |
| 21251 } |
| 21252 |
| 21253 |
| 21254 TEST(RequestInterruptTestWithMethodCall) { |
| 21255 RequestInterruptTestWithMethodCall().RunTest(); |
| 21256 } |
| 21257 |
| 21258 |
| 21259 TEST(RequestInterruptTestWithAccessor) { |
| 21260 RequestInterruptTestWithAccessor().RunTest(); |
| 21261 } |
| 21262 |
| 21263 |
| 21264 TEST(RequestInterruptTestWithNativeAccessor) { |
| 21265 RequestInterruptTestWithNativeAccessor().RunTest(); |
| 21266 } |
| 21267 |
| 21268 |
| 21269 TEST(RequestInterruptTestWithMethodCallAndInterceptor) { |
| 21270 RequestInterruptTestWithMethodCallAndInterceptor().RunTest(); |
| 21271 } |
| 21272 |
| 21273 |
| 21274 TEST(RequestInterruptTestWithMathAbs) { |
| 21275 RequestInterruptTestWithMathAbs().RunTest(); |
| 21276 } |
21026 | 21277 |
21027 | 21278 |
21028 static Local<Value> function_new_expected_env; | 21279 static Local<Value> function_new_expected_env; |
21029 static void FunctionNewCallback(const v8::FunctionCallbackInfo<Value>& info) { | 21280 static void FunctionNewCallback(const v8::FunctionCallbackInfo<Value>& info) { |
21030 CHECK_EQ(function_new_expected_env, info.Data()); | 21281 CHECK_EQ(function_new_expected_env, info.Data()); |
21031 info.GetReturnValue().Set(17); | 21282 info.GetReturnValue().Set(17); |
21032 } | 21283 } |
21033 | 21284 |
21034 | 21285 |
21035 THREADED_TEST(FunctionNew) { | 21286 THREADED_TEST(FunctionNew) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21075 } | 21326 } |
21076 for (int i = 0; i < runs; i++) { | 21327 for (int i = 0; i < runs; i++) { |
21077 Local<String> expected; | 21328 Local<String> expected; |
21078 if (i != 0) { | 21329 if (i != 0) { |
21079 CHECK_EQ(v8_str("escape value"), values[i]); | 21330 CHECK_EQ(v8_str("escape value"), values[i]); |
21080 } else { | 21331 } else { |
21081 CHECK(values[i].IsEmpty()); | 21332 CHECK(values[i].IsEmpty()); |
21082 } | 21333 } |
21083 } | 21334 } |
21084 } | 21335 } |
OLD | NEW |