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 1818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1829 if (str_obj.IsNull()) { | 1829 if (str_obj.IsNull()) { |
1830 RETURN_TYPE_ERROR(isolate, str, String); | 1830 RETURN_TYPE_ERROR(isolate, str, String); |
1831 } | 1831 } |
1832 if (array == NULL) { | 1832 if (array == NULL) { |
1833 RETURN_NULL_ERROR(array); | 1833 RETURN_NULL_ERROR(array); |
1834 } | 1834 } |
1835 intptr_t str_size = (str_obj.Length() * str_obj.CharSize()); | 1835 intptr_t str_size = (str_obj.Length() * str_obj.CharSize()); |
1836 if ((length < str_size) || (length > String::kMaxElements)) { | 1836 if ((length < str_size) || (length > String::kMaxElements)) { |
1837 return Api::NewError("Dart_MakeExternalString " | 1837 return Api::NewError("Dart_MakeExternalString " |
1838 "expects argument length to be in the range" | 1838 "expects argument length to be in the range" |
1839 "[%"Pd"..%"Pd"].", | 1839 "[%" Pd "..%" Pd "].", |
1840 str_size, String::kMaxElements); | 1840 str_size, String::kMaxElements); |
1841 } | 1841 } |
1842 if (str_obj.InVMHeap()) { | 1842 if (str_obj.InVMHeap()) { |
1843 // Since the string object is read only we do not externalize | 1843 // Since the string object is read only we do not externalize |
1844 // the string but instead copy the contents of the string into the | 1844 // the string but instead copy the contents of the string into the |
1845 // specified buffer and return a Null object. | 1845 // specified buffer and return a Null object. |
1846 // This ensures that the embedder does not have to call again | 1846 // This ensures that the embedder does not have to call again |
1847 // to get at the contents. | 1847 // to get at the contents. |
1848 intptr_t copy_len = str_obj.Length(); | 1848 intptr_t copy_len = str_obj.Length(); |
1849 if (str_obj.IsOneByteString()) { | 1849 if (str_obj.IsOneByteString()) { |
(...skipping 2022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3872 RETURN_NULL_ERROR(buffer); | 3872 RETURN_NULL_ERROR(buffer); |
3873 } | 3873 } |
3874 NoHeapGrowthControlScope no_growth_control; | 3874 NoHeapGrowthControlScope no_growth_control; |
3875 | 3875 |
3876 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 3876 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
3877 if (!snapshot->IsScriptSnapshot()) { | 3877 if (!snapshot->IsScriptSnapshot()) { |
3878 return Api::NewError("%s expects parameter 'buffer' to be a script type" | 3878 return Api::NewError("%s expects parameter 'buffer' to be a script type" |
3879 " snapshot.", CURRENT_FUNC); | 3879 " snapshot.", CURRENT_FUNC); |
3880 } | 3880 } |
3881 if (snapshot->length() != buffer_len) { | 3881 if (snapshot->length() != buffer_len) { |
3882 return Api::NewError("%s: 'buffer_len' of %"Pd" is not equal to %d which" | 3882 return Api::NewError("%s: 'buffer_len' of %" Pd " is not equal to %d which" |
3883 " is the expected length in the snapshot.", | 3883 " is the expected length in the snapshot.", |
3884 CURRENT_FUNC, buffer_len, snapshot->length()); | 3884 CURRENT_FUNC, buffer_len, snapshot->length()); |
3885 } | 3885 } |
3886 Library& library = | 3886 Library& library = |
3887 Library::Handle(isolate, isolate->object_store()->root_library()); | 3887 Library::Handle(isolate, isolate->object_store()->root_library()); |
3888 if (!library.IsNull()) { | 3888 if (!library.IsNull()) { |
3889 const String& library_url = String::Handle(isolate, library.url()); | 3889 const String& library_url = String::Handle(isolate, library.url()); |
3890 return Api::NewError("%s: A script has already been loaded from '%s'.", | 3890 return Api::NewError("%s: A script has already been loaded from '%s'.", |
3891 CURRENT_FUNC, library_url.ToCString()); | 3891 CURRENT_FUNC, library_url.ToCString()); |
3892 } | 3892 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3974 if (!ambiguity_error_msg.IsNull()) { | 3974 if (!ambiguity_error_msg.IsNull()) { |
3975 return Api::NewError("%s.", ambiguity_error_msg.ToCString()); | 3975 return Api::NewError("%s.", ambiguity_error_msg.ToCString()); |
3976 } | 3976 } |
3977 const String& lib_name = String::Handle(isolate, lib.name()); | 3977 const String& lib_name = String::Handle(isolate, lib.name()); |
3978 return Api::NewError("Type '%s' not found in library '%s'.", | 3978 return Api::NewError("Type '%s' not found in library '%s'.", |
3979 name_str.ToCString(), lib_name.ToCString()); | 3979 name_str.ToCString(), lib_name.ToCString()); |
3980 } | 3980 } |
3981 if (cls.NumTypeArguments() == 0) { | 3981 if (cls.NumTypeArguments() == 0) { |
3982 if (number_of_type_arguments != 0) { | 3982 if (number_of_type_arguments != 0) { |
3983 return Api::NewError("Invalid number of type arguments specified, " | 3983 return Api::NewError("Invalid number of type arguments specified, " |
3984 "got %"Pd" expected 0", number_of_type_arguments); | 3984 "got %" Pd " expected 0", number_of_type_arguments); |
3985 } | 3985 } |
3986 return Api::NewHandle(isolate, Type::NewNonParameterizedType(cls)); | 3986 return Api::NewHandle(isolate, Type::NewNonParameterizedType(cls)); |
3987 } | 3987 } |
3988 intptr_t num_expected_type_arguments = cls.NumTypeParameters(); | 3988 intptr_t num_expected_type_arguments = cls.NumTypeParameters(); |
3989 TypeArguments& type_args_obj = TypeArguments::Handle(); | 3989 TypeArguments& type_args_obj = TypeArguments::Handle(); |
3990 if (number_of_type_arguments > 0) { | 3990 if (number_of_type_arguments > 0) { |
3991 if (type_arguments == NULL) { | 3991 if (type_arguments == NULL) { |
3992 RETURN_NULL_ERROR(type_arguments); | 3992 RETURN_NULL_ERROR(type_arguments); |
3993 } | 3993 } |
3994 if (num_expected_type_arguments != number_of_type_arguments) { | 3994 if (num_expected_type_arguments != number_of_type_arguments) { |
3995 return Api::NewError("Invalid number of type arguments specified, " | 3995 return Api::NewError("Invalid number of type arguments specified, " |
3996 "got %"Pd" expected %"Pd, | 3996 "got %" Pd " expected %" Pd, |
3997 number_of_type_arguments, | 3997 number_of_type_arguments, |
3998 num_expected_type_arguments); | 3998 num_expected_type_arguments); |
3999 } | 3999 } |
4000 const Array& array = Api::UnwrapArrayHandle(isolate, *type_arguments); | 4000 const Array& array = Api::UnwrapArrayHandle(isolate, *type_arguments); |
4001 if (array.IsNull()) { | 4001 if (array.IsNull()) { |
4002 RETURN_TYPE_ERROR(isolate, *type_arguments, Array); | 4002 RETURN_TYPE_ERROR(isolate, *type_arguments, Array); |
4003 } | 4003 } |
4004 if (array.Length() != num_expected_type_arguments) { | 4004 if (array.Length() != num_expected_type_arguments) { |
4005 return Api::NewError("Invalid type arguments specified, expected an " | 4005 return Api::NewError("Invalid type arguments specified, expected an " |
4006 "array of len %"Pd" but got an array of len %"Pd, | 4006 "array of len %" Pd " but got an array of len %" Pd, |
4007 number_of_type_arguments, | 4007 number_of_type_arguments, |
4008 array.Length()); | 4008 array.Length()); |
4009 } | 4009 } |
4010 // Set up the type arguments array. | 4010 // Set up the type arguments array. |
4011 type_args_obj ^= TypeArguments::New(num_expected_type_arguments); | 4011 type_args_obj ^= TypeArguments::New(num_expected_type_arguments); |
4012 AbstractType& type_arg = AbstractType::Handle(); | 4012 AbstractType& type_arg = AbstractType::Handle(); |
4013 for (intptr_t i = 0; i < number_of_type_arguments; i++) { | 4013 for (intptr_t i = 0; i < number_of_type_arguments; i++) { |
4014 type_arg ^= array.At(i); | 4014 type_arg ^= array.At(i); |
4015 type_args_obj.SetTypeAt(i, type_arg); | 4015 type_args_obj.SetTypeAt(i, type_arg); |
4016 } | 4016 } |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4249 } | 4249 } |
4250 { | 4250 { |
4251 NoGCScope no_gc; | 4251 NoGCScope no_gc; |
4252 RawObject* raw_obj = obj.raw(); | 4252 RawObject* raw_obj = obj.raw(); |
4253 isolate->heap()->SetPeer(raw_obj, peer); | 4253 isolate->heap()->SetPeer(raw_obj, peer); |
4254 } | 4254 } |
4255 return Api::Success(); | 4255 return Api::Success(); |
4256 } | 4256 } |
4257 | 4257 |
4258 } // namespace dart | 4258 } // namespace dart |
OLD | NEW |