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

Side by Side Diff: src/accessors.cc

Issue 246693005: Convert function.prototype to API-style accessor. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Check that exception is never thrown 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 | « src/accessors.h ('k') | src/bootstrapper.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 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 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 } 790 }
791 791
792 if (!function->has_prototype()) { 792 if (!function->has_prototype()) {
793 Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function); 793 Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function);
794 JSFunction::SetPrototype(function, proto); 794 JSFunction::SetPrototype(function, proto);
795 } 795 }
796 return Handle<Object>(function->prototype(), isolate); 796 return Handle<Object>(function->prototype(), isolate);
797 } 797 }
798 798
799 799
800 Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) { 800 static Handle<Object> SetFunctionPrototype(Isolate* isolate,
801 return GetFunctionPrototype(function->GetIsolate(), function); 801 Handle<JSObject> receiver,
802 } 802 Handle<Object> value) {
803 803 Handle<JSFunction> function;
804
805
806 MaybeHandle<Object> SetFunctionPrototype(Isolate* isolate,
807 Handle<JSObject> receiver,
808 Handle<Object> value) {
809 Handle<JSFunction> function;
810 { 804 {
811 DisallowHeapAllocation no_allocation; 805 DisallowHeapAllocation no_allocation;
812 JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, *receiver); 806 JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, *receiver);
813 if (function_raw == NULL) return isolate->factory()->undefined_value(); 807 if (function_raw == NULL) return isolate->factory()->undefined_value();
814 function = Handle<JSFunction>(function_raw, isolate); 808 function = Handle<JSFunction>(function_raw, isolate);
815 } 809 }
816 810
817 if (!function->should_have_prototype()) { 811 if (!function->should_have_prototype()) {
818 // Since we hit this accessor, object will have no prototype property. 812 // Since we hit this accessor, object will have no prototype property.
819 return JSObject::SetLocalPropertyIgnoreAttributes( 813 MaybeHandle<Object> maybe_result =
820 receiver, isolate->factory()->prototype_string(), value, NONE); 814 JSObject::SetLocalPropertyIgnoreAttributes(
815 receiver, isolate->factory()->prototype_string(), value, NONE);
816 return maybe_result.ToHandleChecked();
821 } 817 }
822 818
823 Handle<Object> old_value; 819 Handle<Object> old_value;
824 bool is_observed = *function == *receiver && function->map()->is_observed(); 820 bool is_observed = *function == *receiver && function->map()->is_observed();
825 if (is_observed) { 821 if (is_observed) {
826 if (function->has_prototype()) 822 if (function->has_prototype())
827 old_value = handle(function->prototype(), isolate); 823 old_value = handle(function->prototype(), isolate);
828 else 824 else
829 old_value = isolate->factory()->NewFunctionPrototype(function); 825 old_value = isolate->factory()->NewFunctionPrototype(function);
830 } 826 }
831 827
832 JSFunction::SetPrototype(function, value); 828 JSFunction::SetPrototype(function, value);
833 ASSERT(function->prototype() == *value); 829 ASSERT(function->prototype() == *value);
834 830
835 if (is_observed && !old_value->SameValue(*value)) { 831 if (is_observed && !old_value->SameValue(*value)) {
836 JSObject::EnqueueChangeRecord( 832 JSObject::EnqueueChangeRecord(
837 function, "update", isolate->factory()->prototype_string(), old_value); 833 function, "update", isolate->factory()->prototype_string(), old_value);
838 } 834 }
839 835
840 return function; 836 return function;
841 } 837 }
842 838
843 839
840 Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) {
841 return GetFunctionPrototype(function->GetIsolate(), function);
842 }
843
844
844 Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function, 845 Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function,
845 Handle<Object> prototype) { 846 Handle<Object> prototype) {
846 ASSERT(function->should_have_prototype()); 847 ASSERT(function->should_have_prototype());
847 Isolate* isolate = function->GetIsolate(); 848 Isolate* isolate = function->GetIsolate();
848 Handle<Object> result; 849 return SetFunctionPrototype(isolate, function, prototype);
849 SetFunctionPrototype(isolate, function, prototype).ToHandle(&result);
850 return result;
851 } 850 }
852 851
853 852
854 MaybeObject* Accessors::FunctionGetPrototype(Isolate* isolate, 853 void Accessors::FunctionPrototypeGetter(
855 Object* object, 854 v8::Local<v8::String> name,
856 void*) { 855 const v8::PropertyCallbackInfo<v8::Value>& info) {
856 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
857 HandleScope scope(isolate); 857 HandleScope scope(isolate);
858 return *GetFunctionPrototype(isolate, Handle<Object>(object, isolate)); 858 Handle<Object> object = Utils::OpenHandle(*info.This());
859 Handle<Object> result = GetFunctionPrototype(isolate, object);
860 info.GetReturnValue().Set(Utils::ToLocal(result));
859 } 861 }
860 862
861 863
862 MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate, 864 void Accessors::FunctionPrototypeSetter(
863 JSObject* object, 865 v8::Local<v8::String> name,
864 Object* value, 866 v8::Local<v8::Value> val,
865 void*) { 867 const v8::PropertyCallbackInfo<void>& info) {
866 Handle<Object> result; 868 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
867 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 869 HandleScope scope(isolate);
868 isolate, result, 870 Handle<JSObject> object = Utils::OpenHandle(*info.This());
869 SetFunctionPrototype(isolate, 871 Handle<Object> value = Utils::OpenHandle(*val);
870 Handle<JSObject>(object, isolate), 872
871 Handle<Object>(value, isolate))); 873 SetFunctionPrototype(isolate, object, value);
872 return *result;
873 } 874 }
874 875
875 876
876 const AccessorDescriptor Accessors::FunctionPrototype = { 877 Handle<AccessorInfo> Accessors::FunctionPrototypeInfo(
877 FunctionGetPrototype, 878 Isolate* isolate, PropertyAttributes attributes) {
878 FunctionSetPrototype, 879 return MakeAccessor(isolate,
879 0 880 isolate->factory()->prototype_string(),
880 }; 881 &FunctionPrototypeGetter,
882 &FunctionPrototypeSetter,
883 attributes);
884 }
881 885
882 886
883 // 887 //
884 // Accessors::FunctionLength 888 // Accessors::FunctionLength
885 // 889 //
886 890
887 891
888 MaybeObject* Accessors::FunctionGetLength(Isolate* isolate, 892 MaybeObject* Accessors::FunctionGetLength(Isolate* isolate,
889 Object* object, 893 Object* object,
890 void*) { 894 void*) {
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 info->set_data(Smi::FromInt(index)); 1222 info->set_data(Smi::FromInt(index));
1219 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); 1223 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport);
1220 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); 1224 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport);
1221 info->set_getter(*getter); 1225 info->set_getter(*getter);
1222 if (!(attributes & ReadOnly)) info->set_setter(*setter); 1226 if (!(attributes & ReadOnly)) info->set_setter(*setter);
1223 return info; 1227 return info;
1224 } 1228 }
1225 1229
1226 1230
1227 } } // namespace v8::internal 1231 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/accessors.h ('k') | src/bootstrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698