| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 LocalContext(v8::ExtensionConfiguration* extensions = 0, | 248 LocalContext(v8::ExtensionConfiguration* extensions = 0, |
| 249 v8::Handle<v8::ObjectTemplate> global_template = | 249 v8::Handle<v8::ObjectTemplate> global_template = |
| 250 v8::Handle<v8::ObjectTemplate>(), | 250 v8::Handle<v8::ObjectTemplate>(), |
| 251 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) { | 251 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) { |
| 252 Initialize(CcTest::isolate(), extensions, global_template, global_object); | 252 Initialize(CcTest::isolate(), extensions, global_template, global_object); |
| 253 } | 253 } |
| 254 | 254 |
| 255 virtual ~LocalContext() { | 255 virtual ~LocalContext() { |
| 256 v8::HandleScope scope(isolate_); | 256 v8::HandleScope scope(isolate_); |
| 257 v8::Local<v8::Context>::New(isolate_, context_)->Exit(); | 257 v8::Local<v8::Context>::New(isolate_, context_)->Exit(); |
| 258 context_.Dispose(); | 258 context_.Reset(); |
| 259 } | 259 } |
| 260 | 260 |
| 261 v8::Context* operator->() { | 261 v8::Context* operator->() { |
| 262 return *reinterpret_cast<v8::Context**>(&context_); | 262 return *reinterpret_cast<v8::Context**>(&context_); |
| 263 } | 263 } |
| 264 v8::Context* operator*() { return operator->(); } | 264 v8::Context* operator*() { return operator->(); } |
| 265 bool IsReady() { return !context_.IsEmpty(); } | 265 bool IsReady() { return !context_.IsEmpty(); } |
| 266 | 266 |
| 267 v8::Local<v8::Context> local() { | 267 v8::Local<v8::Context> local() { |
| 268 return v8::Local<v8::Context>::New(isolate_, context_); | 268 return v8::Local<v8::Context>::New(isolate_, context_); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 287 v8::Persistent<v8::Context> context_; | 287 v8::Persistent<v8::Context> context_; |
| 288 v8::Isolate* isolate_; | 288 v8::Isolate* isolate_; |
| 289 }; | 289 }; |
| 290 | 290 |
| 291 static inline v8::Local<v8::Value> v8_num(double x) { | 291 static inline v8::Local<v8::Value> v8_num(double x) { |
| 292 return v8::Number::New(x); | 292 return v8::Number::New(x); |
| 293 } | 293 } |
| 294 | 294 |
| 295 | 295 |
| 296 static inline v8::Local<v8::String> v8_str(const char* x) { | 296 static inline v8::Local<v8::String> v8_str(const char* x) { |
| 297 return v8::String::New(x); | 297 return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), x); |
| 298 } | 298 } |
| 299 | 299 |
| 300 | 300 |
| 301 static inline v8::Local<v8::Script> v8_compile(const char* x) { | 301 static inline v8::Local<v8::Script> v8_compile(const char* x) { |
| 302 return v8::Script::Compile(v8_str(x)); | 302 return v8::Script::Compile(v8_str(x)); |
| 303 } | 303 } |
| 304 | 304 |
| 305 | 305 |
| 306 // Helper function that compiles and runs the source. | 306 // Helper function that compiles and runs the source. |
| 307 static inline v8::Local<v8::Value> CompileRun(const char* source) { | 307 static inline v8::Local<v8::Value> CompileRun(const char* source) { |
| 308 return v8::Script::Compile(v8::String::New(source))->Run(); | 308 return v8::Script::Compile( |
| 309 v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), source))->Run(); |
| 309 } | 310 } |
| 310 | 311 |
| 311 | 312 |
| 312 // Helper function that compiles and runs the source with given origin. | 313 // Helper function that compiles and runs the source with given origin. |
| 313 static inline v8::Local<v8::Value> CompileRunWithOrigin(const char* source, | 314 static inline v8::Local<v8::Value> CompileRunWithOrigin(const char* source, |
| 314 const char* origin_url, | 315 const char* origin_url, |
| 315 int line_number, | 316 int line_number, |
| 316 int column_number) { | 317 int column_number) { |
| 317 v8::ScriptOrigin origin(v8::String::New(origin_url), | 318 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 319 v8::ScriptOrigin origin(v8::String::NewFromUtf8(isolate, origin_url), |
| 318 v8::Integer::New(line_number), | 320 v8::Integer::New(line_number), |
| 319 v8::Integer::New(column_number)); | 321 v8::Integer::New(column_number)); |
| 320 return v8::Script::Compile(v8::String::New(source), &origin)->Run(); | 322 return v8::Script::Compile(v8::String::NewFromUtf8(isolate, source), &origin) |
| 323 ->Run(); |
| 321 } | 324 } |
| 322 | 325 |
| 323 | 326 |
| 324 // Pick a slightly different port to allow tests to be run in parallel. | 327 // Pick a slightly different port to allow tests to be run in parallel. |
| 325 static inline int FlagDependentPortOffset() { | 328 static inline int FlagDependentPortOffset() { |
| 326 return ::v8::internal::FLAG_crankshaft == false ? 100 : | 329 return ::v8::internal::FLAG_crankshaft == false ? 100 : |
| 327 ::v8::internal::FLAG_always_opt ? 200 : 0; | 330 ::v8::internal::FLAG_always_opt ? 200 : 0; |
| 328 } | 331 } |
| 329 | 332 |
| 330 | 333 |
| 331 // Helper function that simulates a full new-space in the heap. | 334 // Helper function that simulates a full new-space in the heap. |
| 332 static inline void SimulateFullSpace(v8::internal::NewSpace* space) { | 335 static inline void SimulateFullSpace(v8::internal::NewSpace* space) { |
| 333 int new_linear_size = static_cast<int>( | 336 int new_linear_size = static_cast<int>( |
| 334 *space->allocation_limit_address() - *space->allocation_top_address()); | 337 *space->allocation_limit_address() - *space->allocation_top_address()); |
| 338 if (new_linear_size == 0) return; |
| 335 v8::internal::MaybeObject* maybe = space->AllocateRaw(new_linear_size); | 339 v8::internal::MaybeObject* maybe = space->AllocateRaw(new_linear_size); |
| 336 v8::internal::FreeListNode* node = v8::internal::FreeListNode::cast(maybe); | 340 v8::internal::FreeListNode* node = v8::internal::FreeListNode::cast(maybe); |
| 337 node->set_size(space->heap(), new_linear_size); | 341 node->set_size(space->heap(), new_linear_size); |
| 338 } | 342 } |
| 339 | 343 |
| 340 | 344 |
| 341 // Helper function that simulates a full old-space in the heap. | 345 // Helper function that simulates a full old-space in the heap. |
| 342 static inline void SimulateFullSpace(v8::internal::PagedSpace* space) { | 346 static inline void SimulateFullSpace(v8::internal::PagedSpace* space) { |
| 343 int old_linear_size = static_cast<int>(space->limit() - space->top()); | 347 space->EmptyAllocationInfo(); |
| 344 space->Free(space->top(), old_linear_size); | |
| 345 space->SetTop(space->limit(), space->limit()); | |
| 346 space->ResetFreeList(); | 348 space->ResetFreeList(); |
| 347 space->ClearStats(); | 349 space->ClearStats(); |
| 348 } | 350 } |
| 349 | 351 |
| 350 | 352 |
| 351 // Helper class for new allocations tracking and checking. | 353 // Helper class for new allocations tracking and checking. |
| 352 // To use checking of JS allocations tracking in a test, | 354 // To use checking of JS allocations tracking in a test, |
| 353 // just create an instance of this class. | 355 // just create an instance of this class. |
| 354 class HeapObjectsTracker { | 356 class HeapObjectsTracker { |
| 355 public: | 357 public: |
| 356 HeapObjectsTracker() { | 358 HeapObjectsTracker() { |
| 357 heap_profiler_ = i::Isolate::Current()->heap_profiler(); | 359 heap_profiler_ = i::Isolate::Current()->heap_profiler(); |
| 358 CHECK_NE(NULL, heap_profiler_); | 360 CHECK_NE(NULL, heap_profiler_); |
| 359 heap_profiler_->StartHeapAllocationsRecording(); | 361 heap_profiler_->StartHeapAllocationsRecording(); |
| 360 } | 362 } |
| 361 | 363 |
| 362 ~HeapObjectsTracker() { | 364 ~HeapObjectsTracker() { |
| 363 i::Isolate::Current()->heap()->CollectAllAvailableGarbage(); | 365 i::Isolate::Current()->heap()->CollectAllAvailableGarbage(); |
| 364 CHECK_EQ(0, heap_profiler_->FindUntrackedObjects()); | 366 CHECK_EQ(0, heap_profiler_->FindUntrackedObjects()); |
| 365 heap_profiler_->StopHeapAllocationsRecording(); | 367 heap_profiler_->StopHeapAllocationsRecording(); |
| 366 } | 368 } |
| 367 | 369 |
| 368 private: | 370 private: |
| 369 i::HeapProfiler* heap_profiler_; | 371 i::HeapProfiler* heap_profiler_; |
| 370 }; | 372 }; |
| 371 | 373 |
| 372 | 374 |
| 373 #endif // ifndef CCTEST_H_ | 375 #endif // ifndef CCTEST_H_ |
| OLD | NEW |