OLD | NEW |
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 2716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2727 Function& func = Function::Handle(); | 2727 Function& func = Function::Handle(); |
2728 String& name = String::Handle(); | 2728 String& name = String::Handle(); |
2729 | 2729 |
2730 if (obj.IsClass()) { | 2730 if (obj.IsClass()) { |
2731 const Class& cls = Class::Cast(obj); | 2731 const Class& cls = Class::Cast(obj); |
2732 const Array& func_array = Array::Handle(cls.functions()); | 2732 const Array& func_array = Array::Handle(cls.functions()); |
2733 | 2733 |
2734 // Some special types like 'dynamic' have a null functions list. | 2734 // Some special types like 'dynamic' have a null functions list. |
2735 if (!func_array.IsNull()) { | 2735 if (!func_array.IsNull()) { |
2736 for (intptr_t i = 0; i < func_array.Length(); ++i) { | 2736 for (intptr_t i = 0; i < func_array.Length(); ++i) { |
2737 func ^= func_array.At(i); | 2737 func |= func_array.At(i); |
2738 | 2738 |
2739 // Skip implicit getters and setters. | 2739 // Skip implicit getters and setters. |
2740 if (func.kind() == RawFunction::kImplicitGetter || | 2740 if (func.kind() == RawFunction::kImplicitGetter || |
2741 func.kind() == RawFunction::kImplicitSetter || | 2741 func.kind() == RawFunction::kImplicitSetter || |
2742 func.kind() == RawFunction::kConstImplicitGetter || | 2742 func.kind() == RawFunction::kConstImplicitGetter || |
2743 func.kind() == RawFunction::kMethodExtractor) { | 2743 func.kind() == RawFunction::kMethodExtractor) { |
2744 continue; | 2744 continue; |
2745 } | 2745 } |
2746 | 2746 |
2747 name = func.UserVisibleName(); | 2747 name = func.UserVisibleName(); |
2748 names.Add(name); | 2748 names.Add(name); |
2749 } | 2749 } |
2750 } | 2750 } |
2751 } else if (obj.IsLibrary()) { | 2751 } else if (obj.IsLibrary()) { |
2752 const Library& lib = Library::Cast(obj); | 2752 const Library& lib = Library::Cast(obj); |
2753 DictionaryIterator it(lib); | 2753 DictionaryIterator it(lib); |
2754 Object& obj = Object::Handle(); | 2754 Object& obj = Object::Handle(); |
2755 while (it.HasNext()) { | 2755 while (it.HasNext()) { |
2756 obj = it.GetNext(); | 2756 obj = it.GetNext(); |
2757 if (obj.IsFunction()) { | 2757 if (obj.IsFunction()) { |
2758 func ^= obj.raw(); | 2758 func |= obj.raw(); |
2759 name = func.UserVisibleName(); | 2759 name = func.UserVisibleName(); |
2760 names.Add(name); | 2760 names.Add(name); |
2761 } | 2761 } |
2762 } | 2762 } |
2763 } else { | 2763 } else { |
2764 return Api::NewError( | 2764 return Api::NewError( |
2765 "%s expects argument 'target' to be a class or library.", | 2765 "%s expects argument 'target' to be a class or library.", |
2766 CURRENT_FUNC); | 2766 CURRENT_FUNC); |
2767 } | 2767 } |
2768 return Api::NewHandle(isolate, Array::MakeArray(names)); | 2768 return Api::NewHandle(isolate, Array::MakeArray(names)); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3071 const Class& cls = Class::Cast(obj); | 3071 const Class& cls = Class::Cast(obj); |
3072 const Array& field_array = Array::Handle(cls.fields()); | 3072 const Array& field_array = Array::Handle(cls.fields()); |
3073 | 3073 |
3074 // Some special types like 'dynamic' have a null fields list. | 3074 // Some special types like 'dynamic' have a null fields list. |
3075 // | 3075 // |
3076 // TODO(turnidge): Fix 'dynamic' so that it does not have a null | 3076 // TODO(turnidge): Fix 'dynamic' so that it does not have a null |
3077 // fields list. This will have to wait until the empty array is | 3077 // fields list. This will have to wait until the empty array is |
3078 // allocated in the vm isolate. | 3078 // allocated in the vm isolate. |
3079 if (!field_array.IsNull()) { | 3079 if (!field_array.IsNull()) { |
3080 for (intptr_t i = 0; i < field_array.Length(); ++i) { | 3080 for (intptr_t i = 0; i < field_array.Length(); ++i) { |
3081 field ^= field_array.At(i); | 3081 field |= field_array.At(i); |
3082 name = field.UserVisibleName(); | 3082 name = field.UserVisibleName(); |
3083 names.Add(name); | 3083 names.Add(name); |
3084 } | 3084 } |
3085 } | 3085 } |
3086 } else if (obj.IsLibrary()) { | 3086 } else if (obj.IsLibrary()) { |
3087 const Library& lib = Library::Cast(obj); | 3087 const Library& lib = Library::Cast(obj); |
3088 DictionaryIterator it(lib); | 3088 DictionaryIterator it(lib); |
3089 Object& obj = Object::Handle(isolate); | 3089 Object& obj = Object::Handle(isolate); |
3090 while (it.HasNext()) { | 3090 while (it.HasNext()) { |
3091 obj = it.GetNext(); | 3091 obj = it.GetNext(); |
3092 if (obj.IsField()) { | 3092 if (obj.IsField()) { |
3093 field ^= obj.raw(); | 3093 field |= obj.raw(); |
3094 name = field.UserVisibleName(); | 3094 name = field.UserVisibleName(); |
3095 names.Add(name); | 3095 names.Add(name); |
3096 } | 3096 } |
3097 } | 3097 } |
3098 } else { | 3098 } else { |
3099 return Api::NewError( | 3099 return Api::NewError( |
3100 "%s expects argument 'target' to be a class or library.", | 3100 "%s expects argument 'target' to be a class or library.", |
3101 CURRENT_FUNC); | 3101 CURRENT_FUNC); |
3102 } | 3102 } |
3103 return Api::NewHandle(isolate, Array::MakeArray(names)); | 3103 return Api::NewHandle(isolate, Array::MakeArray(names)); |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3386 | 3386 |
3387 // Resolve the constructor. | 3387 // Resolve the constructor. |
3388 result = ResolveConstructor( | 3388 result = ResolveConstructor( |
3389 "Dart_New", cls, base_constructor_name, dot_name, number_of_arguments); | 3389 "Dart_New", cls, base_constructor_name, dot_name, number_of_arguments); |
3390 if (result.IsError()) { | 3390 if (result.IsError()) { |
3391 return Api::NewHandle(isolate, result.raw()); | 3391 return Api::NewHandle(isolate, result.raw()); |
3392 } | 3392 } |
3393 // TODO(turnidge): Support redirecting factories. | 3393 // TODO(turnidge): Support redirecting factories. |
3394 ASSERT(result.IsFunction()); | 3394 ASSERT(result.IsFunction()); |
3395 Function& constructor = Function::Handle(isolate); | 3395 Function& constructor = Function::Handle(isolate); |
3396 constructor ^= result.raw(); | 3396 constructor |= result.raw(); |
3397 | 3397 |
3398 Instance& new_object = Instance::Handle(isolate); | 3398 Instance& new_object = Instance::Handle(isolate); |
3399 if (constructor.IsConstructor()) { | 3399 if (constructor.IsConstructor()) { |
3400 // Create the new object. | 3400 // Create the new object. |
3401 new_object = Instance::New(cls); | 3401 new_object = Instance::New(cls); |
3402 } | 3402 } |
3403 | 3403 |
3404 // Create the argument list. | 3404 // Create the argument list. |
3405 intptr_t arg_index = 0; | 3405 intptr_t arg_index = 0; |
3406 int extra_args = (constructor.IsConstructor() ? 2 : 1); | 3406 int extra_args = (constructor.IsConstructor() ? 2 : 1); |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3799 | 3799 |
3800 } else if (obj.IsLibrary()) { | 3800 } else if (obj.IsLibrary()) { |
3801 // To access a top-level we may need to use the Field or the | 3801 // To access a top-level we may need to use the Field or the |
3802 // setter Function. The setter function may either be in the | 3802 // setter Function. The setter function may either be in the |
3803 // library or in the field's owner class, depending. | 3803 // library or in the field's owner class, depending. |
3804 const Library& lib = Library::Cast(obj); | 3804 const Library& lib = Library::Cast(obj); |
3805 field = lib.LookupFieldAllowPrivate(field_name); | 3805 field = lib.LookupFieldAllowPrivate(field_name); |
3806 if (field.IsNull()) { | 3806 if (field.IsNull()) { |
3807 const String& setter_name = | 3807 const String& setter_name = |
3808 String::Handle(isolate, Field::SetterName(field_name)); | 3808 String::Handle(isolate, Field::SetterName(field_name)); |
3809 setter ^= lib.LookupFunctionAllowPrivate(setter_name); | 3809 setter |= lib.LookupFunctionAllowPrivate(setter_name); |
3810 } | 3810 } |
3811 | 3811 |
3812 if (!setter.IsNull()) { | 3812 if (!setter.IsNull()) { |
3813 // Invoke the setter and return the result. | 3813 // Invoke the setter and return the result. |
3814 const int kNumArgs = 1; | 3814 const int kNumArgs = 1; |
3815 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 3815 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
3816 args.SetAt(0, value_instance); | 3816 args.SetAt(0, value_instance); |
3817 const Object& result = | 3817 const Object& result = |
3818 Object::Handle(isolate, DartEntry::InvokeStatic(setter, args)); | 3818 Object::Handle(isolate, DartEntry::InvokeStatic(setter, args)); |
3819 if (result.IsError()) { | 3819 if (result.IsError()) { |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4173 } | 4173 } |
4174 SnapshotReader reader(snapshot->content(), | 4174 SnapshotReader reader(snapshot->content(), |
4175 snapshot->length(), | 4175 snapshot->length(), |
4176 snapshot->kind(), | 4176 snapshot->kind(), |
4177 isolate); | 4177 isolate); |
4178 const Object& tmp = Object::Handle(isolate, reader.ReadObject()); | 4178 const Object& tmp = Object::Handle(isolate, reader.ReadObject()); |
4179 if (!tmp.IsLibrary()) { | 4179 if (!tmp.IsLibrary()) { |
4180 return Api::NewError("%s: Unable to deserialize snapshot correctly.", | 4180 return Api::NewError("%s: Unable to deserialize snapshot correctly.", |
4181 CURRENT_FUNC); | 4181 CURRENT_FUNC); |
4182 } | 4182 } |
4183 library ^= tmp.raw(); | 4183 library |= tmp.raw(); |
4184 library.set_debuggable(true); | 4184 library.set_debuggable(true); |
4185 isolate->object_store()->set_root_library(library); | 4185 isolate->object_store()->set_root_library(library); |
4186 return Api::NewHandle(isolate, library.raw()); | 4186 return Api::NewHandle(isolate, library.raw()); |
4187 } | 4187 } |
4188 | 4188 |
4189 | 4189 |
4190 DART_EXPORT Dart_Handle Dart_RootLibrary() { | 4190 DART_EXPORT Dart_Handle Dart_RootLibrary() { |
4191 Isolate* isolate = Isolate::Current(); | 4191 Isolate* isolate = Isolate::Current(); |
4192 DARTSCOPE(isolate); | 4192 DARTSCOPE(isolate); |
4193 Library& library = | 4193 Library& library = |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4524 } | 4524 } |
4525 { | 4525 { |
4526 NoGCScope no_gc; | 4526 NoGCScope no_gc; |
4527 RawObject* raw_obj = obj.raw(); | 4527 RawObject* raw_obj = obj.raw(); |
4528 isolate->heap()->SetPeer(raw_obj, peer); | 4528 isolate->heap()->SetPeer(raw_obj, peer); |
4529 } | 4529 } |
4530 return Api::Success(isolate); | 4530 return Api::Success(isolate); |
4531 } | 4531 } |
4532 | 4532 |
4533 } // namespace dart | 4533 } // namespace dart |
OLD | NEW |