| 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 #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 1856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1867 } | 1867 } |
| 1868 CHECK_CALLBACK_STATE(isolate); | 1868 CHECK_CALLBACK_STATE(isolate); |
| 1869 | 1869 |
| 1870 // Now check and handle a dart object that implements the List interface. | 1870 // Now check and handle a dart object that implements the List interface. |
| 1871 const Instance& instance = | 1871 const Instance& instance = |
| 1872 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 1872 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 1873 if (instance.IsNull()) { | 1873 if (instance.IsNull()) { |
| 1874 return Api::NewError("Object does not implement the List interface"); | 1874 return Api::NewError("Object does not implement the List interface"); |
| 1875 } | 1875 } |
| 1876 const String& name = String::Handle(Field::GetterName(Symbols::Length())); | 1876 const String& name = String::Handle(Field::GetterName(Symbols::Length())); |
| 1877 const int kNumArgs = 1; |
| 1878 ArgumentsDescriptor args_desc( |
| 1879 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
| 1877 const Function& function = | 1880 const Function& function = |
| 1878 Function::Handle(isolate, Resolver::ResolveDynamic(instance, name, 1, 0)); | 1881 Function::Handle(isolate, Resolver::ResolveDynamic(instance, |
| 1882 name, |
| 1883 args_desc)); |
| 1879 if (function.IsNull()) { | 1884 if (function.IsNull()) { |
| 1880 return Api::NewError("List object does not have a 'length' field."); | 1885 return Api::NewError("List object does not have a 'length' field."); |
| 1881 } | 1886 } |
| 1882 | 1887 |
| 1883 const int kNumArgs = 1; | |
| 1884 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 1888 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
| 1885 args.SetAt(0, instance); // Set up the receiver as the first argument. | 1889 args.SetAt(0, instance); // Set up the receiver as the first argument. |
| 1886 const Object& retval = | 1890 const Object& retval = |
| 1887 Object::Handle(isolate, DartEntry::InvokeFunction(function, args)); | 1891 Object::Handle(isolate, DartEntry::InvokeFunction(function, args)); |
| 1888 if (retval.IsSmi()) { | 1892 if (retval.IsSmi()) { |
| 1889 *len = Smi::Cast(retval).Value(); | 1893 *len = Smi::Cast(retval).Value(); |
| 1890 return Api::Success(); | 1894 return Api::Success(); |
| 1891 } else if (retval.IsMint() || retval.IsBigint()) { | 1895 } else if (retval.IsMint() || retval.IsBigint()) { |
| 1892 if (retval.IsMint()) { | 1896 if (retval.IsMint()) { |
| 1893 int64_t mint_value = Mint::Cast(retval).value(); | 1897 int64_t mint_value = Mint::Cast(retval).value(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1933 GET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index); | 1937 GET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index); |
| 1934 } else if (obj.IsError()) { | 1938 } else if (obj.IsError()) { |
| 1935 return list; | 1939 return list; |
| 1936 } else { | 1940 } else { |
| 1937 CHECK_CALLBACK_STATE(isolate); | 1941 CHECK_CALLBACK_STATE(isolate); |
| 1938 | 1942 |
| 1939 // Check and handle a dart object that implements the List interface. | 1943 // Check and handle a dart object that implements the List interface. |
| 1940 const Instance& instance = | 1944 const Instance& instance = |
| 1941 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 1945 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 1942 if (!instance.IsNull()) { | 1946 if (!instance.IsNull()) { |
| 1947 const int kNumArgs = 2; |
| 1948 ArgumentsDescriptor args_desc( |
| 1949 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
| 1943 const Function& function = Function::Handle( | 1950 const Function& function = Function::Handle( |
| 1944 isolate, | 1951 isolate, |
| 1945 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), 2, 0)); | 1952 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), args_desc)); |
| 1946 if (!function.IsNull()) { | 1953 if (!function.IsNull()) { |
| 1947 const int kNumArgs = 2; | |
| 1948 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 1954 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
| 1949 const Integer& indexobj = Integer::Handle(isolate, Integer::New(index)); | 1955 const Integer& indexobj = Integer::Handle(isolate, Integer::New(index)); |
| 1950 args.SetAt(0, instance); | 1956 args.SetAt(0, instance); |
| 1951 args.SetAt(1, indexobj); | 1957 args.SetAt(1, indexobj); |
| 1952 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, | 1958 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, |
| 1953 args)); | 1959 args)); |
| 1954 } | 1960 } |
| 1955 } | 1961 } |
| 1956 return Api::NewError("Object does not implement the 'List' interface"); | 1962 return Api::NewError("Object does not implement the 'List' interface"); |
| 1957 } | 1963 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1985 SET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index, value); | 1991 SET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index, value); |
| 1986 } else if (obj.IsError()) { | 1992 } else if (obj.IsError()) { |
| 1987 return list; | 1993 return list; |
| 1988 } else { | 1994 } else { |
| 1989 CHECK_CALLBACK_STATE(isolate); | 1995 CHECK_CALLBACK_STATE(isolate); |
| 1990 | 1996 |
| 1991 // Check and handle a dart object that implements the List interface. | 1997 // Check and handle a dart object that implements the List interface. |
| 1992 const Instance& instance = | 1998 const Instance& instance = |
| 1993 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 1999 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 1994 if (!instance.IsNull()) { | 2000 if (!instance.IsNull()) { |
| 2001 const intptr_t kNumArgs = 3; |
| 2002 ArgumentsDescriptor args_desc( |
| 2003 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
| 1995 const Function& function = Function::Handle( | 2004 const Function& function = Function::Handle( |
| 1996 isolate, | 2005 isolate, |
| 1997 Resolver::ResolveDynamic(instance, | 2006 Resolver::ResolveDynamic(instance, |
| 1998 Symbols::AssignIndexToken(), | 2007 Symbols::AssignIndexToken(), |
| 1999 3, | 2008 args_desc)); |
| 2000 0)); | |
| 2001 if (!function.IsNull()) { | 2009 if (!function.IsNull()) { |
| 2002 const Integer& index_obj = | 2010 const Integer& index_obj = |
| 2003 Integer::Handle(isolate, Integer::New(index)); | 2011 Integer::Handle(isolate, Integer::New(index)); |
| 2004 const Object& value_obj = | 2012 const Object& value_obj = |
| 2005 Object::Handle(isolate, Api::UnwrapHandle(value)); | 2013 Object::Handle(isolate, Api::UnwrapHandle(value)); |
| 2006 if (!value_obj.IsNull() && !value_obj.IsInstance()) { | 2014 if (!value_obj.IsNull() && !value_obj.IsInstance()) { |
| 2007 RETURN_TYPE_ERROR(isolate, value, Instance); | 2015 RETURN_TYPE_ERROR(isolate, value, Instance); |
| 2008 } | 2016 } |
| 2009 const intptr_t kNumArgs = 3; | |
| 2010 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 2017 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
| 2011 args.SetAt(0, instance); | 2018 args.SetAt(0, instance); |
| 2012 args.SetAt(1, index_obj); | 2019 args.SetAt(1, index_obj); |
| 2013 args.SetAt(2, value_obj); | 2020 args.SetAt(2, value_obj); |
| 2014 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, | 2021 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, |
| 2015 args)); | 2022 args)); |
| 2016 } | 2023 } |
| 2017 } | 2024 } |
| 2018 return Api::NewError("Object does not implement the 'List' interface"); | 2025 return Api::NewError("Object does not implement the 'List' interface"); |
| 2019 } | 2026 } |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2158 } | 2165 } |
| 2159 if (obj.IsError()) { | 2166 if (obj.IsError()) { |
| 2160 return list; | 2167 return list; |
| 2161 } | 2168 } |
| 2162 CHECK_CALLBACK_STATE(isolate); | 2169 CHECK_CALLBACK_STATE(isolate); |
| 2163 | 2170 |
| 2164 // Check and handle a dart object that implements the List interface. | 2171 // Check and handle a dart object that implements the List interface. |
| 2165 const Instance& instance = | 2172 const Instance& instance = |
| 2166 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 2173 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 2167 if (!instance.IsNull()) { | 2174 if (!instance.IsNull()) { |
| 2175 const int kNumArgs = 2; |
| 2176 ArgumentsDescriptor args_desc( |
| 2177 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
| 2168 const Function& function = Function::Handle( | 2178 const Function& function = Function::Handle( |
| 2169 isolate, | 2179 isolate, |
| 2170 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), 2, 0)); | 2180 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), args_desc)); |
| 2171 if (!function.IsNull()) { | 2181 if (!function.IsNull()) { |
| 2172 Object& result = Object::Handle(isolate); | 2182 Object& result = Object::Handle(isolate); |
| 2173 Integer& intobj = Integer::Handle(isolate); | 2183 Integer& intobj = Integer::Handle(isolate); |
| 2174 const int kNumArgs = 2; | |
| 2175 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 2184 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
| 2176 args.SetAt(0, instance); // Set up the receiver as the first argument. | 2185 args.SetAt(0, instance); // Set up the receiver as the first argument. |
| 2177 for (int i = 0; i < length; i++) { | 2186 for (int i = 0; i < length; i++) { |
| 2178 intobj = Integer::New(offset + i); | 2187 intobj = Integer::New(offset + i); |
| 2179 args.SetAt(1, intobj); | 2188 args.SetAt(1, intobj); |
| 2180 result = DartEntry::InvokeFunction(function, args); | 2189 result = DartEntry::InvokeFunction(function, args); |
| 2181 if (result.IsError()) { | 2190 if (result.IsError()) { |
| 2182 return Api::NewHandle(isolate, result.raw()); | 2191 return Api::NewHandle(isolate, result.raw()); |
| 2183 } | 2192 } |
| 2184 if (!result.IsInteger()) { | 2193 if (!result.IsInteger()) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2253 } | 2262 } |
| 2254 if (obj.IsError()) { | 2263 if (obj.IsError()) { |
| 2255 return list; | 2264 return list; |
| 2256 } | 2265 } |
| 2257 CHECK_CALLBACK_STATE(isolate); | 2266 CHECK_CALLBACK_STATE(isolate); |
| 2258 | 2267 |
| 2259 // Check and handle a dart object that implements the List interface. | 2268 // Check and handle a dart object that implements the List interface. |
| 2260 const Instance& instance = | 2269 const Instance& instance = |
| 2261 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 2270 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 2262 if (!instance.IsNull()) { | 2271 if (!instance.IsNull()) { |
| 2272 const int kNumArgs = 3; |
| 2273 ArgumentsDescriptor args_desc( |
| 2274 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
| 2263 const Function& function = Function::Handle( | 2275 const Function& function = Function::Handle( |
| 2264 isolate, | 2276 isolate, |
| 2265 Resolver::ResolveDynamic(instance, | 2277 Resolver::ResolveDynamic(instance, |
| 2266 Symbols::AssignIndexToken(), | 2278 Symbols::AssignIndexToken(), |
| 2267 3, | 2279 args_desc)); |
| 2268 0)); | |
| 2269 if (!function.IsNull()) { | 2280 if (!function.IsNull()) { |
| 2270 Integer& indexobj = Integer::Handle(isolate); | 2281 Integer& indexobj = Integer::Handle(isolate); |
| 2271 Integer& valueobj = Integer::Handle(isolate); | 2282 Integer& valueobj = Integer::Handle(isolate); |
| 2272 const int kNumArgs = 3; | |
| 2273 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 2283 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
| 2274 args.SetAt(0, instance); // Set up the receiver as the first argument. | 2284 args.SetAt(0, instance); // Set up the receiver as the first argument. |
| 2275 for (int i = 0; i < length; i++) { | 2285 for (int i = 0; i < length; i++) { |
| 2276 indexobj = Integer::New(offset + i); | 2286 indexobj = Integer::New(offset + i); |
| 2277 valueobj = Integer::New(native_array[i]); | 2287 valueobj = Integer::New(native_array[i]); |
| 2278 args.SetAt(1, indexobj); | 2288 args.SetAt(1, indexobj); |
| 2279 args.SetAt(2, valueobj); | 2289 args.SetAt(2, valueobj); |
| 2280 const Object& result = Object::Handle( | 2290 const Object& result = Object::Handle( |
| 2281 isolate, DartEntry::InvokeFunction(function, args)); | 2291 isolate, DartEntry::InvokeFunction(function, args)); |
| 2282 if (result.IsError()) { | 2292 if (result.IsError()) { |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2950 return Api::NewError("%s: did not find static method '%s.%s'.", | 2960 return Api::NewError("%s: did not find static method '%s.%s'.", |
| 2951 CURRENT_FUNC, | 2961 CURRENT_FUNC, |
| 2952 cls_name.ToCString(), | 2962 cls_name.ToCString(), |
| 2953 function_name.ToCString()); | 2963 function_name.ToCString()); |
| 2954 } | 2964 } |
| 2955 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, args)); | 2965 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, args)); |
| 2956 | 2966 |
| 2957 } else if (obj.IsNull() || obj.IsInstance()) { | 2967 } else if (obj.IsNull() || obj.IsInstance()) { |
| 2958 Instance& instance = Instance::Handle(isolate); | 2968 Instance& instance = Instance::Handle(isolate); |
| 2959 instance ^= obj.raw(); | 2969 instance ^= obj.raw(); |
| 2970 ArgumentsDescriptor args_desc( |
| 2971 Array::Handle(ArgumentsDescriptor::New(number_of_arguments + 1))); |
| 2960 const Function& function = Function::Handle( | 2972 const Function& function = Function::Handle( |
| 2961 isolate, | 2973 isolate, |
| 2962 Resolver::ResolveDynamic(instance, | 2974 Resolver::ResolveDynamic(instance, function_name, args_desc)); |
| 2963 function_name, | |
| 2964 (number_of_arguments + 1), | |
| 2965 Resolver::kIsQualified)); | |
| 2966 args.SetAt(0, instance); | 2975 args.SetAt(0, instance); |
| 2967 if (function.IsNull()) { | 2976 if (function.IsNull()) { |
| 2968 const Array& args_descriptor = | 2977 const Array& args_descriptor = |
| 2969 Array::Handle(ArgumentsDescriptor::New(args.Length())); | 2978 Array::Handle(ArgumentsDescriptor::New(args.Length())); |
| 2970 return Api::NewHandle(isolate, | 2979 return Api::NewHandle(isolate, |
| 2971 DartEntry::InvokeNoSuchMethod(instance, | 2980 DartEntry::InvokeNoSuchMethod(instance, |
| 2972 function_name, | 2981 function_name, |
| 2973 args, | 2982 args, |
| 2974 args_descriptor)); | 2983 args_descriptor)); |
| 2975 } | 2984 } |
| (...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3995 } | 4004 } |
| 3996 { | 4005 { |
| 3997 NoGCScope no_gc; | 4006 NoGCScope no_gc; |
| 3998 RawObject* raw_obj = obj.raw(); | 4007 RawObject* raw_obj = obj.raw(); |
| 3999 isolate->heap()->SetPeer(raw_obj, peer); | 4008 isolate->heap()->SetPeer(raw_obj, peer); |
| 4000 } | 4009 } |
| 4001 return Api::Success(); | 4010 return Api::Success(); |
| 4002 } | 4011 } |
| 4003 | 4012 |
| 4004 } // namespace dart | 4013 } // namespace dart |
| OLD | NEW |