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

Side by Side Diff: src/handles.cc

Issue 8256015: Implement for-in loop for proxies. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed Rico's comments. Created 9 years, 2 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/handles.h ('k') | src/ia32/full-codegen-ia32.cc » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 return line; 684 return line;
685 } 685 }
686 686
687 687
688 void CustomArguments::IterateInstance(ObjectVisitor* v) { 688 void CustomArguments::IterateInstance(ObjectVisitor* v) {
689 v->VisitPointers(values_, values_ + ARRAY_SIZE(values_)); 689 v->VisitPointers(values_, values_ + ARRAY_SIZE(values_));
690 } 690 }
691 691
692 692
693 // Compute the property keys from the interceptor. 693 // Compute the property keys from the interceptor.
694 v8::Handle<v8::Array> GetKeysForNamedInterceptor(Handle<JSObject> receiver, 694 v8::Handle<v8::Array> GetKeysForNamedInterceptor(Handle<JSReceiver> receiver,
695 Handle<JSObject> object) { 695 Handle<JSObject> object) {
696 Isolate* isolate = receiver->GetIsolate(); 696 Isolate* isolate = receiver->GetIsolate();
697 Handle<InterceptorInfo> interceptor(object->GetNamedInterceptor()); 697 Handle<InterceptorInfo> interceptor(object->GetNamedInterceptor());
698 CustomArguments args(isolate, interceptor->data(), *receiver, *object); 698 CustomArguments args(isolate, interceptor->data(), *receiver, *object);
699 v8::AccessorInfo info(args.end()); 699 v8::AccessorInfo info(args.end());
700 v8::Handle<v8::Array> result; 700 v8::Handle<v8::Array> result;
701 if (!interceptor->enumerator()->IsUndefined()) { 701 if (!interceptor->enumerator()->IsUndefined()) {
702 v8::NamedPropertyEnumerator enum_fun = 702 v8::NamedPropertyEnumerator enum_fun =
703 v8::ToCData<v8::NamedPropertyEnumerator>(interceptor->enumerator()); 703 v8::ToCData<v8::NamedPropertyEnumerator>(interceptor->enumerator());
704 LOG(isolate, ApiObjectAccess("interceptor-named-enum", *object)); 704 LOG(isolate, ApiObjectAccess("interceptor-named-enum", *object));
705 { 705 {
706 // Leaving JavaScript. 706 // Leaving JavaScript.
707 VMState state(isolate, EXTERNAL); 707 VMState state(isolate, EXTERNAL);
708 result = enum_fun(info); 708 result = enum_fun(info);
709 } 709 }
710 } 710 }
711 return result; 711 return result;
712 } 712 }
713 713
714 714
715 // Compute the element keys from the interceptor. 715 // Compute the element keys from the interceptor.
716 v8::Handle<v8::Array> GetKeysForIndexedInterceptor(Handle<JSObject> receiver, 716 v8::Handle<v8::Array> GetKeysForIndexedInterceptor(Handle<JSReceiver> receiver,
717 Handle<JSObject> object) { 717 Handle<JSObject> object) {
718 Isolate* isolate = receiver->GetIsolate(); 718 Isolate* isolate = receiver->GetIsolate();
719 Handle<InterceptorInfo> interceptor(object->GetIndexedInterceptor()); 719 Handle<InterceptorInfo> interceptor(object->GetIndexedInterceptor());
720 CustomArguments args(isolate, interceptor->data(), *receiver, *object); 720 CustomArguments args(isolate, interceptor->data(), *receiver, *object);
721 v8::AccessorInfo info(args.end()); 721 v8::AccessorInfo info(args.end());
722 v8::Handle<v8::Array> result; 722 v8::Handle<v8::Array> result;
723 if (!interceptor->enumerator()->IsUndefined()) { 723 if (!interceptor->enumerator()->IsUndefined()) {
724 v8::IndexedPropertyEnumerator enum_fun = 724 v8::IndexedPropertyEnumerator enum_fun =
725 v8::ToCData<v8::IndexedPropertyEnumerator>(interceptor->enumerator()); 725 v8::ToCData<v8::IndexedPropertyEnumerator>(interceptor->enumerator());
726 LOG(isolate, ApiObjectAccess("interceptor-indexed-enum", *object)); 726 LOG(isolate, ApiObjectAccess("interceptor-indexed-enum", *object));
(...skipping 10 matching lines...) Expand all
737 static bool ContainsOnlyValidKeys(Handle<FixedArray> array) { 737 static bool ContainsOnlyValidKeys(Handle<FixedArray> array) {
738 int len = array->length(); 738 int len = array->length();
739 for (int i = 0; i < len; i++) { 739 for (int i = 0; i < len; i++) {
740 Object* e = array->get(i); 740 Object* e = array->get(i);
741 if (!(e->IsString() || e->IsNumber())) return false; 741 if (!(e->IsString() || e->IsNumber())) return false;
742 } 742 }
743 return true; 743 return true;
744 } 744 }
745 745
746 746
747 Handle<FixedArray> GetKeysInFixedArrayFor(Handle<JSObject> object, 747 Handle<FixedArray> GetKeysInFixedArrayFor(Handle<JSReceiver> object,
748 KeyCollectionType type) { 748 KeyCollectionType type,
749 bool* threw) {
749 USE(ContainsOnlyValidKeys); 750 USE(ContainsOnlyValidKeys);
750 Isolate* isolate = object->GetIsolate(); 751 Isolate* isolate = object->GetIsolate();
751 Handle<FixedArray> content = isolate->factory()->empty_fixed_array(); 752 Handle<FixedArray> content = isolate->factory()->empty_fixed_array();
752 Handle<JSObject> arguments_boilerplate = Handle<JSObject>( 753 Handle<JSObject> arguments_boilerplate = Handle<JSObject>(
753 isolate->context()->global_context()->arguments_boilerplate(), 754 isolate->context()->global_context()->arguments_boilerplate(),
754 isolate); 755 isolate);
755 Handle<JSFunction> arguments_function = Handle<JSFunction>( 756 Handle<JSFunction> arguments_function = Handle<JSFunction>(
756 JSFunction::cast(arguments_boilerplate->map()->constructor()), 757 JSFunction::cast(arguments_boilerplate->map()->constructor()),
757 isolate); 758 isolate);
758 759
759 // Only collect keys if access is permitted. 760 // Only collect keys if access is permitted.
760 for (Handle<Object> p = object; 761 for (Handle<Object> p = object;
761 *p != isolate->heap()->null_value(); 762 *p != isolate->heap()->null_value();
762 p = Handle<Object>(p->GetPrototype(), isolate)) { 763 p = Handle<Object>(p->GetPrototype(), isolate)) {
764 if (p->IsJSProxy()) {
765 Handle<JSProxy> proxy(JSProxy::cast(*p), isolate);
766 Handle<Object> args[] = { proxy };
767 Handle<Object> names = Execution::Call(
768 isolate->proxy_enumerate(), object, ARRAY_SIZE(args), args, threw);
769 if (*threw) return content;
770 content = AddKeysFromJSArray(content, Handle<JSArray>::cast(names));
771 break;
772 }
773
763 Handle<JSObject> current(JSObject::cast(*p), isolate); 774 Handle<JSObject> current(JSObject::cast(*p), isolate);
764 775
765 // Check access rights if required. 776 // Check access rights if required.
766 if (current->IsAccessCheckNeeded() && 777 if (current->IsAccessCheckNeeded() &&
767 !isolate->MayNamedAccess(*current, 778 !isolate->MayNamedAccess(*current,
768 isolate->heap()->undefined_value(), 779 isolate->heap()->undefined_value(),
769 v8::ACCESS_KEYS)) { 780 v8::ACCESS_KEYS)) {
770 isolate->ReportFailedAccessCheck(*current, v8::ACCESS_KEYS); 781 isolate->ReportFailedAccessCheck(*current, v8::ACCESS_KEYS);
771 break; 782 break;
772 } 783 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 830
820 // If we only want local properties we bail out after the first 831 // If we only want local properties we bail out after the first
821 // iteration. 832 // iteration.
822 if (type == LOCAL_ONLY) 833 if (type == LOCAL_ONLY)
823 break; 834 break;
824 } 835 }
825 return content; 836 return content;
826 } 837 }
827 838
828 839
829 Handle<JSArray> GetKeysFor(Handle<JSObject> object) { 840 Handle<JSArray> GetKeysFor(Handle<JSReceiver> object, bool* threw) {
830 Isolate* isolate = object->GetIsolate(); 841 Isolate* isolate = object->GetIsolate();
831 isolate->counters()->for_in()->Increment(); 842 isolate->counters()->for_in()->Increment();
832 Handle<FixedArray> elements = GetKeysInFixedArrayFor(object, 843 Handle<FixedArray> elements =
833 INCLUDE_PROTOS); 844 GetKeysInFixedArrayFor(object, INCLUDE_PROTOS, threw);
834 return isolate->factory()->NewJSArrayWithElements(elements); 845 return isolate->factory()->NewJSArrayWithElements(elements);
835 } 846 }
836 847
837 848
838 Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object, 849 Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object,
839 bool cache_result) { 850 bool cache_result) {
840 int index = 0; 851 int index = 0;
841 Isolate* isolate = object->GetIsolate(); 852 Isolate* isolate = object->GetIsolate();
842 if (object->HasFastProperties()) { 853 if (object->HasFastProperties()) {
843 if (object->map()->instance_descriptors()->HasEnumCache()) { 854 if (object->map()->instance_descriptors()->HasEnumCache()) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 Handle<ObjectHashTable> PutIntoObjectHashTable(Handle<ObjectHashTable> table, 894 Handle<ObjectHashTable> PutIntoObjectHashTable(Handle<ObjectHashTable> table,
884 Handle<JSReceiver> key, 895 Handle<JSReceiver> key,
885 Handle<Object> value) { 896 Handle<Object> value) {
886 CALL_HEAP_FUNCTION(table->GetIsolate(), 897 CALL_HEAP_FUNCTION(table->GetIsolate(),
887 table->Put(*key, *value), 898 table->Put(*key, *value),
888 ObjectHashTable); 899 ObjectHashTable);
889 } 900 }
890 901
891 902
892 } } // namespace v8::internal 903 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/handles.h ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698