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

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

Issue 2582623003: [serializer] add test for snapshotting cached accessor property. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | 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 2371 matching lines...) Expand 10 before | Expand all | Expand 10 after
2382 v8::HandleScope handle_scope(isolate); 2382 v8::HandleScope handle_scope(isolate);
2383 v8::Local<v8::ObjectTemplate> global_template = 2383 v8::Local<v8::ObjectTemplate> global_template =
2384 v8::ObjectTemplate::New(isolate); 2384 v8::ObjectTemplate::New(isolate);
2385 v8::Local<v8::FunctionTemplate> callback = 2385 v8::Local<v8::FunctionTemplate> callback =
2386 v8::FunctionTemplate::New(isolate, SerializedCallback); 2386 v8::FunctionTemplate::New(isolate, SerializedCallback);
2387 global_template->SetInternalFieldCount(3); 2387 global_template->SetInternalFieldCount(3);
2388 global_template->Set(v8_str("f"), callback); 2388 global_template->Set(v8_str("f"), callback);
2389 global_template->SetHandler(v8::NamedPropertyHandlerConfiguration( 2389 global_template->SetHandler(v8::NamedPropertyHandlerConfiguration(
2390 NamedPropertyGetterForSerialization)); 2390 NamedPropertyGetterForSerialization));
2391 global_template->SetAccessor(v8_str("y"), AccessorForSerialization); 2391 global_template->SetAccessor(v8_str("y"), AccessorForSerialization);
2392 v8::Local<v8::Private> priv =
2393 v8::Private::ForApi(isolate, v8_str("cached"));
2394 global_template->SetAccessorProperty(
2395 v8_str("cached"),
2396 v8::FunctionTemplate::NewWithCache(isolate, SerializedCallback, priv,
2397 v8::Local<v8::Value>()));
2392 v8::Local<v8::Context> context = 2398 v8::Local<v8::Context> context =
2393 v8::Context::New(isolate, &extensions, global_template); 2399 v8::Context::New(isolate, &extensions, global_template);
2394 v8::Context::Scope context_scope(context); 2400 v8::Context::Scope context_scope(context);
2401
2402 // Set hidden property.
2403 CHECK(context->Global()
jochen (gone - plz use gerrit) 2016/12/16 11:43:23 can you also test that setting this after deserial
2404 ->SetPrivate(context, priv, v8_str("cached string"))
2405 .FromJust());
2406
2395 ExpectInt32("f()", 42); 2407 ExpectInt32("f()", 42);
2396 ExpectInt32("g()", 12); 2408 ExpectInt32("g()", 12);
2397 ExpectInt32("h()", 13); 2409 ExpectInt32("h()", 13);
2398 ExpectInt32("o.p", 7); 2410 ExpectInt32("o.p", 7);
2399 ExpectInt32("x", 2016); 2411 ExpectInt32("x", 2016);
2400 ExpectInt32("y", 2017); 2412 ExpectInt32("y", 2017);
2413 ExpectString("cached", "cached string");
2414
2401 CHECK_EQ(0u, creator.AddContext(context)); 2415 CHECK_EQ(0u, creator.AddContext(context));
2402 } 2416 }
2403 blob = creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear, 2417 blob = creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear,
2404 SerializeInternalFields); 2418 SerializeInternalFields);
2405 } 2419 }
2406 2420
2407 { 2421 {
2408 v8::Isolate::CreateParams params; 2422 v8::Isolate::CreateParams params;
2409 params.snapshot_blob = &blob; 2423 params.snapshot_blob = &blob;
2410 params.array_buffer_allocator = CcTest::array_buffer_allocator(); 2424 params.array_buffer_allocator = CcTest::array_buffer_allocator();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2446 v8::Context::FromSnapshot(isolate, 0).ToLocalChecked(); 2460 v8::Context::FromSnapshot(isolate, 0).ToLocalChecked();
2447 { 2461 {
2448 v8::Context::Scope context_scope(context); 2462 v8::Context::Scope context_scope(context);
2449 ExpectInt32("f()", 42); 2463 ExpectInt32("f()", 42);
2450 ExpectInt32("g()", 12); 2464 ExpectInt32("g()", 12);
2451 ExpectInt32("h()", 13); 2465 ExpectInt32("h()", 13);
2452 ExpectInt32("i()", 24); 2466 ExpectInt32("i()", 24);
2453 ExpectInt32("j()", 25); 2467 ExpectInt32("j()", 25);
2454 ExpectInt32("o.p", 8); 2468 ExpectInt32("o.p", 8);
2455 ExpectInt32("x", 2016); 2469 ExpectInt32("x", 2016);
2470 ExpectString("cached", "cached string");
2456 } 2471 }
2457 2472
2458 v8::Local<v8::Object> global = context->Global(); 2473 v8::Local<v8::Object> global = context->Global();
2459 CHECK_EQ(3, global->InternalFieldCount()); 2474 CHECK_EQ(3, global->InternalFieldCount());
2460 context->DetachGlobal(); 2475 context->DetachGlobal();
2461 2476
2462 // New context, but reuse global proxy. 2477 // New context, but reuse global proxy.
2463 v8::ExtensionConfiguration* no_extensions = nullptr; 2478 v8::ExtensionConfiguration* no_extensions = nullptr;
2464 v8::Local<v8::Context> context2 = 2479 v8::Local<v8::Context> context2 =
2465 v8::Context::FromSnapshot(isolate, 0, no_extensions, global) 2480 v8::Context::FromSnapshot(isolate, 0, no_extensions, global)
2466 .ToLocalChecked(); 2481 .ToLocalChecked();
2467 { 2482 {
2468 v8::Context::Scope context_scope(context2); 2483 v8::Context::Scope context_scope(context2);
2469 ExpectInt32("f()", 42); 2484 ExpectInt32("f()", 42);
2470 ExpectInt32("g()", 12); 2485 ExpectInt32("g()", 12);
2471 ExpectInt32("h()", 13); 2486 ExpectInt32("h()", 13);
2472 ExpectInt32("i()", 24); 2487 ExpectInt32("i()", 24);
2473 ExpectInt32("j()", 25); 2488 ExpectInt32("j()", 25);
2474 ExpectInt32("o.p", 8); 2489 ExpectInt32("o.p", 8);
2475 ExpectInt32("x", 2016); 2490 ExpectInt32("x", 2016);
2491 ExpectString("cached", "cached string");
2476 } 2492 }
2477 2493
2478 CHECK(context2->Global()->Equals(context2, global).FromJust()); 2494 CHECK(context2->Global()->Equals(context2, global).FromJust());
2479 } 2495 }
2480 } 2496 }
2481 isolate->Dispose(); 2497 isolate->Dispose();
2482 } 2498 }
2483 delete[] blob.data; 2499 delete[] blob.data;
2484 } 2500 }
2485 2501
2486 TEST(SerializationMemoryStats) { 2502 TEST(SerializationMemoryStats) {
2487 FLAG_profile_deserialization = true; 2503 FLAG_profile_deserialization = true;
2488 FLAG_always_opt = false; 2504 FLAG_always_opt = false;
2489 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); 2505 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob();
2490 delete[] blob.data; 2506 delete[] blob.data;
2491 } 2507 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698