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

Side by Side Diff: src/accessors.cc

Issue 240323004: Handlify function.prototype accessor. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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 | « 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 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 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 &ScriptEvalFromFunctionNameGetter, 766 &ScriptEvalFromFunctionNameGetter,
767 &ScriptEvalFromFunctionNameSetter, 767 &ScriptEvalFromFunctionNameSetter,
768 attributes); 768 attributes);
769 } 769 }
770 770
771 771
772 // 772 //
773 // Accessors::FunctionPrototype 773 // Accessors::FunctionPrototype
774 // 774 //
775 775
776 static Handle<Object> GetFunctionPrototype(Handle<Object> receiver,
777 Isolate* isolate) {
Yang 2014/04/17 05:55:42 I think the convention is (mostly) to have Isolate
778 Handle<JSFunction> function;
779 {
780 DisallowHeapAllocation no_allocation;
781 JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, *receiver);
782 if (function_raw == NULL) return isolate->factory()->undefined_value();
783 while (!function_raw->should_have_prototype()) {
784 function_raw = FindInstanceOf<JSFunction>(isolate,
785 function_raw->GetPrototype());
786 // There has to be one because we hit the getter.
787 ASSERT(function_raw != NULL);
788 }
789 function = Handle<JSFunction>(function_raw, isolate);
790 }
776 791
777 Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) { 792 if (!function->has_prototype()) {
778 CALL_HEAP_FUNCTION(function->GetIsolate(), 793 Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function);
779 Accessors::FunctionGetPrototype(function->GetIsolate(), 794 JSFunction::SetPrototype(function, proto);
780 *function, 795 }
781 NULL), 796 return Handle<Object>(function->prototype(), isolate);
782 Object);
783 } 797 }
784 798
785 799
786 Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function, 800 Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) {
787 Handle<Object> prototype) { 801 return GetFunctionPrototype(function, function->GetIsolate());
788 ASSERT(function->should_have_prototype());
789 CALL_HEAP_FUNCTION(function->GetIsolate(),
790 Accessors::FunctionSetPrototype(function->GetIsolate(),
791 *function,
792 *prototype,
793 NULL),
794 Object);
795 } 802 }
796 803
797 804
798 MaybeObject* Accessors::FunctionGetPrototype(Isolate* isolate, 805
799 Object* object, 806 MaybeHandle<Object> SetFunctionPrototype(Handle<JSObject> receiver,
800 void*) { 807 Handle<Object> value,
801 JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, object); 808 Isolate* isolate) {
Yang 2014/04/17 05:55:42 Same here.
802 if (function_raw == NULL) return isolate->heap()->undefined_value(); 809 Handle<JSFunction> function;
803 while (!function_raw->should_have_prototype()) { 810 {
804 function_raw = FindInstanceOf<JSFunction>(isolate, 811 DisallowHeapAllocation no_allocation;
805 function_raw->GetPrototype()); 812 JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, *receiver);
806 // There has to be one because we hit the getter. 813 if (function_raw == NULL) return isolate->factory()->undefined_value();
807 ASSERT(function_raw != NULL); 814 function = Handle<JSFunction>(function_raw, isolate);
808 } 815 }
809 816
810 if (!function_raw->has_prototype()) {
811 HandleScope scope(isolate);
812 Handle<JSFunction> function(function_raw);
813 Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function);
814 JSFunction::SetPrototype(function, proto);
815 function_raw = *function;
816 }
817 return function_raw->prototype();
818 }
819
820
821 MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate,
822 JSObject* object_raw,
823 Object* value_raw,
824 void*) {
825 JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, object_raw);
826 if (function_raw == NULL) return isolate->heap()->undefined_value();
827
828 HandleScope scope(isolate);
829 Handle<JSFunction> function(function_raw, isolate);
830 Handle<JSObject> object(object_raw, isolate);
831 Handle<Object> value(value_raw, isolate);
832 if (!function->should_have_prototype()) { 817 if (!function->should_have_prototype()) {
833 // Since we hit this accessor, object will have no prototype property. 818 // Since we hit this accessor, object will have no prototype property.
834 Handle<Object> result; 819 return JSObject::SetLocalPropertyIgnoreAttributes(
835 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 820 receiver, isolate->factory()->prototype_string(), value, NONE);
836 isolate, result,
837 JSObject::SetLocalPropertyIgnoreAttributes(
838 object, isolate->factory()->prototype_string(), value, NONE));
839 return *result;
840 } 821 }
841 822
842 Handle<Object> old_value; 823 Handle<Object> old_value;
843 bool is_observed = *function == *object && function->map()->is_observed(); 824 bool is_observed = *function == *receiver && function->map()->is_observed();
844 if (is_observed) { 825 if (is_observed) {
845 if (function->has_prototype()) 826 if (function->has_prototype())
846 old_value = handle(function->prototype(), isolate); 827 old_value = handle(function->prototype(), isolate);
847 else 828 else
848 old_value = isolate->factory()->NewFunctionPrototype(function); 829 old_value = isolate->factory()->NewFunctionPrototype(function);
849 } 830 }
850 831
851 JSFunction::SetPrototype(function, value); 832 JSFunction::SetPrototype(function, value);
852 ASSERT(function->prototype() == *value); 833 ASSERT(function->prototype() == *value);
853 834
854 if (is_observed && !old_value->SameValue(*value)) { 835 if (is_observed && !old_value->SameValue(*value)) {
855 JSObject::EnqueueChangeRecord( 836 JSObject::EnqueueChangeRecord(
856 function, "update", isolate->factory()->prototype_string(), old_value); 837 function, "update", isolate->factory()->prototype_string(), old_value);
857 } 838 }
858 839
859 return *function; 840 return function;
860 } 841 }
861 842
862 843
844 Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function,
845 Handle<Object> prototype) {
846 ASSERT(function->should_have_prototype());
847 Isolate* isolate = function->GetIsolate();
848 Handle<Object> result;
849 SetFunctionPrototype(function, prototype, isolate).ToHandle(&result);
850 return result;
851 }
852
853
854 MaybeObject* Accessors::FunctionGetPrototype(Isolate* isolate,
855 Object* object,
856 void*) {
857 HandleScope scope(isolate);
858 return *GetFunctionPrototype(Handle<Object>(object, isolate), isolate);
859 }
860
861
862 MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate,
863 JSObject* object,
864 Object* value,
865 void*) {
866 Handle<Object> result;
867 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
868 isolate, result,
869 SetFunctionPrototype(Handle<JSObject>(object, isolate),
870 Handle<Object>(value, isolate),
871 isolate));
872 return *result;
873 }
874
875
863 const AccessorDescriptor Accessors::FunctionPrototype = { 876 const AccessorDescriptor Accessors::FunctionPrototype = {
864 FunctionGetPrototype, 877 FunctionGetPrototype,
865 FunctionSetPrototype, 878 FunctionSetPrototype,
866 0 879 0
867 }; 880 };
868 881
869 882
870 // 883 //
871 // Accessors::FunctionLength 884 // Accessors::FunctionLength
872 // 885 //
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 info->set_data(Smi::FromInt(index)); 1218 info->set_data(Smi::FromInt(index));
1206 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); 1219 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport);
1207 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); 1220 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport);
1208 info->set_getter(*getter); 1221 info->set_getter(*getter);
1209 if (!(attributes & ReadOnly)) info->set_setter(*setter); 1222 if (!(attributes & ReadOnly)) info->set_setter(*setter);
1210 return info; 1223 return info;
1211 } 1224 }
1212 1225
1213 1226
1214 } } // namespace v8::internal 1227 } } // namespace v8::internal
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