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

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 11968022: Lookup functions by name that contains the private key, except for dart_api which allows ignoring t… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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 | « runtime/lib/isolate.cc ('k') | runtime/vm/dart_api_impl_test.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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 } 1097 }
1098 1098
1099 1099
1100 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { 1100 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) {
1101 Isolate* isolate = Isolate::Current(); 1101 Isolate* isolate = Isolate::Current();
1102 DARTSCOPE(isolate); 1102 DARTSCOPE(isolate);
1103 Library& isolate_lib = Library::Handle(isolate, Library::IsolateLibrary()); 1103 Library& isolate_lib = Library::Handle(isolate, Library::IsolateLibrary());
1104 ASSERT(!isolate_lib.IsNull()); 1104 ASSERT(!isolate_lib.IsNull());
1105 const String& class_name = String::Handle( 1105 const String& class_name = String::Handle(
1106 isolate, isolate_lib.PrivateName(Symbols::_ReceivePortImpl())); 1106 isolate, isolate_lib.PrivateName(Symbols::_ReceivePortImpl()));
1107 // TODO(asiva): Symbols should contain private keys.
1108 const String& function_name =
1109 String::Handle(isolate_lib.PrivateName(Symbols::_get_or_create()));
1107 const int kNumArguments = 1; 1110 const int kNumArguments = 1;
1108 const Function& function = Function::Handle( 1111 const Function& function = Function::Handle(
1109 isolate, 1112 isolate,
1110 Resolver::ResolveStatic(isolate_lib, 1113 Resolver::ResolveStatic(isolate_lib,
1111 class_name, 1114 class_name,
1112 Symbols::_get_or_create(), 1115 function_name,
1113 kNumArguments, 1116 kNumArguments,
1114 Object::empty_array(), 1117 Object::empty_array(),
1115 Resolver::kIsQualified)); 1118 Resolver::kIsQualified));
1119 ASSERT(!function.IsNull());
1116 const Array& args = Array::Handle(isolate, Array::New(kNumArguments)); 1120 const Array& args = Array::Handle(isolate, Array::New(kNumArguments));
1117 args.SetAt(0, Integer::Handle(isolate, Integer::New(port_id))); 1121 args.SetAt(0, Integer::Handle(isolate, Integer::New(port_id)));
1118 return Api::NewHandle(isolate, DartEntry::InvokeStatic(function, args)); 1122 return Api::NewHandle(isolate, DartEntry::InvokeStatic(function, args));
1119 } 1123 }
1120 1124
1121 1125
1122 DART_EXPORT Dart_Port Dart_GetMainPortId() { 1126 DART_EXPORT Dart_Port Dart_GetMainPortId() {
1123 Isolate* isolate = Isolate::Current(); 1127 Isolate* isolate = Isolate::Current();
1124 CHECK_ISOLATE(isolate); 1128 CHECK_ISOLATE(isolate);
1125 return isolate->main_port(); 1129 return isolate->main_port();
(...skipping 1650 matching lines...) Expand 10 before | Expand all | Expand 10 after
2776 if (func_name.IsNull()) { 2780 if (func_name.IsNull()) {
2777 RETURN_TYPE_ERROR(isolate, function_name, String); 2781 RETURN_TYPE_ERROR(isolate, function_name, String);
2778 } 2782 }
2779 2783
2780 Function& func = Function::Handle(isolate); 2784 Function& func = Function::Handle(isolate);
2781 String& tmp_name = String::Handle(isolate); 2785 String& tmp_name = String::Handle(isolate);
2782 if (obj.IsClass()) { 2786 if (obj.IsClass()) {
2783 const Class& cls = Class::Cast(obj); 2787 const Class& cls = Class::Cast(obj);
2784 2788
2785 // Case 1. Lookup the unmodified function name. 2789 // Case 1. Lookup the unmodified function name.
2786 func = cls.LookupFunction(func_name); 2790 func = cls.LookupFunctionAllowPrivate(func_name);
2787 2791
2788 // Case 2. Lookup the function without the external setter suffix 2792 // Case 2. Lookup the function without the external setter suffix
2789 // '='. Make sure to do this check after the regular lookup, so 2793 // '='. Make sure to do this check after the regular lookup, so
2790 // that we don't interfere with operator lookups (like ==). 2794 // that we don't interfere with operator lookups (like ==).
2791 if (func.IsNull() && HasExternalSetterSuffix(func_name)) { 2795 if (func.IsNull() && HasExternalSetterSuffix(func_name)) {
2792 tmp_name = RemoveExternalSetterSuffix(func_name); 2796 tmp_name = RemoveExternalSetterSuffix(func_name);
2793 tmp_name = Field::SetterName(tmp_name); 2797 tmp_name = Field::SetterName(tmp_name);
2794 func = cls.LookupFunction(tmp_name); 2798 func = cls.LookupFunctionAllowPrivate(tmp_name);
2795 } 2799 }
2796 2800
2797 // Case 3. Lookup the funciton with the getter prefix prepended. 2801 // Case 3. Lookup the funciton with the getter prefix prepended.
2798 if (func.IsNull()) { 2802 if (func.IsNull()) {
2799 tmp_name = Field::GetterName(func_name); 2803 tmp_name = Field::GetterName(func_name);
2800 func = cls.LookupFunction(tmp_name); 2804 func = cls.LookupFunctionAllowPrivate(tmp_name);
2801 } 2805 }
2802 2806
2803 // Case 4. Lookup the function with a . appended to find the 2807 // Case 4. Lookup the function with a . appended to find the
2804 // unnamed constructor. 2808 // unnamed constructor.
2805 if (func.IsNull()) { 2809 if (func.IsNull()) {
2806 tmp_name = String::Concat(func_name, Symbols::Dot()); 2810 tmp_name = String::Concat(func_name, Symbols::Dot());
2807 func = cls.LookupFunction(tmp_name); 2811 func = cls.LookupFunctionAllowPrivate(tmp_name);
2808 } 2812 }
2809 } else if (obj.IsLibrary()) { 2813 } else if (obj.IsLibrary()) {
2810 const Library& lib = Library::Cast(obj); 2814 const Library& lib = Library::Cast(obj);
2811 2815
2812 // Case 1. Lookup the unmodified function name. 2816 // Case 1. Lookup the unmodified function name.
2813 func = lib.LookupFunctionAllowPrivate(func_name); 2817 func = lib.LookupFunctionAllowPrivate(func_name);
2814 2818
2815 // Case 2. Lookup the function without the external setter suffix 2819 // Case 2. Lookup the function without the external setter suffix
2816 // '='. Make sure to do this check after the regular lookup, so 2820 // '='. Make sure to do this check after the regular lookup, so
2817 // that we don't interfere with operator lookups (like ==). 2821 // that we don't interfere with operator lookups (like ==).
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
3292 3296
3293 3297
3294 static RawObject* ResolveConstructor(const char* current_func, 3298 static RawObject* ResolveConstructor(const char* current_func,
3295 const Class& cls, 3299 const Class& cls,
3296 const String& class_name, 3300 const String& class_name,
3297 const String& dotted_name, 3301 const String& dotted_name,
3298 int num_args) { 3302 int num_args) {
3299 // The constructor must be present in the interface. 3303 // The constructor must be present in the interface.
3300 String& constr_name = String::Handle(String::Concat(class_name, dotted_name)); 3304 String& constr_name = String::Handle(String::Concat(class_name, dotted_name));
3301 const Function& constructor = 3305 const Function& constructor =
3302 Function::Handle(cls.LookupFunction(constr_name)); 3306 Function::Handle(cls.LookupFunctionAllowPrivate(constr_name));
3303 if (constructor.IsNull() || 3307 if (constructor.IsNull() ||
3304 (!constructor.IsConstructor() && !constructor.IsFactory())) { 3308 (!constructor.IsConstructor() && !constructor.IsFactory())) {
3305 const String& lookup_class_name = String::Handle(cls.Name()); 3309 const String& lookup_class_name = String::Handle(cls.Name());
3306 if (!class_name.Equals(lookup_class_name)) { 3310 if (!class_name.Equals(lookup_class_name)) {
3307 // When the class name used to build the constructor name is 3311 // When the class name used to build the constructor name is
3308 // different than the name of the class in which we are doing 3312 // different than the name of the class in which we are doing
3309 // the lookup, it can be confusing to the user to figure out 3313 // the lookup, it can be confusing to the user to figure out
3310 // what's going on. Be a little more explicit for these error 3314 // what's going on. Be a little more explicit for these error
3311 // messages. 3315 // messages.
3312 const String& message = String::Handle( 3316 const String& message = String::Handle(
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
3604 CURRENT_FUNC); 3608 CURRENT_FUNC);
3605 } else if (obj.IsInstance()) { 3609 } else if (obj.IsInstance()) {
3606 // Every instance field has a getter Function. Try to find the 3610 // Every instance field has a getter Function. Try to find the
3607 // getter in any superclass and use that function to access the 3611 // getter in any superclass and use that function to access the
3608 // field. 3612 // field.
3609 const Instance& instance = Instance::Cast(obj); 3613 const Instance& instance = Instance::Cast(obj);
3610 Class& cls = Class::Handle(isolate, instance.clazz()); 3614 Class& cls = Class::Handle(isolate, instance.clazz());
3611 while (!cls.IsNull()) { 3615 while (!cls.IsNull()) {
3612 String& getter_name = 3616 String& getter_name =
3613 String::Handle(isolate, Field::GetterName(field_name)); 3617 String::Handle(isolate, Field::GetterName(field_name));
3614 getter = cls.LookupDynamicFunction(getter_name); 3618 getter = cls.LookupDynamicFunctionAllowPrivate(getter_name);
3615 if (!getter.IsNull()) { 3619 if (!getter.IsNull()) {
3616 break; 3620 break;
3617 } 3621 }
3618 cls = cls.SuperClass(); 3622 cls = cls.SuperClass();
3619 } 3623 }
3620 3624
3621 if (getter.IsNull()) { 3625 if (getter.IsNull()) {
3622 return Api::NewError("%s: did not find instance field '%s'.", 3626 return Api::NewError("%s: did not find instance field '%s'.",
3623 CURRENT_FUNC, field_name.ToCString()); 3627 CURRENT_FUNC, field_name.ToCString());
3624 } 3628 }
(...skipping 10 matching lines...) Expand all
3635 if (msg != NULL) { 3639 if (msg != NULL) {
3636 return Api::NewError("%s", msg); 3640 return Api::NewError("%s", msg);
3637 } 3641 }
3638 // To access a static field we may need to use the Field or the 3642 // To access a static field we may need to use the Field or the
3639 // getter Function. 3643 // getter Function.
3640 const Class& cls = Class::Cast(obj); 3644 const Class& cls = Class::Cast(obj);
3641 field = cls.LookupStaticField(field_name); 3645 field = cls.LookupStaticField(field_name);
3642 if (field.IsNull() || FieldIsUninitialized(isolate, field)) { 3646 if (field.IsNull() || FieldIsUninitialized(isolate, field)) {
3643 const String& getter_name = 3647 const String& getter_name =
3644 String::Handle(isolate, Field::GetterName(field_name)); 3648 String::Handle(isolate, Field::GetterName(field_name));
3645 getter = cls.LookupStaticFunction(getter_name); 3649 getter = cls.LookupStaticFunctionAllowPrivate(getter_name);
3646 } 3650 }
3647 3651
3648 if (!getter.IsNull()) { 3652 if (!getter.IsNull()) {
3649 // Invoke the getter and return the result. 3653 // Invoke the getter and return the result.
3650 return Api::NewHandle( 3654 return Api::NewHandle(
3651 isolate, DartEntry::InvokeStatic(getter, Object::empty_array())); 3655 isolate, DartEntry::InvokeStatic(getter, Object::empty_array()));
3652 } else if (!field.IsNull()) { 3656 } else if (!field.IsNull()) {
3653 return Api::NewHandle(isolate, field.value()); 3657 return Api::NewHandle(isolate, field.value());
3654 } else { 3658 } else {
3655 return Api::NewError("%s: did not find static field '%s'.", 3659 return Api::NewError("%s: did not find static field '%s'.",
(...skipping 11 matching lines...) Expand all
3667 if (field.IsNull()) { 3671 if (field.IsNull()) {
3668 // No field found. Check for a getter in the lib. 3672 // No field found. Check for a getter in the lib.
3669 const String& getter_name = 3673 const String& getter_name =
3670 String::Handle(isolate, Field::GetterName(field_name)); 3674 String::Handle(isolate, Field::GetterName(field_name));
3671 getter = lib.LookupFunctionAllowPrivate(getter_name); 3675 getter = lib.LookupFunctionAllowPrivate(getter_name);
3672 } else if (FieldIsUninitialized(isolate, field)) { 3676 } else if (FieldIsUninitialized(isolate, field)) {
3673 // A field was found. Check for a getter in the field's owner classs. 3677 // A field was found. Check for a getter in the field's owner classs.
3674 const Class& cls = Class::Handle(isolate, field.owner()); 3678 const Class& cls = Class::Handle(isolate, field.owner());
3675 const String& getter_name = 3679 const String& getter_name =
3676 String::Handle(isolate, Field::GetterName(field_name)); 3680 String::Handle(isolate, Field::GetterName(field_name));
3677 getter = cls.LookupStaticFunction(getter_name); 3681 getter = cls.LookupStaticFunctionAllowPrivate(getter_name);
3678 } 3682 }
3679 3683
3680 if (!getter.IsNull()) { 3684 if (!getter.IsNull()) {
3681 // Invoke the getter and return the result. 3685 // Invoke the getter and return the result.
3682 return Api::NewHandle( 3686 return Api::NewHandle(
3683 isolate, DartEntry::InvokeStatic(getter, Object::empty_array())); 3687 isolate, DartEntry::InvokeStatic(getter, Object::empty_array()));
3684 } else if (!field.IsNull()) { 3688 } else if (!field.IsNull()) {
3685 return Api::NewHandle(isolate, field.value()); 3689 return Api::NewHandle(isolate, field.value());
3686 } else { 3690 } else {
3687 return Api::NewError("%s: did not find top-level variable '%s'.", 3691 return Api::NewError("%s: did not find top-level variable '%s'.",
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3730 const Instance& instance = Instance::Cast(obj); 3734 const Instance& instance = Instance::Cast(obj);
3731 Class& cls = Class::Handle(isolate, instance.clazz()); 3735 Class& cls = Class::Handle(isolate, instance.clazz());
3732 while (!cls.IsNull()) { 3736 while (!cls.IsNull()) {
3733 field = cls.LookupInstanceField(field_name); 3737 field = cls.LookupInstanceField(field_name);
3734 if (!field.IsNull() && field.is_final()) { 3738 if (!field.IsNull() && field.is_final()) {
3735 return Api::NewError("%s: cannot set final field '%s'.", 3739 return Api::NewError("%s: cannot set final field '%s'.",
3736 CURRENT_FUNC, field_name.ToCString()); 3740 CURRENT_FUNC, field_name.ToCString());
3737 } 3741 }
3738 String& setter_name = 3742 String& setter_name =
3739 String::Handle(isolate, Field::SetterName(field_name)); 3743 String::Handle(isolate, Field::SetterName(field_name));
3740 setter = cls.LookupDynamicFunction(setter_name); 3744 setter = cls.LookupDynamicFunctionAllowPrivate(setter_name);
3741 if (!setter.IsNull()) { 3745 if (!setter.IsNull()) {
3742 break; 3746 break;
3743 } 3747 }
3744 cls = cls.SuperClass(); 3748 cls = cls.SuperClass();
3745 } 3749 }
3746 3750
3747 if (setter.IsNull()) { 3751 if (setter.IsNull()) {
3748 return Api::NewError("%s: did not find instance field '%s'.", 3752 return Api::NewError("%s: did not find instance field '%s'.",
3749 CURRENT_FUNC, field_name.ToCString()); 3753 CURRENT_FUNC, field_name.ToCString());
3750 } 3754 }
3751 3755
3752 // Invoke the setter and return the result. 3756 // Invoke the setter and return the result.
3753 const int kNumArgs = 2; 3757 const int kNumArgs = 2;
3754 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); 3758 const Array& args = Array::Handle(isolate, Array::New(kNumArgs));
3755 args.SetAt(0, instance); 3759 args.SetAt(0, instance);
3756 args.SetAt(1, value_instance); 3760 args.SetAt(1, value_instance);
3757 return Api::NewHandle(isolate, DartEntry::InvokeDynamic(setter, args)); 3761 return Api::NewHandle(isolate, DartEntry::InvokeDynamic(setter, args));
3758 3762
3759 } else if (obj.IsClass()) { 3763 } else if (obj.IsClass()) {
3760 // To access a static field we may need to use the Field or the 3764 // To access a static field we may need to use the Field or the
3761 // setter Function. 3765 // setter Function.
3762 const Class& cls = Class::Cast(obj); 3766 const Class& cls = Class::Cast(obj);
3763 field = cls.LookupStaticField(field_name); 3767 field = cls.LookupStaticField(field_name);
3764 if (field.IsNull()) { 3768 if (field.IsNull()) {
3765 String& setter_name = 3769 String& setter_name =
3766 String::Handle(isolate, Field::SetterName(field_name)); 3770 String::Handle(isolate, Field::SetterName(field_name));
3767 setter = cls.LookupStaticFunction(setter_name); 3771 setter = cls.LookupStaticFunctionAllowPrivate(setter_name);
3768 } 3772 }
3769 3773
3770 if (!setter.IsNull()) { 3774 if (!setter.IsNull()) {
3771 // Invoke the setter and return the result. 3775 // Invoke the setter and return the result.
3772 const int kNumArgs = 1; 3776 const int kNumArgs = 1;
3773 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); 3777 const Array& args = Array::Handle(isolate, Array::New(kNumArgs));
3774 args.SetAt(0, value_instance); 3778 args.SetAt(0, value_instance);
3775 const Object& result = 3779 const Object& result =
3776 Object::Handle(isolate, DartEntry::InvokeStatic(setter, args)); 3780 Object::Handle(isolate, DartEntry::InvokeStatic(setter, args));
3777 if (result.IsError()) { 3781 if (result.IsError()) {
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
4519 } 4523 }
4520 { 4524 {
4521 NoGCScope no_gc; 4525 NoGCScope no_gc;
4522 RawObject* raw_obj = obj.raw(); 4526 RawObject* raw_obj = obj.raw();
4523 isolate->heap()->SetPeer(raw_obj, peer); 4527 isolate->heap()->SetPeer(raw_obj, peer);
4524 } 4528 }
4525 return Api::Success(isolate); 4529 return Api::Success(isolate);
4526 } 4530 }
4527 4531
4528 } // namespace dart 4532 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/isolate.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698