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

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

Issue 1587633002: LookupIterator should find private symbols on JSProxies (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 years, 11 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
« no previous file with comments | « src/objects.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 2720 matching lines...) Expand 10 before | Expand all | Expand 10 after
2731 v8::Local<v8::Name> name = v8::Symbol::New(isolate); 2731 v8::Local<v8::Name> name = v8::Symbol::New(isolate);
2732 CHECK(!name.IsEmpty()); 2732 CHECK(!name.IsEmpty());
2733 foo->PrototypeTemplate()->Set(name, v8::FunctionTemplate::New(isolate)); 2733 foo->PrototypeTemplate()->Set(name, v8::FunctionTemplate::New(isolate));
2734 v8::Local<v8::Object> new_instance = 2734 v8::Local<v8::Object> new_instance =
2735 foo->InstanceTemplate()->NewInstance(env.local()).ToLocalChecked(); 2735 foo->InstanceTemplate()->NewInstance(env.local()).ToLocalChecked();
2736 CHECK(!new_instance.IsEmpty()); 2736 CHECK(!new_instance.IsEmpty());
2737 CHECK(new_instance->Has(env.local(), name).FromJust()); 2737 CHECK(new_instance->Has(env.local(), name).FromJust());
2738 } 2738 }
2739 2739
2740 2740
2741 THREADED_TEST(PrivatePropertiesOnProxies) {
2742 i::FLAG_harmony_proxies = true;
2743 LocalContext env;
2744 v8::Isolate* isolate = env->GetIsolate();
2745 v8::HandleScope scope(isolate);
2746
2747 v8::Local<v8::Object> target = CompileRun("({})").As<v8::Object>();
2748 v8::Local<v8::Object> handler = CompileRun("({})").As<v8::Object>();
2749
2750 v8::Local<v8::Proxy> proxy =
2751 v8::Proxy::New(env.local(), target, handler).ToLocalChecked();
2752
2753 v8::Local<v8::Private> priv1 = v8::Private::New(isolate);
2754 v8::Local<v8::Private> priv2 =
2755 v8::Private::New(isolate, v8_str("my-private"));
2756
2757 CcTest::heap()->CollectAllGarbage();
2758
2759 CHECK(priv2->Name()
2760 ->Equals(env.local(),
2761 v8::String::NewFromUtf8(isolate, "my-private",
2762 v8::NewStringType::kNormal)
2763 .ToLocalChecked())
2764 .FromJust());
2765
2766 // Make sure delete of a non-existent private symbol property works.
2767 proxy->DeletePrivate(env.local(), priv1).FromJust();
2768 CHECK(!proxy->HasPrivate(env.local(), priv1).FromJust());
2769
2770 CHECK(proxy->SetPrivate(env.local(), priv1, v8::Integer::New(isolate, 1503))
2771 .FromJust());
2772 CHECK(proxy->HasPrivate(env.local(), priv1).FromJust());
2773 CHECK_EQ(1503, proxy->GetPrivate(env.local(), priv1)
2774 .ToLocalChecked()
2775 ->Int32Value(env.local())
2776 .FromJust());
2777 CHECK(proxy->SetPrivate(env.local(), priv1, v8::Integer::New(isolate, 2002))
2778 .FromJust());
2779 CHECK(proxy->HasPrivate(env.local(), priv1).FromJust());
2780 CHECK_EQ(2002, proxy->GetPrivate(env.local(), priv1)
2781 .ToLocalChecked()
2782 ->Int32Value(env.local())
2783 .FromJust());
2784
2785 CHECK_EQ(0u,
2786 proxy->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length());
2787 unsigned num_props =
2788 proxy->GetPropertyNames(env.local()).ToLocalChecked()->Length();
2789 CHECK(proxy->Set(env.local(), v8::String::NewFromUtf8(
2790 isolate, "bla", v8::NewStringType::kNormal)
2791 .ToLocalChecked(),
2792 v8::Integer::New(isolate, 20))
2793 .FromJust());
2794 CHECK_EQ(1u,
2795 proxy->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length());
2796 CHECK_EQ(num_props + 1,
2797 proxy->GetPropertyNames(env.local()).ToLocalChecked()->Length());
2798
2799 CcTest::heap()->CollectAllGarbage();
2800
2801 // Add another property and delete it afterwards to force the object in
2802 // slow case.
2803 CHECK(proxy->SetPrivate(env.local(), priv2, v8::Integer::New(isolate, 2008))
2804 .FromJust());
2805 CHECK_EQ(2002, proxy->GetPrivate(env.local(), priv1)
2806 .ToLocalChecked()
2807 ->Int32Value(env.local())
2808 .FromJust());
2809 CHECK_EQ(2008, proxy->GetPrivate(env.local(), priv2)
2810 .ToLocalChecked()
2811 ->Int32Value(env.local())
2812 .FromJust());
2813 CHECK_EQ(2002, proxy->GetPrivate(env.local(), priv1)
2814 .ToLocalChecked()
2815 ->Int32Value(env.local())
2816 .FromJust());
2817 CHECK_EQ(1u,
2818 proxy->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length());
2819
2820 CHECK(proxy->HasPrivate(env.local(), priv1).FromJust());
2821 CHECK(proxy->HasPrivate(env.local(), priv2).FromJust());
2822 CHECK(proxy->DeletePrivate(env.local(), priv2).FromJust());
2823 CHECK(proxy->HasPrivate(env.local(), priv1).FromJust());
2824 CHECK(!proxy->HasPrivate(env.local(), priv2).FromJust());
2825 CHECK_EQ(2002, proxy->GetPrivate(env.local(), priv1)
2826 .ToLocalChecked()
2827 ->Int32Value(env.local())
2828 .FromJust());
2829 CHECK_EQ(1u,
2830 proxy->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length());
2831
2832 // Private properties are not inherited (for the time being).
2833 v8::Local<v8::Object> child = v8::Object::New(isolate);
2834 CHECK(child->SetPrototype(env.local(), proxy).FromJust());
2835 CHECK(!child->HasPrivate(env.local(), priv1).FromJust());
2836 CHECK_EQ(0u,
2837 child->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length());
2838 }
2839
2840
2741 THREADED_TEST(PrivateProperties) { 2841 THREADED_TEST(PrivateProperties) {
2742 LocalContext env; 2842 LocalContext env;
2743 v8::Isolate* isolate = env->GetIsolate(); 2843 v8::Isolate* isolate = env->GetIsolate();
2744 v8::HandleScope scope(isolate); 2844 v8::HandleScope scope(isolate);
2745 2845
2746 v8::Local<v8::Object> obj = v8::Object::New(isolate); 2846 v8::Local<v8::Object> obj = v8::Object::New(isolate);
2747 v8::Local<v8::Private> priv1 = v8::Private::New(isolate); 2847 v8::Local<v8::Private> priv1 = v8::Private::New(isolate);
2748 v8::Local<v8::Private> priv2 = 2848 v8::Local<v8::Private> priv2 =
2749 v8::Private::New(isolate, v8_str("my-private")); 2849 v8::Private::New(isolate, v8_str("my-private"));
2750 2850
(...skipping 21591 matching lines...) Expand 10 before | Expand all | Expand 10 after
24342 CHECK(proxy->GetTarget()->SameValue(target)); 24442 CHECK(proxy->GetTarget()->SameValue(target));
24343 CHECK(proxy->GetHandler()->SameValue(handler)); 24443 CHECK(proxy->GetHandler()->SameValue(handler));
24344 24444
24345 proxy->Revoke(); 24445 proxy->Revoke();
24346 CHECK(proxy->IsProxy()); 24446 CHECK(proxy->IsProxy());
24347 CHECK(!target->IsProxy()); 24447 CHECK(!target->IsProxy());
24348 CHECK(proxy->IsRevoked()); 24448 CHECK(proxy->IsRevoked());
24349 CHECK(proxy->GetTarget()->SameValue(target)); 24449 CHECK(proxy->GetTarget()->SameValue(target));
24350 CHECK(proxy->GetHandler()->IsNull()); 24450 CHECK(proxy->GetHandler()->IsNull());
24351 } 24451 }
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698