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

Side by Side Diff: src/accessors.cc

Issue 257423009: Convert function.length to API-style 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 | « 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 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 &FunctionPrototypeSetter, 882 &FunctionPrototypeSetter,
883 attributes); 883 attributes);
884 } 884 }
885 885
886 886
887 // 887 //
888 // Accessors::FunctionLength 888 // Accessors::FunctionLength
889 // 889 //
890 890
891 891
892 Object* Accessors::FunctionGetLength(Isolate* isolate, 892 void Accessors::FunctionLengthGetter(
893 Object* object, 893 v8::Local<v8::String> name,
894 void*) { 894 const v8::PropertyCallbackInfo<v8::Value>& info) {
895 JSFunction* function = FindInstanceOf<JSFunction>(isolate, object); 895 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
896 if (function == NULL) return Smi::FromInt(0); 896 HandleScope scope(isolate);
897 // Check if already compiled. 897 Handle<Object> object = Utils::OpenHandle(*info.This());
898 if (function->shared()->is_compiled()) { 898 MaybeHandle<JSFunction> maybe_function;
899 return Smi::FromInt(function->shared()->length()); 899
900 {
901 DisallowHeapAllocation no_allocation;
902 JSFunction* function = FindInstanceOf<JSFunction>(isolate, *object);
903 if (function != NULL) maybe_function = Handle<JSFunction>(function);
900 } 904 }
901 // If the function isn't compiled yet, the length is not computed correctly 905
902 // yet. Compile it now and return the right length. 906 int length = 0;
903 HandleScope scope(isolate); 907 Handle<JSFunction> function;
904 Handle<JSFunction> function_handle(function); 908 if (maybe_function.ToHandle(&function)) {
905 if (Compiler::EnsureCompiled(function_handle, KEEP_EXCEPTION)) { 909 if (function->shared()->is_compiled()) {
906 return Smi::FromInt(function_handle->shared()->length()); 910 length = function->shared()->length();
911 } else {
912 // If the function isn't compiled yet, the length is not computed
913 // correctly yet. Compile it now and return the right length.
914 if (Compiler::EnsureCompiled(function, KEEP_EXCEPTION)) {
915 length = function->shared()->length();
916 }
917 if (isolate->has_pending_exception()) {
918 isolate->OptionalRescheduleException(false);
ulan 2014/04/24 10:27:03 I added a test that checks this.
919 }
920 }
907 } 921 }
908 return isolate->heap()->exception(); 922 Handle<Object> result(Smi::FromInt(length), isolate);
923 info.GetReturnValue().Set(Utils::ToLocal(result));
909 } 924 }
910 925
911 926
912 const AccessorDescriptor Accessors::FunctionLength = { 927 void Accessors::FunctionLengthSetter(
913 FunctionGetLength, 928 v8::Local<v8::String> name,
914 ReadOnlySetAccessor, 929 v8::Local<v8::Value> val,
915 0 930 const v8::PropertyCallbackInfo<void>& info) {
916 }; 931 // Do nothing.
932 }
933
934
935 Handle<AccessorInfo> Accessors::FunctionLengthInfo(
936 Isolate* isolate, PropertyAttributes attributes) {
937 return MakeAccessor(isolate,
938 isolate->factory()->length_string(),
939 &FunctionLengthGetter,
940 &FunctionLengthSetter,
941 attributes);
942 }
917 943
918 944
919 // 945 //
920 // Accessors::FunctionName 946 // Accessors::FunctionName
921 // 947 //
922 948
923 949
924 Object* Accessors::FunctionGetName(Isolate* isolate, 950 Object* Accessors::FunctionGetName(Isolate* isolate,
925 Object* object, 951 Object* object,
926 void*) { 952 void*) {
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 info->set_data(Smi::FromInt(index)); 1248 info->set_data(Smi::FromInt(index));
1223 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); 1249 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport);
1224 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); 1250 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport);
1225 info->set_getter(*getter); 1251 info->set_getter(*getter);
1226 if (!(attributes & ReadOnly)) info->set_setter(*setter); 1252 if (!(attributes & ReadOnly)) info->set_setter(*setter);
1227 return info; 1253 return info;
1228 } 1254 }
1229 1255
1230 1256
1231 } } // namespace v8::internal 1257 } } // 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