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

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

Issue 12716010: Added a version of the v8::HandleScope constructor with an Isolate and use that consistently. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Feedback. Rebased Created 7 years, 9 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/test-regexp.cc ('k') | test/cctest/test-strings.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 2007-2010 the V8 project authors. All rights reserved. 1 // Copyright 2007-2010 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 275
276 //---------------------------------------------------------------------------- 276 //----------------------------------------------------------------------------
277 // Tests that the heap can be deserialized. 277 // Tests that the heap can be deserialized.
278 278
279 static void Deserialize() { 279 static void Deserialize() {
280 CHECK(Snapshot::Initialize(FLAG_testing_serialization_file)); 280 CHECK(Snapshot::Initialize(FLAG_testing_serialization_file));
281 } 281 }
282 282
283 283
284 static void SanityCheck() { 284 static void SanityCheck() {
285 v8::HandleScope scope; 285 v8::HandleScope scope(v8::Isolate::GetCurrent());
286 #ifdef VERIFY_HEAP 286 #ifdef VERIFY_HEAP
287 HEAP->Verify(); 287 HEAP->Verify();
288 #endif 288 #endif
289 CHECK(Isolate::Current()->global_object()->IsJSObject()); 289 CHECK(Isolate::Current()->global_object()->IsJSObject());
290 CHECK(Isolate::Current()->native_context()->IsContext()); 290 CHECK(Isolate::Current()->native_context()->IsContext());
291 CHECK(HEAP->string_table()->IsStringTable()); 291 CHECK(HEAP->string_table()->IsStringTable());
292 CHECK(!FACTORY->InternalizeOneByteString( 292 CHECK(!FACTORY->InternalizeOneByteString(
293 STATIC_ASCII_VECTOR("Empty"))->IsFailure()); 293 STATIC_ASCII_VECTOR("Empty"))->IsFailure());
294 } 294 }
295 295
296 296
297 DEPENDENT_TEST(Deserialize, Serialize) { 297 DEPENDENT_TEST(Deserialize, Serialize) {
298 // The serialize-deserialize tests only work if the VM is built without 298 // The serialize-deserialize tests only work if the VM is built without
299 // serialization. That doesn't matter. We don't need to be able to 299 // serialization. That doesn't matter. We don't need to be able to
300 // serialize a snapshot in a VM that is booted from a snapshot. 300 // serialize a snapshot in a VM that is booted from a snapshot.
301 if (!Snapshot::HaveASnapshotToStartFrom()) { 301 if (!Snapshot::HaveASnapshotToStartFrom()) {
302 v8::HandleScope scope; 302 v8::HandleScope scope(v8::Isolate::GetCurrent());
303 Deserialize(); 303 Deserialize();
304 304
305 v8::Persistent<v8::Context> env = v8::Context::New(); 305 v8::Persistent<v8::Context> env = v8::Context::New();
306 env->Enter(); 306 env->Enter();
307 307
308 SanityCheck(); 308 SanityCheck();
309 } 309 }
310 } 310 }
311 311
312 312
313 DEPENDENT_TEST(DeserializeFromSecondSerialization, SerializeTwice) { 313 DEPENDENT_TEST(DeserializeFromSecondSerialization, SerializeTwice) {
314 if (!Snapshot::HaveASnapshotToStartFrom()) { 314 if (!Snapshot::HaveASnapshotToStartFrom()) {
315 v8::HandleScope scope; 315 v8::HandleScope scope(v8::Isolate::GetCurrent());
316 Deserialize(); 316 Deserialize();
317 317
318 v8::Persistent<v8::Context> env = v8::Context::New(); 318 v8::Persistent<v8::Context> env = v8::Context::New();
319 env->Enter(); 319 env->Enter();
320 320
321 SanityCheck(); 321 SanityCheck();
322 } 322 }
323 } 323 }
324 324
325 325
326 DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) { 326 DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) {
327 if (!Snapshot::HaveASnapshotToStartFrom()) { 327 if (!Snapshot::HaveASnapshotToStartFrom()) {
328 v8::HandleScope scope; 328 v8::HandleScope scope(v8::Isolate::GetCurrent());
329 Deserialize(); 329 Deserialize();
330 330
331 v8::Persistent<v8::Context> env = v8::Context::New(); 331 v8::Persistent<v8::Context> env = v8::Context::New();
332 env->Enter(); 332 env->Enter();
333 333
334 const char* c_source = "\"1234\".length"; 334 const char* c_source = "\"1234\".length";
335 v8::Local<v8::String> source = v8::String::New(c_source); 335 v8::Local<v8::String> source = v8::String::New(c_source);
336 v8::Local<v8::Script> script = v8::Script::Compile(source); 336 v8::Local<v8::Script> script = v8::Script::Compile(source);
337 CHECK_EQ(4, script->Run()->Int32Value()); 337 CHECK_EQ(4, script->Run()->Int32Value());
338 } 338 }
339 } 339 }
340 340
341 341
342 DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2, 342 DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2,
343 SerializeTwice) { 343 SerializeTwice) {
344 if (!Snapshot::HaveASnapshotToStartFrom()) { 344 if (!Snapshot::HaveASnapshotToStartFrom()) {
345 v8::HandleScope scope; 345 v8::HandleScope scope(v8::Isolate::GetCurrent());
346 Deserialize(); 346 Deserialize();
347 347
348 v8::Persistent<v8::Context> env = v8::Context::New(); 348 v8::Persistent<v8::Context> env = v8::Context::New();
349 env->Enter(); 349 env->Enter();
350 350
351 const char* c_source = "\"1234\".length"; 351 const char* c_source = "\"1234\".length";
352 v8::Local<v8::String> source = v8::String::New(c_source); 352 v8::Local<v8::String> source = v8::String::New(c_source);
353 v8::Local<v8::Script> script = v8::Script::Compile(source); 353 v8::Local<v8::Script> script = v8::Script::Compile(source);
354 CHECK_EQ(4, script->Run()->Int32Value()); 354 CHECK_EQ(4, script->Run()->Int32Value());
355 } 355 }
(...skipping 14 matching lines...) Expand all
370 { HandleScope scope(isolate); 370 { HandleScope scope(isolate);
371 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { 371 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
372 isolate->bootstrapper()->NativesSourceLookup(i); 372 isolate->bootstrapper()->NativesSourceLookup(i);
373 } 373 }
374 } 374 }
375 heap->CollectAllGarbage(Heap::kNoGCFlags); 375 heap->CollectAllGarbage(Heap::kNoGCFlags);
376 heap->CollectAllGarbage(Heap::kNoGCFlags); 376 heap->CollectAllGarbage(Heap::kNoGCFlags);
377 377
378 Object* raw_foo; 378 Object* raw_foo;
379 { 379 {
380 v8::HandleScope handle_scope; 380 v8::HandleScope handle_scope(env->GetIsolate());
381 v8::Local<v8::String> foo = v8::String::New("foo"); 381 v8::Local<v8::String> foo = v8::String::New("foo");
382 ASSERT(!foo.IsEmpty()); 382 ASSERT(!foo.IsEmpty());
383 raw_foo = *(v8::Utils::OpenHandle(*foo)); 383 raw_foo = *(v8::Utils::OpenHandle(*foo));
384 } 384 }
385 385
386 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; 386 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
387 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); 387 Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
388 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); 388 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
389 389
390 env->Exit(); 390 env->Exit();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 byte* snapshot = ReadBytes(file_name, &snapshot_size); 466 byte* snapshot = ReadBytes(file_name, &snapshot_size);
467 467
468 Object* root; 468 Object* root;
469 { 469 {
470 SnapshotByteSource source(snapshot, snapshot_size); 470 SnapshotByteSource source(snapshot, snapshot_size);
471 Deserializer deserializer(&source); 471 Deserializer deserializer(&source);
472 ReserveSpaceForSnapshot(&deserializer, file_name); 472 ReserveSpaceForSnapshot(&deserializer, file_name);
473 deserializer.DeserializePartial(&root); 473 deserializer.DeserializePartial(&root);
474 CHECK(root->IsString()); 474 CHECK(root->IsString());
475 } 475 }
476 v8::HandleScope handle_scope; 476 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
477 Handle<Object> root_handle(root, Isolate::Current()); 477 Handle<Object> root_handle(root, Isolate::Current());
478 478
479 479
480 Object* root2; 480 Object* root2;
481 { 481 {
482 SnapshotByteSource source(snapshot, snapshot_size); 482 SnapshotByteSource source(snapshot, snapshot_size);
483 Deserializer deserializer(&source); 483 Deserializer deserializer(&source);
484 ReserveSpaceForSnapshot(&deserializer, file_name); 484 ReserveSpaceForSnapshot(&deserializer, file_name);
485 deserializer.DeserializePartial(&root2); 485 deserializer.DeserializePartial(&root2);
486 CHECK(root2->IsString()); 486 CHECK(root2->IsString());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 byte* snapshot = ReadBytes(file_name, &snapshot_size); 564 byte* snapshot = ReadBytes(file_name, &snapshot_size);
565 565
566 Object* root; 566 Object* root;
567 { 567 {
568 SnapshotByteSource source(snapshot, snapshot_size); 568 SnapshotByteSource source(snapshot, snapshot_size);
569 Deserializer deserializer(&source); 569 Deserializer deserializer(&source);
570 ReserveSpaceForSnapshot(&deserializer, file_name); 570 ReserveSpaceForSnapshot(&deserializer, file_name);
571 deserializer.DeserializePartial(&root); 571 deserializer.DeserializePartial(&root);
572 CHECK(root->IsContext()); 572 CHECK(root->IsContext());
573 } 573 }
574 v8::HandleScope handle_scope; 574 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
575 Handle<Object> root_handle(root, Isolate::Current()); 575 Handle<Object> root_handle(root, Isolate::Current());
576 576
577 577
578 Object* root2; 578 Object* root2;
579 { 579 {
580 SnapshotByteSource source(snapshot, snapshot_size); 580 SnapshotByteSource source(snapshot, snapshot_size);
581 Deserializer deserializer(&source); 581 Deserializer deserializer(&source);
582 ReserveSpaceForSnapshot(&deserializer, file_name); 582 ReserveSpaceForSnapshot(&deserializer, file_name);
583 deserializer.DeserializePartial(&root2); 583 deserializer.DeserializePartial(&root2);
584 CHECK(root2->IsContext()); 584 CHECK(root2->IsContext());
(...skipping 10 matching lines...) Expand all
595 TEST(TestThatAlwaysFails) { 595 TEST(TestThatAlwaysFails) {
596 bool ArtificialFailure = false; 596 bool ArtificialFailure = false;
597 CHECK(ArtificialFailure); 597 CHECK(ArtificialFailure);
598 } 598 }
599 599
600 600
601 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { 601 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) {
602 bool ArtificialFailure2 = false; 602 bool ArtificialFailure2 = false;
603 CHECK(ArtificialFailure2); 603 CHECK(ArtificialFailure2);
604 } 604 }
OLDNEW
« no previous file with comments | « test/cctest/test-regexp.cc ('k') | test/cctest/test-strings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698