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

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

Issue 583153002: Reland 24052 - Require V8 to be explicitly initialized before an Isolate is created (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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/cctest.cc ('k') | test/cctest/test-ast.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 19468 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 IsolateThread(v8::Isolate* isolate, int fib_limit) 19489 explicit IsolateThread(int fib_limit)
19490 : Thread(Options("IsolateThread")), 19490 : Thread(Options("IsolateThread")), fib_limit_(fib_limit), result_(0) {}
19491 isolate_(isolate),
19492 fib_limit_(fib_limit),
19493 result_(0) {}
19494 19491
19495 void Run() { 19492 void Run() {
19496 result_ = CalcFibonacci(isolate_, fib_limit_); 19493 v8::Isolate* isolate = v8::Isolate::New();
19494 result_ = CalcFibonacci(isolate, fib_limit_);
19495 isolate->Dispose();
19497 } 19496 }
19498 19497
19499 int result() { return result_; } 19498 int result() { return result_; }
19500 19499
19501 private: 19500 private:
19502 v8::Isolate* isolate_;
19503 int fib_limit_; 19501 int fib_limit_;
19504 int result_; 19502 int result_;
19505 }; 19503 };
19506 19504
19507 19505
19508 TEST(MultipleIsolatesOnIndividualThreads) { 19506 TEST(MultipleIsolatesOnIndividualThreads) {
19509 v8::Isolate* isolate1 = v8::Isolate::New(); 19507 IsolateThread thread1(21);
19510 v8::Isolate* isolate2 = v8::Isolate::New(); 19508 IsolateThread thread2(12);
19511
19512 IsolateThread thread1(isolate1, 21);
19513 IsolateThread thread2(isolate2, 12);
19514 19509
19515 // Compute some fibonacci numbers on 3 threads in 3 isolates. 19510 // Compute some fibonacci numbers on 3 threads in 3 isolates.
19516 thread1.Start(); 19511 thread1.Start();
19517 thread2.Start(); 19512 thread2.Start();
19518 19513
19519 int result1 = CalcFibonacci(CcTest::isolate(), 21); 19514 int result1 = CalcFibonacci(CcTest::isolate(), 21);
19520 int result2 = CalcFibonacci(CcTest::isolate(), 12); 19515 int result2 = CalcFibonacci(CcTest::isolate(), 12);
19521 19516
19522 thread1.Join(); 19517 thread1.Join();
19523 thread2.Join(); 19518 thread2.Join();
19524 19519
19525 // Compare results. The actual fibonacci numbers for 12 and 21 are taken 19520 // Compare results. The actual fibonacci numbers for 12 and 21 are taken
19526 // (I'm lazy!) from http://en.wikipedia.org/wiki/Fibonacci_number 19521 // (I'm lazy!) from http://en.wikipedia.org/wiki/Fibonacci_number
19527 CHECK_EQ(result1, 10946); 19522 CHECK_EQ(result1, 10946);
19528 CHECK_EQ(result2, 144); 19523 CHECK_EQ(result2, 144);
19529 CHECK_EQ(result1, thread1.result()); 19524 CHECK_EQ(result1, thread1.result());
19530 CHECK_EQ(result2, thread2.result()); 19525 CHECK_EQ(result2, thread2.result());
19531
19532 isolate1->Dispose();
19533 isolate2->Dispose();
19534 } 19526 }
19535 19527
19536 19528
19537 TEST(IsolateDifferentContexts) { 19529 TEST(IsolateDifferentContexts) {
19538 v8::Isolate* isolate = v8::Isolate::New(); 19530 v8::Isolate* isolate = v8::Isolate::New();
19539 Local<v8::Context> context; 19531 Local<v8::Context> context;
19540 { 19532 {
19541 v8::Isolate::Scope isolate_scope(isolate); 19533 v8::Isolate::Scope isolate_scope(isolate);
19542 v8::HandleScope handle_scope(isolate); 19534 v8::HandleScope handle_scope(isolate);
19543 context = v8::Context::New(isolate); 19535 context = v8::Context::New(isolate);
(...skipping 3775 matching lines...) Expand 10 before | Expand all | Expand 10 after
23319 // TestSourceStream::GetMoreData won't block, so it's OK to just run the 23311 // TestSourceStream::GetMoreData won't block, so it's OK to just run the
23320 // task here in the main thread. 23312 // task here in the main thread.
23321 task->Run(); 23313 task->Run();
23322 delete task; 23314 delete task;
23323 23315
23324 const v8::ScriptCompiler::CachedData* cached_data = source.GetCachedData(); 23316 const v8::ScriptCompiler::CachedData* cached_data = source.GetCachedData();
23325 CHECK(cached_data != NULL); 23317 CHECK(cached_data != NULL);
23326 CHECK(cached_data->data != NULL); 23318 CHECK(cached_data->data != NULL);
23327 CHECK_GT(cached_data->length, 0); 23319 CHECK_GT(cached_data->length, 0);
23328 } 23320 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.cc ('k') | test/cctest/test-ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698