Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: test/cctest/test-api.cc

Issue 796623003: Support multiple interrupt requests in v8 API. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/isolate.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 23030 matching lines...) Expand 10 before | Expand all | Expand 10 after
23041 23041
23042 virtual void TestBody() = 0; 23042 virtual void TestBody() = 0;
23043 23043
23044 void RunTest() { 23044 void RunTest() {
23045 StartInterruptThread(); 23045 StartInterruptThread();
23046 23046
23047 v8::HandleScope handle_scope(isolate_); 23047 v8::HandleScope handle_scope(isolate_);
23048 23048
23049 TestBody(); 23049 TestBody();
23050 23050
23051 isolate_->ClearInterrupt();
23052
23053 // Verify we arrived here because interruptor was called 23051 // Verify we arrived here because interruptor was called
23054 // not due to a bug causing us to exit the loop too early. 23052 // not due to a bug causing us to exit the loop too early.
23055 CHECK(!should_continue()); 23053 CHECK(!should_continue());
23056 } 23054 }
23057 23055
23058 void WakeUpInterruptor() { 23056 void WakeUpInterruptor() {
23059 sem_.Signal(); 23057 sem_.Signal();
23060 } 23058 }
23061 23059
23062 bool should_continue() const { return should_continue_; } 23060 bool should_continue() const { return should_continue_; }
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
23291 TEST(RequestInterruptTestWithMethodCallAndInterceptor) { 23289 TEST(RequestInterruptTestWithMethodCallAndInterceptor) {
23292 RequestInterruptTestWithMethodCallAndInterceptor().RunTest(); 23290 RequestInterruptTestWithMethodCallAndInterceptor().RunTest();
23293 } 23291 }
23294 23292
23295 23293
23296 TEST(RequestInterruptTestWithMathAbs) { 23294 TEST(RequestInterruptTestWithMathAbs) {
23297 RequestInterruptTestWithMathAbs().RunTest(); 23295 RequestInterruptTestWithMathAbs().RunTest();
23298 } 23296 }
23299 23297
23300 23298
23301 class ClearInterruptFromAnotherThread 23299 class RequestMultipleInterrupts : public RequestInterruptTestBase {
23302 : public RequestInterruptTestBase {
23303 public: 23300 public:
23304 ClearInterruptFromAnotherThread() : i_thread(this), sem2_(0) { } 23301 RequestMultipleInterrupts() : i_thread(this), counter_(0) {}
23305 23302
23306 virtual void StartInterruptThread() { 23303 virtual void StartInterruptThread() {
23307 i_thread.Start(); 23304 i_thread.Start();
23308 } 23305 }
23309 23306
23310 virtual void TestBody() { 23307 virtual void TestBody() {
23311 Local<Function> func = Function::New( 23308 Local<Function> func = Function::New(
23312 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)); 23309 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this));
23313 env_->Global()->Set(v8_str("ShouldContinue"), func); 23310 env_->Global()->Set(v8_str("ShouldContinue"), func);
23314 23311
23315 CompileRun("while (ShouldContinue()) { }"); 23312 CompileRun("while (ShouldContinue()) { }");
23316 } 23313 }
23317 23314
23318 private: 23315 private:
23319 class InterruptThread : public v8::base::Thread { 23316 class InterruptThread : public v8::base::Thread {
23320 public: 23317 public:
23321 explicit InterruptThread(ClearInterruptFromAnotherThread* test) 23318 enum { NUM_INTERRUPTS = 10 };
23319 explicit InterruptThread(RequestMultipleInterrupts* test)
23322 : Thread(Options("RequestInterruptTest")), test_(test) {} 23320 : Thread(Options("RequestInterruptTest")), test_(test) {}
23323 23321
23324 virtual void Run() { 23322 virtual void Run() {
23325 test_->sem_.Wait(); 23323 test_->sem_.Wait();
23326 test_->isolate_->RequestInterrupt(&OnInterrupt, test_); 23324 for (int i = 0; i < NUM_INTERRUPTS; i++) {
23327 test_->sem_.Wait(); 23325 test_->isolate_->RequestInterrupt(&OnInterrupt, test_);
23328 test_->isolate_->ClearInterrupt(); 23326 }
23329 test_->sem2_.Signal();
23330 } 23327 }
23331 23328
23332 static void OnInterrupt(v8::Isolate* isolate, void* data) { 23329 static void OnInterrupt(v8::Isolate* isolate, void* data) {
23333 ClearInterruptFromAnotherThread* test = 23330 RequestMultipleInterrupts* test =
23334 reinterpret_cast<ClearInterruptFromAnotherThread*>(data); 23331 reinterpret_cast<RequestMultipleInterrupts*>(data);
23335 test->sem_.Signal(); 23332 test->should_continue_ = ++test->counter_ < NUM_INTERRUPTS;
23336 bool success = test->sem2_.WaitFor(v8::base::TimeDelta::FromSeconds(2));
23337 // Crash instead of timeout to make this failure more prominent.
23338 CHECK(success);
23339 test->should_continue_ = false;
23340 } 23333 }
23341 23334
23342 private: 23335 private:
23343 ClearInterruptFromAnotherThread* test_; 23336 RequestMultipleInterrupts* test_;
23344 }; 23337 };
23345 23338
23346 InterruptThread i_thread; 23339 InterruptThread i_thread;
23347 v8::base::Semaphore sem2_; 23340 int counter_;
23348 }; 23341 };
23349 23342
23350 23343
23351 TEST(ClearInterruptFromAnotherThread) { 23344 TEST(RequestMultipleInterrupts) { RequestMultipleInterrupts().RunTest(); }
23352 ClearInterruptFromAnotherThread().RunTest();
23353 }
23354 23345
23355 23346
23356 static Local<Value> function_new_expected_env; 23347 static Local<Value> function_new_expected_env;
23357 static void FunctionNewCallback(const v8::FunctionCallbackInfo<Value>& info) { 23348 static void FunctionNewCallback(const v8::FunctionCallbackInfo<Value>& info) {
23358 CHECK_EQ(function_new_expected_env, info.Data()); 23349 CHECK_EQ(function_new_expected_env, info.Data());
23359 info.GetReturnValue().Set(17); 23350 info.GetReturnValue().Set(17);
23360 } 23351 }
23361 23352
23362 23353
23363 THREADED_TEST(FunctionNew) { 23354 THREADED_TEST(FunctionNew) {
(...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after
24638 TEST(ClassPrototypeCreationContext) { 24629 TEST(ClassPrototypeCreationContext) {
24639 i::FLAG_harmony_classes = true; 24630 i::FLAG_harmony_classes = true;
24640 v8::Isolate* isolate = CcTest::isolate(); 24631 v8::Isolate* isolate = CcTest::isolate();
24641 v8::HandleScope handle_scope(isolate); 24632 v8::HandleScope handle_scope(isolate);
24642 LocalContext env; 24633 LocalContext env;
24643 24634
24644 Handle<Object> result = Handle<Object>::Cast( 24635 Handle<Object> result = Handle<Object>::Cast(
24645 CompileRun("'use strict'; class Example { }; Example.prototype")); 24636 CompileRun("'use strict'; class Example { }; Example.prototype"));
24646 CHECK(env.local() == result->CreationContext()); 24637 CHECK(env.local() == result->CreationContext());
24647 } 24638 }
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698