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 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 DARTSCOPE(isolate); | 1095 DARTSCOPE(isolate); |
1096 return Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id)); | 1096 return Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id)); |
1097 } | 1097 } |
1098 | 1098 |
1099 | 1099 |
1100 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { | 1100 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { |
1101 Isolate* isolate = Isolate::Current(); | 1101 Isolate* isolate = Isolate::Current(); |
1102 DARTSCOPE(isolate); | 1102 DARTSCOPE(isolate); |
1103 Library& isolate_lib = Library::Handle(isolate, Library::IsolateLibrary()); | 1103 Library& isolate_lib = Library::Handle(isolate, Library::IsolateLibrary()); |
1104 ASSERT(!isolate_lib.IsNull()); | 1104 ASSERT(!isolate_lib.IsNull()); |
1105 const String& public_class_name = | 1105 const String& class_name = String::Handle( |
1106 String::Handle(isolate, String::New("_ReceivePortImpl")); | 1106 isolate, isolate_lib.PrivateName(Symbols::_ReceivePortImpl())); |
1107 const String& class_name = | |
1108 String::Handle(isolate, isolate_lib.PrivateName(public_class_name)); | |
1109 const String& function_name = | |
1110 String::Handle(isolate, Symbols::New("_get_or_create")); | |
1111 const int kNumArguments = 1; | 1107 const int kNumArguments = 1; |
1112 const Array& kNoArgNames = Array::Handle(isolate); | |
1113 const Function& function = Function::Handle( | 1108 const Function& function = Function::Handle( |
1114 isolate, | 1109 isolate, |
1115 Resolver::ResolveStatic(isolate_lib, | 1110 Resolver::ResolveStatic(isolate_lib, |
1116 class_name, | 1111 class_name, |
1117 function_name, | 1112 Symbols::_get_or_create(), |
1118 kNumArguments, | 1113 kNumArguments, |
1119 kNoArgNames, | 1114 Object::empty_array(), |
1120 Resolver::kIsQualified)); | 1115 Resolver::kIsQualified)); |
1121 const Array& args = Array::Handle(isolate, Array::New(kNumArguments)); | 1116 const Array& args = Array::Handle(isolate, Array::New(kNumArguments)); |
1122 args.SetAt(0, Integer::Handle(isolate, Integer::New(port_id))); | 1117 args.SetAt(0, Integer::Handle(isolate, Integer::New(port_id))); |
1123 return Api::NewHandle(isolate, DartEntry::InvokeStatic(function, args)); | 1118 return Api::NewHandle(isolate, DartEntry::InvokeStatic(function, args)); |
1124 } | 1119 } |
1125 | 1120 |
1126 | 1121 |
1127 DART_EXPORT Dart_Port Dart_GetMainPortId() { | 1122 DART_EXPORT Dart_Port Dart_GetMainPortId() { |
1128 Isolate* isolate = Isolate::Current(); | 1123 Isolate* isolate = Isolate::Current(); |
1129 CHECK_ISOLATE(isolate); | 1124 CHECK_ISOLATE(isolate); |
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1881 } | 1876 } |
1882 if (obj.IsGrowableObjectArray()) { | 1877 if (obj.IsGrowableObjectArray()) { |
1883 GET_LIST_LENGTH(isolate, GrowableObjectArray, obj, len); | 1878 GET_LIST_LENGTH(isolate, GrowableObjectArray, obj, len); |
1884 } | 1879 } |
1885 // Now check and handle a dart object that implements the List interface. | 1880 // Now check and handle a dart object that implements the List interface. |
1886 const Instance& instance = | 1881 const Instance& instance = |
1887 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 1882 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
1888 if (instance.IsNull()) { | 1883 if (instance.IsNull()) { |
1889 return Api::NewError("Object does not implement the List interface"); | 1884 return Api::NewError("Object does not implement the List interface"); |
1890 } | 1885 } |
1891 String& name = String::Handle(isolate, Symbols::Length()); | 1886 const String& name = String::Handle(Field::GetterName(Symbols::Length())); |
1892 name = Field::GetterName(name); | |
1893 const Function& function = | 1887 const Function& function = |
1894 Function::Handle(isolate, Resolver::ResolveDynamic(instance, name, 1, 0)); | 1888 Function::Handle(isolate, Resolver::ResolveDynamic(instance, name, 1, 0)); |
1895 if (function.IsNull()) { | 1889 if (function.IsNull()) { |
1896 return Api::NewError("List object does not have a 'length' field."); | 1890 return Api::NewError("List object does not have a 'length' field."); |
1897 } | 1891 } |
1898 | 1892 |
1899 const int kNumArgs = 1; | 1893 const int kNumArgs = 1; |
1900 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 1894 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
1901 args.SetAt(0, instance); // Set up the receiver as the first argument. | 1895 args.SetAt(0, instance); // Set up the receiver as the first argument. |
1902 const Object& retval = | 1896 const Object& retval = |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1949 GET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index); | 1943 GET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index); |
1950 } else if (obj.IsError()) { | 1944 } else if (obj.IsError()) { |
1951 return list; | 1945 return list; |
1952 } else { | 1946 } else { |
1953 // Check and handle a dart object that implements the List interface. | 1947 // Check and handle a dart object that implements the List interface. |
1954 const Instance& instance = | 1948 const Instance& instance = |
1955 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 1949 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
1956 if (!instance.IsNull()) { | 1950 if (!instance.IsNull()) { |
1957 const Function& function = Function::Handle( | 1951 const Function& function = Function::Handle( |
1958 isolate, | 1952 isolate, |
1959 Resolver::ResolveDynamic(instance, | 1953 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), 2, 0)); |
1960 Symbols::IndexTokenHandle(), | |
1961 2, | |
1962 0)); | |
1963 if (!function.IsNull()) { | 1954 if (!function.IsNull()) { |
1964 const int kNumArgs = 2; | 1955 const int kNumArgs = 2; |
1965 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 1956 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
1966 const Integer& indexobj = Integer::Handle(isolate, Integer::New(index)); | 1957 const Integer& indexobj = Integer::Handle(isolate, Integer::New(index)); |
1967 args.SetAt(0, instance); | 1958 args.SetAt(0, instance); |
1968 args.SetAt(1, indexobj); | 1959 args.SetAt(1, indexobj); |
1969 return Api::NewHandle(isolate, DartEntry::InvokeDynamic(function, | 1960 return Api::NewHandle(isolate, DartEntry::InvokeDynamic(function, |
1970 args)); | 1961 args)); |
1971 } | 1962 } |
1972 } | 1963 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2004 } else if (obj.IsError()) { | 1995 } else if (obj.IsError()) { |
2005 return list; | 1996 return list; |
2006 } else { | 1997 } else { |
2007 // Check and handle a dart object that implements the List interface. | 1998 // Check and handle a dart object that implements the List interface. |
2008 const Instance& instance = | 1999 const Instance& instance = |
2009 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 2000 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
2010 if (!instance.IsNull()) { | 2001 if (!instance.IsNull()) { |
2011 const Function& function = Function::Handle( | 2002 const Function& function = Function::Handle( |
2012 isolate, | 2003 isolate, |
2013 Resolver::ResolveDynamic(instance, | 2004 Resolver::ResolveDynamic(instance, |
2014 Symbols::AssignIndexTokenHandle(), | 2005 Symbols::AssignIndexToken(), |
2015 3, | 2006 3, |
2016 0)); | 2007 0)); |
2017 if (!function.IsNull()) { | 2008 if (!function.IsNull()) { |
2018 const Integer& index_obj = | 2009 const Integer& index_obj = |
2019 Integer::Handle(isolate, Integer::New(index)); | 2010 Integer::Handle(isolate, Integer::New(index)); |
2020 const Object& value_obj = | 2011 const Object& value_obj = |
2021 Object::Handle(isolate, Api::UnwrapHandle(value)); | 2012 Object::Handle(isolate, Api::UnwrapHandle(value)); |
2022 if (!value_obj.IsNull() && !value_obj.IsInstance()) { | 2013 if (!value_obj.IsNull() && !value_obj.IsInstance()) { |
2023 RETURN_TYPE_ERROR(isolate, value, Instance); | 2014 RETURN_TYPE_ERROR(isolate, value, Instance); |
2024 } | 2015 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2089 length); | 2080 length); |
2090 } else if (obj.IsError()) { | 2081 } else if (obj.IsError()) { |
2091 return list; | 2082 return list; |
2092 } else { | 2083 } else { |
2093 // Check and handle a dart object that implements the List interface. | 2084 // Check and handle a dart object that implements the List interface. |
2094 const Instance& instance = | 2085 const Instance& instance = |
2095 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 2086 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
2096 if (!instance.IsNull()) { | 2087 if (!instance.IsNull()) { |
2097 const Function& function = Function::Handle( | 2088 const Function& function = Function::Handle( |
2098 isolate, | 2089 isolate, |
2099 Resolver::ResolveDynamic(instance, | 2090 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), 2, 0)); |
2100 Symbols::IndexTokenHandle(), | |
2101 2, | |
2102 0)); | |
2103 if (!function.IsNull()) { | 2091 if (!function.IsNull()) { |
2104 Object& result = Object::Handle(isolate); | 2092 Object& result = Object::Handle(isolate); |
2105 Integer& intobj = Integer::Handle(isolate); | 2093 Integer& intobj = Integer::Handle(isolate); |
2106 const int kNumArgs = 2; | 2094 const int kNumArgs = 2; |
2107 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 2095 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
2108 args.SetAt(0, instance); // Set up the receiver as the first argument. | 2096 args.SetAt(0, instance); // Set up the receiver as the first argument. |
2109 for (int i = 0; i < length; i++) { | 2097 for (int i = 0; i < length; i++) { |
2110 intobj = Integer::New(offset + i); | 2098 intobj = Integer::New(offset + i); |
2111 args.SetAt(1, intobj); | 2099 args.SetAt(1, intobj); |
2112 result = DartEntry::InvokeDynamic(function, args); | 2100 result = DartEntry::InvokeDynamic(function, args); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2181 } else if (obj.IsError()) { | 2169 } else if (obj.IsError()) { |
2182 return list; | 2170 return list; |
2183 } else { | 2171 } else { |
2184 // Check and handle a dart object that implements the List interface. | 2172 // Check and handle a dart object that implements the List interface. |
2185 const Instance& instance = | 2173 const Instance& instance = |
2186 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 2174 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
2187 if (!instance.IsNull()) { | 2175 if (!instance.IsNull()) { |
2188 const Function& function = Function::Handle( | 2176 const Function& function = Function::Handle( |
2189 isolate, | 2177 isolate, |
2190 Resolver::ResolveDynamic(instance, | 2178 Resolver::ResolveDynamic(instance, |
2191 Symbols::AssignIndexTokenHandle(), | 2179 Symbols::AssignIndexToken(), |
2192 3, | 2180 3, |
2193 0)); | 2181 0)); |
2194 if (!function.IsNull()) { | 2182 if (!function.IsNull()) { |
2195 Integer& indexobj = Integer::Handle(isolate); | 2183 Integer& indexobj = Integer::Handle(isolate); |
2196 Integer& valueobj = Integer::Handle(isolate); | 2184 Integer& valueobj = Integer::Handle(isolate); |
2197 const int kNumArgs = 3; | 2185 const int kNumArgs = 3; |
2198 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 2186 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
2199 args.SetAt(0, instance); // Set up the receiver as the first argument. | 2187 args.SetAt(0, instance); // Set up the receiver as the first argument. |
2200 for (int i = 0; i < length; i++) { | 2188 for (int i = 0; i < length; i++) { |
2201 indexobj = Integer::New(offset + i); | 2189 indexobj = Integer::New(offset + i); |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2792 | 2780 |
2793 // Case 3. Lookup the funciton with the getter prefix prepended. | 2781 // Case 3. Lookup the funciton with the getter prefix prepended. |
2794 if (func.IsNull()) { | 2782 if (func.IsNull()) { |
2795 tmp_name = Field::GetterName(func_name); | 2783 tmp_name = Field::GetterName(func_name); |
2796 func = cls.LookupFunction(tmp_name); | 2784 func = cls.LookupFunction(tmp_name); |
2797 } | 2785 } |
2798 | 2786 |
2799 // Case 4. Lookup the function with a . appended to find the | 2787 // Case 4. Lookup the function with a . appended to find the |
2800 // unnamed constructor. | 2788 // unnamed constructor. |
2801 if (func.IsNull()) { | 2789 if (func.IsNull()) { |
2802 tmp_name = String::Concat(func_name, Symbols::DotHandle()); | 2790 tmp_name = String::Concat(func_name, Symbols::Dot()); |
2803 func = cls.LookupFunction(tmp_name); | 2791 func = cls.LookupFunction(tmp_name); |
2804 } | 2792 } |
2805 } else if (obj.IsLibrary()) { | 2793 } else if (obj.IsLibrary()) { |
2806 const Library& lib = Library::Cast(obj); | 2794 const Library& lib = Library::Cast(obj); |
2807 | 2795 |
2808 // Case 1. Lookup the unmodified function name. | 2796 // Case 1. Lookup the unmodified function name. |
2809 func = lib.LookupFunctionAllowPrivate(func_name); | 2797 func = lib.LookupFunctionAllowPrivate(func_name); |
2810 | 2798 |
2811 // Case 2. Lookup the function without the external setter suffix | 2799 // Case 2. Lookup the function without the external setter suffix |
2812 // '='. Make sure to do this check after the regular lookup, so | 2800 // '='. Make sure to do this check after the regular lookup, so |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3357 RETURN_TYPE_ERROR(isolate, clazz, Class); | 3345 RETURN_TYPE_ERROR(isolate, clazz, Class); |
3358 } | 3346 } |
3359 String& base_constructor_name = String::Handle(); | 3347 String& base_constructor_name = String::Handle(); |
3360 base_constructor_name = cls.Name(); | 3348 base_constructor_name = cls.Name(); |
3361 | 3349 |
3362 // And get the name of the constructor to invoke. | 3350 // And get the name of the constructor to invoke. |
3363 String& dot_name = String::Handle(isolate); | 3351 String& dot_name = String::Handle(isolate); |
3364 const Object& name_obj = | 3352 const Object& name_obj = |
3365 Object::Handle(isolate, Api::UnwrapHandle(constructor_name)); | 3353 Object::Handle(isolate, Api::UnwrapHandle(constructor_name)); |
3366 if (name_obj.IsNull()) { | 3354 if (name_obj.IsNull()) { |
3367 dot_name = Symbols::Dot(); | 3355 dot_name = Symbols::Dot().raw(); |
3368 } else if (name_obj.IsString()) { | 3356 } else if (name_obj.IsString()) { |
3369 dot_name = String::Concat(Symbols::DotHandle(), String::Cast(name_obj)); | 3357 dot_name = String::Concat(Symbols::Dot(), String::Cast(name_obj)); |
3370 } else { | 3358 } else { |
3371 RETURN_TYPE_ERROR(isolate, constructor_name, String); | 3359 RETURN_TYPE_ERROR(isolate, constructor_name, String); |
3372 } | 3360 } |
3373 const char* msg = CheckIsolateState(isolate); | 3361 const char* msg = CheckIsolateState(isolate); |
3374 if (msg != NULL) { | 3362 if (msg != NULL) { |
3375 return Api::NewError("%s", msg); | 3363 return Api::NewError("%s", msg); |
3376 } | 3364 } |
3377 | 3365 |
3378 // Resolve the constructor. | 3366 // Resolve the constructor. |
3379 result = ResolveConstructor( | 3367 result = ResolveConstructor( |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3503 if (msg != NULL) { | 3491 if (msg != NULL) { |
3504 return Api::NewError("%s", msg); | 3492 return Api::NewError("%s", msg); |
3505 } | 3493 } |
3506 | 3494 |
3507 const Class& cls = Class::Cast(obj); | 3495 const Class& cls = Class::Cast(obj); |
3508 const Function& function = Function::Handle( | 3496 const Function& function = Function::Handle( |
3509 isolate, | 3497 isolate, |
3510 Resolver::ResolveStatic(cls, | 3498 Resolver::ResolveStatic(cls, |
3511 function_name, | 3499 function_name, |
3512 number_of_arguments, | 3500 number_of_arguments, |
3513 Array::Handle(isolate), | 3501 Object::empty_array(), |
3514 Resolver::kIsQualified)); | 3502 Resolver::kIsQualified)); |
3515 if (function.IsNull()) { | 3503 if (function.IsNull()) { |
3516 const String& cls_name = String::Handle(isolate, cls.Name()); | 3504 const String& cls_name = String::Handle(isolate, cls.Name()); |
3517 return Api::NewError("%s: did not find static method '%s.%s'.", | 3505 return Api::NewError("%s: did not find static method '%s.%s'.", |
3518 CURRENT_FUNC, | 3506 CURRENT_FUNC, |
3519 cls_name.ToCString(), | 3507 cls_name.ToCString(), |
3520 function_name.ToCString()); | 3508 function_name.ToCString()); |
3521 } | 3509 } |
3522 return Api::NewHandle(isolate, DartEntry::InvokeStatic(function, args)); | 3510 return Api::NewHandle(isolate, DartEntry::InvokeStatic(function, args)); |
3523 | 3511 |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4333 if (library_vm.IsNull()) { | 4321 if (library_vm.IsNull()) { |
4334 RETURN_TYPE_ERROR(isolate, library, Library); | 4322 RETURN_TYPE_ERROR(isolate, library, Library); |
4335 } | 4323 } |
4336 const Library& import_vm = Api::UnwrapLibraryHandle(isolate, import); | 4324 const Library& import_vm = Api::UnwrapLibraryHandle(isolate, import); |
4337 if (import_vm.IsNull()) { | 4325 if (import_vm.IsNull()) { |
4338 RETURN_TYPE_ERROR(isolate, import, Library); | 4326 RETURN_TYPE_ERROR(isolate, import, Library); |
4339 } | 4327 } |
4340 const Object& prefix_object = | 4328 const Object& prefix_object = |
4341 Object::Handle(isolate, Api::UnwrapHandle(prefix)); | 4329 Object::Handle(isolate, Api::UnwrapHandle(prefix)); |
4342 const String& prefix_vm = prefix_object.IsNull() | 4330 const String& prefix_vm = prefix_object.IsNull() |
4343 ? String::Handle(isolate, Symbols::New("")) | 4331 ? Symbols::Empty() |
4344 : String::Cast(prefix_object); | 4332 : String::Cast(prefix_object); |
4345 if (prefix_vm.IsNull()) { | 4333 if (prefix_vm.IsNull()) { |
4346 RETURN_TYPE_ERROR(isolate, prefix, String); | 4334 RETURN_TYPE_ERROR(isolate, prefix, String); |
4347 } | 4335 } |
4348 const String& prefix_symbol = | 4336 const String& prefix_symbol = |
4349 String::Handle(isolate, Symbols::New(prefix_vm)); | 4337 String::Handle(isolate, Symbols::New(prefix_vm)); |
4350 const Namespace& import_ns = Namespace::Handle( | 4338 const Namespace& import_ns = Namespace::Handle( |
4351 Namespace::New(import_vm, Array::Handle(), Array::Handle())); | 4339 Namespace::New(import_vm, Array::Handle(), Array::Handle())); |
4352 if (prefix_vm.Length() == 0) { | 4340 if (prefix_vm.Length() == 0) { |
4353 library_vm.AddImport(import_ns); | 4341 library_vm.AddImport(import_ns); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4477 } | 4465 } |
4478 { | 4466 { |
4479 NoGCScope no_gc; | 4467 NoGCScope no_gc; |
4480 RawObject* raw_obj = obj.raw(); | 4468 RawObject* raw_obj = obj.raw(); |
4481 isolate->heap()->SetPeer(raw_obj, peer); | 4469 isolate->heap()->SetPeer(raw_obj, peer); |
4482 } | 4470 } |
4483 return Api::Success(isolate); | 4471 return Api::Success(isolate); |
4484 } | 4472 } |
4485 | 4473 |
4486 } // namespace dart | 4474 } // namespace dart |
OLD | NEW |