Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
| 7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
| 8 | 8 |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "lib/stacktrace.h" | 10 #include "lib/stacktrace.h" |
| (...skipping 4101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4112 function_name, | 4112 function_name, |
| 4113 number_of_arguments, | 4113 number_of_arguments, |
| 4114 Object::empty_array())); | 4114 Object::empty_array())); |
| 4115 if (function.IsNull()) { | 4115 if (function.IsNull()) { |
| 4116 const String& cls_name = String::Handle(Z, cls.Name()); | 4116 const String& cls_name = String::Handle(Z, cls.Name()); |
| 4117 return Api::NewError("%s: did not find static method '%s.%s'.", | 4117 return Api::NewError("%s: did not find static method '%s.%s'.", |
| 4118 CURRENT_FUNC, | 4118 CURRENT_FUNC, |
| 4119 cls_name.ToCString(), | 4119 cls_name.ToCString(), |
| 4120 function_name.ToCString()); | 4120 function_name.ToCString()); |
| 4121 } | 4121 } |
| 4122 NOT_IN_PRODUCT(if (tds.enabled()) { | |
| 4123 const String& cls_name = String::Handle(Z, cls.Name()); | |
| 4124 tds.SetNumArguments(1); | |
| 4125 tds.FormatArgument(0, | |
| 4126 "name", | |
| 4127 "%s.%s", | |
| 4128 cls_name.ToCString(), | |
| 4129 function_name.ToCString()); | |
| 4130 }); | |
| 4122 // Setup args and check for malformed arguments in the arguments list. | 4131 // Setup args and check for malformed arguments in the arguments list. |
| 4123 result = SetupArguments(T, number_of_arguments, arguments, 0, &args); | 4132 result = SetupArguments(T, number_of_arguments, arguments, 0, &args); |
| 4124 if (!::Dart_IsError(result)) { | 4133 if (!::Dart_IsError(result)) { |
| 4125 result = Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); | 4134 result = Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); |
| 4126 } | 4135 } |
| 4127 return result; | 4136 return result; |
| 4128 } else if (obj.IsNull() || obj.IsInstance()) { | 4137 } else if (obj.IsNull() || obj.IsInstance()) { |
| 4129 // Since we have allocated an object it would mean that the type of the | 4138 // Since we have allocated an object it would mean that the type of the |
| 4130 // receiver is already resolved and finalized, hence it is not necessary | 4139 // receiver is already resolved and finalized, hence it is not necessary |
| 4131 // to check here. | 4140 // to check here. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 4147 const Array& args_descriptor = | 4156 const Array& args_descriptor = |
| 4148 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); | 4157 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); |
| 4149 result = Api::NewHandle(T, | 4158 result = Api::NewHandle(T, |
| 4150 DartEntry::InvokeNoSuchMethod(instance, | 4159 DartEntry::InvokeNoSuchMethod(instance, |
| 4151 function_name, | 4160 function_name, |
| 4152 args, | 4161 args, |
| 4153 args_descriptor)); | 4162 args_descriptor)); |
| 4154 } | 4163 } |
| 4155 return result; | 4164 return result; |
| 4156 } | 4165 } |
| 4166 NOT_IN_PRODUCT(if (tds.enabled()) { | |
| 4167 const Class& cls = Class::Handle(Z, instance.clazz()); | |
| 4168 ASSERT(!cls.IsNull()); | |
| 4169 const String& cls_name = String::Handle(Z, cls.Name()); | |
| 4170 tds.SetNumArguments(1); | |
| 4171 tds.FormatArgument(0, | |
| 4172 "name", | |
| 4173 "%s.%s", | |
| 4174 cls_name.ToCString(), | |
| 4175 function_name.ToCString()); | |
| 4176 }); | |
| 4157 // Setup args and check for malformed arguments in the arguments list. | 4177 // Setup args and check for malformed arguments in the arguments list. |
| 4158 result = SetupArguments(T, number_of_arguments, arguments, 1, &args); | 4178 result = SetupArguments(T, number_of_arguments, arguments, 1, &args); |
| 4159 if (!::Dart_IsError(result)) { | 4179 if (!::Dart_IsError(result)) { |
| 4160 args.SetAt(0, instance); | 4180 args.SetAt(0, instance); |
| 4161 result = Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); | 4181 result = Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); |
| 4162 } | 4182 } |
| 4163 return result; | 4183 return result; |
| 4164 } else if (obj.IsLibrary()) { | 4184 } else if (obj.IsLibrary()) { |
| 4165 // Check whether class finalization is needed. | 4185 // Check whether class finalization is needed. |
| 4166 const Library& lib = Library::Cast(obj); | 4186 const Library& lib = Library::Cast(obj); |
| 4167 | 4187 |
| 4168 // Check that the library is loaded. | 4188 // Check that the library is loaded. |
| 4169 if (!lib.Loaded()) { | 4189 if (!lib.Loaded()) { |
| 4170 return Api::NewError( | 4190 return Api::NewError( |
| 4171 "%s expects library argument 'target' to be loaded.", | 4191 "%s expects library argument 'target' to be loaded.", |
| 4172 CURRENT_FUNC); | 4192 CURRENT_FUNC); |
| 4173 } | 4193 } |
| 4174 | 4194 |
| 4175 const Function& function = | 4195 const Function& function = |
| 4176 Function::Handle(Z, lib.LookupFunctionAllowPrivate(function_name)); | 4196 Function::Handle(Z, lib.LookupFunctionAllowPrivate(function_name)); |
| 4177 if (function.IsNull()) { | 4197 if (function.IsNull()) { |
| 4178 return Api::NewError("%s: did not find top-level function '%s'.", | 4198 return Api::NewError("%s: did not find top-level function '%s'.", |
| 4179 CURRENT_FUNC, | 4199 CURRENT_FUNC, |
| 4180 function_name.ToCString()); | 4200 function_name.ToCString()); |
| 4181 } | 4201 } |
| 4202 | |
| 4203 NOT_IN_PRODUCT(if (tds.enabled()) { | |
| 4204 const String& lib_name = String::Handle(Z, lib.name()); | |
|
rmacnak
2016/05/05 23:30:54
This is often the empty string, consider lib.uri i
Cutch
2016/05/05 23:50:03
Done.
| |
| 4205 tds.SetNumArguments(1); | |
| 4206 tds.FormatArgument(0, | |
| 4207 "name", | |
| 4208 "%s.%s", | |
| 4209 lib_name.ToCString(), | |
| 4210 function_name.ToCString()); | |
| 4211 }); | |
| 4212 | |
| 4182 // LookupFunctionAllowPrivate does not check argument arity, so we | 4213 // LookupFunctionAllowPrivate does not check argument arity, so we |
| 4183 // do it here. | 4214 // do it here. |
| 4184 String& error_message = String::Handle(Z); | 4215 String& error_message = String::Handle(Z); |
| 4185 if (!function.AreValidArgumentCounts(number_of_arguments, | 4216 if (!function.AreValidArgumentCounts(number_of_arguments, |
| 4186 0, | 4217 0, |
| 4187 &error_message)) { | 4218 &error_message)) { |
| 4188 return Api::NewError("%s: wrong argument count for function '%s': %s.", | 4219 return Api::NewError("%s: wrong argument count for function '%s': %s.", |
| 4189 CURRENT_FUNC, | 4220 CURRENT_FUNC, |
| 4190 function_name.ToCString(), | 4221 function_name.ToCString(), |
| 4191 error_message.ToCString()); | 4222 error_message.ToCString()); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4262 // getter Function. | 4293 // getter Function. |
| 4263 Class& cls = Class::Handle(Z, Type::Cast(obj).type_class()); | 4294 Class& cls = Class::Handle(Z, Type::Cast(obj).type_class()); |
| 4264 | 4295 |
| 4265 field = cls.LookupStaticFieldAllowPrivate(field_name); | 4296 field = cls.LookupStaticFieldAllowPrivate(field_name); |
| 4266 if (field.IsNull() || field.IsUninitialized()) { | 4297 if (field.IsNull() || field.IsUninitialized()) { |
| 4267 const String& getter_name = | 4298 const String& getter_name = |
| 4268 String::Handle(Z, Field::GetterName(field_name)); | 4299 String::Handle(Z, Field::GetterName(field_name)); |
| 4269 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); | 4300 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); |
| 4270 } | 4301 } |
| 4271 | 4302 |
| 4303 NOT_IN_PRODUCT(if (tds.enabled()) { | |
| 4304 const String& cls_name = String::Handle(cls.Name()); | |
| 4305 tds.SetNumArguments(1); | |
| 4306 tds.FormatArgument(0, | |
| 4307 "name", | |
| 4308 "%s.%s", | |
| 4309 cls_name.ToCString(), field_name.ToCString()); | |
| 4310 }); | |
| 4311 | |
| 4272 if (!getter.IsNull()) { | 4312 if (!getter.IsNull()) { |
| 4273 // Invoke the getter and return the result. | 4313 // Invoke the getter and return the result. |
| 4274 return Api::NewHandle( | 4314 return Api::NewHandle( |
| 4275 T, DartEntry::InvokeFunction(getter, Object::empty_array())); | 4315 T, DartEntry::InvokeFunction(getter, Object::empty_array())); |
| 4276 } else if (!field.IsNull()) { | 4316 } else if (!field.IsNull()) { |
| 4277 return Api::NewHandle(T, field.StaticValue()); | 4317 return Api::NewHandle(T, field.StaticValue()); |
| 4278 } else { | 4318 } else { |
| 4279 return Api::NewError("%s: did not find static field '%s'.", | 4319 return Api::NewError("%s: did not find static field '%s'.", |
| 4280 CURRENT_FUNC, field_name.ToCString()); | 4320 CURRENT_FUNC, field_name.ToCString()); |
| 4281 } | 4321 } |
| 4282 | 4322 |
| 4283 } else if (obj.IsInstance()) { | 4323 } else if (obj.IsInstance()) { |
| 4284 // Every instance field has a getter Function. Try to find the | 4324 // Every instance field has a getter Function. Try to find the |
| 4285 // getter in any superclass and use that function to access the | 4325 // getter in any superclass and use that function to access the |
| 4286 // field. | 4326 // field. |
| 4287 const Instance& instance = Instance::Cast(obj); | 4327 const Instance& instance = Instance::Cast(obj); |
| 4288 Class& cls = Class::Handle(Z, instance.clazz()); | 4328 Class& cls = Class::Handle(Z, instance.clazz()); |
| 4289 String& getter_name = String::Handle(Z, Field::GetterName(field_name)); | 4329 String& getter_name = String::Handle(Z, Field::GetterName(field_name)); |
| 4290 while (!cls.IsNull()) { | 4330 while (!cls.IsNull()) { |
| 4291 getter = cls.LookupDynamicFunctionAllowPrivate(getter_name); | 4331 getter = cls.LookupDynamicFunctionAllowPrivate(getter_name); |
| 4292 if (!getter.IsNull()) { | 4332 if (!getter.IsNull()) { |
| 4293 break; | 4333 break; |
| 4294 } | 4334 } |
| 4295 cls = cls.SuperClass(); | 4335 cls = cls.SuperClass(); |
| 4296 } | 4336 } |
| 4297 | 4337 |
| 4338 NOT_IN_PRODUCT(if (tds.enabled()) { | |
| 4339 const String& cls_name = String::Handle(cls.Name()); | |
| 4340 tds.SetNumArguments(1); | |
| 4341 tds.FormatArgument(0, | |
| 4342 "name", | |
| 4343 "%s.%s", | |
| 4344 cls_name.ToCString(), field_name.ToCString()); | |
| 4345 }); | |
| 4346 | |
| 4298 // Invoke the getter and return the result. | 4347 // Invoke the getter and return the result. |
| 4299 const int kNumArgs = 1; | 4348 const int kNumArgs = 1; |
| 4300 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); | 4349 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
| 4301 args.SetAt(0, instance); | 4350 args.SetAt(0, instance); |
| 4302 if (getter.IsNull()) { | 4351 if (getter.IsNull()) { |
| 4303 const Array& args_descriptor = | 4352 const Array& args_descriptor = |
| 4304 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); | 4353 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); |
| 4305 return Api::NewHandle(T, DartEntry::InvokeNoSuchMethod(instance, | 4354 return Api::NewHandle(T, DartEntry::InvokeNoSuchMethod(instance, |
| 4306 getter_name, | 4355 getter_name, |
| 4307 args, | 4356 args, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 4327 String::Handle(Z, Field::GetterName(field_name)); | 4376 String::Handle(Z, Field::GetterName(field_name)); |
| 4328 getter = lib.LookupFunctionAllowPrivate(getter_name); | 4377 getter = lib.LookupFunctionAllowPrivate(getter_name); |
| 4329 } else if (!field.IsNull() && field.IsUninitialized()) { | 4378 } else if (!field.IsNull() && field.IsUninitialized()) { |
| 4330 // A field was found. Check for a getter in the field's owner classs. | 4379 // A field was found. Check for a getter in the field's owner classs. |
| 4331 const Class& cls = Class::Handle(Z, field.Owner()); | 4380 const Class& cls = Class::Handle(Z, field.Owner()); |
| 4332 const String& getter_name = String::Handle(Z, | 4381 const String& getter_name = String::Handle(Z, |
| 4333 Field::GetterName(field_name)); | 4382 Field::GetterName(field_name)); |
| 4334 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); | 4383 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); |
| 4335 } | 4384 } |
| 4336 | 4385 |
| 4386 NOT_IN_PRODUCT(if (tds.enabled()) { | |
| 4387 const String& lib_name = String::Handle(lib.name()); | |
|
rmacnak
2016/05/05 23:30:54
This is often the empty string, consider lib.uri i
Cutch
2016/05/05 23:50:04
Done.
| |
| 4388 tds.SetNumArguments(1); | |
| 4389 tds.FormatArgument(0, | |
| 4390 "name", | |
| 4391 "%s.%s", | |
| 4392 lib_name.ToCString(), field_name.ToCString()); | |
| 4393 }); | |
| 4394 | |
| 4337 if (!getter.IsNull()) { | 4395 if (!getter.IsNull()) { |
| 4338 // Invoke the getter and return the result. | 4396 // Invoke the getter and return the result. |
| 4339 return Api::NewHandle( | 4397 return Api::NewHandle( |
| 4340 T, DartEntry::InvokeFunction(getter, Object::empty_array())); | 4398 T, DartEntry::InvokeFunction(getter, Object::empty_array())); |
| 4341 } | 4399 } |
| 4342 if (!field.IsNull()) { | 4400 if (!field.IsNull()) { |
| 4343 return Api::NewHandle(T, field.StaticValue()); | 4401 return Api::NewHandle(T, field.StaticValue()); |
| 4344 } | 4402 } |
| 4345 return Api::NewError("%s: did not find top-level variable '%s'.", | 4403 return Api::NewError("%s: did not find top-level variable '%s'.", |
| 4346 CURRENT_FUNC, field_name.ToCString()); | 4404 CURRENT_FUNC, field_name.ToCString()); |
| (...skipping 1956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6303 | 6361 |
| 6304 DART_EXPORT bool Dart_IsPrecompiledRuntime() { | 6362 DART_EXPORT bool Dart_IsPrecompiledRuntime() { |
| 6305 #if defined(DART_PRECOMPILED_RUNTIME) | 6363 #if defined(DART_PRECOMPILED_RUNTIME) |
| 6306 return true; | 6364 return true; |
| 6307 #else | 6365 #else |
| 6308 return false; | 6366 return false; |
| 6309 #endif | 6367 #endif |
| 6310 } | 6368 } |
| 6311 | 6369 |
| 6312 } // namespace dart | 6370 } // namespace dart |
| OLD | NEW |