| 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 19468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19479 " return fib(n-1) + fib(n-2);" | 19479 " return fib(n-1) + fib(n-2);" |
| 19480 "}" | 19480 "}" |
| 19481 "fib(%d)", limit); | 19481 "fib(%d)", limit); |
| 19482 Local<Value> value = CompileRun(code.start()); | 19482 Local<Value> value = CompileRun(code.start()); |
| 19483 CHECK(value->IsNumber()); | 19483 CHECK(value->IsNumber()); |
| 19484 return static_cast<int>(value->NumberValue()); | 19484 return static_cast<int>(value->NumberValue()); |
| 19485 } | 19485 } |
| 19486 | 19486 |
| 19487 class IsolateThread : public v8::base::Thread { | 19487 class IsolateThread : public v8::base::Thread { |
| 19488 public: | 19488 public: |
| 19489 explicit IsolateThread(int fib_limit) | 19489 IsolateThread(v8::Isolate* isolate, int fib_limit) |
| 19490 : Thread(Options("IsolateThread")), fib_limit_(fib_limit), result_(0) {} | 19490 : Thread(Options("IsolateThread")), |
| 19491 isolate_(isolate), |
| 19492 fib_limit_(fib_limit), |
| 19493 result_(0) {} |
| 19491 | 19494 |
| 19492 void Run() { | 19495 void Run() { |
| 19493 v8::Isolate* isolate = v8::Isolate::New(); | 19496 result_ = CalcFibonacci(isolate_, fib_limit_); |
| 19494 result_ = CalcFibonacci(isolate, fib_limit_); | |
| 19495 isolate->Dispose(); | |
| 19496 } | 19497 } |
| 19497 | 19498 |
| 19498 int result() { return result_; } | 19499 int result() { return result_; } |
| 19499 | 19500 |
| 19500 private: | 19501 private: |
| 19502 v8::Isolate* isolate_; |
| 19501 int fib_limit_; | 19503 int fib_limit_; |
| 19502 int result_; | 19504 int result_; |
| 19503 }; | 19505 }; |
| 19504 | 19506 |
| 19505 | 19507 |
| 19506 TEST(MultipleIsolatesOnIndividualThreads) { | 19508 TEST(MultipleIsolatesOnIndividualThreads) { |
| 19507 IsolateThread thread1(21); | 19509 v8::Isolate* isolate1 = v8::Isolate::New(); |
| 19508 IsolateThread thread2(12); | 19510 v8::Isolate* isolate2 = v8::Isolate::New(); |
| 19511 |
| 19512 IsolateThread thread1(isolate1, 21); |
| 19513 IsolateThread thread2(isolate2, 12); |
| 19509 | 19514 |
| 19510 // Compute some fibonacci numbers on 3 threads in 3 isolates. | 19515 // Compute some fibonacci numbers on 3 threads in 3 isolates. |
| 19511 thread1.Start(); | 19516 thread1.Start(); |
| 19512 thread2.Start(); | 19517 thread2.Start(); |
| 19513 | 19518 |
| 19514 int result1 = CalcFibonacci(CcTest::isolate(), 21); | 19519 int result1 = CalcFibonacci(CcTest::isolate(), 21); |
| 19515 int result2 = CalcFibonacci(CcTest::isolate(), 12); | 19520 int result2 = CalcFibonacci(CcTest::isolate(), 12); |
| 19516 | 19521 |
| 19517 thread1.Join(); | 19522 thread1.Join(); |
| 19518 thread2.Join(); | 19523 thread2.Join(); |
| 19519 | 19524 |
| 19520 // Compare results. The actual fibonacci numbers for 12 and 21 are taken | 19525 // Compare results. The actual fibonacci numbers for 12 and 21 are taken |
| 19521 // (I'm lazy!) from http://en.wikipedia.org/wiki/Fibonacci_number | 19526 // (I'm lazy!) from http://en.wikipedia.org/wiki/Fibonacci_number |
| 19522 CHECK_EQ(result1, 10946); | 19527 CHECK_EQ(result1, 10946); |
| 19523 CHECK_EQ(result2, 144); | 19528 CHECK_EQ(result2, 144); |
| 19524 CHECK_EQ(result1, thread1.result()); | 19529 CHECK_EQ(result1, thread1.result()); |
| 19525 CHECK_EQ(result2, thread2.result()); | 19530 CHECK_EQ(result2, thread2.result()); |
| 19531 |
| 19532 isolate1->Dispose(); |
| 19533 isolate2->Dispose(); |
| 19526 } | 19534 } |
| 19527 | 19535 |
| 19528 | 19536 |
| 19529 TEST(IsolateDifferentContexts) { | 19537 TEST(IsolateDifferentContexts) { |
| 19530 v8::Isolate* isolate = v8::Isolate::New(); | 19538 v8::Isolate* isolate = v8::Isolate::New(); |
| 19531 Local<v8::Context> context; | 19539 Local<v8::Context> context; |
| 19532 { | 19540 { |
| 19533 v8::Isolate::Scope isolate_scope(isolate); | 19541 v8::Isolate::Scope isolate_scope(isolate); |
| 19534 v8::HandleScope handle_scope(isolate); | 19542 v8::HandleScope handle_scope(isolate); |
| 19535 context = v8::Context::New(isolate); | 19543 context = v8::Context::New(isolate); |
| (...skipping 3775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 23311 // TestSourceStream::GetMoreData won't block, so it's OK to just run the | 23319 // TestSourceStream::GetMoreData won't block, so it's OK to just run the |
| 23312 // task here in the main thread. | 23320 // task here in the main thread. |
| 23313 task->Run(); | 23321 task->Run(); |
| 23314 delete task; | 23322 delete task; |
| 23315 | 23323 |
| 23316 const v8::ScriptCompiler::CachedData* cached_data = source.GetCachedData(); | 23324 const v8::ScriptCompiler::CachedData* cached_data = source.GetCachedData(); |
| 23317 CHECK(cached_data != NULL); | 23325 CHECK(cached_data != NULL); |
| 23318 CHECK(cached_data->data != NULL); | 23326 CHECK(cached_data->data != NULL); |
| 23319 CHECK_GT(cached_data->length, 0); | 23327 CHECK_GT(cached_data->length, 0); |
| 23320 } | 23328 } |
| OLD | NEW |