| 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 1777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2489 return Api::NewError( | 2497 return Api::NewError( |
| 2490 "%s expects argument %d to be an instance of Object.", | 2498 "%s expects argument %d to be an instance of Object.", |
| 2491 CURRENT_FUNC, i); | 2499 CURRENT_FUNC, i); |
| 2492 } | 2500 } |
| 2493 } | 2501 } |
| 2494 args.Add(&arg); | 2502 args.Add(&arg); |
| 2495 } | 2503 } |
| 2496 | 2504 |
| 2497 const Array& kNoArgNames = Array::Handle(isolate); | 2505 const Array& kNoArgNames = Array::Handle(isolate); |
| 2498 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); | 2506 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); |
| 2507 if (obj.IsError()) { |
| 2508 return target; |
| 2509 } |
| 2510 |
| 2499 if (obj.IsNull() || obj.IsInstance()) { | 2511 if (obj.IsNull() || obj.IsInstance()) { |
| 2500 Instance& instance = Instance::Handle(isolate); | 2512 Instance& instance = Instance::Handle(isolate); |
| 2501 instance ^= obj.raw(); | 2513 instance ^= obj.raw(); |
| 2502 const Function& function = Function::Handle( | 2514 const Function& function = Function::Handle( |
| 2503 isolate, | 2515 isolate, |
| 2504 Resolver::ResolveDynamic(instance, | 2516 Resolver::ResolveDynamic(instance, |
| 2505 function_name, | 2517 function_name, |
| 2506 (number_of_arguments + 1), | 2518 (number_of_arguments + 1), |
| 2507 Resolver::kIsQualified)); | 2519 Resolver::kIsQualified)); |
| 2508 // TODO(5415268): Invoke noSuchMethod instead of failing. | 2520 // TODO(5415268): Invoke noSuchMethod instead of failing. |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2887 const Class& cls = Class::Handle( | 2899 const Class& cls = Class::Handle( |
| 2888 isolate, Class::NewNativeWrapper(&lib, cls_name, field_count)); | 2900 isolate, Class::NewNativeWrapper(&lib, cls_name, field_count)); |
| 2889 if (cls.IsNull()) { | 2901 if (cls.IsNull()) { |
| 2890 return Api::NewError( | 2902 return Api::NewError( |
| 2891 "Unable to create native wrapper class : already exists"); | 2903 "Unable to create native wrapper class : already exists"); |
| 2892 } | 2904 } |
| 2893 return Api::NewHandle(isolate, cls.raw()); | 2905 return Api::NewHandle(isolate, cls.raw()); |
| 2894 } | 2906 } |
| 2895 | 2907 |
| 2896 | 2908 |
| 2909 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, |
| 2910 int* count) { |
| 2911 Isolate* isolate = Isolate::Current(); |
| 2912 DARTSCOPE(isolate); |
| 2913 const Instance& instance = Api::UnwrapInstanceHandle(isolate, obj); |
| 2914 if (instance.IsNull()) { |
| 2915 RETURN_TYPE_ERROR(isolate, obj, Instance); |
| 2916 } |
| 2917 const Class& cls = Class::Handle(isolate, instance.clazz()); |
| 2918 *count = cls.num_native_fields(); |
| 2919 return Api::Success(isolate); |
| 2920 } |
| 2921 |
| 2922 |
| 2897 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, | 2923 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, |
| 2898 int index, | 2924 int index, |
| 2899 intptr_t* value) { | 2925 intptr_t* value) { |
| 2900 Isolate* isolate = Isolate::Current(); | 2926 Isolate* isolate = Isolate::Current(); |
| 2901 DARTSCOPE(isolate); | 2927 DARTSCOPE(isolate); |
| 2902 const Instance& object = Api::UnwrapInstanceHandle(isolate, obj); | 2928 const Instance& instance = Api::UnwrapInstanceHandle(isolate, obj); |
| 2903 if (object.IsNull()) { | 2929 if (instance.IsNull()) { |
| 2904 RETURN_TYPE_ERROR(isolate, obj, Instance); | 2930 RETURN_TYPE_ERROR(isolate, obj, Instance); |
| 2905 } | 2931 } |
| 2906 if (!object.IsValidNativeIndex(index)) { | 2932 if (!instance.IsValidNativeIndex(index)) { |
| 2907 return Api::NewError( | 2933 return Api::NewError( |
| 2908 "Invalid index passed in to access native instance field"); | 2934 "%s: invalid index %d passed in to access native instance field", |
| 2935 CURRENT_FUNC, index); |
| 2909 } | 2936 } |
| 2910 *value = object.GetNativeField(index); | 2937 *value = instance.GetNativeField(index); |
| 2911 return Api::Success(isolate); | 2938 return Api::Success(isolate); |
| 2912 } | 2939 } |
| 2913 | 2940 |
| 2914 | 2941 |
| 2915 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, | 2942 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, |
| 2916 int index, | 2943 int index, |
| 2917 intptr_t value) { | 2944 intptr_t value) { |
| 2918 Isolate* isolate = Isolate::Current(); | 2945 Isolate* isolate = Isolate::Current(); |
| 2919 DARTSCOPE(isolate); | 2946 DARTSCOPE(isolate); |
| 2920 const Instance& object = Api::UnwrapInstanceHandle(isolate, obj); | 2947 const Instance& instance = Api::UnwrapInstanceHandle(isolate, obj); |
| 2921 if (object.IsNull()) { | 2948 if (instance.IsNull()) { |
| 2922 RETURN_TYPE_ERROR(isolate, obj, Instance); | 2949 RETURN_TYPE_ERROR(isolate, obj, Instance); |
| 2923 } | 2950 } |
| 2924 if (!object.IsValidNativeIndex(index)) { | 2951 if (!instance.IsValidNativeIndex(index)) { |
| 2925 return Api::NewError( | 2952 return Api::NewError( |
| 2926 "Invalid index passed in to set native instance field"); | 2953 "%s: invalid index %d passed in to set native instance field", |
| 2954 CURRENT_FUNC, index); |
| 2927 } | 2955 } |
| 2928 object.SetNativeField(index, value); | 2956 instance.SetNativeField(index, value); |
| 2929 return Api::Success(isolate); | 2957 return Api::Success(isolate); |
| 2930 } | 2958 } |
| 2931 | 2959 |
| 2932 | 2960 |
| 2933 // --- Exceptions ---- | 2961 // --- Exceptions ---- |
| 2934 | 2962 |
| 2935 | 2963 |
| 2936 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { | 2964 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { |
| 2937 Isolate* isolate = Isolate::Current(); | 2965 Isolate* isolate = Isolate::Current(); |
| 2938 DARTSCOPE(isolate); | 2966 DARTSCOPE(isolate); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3186 if (cls.IsNull()) { | 3214 if (cls.IsNull()) { |
| 3187 // TODO(turnidge): Return null or error in this case? | 3215 // TODO(turnidge): Return null or error in this case? |
| 3188 const String& lib_name = String::Handle(isolate, lib.name()); | 3216 const String& lib_name = String::Handle(isolate, lib.name()); |
| 3189 return Api::NewError("Class '%s' not found in library '%s'.", | 3217 return Api::NewError("Class '%s' not found in library '%s'.", |
| 3190 cls_name.ToCString(), lib_name.ToCString()); | 3218 cls_name.ToCString(), lib_name.ToCString()); |
| 3191 } | 3219 } |
| 3192 return Api::NewHandle(isolate, cls.raw()); | 3220 return Api::NewHandle(isolate, cls.raw()); |
| 3193 } | 3221 } |
| 3194 | 3222 |
| 3195 | 3223 |
| 3224 DART_EXPORT Dart_Handle Dart_LibraryName(Dart_Handle library) { |
| 3225 Isolate* isolate = Isolate::Current(); |
| 3226 DARTSCOPE(isolate); |
| 3227 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 3228 if (lib.IsNull()) { |
| 3229 RETURN_TYPE_ERROR(isolate, library, Library); |
| 3230 } |
| 3231 const String& name = String::Handle(isolate, lib.name()); |
| 3232 ASSERT(!name.IsNull()); |
| 3233 return Api::NewHandle(isolate, name.raw()); |
| 3234 } |
| 3235 |
| 3236 |
| 3196 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { | 3237 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { |
| 3197 Isolate* isolate = Isolate::Current(); | 3238 Isolate* isolate = Isolate::Current(); |
| 3198 DARTSCOPE(isolate); | 3239 DARTSCOPE(isolate); |
| 3199 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 3240 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 3200 if (lib.IsNull()) { | 3241 if (lib.IsNull()) { |
| 3201 RETURN_TYPE_ERROR(isolate, library, Library); | 3242 RETURN_TYPE_ERROR(isolate, library, Library); |
| 3202 } | 3243 } |
| 3203 const String& url = String::Handle(isolate, lib.url()); | 3244 const String& url = String::Handle(isolate, lib.url()); |
| 3204 ASSERT(!url.IsNull()); | 3245 ASSERT(!url.IsNull()); |
| 3205 return Api::NewHandle(isolate, url.raw()); | 3246 return Api::NewHandle(isolate, url.raw()); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3351 *buffer = NULL; | 3392 *buffer = NULL; |
| 3352 } | 3393 } |
| 3353 delete debug_region; | 3394 delete debug_region; |
| 3354 } else { | 3395 } else { |
| 3355 *buffer = NULL; | 3396 *buffer = NULL; |
| 3356 *buffer_size = 0; | 3397 *buffer_size = 0; |
| 3357 } | 3398 } |
| 3358 } | 3399 } |
| 3359 | 3400 |
| 3360 } // namespace dart | 3401 } // namespace dart |
| OLD | NEW |