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

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

Issue 15038002: Revert "deprecate Context::New which returns Persistent" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 7 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') | no next file » | 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 244
245 return true; 245 return true;
246 } 246 }
247 247
248 248
249 static void Serialize() { 249 static void Serialize() {
250 // We have to create one context. One reason for this is so that the builtins 250 // We have to create one context. One reason for this is so that the builtins
251 // can be loaded from v8natives.js and their addresses can be processed. This 251 // can be loaded from v8natives.js and their addresses can be processed. This
252 // will clear the pending fixups array, which would otherwise contain GC roots 252 // will clear the pending fixups array, which would otherwise contain GC roots
253 // that would confuse the serialization/deserialization process. 253 // that would confuse the serialization/deserialization process.
254 { 254 v8::Persistent<v8::Context> env = v8::Context::New();
255 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 255 env.Dispose(env->GetIsolate());
256 v8::HandleScope scope(isolate);
257 v8::Context::New(isolate);
258 }
259 WriteToFile(FLAG_testing_serialization_file); 256 WriteToFile(FLAG_testing_serialization_file);
260 } 257 }
261 258
262 259
263 // Test that the whole heap can be serialized. 260 // Test that the whole heap can be serialized.
264 TEST(Serialize) { 261 TEST(Serialize) {
265 if (!Snapshot::HaveASnapshotToStartFrom()) { 262 if (!Snapshot::HaveASnapshotToStartFrom()) {
266 Serializer::Enable(); 263 Serializer::Enable();
267 v8::V8::Initialize(); 264 v8::V8::Initialize();
268 Serialize(); 265 Serialize();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 CHECK(!FACTORY->InternalizeOneByteString( 297 CHECK(!FACTORY->InternalizeOneByteString(
301 STATIC_ASCII_VECTOR("Empty"))->IsFailure()); 298 STATIC_ASCII_VECTOR("Empty"))->IsFailure());
302 } 299 }
303 300
304 301
305 DEPENDENT_TEST(Deserialize, Serialize) { 302 DEPENDENT_TEST(Deserialize, Serialize) {
306 // The serialize-deserialize tests only work if the VM is built without 303 // The serialize-deserialize tests only work if the VM is built without
307 // serialization. That doesn't matter. We don't need to be able to 304 // serialization. That doesn't matter. We don't need to be able to
308 // serialize a snapshot in a VM that is booted from a snapshot. 305 // serialize a snapshot in a VM that is booted from a snapshot.
309 if (!Snapshot::HaveASnapshotToStartFrom()) { 306 if (!Snapshot::HaveASnapshotToStartFrom()) {
310 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 307 v8::HandleScope scope(v8::Isolate::GetCurrent());
311 v8::HandleScope scope(isolate);
312 Deserialize(); 308 Deserialize();
313 309
314 v8::Local<v8::Context> env = v8::Context::New(isolate); 310 v8::Persistent<v8::Context> env = v8::Context::New();
315 env->Enter(); 311 env->Enter();
316 312
317 SanityCheck(); 313 SanityCheck();
318 } 314 }
319 } 315 }
320 316
321 317
322 DEPENDENT_TEST(DeserializeFromSecondSerialization, SerializeTwice) { 318 DEPENDENT_TEST(DeserializeFromSecondSerialization, SerializeTwice) {
323 if (!Snapshot::HaveASnapshotToStartFrom()) { 319 if (!Snapshot::HaveASnapshotToStartFrom()) {
324 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 320 v8::HandleScope scope(v8::Isolate::GetCurrent());
325 v8::HandleScope scope(isolate);
326 Deserialize(); 321 Deserialize();
327 322
328 v8::Local<v8::Context> env = v8::Context::New(isolate); 323 v8::Persistent<v8::Context> env = v8::Context::New();
329 env->Enter(); 324 env->Enter();
330 325
331 SanityCheck(); 326 SanityCheck();
332 } 327 }
333 } 328 }
334 329
335 330
336 DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) { 331 DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) {
337 if (!Snapshot::HaveASnapshotToStartFrom()) { 332 if (!Snapshot::HaveASnapshotToStartFrom()) {
338 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 333 v8::HandleScope scope(v8::Isolate::GetCurrent());
339 v8::HandleScope scope(isolate);
340 Deserialize(); 334 Deserialize();
341 335
342 v8::Local<v8::Context> env = v8::Context::New(isolate); 336 v8::Persistent<v8::Context> env = v8::Context::New();
343 env->Enter(); 337 env->Enter();
344 338
345 const char* c_source = "\"1234\".length"; 339 const char* c_source = "\"1234\".length";
346 v8::Local<v8::String> source = v8::String::New(c_source); 340 v8::Local<v8::String> source = v8::String::New(c_source);
347 v8::Local<v8::Script> script = v8::Script::Compile(source); 341 v8::Local<v8::Script> script = v8::Script::Compile(source);
348 CHECK_EQ(4, script->Run()->Int32Value()); 342 CHECK_EQ(4, script->Run()->Int32Value());
349 } 343 }
350 } 344 }
351 345
352 346
353 DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2, 347 DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2,
354 SerializeTwice) { 348 SerializeTwice) {
355 if (!Snapshot::HaveASnapshotToStartFrom()) { 349 if (!Snapshot::HaveASnapshotToStartFrom()) {
356 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 350 v8::HandleScope scope(v8::Isolate::GetCurrent());
357 v8::HandleScope scope(isolate);
358 Deserialize(); 351 Deserialize();
359 352
360 v8::Local<v8::Context> env = v8::Context::New(isolate); 353 v8::Persistent<v8::Context> env = v8::Context::New();
361 env->Enter(); 354 env->Enter();
362 355
363 const char* c_source = "\"1234\".length"; 356 const char* c_source = "\"1234\".length";
364 v8::Local<v8::String> source = v8::String::New(c_source); 357 v8::Local<v8::String> source = v8::String::New(c_source);
365 v8::Local<v8::Script> script = v8::Script::Compile(source); 358 v8::Local<v8::Script> script = v8::Script::Compile(source);
366 CHECK_EQ(4, script->Run()->Int32Value()); 359 CHECK_EQ(4, script->Run()->Int32Value());
367 } 360 }
368 } 361 }
369 362
370 363
371 TEST(PartialSerialization) { 364 TEST(PartialSerialization) {
372 if (!Snapshot::HaveASnapshotToStartFrom()) { 365 if (!Snapshot::HaveASnapshotToStartFrom()) {
373 Serializer::Enable(); 366 Serializer::Enable();
374 v8::V8::Initialize(); 367 v8::V8::Initialize();
375 Isolate* isolate = Isolate::Current(); 368 Isolate* isolate = Isolate::Current();
376 Heap* heap = isolate->heap(); 369 Heap* heap = isolate->heap();
377 370
378 v8::Persistent<v8::Context> env; 371 v8::Persistent<v8::Context> env = v8::Context::New();
379 {
380 HandleScope scope(isolate);
381 env.Reset(v8::Isolate::GetCurrent(),
382 v8::Context::New(v8::Isolate::GetCurrent()));
383 }
384 ASSERT(!env.IsEmpty()); 372 ASSERT(!env.IsEmpty());
385 env->Enter(); 373 env->Enter();
386 // Make sure all builtin scripts are cached. 374 // Make sure all builtin scripts are cached.
387 { HandleScope scope(isolate); 375 { HandleScope scope(isolate);
388 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { 376 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
389 isolate->bootstrapper()->NativesSourceLookup(i); 377 isolate->bootstrapper()->NativesSourceLookup(i);
390 } 378 }
391 } 379 }
392 heap->CollectAllGarbage(Heap::kNoGCFlags); 380 heap->CollectAllGarbage(Heap::kNoGCFlags);
393 heap->CollectAllGarbage(Heap::kNoGCFlags); 381 heap->CollectAllGarbage(Heap::kNoGCFlags);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 } 495 }
508 496
509 497
510 TEST(ContextSerialization) { 498 TEST(ContextSerialization) {
511 if (!Snapshot::HaveASnapshotToStartFrom()) { 499 if (!Snapshot::HaveASnapshotToStartFrom()) {
512 Serializer::Enable(); 500 Serializer::Enable();
513 v8::V8::Initialize(); 501 v8::V8::Initialize();
514 Isolate* isolate = Isolate::Current(); 502 Isolate* isolate = Isolate::Current();
515 Heap* heap = isolate->heap(); 503 Heap* heap = isolate->heap();
516 504
517 v8::Persistent<v8::Context> env; 505 v8::Persistent<v8::Context> env = v8::Context::New();
518 {
519 HandleScope scope(isolate);
520 env.Reset(v8::Isolate::GetCurrent(),
521 v8::Context::New(v8::Isolate::GetCurrent()));
522 }
523 ASSERT(!env.IsEmpty()); 506 ASSERT(!env.IsEmpty());
524 env->Enter(); 507 env->Enter();
525 // Make sure all builtin scripts are cached. 508 // Make sure all builtin scripts are cached.
526 { HandleScope scope(isolate); 509 { HandleScope scope(isolate);
527 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { 510 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
528 isolate->bootstrapper()->NativesSourceLookup(i); 511 isolate->bootstrapper()->NativesSourceLookup(i);
529 } 512 }
530 } 513 }
531 // If we don't do this then we end up with a stray root pointing at the 514 // If we don't do this then we end up with a stray root pointing at the
532 // context even after we have disposed of env. 515 // context even after we have disposed of env.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 TEST(TestThatAlwaysFails) { 600 TEST(TestThatAlwaysFails) {
618 bool ArtificialFailure = false; 601 bool ArtificialFailure = false;
619 CHECK(ArtificialFailure); 602 CHECK(ArtificialFailure);
620 } 603 }
621 604
622 605
623 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { 606 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) {
624 bool ArtificialFailure2 = false; 607 bool ArtificialFailure2 = false;
625 CHECK(ArtificialFailure2); 608 CHECK(ArtificialFailure2);
626 } 609 }
OLDNEW
« no previous file with comments | « test/cctest/test-regexp.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698