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

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

Issue 23633002: Implementation for ClosureMirror.findInContext. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Aaaaaaaaaand one more round of comments Created 7 years, 2 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/vm/bootstrap_natives.h ('k') | runtime/vm/object.h » ('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) 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 "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 3098 matching lines...) Expand 10 before | Expand all | Expand 10 after
3109 if (!obj.IsNull() && !obj.IsInstance()) { 3109 if (!obj.IsNull() && !obj.IsInstance()) {
3110 RETURN_TYPE_ERROR(isolate, arguments[i], Instance); 3110 RETURN_TYPE_ERROR(isolate, arguments[i], Instance);
3111 } 3111 }
3112 args.SetAt(i + 1, obj); 3112 args.SetAt(i + 1, obj);
3113 } 3113 }
3114 // Now try to invoke the closure. 3114 // Now try to invoke the closure.
3115 return Api::NewHandle(isolate, DartEntry::InvokeClosure(args)); 3115 return Api::NewHandle(isolate, DartEntry::InvokeClosure(args));
3116 } 3116 }
3117 3117
3118 3118
3119 static bool FieldIsUninitialized(Isolate* isolate, const Field& fld) {
3120 ASSERT(!fld.IsNull());
3121
3122 // Return getter method for uninitialized fields, rather than the
3123 // field object, since the value in the field object will not be
3124 // initialized until the first time the getter is invoked.
3125 const Instance& value = Instance::Handle(isolate, fld.value());
3126 ASSERT(value.raw() != Object::transition_sentinel().raw());
3127 return value.raw() == Object::sentinel().raw();
3128 }
3129
3130
3131 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { 3119 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) {
3132 Isolate* isolate = Isolate::Current(); 3120 Isolate* isolate = Isolate::Current();
3133 DARTSCOPE(isolate); 3121 DARTSCOPE(isolate);
3134 CHECK_CALLBACK_STATE(isolate); 3122 CHECK_CALLBACK_STATE(isolate);
3135 3123
3136 const String& field_name = Api::UnwrapStringHandle(isolate, name); 3124 const String& field_name = Api::UnwrapStringHandle(isolate, name);
3137 if (field_name.IsNull()) { 3125 if (field_name.IsNull()) {
3138 RETURN_TYPE_ERROR(isolate, name, String); 3126 RETURN_TYPE_ERROR(isolate, name, String);
3139 } 3127 }
3140 3128
3141 // Finalize all classes. 3129 // Finalize all classes.
3142 Dart_Handle state = Api::CheckIsolateState(isolate); 3130 Dart_Handle state = Api::CheckIsolateState(isolate);
3143 if (::Dart_IsError(state)) { 3131 if (::Dart_IsError(state)) {
3144 return state; 3132 return state;
3145 } 3133 }
3146 3134
3147 Field& field = Field::Handle(isolate); 3135 Field& field = Field::Handle(isolate);
3148 Function& getter = Function::Handle(isolate); 3136 Function& getter = Function::Handle(isolate);
3149 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); 3137 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container));
3150 if (obj.IsNull()) { 3138 if (obj.IsNull()) {
3151 return Api::NewError("%s expects argument 'container' to be non-null.", 3139 return Api::NewError("%s expects argument 'container' to be non-null.",
3152 CURRENT_FUNC); 3140 CURRENT_FUNC);
3153 } else if (obj.IsType()) { 3141 } else if (obj.IsType()) {
3154 // To access a static field we may need to use the Field or the 3142 // To access a static field we may need to use the Field or the
3155 // getter Function. 3143 // getter Function.
3156 Class& cls = Class::Handle(isolate, Type::Cast(obj).type_class()); 3144 Class& cls = Class::Handle(isolate, Type::Cast(obj).type_class());
3157 3145
3158 field = cls.LookupStaticField(field_name); 3146 field = cls.LookupStaticField(field_name);
3159 if (field.IsNull() || FieldIsUninitialized(isolate, field)) { 3147 if (field.IsNull() || field.IsUninitialized()) {
3160 const String& getter_name = 3148 const String& getter_name =
3161 String::Handle(isolate, Field::GetterName(field_name)); 3149 String::Handle(isolate, Field::GetterName(field_name));
3162 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); 3150 getter = cls.LookupStaticFunctionAllowPrivate(getter_name);
3163 } 3151 }
3164 3152
3165 if (!getter.IsNull()) { 3153 if (!getter.IsNull()) {
3166 // Invoke the getter and return the result. 3154 // Invoke the getter and return the result.
3167 return Api::NewHandle( 3155 return Api::NewHandle(
3168 isolate, DartEntry::InvokeFunction(getter, Object::empty_array())); 3156 isolate, DartEntry::InvokeFunction(getter, Object::empty_array()));
3169 } else if (!field.IsNull()) { 3157 } else if (!field.IsNull()) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3208 // To access a top-level we may need to use the Field or the 3196 // To access a top-level we may need to use the Field or the
3209 // getter Function. The getter function may either be in the 3197 // getter Function. The getter function may either be in the
3210 // library or in the field's owner class, depending. 3198 // library or in the field's owner class, depending.
3211 const Library& lib = Library::Cast(obj); 3199 const Library& lib = Library::Cast(obj);
3212 field = lib.LookupFieldAllowPrivate(field_name); 3200 field = lib.LookupFieldAllowPrivate(field_name);
3213 if (field.IsNull()) { 3201 if (field.IsNull()) {
3214 // No field found and no ambiguity error. Check for a getter in the lib. 3202 // No field found and no ambiguity error. Check for a getter in the lib.
3215 const String& getter_name = 3203 const String& getter_name =
3216 String::Handle(isolate, Field::GetterName(field_name)); 3204 String::Handle(isolate, Field::GetterName(field_name));
3217 getter = lib.LookupFunctionAllowPrivate(getter_name); 3205 getter = lib.LookupFunctionAllowPrivate(getter_name);
3218 } else if (!field.IsNull() && FieldIsUninitialized(isolate, field)) { 3206 } else if (!field.IsNull() && field.IsUninitialized()) {
3219 // A field was found. Check for a getter in the field's owner classs. 3207 // A field was found. Check for a getter in the field's owner classs.
3220 const Class& cls = Class::Handle(isolate, field.owner()); 3208 const Class& cls = Class::Handle(isolate, field.owner());
3221 const String& getter_name = 3209 const String& getter_name =
3222 String::Handle(isolate, Field::GetterName(field_name)); 3210 String::Handle(isolate, Field::GetterName(field_name));
3223 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); 3211 getter = cls.LookupStaticFunctionAllowPrivate(getter_name);
3224 } 3212 }
3225 3213
3226 if (!getter.IsNull()) { 3214 if (!getter.IsNull()) {
3227 // Invoke the getter and return the result. 3215 // Invoke the getter and return the result.
3228 return Api::NewHandle( 3216 return Api::NewHandle(
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after
4296 } 4284 }
4297 { 4285 {
4298 NoGCScope no_gc; 4286 NoGCScope no_gc;
4299 RawObject* raw_obj = obj.raw(); 4287 RawObject* raw_obj = obj.raw();
4300 isolate->heap()->SetPeer(raw_obj, peer); 4288 isolate->heap()->SetPeer(raw_obj, peer);
4301 } 4289 }
4302 return Api::Success(); 4290 return Api::Success();
4303 } 4291 }
4304 4292
4305 } // namespace dart 4293 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/bootstrap_natives.h ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698