OLD | NEW |
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 | 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 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 isolate, | 1124 isolate, |
1125 Resolver::ResolveStatic(isolate_lib, | 1125 Resolver::ResolveStatic(isolate_lib, |
1126 class_name, | 1126 class_name, |
1127 function_name, | 1127 function_name, |
1128 kNumArguments, | 1128 kNumArguments, |
1129 Object::empty_array(), | 1129 Object::empty_array(), |
1130 Resolver::kIsQualified)); | 1130 Resolver::kIsQualified)); |
1131 ASSERT(!function.IsNull()); | 1131 ASSERT(!function.IsNull()); |
1132 const Array& args = Array::Handle(isolate, Array::New(kNumArguments)); | 1132 const Array& args = Array::Handle(isolate, Array::New(kNumArguments)); |
1133 args.SetAt(0, Integer::Handle(isolate, Integer::New(port_id))); | 1133 args.SetAt(0, Integer::Handle(isolate, Integer::New(port_id))); |
1134 return Api::NewHandle(isolate, DartEntry::InvokeStatic(function, args)); | 1134 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, args)); |
1135 } | 1135 } |
1136 | 1136 |
1137 | 1137 |
1138 DART_EXPORT Dart_Port Dart_GetMainPortId() { | 1138 DART_EXPORT Dart_Port Dart_GetMainPortId() { |
1139 Isolate* isolate = Isolate::Current(); | 1139 Isolate* isolate = Isolate::Current(); |
1140 CHECK_ISOLATE(isolate); | 1140 CHECK_ISOLATE(isolate); |
1141 return isolate->main_port(); | 1141 return isolate->main_port(); |
1142 } | 1142 } |
1143 | 1143 |
1144 // --- Scopes ---- | 1144 // --- Scopes ---- |
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1917 const Function& function = | 1917 const Function& function = |
1918 Function::Handle(isolate, Resolver::ResolveDynamic(instance, name, 1, 0)); | 1918 Function::Handle(isolate, Resolver::ResolveDynamic(instance, name, 1, 0)); |
1919 if (function.IsNull()) { | 1919 if (function.IsNull()) { |
1920 return Api::NewError("List object does not have a 'length' field."); | 1920 return Api::NewError("List object does not have a 'length' field."); |
1921 } | 1921 } |
1922 | 1922 |
1923 const int kNumArgs = 1; | 1923 const int kNumArgs = 1; |
1924 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 1924 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
1925 args.SetAt(0, instance); // Set up the receiver as the first argument. | 1925 args.SetAt(0, instance); // Set up the receiver as the first argument. |
1926 const Object& retval = | 1926 const Object& retval = |
1927 Object::Handle(isolate, DartEntry::InvokeDynamic(function, args)); | 1927 Object::Handle(isolate, DartEntry::InvokeFunction(function, args)); |
1928 if (retval.IsSmi()) { | 1928 if (retval.IsSmi()) { |
1929 *len = Smi::Cast(retval).Value(); | 1929 *len = Smi::Cast(retval).Value(); |
1930 return Api::Success(isolate); | 1930 return Api::Success(isolate); |
1931 } else if (retval.IsMint() || retval.IsBigint()) { | 1931 } else if (retval.IsMint() || retval.IsBigint()) { |
1932 if (retval.IsMint()) { | 1932 if (retval.IsMint()) { |
1933 int64_t mint_value = Mint::Cast(retval).value(); | 1933 int64_t mint_value = Mint::Cast(retval).value(); |
1934 if (mint_value >= kIntptrMin && mint_value <= kIntptrMax) { | 1934 if (mint_value >= kIntptrMin && mint_value <= kIntptrMax) { |
1935 *len = static_cast<intptr_t>(mint_value); | 1935 *len = static_cast<intptr_t>(mint_value); |
1936 } | 1936 } |
1937 } else { | 1937 } else { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1982 if (!instance.IsNull()) { | 1982 if (!instance.IsNull()) { |
1983 const Function& function = Function::Handle( | 1983 const Function& function = Function::Handle( |
1984 isolate, | 1984 isolate, |
1985 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), 2, 0)); | 1985 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), 2, 0)); |
1986 if (!function.IsNull()) { | 1986 if (!function.IsNull()) { |
1987 const int kNumArgs = 2; | 1987 const int kNumArgs = 2; |
1988 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 1988 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
1989 const Integer& indexobj = Integer::Handle(isolate, Integer::New(index)); | 1989 const Integer& indexobj = Integer::Handle(isolate, Integer::New(index)); |
1990 args.SetAt(0, instance); | 1990 args.SetAt(0, instance); |
1991 args.SetAt(1, indexobj); | 1991 args.SetAt(1, indexobj); |
1992 return Api::NewHandle(isolate, DartEntry::InvokeDynamic(function, | 1992 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, |
1993 args)); | 1993 args)); |
1994 } | 1994 } |
1995 } | 1995 } |
1996 return Api::NewError("Object does not implement the 'List' interface"); | 1996 return Api::NewError("Object does not implement the 'List' interface"); |
1997 } | 1997 } |
1998 } | 1998 } |
1999 | 1999 |
2000 | 2000 |
2001 #define SET_LIST_ELEMENT(isolate, type, obj, index, value) \ | 2001 #define SET_LIST_ELEMENT(isolate, type, obj, index, value) \ |
2002 const type& array = type::Cast(obj); \ | 2002 const type& array = type::Cast(obj); \ |
2003 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); \ | 2003 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); \ |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2044 const Object& value_obj = | 2044 const Object& value_obj = |
2045 Object::Handle(isolate, Api::UnwrapHandle(value)); | 2045 Object::Handle(isolate, Api::UnwrapHandle(value)); |
2046 if (!value_obj.IsNull() && !value_obj.IsInstance()) { | 2046 if (!value_obj.IsNull() && !value_obj.IsInstance()) { |
2047 RETURN_TYPE_ERROR(isolate, value, Instance); | 2047 RETURN_TYPE_ERROR(isolate, value, Instance); |
2048 } | 2048 } |
2049 const intptr_t kNumArgs = 3; | 2049 const intptr_t kNumArgs = 3; |
2050 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 2050 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
2051 args.SetAt(0, instance); | 2051 args.SetAt(0, instance); |
2052 args.SetAt(1, index_obj); | 2052 args.SetAt(1, index_obj); |
2053 args.SetAt(2, value_obj); | 2053 args.SetAt(2, value_obj); |
2054 return Api::NewHandle(isolate, DartEntry::InvokeDynamic(function, | 2054 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, |
2055 args)); | 2055 args)); |
2056 } | 2056 } |
2057 } | 2057 } |
2058 return Api::NewError("Object does not implement the 'List' interface"); | 2058 return Api::NewError("Object does not implement the 'List' interface"); |
2059 } | 2059 } |
2060 } | 2060 } |
2061 | 2061 |
2062 | 2062 |
2063 static RawObject* ResolveConstructor(const char* current_func, | 2063 static RawObject* ResolveConstructor(const char* current_func, |
2064 const Class& cls, | 2064 const Class& cls, |
2065 const String& class_name, | 2065 const String& class_name, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2103 CURRENT_FUNC, class_name.ToCString())); | 2103 CURRENT_FUNC, class_name.ToCString())); |
2104 return ApiError::New(message); | 2104 return ApiError::New(message); |
2105 } | 2105 } |
2106 Instance& exception = Instance::Handle(isolate); | 2106 Instance& exception = Instance::Handle(isolate); |
2107 exception = Instance::New(cls); | 2107 exception = Instance::New(cls); |
2108 const Array& args = Array::Handle(isolate, Array::New(3)); | 2108 const Array& args = Array::Handle(isolate, Array::New(3)); |
2109 args.SetAt(0, exception); | 2109 args.SetAt(0, exception); |
2110 args.SetAt(1, | 2110 args.SetAt(1, |
2111 Smi::Handle(isolate, Smi::New(Function::kCtorPhaseAll))); | 2111 Smi::Handle(isolate, Smi::New(Function::kCtorPhaseAll))); |
2112 args.SetAt(2, String::Handle(String::New(exception_message))); | 2112 args.SetAt(2, String::Handle(String::New(exception_message))); |
2113 result = DartEntry::InvokeStatic(constructor, args); | 2113 result = DartEntry::InvokeFunction(constructor, args); |
2114 if (result.IsError()) return result.raw(); | 2114 if (result.IsError()) return result.raw(); |
2115 ASSERT(result.IsNull()); | 2115 ASSERT(result.IsNull()); |
2116 | 2116 |
2117 if (isolate->top_exit_frame_info() == 0) { | 2117 if (isolate->top_exit_frame_info() == 0) { |
2118 // There are no dart frames on the stack so it would be illegal to | 2118 // There are no dart frames on the stack so it would be illegal to |
2119 // throw an exception here. | 2119 // throw an exception here. |
2120 const String& message = String::Handle( | 2120 const String& message = String::Handle( |
2121 String::New("No Dart frames on stack, cannot throw exception")); | 2121 String::New("No Dart frames on stack, cannot throw exception")); |
2122 return ApiError::New(message); | 2122 return ApiError::New(message); |
2123 } | 2123 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2204 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), 2, 0)); | 2204 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), 2, 0)); |
2205 if (!function.IsNull()) { | 2205 if (!function.IsNull()) { |
2206 Object& result = Object::Handle(isolate); | 2206 Object& result = Object::Handle(isolate); |
2207 Integer& intobj = Integer::Handle(isolate); | 2207 Integer& intobj = Integer::Handle(isolate); |
2208 const int kNumArgs = 2; | 2208 const int kNumArgs = 2; |
2209 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 2209 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
2210 args.SetAt(0, instance); // Set up the receiver as the first argument. | 2210 args.SetAt(0, instance); // Set up the receiver as the first argument. |
2211 for (int i = 0; i < length; i++) { | 2211 for (int i = 0; i < length; i++) { |
2212 intobj = Integer::New(offset + i); | 2212 intobj = Integer::New(offset + i); |
2213 args.SetAt(1, intobj); | 2213 args.SetAt(1, intobj); |
2214 result = DartEntry::InvokeDynamic(function, args); | 2214 result = DartEntry::InvokeFunction(function, args); |
2215 if (result.IsError()) { | 2215 if (result.IsError()) { |
2216 return Api::NewHandle(isolate, result.raw()); | 2216 return Api::NewHandle(isolate, result.raw()); |
2217 } | 2217 } |
2218 if (!result.IsInteger()) { | 2218 if (!result.IsInteger()) { |
2219 return Api::NewError("%s expects the argument 'list' to be " | 2219 return Api::NewError("%s expects the argument 'list' to be " |
2220 "a List of int", CURRENT_FUNC); | 2220 "a List of int", CURRENT_FUNC); |
2221 } | 2221 } |
2222 const Integer& integer_result = Integer::Cast(result); | 2222 const Integer& integer_result = Integer::Cast(result); |
2223 ASSERT(integer_result.AsInt64Value() <= 0xff); | 2223 ASSERT(integer_result.AsInt64Value() <= 0xff); |
2224 // TODO(hpayer): value should always be smaller then 0xff. Add error | 2224 // TODO(hpayer): value should always be smaller then 0xff. Add error |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2299 Integer& valueobj = Integer::Handle(isolate); | 2299 Integer& valueobj = Integer::Handle(isolate); |
2300 const int kNumArgs = 3; | 2300 const int kNumArgs = 3; |
2301 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 2301 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
2302 args.SetAt(0, instance); // Set up the receiver as the first argument. | 2302 args.SetAt(0, instance); // Set up the receiver as the first argument. |
2303 for (int i = 0; i < length; i++) { | 2303 for (int i = 0; i < length; i++) { |
2304 indexobj = Integer::New(offset + i); | 2304 indexobj = Integer::New(offset + i); |
2305 valueobj = Integer::New(native_array[i]); | 2305 valueobj = Integer::New(native_array[i]); |
2306 args.SetAt(1, indexobj); | 2306 args.SetAt(1, indexobj); |
2307 args.SetAt(2, valueobj); | 2307 args.SetAt(2, valueobj); |
2308 const Object& result = Object::Handle( | 2308 const Object& result = Object::Handle( |
2309 isolate, DartEntry::InvokeDynamic(function, args)); | 2309 isolate, DartEntry::InvokeFunction(function, args)); |
2310 if (result.IsError()) { | 2310 if (result.IsError()) { |
2311 return Api::NewHandle(isolate, result.raw()); | 2311 return Api::NewHandle(isolate, result.raw()); |
2312 } | 2312 } |
2313 } | 2313 } |
2314 return Api::Success(isolate); | 2314 return Api::Success(isolate); |
2315 } | 2315 } |
2316 } | 2316 } |
2317 return Api::NewError("Object does not implement the 'List' interface"); | 2317 return Api::NewError("Object does not implement the 'List' interface"); |
2318 } | 2318 } |
2319 } | 2319 } |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2657 Object& obj = Object::Handle(isolate); | 2657 Object& obj = Object::Handle(isolate); |
2658 args.SetAt(0, closure_obj); | 2658 args.SetAt(0, closure_obj); |
2659 for (int i = 0; i < number_of_arguments; i++) { | 2659 for (int i = 0; i < number_of_arguments; i++) { |
2660 obj = Api::UnwrapHandle(arguments[i]); | 2660 obj = Api::UnwrapHandle(arguments[i]); |
2661 if (!obj.IsNull() && !obj.IsInstance()) { | 2661 if (!obj.IsNull() && !obj.IsInstance()) { |
2662 RETURN_TYPE_ERROR(isolate, arguments[i], Instance); | 2662 RETURN_TYPE_ERROR(isolate, arguments[i], Instance); |
2663 } | 2663 } |
2664 args.SetAt(i + 1, obj); | 2664 args.SetAt(i + 1, obj); |
2665 } | 2665 } |
2666 // Now try to invoke the closure. | 2666 // Now try to invoke the closure. |
2667 return Api::NewHandle(isolate, DartEntry::InvokeClosure(closure_obj, args)); | 2667 return Api::NewHandle(isolate, DartEntry::InvokeClosure(args)); |
2668 } | 2668 } |
2669 | 2669 |
2670 | 2670 |
2671 // --- Classes --- | 2671 // --- Classes --- |
2672 | 2672 |
2673 | 2673 |
2674 DART_EXPORT bool Dart_IsClass(Dart_Handle handle) { | 2674 DART_EXPORT bool Dart_IsClass(Dart_Handle handle) { |
2675 Isolate* isolate = Isolate::Current(); | 2675 Isolate* isolate = Isolate::Current(); |
2676 DARTSCOPE(isolate); | 2676 DARTSCOPE(isolate); |
2677 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 2677 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3563 } else { | 3563 } else { |
3564 return Api::NewError( | 3564 return Api::NewError( |
3565 "%s expects arguments[%d] to be an Instance handle.", | 3565 "%s expects arguments[%d] to be an Instance handle.", |
3566 CURRENT_FUNC, i); | 3566 CURRENT_FUNC, i); |
3567 } | 3567 } |
3568 } | 3568 } |
3569 args.SetAt(arg_index++, argument); | 3569 args.SetAt(arg_index++, argument); |
3570 } | 3570 } |
3571 | 3571 |
3572 // Invoke the constructor and return the new object. | 3572 // Invoke the constructor and return the new object. |
3573 result = DartEntry::InvokeStatic(constructor, args); | 3573 result = DartEntry::InvokeFunction(constructor, args); |
3574 if (result.IsError()) { | 3574 if (result.IsError()) { |
3575 return Api::NewHandle(isolate, result.raw()); | 3575 return Api::NewHandle(isolate, result.raw()); |
3576 } | 3576 } |
3577 if (constructor.IsConstructor()) { | 3577 if (constructor.IsConstructor()) { |
3578 ASSERT(result.IsNull()); | 3578 ASSERT(result.IsNull()); |
3579 } else { | 3579 } else { |
3580 ASSERT(result.IsNull() || result.IsInstance()); | 3580 ASSERT(result.IsNull() || result.IsInstance()); |
3581 new_object ^= result.raw(); | 3581 new_object ^= result.raw(); |
3582 } | 3582 } |
3583 return Api::NewHandle(isolate, new_object.raw()); | 3583 return Api::NewHandle(isolate, new_object.raw()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3637 // TODO(5415268): Invoke noSuchMethod instead of failing. | 3637 // TODO(5415268): Invoke noSuchMethod instead of failing. |
3638 if (function.IsNull()) { | 3638 if (function.IsNull()) { |
3639 const Type& type = Type::Handle(isolate, instance.GetType()); | 3639 const Type& type = Type::Handle(isolate, instance.GetType()); |
3640 const String& cls_name = String::Handle(isolate, type.ClassName()); | 3640 const String& cls_name = String::Handle(isolate, type.ClassName()); |
3641 return Api::NewError("%s: did not find instance method '%s.%s'.", | 3641 return Api::NewError("%s: did not find instance method '%s.%s'.", |
3642 CURRENT_FUNC, | 3642 CURRENT_FUNC, |
3643 cls_name.ToCString(), | 3643 cls_name.ToCString(), |
3644 function_name.ToCString()); | 3644 function_name.ToCString()); |
3645 } | 3645 } |
3646 args.SetAt(0, instance); | 3646 args.SetAt(0, instance); |
3647 return Api::NewHandle(isolate, DartEntry::InvokeDynamic(function, args)); | 3647 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, args)); |
3648 | 3648 |
3649 } else if (obj.IsClass()) { | 3649 } else if (obj.IsClass()) { |
3650 // Finalize all classes. | 3650 // Finalize all classes. |
3651 Dart_Handle state = Api::CheckIsolateState(isolate); | 3651 Dart_Handle state = Api::CheckIsolateState(isolate); |
3652 if (::Dart_IsError(state)) { | 3652 if (::Dart_IsError(state)) { |
3653 return state; | 3653 return state; |
3654 } | 3654 } |
3655 | 3655 |
3656 const Class& cls = Class::Cast(obj); | 3656 const Class& cls = Class::Cast(obj); |
3657 const Function& function = Function::Handle( | 3657 const Function& function = Function::Handle( |
3658 isolate, | 3658 isolate, |
3659 Resolver::ResolveStatic(cls, | 3659 Resolver::ResolveStatic(cls, |
3660 function_name, | 3660 function_name, |
3661 number_of_arguments, | 3661 number_of_arguments, |
3662 Object::empty_array(), | 3662 Object::empty_array(), |
3663 Resolver::kIsQualified)); | 3663 Resolver::kIsQualified)); |
3664 if (function.IsNull()) { | 3664 if (function.IsNull()) { |
3665 const String& cls_name = String::Handle(isolate, cls.Name()); | 3665 const String& cls_name = String::Handle(isolate, cls.Name()); |
3666 return Api::NewError("%s: did not find static method '%s.%s'.", | 3666 return Api::NewError("%s: did not find static method '%s.%s'.", |
3667 CURRENT_FUNC, | 3667 CURRENT_FUNC, |
3668 cls_name.ToCString(), | 3668 cls_name.ToCString(), |
3669 function_name.ToCString()); | 3669 function_name.ToCString()); |
3670 } | 3670 } |
3671 return Api::NewHandle(isolate, DartEntry::InvokeStatic(function, args)); | 3671 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, args)); |
3672 | 3672 |
3673 } else if (obj.IsLibrary()) { | 3673 } else if (obj.IsLibrary()) { |
3674 // Check whether class finalization is needed. | 3674 // Check whether class finalization is needed. |
3675 bool finalize_classes = true; | 3675 bool finalize_classes = true; |
3676 const Library& lib = Library::Cast(obj); | 3676 const Library& lib = Library::Cast(obj); |
3677 | 3677 |
3678 // When calling functions in the dart:builtin library do not finalize as it | 3678 // When calling functions in the dart:builtin library do not finalize as it |
3679 // should have been prefinalized. | 3679 // should have been prefinalized. |
3680 Library& builtin = | 3680 Library& builtin = |
3681 Library::Handle(isolate, isolate->object_store()->builtin_library()); | 3681 Library::Handle(isolate, isolate->object_store()->builtin_library()); |
(...skipping 20 matching lines...) Expand all Loading... |
3702 // do it here. | 3702 // do it here. |
3703 String& error_message = String::Handle(); | 3703 String& error_message = String::Handle(); |
3704 if (!function.AreValidArgumentCounts(number_of_arguments, | 3704 if (!function.AreValidArgumentCounts(number_of_arguments, |
3705 0, | 3705 0, |
3706 &error_message)) { | 3706 &error_message)) { |
3707 return Api::NewError("%s: wrong argument count for function '%s': %s.", | 3707 return Api::NewError("%s: wrong argument count for function '%s': %s.", |
3708 CURRENT_FUNC, | 3708 CURRENT_FUNC, |
3709 function_name.ToCString(), | 3709 function_name.ToCString(), |
3710 error_message.ToCString()); | 3710 error_message.ToCString()); |
3711 } | 3711 } |
3712 return Api::NewHandle(isolate, DartEntry::InvokeStatic(function, args)); | 3712 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, args)); |
3713 | 3713 |
3714 } else { | 3714 } else { |
3715 return Api::NewError( | 3715 return Api::NewError( |
3716 "%s expects argument 'target' to be an object, class, or library.", | 3716 "%s expects argument 'target' to be an object, class, or library.", |
3717 CURRENT_FUNC); | 3717 CURRENT_FUNC); |
3718 } | 3718 } |
3719 } | 3719 } |
3720 | 3720 |
3721 | 3721 |
3722 static bool FieldIsUninitialized(Isolate* isolate, const Field& fld) { | 3722 static bool FieldIsUninitialized(Isolate* isolate, const Field& fld) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3766 | 3766 |
3767 if (getter.IsNull()) { | 3767 if (getter.IsNull()) { |
3768 return Api::NewError("%s: did not find instance field '%s'.", | 3768 return Api::NewError("%s: did not find instance field '%s'.", |
3769 CURRENT_FUNC, field_name.ToCString()); | 3769 CURRENT_FUNC, field_name.ToCString()); |
3770 } | 3770 } |
3771 | 3771 |
3772 // Invoke the getter and return the result. | 3772 // Invoke the getter and return the result. |
3773 const int kNumArgs = 1; | 3773 const int kNumArgs = 1; |
3774 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 3774 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
3775 args.SetAt(0, instance); | 3775 args.SetAt(0, instance); |
3776 return Api::NewHandle(isolate, DartEntry::InvokeDynamic(getter, args)); | 3776 return Api::NewHandle(isolate, DartEntry::InvokeFunction(getter, args)); |
3777 | 3777 |
3778 } else if (obj.IsClass()) { | 3778 } else if (obj.IsClass()) { |
3779 // Finalize all classes. | 3779 // Finalize all classes. |
3780 Dart_Handle state = Api::CheckIsolateState(isolate); | 3780 Dart_Handle state = Api::CheckIsolateState(isolate); |
3781 if (::Dart_IsError(state)) { | 3781 if (::Dart_IsError(state)) { |
3782 return state; | 3782 return state; |
3783 } | 3783 } |
3784 // To access a static field we may need to use the Field or the | 3784 // To access a static field we may need to use the Field or the |
3785 // getter Function. | 3785 // getter Function. |
3786 const Class& cls = Class::Cast(obj); | 3786 const Class& cls = Class::Cast(obj); |
3787 field = cls.LookupStaticField(field_name); | 3787 field = cls.LookupStaticField(field_name); |
3788 if (field.IsNull() || FieldIsUninitialized(isolate, field)) { | 3788 if (field.IsNull() || FieldIsUninitialized(isolate, field)) { |
3789 const String& getter_name = | 3789 const String& getter_name = |
3790 String::Handle(isolate, Field::GetterName(field_name)); | 3790 String::Handle(isolate, Field::GetterName(field_name)); |
3791 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); | 3791 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); |
3792 } | 3792 } |
3793 | 3793 |
3794 if (!getter.IsNull()) { | 3794 if (!getter.IsNull()) { |
3795 // Invoke the getter and return the result. | 3795 // Invoke the getter and return the result. |
3796 return Api::NewHandle( | 3796 return Api::NewHandle( |
3797 isolate, DartEntry::InvokeStatic(getter, Object::empty_array())); | 3797 isolate, DartEntry::InvokeFunction(getter, Object::empty_array())); |
3798 } else if (!field.IsNull()) { | 3798 } else if (!field.IsNull()) { |
3799 return Api::NewHandle(isolate, field.value()); | 3799 return Api::NewHandle(isolate, field.value()); |
3800 } else { | 3800 } else { |
3801 return Api::NewError("%s: did not find static field '%s'.", | 3801 return Api::NewError("%s: did not find static field '%s'.", |
3802 CURRENT_FUNC, field_name.ToCString()); | 3802 CURRENT_FUNC, field_name.ToCString()); |
3803 } | 3803 } |
3804 | 3804 |
3805 } else if (obj.IsLibrary()) { | 3805 } else if (obj.IsLibrary()) { |
3806 // TODO(turnidge): Do we need to call CheckIsolateState here? | 3806 // TODO(turnidge): Do we need to call CheckIsolateState here? |
3807 | 3807 |
(...skipping 11 matching lines...) Expand all Loading... |
3819 // A field was found. Check for a getter in the field's owner classs. | 3819 // A field was found. Check for a getter in the field's owner classs. |
3820 const Class& cls = Class::Handle(isolate, field.owner()); | 3820 const Class& cls = Class::Handle(isolate, field.owner()); |
3821 const String& getter_name = | 3821 const String& getter_name = |
3822 String::Handle(isolate, Field::GetterName(field_name)); | 3822 String::Handle(isolate, Field::GetterName(field_name)); |
3823 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); | 3823 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); |
3824 } | 3824 } |
3825 | 3825 |
3826 if (!getter.IsNull()) { | 3826 if (!getter.IsNull()) { |
3827 // Invoke the getter and return the result. | 3827 // Invoke the getter and return the result. |
3828 return Api::NewHandle( | 3828 return Api::NewHandle( |
3829 isolate, DartEntry::InvokeStatic(getter, Object::empty_array())); | 3829 isolate, DartEntry::InvokeFunction(getter, Object::empty_array())); |
3830 } else if (!field.IsNull()) { | 3830 } else if (!field.IsNull()) { |
3831 return Api::NewHandle(isolate, field.value()); | 3831 return Api::NewHandle(isolate, field.value()); |
3832 } else { | 3832 } else { |
3833 return Api::NewError("%s: did not find top-level variable '%s'.", | 3833 return Api::NewError("%s: did not find top-level variable '%s'.", |
3834 CURRENT_FUNC, field_name.ToCString()); | 3834 CURRENT_FUNC, field_name.ToCString()); |
3835 } | 3835 } |
3836 | 3836 |
3837 } else if (obj.IsError()) { | 3837 } else if (obj.IsError()) { |
3838 return container; | 3838 return container; |
3839 } else { | 3839 } else { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3894 if (setter.IsNull()) { | 3894 if (setter.IsNull()) { |
3895 return Api::NewError("%s: did not find instance field '%s'.", | 3895 return Api::NewError("%s: did not find instance field '%s'.", |
3896 CURRENT_FUNC, field_name.ToCString()); | 3896 CURRENT_FUNC, field_name.ToCString()); |
3897 } | 3897 } |
3898 | 3898 |
3899 // Invoke the setter and return the result. | 3899 // Invoke the setter and return the result. |
3900 const int kNumArgs = 2; | 3900 const int kNumArgs = 2; |
3901 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 3901 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
3902 args.SetAt(0, instance); | 3902 args.SetAt(0, instance); |
3903 args.SetAt(1, value_instance); | 3903 args.SetAt(1, value_instance); |
3904 return Api::NewHandle(isolate, DartEntry::InvokeDynamic(setter, args)); | 3904 return Api::NewHandle(isolate, DartEntry::InvokeFunction(setter, args)); |
3905 | 3905 |
3906 } else if (obj.IsClass()) { | 3906 } else if (obj.IsClass()) { |
3907 // To access a static field we may need to use the Field or the | 3907 // To access a static field we may need to use the Field or the |
3908 // setter Function. | 3908 // setter Function. |
3909 const Class& cls = Class::Cast(obj); | 3909 const Class& cls = Class::Cast(obj); |
3910 field = cls.LookupStaticField(field_name); | 3910 field = cls.LookupStaticField(field_name); |
3911 if (field.IsNull()) { | 3911 if (field.IsNull()) { |
3912 String& setter_name = | 3912 String& setter_name = |
3913 String::Handle(isolate, Field::SetterName(field_name)); | 3913 String::Handle(isolate, Field::SetterName(field_name)); |
3914 setter = cls.LookupStaticFunctionAllowPrivate(setter_name); | 3914 setter = cls.LookupStaticFunctionAllowPrivate(setter_name); |
3915 } | 3915 } |
3916 | 3916 |
3917 if (!setter.IsNull()) { | 3917 if (!setter.IsNull()) { |
3918 // Invoke the setter and return the result. | 3918 // Invoke the setter and return the result. |
3919 const int kNumArgs = 1; | 3919 const int kNumArgs = 1; |
3920 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 3920 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
3921 args.SetAt(0, value_instance); | 3921 args.SetAt(0, value_instance); |
3922 const Object& result = | 3922 const Object& result = |
3923 Object::Handle(isolate, DartEntry::InvokeStatic(setter, args)); | 3923 Object::Handle(isolate, DartEntry::InvokeFunction(setter, args)); |
3924 if (result.IsError()) { | 3924 if (result.IsError()) { |
3925 return Api::NewHandle(isolate, result.raw()); | 3925 return Api::NewHandle(isolate, result.raw()); |
3926 } else { | 3926 } else { |
3927 return Api::Success(isolate); | 3927 return Api::Success(isolate); |
3928 } | 3928 } |
3929 } else if (!field.IsNull()) { | 3929 } else if (!field.IsNull()) { |
3930 if (field.is_final()) { | 3930 if (field.is_final()) { |
3931 return Api::NewError("%s: cannot set final field '%s'.", | 3931 return Api::NewError("%s: cannot set final field '%s'.", |
3932 CURRENT_FUNC, field_name.ToCString()); | 3932 CURRENT_FUNC, field_name.ToCString()); |
3933 } else { | 3933 } else { |
(...skipping 16 matching lines...) Expand all Loading... |
3950 String::Handle(isolate, Field::SetterName(field_name)); | 3950 String::Handle(isolate, Field::SetterName(field_name)); |
3951 setter ^= lib.LookupFunctionAllowPrivate(setter_name); | 3951 setter ^= lib.LookupFunctionAllowPrivate(setter_name); |
3952 } | 3952 } |
3953 | 3953 |
3954 if (!setter.IsNull()) { | 3954 if (!setter.IsNull()) { |
3955 // Invoke the setter and return the result. | 3955 // Invoke the setter and return the result. |
3956 const int kNumArgs = 1; | 3956 const int kNumArgs = 1; |
3957 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 3957 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
3958 args.SetAt(0, value_instance); | 3958 args.SetAt(0, value_instance); |
3959 const Object& result = | 3959 const Object& result = |
3960 Object::Handle(isolate, DartEntry::InvokeStatic(setter, args)); | 3960 Object::Handle(isolate, DartEntry::InvokeFunction(setter, args)); |
3961 if (result.IsError()) { | 3961 if (result.IsError()) { |
3962 return Api::NewHandle(isolate, result.raw()); | 3962 return Api::NewHandle(isolate, result.raw()); |
3963 } else { | 3963 } else { |
3964 return Api::Success(isolate); | 3964 return Api::Success(isolate); |
3965 } | 3965 } |
3966 } else if (!field.IsNull()) { | 3966 } else if (!field.IsNull()) { |
3967 if (field.is_final()) { | 3967 if (field.is_final()) { |
3968 return Api::NewError("%s: cannot set final top-level variable '%s'.", | 3968 return Api::NewError("%s: cannot set final top-level variable '%s'.", |
3969 CURRENT_FUNC, field_name.ToCString()); | 3969 CURRENT_FUNC, field_name.ToCString()); |
3970 } else { | 3970 } else { |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4684 } | 4684 } |
4685 { | 4685 { |
4686 NoGCScope no_gc; | 4686 NoGCScope no_gc; |
4687 RawObject* raw_obj = obj.raw(); | 4687 RawObject* raw_obj = obj.raw(); |
4688 isolate->heap()->SetPeer(raw_obj, peer); | 4688 isolate->heap()->SetPeer(raw_obj, peer); |
4689 } | 4689 } |
4690 return Api::Success(isolate); | 4690 return Api::Success(isolate); |
4691 } | 4691 } |
4692 | 4692 |
4693 } // namespace dart | 4693 } // namespace dart |
OLD | NEW |