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

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

Issue 484643002: Version 3.28.71.3 (merged r23081) (Closed) Base URL: https://v8.googlecode.com/svn/branches/3.28
Patch Set: Created 6 years, 4 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
« no previous file with comments | « test/cctest/compiler/test-simplified-lowering.cc ('k') | test/cctest/test-circular-queue.cc » ('j') | 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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 LocalContext env; 402 LocalContext env;
403 v8::HandleScope scope(env->GetIsolate()); 403 v8::HandleScope scope(env->GetIsolate());
404 const char* source = "1 + 2 + 3"; 404 const char* source = "1 + 2 + 3";
405 Local<Script> script = v8_compile(source); 405 Local<Script> script = v8_compile(source);
406 CHECK_EQ(6, script->Run()->Int32Value()); 406 CHECK_EQ(6, script->Run()->Int32Value());
407 } 407 }
408 408
409 409
410 class TestResource: public String::ExternalStringResource { 410 class TestResource: public String::ExternalStringResource {
411 public: 411 public:
412 TestResource(uint16_t* data, int* counter = NULL, bool owning_data = true) 412 explicit TestResource(uint16_t* data, int* counter = NULL,
413 bool owning_data = true)
413 : data_(data), length_(0), counter_(counter), owning_data_(owning_data) { 414 : data_(data), length_(0), counter_(counter), owning_data_(owning_data) {
414 while (data[length_]) ++length_; 415 while (data[length_]) ++length_;
415 } 416 }
416 417
417 ~TestResource() { 418 ~TestResource() {
418 if (owning_data_) i::DeleteArray(data_); 419 if (owning_data_) i::DeleteArray(data_);
419 if (counter_ != NULL) ++*counter_; 420 if (counter_ != NULL) ++*counter_;
420 } 421 }
421 422
422 const uint16_t* data() const { 423 const uint16_t* data() const {
423 return data_; 424 return data_;
424 } 425 }
425 426
426 size_t length() const { 427 size_t length() const {
427 return length_; 428 return length_;
428 } 429 }
429 430
430 private: 431 private:
431 uint16_t* data_; 432 uint16_t* data_;
432 size_t length_; 433 size_t length_;
433 int* counter_; 434 int* counter_;
434 bool owning_data_; 435 bool owning_data_;
435 }; 436 };
436 437
437 438
438 class TestAsciiResource: public String::ExternalAsciiStringResource { 439 class TestAsciiResource: public String::ExternalAsciiStringResource {
439 public: 440 public:
440 TestAsciiResource(const char* data, int* counter = NULL, size_t offset = 0) 441 explicit TestAsciiResource(const char* data, int* counter = NULL,
442 size_t offset = 0)
441 : orig_data_(data), 443 : orig_data_(data),
442 data_(data + offset), 444 data_(data + offset),
443 length_(strlen(data) - offset), 445 length_(strlen(data) - offset),
444 counter_(counter) { } 446 counter_(counter) {}
445 447
446 ~TestAsciiResource() { 448 ~TestAsciiResource() {
447 i::DeleteArray(orig_data_); 449 i::DeleteArray(orig_data_);
448 if (counter_ != NULL) ++*counter_; 450 if (counter_ != NULL) ++*counter_;
449 } 451 }
450 452
451 const char* data() const { 453 const char* data() const {
452 return data_; 454 return data_;
453 } 455 }
454 456
(...skipping 14696 matching lines...) Expand 10 before | Expand all | Expand 10 after
15151 struct RegExpInterruptionData { 15153 struct RegExpInterruptionData {
15152 int loop_count; 15154 int loop_count;
15153 UC16VectorResource* string_resource; 15155 UC16VectorResource* string_resource;
15154 v8::Persistent<v8::String> string; 15156 v8::Persistent<v8::String> string;
15155 } regexp_interruption_data; 15157 } regexp_interruption_data;
15156 15158
15157 15159
15158 class RegExpInterruptionThread : public v8::base::Thread { 15160 class RegExpInterruptionThread : public v8::base::Thread {
15159 public: 15161 public:
15160 explicit RegExpInterruptionThread(v8::Isolate* isolate) 15162 explicit RegExpInterruptionThread(v8::Isolate* isolate)
15161 : Thread("TimeoutThread"), isolate_(isolate) {} 15163 : Thread(Options("TimeoutThread")), isolate_(isolate) {}
15162 15164
15163 virtual void Run() { 15165 virtual void Run() {
15164 for (regexp_interruption_data.loop_count = 0; 15166 for (regexp_interruption_data.loop_count = 0;
15165 regexp_interruption_data.loop_count < 7; 15167 regexp_interruption_data.loop_count < 7;
15166 regexp_interruption_data.loop_count++) { 15168 regexp_interruption_data.loop_count++) {
15167 v8::base::OS::Sleep(50); // Wait a bit before requesting GC. 15169 v8::base::OS::Sleep(50); // Wait a bit before requesting GC.
15168 reinterpret_cast<i::Isolate*>(isolate_)->stack_guard()->RequestGC(); 15170 reinterpret_cast<i::Isolate*>(isolate_)->stack_guard()->RequestGC();
15169 } 15171 }
15170 v8::base::OS::Sleep(50); // Wait a bit before terminating. 15172 v8::base::OS::Sleep(50); // Wait a bit before terminating.
15171 v8::V8::TerminateExecution(isolate_); 15173 v8::V8::TerminateExecution(isolate_);
(...skipping 4187 matching lines...) Expand 10 before | Expand all | Expand 10 after
19359 "}" 19361 "}"
19360 "fib(%d)", limit); 19362 "fib(%d)", limit);
19361 Local<Value> value = CompileRun(code.start()); 19363 Local<Value> value = CompileRun(code.start());
19362 CHECK(value->IsNumber()); 19364 CHECK(value->IsNumber());
19363 return static_cast<int>(value->NumberValue()); 19365 return static_cast<int>(value->NumberValue());
19364 } 19366 }
19365 19367
19366 class IsolateThread : public v8::base::Thread { 19368 class IsolateThread : public v8::base::Thread {
19367 public: 19369 public:
19368 IsolateThread(v8::Isolate* isolate, int fib_limit) 19370 IsolateThread(v8::Isolate* isolate, int fib_limit)
19369 : Thread("IsolateThread"), 19371 : Thread(Options("IsolateThread")),
19370 isolate_(isolate), 19372 isolate_(isolate),
19371 fib_limit_(fib_limit), 19373 fib_limit_(fib_limit),
19372 result_(0) { } 19374 result_(0) {}
19373 19375
19374 void Run() { 19376 void Run() {
19375 result_ = CalcFibonacci(isolate_, fib_limit_); 19377 result_ = CalcFibonacci(isolate_, fib_limit_);
19376 } 19378 }
19377 19379
19378 int result() { return result_; } 19380 int result() { return result_; }
19379 19381
19380 private: 19382 private:
19381 v8::Isolate* isolate_; 19383 v8::Isolate* isolate_;
19382 int fib_limit_; 19384 int fib_limit_;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
19441 public: 19443 public:
19442 enum TestCase { 19444 enum TestCase {
19443 SetResourceConstraints, 19445 SetResourceConstraints,
19444 SetFatalHandler, 19446 SetFatalHandler,
19445 SetCounterFunction, 19447 SetCounterFunction,
19446 SetCreateHistogramFunction, 19448 SetCreateHistogramFunction,
19447 SetAddHistogramSampleFunction 19449 SetAddHistogramSampleFunction
19448 }; 19450 };
19449 19451
19450 explicit InitDefaultIsolateThread(TestCase testCase) 19452 explicit InitDefaultIsolateThread(TestCase testCase)
19451 : Thread("InitDefaultIsolateThread"), 19453 : Thread(Options("InitDefaultIsolateThread")),
19452 testCase_(testCase), 19454 testCase_(testCase),
19453 result_(false) { } 19455 result_(false) {}
19454 19456
19455 void Run() { 19457 void Run() {
19456 v8::Isolate* isolate = v8::Isolate::New(); 19458 v8::Isolate* isolate = v8::Isolate::New();
19457 isolate->Enter(); 19459 isolate->Enter();
19458 switch (testCase_) { 19460 switch (testCase_) {
19459 case SetResourceConstraints: { 19461 case SetResourceConstraints: {
19460 v8::ResourceConstraints constraints; 19462 v8::ResourceConstraints constraints;
19461 constraints.set_max_semi_space_size(1); 19463 constraints.set_max_semi_space_size(1);
19462 constraints.set_max_old_space_size(4); 19464 constraints.set_max_old_space_size(4);
19463 v8::SetResourceConstraints(CcTest::isolate(), &constraints); 19465 v8::SetResourceConstraints(CcTest::isolate(), &constraints);
(...skipping 2037 matching lines...) Expand 10 before | Expand all | Expand 10 after
21501 sem_.Wait(); 21503 sem_.Wait();
21502 CHECK_EQ(kExpectedValue, sem_value_); 21504 CHECK_EQ(kExpectedValue, sem_value_);
21503 } 21505 }
21504 21506
21505 private: 21507 private:
21506 static const int kExpectedValue = 1; 21508 static const int kExpectedValue = 1;
21507 21509
21508 class InterruptThread : public v8::base::Thread { 21510 class InterruptThread : public v8::base::Thread {
21509 public: 21511 public:
21510 explicit InterruptThread(ThreadInterruptTest* test) 21512 explicit InterruptThread(ThreadInterruptTest* test)
21511 : Thread("InterruptThread"), test_(test) {} 21513 : Thread(Options("InterruptThread")), test_(test) {}
21512 21514
21513 virtual void Run() { 21515 virtual void Run() {
21514 struct sigaction action; 21516 struct sigaction action;
21515 21517
21516 // Ensure that we'll enter waiting condition 21518 // Ensure that we'll enter waiting condition
21517 v8::base::OS::Sleep(100); 21519 v8::base::OS::Sleep(100);
21518 21520
21519 // Setup signal handler 21521 // Setup signal handler
21520 memset(&action, 0, sizeof(action)); 21522 memset(&action, 0, sizeof(action));
21521 action.sa_handler = SignalHandler; 21523 action.sa_handler = SignalHandler;
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
21909 RequestInterruptTestBaseWithSimpleInterrupt() : i_thread(this) { } 21911 RequestInterruptTestBaseWithSimpleInterrupt() : i_thread(this) { }
21910 21912
21911 virtual void StartInterruptThread() { 21913 virtual void StartInterruptThread() {
21912 i_thread.Start(); 21914 i_thread.Start();
21913 } 21915 }
21914 21916
21915 private: 21917 private:
21916 class InterruptThread : public v8::base::Thread { 21918 class InterruptThread : public v8::base::Thread {
21917 public: 21919 public:
21918 explicit InterruptThread(RequestInterruptTestBase* test) 21920 explicit InterruptThread(RequestInterruptTestBase* test)
21919 : Thread("RequestInterruptTest"), test_(test) {} 21921 : Thread(Options("RequestInterruptTest")), test_(test) {}
21920 21922
21921 virtual void Run() { 21923 virtual void Run() {
21922 test_->sem_.Wait(); 21924 test_->sem_.Wait();
21923 test_->isolate_->RequestInterrupt(&OnInterrupt, test_); 21925 test_->isolate_->RequestInterrupt(&OnInterrupt, test_);
21924 } 21926 }
21925 21927
21926 static void OnInterrupt(v8::Isolate* isolate, void* data) { 21928 static void OnInterrupt(v8::Isolate* isolate, void* data) {
21927 reinterpret_cast<RequestInterruptTestBase*>(data)-> 21929 reinterpret_cast<RequestInterruptTestBase*>(data)->
21928 should_continue_ = false; 21930 should_continue_ = false;
21929 } 21931 }
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
22129 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)); 22131 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this));
22130 env_->Global()->Set(v8_str("ShouldContinue"), func); 22132 env_->Global()->Set(v8_str("ShouldContinue"), func);
22131 22133
22132 CompileRun("while (ShouldContinue()) { }"); 22134 CompileRun("while (ShouldContinue()) { }");
22133 } 22135 }
22134 22136
22135 private: 22137 private:
22136 class InterruptThread : public v8::base::Thread { 22138 class InterruptThread : public v8::base::Thread {
22137 public: 22139 public:
22138 explicit InterruptThread(ClearInterruptFromAnotherThread* test) 22140 explicit InterruptThread(ClearInterruptFromAnotherThread* test)
22139 : Thread("RequestInterruptTest"), test_(test) {} 22141 : Thread(Options("RequestInterruptTest")), test_(test) {}
22140 22142
22141 virtual void Run() { 22143 virtual void Run() {
22142 test_->sem_.Wait(); 22144 test_->sem_.Wait();
22143 test_->isolate_->RequestInterrupt(&OnInterrupt, test_); 22145 test_->isolate_->RequestInterrupt(&OnInterrupt, test_);
22144 test_->sem_.Wait(); 22146 test_->sem_.Wait();
22145 test_->isolate_->ClearInterrupt(); 22147 test_->isolate_->ClearInterrupt();
22146 test_->sem2_.Signal(); 22148 test_->sem2_.Signal();
22147 } 22149 }
22148 22150
22149 static void OnInterrupt(v8::Isolate* isolate, void* data) { 22151 static void OnInterrupt(v8::Isolate* isolate, void* data) {
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
22861 desc = x->GetOwnPropertyDescriptor(v8_str("p1")); 22863 desc = x->GetOwnPropertyDescriptor(v8_str("p1"));
22862 Local<Function> set = 22864 Local<Function> set =
22863 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set"))); 22865 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set")));
22864 Local<Function> get = 22866 Local<Function> get =
22865 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get"))); 22867 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get")));
22866 CHECK_EQ(v8_num(13), get->Call(x, 0, NULL)); 22868 CHECK_EQ(v8_num(13), get->Call(x, 0, NULL));
22867 Handle<Value> args[] = { v8_num(14) }; 22869 Handle<Value> args[] = { v8_num(14) };
22868 set->Call(x, 1, args); 22870 set->Call(x, 1, args);
22869 CHECK_EQ(v8_num(14), get->Call(x, 0, NULL)); 22871 CHECK_EQ(v8_num(14), get->Call(x, 0, NULL));
22870 } 22872 }
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-simplified-lowering.cc ('k') | test/cctest/test-circular-queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698