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 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 STOP_TIMER(time_total_runtime); | 692 STOP_TIMER(time_total_runtime); |
693 Dart::ShutdownIsolate(); | 693 Dart::ShutdownIsolate(); |
694 } | 694 } |
695 | 695 |
696 | 696 |
697 DART_EXPORT Dart_Isolate Dart_CurrentIsolate() { | 697 DART_EXPORT Dart_Isolate Dart_CurrentIsolate() { |
698 return Api::CastIsolate(Isolate::Current()); | 698 return Api::CastIsolate(Isolate::Current()); |
699 } | 699 } |
700 | 700 |
701 | 701 |
| 702 DART_EXPORT Dart_Handle Dart_DebugName() { |
| 703 Isolate* isolate = Isolate::Current(); |
| 704 CHECK_ISOLATE(isolate); |
| 705 return Api::NewHandle(isolate, String::New(isolate->name())); |
| 706 } |
| 707 |
| 708 |
| 709 |
702 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate dart_isolate) { | 710 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate dart_isolate) { |
703 CHECK_NO_ISOLATE(Isolate::Current()); | 711 CHECK_NO_ISOLATE(Isolate::Current()); |
704 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); | 712 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); |
705 Isolate::SetCurrent(isolate); | 713 Isolate::SetCurrent(isolate); |
706 } | 714 } |
707 | 715 |
708 | 716 |
709 DART_EXPORT void Dart_ExitIsolate() { | 717 DART_EXPORT void Dart_ExitIsolate() { |
710 CHECK_ISOLATE(Isolate::Current()); | 718 CHECK_ISOLATE(Isolate::Current()); |
711 Isolate::SetCurrent(NULL); | 719 Isolate::SetCurrent(NULL); |
(...skipping 1739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2451 return Api::NewError( | 2459 return Api::NewError( |
2452 "%s expects argument %d to be an instance of Object.", | 2460 "%s expects argument %d to be an instance of Object.", |
2453 CURRENT_FUNC, i); | 2461 CURRENT_FUNC, i); |
2454 } | 2462 } |
2455 } | 2463 } |
2456 args.Add(&arg); | 2464 args.Add(&arg); |
2457 } | 2465 } |
2458 | 2466 |
2459 const Array& kNoArgNames = Array::Handle(isolate); | 2467 const Array& kNoArgNames = Array::Handle(isolate); |
2460 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); | 2468 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); |
| 2469 if (obj.IsError()) { |
| 2470 return target; |
| 2471 } |
| 2472 |
2461 if (obj.IsNull() || obj.IsInstance()) { | 2473 if (obj.IsNull() || obj.IsInstance()) { |
2462 Instance& instance = Instance::Handle(isolate); | 2474 Instance& instance = Instance::Handle(isolate); |
2463 instance ^= obj.raw(); | 2475 instance ^= obj.raw(); |
2464 const Function& function = Function::Handle( | 2476 const Function& function = Function::Handle( |
2465 isolate, | 2477 isolate, |
2466 Resolver::ResolveDynamic(instance, | 2478 Resolver::ResolveDynamic(instance, |
2467 function_name, | 2479 function_name, |
2468 (number_of_arguments + 1), | 2480 (number_of_arguments + 1), |
2469 Resolver::kIsQualified)); | 2481 Resolver::kIsQualified)); |
2470 // TODO(5415268): Invoke noSuchMethod instead of failing. | 2482 // TODO(5415268): Invoke noSuchMethod instead of failing. |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2849 const Class& cls = Class::Handle( | 2861 const Class& cls = Class::Handle( |
2850 isolate, Class::NewNativeWrapper(&lib, cls_name, field_count)); | 2862 isolate, Class::NewNativeWrapper(&lib, cls_name, field_count)); |
2851 if (cls.IsNull()) { | 2863 if (cls.IsNull()) { |
2852 return Api::NewError( | 2864 return Api::NewError( |
2853 "Unable to create native wrapper class : already exists"); | 2865 "Unable to create native wrapper class : already exists"); |
2854 } | 2866 } |
2855 return Api::NewHandle(isolate, cls.raw()); | 2867 return Api::NewHandle(isolate, cls.raw()); |
2856 } | 2868 } |
2857 | 2869 |
2858 | 2870 |
| 2871 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, |
| 2872 int* count) { |
| 2873 Isolate* isolate = Isolate::Current(); |
| 2874 DARTSCOPE(isolate); |
| 2875 const Instance& instance = Api::UnwrapInstanceHandle(isolate, obj); |
| 2876 if (instance.IsNull()) { |
| 2877 RETURN_TYPE_ERROR(isolate, obj, Instance); |
| 2878 } |
| 2879 const Class& cls = Class::Handle(isolate, instance.clazz()); |
| 2880 *count = cls.num_native_fields(); |
| 2881 return Api::Success(isolate); |
| 2882 } |
| 2883 |
| 2884 |
2859 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, | 2885 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, |
2860 int index, | 2886 int index, |
2861 intptr_t* value) { | 2887 intptr_t* value) { |
2862 Isolate* isolate = Isolate::Current(); | 2888 Isolate* isolate = Isolate::Current(); |
2863 DARTSCOPE(isolate); | 2889 DARTSCOPE(isolate); |
2864 const Instance& object = Api::UnwrapInstanceHandle(isolate, obj); | 2890 const Instance& instance = Api::UnwrapInstanceHandle(isolate, obj); |
2865 if (object.IsNull()) { | 2891 if (instance.IsNull()) { |
2866 RETURN_TYPE_ERROR(isolate, obj, Instance); | 2892 RETURN_TYPE_ERROR(isolate, obj, Instance); |
2867 } | 2893 } |
2868 if (!object.IsValidNativeIndex(index)) { | 2894 if (!instance.IsValidNativeIndex(index)) { |
2869 return Api::NewError( | 2895 return Api::NewError( |
2870 "Invalid index passed in to access native instance field"); | 2896 "%s: invalid index %d passed in to access native instance field", |
| 2897 CURRENT_FUNC, index); |
2871 } | 2898 } |
2872 *value = object.GetNativeField(index); | 2899 *value = instance.GetNativeField(index); |
2873 return Api::Success(isolate); | 2900 return Api::Success(isolate); |
2874 } | 2901 } |
2875 | 2902 |
2876 | 2903 |
2877 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, | 2904 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, |
2878 int index, | 2905 int index, |
2879 intptr_t value) { | 2906 intptr_t value) { |
2880 Isolate* isolate = Isolate::Current(); | 2907 Isolate* isolate = Isolate::Current(); |
2881 DARTSCOPE(isolate); | 2908 DARTSCOPE(isolate); |
2882 const Instance& object = Api::UnwrapInstanceHandle(isolate, obj); | 2909 const Instance& instance = Api::UnwrapInstanceHandle(isolate, obj); |
2883 if (object.IsNull()) { | 2910 if (instance.IsNull()) { |
2884 RETURN_TYPE_ERROR(isolate, obj, Instance); | 2911 RETURN_TYPE_ERROR(isolate, obj, Instance); |
2885 } | 2912 } |
2886 if (!object.IsValidNativeIndex(index)) { | 2913 if (!instance.IsValidNativeIndex(index)) { |
2887 return Api::NewError( | 2914 return Api::NewError( |
2888 "Invalid index passed in to set native instance field"); | 2915 "%s: invalid index %d passed in to set native instance field", |
| 2916 CURRENT_FUNC, index); |
2889 } | 2917 } |
2890 object.SetNativeField(index, value); | 2918 instance.SetNativeField(index, value); |
2891 return Api::Success(isolate); | 2919 return Api::Success(isolate); |
2892 } | 2920 } |
2893 | 2921 |
2894 | 2922 |
2895 // --- Exceptions ---- | 2923 // --- Exceptions ---- |
2896 | 2924 |
2897 | 2925 |
2898 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { | 2926 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { |
2899 Isolate* isolate = Isolate::Current(); | 2927 Isolate* isolate = Isolate::Current(); |
2900 DARTSCOPE(isolate); | 2928 DARTSCOPE(isolate); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3095 | 3123 |
3096 DART_EXPORT Dart_Handle Dart_RootLibrary() { | 3124 DART_EXPORT Dart_Handle Dart_RootLibrary() { |
3097 Isolate* isolate = Isolate::Current(); | 3125 Isolate* isolate = Isolate::Current(); |
3098 DARTSCOPE(isolate); | 3126 DARTSCOPE(isolate); |
3099 Library& library = | 3127 Library& library = |
3100 Library::Handle(isolate, isolate->object_store()->root_library()); | 3128 Library::Handle(isolate, isolate->object_store()->root_library()); |
3101 return Api::NewHandle(isolate, library.raw()); | 3129 return Api::NewHandle(isolate, library.raw()); |
3102 } | 3130 } |
3103 | 3131 |
3104 | 3132 |
| 3133 DART_EXPORT Dart_Handle Dart_RegisteredLibraryUrls() { |
| 3134 Isolate* isolate = Isolate::Current(); |
| 3135 DARTSCOPE(isolate); |
| 3136 const GrowableObjectArray& lib_urls = GrowableObjectArray::Handle( |
| 3137 isolate, GrowableObjectArray::New()); |
| 3138 const GrowableObjectArray& libs = GrowableObjectArray::Handle( |
| 3139 isolate, isolate->object_store()->libraries()); |
| 3140 Library& lib = Library::Handle(isolate); |
| 3141 String& lib_url = String::Handle(isolate); |
| 3142 for (int i = 0; i < libs.Length(); i++) { |
| 3143 lib ^= libs.At(i); |
| 3144 lib_url = lib.url(); |
| 3145 lib_urls.Add(lib_url); |
| 3146 } |
| 3147 return Api::NewHandle(isolate, lib_urls.raw()); |
| 3148 } |
| 3149 |
| 3150 |
3105 static void CompileAll(Isolate* isolate, Dart_Handle* result) { | 3151 static void CompileAll(Isolate* isolate, Dart_Handle* result) { |
3106 ASSERT(isolate != NULL); | 3152 ASSERT(isolate != NULL); |
3107 const Error& error = Error::Handle(isolate, Library::CompileAll()); | 3153 const Error& error = Error::Handle(isolate, Library::CompileAll()); |
3108 if (error.IsNull()) { | 3154 if (error.IsNull()) { |
3109 *result = Api::Success(isolate); | 3155 *result = Api::Success(isolate); |
3110 } else { | 3156 } else { |
3111 *result = Api::NewHandle(isolate, error.raw()); | 3157 *result = Api::NewHandle(isolate, error.raw()); |
3112 } | 3158 } |
3113 } | 3159 } |
3114 | 3160 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3148 if (cls.IsNull()) { | 3194 if (cls.IsNull()) { |
3149 // TODO(turnidge): Return null or error in this case? | 3195 // TODO(turnidge): Return null or error in this case? |
3150 const String& lib_name = String::Handle(isolate, lib.name()); | 3196 const String& lib_name = String::Handle(isolate, lib.name()); |
3151 return Api::NewError("Class '%s' not found in library '%s'.", | 3197 return Api::NewError("Class '%s' not found in library '%s'.", |
3152 cls_name.ToCString(), lib_name.ToCString()); | 3198 cls_name.ToCString(), lib_name.ToCString()); |
3153 } | 3199 } |
3154 return Api::NewHandle(isolate, cls.raw()); | 3200 return Api::NewHandle(isolate, cls.raw()); |
3155 } | 3201 } |
3156 | 3202 |
3157 | 3203 |
| 3204 DART_EXPORT Dart_Handle Dart_LibraryName(Dart_Handle library) { |
| 3205 Isolate* isolate = Isolate::Current(); |
| 3206 DARTSCOPE(isolate); |
| 3207 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 3208 if (lib.IsNull()) { |
| 3209 RETURN_TYPE_ERROR(isolate, library, Library); |
| 3210 } |
| 3211 const String& name = String::Handle(isolate, lib.name()); |
| 3212 ASSERT(!name.IsNull()); |
| 3213 return Api::NewHandle(isolate, name.raw()); |
| 3214 } |
| 3215 |
| 3216 |
3158 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { | 3217 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { |
3159 Isolate* isolate = Isolate::Current(); | 3218 Isolate* isolate = Isolate::Current(); |
3160 DARTSCOPE(isolate); | 3219 DARTSCOPE(isolate); |
3161 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 3220 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
3162 if (lib.IsNull()) { | 3221 if (lib.IsNull()) { |
3163 RETURN_TYPE_ERROR(isolate, library, Library); | 3222 RETURN_TYPE_ERROR(isolate, library, Library); |
3164 } | 3223 } |
3165 const String& url = String::Handle(isolate, lib.url()); | 3224 const String& url = String::Handle(isolate, lib.url()); |
3166 ASSERT(!url.IsNull()); | 3225 ASSERT(!url.IsNull()); |
3167 return Api::NewHandle(isolate, url.raw()); | 3226 return Api::NewHandle(isolate, url.raw()); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3313 *buffer = NULL; | 3372 *buffer = NULL; |
3314 } | 3373 } |
3315 delete debug_region; | 3374 delete debug_region; |
3316 } else { | 3375 } else { |
3317 *buffer = NULL; | 3376 *buffer = NULL; |
3318 *buffer_size = 0; | 3377 *buffer_size = 0; |
3319 } | 3378 } |
3320 } | 3379 } |
3321 | 3380 |
3322 } // namespace dart | 3381 } // namespace dart |
OLD | NEW |