| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/accessors.h" | 5 #include "src/accessors.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/contexts.h" | 8 #include "src/contexts.h" |
| 9 #include "src/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
| 10 #include "src/execution.h" | 10 #include "src/execution.h" |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 // | 803 // |
| 804 | 804 |
| 805 | 805 |
| 806 void Accessors::FunctionLengthGetter( | 806 void Accessors::FunctionLengthGetter( |
| 807 v8::Local<v8::Name> name, | 807 v8::Local<v8::Name> name, |
| 808 const v8::PropertyCallbackInfo<v8::Value>& info) { | 808 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 809 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); | 809 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
| 810 HandleScope scope(isolate); | 810 HandleScope scope(isolate); |
| 811 Handle<JSFunction> function = | 811 Handle<JSFunction> function = |
| 812 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder())); | 812 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder())); |
| 813 Handle<Object> result; |
| 814 if (!JSFunction::GetLength(isolate, function).ToHandle(&result)) { |
| 815 result = handle(Smi::FromInt(0), isolate); |
| 816 isolate->OptionalRescheduleException(false); |
| 817 } |
| 813 | 818 |
| 814 int length = 0; | |
| 815 if (function->shared()->is_compiled()) { | |
| 816 length = function->shared()->length(); | |
| 817 } else { | |
| 818 // If the function isn't compiled yet, the length is not computed | |
| 819 // correctly yet. Compile it now and return the right length. | |
| 820 if (Compiler::Compile(function, Compiler::KEEP_EXCEPTION)) { | |
| 821 length = function->shared()->length(); | |
| 822 } | |
| 823 if (isolate->has_pending_exception()) { | |
| 824 isolate->OptionalRescheduleException(false); | |
| 825 } | |
| 826 } | |
| 827 Handle<Object> result(Smi::FromInt(length), isolate); | |
| 828 info.GetReturnValue().Set(Utils::ToLocal(result)); | 819 info.GetReturnValue().Set(Utils::ToLocal(result)); |
| 829 } | 820 } |
| 830 | 821 |
| 831 void Accessors::ObservedReconfigureToDataProperty( | 822 void Accessors::ObservedReconfigureToDataProperty( |
| 832 v8::Local<v8::Name> key, v8::Local<v8::Value> val, | 823 v8::Local<v8::Name> key, v8::Local<v8::Value> val, |
| 833 const v8::PropertyCallbackInfo<void>& info) { | 824 const v8::PropertyCallbackInfo<void>& info) { |
| 834 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); | 825 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
| 835 HandleScope scope(isolate); | 826 HandleScope scope(isolate); |
| 836 Handle<JSObject> receiver = | 827 Handle<JSObject> receiver = |
| 837 Handle<JSObject>::cast(Utils::OpenHandle(*info.This())); | 828 Handle<JSObject>::cast(Utils::OpenHandle(*info.This())); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 858 // | 849 // |
| 859 | 850 |
| 860 | 851 |
| 861 void Accessors::FunctionNameGetter( | 852 void Accessors::FunctionNameGetter( |
| 862 v8::Local<v8::Name> name, | 853 v8::Local<v8::Name> name, |
| 863 const v8::PropertyCallbackInfo<v8::Value>& info) { | 854 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 864 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); | 855 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
| 865 HandleScope scope(isolate); | 856 HandleScope scope(isolate); |
| 866 Handle<JSFunction> function = | 857 Handle<JSFunction> function = |
| 867 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder())); | 858 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder())); |
| 868 Handle<Object> result; | 859 Handle<Object> result = JSFunction::GetName(isolate, function); |
| 869 if (function->shared()->name_should_print_as_anonymous()) { | |
| 870 result = isolate->factory()->anonymous_string(); | |
| 871 } else { | |
| 872 result = handle(function->shared()->name(), isolate); | |
| 873 } | |
| 874 info.GetReturnValue().Set(Utils::ToLocal(result)); | 860 info.GetReturnValue().Set(Utils::ToLocal(result)); |
| 875 } | 861 } |
| 876 | 862 |
| 877 Handle<AccessorInfo> Accessors::FunctionNameInfo( | 863 Handle<AccessorInfo> Accessors::FunctionNameInfo( |
| 878 Isolate* isolate, PropertyAttributes attributes) { | 864 Isolate* isolate, PropertyAttributes attributes) { |
| 879 return MakeAccessor(isolate, isolate->factory()->name_string(), | 865 return MakeAccessor(isolate, isolate->factory()->name_string(), |
| 880 &FunctionNameGetter, &ObservedReconfigureToDataProperty, | 866 &FunctionNameGetter, &ObservedReconfigureToDataProperty, |
| 881 attributes); | 867 attributes); |
| 882 } | 868 } |
| 883 | 869 |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 | 1133 |
| 1148 | 1134 |
| 1149 Handle<AccessorInfo> Accessors::FunctionCallerInfo( | 1135 Handle<AccessorInfo> Accessors::FunctionCallerInfo( |
| 1150 Isolate* isolate, PropertyAttributes attributes) { | 1136 Isolate* isolate, PropertyAttributes attributes) { |
| 1151 return MakeAccessor(isolate, isolate->factory()->caller_string(), | 1137 return MakeAccessor(isolate, isolate->factory()->caller_string(), |
| 1152 &FunctionCallerGetter, nullptr, attributes); | 1138 &FunctionCallerGetter, nullptr, attributes); |
| 1153 } | 1139 } |
| 1154 | 1140 |
| 1155 | 1141 |
| 1156 // | 1142 // |
| 1143 // Accessors::BoundFunctionLength |
| 1144 // |
| 1145 |
| 1146 void Accessors::BoundFunctionLengthGetter( |
| 1147 v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1148 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
| 1149 HandleScope scope(isolate); |
| 1150 Handle<JSBoundFunction> function = |
| 1151 Handle<JSBoundFunction>::cast(Utils::OpenHandle(*info.Holder())); |
| 1152 |
| 1153 Handle<Smi> target_length; |
| 1154 Handle<JSFunction> target(JSFunction::cast(function->bound_target_function()), |
| 1155 isolate); |
| 1156 if (!JSFunction::GetLength(isolate, target).ToHandle(&target_length)) { |
| 1157 target_length = handle(Smi::FromInt(0), isolate); |
| 1158 isolate->OptionalRescheduleException(false); |
| 1159 return; |
| 1160 } |
| 1161 |
| 1162 int bound_length = function->bound_arguments()->length(); |
| 1163 int length = Max(0, target_length->value() - bound_length); |
| 1164 |
| 1165 Handle<Object> result(Smi::FromInt(length), isolate); |
| 1166 info.GetReturnValue().Set(Utils::ToLocal(result)); |
| 1167 } |
| 1168 |
| 1169 Handle<AccessorInfo> Accessors::BoundFunctionLengthInfo( |
| 1170 Isolate* isolate, PropertyAttributes attributes) { |
| 1171 return MakeAccessor(isolate, isolate->factory()->length_string(), |
| 1172 &BoundFunctionLengthGetter, |
| 1173 &ObservedReconfigureToDataProperty, attributes); |
| 1174 } |
| 1175 |
| 1176 // |
| 1177 // Accessors::BoundFunctionName |
| 1178 // |
| 1179 |
| 1180 void Accessors::BoundFunctionNameGetter( |
| 1181 v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1182 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
| 1183 HandleScope scope(isolate); |
| 1184 Handle<JSBoundFunction> function = |
| 1185 Handle<JSBoundFunction>::cast(Utils::OpenHandle(*info.Holder())); |
| 1186 Handle<Object> result; |
| 1187 if (!JSBoundFunction::GetName(isolate, function).ToHandle(&result)) { |
| 1188 isolate->OptionalRescheduleException(false); |
| 1189 return; |
| 1190 } |
| 1191 info.GetReturnValue().Set(Utils::ToLocal(result)); |
| 1192 } |
| 1193 |
| 1194 Handle<AccessorInfo> Accessors::BoundFunctionNameInfo( |
| 1195 Isolate* isolate, PropertyAttributes attributes) { |
| 1196 return MakeAccessor(isolate, isolate->factory()->name_string(), |
| 1197 &BoundFunctionNameGetter, |
| 1198 &ObservedReconfigureToDataProperty, attributes); |
| 1199 } |
| 1200 |
| 1201 // |
| 1157 // Accessors::MakeModuleExport | 1202 // Accessors::MakeModuleExport |
| 1158 // | 1203 // |
| 1159 | 1204 |
| 1160 static void ModuleGetExport(v8::Local<v8::Name> property, | 1205 static void ModuleGetExport(v8::Local<v8::Name> property, |
| 1161 const v8::PropertyCallbackInfo<v8::Value>& info) { | 1206 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1162 JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder())); | 1207 JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder())); |
| 1163 Context* context = Context::cast(instance->context()); | 1208 Context* context = Context::cast(instance->context()); |
| 1164 DCHECK(context->IsModuleContext()); | 1209 DCHECK(context->IsModuleContext()); |
| 1165 Isolate* isolate = instance->GetIsolate(); | 1210 Isolate* isolate = instance->GetIsolate(); |
| 1166 int slot = info.Data() | 1211 int slot = info.Data() |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1206 Isolate* isolate = name->GetIsolate(); | 1251 Isolate* isolate = name->GetIsolate(); |
| 1207 Handle<AccessorInfo> info = MakeAccessor(isolate, name, &ModuleGetExport, | 1252 Handle<AccessorInfo> info = MakeAccessor(isolate, name, &ModuleGetExport, |
| 1208 &ModuleSetExport, attributes); | 1253 &ModuleSetExport, attributes); |
| 1209 info->set_data(Smi::FromInt(index)); | 1254 info->set_data(Smi::FromInt(index)); |
| 1210 return info; | 1255 return info; |
| 1211 } | 1256 } |
| 1212 | 1257 |
| 1213 | 1258 |
| 1214 } // namespace internal | 1259 } // namespace internal |
| 1215 } // namespace v8 | 1260 } // namespace v8 |
| OLD | NEW |