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

Side by Side Diff: src/objects.cc

Issue 12422019: ES6 symbols: prevent reflection and proxy APIs from leaking symbols (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Deal with Object.observe as well 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 | « src/objects.h ('k') | src/runtime.h » ('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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 } 368 }
369 369
370 370
371 MaybeObject* JSProxy::GetPropertyWithHandler(Object* receiver_raw, 371 MaybeObject* JSProxy::GetPropertyWithHandler(Object* receiver_raw,
372 Name* name_raw) { 372 Name* name_raw) {
373 Isolate* isolate = GetIsolate(); 373 Isolate* isolate = GetIsolate();
374 HandleScope scope(isolate); 374 HandleScope scope(isolate);
375 Handle<Object> receiver(receiver_raw, isolate); 375 Handle<Object> receiver(receiver_raw, isolate);
376 Handle<Object> name(name_raw, isolate); 376 Handle<Object> name(name_raw, isolate);
377 377
378 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
379 if (name->IsSymbol()) return isolate->heap()->undefined_value();
380
378 Handle<Object> args[] = { receiver, name }; 381 Handle<Object> args[] = { receiver, name };
379 Handle<Object> result = CallTrap( 382 Handle<Object> result = CallTrap(
380 "get", isolate->derived_get_trap(), ARRAY_SIZE(args), args); 383 "get", isolate->derived_get_trap(), ARRAY_SIZE(args), args);
381 if (isolate->has_pending_exception()) return Failure::Exception(); 384 if (isolate->has_pending_exception()) return Failure::Exception();
382 385
383 return *result; 386 return *result;
384 } 387 }
385 388
386 389
387 Handle<Object> Object::GetProperty(Handle<Object> object, Handle<Name> name) { 390 Handle<Object> Object::GetProperty(Handle<Object> object, Handle<Name> name) {
(...skipping 2361 matching lines...) Expand 10 before | Expand all | Expand 10 after
2749 } 2752 }
2750 } 2753 }
2751 2754
2752 2755
2753 bool JSProxy::HasPropertyWithHandler(Name* name_raw) { 2756 bool JSProxy::HasPropertyWithHandler(Name* name_raw) {
2754 Isolate* isolate = GetIsolate(); 2757 Isolate* isolate = GetIsolate();
2755 HandleScope scope(isolate); 2758 HandleScope scope(isolate);
2756 Handle<Object> receiver(this, isolate); 2759 Handle<Object> receiver(this, isolate);
2757 Handle<Object> name(name_raw, isolate); 2760 Handle<Object> name(name_raw, isolate);
2758 2761
2762 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
2763 if (name->IsSymbol()) return false;
2764
2759 Handle<Object> args[] = { name }; 2765 Handle<Object> args[] = { name };
2760 Handle<Object> result = CallTrap( 2766 Handle<Object> result = CallTrap(
2761 "has", isolate->derived_has_trap(), ARRAY_SIZE(args), args); 2767 "has", isolate->derived_has_trap(), ARRAY_SIZE(args), args);
2762 if (isolate->has_pending_exception()) return false; 2768 if (isolate->has_pending_exception()) return false;
2763 2769
2764 return result->BooleanValue(); 2770 return result->BooleanValue();
2765 } 2771 }
2766 2772
2767 2773
2768 MUST_USE_RESULT MaybeObject* JSProxy::SetPropertyWithHandler( 2774 MUST_USE_RESULT MaybeObject* JSProxy::SetPropertyWithHandler(
2769 JSReceiver* receiver_raw, 2775 JSReceiver* receiver_raw,
2770 Name* name_raw, 2776 Name* name_raw,
2771 Object* value_raw, 2777 Object* value_raw,
2772 PropertyAttributes attributes, 2778 PropertyAttributes attributes,
2773 StrictModeFlag strict_mode) { 2779 StrictModeFlag strict_mode) {
2774 Isolate* isolate = GetIsolate(); 2780 Isolate* isolate = GetIsolate();
2775 HandleScope scope(isolate); 2781 HandleScope scope(isolate);
2776 Handle<JSReceiver> receiver(receiver_raw); 2782 Handle<JSReceiver> receiver(receiver_raw);
2777 Handle<Object> name(name_raw, isolate); 2783 Handle<Object> name(name_raw, isolate);
2778 Handle<Object> value(value_raw, isolate); 2784 Handle<Object> value(value_raw, isolate);
2779 2785
2786 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
2787 if (name->IsSymbol()) return *value;
2788
2780 Handle<Object> args[] = { receiver, name, value }; 2789 Handle<Object> args[] = { receiver, name, value };
2781 CallTrap("set", isolate->derived_set_trap(), ARRAY_SIZE(args), args); 2790 CallTrap("set", isolate->derived_set_trap(), ARRAY_SIZE(args), args);
2782 if (isolate->has_pending_exception()) return Failure::Exception(); 2791 if (isolate->has_pending_exception()) return Failure::Exception();
2783 2792
2784 return *value; 2793 return *value;
2785 } 2794 }
2786 2795
2787 2796
2788 MUST_USE_RESULT MaybeObject* JSProxy::SetPropertyViaPrototypesWithHandler( 2797 MUST_USE_RESULT MaybeObject* JSProxy::SetPropertyViaPrototypesWithHandler(
2789 JSReceiver* receiver_raw, 2798 JSReceiver* receiver_raw,
2790 Name* name_raw, 2799 Name* name_raw,
2791 Object* value_raw, 2800 Object* value_raw,
2792 PropertyAttributes attributes, 2801 PropertyAttributes attributes,
2793 StrictModeFlag strict_mode, 2802 StrictModeFlag strict_mode,
2794 bool* done) { 2803 bool* done) {
2795 Isolate* isolate = GetIsolate(); 2804 Isolate* isolate = GetIsolate();
2796 Handle<JSProxy> proxy(this); 2805 Handle<JSProxy> proxy(this);
2797 Handle<JSReceiver> receiver(receiver_raw); 2806 Handle<JSReceiver> receiver(receiver_raw);
2798 Handle<Name> name(name_raw); 2807 Handle<Name> name(name_raw);
2799 Handle<Object> value(value_raw, isolate); 2808 Handle<Object> value(value_raw, isolate);
2800 Handle<Object> handler(this->handler(), isolate); // Trap might morph proxy. 2809 Handle<Object> handler(this->handler(), isolate); // Trap might morph proxy.
2801 2810
2811 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
2812 if (name->IsSymbol()) {
2813 *done = false;
2814 return isolate->heap()->the_hole_value();
2815 }
2816
2802 *done = true; // except where redefined... 2817 *done = true; // except where redefined...
2803 Handle<Object> args[] = { name }; 2818 Handle<Object> args[] = { name };
2804 Handle<Object> result = proxy->CallTrap( 2819 Handle<Object> result = proxy->CallTrap(
2805 "getPropertyDescriptor", Handle<Object>(), ARRAY_SIZE(args), args); 2820 "getPropertyDescriptor", Handle<Object>(), ARRAY_SIZE(args), args);
2806 if (isolate->has_pending_exception()) return Failure::Exception(); 2821 if (isolate->has_pending_exception()) return Failure::Exception();
2807 2822
2808 if (result->IsUndefined()) { 2823 if (result->IsUndefined()) {
2809 *done = false; 2824 *done = false;
2810 return GetHeap()->the_hole_value(); 2825 return isolate->heap()->the_hole_value();
2811 } 2826 }
2812 2827
2813 // Emulate [[GetProperty]] semantics for proxies. 2828 // Emulate [[GetProperty]] semantics for proxies.
2814 bool has_pending_exception; 2829 bool has_pending_exception;
2815 Handle<Object> argv[] = { result }; 2830 Handle<Object> argv[] = { result };
2816 Handle<Object> desc = 2831 Handle<Object> desc =
2817 Execution::Call(isolate->to_complete_property_descriptor(), result, 2832 Execution::Call(isolate->to_complete_property_descriptor(), result,
2818 ARRAY_SIZE(argv), argv, &has_pending_exception); 2833 ARRAY_SIZE(argv), argv, &has_pending_exception);
2819 if (has_pending_exception) return Failure::Exception(); 2834 if (has_pending_exception) return Failure::Exception();
2820 2835
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2881 } 2896 }
2882 2897
2883 2898
2884 MUST_USE_RESULT MaybeObject* JSProxy::DeletePropertyWithHandler( 2899 MUST_USE_RESULT MaybeObject* JSProxy::DeletePropertyWithHandler(
2885 Name* name_raw, DeleteMode mode) { 2900 Name* name_raw, DeleteMode mode) {
2886 Isolate* isolate = GetIsolate(); 2901 Isolate* isolate = GetIsolate();
2887 HandleScope scope(isolate); 2902 HandleScope scope(isolate);
2888 Handle<JSProxy> receiver(this); 2903 Handle<JSProxy> receiver(this);
2889 Handle<Object> name(name_raw, isolate); 2904 Handle<Object> name(name_raw, isolate);
2890 2905
2906 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
2907 if (name->IsSymbol()) return isolate->heap()->false_value();
2908
2891 Handle<Object> args[] = { name }; 2909 Handle<Object> args[] = { name };
2892 Handle<Object> result = CallTrap( 2910 Handle<Object> result = CallTrap(
2893 "delete", Handle<Object>(), ARRAY_SIZE(args), args); 2911 "delete", Handle<Object>(), ARRAY_SIZE(args), args);
2894 if (isolate->has_pending_exception()) return Failure::Exception(); 2912 if (isolate->has_pending_exception()) return Failure::Exception();
2895 2913
2896 bool result_bool = result->BooleanValue(); 2914 bool result_bool = result->BooleanValue();
2897 if (mode == STRICT_DELETION && !result_bool) { 2915 if (mode == STRICT_DELETION && !result_bool) {
2898 Handle<Object> handler(receiver->handler(), isolate); 2916 Handle<Object> handler(receiver->handler(), isolate);
2899 Handle<String> trap_name = isolate->factory()->InternalizeOneByteString( 2917 Handle<String> trap_name = isolate->factory()->InternalizeOneByteString(
2900 STATIC_ASCII_VECTOR("delete")); 2918 STATIC_ASCII_VECTOR("delete"));
(...skipping 20 matching lines...) Expand all
2921 MUST_USE_RESULT PropertyAttributes JSProxy::GetPropertyAttributeWithHandler( 2939 MUST_USE_RESULT PropertyAttributes JSProxy::GetPropertyAttributeWithHandler(
2922 JSReceiver* receiver_raw, 2940 JSReceiver* receiver_raw,
2923 Name* name_raw) { 2941 Name* name_raw) {
2924 Isolate* isolate = GetIsolate(); 2942 Isolate* isolate = GetIsolate();
2925 HandleScope scope(isolate); 2943 HandleScope scope(isolate);
2926 Handle<JSProxy> proxy(this); 2944 Handle<JSProxy> proxy(this);
2927 Handle<Object> handler(this->handler(), isolate); // Trap might morph proxy. 2945 Handle<Object> handler(this->handler(), isolate); // Trap might morph proxy.
2928 Handle<JSReceiver> receiver(receiver_raw); 2946 Handle<JSReceiver> receiver(receiver_raw);
2929 Handle<Object> name(name_raw, isolate); 2947 Handle<Object> name(name_raw, isolate);
2930 2948
2949 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
2950 if (name->IsSymbol()) return ABSENT;
2951
2931 Handle<Object> args[] = { name }; 2952 Handle<Object> args[] = { name };
2932 Handle<Object> result = CallTrap( 2953 Handle<Object> result = CallTrap(
2933 "getPropertyDescriptor", Handle<Object>(), ARRAY_SIZE(args), args); 2954 "getPropertyDescriptor", Handle<Object>(), ARRAY_SIZE(args), args);
2934 if (isolate->has_pending_exception()) return NONE; 2955 if (isolate->has_pending_exception()) return NONE;
2935 2956
2936 if (result->IsUndefined()) return ABSENT; 2957 if (result->IsUndefined()) return ABSENT;
2937 2958
2938 bool has_pending_exception; 2959 bool has_pending_exception;
2939 Handle<Object> argv[] = { result }; 2960 Handle<Object> argv[] = { result };
2940 Handle<Object> desc = 2961 Handle<Object> desc =
(...skipping 8639 matching lines...) Expand 10 before | Expand all | Expand 10 after
11580 } else { 11601 } else {
11581 HeapSortPairs(this, numbers, len); 11602 HeapSortPairs(this, numbers, len);
11582 return; 11603 return;
11583 } 11604 }
11584 } 11605 }
11585 11606
11586 11607
11587 // Fill in the names of local properties into the supplied storage. The main 11608 // Fill in the names of local properties into the supplied storage. The main
11588 // purpose of this function is to provide reflection information for the object 11609 // purpose of this function is to provide reflection information for the object
11589 // mirrors. 11610 // mirrors.
11590 void JSObject::GetLocalPropertyNames(FixedArray* storage, int index) { 11611 void JSObject::GetLocalPropertyNames(
11591 ASSERT(storage->length() >= (NumberOfLocalProperties() - index)); 11612 FixedArray* storage, int index, PropertyAttributes filter) {
11613 ASSERT(storage->length() >= (NumberOfLocalProperties(filter) - index));
11592 if (HasFastProperties()) { 11614 if (HasFastProperties()) {
11593 int real_size = map()->NumberOfOwnDescriptors(); 11615 int real_size = map()->NumberOfOwnDescriptors();
11594 DescriptorArray* descs = map()->instance_descriptors(); 11616 DescriptorArray* descs = map()->instance_descriptors();
11595 ASSERT(storage->length() >= index + real_size);
11596 for (int i = 0; i < real_size; i++) { 11617 for (int i = 0; i < real_size; i++) {
11597 storage->set(index + i, descs->GetKey(i)); 11618 if ((descs->GetDetails(i).attributes() & filter) == 0 &&
11619 ((filter & SYMBOLIC) == 0 || !descs->GetKey(i)->IsSymbol())) {
11620 storage->set(index++, descs->GetKey(i));
11621 }
11598 } 11622 }
11599 } else { 11623 } else {
11600 property_dictionary()->CopyKeysTo(storage, 11624 property_dictionary()->CopyKeysTo(storage,
11601 index, 11625 index,
11626 filter,
11602 NameDictionary::UNSORTED); 11627 NameDictionary::UNSORTED);
11603 } 11628 }
11604 } 11629 }
11605 11630
11606 11631
11607 int JSObject::NumberOfLocalElements(PropertyAttributes filter) { 11632 int JSObject::NumberOfLocalElements(PropertyAttributes filter) {
11608 return GetLocalElementKeys(NULL, filter); 11633 return GetLocalElementKeys(NULL, filter);
11609 } 11634 }
11610 11635
11611 11636
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
12342 DeleteProperty(int, JSObject::DeleteMode); 12367 DeleteProperty(int, JSObject::DeleteMode);
12343 12368
12344 template MaybeObject* Dictionary<NameDictionaryShape, Name*>::Shrink(Name* n); 12369 template MaybeObject* Dictionary<NameDictionaryShape, Name*>::Shrink(Name* n);
12345 12370
12346 template MaybeObject* Dictionary<SeededNumberDictionaryShape, uint32_t>::Shrink( 12371 template MaybeObject* Dictionary<SeededNumberDictionaryShape, uint32_t>::Shrink(
12347 uint32_t); 12372 uint32_t);
12348 12373
12349 template void Dictionary<NameDictionaryShape, Name*>::CopyKeysTo( 12374 template void Dictionary<NameDictionaryShape, Name*>::CopyKeysTo(
12350 FixedArray*, 12375 FixedArray*,
12351 int, 12376 int,
12377 PropertyAttributes,
12352 Dictionary<NameDictionaryShape, Name*>::SortMode); 12378 Dictionary<NameDictionaryShape, Name*>::SortMode);
12353 12379
12354 template int 12380 template int
12355 Dictionary<NameDictionaryShape, Name*>::NumberOfElementsFilterAttributes( 12381 Dictionary<NameDictionaryShape, Name*>::NumberOfElementsFilterAttributes(
12356 PropertyAttributes); 12382 PropertyAttributes);
12357 12383
12358 template MaybeObject* Dictionary<NameDictionaryShape, Name*>::Add( 12384 template MaybeObject* Dictionary<NameDictionaryShape, Name*>::Add(
12359 Name*, Object*, PropertyDetails); 12385 Name*, Object*, PropertyDetails);
12360 12386
12361 template MaybeObject* 12387 template MaybeObject*
(...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after
13584 RightTrimFixedArray<FROM_MUTATOR>(heap, storage, length - properties); 13610 RightTrimFixedArray<FROM_MUTATOR>(heap, storage, length - properties);
13585 } 13611 }
13586 return storage; 13612 return storage;
13587 } 13613 }
13588 13614
13589 13615
13590 template<typename Shape, typename Key> 13616 template<typename Shape, typename Key>
13591 void Dictionary<Shape, Key>::CopyKeysTo( 13617 void Dictionary<Shape, Key>::CopyKeysTo(
13592 FixedArray* storage, 13618 FixedArray* storage,
13593 int index, 13619 int index,
13620 PropertyAttributes filter,
13594 typename Dictionary<Shape, Key>::SortMode sort_mode) { 13621 typename Dictionary<Shape, Key>::SortMode sort_mode) {
13595 ASSERT(storage->length() >= NumberOfElementsFilterAttributes( 13622 ASSERT(storage->length() >= NumberOfElementsFilterAttributes(
13596 static_cast<PropertyAttributes>(NONE))); 13623 static_cast<PropertyAttributes>(NONE)));
13597 int capacity = HashTable<Shape, Key>::Capacity(); 13624 int capacity = HashTable<Shape, Key>::Capacity();
13598 for (int i = 0; i < capacity; i++) { 13625 for (int i = 0; i < capacity; i++) {
13599 Object* k = HashTable<Shape, Key>::KeyAt(i); 13626 Object* k = HashTable<Shape, Key>::KeyAt(i);
13600 if (HashTable<Shape, Key>::IsKey(k)) { 13627 if (HashTable<Shape, Key>::IsKey(k)) {
13601 PropertyDetails details = DetailsAt(i); 13628 PropertyDetails details = DetailsAt(i);
13602 if (details.IsDeleted()) continue; 13629 if (details.IsDeleted()) continue;
13603 storage->set(index++, k); 13630 PropertyAttributes attr = details.attributes();
13631 if ((attr & filter) == 0) storage->set(index++, k);
13604 } 13632 }
13605 } 13633 }
13606 if (sort_mode == Dictionary<Shape, Key>::SORTED) { 13634 if (sort_mode == Dictionary<Shape, Key>::SORTED) {
13607 storage->SortPairs(storage, index); 13635 storage->SortPairs(storage, index);
13608 } 13636 }
13609 ASSERT(storage->length() >= index); 13637 ASSERT(storage->length() >= index);
13610 } 13638 }
13611 13639
13612 13640
13613 // Backwards lookup (slow). 13641 // Backwards lookup (slow).
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
14327 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 14355 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
14328 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 14356 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
14329 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 14357 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
14330 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 14358 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
14331 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 14359 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
14332 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 14360 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
14333 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 14361 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
14334 } 14362 }
14335 14363
14336 } } // namespace v8::internal 14364 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698