OLD | NEW |
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 Loading... |
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 CHECK(context->Global() |
| 2403 ->SetPrivate(context, priv, v8_str("cached string")) |
| 2404 .FromJust()); |
| 2405 v8::Local<v8::Private> hidden = |
| 2406 v8::Private::ForApi(isolate, v8_str("hidden")); |
| 2407 CHECK(context->Global() |
| 2408 ->SetPrivate(context, hidden, v8_str("hidden string")) |
| 2409 .FromJust()); |
| 2410 |
2395 ExpectInt32("f()", 42); | 2411 ExpectInt32("f()", 42); |
2396 ExpectInt32("g()", 12); | 2412 ExpectInt32("g()", 12); |
2397 ExpectInt32("h()", 13); | 2413 ExpectInt32("h()", 13); |
2398 ExpectInt32("o.p", 7); | 2414 ExpectInt32("o.p", 7); |
2399 ExpectInt32("x", 2016); | 2415 ExpectInt32("x", 2016); |
2400 ExpectInt32("y", 2017); | 2416 ExpectInt32("y", 2017); |
| 2417 CHECK(v8_str("hidden string") |
| 2418 ->Equals(context, context->Global() |
| 2419 ->GetPrivate(context, hidden) |
| 2420 .ToLocalChecked()) |
| 2421 .FromJust()); |
| 2422 |
2401 CHECK_EQ(0u, creator.AddContext(context)); | 2423 CHECK_EQ(0u, creator.AddContext(context)); |
2402 } | 2424 } |
2403 blob = creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear, | 2425 blob = creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear, |
2404 SerializeInternalFields); | 2426 SerializeInternalFields); |
2405 } | 2427 } |
2406 | 2428 |
2407 { | 2429 { |
2408 v8::Isolate::CreateParams params; | 2430 v8::Isolate::CreateParams params; |
2409 params.snapshot_blob = &blob; | 2431 params.snapshot_blob = &blob; |
2410 params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 2432 params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2446 v8::Context::FromSnapshot(isolate, 0).ToLocalChecked(); | 2468 v8::Context::FromSnapshot(isolate, 0).ToLocalChecked(); |
2447 { | 2469 { |
2448 v8::Context::Scope context_scope(context); | 2470 v8::Context::Scope context_scope(context); |
2449 ExpectInt32("f()", 42); | 2471 ExpectInt32("f()", 42); |
2450 ExpectInt32("g()", 12); | 2472 ExpectInt32("g()", 12); |
2451 ExpectInt32("h()", 13); | 2473 ExpectInt32("h()", 13); |
2452 ExpectInt32("i()", 24); | 2474 ExpectInt32("i()", 24); |
2453 ExpectInt32("j()", 25); | 2475 ExpectInt32("j()", 25); |
2454 ExpectInt32("o.p", 8); | 2476 ExpectInt32("o.p", 8); |
2455 ExpectInt32("x", 2016); | 2477 ExpectInt32("x", 2016); |
| 2478 v8::Local<v8::Private> hidden = |
| 2479 v8::Private::ForApi(isolate, v8_str("hidden")); |
| 2480 CHECK(v8_str("hidden string") |
| 2481 ->Equals(context, context->Global() |
| 2482 ->GetPrivate(context, hidden) |
| 2483 .ToLocalChecked()) |
| 2484 .FromJust()); |
| 2485 ExpectString("cached", "cached string"); |
2456 } | 2486 } |
2457 | 2487 |
2458 v8::Local<v8::Object> global = context->Global(); | 2488 v8::Local<v8::Object> global = context->Global(); |
2459 CHECK_EQ(3, global->InternalFieldCount()); | 2489 CHECK_EQ(3, global->InternalFieldCount()); |
2460 context->DetachGlobal(); | 2490 context->DetachGlobal(); |
2461 | 2491 |
2462 // New context, but reuse global proxy. | 2492 // New context, but reuse global proxy. |
2463 v8::ExtensionConfiguration* no_extensions = nullptr; | 2493 v8::ExtensionConfiguration* no_extensions = nullptr; |
2464 v8::Local<v8::Context> context2 = | 2494 v8::Local<v8::Context> context2 = |
2465 v8::Context::FromSnapshot(isolate, 0, no_extensions, global) | 2495 v8::Context::FromSnapshot(isolate, 0, no_extensions, global) |
2466 .ToLocalChecked(); | 2496 .ToLocalChecked(); |
2467 { | 2497 { |
2468 v8::Context::Scope context_scope(context2); | 2498 v8::Context::Scope context_scope(context2); |
2469 ExpectInt32("f()", 42); | 2499 ExpectInt32("f()", 42); |
2470 ExpectInt32("g()", 12); | 2500 ExpectInt32("g()", 12); |
2471 ExpectInt32("h()", 13); | 2501 ExpectInt32("h()", 13); |
2472 ExpectInt32("i()", 24); | 2502 ExpectInt32("i()", 24); |
2473 ExpectInt32("j()", 25); | 2503 ExpectInt32("j()", 25); |
2474 ExpectInt32("o.p", 8); | 2504 ExpectInt32("o.p", 8); |
2475 ExpectInt32("x", 2016); | 2505 ExpectInt32("x", 2016); |
| 2506 v8::Local<v8::Private> hidden = |
| 2507 v8::Private::ForApi(isolate, v8_str("hidden")); |
| 2508 CHECK(v8_str("hidden string") |
| 2509 ->Equals(context2, context2->Global() |
| 2510 ->GetPrivate(context2, hidden) |
| 2511 .ToLocalChecked()) |
| 2512 .FromJust()); |
| 2513 |
| 2514 // Set cached accessor property again. |
| 2515 v8::Local<v8::Private> priv = |
| 2516 v8::Private::ForApi(isolate, v8_str("cached")); |
| 2517 CHECK(context2->Global() |
| 2518 ->SetPrivate(context2, priv, v8_str("cached string 1")) |
| 2519 .FromJust()); |
| 2520 ExpectString("cached", "cached string 1"); |
2476 } | 2521 } |
2477 | 2522 |
2478 CHECK(context2->Global()->Equals(context2, global).FromJust()); | 2523 CHECK(context2->Global()->Equals(context2, global).FromJust()); |
2479 } | 2524 } |
2480 } | 2525 } |
2481 isolate->Dispose(); | 2526 isolate->Dispose(); |
2482 } | 2527 } |
2483 delete[] blob.data; | 2528 delete[] blob.data; |
2484 } | 2529 } |
2485 | 2530 |
2486 TEST(SerializationMemoryStats) { | 2531 TEST(SerializationMemoryStats) { |
2487 FLAG_profile_deserialization = true; | 2532 FLAG_profile_deserialization = true; |
2488 FLAG_always_opt = false; | 2533 FLAG_always_opt = false; |
2489 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); | 2534 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); |
2490 delete[] blob.data; | 2535 delete[] blob.data; |
2491 } | 2536 } |
OLD | NEW |