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

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

Issue 358363002: Move platform abstraction to base library (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates Created 6 years, 5 months 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 | Annotate | Revision Log
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 21 matching lines...) Expand all
32 32
33 #include "src/v8.h" 33 #include "src/v8.h"
34 34
35 #if V8_OS_POSIX 35 #if V8_OS_POSIX
36 #include <unistd.h> // NOLINT 36 #include <unistd.h> // NOLINT
37 #endif 37 #endif
38 38
39 #include "include/v8-util.h" 39 #include "include/v8-util.h"
40 #include "src/api.h" 40 #include "src/api.h"
41 #include "src/arguments.h" 41 #include "src/arguments.h"
42 #include "src/base/platform/platform.h"
42 #include "src/compilation-cache.h" 43 #include "src/compilation-cache.h"
43 #include "src/cpu-profiler.h" 44 #include "src/cpu-profiler.h"
44 #include "src/execution.h" 45 #include "src/execution.h"
45 #include "src/isolate.h" 46 #include "src/isolate.h"
46 #include "src/objects.h" 47 #include "src/objects.h"
47 #include "src/parser.h" 48 #include "src/parser.h"
48 #include "src/platform.h"
49 #include "src/snapshot.h" 49 #include "src/snapshot.h"
50 #include "src/unicode-inl.h" 50 #include "src/unicode-inl.h"
51 #include "src/utils.h" 51 #include "src/utils.h"
52 #include "src/vm-state.h" 52 #include "src/vm-state.h"
53 #include "test/cctest/cctest.h" 53 #include "test/cctest/cctest.h"
54 54
55 static const bool kLogThreading = false; 55 static const bool kLogThreading = false;
56 56
57 using ::v8::Boolean; 57 using ::v8::Boolean;
58 using ::v8::BooleanObject; 58 using ::v8::BooleanObject;
(...skipping 5333 matching lines...) Expand 10 before | Expand all | Expand 10 after
5392 CHECK_EQ(v8_num(1.00), v8_num(1)); 5392 CHECK_EQ(v8_num(1.00), v8_num(1));
5393 CHECK_NE(v8_num(1), v8_num(2)); 5393 CHECK_NE(v8_num(1), v8_num(2));
5394 5394
5395 // Assume String is not internalized. 5395 // Assume String is not internalized.
5396 CHECK(v8_str("a")->StrictEquals(v8_str("a"))); 5396 CHECK(v8_str("a")->StrictEquals(v8_str("a")));
5397 CHECK(!v8_str("a")->StrictEquals(v8_str("b"))); 5397 CHECK(!v8_str("a")->StrictEquals(v8_str("b")));
5398 CHECK(!v8_str("5")->StrictEquals(v8_num(5))); 5398 CHECK(!v8_str("5")->StrictEquals(v8_num(5)));
5399 CHECK(v8_num(1)->StrictEquals(v8_num(1))); 5399 CHECK(v8_num(1)->StrictEquals(v8_num(1)));
5400 CHECK(!v8_num(1)->StrictEquals(v8_num(2))); 5400 CHECK(!v8_num(1)->StrictEquals(v8_num(2)));
5401 CHECK(v8_num(0.0)->StrictEquals(v8_num(-0.0))); 5401 CHECK(v8_num(0.0)->StrictEquals(v8_num(-0.0)));
5402 Local<Value> not_a_number = v8_num(i::OS::nan_value()); 5402 Local<Value> not_a_number = v8_num(v8::base::OS::nan_value());
5403 CHECK(!not_a_number->StrictEquals(not_a_number)); 5403 CHECK(!not_a_number->StrictEquals(not_a_number));
5404 CHECK(v8::False(isolate)->StrictEquals(v8::False(isolate))); 5404 CHECK(v8::False(isolate)->StrictEquals(v8::False(isolate)));
5405 CHECK(!v8::False(isolate)->StrictEquals(v8::Undefined(isolate))); 5405 CHECK(!v8::False(isolate)->StrictEquals(v8::Undefined(isolate)));
5406 5406
5407 v8::Handle<v8::Object> obj = v8::Object::New(isolate); 5407 v8::Handle<v8::Object> obj = v8::Object::New(isolate);
5408 v8::Persistent<v8::Object> alias(isolate, obj); 5408 v8::Persistent<v8::Object> alias(isolate, obj);
5409 CHECK(v8::Local<v8::Object>::New(isolate, alias)->StrictEquals(obj)); 5409 CHECK(v8::Local<v8::Object>::New(isolate, alias)->StrictEquals(obj));
5410 alias.Reset(); 5410 alias.Reset();
5411 5411
5412 CHECK(v8_str("a")->SameValue(v8_str("a"))); 5412 CHECK(v8_str("a")->SameValue(v8_str("a")));
(...skipping 7676 matching lines...) Expand 10 before | Expand all | Expand 10 after
13089 CHECK(c->IsObject() && c->ToObject()->GetConstructorName()->Equals( 13089 CHECK(c->IsObject() && c->ToObject()->GetConstructorName()->Equals(
13090 v8_str("Child"))); 13090 v8_str("Child")));
13091 13091
13092 Local<v8::Value> x = context->Global()->Get(v8_str("x")); 13092 Local<v8::Value> x = context->Global()->Get(v8_str("x"));
13093 CHECK(x->IsObject() && x->ToObject()->GetConstructorName()->Equals( 13093 CHECK(x->IsObject() && x->ToObject()->GetConstructorName()->Equals(
13094 v8_str("outer.inner"))); 13094 v8_str("outer.inner")));
13095 } 13095 }
13096 13096
13097 13097
13098 bool ApiTestFuzzer::fuzzing_ = false; 13098 bool ApiTestFuzzer::fuzzing_ = false;
13099 i::Semaphore ApiTestFuzzer::all_tests_done_(0); 13099 v8::base::Semaphore ApiTestFuzzer::all_tests_done_(0);
13100 int ApiTestFuzzer::active_tests_; 13100 int ApiTestFuzzer::active_tests_;
13101 int ApiTestFuzzer::tests_being_run_; 13101 int ApiTestFuzzer::tests_being_run_;
13102 int ApiTestFuzzer::current_; 13102 int ApiTestFuzzer::current_;
13103 13103
13104 13104
13105 // We are in a callback and want to switch to another thread (if we 13105 // We are in a callback and want to switch to another thread (if we
13106 // are currently running the thread fuzzing test). 13106 // are currently running the thread fuzzing test).
13107 void ApiTestFuzzer::Fuzz() { 13107 void ApiTestFuzzer::Fuzz() {
13108 if (!fuzzing_) return; 13108 if (!fuzzing_) return;
13109 ApiTestFuzzer* test = RegisterThreadedTest::nth(current_)->fuzzer_; 13109 ApiTestFuzzer* test = RegisterThreadedTest::nth(current_)->fuzzer_;
(...skipping 2041 matching lines...) Expand 10 before | Expand all | Expand 10 after
15151 15151
15152 #ifndef V8_INTERPRETED_REGEXP 15152 #ifndef V8_INTERPRETED_REGEXP
15153 15153
15154 struct RegExpInterruptionData { 15154 struct RegExpInterruptionData {
15155 int loop_count; 15155 int loop_count;
15156 UC16VectorResource* string_resource; 15156 UC16VectorResource* string_resource;
15157 v8::Persistent<v8::String> string; 15157 v8::Persistent<v8::String> string;
15158 } regexp_interruption_data; 15158 } regexp_interruption_data;
15159 15159
15160 15160
15161 class RegExpInterruptionThread : public i::Thread { 15161 class RegExpInterruptionThread : public v8::base::Thread {
15162 public: 15162 public:
15163 explicit RegExpInterruptionThread(v8::Isolate* isolate) 15163 explicit RegExpInterruptionThread(v8::Isolate* isolate)
15164 : Thread("TimeoutThread"), isolate_(isolate) {} 15164 : Thread("TimeoutThread"), isolate_(isolate) {}
15165 15165
15166 virtual void Run() { 15166 virtual void Run() {
15167 for (regexp_interruption_data.loop_count = 0; 15167 for (regexp_interruption_data.loop_count = 0;
15168 regexp_interruption_data.loop_count < 7; 15168 regexp_interruption_data.loop_count < 7;
15169 regexp_interruption_data.loop_count++) { 15169 regexp_interruption_data.loop_count++) {
15170 i::OS::Sleep(50); // Wait a bit before requesting GC. 15170 v8::base::OS::Sleep(50); // Wait a bit before requesting GC.
15171 reinterpret_cast<i::Isolate*>(isolate_)->stack_guard()->RequestGC(); 15171 reinterpret_cast<i::Isolate*>(isolate_)->stack_guard()->RequestGC();
15172 } 15172 }
15173 i::OS::Sleep(50); // Wait a bit before terminating. 15173 v8::base::OS::Sleep(50); // Wait a bit before terminating.
15174 v8::V8::TerminateExecution(isolate_); 15174 v8::V8::TerminateExecution(isolate_);
15175 } 15175 }
15176 15176
15177 private: 15177 private:
15178 v8::Isolate* isolate_; 15178 v8::Isolate* isolate_;
15179 }; 15179 };
15180 15180
15181 15181
15182 void RunBeforeGC(v8::GCType type, v8::GCCallbackFlags flags) { 15182 void RunBeforeGC(v8::GCType type, v8::GCCallbackFlags flags) {
15183 if (regexp_interruption_data.loop_count != 2) return; 15183 if (regexp_interruption_data.loop_count != 2) return;
(...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after
16245 CHECK_EQ(false, result->BooleanValue()); 16245 CHECK_EQ(false, result->BooleanValue());
16246 16246
16247 // Check other boundary conditions, values and operations. 16247 // Check other boundary conditions, values and operations.
16248 result = CompileRun("for (var i = 0; i < 8; i++) {" 16248 result = CompileRun("for (var i = 0; i < 8; i++) {"
16249 " ext_array[7] = undefined;" 16249 " ext_array[7] = undefined;"
16250 "}" 16250 "}"
16251 "ext_array[7];"); 16251 "ext_array[7];");
16252 CHECK_EQ(0, result->Int32Value()); 16252 CHECK_EQ(0, result->Int32Value());
16253 if (array_type == v8::kExternalFloat64Array || 16253 if (array_type == v8::kExternalFloat64Array ||
16254 array_type == v8::kExternalFloat32Array) { 16254 array_type == v8::kExternalFloat32Array) {
16255 CHECK_EQ(static_cast<int>(i::OS::nan_value()), 16255 CHECK_EQ(static_cast<int>(v8::base::OS::nan_value()),
16256 static_cast<int>( 16256 static_cast<int>(
16257 i::Object::GetElement( 16257 i::Object::GetElement(
16258 isolate, jsobj, 7).ToHandleChecked()->Number())); 16258 isolate, jsobj, 7).ToHandleChecked()->Number()));
16259 } else { 16259 } else {
16260 CheckElementValue(isolate, 0, jsobj, 7); 16260 CheckElementValue(isolate, 0, jsobj, 7);
16261 } 16261 }
16262 16262
16263 result = CompileRun("for (var i = 0; i < 8; i++) {" 16263 result = CompileRun("for (var i = 0; i < 8; i++) {"
16264 " ext_array[6] = '2.3';" 16264 " ext_array[6] = '2.3';"
16265 "}" 16265 "}"
(...skipping 1758 matching lines...) Expand 10 before | Expand all | Expand 10 after
18024 static uint64_t DoubleToBits(double value) { 18024 static uint64_t DoubleToBits(double value) {
18025 uint64_t target; 18025 uint64_t target;
18026 i::MemCopy(&target, &value, sizeof(target)); 18026 i::MemCopy(&target, &value, sizeof(target));
18027 return target; 18027 return target;
18028 } 18028 }
18029 18029
18030 18030
18031 static double DoubleToDateTime(double input) { 18031 static double DoubleToDateTime(double input) {
18032 double date_limit = 864e13; 18032 double date_limit = 864e13;
18033 if (std::isnan(input) || input < -date_limit || input > date_limit) { 18033 if (std::isnan(input) || input < -date_limit || input > date_limit) {
18034 return i::OS::nan_value(); 18034 return v8::base::OS::nan_value();
18035 } 18035 }
18036 return (input < 0) ? -(std::floor(-input)) : std::floor(input); 18036 return (input < 0) ? -(std::floor(-input)) : std::floor(input);
18037 } 18037 }
18038 18038
18039 18039
18040 // We don't have a consistent way to write 64-bit constants syntactically, so we 18040 // We don't have a consistent way to write 64-bit constants syntactically, so we
18041 // split them into two 32-bit constants and combine them programmatically. 18041 // split them into two 32-bit constants and combine them programmatically.
18042 static double DoubleFromBits(uint32_t high_bits, uint32_t low_bits) { 18042 static double DoubleFromBits(uint32_t high_bits, uint32_t low_bits) {
18043 return DoubleFromBits((static_cast<uint64_t>(high_bits) << 32) | low_bits); 18043 return DoubleFromBits((static_cast<uint64_t>(high_bits) << 32) | low_bits);
18044 } 18044 }
(...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after
19355 i::SNPrintF(code, "function fib(n) {" 19355 i::SNPrintF(code, "function fib(n) {"
19356 " if (n <= 2) return 1;" 19356 " if (n <= 2) return 1;"
19357 " return fib(n-1) + fib(n-2);" 19357 " return fib(n-1) + fib(n-2);"
19358 "}" 19358 "}"
19359 "fib(%d)", limit); 19359 "fib(%d)", limit);
19360 Local<Value> value = CompileRun(code.start()); 19360 Local<Value> value = CompileRun(code.start());
19361 CHECK(value->IsNumber()); 19361 CHECK(value->IsNumber());
19362 return static_cast<int>(value->NumberValue()); 19362 return static_cast<int>(value->NumberValue());
19363 } 19363 }
19364 19364
19365 class IsolateThread : public v8::internal::Thread { 19365 class IsolateThread : public v8::base::Thread {
19366 public: 19366 public:
19367 IsolateThread(v8::Isolate* isolate, int fib_limit) 19367 IsolateThread(v8::Isolate* isolate, int fib_limit)
19368 : Thread("IsolateThread"), 19368 : Thread("IsolateThread"),
19369 isolate_(isolate), 19369 isolate_(isolate),
19370 fib_limit_(fib_limit), 19370 fib_limit_(fib_limit),
19371 result_(0) { } 19371 result_(0) { }
19372 19372
19373 void Run() { 19373 void Run() {
19374 result_ = CalcFibonacci(isolate_, fib_limit_); 19374 result_ = CalcFibonacci(isolate_, fib_limit_);
19375 } 19375 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
19429 v8::HandleScope handle_scope(isolate); 19429 v8::HandleScope handle_scope(isolate);
19430 context = v8::Context::New(isolate); 19430 context = v8::Context::New(isolate);
19431 v8::Context::Scope context_scope(context); 19431 v8::Context::Scope context_scope(context);
19432 Local<Value> v = CompileRun("22"); 19432 Local<Value> v = CompileRun("22");
19433 CHECK(v->IsNumber()); 19433 CHECK(v->IsNumber());
19434 CHECK_EQ(22, static_cast<int>(v->NumberValue())); 19434 CHECK_EQ(22, static_cast<int>(v->NumberValue()));
19435 } 19435 }
19436 isolate->Dispose(); 19436 isolate->Dispose();
19437 } 19437 }
19438 19438
19439 class InitDefaultIsolateThread : public v8::internal::Thread { 19439 class InitDefaultIsolateThread : public v8::base::Thread {
19440 public: 19440 public:
19441 enum TestCase { 19441 enum TestCase {
19442 SetResourceConstraints, 19442 SetResourceConstraints,
19443 SetFatalHandler, 19443 SetFatalHandler,
19444 SetCounterFunction, 19444 SetCounterFunction,
19445 SetCreateHistogramFunction, 19445 SetCreateHistogramFunction,
19446 SetAddHistogramSampleFunction 19446 SetAddHistogramSampleFunction
19447 }; 19447 };
19448 19448
19449 explicit InitDefaultIsolateThread(TestCase testCase) 19449 explicit InitDefaultIsolateThread(TestCase testCase)
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after
20539 TestReceiver(i, foreign_context->Global(), "func()"); 20539 TestReceiver(i, foreign_context->Global(), "func()");
20540 // Calling with no base. 20540 // Calling with no base.
20541 TestReceiver(i, foreign_context->Global(), "(1,func)()"); 20541 TestReceiver(i, foreign_context->Global(), "(1,func)()");
20542 } 20542 }
20543 20543
20544 20544
20545 uint8_t callback_fired = 0; 20545 uint8_t callback_fired = 0;
20546 20546
20547 20547
20548 void CallCompletedCallback1() { 20548 void CallCompletedCallback1() {
20549 i::OS::Print("Firing callback 1.\n"); 20549 v8::base::OS::Print("Firing callback 1.\n");
20550 callback_fired ^= 1; // Toggle first bit. 20550 callback_fired ^= 1; // Toggle first bit.
20551 } 20551 }
20552 20552
20553 20553
20554 void CallCompletedCallback2() { 20554 void CallCompletedCallback2() {
20555 i::OS::Print("Firing callback 2.\n"); 20555 v8::base::OS::Print("Firing callback 2.\n");
20556 callback_fired ^= 2; // Toggle second bit. 20556 callback_fired ^= 2; // Toggle second bit.
20557 } 20557 }
20558 20558
20559 20559
20560 void RecursiveCall(const v8::FunctionCallbackInfo<v8::Value>& args) { 20560 void RecursiveCall(const v8::FunctionCallbackInfo<v8::Value>& args) {
20561 int32_t level = args[0]->Int32Value(); 20561 int32_t level = args[0]->Int32Value();
20562 if (level < 3) { 20562 if (level < 3) {
20563 level++; 20563 level++;
20564 i::OS::Print("Entering recursion level %d.\n", level); 20564 v8::base::OS::Print("Entering recursion level %d.\n", level);
20565 char script[64]; 20565 char script[64];
20566 i::Vector<char> script_vector(script, sizeof(script)); 20566 i::Vector<char> script_vector(script, sizeof(script));
20567 i::SNPrintF(script_vector, "recursion(%d)", level); 20567 i::SNPrintF(script_vector, "recursion(%d)", level);
20568 CompileRun(script_vector.start()); 20568 CompileRun(script_vector.start());
20569 i::OS::Print("Leaving recursion level %d.\n", level); 20569 v8::base::OS::Print("Leaving recursion level %d.\n", level);
20570 CHECK_EQ(0, callback_fired); 20570 CHECK_EQ(0, callback_fired);
20571 } else { 20571 } else {
20572 i::OS::Print("Recursion ends.\n"); 20572 v8::base::OS::Print("Recursion ends.\n");
20573 CHECK_EQ(0, callback_fired); 20573 CHECK_EQ(0, callback_fired);
20574 } 20574 }
20575 } 20575 }
20576 20576
20577 20577
20578 TEST(CallCompletedCallback) { 20578 TEST(CallCompletedCallback) {
20579 LocalContext env; 20579 LocalContext env;
20580 v8::HandleScope scope(env->GetIsolate()); 20580 v8::HandleScope scope(env->GetIsolate());
20581 v8::Handle<v8::FunctionTemplate> recursive_runtime = 20581 v8::Handle<v8::FunctionTemplate> recursive_runtime =
20582 v8::FunctionTemplate::New(env->GetIsolate(), RecursiveCall); 20582 v8::FunctionTemplate::New(env->GetIsolate(), RecursiveCall);
20583 env->Global()->Set(v8_str("recursion"), 20583 env->Global()->Set(v8_str("recursion"),
20584 recursive_runtime->GetFunction()); 20584 recursive_runtime->GetFunction());
20585 // Adding the same callback a second time has no effect. 20585 // Adding the same callback a second time has no effect.
20586 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1); 20586 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1);
20587 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1); 20587 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1);
20588 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback2); 20588 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback2);
20589 i::OS::Print("--- Script (1) ---\n"); 20589 v8::base::OS::Print("--- Script (1) ---\n");
20590 Local<Script> script = v8::Script::Compile( 20590 Local<Script> script = v8::Script::Compile(
20591 v8::String::NewFromUtf8(env->GetIsolate(), "recursion(0)")); 20591 v8::String::NewFromUtf8(env->GetIsolate(), "recursion(0)"));
20592 script->Run(); 20592 script->Run();
20593 CHECK_EQ(3, callback_fired); 20593 CHECK_EQ(3, callback_fired);
20594 20594
20595 i::OS::Print("\n--- Script (2) ---\n"); 20595 v8::base::OS::Print("\n--- Script (2) ---\n");
20596 callback_fired = 0; 20596 callback_fired = 0;
20597 env->GetIsolate()->RemoveCallCompletedCallback(CallCompletedCallback1); 20597 env->GetIsolate()->RemoveCallCompletedCallback(CallCompletedCallback1);
20598 script->Run(); 20598 script->Run();
20599 CHECK_EQ(2, callback_fired); 20599 CHECK_EQ(2, callback_fired);
20600 20600
20601 i::OS::Print("\n--- Function ---\n"); 20601 v8::base::OS::Print("\n--- Function ---\n");
20602 callback_fired = 0; 20602 callback_fired = 0;
20603 Local<Function> recursive_function = 20603 Local<Function> recursive_function =
20604 Local<Function>::Cast(env->Global()->Get(v8_str("recursion"))); 20604 Local<Function>::Cast(env->Global()->Get(v8_str("recursion")));
20605 v8::Handle<Value> args[] = { v8_num(0) }; 20605 v8::Handle<Value> args[] = { v8_num(0) };
20606 recursive_function->Call(env->Global(), 1, args); 20606 recursive_function->Call(env->Global(), 1, args);
20607 CHECK_EQ(2, callback_fired); 20607 CHECK_EQ(2, callback_fired);
20608 } 20608 }
20609 20609
20610 20610
20611 void CallCompletedCallbackNoException() { 20611 void CallCompletedCallbackNoException() {
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
21499 InterruptThread i_thread(this); 21499 InterruptThread i_thread(this);
21500 i_thread.Start(); 21500 i_thread.Start();
21501 21501
21502 sem_.Wait(); 21502 sem_.Wait();
21503 CHECK_EQ(kExpectedValue, sem_value_); 21503 CHECK_EQ(kExpectedValue, sem_value_);
21504 } 21504 }
21505 21505
21506 private: 21506 private:
21507 static const int kExpectedValue = 1; 21507 static const int kExpectedValue = 1;
21508 21508
21509 class InterruptThread : public i::Thread { 21509 class InterruptThread : public v8::base::Thread {
21510 public: 21510 public:
21511 explicit InterruptThread(ThreadInterruptTest* test) 21511 explicit InterruptThread(ThreadInterruptTest* test)
21512 : Thread("InterruptThread"), test_(test) {} 21512 : Thread("InterruptThread"), test_(test) {}
21513 21513
21514 virtual void Run() { 21514 virtual void Run() {
21515 struct sigaction action; 21515 struct sigaction action;
21516 21516
21517 // Ensure that we'll enter waiting condition 21517 // Ensure that we'll enter waiting condition
21518 i::OS::Sleep(100); 21518 v8::base::OS::Sleep(100);
21519 21519
21520 // Setup signal handler 21520 // Setup signal handler
21521 memset(&action, 0, sizeof(action)); 21521 memset(&action, 0, sizeof(action));
21522 action.sa_handler = SignalHandler; 21522 action.sa_handler = SignalHandler;
21523 sigaction(SIGCHLD, &action, NULL); 21523 sigaction(SIGCHLD, &action, NULL);
21524 21524
21525 // Send signal 21525 // Send signal
21526 kill(getpid(), SIGCHLD); 21526 kill(getpid(), SIGCHLD);
21527 21527
21528 // Ensure that if wait has returned because of error 21528 // Ensure that if wait has returned because of error
21529 i::OS::Sleep(100); 21529 v8::base::OS::Sleep(100);
21530 21530
21531 // Set value and signal semaphore 21531 // Set value and signal semaphore
21532 test_->sem_value_ = 1; 21532 test_->sem_value_ = 1;
21533 test_->sem_.Signal(); 21533 test_->sem_.Signal();
21534 } 21534 }
21535 21535
21536 static void SignalHandler(int signal) { 21536 static void SignalHandler(int signal) {
21537 } 21537 }
21538 21538
21539 private: 21539 private:
21540 ThreadInterruptTest* test_; 21540 ThreadInterruptTest* test_;
21541 }; 21541 };
21542 21542
21543 i::Semaphore sem_; 21543 v8::base::Semaphore sem_;
21544 volatile int sem_value_; 21544 volatile int sem_value_;
21545 }; 21545 };
21546 21546
21547 21547
21548 THREADED_TEST(SemaphoreInterruption) { 21548 THREADED_TEST(SemaphoreInterruption) {
21549 ThreadInterruptTest().RunTest(); 21549 ThreadInterruptTest().RunTest();
21550 } 21550 }
21551 21551
21552 21552
21553 #endif // V8_OS_POSIX 21553 #endif // V8_OS_POSIX
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
21893 static void ShouldContinueCallback( 21893 static void ShouldContinueCallback(
21894 const v8::FunctionCallbackInfo<Value>& info) { 21894 const v8::FunctionCallbackInfo<Value>& info) {
21895 RequestInterruptTestBase* test = 21895 RequestInterruptTestBase* test =
21896 reinterpret_cast<RequestInterruptTestBase*>( 21896 reinterpret_cast<RequestInterruptTestBase*>(
21897 info.Data().As<v8::External>()->Value()); 21897 info.Data().As<v8::External>()->Value());
21898 info.GetReturnValue().Set(test->ShouldContinue()); 21898 info.GetReturnValue().Set(test->ShouldContinue());
21899 } 21899 }
21900 21900
21901 LocalContext env_; 21901 LocalContext env_;
21902 v8::Isolate* isolate_; 21902 v8::Isolate* isolate_;
21903 i::Semaphore sem_; 21903 v8::base::Semaphore sem_;
21904 int warmup_; 21904 int warmup_;
21905 bool should_continue_; 21905 bool should_continue_;
21906 }; 21906 };
21907 21907
21908 21908
21909 class RequestInterruptTestBaseWithSimpleInterrupt 21909 class RequestInterruptTestBaseWithSimpleInterrupt
21910 : public RequestInterruptTestBase { 21910 : public RequestInterruptTestBase {
21911 public: 21911 public:
21912 RequestInterruptTestBaseWithSimpleInterrupt() : i_thread(this) { } 21912 RequestInterruptTestBaseWithSimpleInterrupt() : i_thread(this) { }
21913 21913
21914 virtual void StartInterruptThread() { 21914 virtual void StartInterruptThread() {
21915 i_thread.Start(); 21915 i_thread.Start();
21916 } 21916 }
21917 21917
21918 private: 21918 private:
21919 class InterruptThread : public i::Thread { 21919 class InterruptThread : public v8::base::Thread {
21920 public: 21920 public:
21921 explicit InterruptThread(RequestInterruptTestBase* test) 21921 explicit InterruptThread(RequestInterruptTestBase* test)
21922 : Thread("RequestInterruptTest"), test_(test) {} 21922 : Thread("RequestInterruptTest"), test_(test) {}
21923 21923
21924 virtual void Run() { 21924 virtual void Run() {
21925 test_->sem_.Wait(); 21925 test_->sem_.Wait();
21926 test_->isolate_->RequestInterrupt(&OnInterrupt, test_); 21926 test_->isolate_->RequestInterrupt(&OnInterrupt, test_);
21927 } 21927 }
21928 21928
21929 static void OnInterrupt(v8::Isolate* isolate, void* data) { 21929 static void OnInterrupt(v8::Isolate* isolate, void* data) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
22129 22129
22130 virtual void TestBody() { 22130 virtual void TestBody() {
22131 Local<Function> func = Function::New( 22131 Local<Function> func = Function::New(
22132 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)); 22132 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this));
22133 env_->Global()->Set(v8_str("ShouldContinue"), func); 22133 env_->Global()->Set(v8_str("ShouldContinue"), func);
22134 22134
22135 CompileRun("while (ShouldContinue()) { }"); 22135 CompileRun("while (ShouldContinue()) { }");
22136 } 22136 }
22137 22137
22138 private: 22138 private:
22139 class InterruptThread : public i::Thread { 22139 class InterruptThread : public v8::base::Thread {
22140 public: 22140 public:
22141 explicit InterruptThread(ClearInterruptFromAnotherThread* test) 22141 explicit InterruptThread(ClearInterruptFromAnotherThread* test)
22142 : Thread("RequestInterruptTest"), test_(test) {} 22142 : Thread("RequestInterruptTest"), test_(test) {}
22143 22143
22144 virtual void Run() { 22144 virtual void Run() {
22145 test_->sem_.Wait(); 22145 test_->sem_.Wait();
22146 test_->isolate_->RequestInterrupt(&OnInterrupt, test_); 22146 test_->isolate_->RequestInterrupt(&OnInterrupt, test_);
22147 test_->sem_.Wait(); 22147 test_->sem_.Wait();
22148 test_->isolate_->ClearInterrupt(); 22148 test_->isolate_->ClearInterrupt();
22149 test_->sem2_.Signal(); 22149 test_->sem2_.Signal();
22150 } 22150 }
22151 22151
22152 static void OnInterrupt(v8::Isolate* isolate, void* data) { 22152 static void OnInterrupt(v8::Isolate* isolate, void* data) {
22153 ClearInterruptFromAnotherThread* test = 22153 ClearInterruptFromAnotherThread* test =
22154 reinterpret_cast<ClearInterruptFromAnotherThread*>(data); 22154 reinterpret_cast<ClearInterruptFromAnotherThread*>(data);
22155 test->sem_.Signal(); 22155 test->sem_.Signal();
22156 bool success = test->sem2_.WaitFor(i::TimeDelta::FromSeconds(2)); 22156 bool success = test->sem2_.WaitFor(v8::base::TimeDelta::FromSeconds(2));
22157 // Crash instead of timeout to make this failure more prominent. 22157 // Crash instead of timeout to make this failure more prominent.
22158 CHECK(success); 22158 CHECK(success);
22159 test->should_continue_ = false; 22159 test->should_continue_ = false;
22160 } 22160 }
22161 22161
22162 private: 22162 private:
22163 ClearInterruptFromAnotherThread* test_; 22163 ClearInterruptFromAnotherThread* test_;
22164 }; 22164 };
22165 22165
22166 InterruptThread i_thread; 22166 InterruptThread i_thread;
22167 i::Semaphore sem2_; 22167 v8::base::Semaphore sem2_;
22168 }; 22168 };
22169 22169
22170 22170
22171 TEST(ClearInterruptFromAnotherThread) { 22171 TEST(ClearInterruptFromAnotherThread) {
22172 ClearInterruptFromAnotherThread().RunTest(); 22172 ClearInterruptFromAnotherThread().RunTest();
22173 } 22173 }
22174 22174
22175 22175
22176 static Local<Value> function_new_expected_env; 22176 static Local<Value> function_new_expected_env;
22177 static void FunctionNewCallback(const v8::FunctionCallbackInfo<Value>& info) { 22177 static void FunctionNewCallback(const v8::FunctionCallbackInfo<Value>& info) {
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
22754 call_eval_context = v8::Context::New(isolate); 22754 call_eval_context = v8::Context::New(isolate);
22755 v8::Context::Scope scope(call_eval_context); 22755 v8::Context::Scope scope(call_eval_context);
22756 call_eval_bound_function = 22756 call_eval_bound_function =
22757 Local<Function>::Cast(CompileRun("eval.bind(this, '1')")); 22757 Local<Function>::Cast(CompileRun("eval.bind(this, '1')"));
22758 } 22758 }
22759 env->Global()->Set(v8_str("CallEval"), 22759 env->Global()->Set(v8_str("CallEval"),
22760 v8::FunctionTemplate::New(isolate, CallEval)->GetFunction()); 22760 v8::FunctionTemplate::New(isolate, CallEval)->GetFunction());
22761 Local<Value> result = CompileRun("CallEval();"); 22761 Local<Value> result = CompileRun("CallEval();");
22762 CHECK_EQ(result, v8::Integer::New(isolate, 1)); 22762 CHECK_EQ(result, v8::Integer::New(isolate, 1));
22763 } 22763 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698