Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 1401643002: Remove isolate parameter when allocating handles (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Sync Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 } 79 }
80 80
81 81
82 #if defined(DEBUG) 82 #if defined(DEBUG)
83 // An object visitor which will iterate over all the function objects in the 83 // An object visitor which will iterate over all the function objects in the
84 // heap and check if the result type and parameter types are canonicalized 84 // heap and check if the result type and parameter types are canonicalized
85 // or not. An assertion is raised if a type is not canonicalized. 85 // or not. An assertion is raised if a type is not canonicalized.
86 class FunctionVisitor : public ObjectVisitor { 86 class FunctionVisitor : public ObjectVisitor {
87 public: 87 public:
88 explicit FunctionVisitor(Isolate* isolate) : 88 explicit FunctionVisitor(Thread* thread) :
89 ObjectVisitor(isolate), 89 ObjectVisitor(thread->isolate()),
90 classHandle_(Class::Handle(isolate)), 90 classHandle_(Class::Handle(thread->zone())),
91 funcHandle_(Function::Handle(isolate)), 91 funcHandle_(Function::Handle(thread->zone())),
92 typeHandle_(AbstractType::Handle(isolate)) {} 92 typeHandle_(AbstractType::Handle(thread->zone())) {}
93 93
94 void VisitObject(RawObject* obj) { 94 void VisitObject(RawObject* obj) {
95 if (obj->IsFunction()) { 95 if (obj->IsFunction()) {
96 funcHandle_ ^= obj; 96 funcHandle_ ^= obj;
97 classHandle_ ^= funcHandle_.Owner(); 97 classHandle_ ^= funcHandle_.Owner();
98 // Verify that the result type of a function is canonical or a 98 // Verify that the result type of a function is canonical or a
99 // TypeParameter. 99 // TypeParameter.
100 typeHandle_ ^= funcHandle_.result_type(); 100 typeHandle_ ^= funcHandle_.result_type();
101 ASSERT(typeHandle_.IsNull() || 101 ASSERT(typeHandle_.IsNull() ||
102 !typeHandle_.IsResolved() || 102 !typeHandle_.IsResolved() ||
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 Dart::IsReadOnlyApiHandle(object)); 390 Dart::IsReadOnlyApiHandle(object));
391 ASSERT(FinalizablePersistentHandle::raw_offset() == 0 && 391 ASSERT(FinalizablePersistentHandle::raw_offset() == 0 &&
392 PersistentHandle::raw_offset() == 0 && 392 PersistentHandle::raw_offset() == 0 &&
393 LocalHandle::raw_offset() == 0); 393 LocalHandle::raw_offset() == 0);
394 #endif 394 #endif
395 return (reinterpret_cast<LocalHandle*>(object))->raw(); 395 return (reinterpret_cast<LocalHandle*>(object))->raw();
396 } 396 }
397 397
398 398
399 #define DEFINE_UNWRAP(type) \ 399 #define DEFINE_UNWRAP(type) \
400 const type& Api::Unwrap##type##Handle(Isolate* iso, \ 400 const type& Api::Unwrap##type##Handle(Zone* zone, \
401 Dart_Handle dart_handle) { \ 401 Dart_Handle dart_handle) { \
402 const Object& obj = Object::Handle(iso, Api::UnwrapHandle(dart_handle)); \ 402 const Object& obj = Object::Handle(zone, Api::UnwrapHandle(dart_handle)); \
403 if (obj.Is##type()) { \ 403 if (obj.Is##type()) { \
404 return type::Cast(obj); \ 404 return type::Cast(obj); \
405 } \ 405 } \
406 return type::Handle(iso); \ 406 return type::Handle(zone ); \
407 } 407 }
408 CLASS_LIST_FOR_HANDLES(DEFINE_UNWRAP) 408 CLASS_LIST_FOR_HANDLES(DEFINE_UNWRAP)
409 #undef DEFINE_UNWRAP 409 #undef DEFINE_UNWRAP
410 410
411 411
412 const String& Api::UnwrapStringHandle(const ReusableObjectHandleScope& reuse, 412 const String& Api::UnwrapStringHandle(const ReusableObjectHandleScope& reuse,
413 Dart_Handle dart_handle) { 413 Dart_Handle dart_handle) {
414 Object& ref = reuse.Handle(); 414 Object& ref = reuse.Handle();
415 ref = Api::UnwrapHandle(dart_handle); 415 ref = Api::UnwrapHandle(dart_handle);
416 if (ref.IsString()) { 416 if (ref.IsString()) {
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 823
824 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) { 824 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) {
825 DARTSCOPE(Thread::Current()); 825 DARTSCOPE(Thread::Current());
826 CHECK_CALLBACK_STATE(I); 826 CHECK_CALLBACK_STATE(I);
827 827
828 Instance& obj = Instance::Handle(Z); 828 Instance& obj = Instance::Handle(Z);
829 intptr_t class_id = Api::ClassId(exception); 829 intptr_t class_id = Api::ClassId(exception);
830 if ((class_id == kApiErrorCid) || (class_id == kLanguageErrorCid)) { 830 if ((class_id == kApiErrorCid) || (class_id == kLanguageErrorCid)) {
831 obj = String::New(::Dart_GetError(exception)); 831 obj = String::New(::Dart_GetError(exception));
832 } else { 832 } else {
833 obj = Api::UnwrapInstanceHandle(I, exception).raw(); 833 obj = Api::UnwrapInstanceHandle(Z, exception).raw();
834 if (obj.IsNull()) { 834 if (obj.IsNull()) {
835 RETURN_TYPE_ERROR(I, exception, Instance); 835 RETURN_TYPE_ERROR(Z, exception, Instance);
836 } 836 }
837 } 837 }
838 const Stacktrace& stacktrace = Stacktrace::Handle(Z); 838 const Stacktrace& stacktrace = Stacktrace::Handle(Z);
839 return Api::NewHandle(I, UnhandledException::New(obj, stacktrace)); 839 return Api::NewHandle(I, UnhandledException::New(obj, stacktrace));
840 } 840 }
841 841
842 842
843 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { 843 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) {
844 Isolate* isolate = Isolate::Current(); 844 Thread* thread = Thread::Current();
845 Isolate* isolate = thread->isolate();
845 { 846 {
846 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); 847 const Object& obj = Object::Handle(thread->zone(),
848 Api::UnwrapHandle(handle));
847 if (!obj.IsError()) { 849 if (!obj.IsError()) {
848 return Api::NewError( 850 return Api::NewError(
849 "%s expects argument 'handle' to be an error handle. " 851 "%s expects argument 'handle' to be an error handle. "
850 "Did you forget to check Dart_IsError first?", 852 "Did you forget to check Dart_IsError first?",
851 CURRENT_FUNC); 853 CURRENT_FUNC);
852 } 854 }
853 } 855 }
854 if (isolate->top_exit_frame_info() == 0) { 856 if (isolate->top_exit_frame_info() == 0) {
855 // There are no dart frames on the stack so it would be illegal to 857 // There are no dart frames on the stack so it would be illegal to
856 // propagate an error here. 858 // propagate an error here.
857 return Api::NewError("No Dart frames on stack, cannot propagate error."); 859 return Api::NewError("No Dart frames on stack, cannot propagate error.");
858 } 860 }
859 861
860 // Unwind all the API scopes till the exit frame before propagating. 862 // Unwind all the API scopes till the exit frame before propagating.
861 ApiState* state = isolate->api_state(); 863 ApiState* state = isolate->api_state();
862 ASSERT(state != NULL); 864 ASSERT(state != NULL);
863 const Error* error; 865 const Error* error;
864 { 866 {
865 // We need to preserve the error object across the destruction of zones 867 // We need to preserve the error object across the destruction of zones
866 // when the ApiScopes are unwound. By using NoSafepointScope, we can ensure 868 // when the ApiScopes are unwound. By using NoSafepointScope, we can ensure
867 // that GC won't touch the raw error object before creating a valid 869 // that GC won't touch the raw error object before creating a valid
868 // handle for it in the surviving zone. 870 // handle for it in the surviving zone.
869 NoSafepointScope no_safepoint; 871 NoSafepointScope no_safepoint;
870 RawError* raw_error = Api::UnwrapErrorHandle(isolate, handle).raw(); 872 RawError* raw_error = Api::UnwrapErrorHandle(thread->zone(), handle).raw();
871 state->UnwindScopes(isolate->top_exit_frame_info()); 873 state->UnwindScopes(isolate->top_exit_frame_info());
872 error = &Error::Handle(isolate, raw_error); 874 // Note that thread's zone is different here than at the beginning of this
875 // function.
876 error = &Error::Handle(thread->zone(), raw_error);
873 } 877 }
874 Exceptions::PropagateError(*error); 878 Exceptions::PropagateError(*error);
875 UNREACHABLE(); 879 UNREACHABLE();
876 return Api::NewError("Cannot reach here. Internal error."); 880 return Api::NewError("Cannot reach here. Internal error.");
877 } 881 }
878 882
879 883
880 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, 884 DART_EXPORT void _Dart_ReportErrorHandle(const char* file,
881 int line, 885 int line,
882 const char* handle, 886 const char* handle,
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 if (isolate_snapshot_size == NULL) { 1527 if (isolate_snapshot_size == NULL) {
1524 RETURN_NULL_ERROR(isolate_snapshot_size); 1528 RETURN_NULL_ERROR(isolate_snapshot_size);
1525 } 1529 }
1526 // Finalize all classes if needed. 1530 // Finalize all classes if needed.
1527 Dart_Handle state = Api::CheckAndFinalizePendingClasses(I); 1531 Dart_Handle state = Api::CheckAndFinalizePendingClasses(I);
1528 if (::Dart_IsError(state)) { 1532 if (::Dart_IsError(state)) {
1529 return state; 1533 return state;
1530 } 1534 }
1531 I->heap()->CollectAllGarbage(); 1535 I->heap()->CollectAllGarbage();
1532 #if defined(DEBUG) 1536 #if defined(DEBUG)
1533 FunctionVisitor check_canonical(I); 1537 FunctionVisitor check_canonical(T);
1534 I->heap()->IterateObjects(&check_canonical); 1538 I->heap()->IterateObjects(&check_canonical);
1535 #endif // #if defined(DEBUG). 1539 #endif // #if defined(DEBUG).
1536 1540
1537 // Since this is only a snapshot the root library should not be set. 1541 // Since this is only a snapshot the root library should not be set.
1538 I->object_store()->set_root_library(Library::Handle(Z)); 1542 I->object_store()->set_root_library(Library::Handle(Z));
1539 FullSnapshotWriter writer(vm_isolate_snapshot_buffer, 1543 FullSnapshotWriter writer(vm_isolate_snapshot_buffer,
1540 isolate_snapshot_buffer, 1544 isolate_snapshot_buffer,
1541 NULL, /* instructions_snapshot_buffer */ 1545 NULL, /* instructions_snapshot_buffer */
1542 ApiReallocate, 1546 ApiReallocate,
1543 false, /* snapshot_code */ 1547 false, /* snapshot_code */
(...skipping 21 matching lines...) Expand all
1565 return state; 1569 return state;
1566 } 1570 }
1567 Library& lib = Library::Handle(Z); 1571 Library& lib = Library::Handle(Z);
1568 if (library == Dart_Null()) { 1572 if (library == Dart_Null()) {
1569 lib ^= I->object_store()->root_library(); 1573 lib ^= I->object_store()->root_library();
1570 } else { 1574 } else {
1571 lib ^= Api::UnwrapHandle(library); 1575 lib ^= Api::UnwrapHandle(library);
1572 } 1576 }
1573 I->heap()->CollectAllGarbage(); 1577 I->heap()->CollectAllGarbage();
1574 #if defined(DEBUG) 1578 #if defined(DEBUG)
1575 FunctionVisitor check_canonical(I); 1579 FunctionVisitor check_canonical(T);
1576 I->heap()->IterateObjects(&check_canonical); 1580 I->heap()->IterateObjects(&check_canonical);
1577 #endif // #if defined(DEBUG). 1581 #endif // #if defined(DEBUG).
1578 ScriptSnapshotWriter writer(buffer, ApiReallocate); 1582 ScriptSnapshotWriter writer(buffer, ApiReallocate);
1579 writer.WriteScriptSnapshot(lib); 1583 writer.WriteScriptSnapshot(lib);
1580 *size = writer.BytesWritten(); 1584 *size = writer.BytesWritten();
1581 return Api::Success(); 1585 return Api::Success();
1582 } 1586 }
1583 1587
1584 1588
1585 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, 1589 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer,
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1750 port_id); 1754 port_id);
1751 } 1755 }
1752 return Api::NewHandle(I, SendPort::New(port_id)); 1756 return Api::NewHandle(I, SendPort::New(port_id));
1753 } 1757 }
1754 1758
1755 1759
1756 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, 1760 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port,
1757 Dart_Port* port_id) { 1761 Dart_Port* port_id) {
1758 DARTSCOPE(Thread::Current()); 1762 DARTSCOPE(Thread::Current());
1759 CHECK_CALLBACK_STATE(I); 1763 CHECK_CALLBACK_STATE(I);
1760 const SendPort& send_port = Api::UnwrapSendPortHandle(I, port); 1764 const SendPort& send_port = Api::UnwrapSendPortHandle(Z, port);
1761 if (send_port.IsNull()) { 1765 if (send_port.IsNull()) {
1762 RETURN_TYPE_ERROR(I, port, SendPort); 1766 RETURN_TYPE_ERROR(Z, port, SendPort);
1763 } 1767 }
1764 if (port_id == NULL) { 1768 if (port_id == NULL) {
1765 RETURN_NULL_ERROR(port_id); 1769 RETURN_NULL_ERROR(port_id);
1766 } 1770 }
1767 *port_id = send_port.Id(); 1771 *port_id = send_port.Id();
1768 return Api::Success(); 1772 return Api::Success();
1769 } 1773 }
1770 1774
1771 1775
1772 DART_EXPORT Dart_Port Dart_GetMainPortId() { 1776 DART_EXPORT Dart_Port Dart_GetMainPortId() {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 1879
1876 1880
1877 // TODO(iposva): This call actually implements IsInstanceOfClass. 1881 // TODO(iposva): This call actually implements IsInstanceOfClass.
1878 // Do we also need a real Dart_IsInstanceOf, which should take an instance 1882 // Do we also need a real Dart_IsInstanceOf, which should take an instance
1879 // rather than an object? 1883 // rather than an object?
1880 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, 1884 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object,
1881 Dart_Handle type, 1885 Dart_Handle type,
1882 bool* value) { 1886 bool* value) {
1883 DARTSCOPE(Thread::Current()); 1887 DARTSCOPE(Thread::Current());
1884 1888
1885 const Type& type_obj = Api::UnwrapTypeHandle(I, type); 1889 const Type& type_obj = Api::UnwrapTypeHandle(Z, type);
1886 if (type_obj.IsNull()) { 1890 if (type_obj.IsNull()) {
1887 *value = false; 1891 *value = false;
1888 RETURN_TYPE_ERROR(I, type, Type); 1892 RETURN_TYPE_ERROR(Z, type, Type);
1889 } 1893 }
1890 if (!type_obj.IsFinalized()) { 1894 if (!type_obj.IsFinalized()) {
1891 return Api::NewError( 1895 return Api::NewError(
1892 "%s expects argument 'type' to be a fully resolved type.", 1896 "%s expects argument 'type' to be a fully resolved type.",
1893 CURRENT_FUNC); 1897 CURRENT_FUNC);
1894 } 1898 }
1895 if (object == Api::Null()) { 1899 if (object == Api::Null()) {
1896 *value = false; 1900 *value = false;
1897 return Api::Success(); 1901 return Api::Success();
1898 } 1902 }
1899 const Instance& instance = Api::UnwrapInstanceHandle(I, object); 1903 const Instance& instance = Api::UnwrapInstanceHandle(Z, object);
1900 if (instance.IsNull()) { 1904 if (instance.IsNull()) {
1901 *value = false; 1905 *value = false;
1902 RETURN_TYPE_ERROR(I, object, Instance); 1906 RETURN_TYPE_ERROR(Z, object, Instance);
1903 } 1907 }
1904 CHECK_CALLBACK_STATE(I); 1908 CHECK_CALLBACK_STATE(I);
1905 Error& malformed_type_error = Error::Handle(Z); 1909 Error& malformed_type_error = Error::Handle(Z);
1906 *value = instance.IsInstanceOf(type_obj, 1910 *value = instance.IsInstanceOf(type_obj,
1907 Object::null_type_arguments(), 1911 Object::null_type_arguments(),
1908 &malformed_type_error); 1912 &malformed_type_error);
1909 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. 1913 ASSERT(malformed_type_error.IsNull()); // Type was created from a class.
1910 return Api::Success(); 1914 return Api::Success();
1911 } 1915 }
1912 1916
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 2066
2063 // --- Instances ---- 2067 // --- Instances ----
2064 2068
2065 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) { 2069 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) {
2066 DARTSCOPE(Thread::Current()); 2070 DARTSCOPE(Thread::Current());
2067 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(instance)); 2071 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(instance));
2068 if (obj.IsNull()) { 2072 if (obj.IsNull()) {
2069 return Api::NewHandle(I, I->object_store()->null_type()); 2073 return Api::NewHandle(I, I->object_store()->null_type());
2070 } 2074 }
2071 if (!obj.IsInstance()) { 2075 if (!obj.IsInstance()) {
2072 RETURN_TYPE_ERROR(I, instance, Instance); 2076 RETURN_TYPE_ERROR(Z, instance, Instance);
2073 } 2077 }
2074 const Type& type = Type::Handle(Instance::Cast(obj).GetType()); 2078 const Type& type = Type::Handle(Instance::Cast(obj).GetType());
2075 return Api::NewHandle(I, type.Canonicalize()); 2079 return Api::NewHandle(I, type.Canonicalize());
2076 } 2080 }
2077 2081
2078 2082
2079 // --- Numbers, Integers and Doubles ---- 2083 // --- Numbers, Integers and Doubles ----
2080 2084
2081 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, 2085 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer,
2082 bool* fits) { 2086 bool* fits) {
2083 // Fast path for Smis and Mints. 2087 // Fast path for Smis and Mints.
2084 Thread* thread = Thread::Current(); 2088 Thread* thread = Thread::Current();
2085 Isolate* isolate = thread->isolate(); 2089 Isolate* isolate = thread->isolate();
2086 CHECK_ISOLATE(isolate); 2090 CHECK_ISOLATE(isolate);
2087 intptr_t class_id = Api::ClassId(integer); 2091 intptr_t class_id = Api::ClassId(integer);
2088 if (class_id == kSmiCid || class_id == kMintCid) { 2092 if (class_id == kSmiCid || class_id == kMintCid) {
2089 *fits = true; 2093 *fits = true;
2090 return Api::Success(); 2094 return Api::Success();
2091 } 2095 }
2092 // Slow path for Mints and Bigints. 2096 // Slow path for Mints and Bigints.
2093 DARTSCOPE(thread); 2097 DARTSCOPE(thread);
2094 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); 2098 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer);
2095 if (int_obj.IsNull()) { 2099 if (int_obj.IsNull()) {
2096 RETURN_TYPE_ERROR(isolate, integer, Integer); 2100 RETURN_TYPE_ERROR(Z, integer, Integer);
2097 } 2101 }
2098 ASSERT(!Bigint::Cast(int_obj).FitsIntoInt64()); 2102 ASSERT(!Bigint::Cast(int_obj).FitsIntoInt64());
2099 *fits = false; 2103 *fits = false;
2100 return Api::Success(); 2104 return Api::Success();
2101 } 2105 }
2102 2106
2103 2107
2104 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, 2108 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer,
2105 bool* fits) { 2109 bool* fits) {
2106 // Fast path for Smis. 2110 // Fast path for Smis.
2107 Thread* thread = Thread::Current(); 2111 Thread* thread = Thread::Current();
2108 Isolate* isolate = thread->isolate(); 2112 Isolate* isolate = thread->isolate();
2109 CHECK_ISOLATE(isolate); 2113 CHECK_ISOLATE(isolate);
2110 if (Api::IsSmi(integer)) { 2114 if (Api::IsSmi(integer)) {
2111 *fits = (Api::SmiValue(integer) >= 0); 2115 *fits = (Api::SmiValue(integer) >= 0);
2112 return Api::Success(); 2116 return Api::Success();
2113 } 2117 }
2114 // Slow path for Mints and Bigints. 2118 // Slow path for Mints and Bigints.
2115 DARTSCOPE(thread); 2119 DARTSCOPE(thread);
2116 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); 2120 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer);
2117 if (int_obj.IsNull()) { 2121 if (int_obj.IsNull()) {
2118 RETURN_TYPE_ERROR(isolate, integer, Integer); 2122 RETURN_TYPE_ERROR(Z, integer, Integer);
2119 } 2123 }
2120 ASSERT(!int_obj.IsSmi()); 2124 ASSERT(!int_obj.IsSmi());
2121 if (int_obj.IsMint()) { 2125 if (int_obj.IsMint()) {
2122 *fits = !int_obj.IsNegative(); 2126 *fits = !int_obj.IsNegative();
2123 } else { 2127 } else {
2124 *fits = Bigint::Cast(int_obj).FitsIntoUint64(); 2128 *fits = Bigint::Cast(int_obj).FitsIntoUint64();
2125 } 2129 }
2126 return Api::Success(); 2130 return Api::Success();
2127 } 2131 }
2128 2132
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2163 // Fast path for Smis. 2167 // Fast path for Smis.
2164 Thread* thread = Thread::Current(); 2168 Thread* thread = Thread::Current();
2165 Isolate* isolate = thread->isolate(); 2169 Isolate* isolate = thread->isolate();
2166 CHECK_ISOLATE(isolate); 2170 CHECK_ISOLATE(isolate);
2167 if (Api::IsSmi(integer)) { 2171 if (Api::IsSmi(integer)) {
2168 *value = Api::SmiValue(integer); 2172 *value = Api::SmiValue(integer);
2169 return Api::Success(); 2173 return Api::Success();
2170 } 2174 }
2171 // Slow path for Mints and Bigints. 2175 // Slow path for Mints and Bigints.
2172 DARTSCOPE(thread); 2176 DARTSCOPE(thread);
2173 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); 2177 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer);
2174 if (int_obj.IsNull()) { 2178 if (int_obj.IsNull()) {
2175 RETURN_TYPE_ERROR(isolate, integer, Integer); 2179 RETURN_TYPE_ERROR(Z, integer, Integer);
2176 } 2180 }
2177 ASSERT(!int_obj.IsSmi()); 2181 ASSERT(!int_obj.IsSmi());
2178 if (int_obj.IsMint()) { 2182 if (int_obj.IsMint()) {
2179 *value = int_obj.AsInt64Value(); 2183 *value = int_obj.AsInt64Value();
2180 return Api::Success(); 2184 return Api::Success();
2181 } else { 2185 } else {
2182 const Bigint& bigint = Bigint::Cast(int_obj); 2186 const Bigint& bigint = Bigint::Cast(int_obj);
2183 if (bigint.FitsIntoInt64()) { 2187 if (bigint.FitsIntoInt64()) {
2184 *value = bigint.AsInt64Value(); 2188 *value = bigint.AsInt64Value();
2185 return Api::Success(); 2189 return Api::Success();
(...skipping 12 matching lines...) Expand all
2198 CHECK_ISOLATE(isolate); 2202 CHECK_ISOLATE(isolate);
2199 if (Api::IsSmi(integer)) { 2203 if (Api::IsSmi(integer)) {
2200 intptr_t smi_value = Api::SmiValue(integer); 2204 intptr_t smi_value = Api::SmiValue(integer);
2201 if (smi_value >= 0) { 2205 if (smi_value >= 0) {
2202 *value = smi_value; 2206 *value = smi_value;
2203 return Api::Success(); 2207 return Api::Success();
2204 } 2208 }
2205 } 2209 }
2206 // Slow path for Mints and Bigints. 2210 // Slow path for Mints and Bigints.
2207 DARTSCOPE(thread); 2211 DARTSCOPE(thread);
2208 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); 2212 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer);
2209 if (int_obj.IsNull()) { 2213 if (int_obj.IsNull()) {
2210 RETURN_TYPE_ERROR(isolate, integer, Integer); 2214 RETURN_TYPE_ERROR(Z, integer, Integer);
2211 } 2215 }
2212 if (int_obj.IsSmi()) { 2216 if (int_obj.IsSmi()) {
2213 ASSERT(int_obj.IsNegative()); 2217 ASSERT(int_obj.IsNegative());
2214 } else if (int_obj.IsMint() && !int_obj.IsNegative()) { 2218 } else if (int_obj.IsMint() && !int_obj.IsNegative()) {
2215 *value = int_obj.AsInt64Value(); 2219 *value = int_obj.AsInt64Value();
2216 return Api::Success(); 2220 return Api::Success();
2217 } else { 2221 } else {
2218 const Bigint& bigint = Bigint::Cast(int_obj); 2222 const Bigint& bigint = Bigint::Cast(int_obj);
2219 if (bigint.FitsIntoUint64()) { 2223 if (bigint.FitsIntoUint64()) {
2220 *value = bigint.AsUint64Value(); 2224 *value = bigint.AsUint64Value();
2221 return Api::Success(); 2225 return Api::Success();
2222 } 2226 }
2223 } 2227 }
2224 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", 2228 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.",
2225 CURRENT_FUNC, int_obj.ToCString()); 2229 CURRENT_FUNC, int_obj.ToCString());
2226 } 2230 }
2227 2231
2228 2232
2229 static uword BigintAllocate(intptr_t size) { 2233 static uword BigintAllocate(intptr_t size) {
2230 return Api::TopScope(Isolate::Current())->zone()->AllocUnsafe(size); 2234 return Api::TopScope(Isolate::Current())->zone()->AllocUnsafe(size);
2231 } 2235 }
2232 2236
2233 2237
2234 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, 2238 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer,
2235 const char** value) { 2239 const char** value) {
2236 DARTSCOPE(Thread::Current()); 2240 DARTSCOPE(Thread::Current());
2237 const Integer& int_obj = Api::UnwrapIntegerHandle(I, integer); 2241 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer);
2238 if (int_obj.IsNull()) { 2242 if (int_obj.IsNull()) {
2239 RETURN_TYPE_ERROR(I, integer, Integer); 2243 RETURN_TYPE_ERROR(Z, integer, Integer);
2240 } 2244 }
2241 if (int_obj.IsSmi() || int_obj.IsMint()) { 2245 if (int_obj.IsSmi() || int_obj.IsMint()) {
2242 const Bigint& bigint = Bigint::Handle(Z, 2246 const Bigint& bigint = Bigint::Handle(Z,
2243 Bigint::NewFromInt64(int_obj.AsInt64Value())); 2247 Bigint::NewFromInt64(int_obj.AsInt64Value()));
2244 *value = bigint.ToHexCString(BigintAllocate); 2248 *value = bigint.ToHexCString(BigintAllocate);
2245 } else { 2249 } else {
2246 *value = Bigint::Cast(int_obj).ToHexCString(BigintAllocate); 2250 *value = Bigint::Cast(int_obj).ToHexCString(BigintAllocate);
2247 } 2251 }
2248 return Api::Success(); 2252 return Api::Success();
2249 } 2253 }
2250 2254
2251 2255
2252 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { 2256 DART_EXPORT Dart_Handle Dart_NewDouble(double value) {
2253 DARTSCOPE(Thread::Current()); 2257 DARTSCOPE(Thread::Current());
2254 CHECK_CALLBACK_STATE(I); 2258 CHECK_CALLBACK_STATE(I);
2255 return Api::NewHandle(I, Double::New(value)); 2259 return Api::NewHandle(I, Double::New(value));
2256 } 2260 }
2257 2261
2258 2262
2259 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, 2263 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj,
2260 double* value) { 2264 double* value) {
2261 DARTSCOPE(Thread::Current()); 2265 DARTSCOPE(Thread::Current());
2262 const Double& obj = Api::UnwrapDoubleHandle(I, double_obj); 2266 const Double& obj = Api::UnwrapDoubleHandle(Z, double_obj);
2263 if (obj.IsNull()) { 2267 if (obj.IsNull()) {
2264 RETURN_TYPE_ERROR(I, double_obj, Double); 2268 RETURN_TYPE_ERROR(Z, double_obj, Double);
2265 } 2269 }
2266 *value = obj.value(); 2270 *value = obj.value();
2267 return Api::Success(); 2271 return Api::Success();
2268 } 2272 }
2269 2273
2270 2274
2271 // --- Booleans ---- 2275 // --- Booleans ----
2272 2276
2273 DART_EXPORT Dart_Handle Dart_True() { 2277 DART_EXPORT Dart_Handle Dart_True() {
2274 ASSERT(Isolate::Current() != NULL); 2278 ASSERT(Isolate::Current() != NULL);
(...skipping 10 matching lines...) Expand all
2285 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) { 2289 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) {
2286 Isolate* isolate = Isolate::Current(); 2290 Isolate* isolate = Isolate::Current();
2287 CHECK_ISOLATE(isolate); 2291 CHECK_ISOLATE(isolate);
2288 return value ? Api::True() : Api::False(); 2292 return value ? Api::True() : Api::False();
2289 } 2293 }
2290 2294
2291 2295
2292 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle boolean_obj, 2296 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle boolean_obj,
2293 bool* value) { 2297 bool* value) {
2294 DARTSCOPE(Thread::Current()); 2298 DARTSCOPE(Thread::Current());
2295 const Bool& obj = Api::UnwrapBoolHandle(I, boolean_obj); 2299 const Bool& obj = Api::UnwrapBoolHandle(Z, boolean_obj);
2296 if (obj.IsNull()) { 2300 if (obj.IsNull()) {
2297 RETURN_TYPE_ERROR(I, boolean_obj, Bool); 2301 RETURN_TYPE_ERROR(Z, boolean_obj, Bool);
2298 } 2302 }
2299 *value = obj.value(); 2303 *value = obj.value();
2300 return Api::Success(); 2304 return Api::Success();
2301 } 2305 }
2302 2306
2303 2307
2304 // --- Strings --- 2308 // --- Strings ---
2305 2309
2306 2310
2307 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) { 2311 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) {
2308 Thread* thread = Thread::Current(); 2312 Thread* thread = Thread::Current();
2309 CHECK_ISOLATE(thread->isolate()); 2313 CHECK_ISOLATE(thread->isolate());
2310 ReusableObjectHandleScope reused_obj_handle(thread); 2314 ReusableObjectHandleScope reused_obj_handle(thread);
2311 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str); 2315 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str);
2312 if (str_obj.IsNull()) { 2316 if (str_obj.IsNull()) {
2313 RETURN_TYPE_ERROR(thread->isolate(), str, String); 2317 RETURN_TYPE_ERROR(thread->zone(), str, String);
2314 } 2318 }
2315 *len = str_obj.Length(); 2319 *len = str_obj.Length();
2316 return Api::Success(); 2320 return Api::Success();
2317 } 2321 }
2318 2322
2319 2323
2320 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) { 2324 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) {
2321 DARTSCOPE(Thread::Current()); 2325 DARTSCOPE(Thread::Current());
2322 if (str == NULL) { 2326 if (str == NULL) {
2323 RETURN_NULL_ERROR(str); 2327 RETURN_NULL_ERROR(str);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2406 SpaceForExternal(I, bytes))); 2410 SpaceForExternal(I, bytes)));
2407 } 2411 }
2408 2412
2409 2413
2410 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, 2414 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object,
2411 const char** cstr) { 2415 const char** cstr) {
2412 DARTSCOPE(Thread::Current()); 2416 DARTSCOPE(Thread::Current());
2413 if (cstr == NULL) { 2417 if (cstr == NULL) {
2414 RETURN_NULL_ERROR(cstr); 2418 RETURN_NULL_ERROR(cstr);
2415 } 2419 }
2416 const String& str_obj = Api::UnwrapStringHandle(I, object); 2420 const String& str_obj = Api::UnwrapStringHandle(Z, object);
2417 if (str_obj.IsNull()) { 2421 if (str_obj.IsNull()) {
2418 RETURN_TYPE_ERROR(I, object, String); 2422 RETURN_TYPE_ERROR(Z, object, String);
2419 } 2423 }
2420 intptr_t string_length = Utf8::Length(str_obj); 2424 intptr_t string_length = Utf8::Length(str_obj);
2421 char* res = Api::TopScope(I)->zone()->Alloc<char>(string_length + 1); 2425 char* res = Api::TopScope(I)->zone()->Alloc<char>(string_length + 1);
2422 if (res == NULL) { 2426 if (res == NULL) {
2423 return Api::NewError("Unable to allocate memory"); 2427 return Api::NewError("Unable to allocate memory");
2424 } 2428 }
2425 const char* string_value = str_obj.ToCString(); 2429 const char* string_value = str_obj.ToCString();
2426 memmove(res, string_value, string_length + 1); 2430 memmove(res, string_value, string_length + 1);
2427 ASSERT(res[string_length] == '\0'); 2431 ASSERT(res[string_length] == '\0');
2428 *cstr = res; 2432 *cstr = res;
2429 return Api::Success(); 2433 return Api::Success();
2430 } 2434 }
2431 2435
2432 2436
2433 DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str, 2437 DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str,
2434 uint8_t** utf8_array, 2438 uint8_t** utf8_array,
2435 intptr_t* length) { 2439 intptr_t* length) {
2436 DARTSCOPE(Thread::Current()); 2440 DARTSCOPE(Thread::Current());
2437 if (utf8_array == NULL) { 2441 if (utf8_array == NULL) {
2438 RETURN_NULL_ERROR(utf8_array); 2442 RETURN_NULL_ERROR(utf8_array);
2439 } 2443 }
2440 if (length == NULL) { 2444 if (length == NULL) {
2441 RETURN_NULL_ERROR(length); 2445 RETURN_NULL_ERROR(length);
2442 } 2446 }
2443 const String& str_obj = Api::UnwrapStringHandle(I, str); 2447 const String& str_obj = Api::UnwrapStringHandle(Z, str);
2444 if (str_obj.IsNull()) { 2448 if (str_obj.IsNull()) {
2445 RETURN_TYPE_ERROR(I, str, String); 2449 RETURN_TYPE_ERROR(Z, str, String);
2446 } 2450 }
2447 intptr_t str_len = Utf8::Length(str_obj); 2451 intptr_t str_len = Utf8::Length(str_obj);
2448 *utf8_array = Api::TopScope(I)->zone()->Alloc<uint8_t>(str_len); 2452 *utf8_array = Api::TopScope(I)->zone()->Alloc<uint8_t>(str_len);
2449 if (*utf8_array == NULL) { 2453 if (*utf8_array == NULL) {
2450 return Api::NewError("Unable to allocate memory"); 2454 return Api::NewError("Unable to allocate memory");
2451 } 2455 }
2452 str_obj.ToUTF8(*utf8_array, str_len); 2456 str_obj.ToUTF8(*utf8_array, str_len);
2453 *length = str_len; 2457 *length = str_len;
2454 return Api::Success(); 2458 return Api::Success();
2455 } 2459 }
2456 2460
2457 2461
2458 DART_EXPORT Dart_Handle Dart_StringToLatin1(Dart_Handle str, 2462 DART_EXPORT Dart_Handle Dart_StringToLatin1(Dart_Handle str,
2459 uint8_t* latin1_array, 2463 uint8_t* latin1_array,
2460 intptr_t* length) { 2464 intptr_t* length) {
2461 DARTSCOPE(Thread::Current()); 2465 DARTSCOPE(Thread::Current());
2462 if (latin1_array == NULL) { 2466 if (latin1_array == NULL) {
2463 RETURN_NULL_ERROR(latin1_array); 2467 RETURN_NULL_ERROR(latin1_array);
2464 } 2468 }
2465 if (length == NULL) { 2469 if (length == NULL) {
2466 RETURN_NULL_ERROR(length); 2470 RETURN_NULL_ERROR(length);
2467 } 2471 }
2468 const String& str_obj = Api::UnwrapStringHandle(I, str); 2472 const String& str_obj = Api::UnwrapStringHandle(Z, str);
2469 if (str_obj.IsNull() || !str_obj.IsOneByteString()) { 2473 if (str_obj.IsNull() || !str_obj.IsOneByteString()) {
2470 RETURN_TYPE_ERROR(I, str, String); 2474 RETURN_TYPE_ERROR(Z, str, String);
2471 } 2475 }
2472 intptr_t str_len = str_obj.Length(); 2476 intptr_t str_len = str_obj.Length();
2473 intptr_t copy_len = (str_len > *length) ? *length : str_len; 2477 intptr_t copy_len = (str_len > *length) ? *length : str_len;
2474 2478
2475 // We have already asserted that the string object is a Latin-1 string 2479 // We have already asserted that the string object is a Latin-1 string
2476 // so we can copy the characters over using a simple loop. 2480 // so we can copy the characters over using a simple loop.
2477 for (intptr_t i = 0; i < copy_len; i++) { 2481 for (intptr_t i = 0; i < copy_len; i++) {
2478 latin1_array[i] = str_obj.CharAt(i); 2482 latin1_array[i] = str_obj.CharAt(i);
2479 } 2483 }
2480 *length = copy_len; 2484 *length = copy_len;
2481 return Api::Success(); 2485 return Api::Success();
2482 } 2486 }
2483 2487
2484 2488
2485 DART_EXPORT Dart_Handle Dart_StringToUTF16(Dart_Handle str, 2489 DART_EXPORT Dart_Handle Dart_StringToUTF16(Dart_Handle str,
2486 uint16_t* utf16_array, 2490 uint16_t* utf16_array,
2487 intptr_t* length) { 2491 intptr_t* length) {
2488 DARTSCOPE(Thread::Current()); 2492 DARTSCOPE(Thread::Current());
2489 const String& str_obj = Api::UnwrapStringHandle(I, str); 2493 const String& str_obj = Api::UnwrapStringHandle(Z, str);
2490 if (str_obj.IsNull()) { 2494 if (str_obj.IsNull()) {
2491 RETURN_TYPE_ERROR(I, str, String); 2495 RETURN_TYPE_ERROR(Z, str, String);
2492 } 2496 }
2493 intptr_t str_len = str_obj.Length(); 2497 intptr_t str_len = str_obj.Length();
2494 intptr_t copy_len = (str_len > *length) ? *length : str_len; 2498 intptr_t copy_len = (str_len > *length) ? *length : str_len;
2495 for (intptr_t i = 0; i < copy_len; i++) { 2499 for (intptr_t i = 0; i < copy_len; i++) {
2496 utf16_array[i] = str_obj.CharAt(i); 2500 utf16_array[i] = str_obj.CharAt(i);
2497 } 2501 }
2498 *length = copy_len; 2502 *length = copy_len;
2499 return Api::Success(); 2503 return Api::Success();
2500 } 2504 }
2501 2505
2502 2506
2503 DART_EXPORT Dart_Handle Dart_StringStorageSize(Dart_Handle str, 2507 DART_EXPORT Dart_Handle Dart_StringStorageSize(Dart_Handle str,
2504 intptr_t* size) { 2508 intptr_t* size) {
2505 Thread* thread = Thread::Current(); 2509 Thread* thread = Thread::Current();
2506 CHECK_ISOLATE(thread->isolate()); 2510 CHECK_ISOLATE(thread->isolate());
2507 ReusableObjectHandleScope reused_obj_handle(thread); 2511 ReusableObjectHandleScope reused_obj_handle(thread);
2508 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str); 2512 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str);
2509 if (str_obj.IsNull()) { 2513 if (str_obj.IsNull()) {
2510 RETURN_TYPE_ERROR(thread->isolate(), str, String); 2514 RETURN_TYPE_ERROR(thread->zone(), str, String);
2511 } 2515 }
2512 if (size == NULL) { 2516 if (size == NULL) {
2513 RETURN_NULL_ERROR(size); 2517 RETURN_NULL_ERROR(size);
2514 } 2518 }
2515 *size = (str_obj.Length() * str_obj.CharSize()); 2519 *size = (str_obj.Length() * str_obj.CharSize());
2516 return Api::Success(); 2520 return Api::Success();
2517 } 2521 }
2518 2522
2519 2523
2520 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str, 2524 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str,
2521 void* array, 2525 void* array,
2522 intptr_t length, 2526 intptr_t length,
2523 void* peer, 2527 void* peer,
2524 Dart_PeerFinalizer cback) { 2528 Dart_PeerFinalizer cback) {
2525 DARTSCOPE(Thread::Current()); 2529 DARTSCOPE(Thread::Current());
2526 const String& str_obj = Api::UnwrapStringHandle(I, str); 2530 const String& str_obj = Api::UnwrapStringHandle(Z, str);
2527 if (str_obj.IsExternal()) { 2531 if (str_obj.IsExternal()) {
2528 return str; // String is already an external string. 2532 return str; // String is already an external string.
2529 } 2533 }
2530 if (str_obj.IsNull()) { 2534 if (str_obj.IsNull()) {
2531 RETURN_TYPE_ERROR(I, str, String); 2535 RETURN_TYPE_ERROR(Z, str, String);
2532 } 2536 }
2533 if (array == NULL) { 2537 if (array == NULL) {
2534 RETURN_NULL_ERROR(array); 2538 RETURN_NULL_ERROR(array);
2535 } 2539 }
2536 intptr_t str_size = (str_obj.Length() * str_obj.CharSize()); 2540 intptr_t str_size = (str_obj.Length() * str_obj.CharSize());
2537 if ((length < str_size) || (length > String::kMaxElements)) { 2541 if ((length < str_size) || (length > String::kMaxElements)) {
2538 return Api::NewError("Dart_MakeExternalString " 2542 return Api::NewError("Dart_MakeExternalString "
2539 "expects argument length to be in the range" 2543 "expects argument length to be in the range"
2540 "[%" Pd "..%" Pd "].", 2544 "[%" Pd "..%" Pd "].",
2541 str_size, String::kMaxElements); 2545 str_size, String::kMaxElements);
(...skipping 29 matching lines...) Expand all
2571 2575
2572 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object, 2576 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object,
2573 intptr_t* char_size, 2577 intptr_t* char_size,
2574 intptr_t* str_len, 2578 intptr_t* str_len,
2575 void** peer) { 2579 void** peer) {
2576 Thread* thread = Thread::Current(); 2580 Thread* thread = Thread::Current();
2577 CHECK_ISOLATE(thread->isolate()); 2581 CHECK_ISOLATE(thread->isolate());
2578 ReusableObjectHandleScope reused_obj_handle(thread); 2582 ReusableObjectHandleScope reused_obj_handle(thread);
2579 const String& str = Api::UnwrapStringHandle(reused_obj_handle, object); 2583 const String& str = Api::UnwrapStringHandle(reused_obj_handle, object);
2580 if (str.IsNull()) { 2584 if (str.IsNull()) {
2581 RETURN_TYPE_ERROR(thread->isolate(), object, String); 2585 RETURN_TYPE_ERROR(thread->zone(), object, String);
2582 } 2586 }
2583 if (str.IsExternal()) { 2587 if (str.IsExternal()) {
2584 *peer = str.GetPeer(); 2588 *peer = str.GetPeer();
2585 ASSERT(*peer != NULL); 2589 ASSERT(*peer != NULL);
2586 } else { 2590 } else {
2587 NoSafepointScope no_safepoint_scope; 2591 NoSafepointScope no_safepoint_scope;
2588 *peer = thread->isolate()->heap()->GetPeer(str.raw()); 2592 *peer = thread->isolate()->heap()->GetPeer(str.raw());
2589 } 2593 }
2590 *char_size = str.CharSize(); 2594 *char_size = str.CharSize();
2591 *str_len = str.Length(); 2595 *str_len = str.Length();
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2768 } 2772 }
2769 return Api::NewError("Object does not implement the 'List' interface"); 2773 return Api::NewError("Object does not implement the 'List' interface");
2770 } 2774 }
2771 } 2775 }
2772 2776
2773 2777
2774 #define SET_LIST_ELEMENT(type, obj, index, value) \ 2778 #define SET_LIST_ELEMENT(type, obj, index, value) \
2775 const type& array = type::Cast(obj); \ 2779 const type& array = type::Cast(obj); \
2776 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); \ 2780 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); \
2777 if (!value_obj.IsNull() && !value_obj.IsInstance()) { \ 2781 if (!value_obj.IsNull() && !value_obj.IsInstance()) { \
2778 RETURN_TYPE_ERROR(I, value, Instance); \ 2782 RETURN_TYPE_ERROR(Z, value, Instance); \
2779 } \ 2783 } \
2780 if ((index >= 0) && (index < array.Length())) { \ 2784 if ((index >= 0) && (index < array.Length())) { \
2781 array.SetAt(index, value_obj); \ 2785 array.SetAt(index, value_obj); \
2782 return Api::Success(); \ 2786 return Api::Success(); \
2783 } \ 2787 } \
2784 return Api::NewError("Invalid index passed in to set list element"); \ 2788 return Api::NewError("Invalid index passed in to set list element"); \
2785 2789
2786 2790
2787 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, 2791 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list,
2788 intptr_t index, 2792 intptr_t index,
(...skipping 18 matching lines...) Expand all
2807 ArgumentsDescriptor args_desc( 2811 ArgumentsDescriptor args_desc(
2808 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); 2812 Array::Handle(ArgumentsDescriptor::New(kNumArgs)));
2809 const Function& function = Function::Handle(Z, 2813 const Function& function = Function::Handle(Z,
2810 Resolver::ResolveDynamic(instance, 2814 Resolver::ResolveDynamic(instance,
2811 Symbols::AssignIndexToken(), 2815 Symbols::AssignIndexToken(),
2812 args_desc)); 2816 args_desc));
2813 if (!function.IsNull()) { 2817 if (!function.IsNull()) {
2814 const Integer& index_obj = Integer::Handle(Z, Integer::New(index)); 2818 const Integer& index_obj = Integer::Handle(Z, Integer::New(index));
2815 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); 2819 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value));
2816 if (!value_obj.IsNull() && !value_obj.IsInstance()) { 2820 if (!value_obj.IsNull() && !value_obj.IsInstance()) {
2817 RETURN_TYPE_ERROR(I, value, Instance); 2821 RETURN_TYPE_ERROR(Z, value, Instance);
2818 } 2822 }
2819 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); 2823 const Array& args = Array::Handle(Z, Array::New(kNumArgs));
2820 args.SetAt(0, instance); 2824 args.SetAt(0, instance);
2821 args.SetAt(1, index_obj); 2825 args.SetAt(1, index_obj);
2822 args.SetAt(2, value_obj); 2826 args.SetAt(2, value_obj);
2823 return Api::NewHandle(I, DartEntry::InvokeFunction(function, 2827 return Api::NewHandle(I, DartEntry::InvokeFunction(function,
2824 args)); 2828 args));
2825 } 2829 }
2826 } 2830 }
2827 return Api::NewError("Object does not implement the 'List' interface"); 2831 return Api::NewError("Object does not implement the 'List' interface");
2828 } 2832 }
2829 } 2833 }
2830 2834
2831 2835
2832 static RawObject* ResolveConstructor(const char* current_func, 2836 static RawObject* ResolveConstructor(const char* current_func,
2833 const Class& cls, 2837 const Class& cls,
2834 const String& class_name, 2838 const String& class_name,
2835 const String& dotted_name, 2839 const String& dotted_name,
2836 int num_args); 2840 int num_args);
2837 2841
2838 2842
2839 static RawObject* ThrowArgumentError(const char* exception_message) { 2843 static RawObject* ThrowArgumentError(const char* exception_message) {
2840 Thread* thread = Thread::Current(); 2844 Thread* thread = Thread::Current();
2841 Isolate* isolate = thread->isolate(); 2845 Isolate* isolate = thread->isolate();
2846 Zone* zone = thread->zone();
2842 // Lookup the class ArgumentError in dart:core. 2847 // Lookup the class ArgumentError in dart:core.
2843 const String& lib_url = String::Handle(String::New("dart:core")); 2848 const String& lib_url = String::Handle(String::New("dart:core"));
2844 const String& class_name = String::Handle(String::New("ArgumentError")); 2849 const String& class_name = String::Handle(String::New("ArgumentError"));
2845 const Library& lib = 2850 const Library& lib =
2846 Library::Handle(isolate, Library::LookupLibrary(lib_url)); 2851 Library::Handle(zone, Library::LookupLibrary(lib_url));
2847 if (lib.IsNull()) { 2852 if (lib.IsNull()) {
2848 const String& message = String::Handle( 2853 const String& message = String::Handle(
2849 String::NewFormatted("%s: library '%s' not found.", 2854 String::NewFormatted("%s: library '%s' not found.",
2850 CURRENT_FUNC, lib_url.ToCString())); 2855 CURRENT_FUNC, lib_url.ToCString()));
2851 return ApiError::New(message); 2856 return ApiError::New(message);
2852 } 2857 }
2853 const Class& cls = Class::Handle( 2858 const Class& cls = Class::Handle(
2854 isolate, lib.LookupClassAllowPrivate(class_name)); 2859 zone, lib.LookupClassAllowPrivate(class_name));
2855 ASSERT(!cls.IsNull()); 2860 ASSERT(!cls.IsNull());
2856 Object& result = Object::Handle(isolate); 2861 Object& result = Object::Handle(zone);
2857 String& dot_name = String::Handle(String::New(".")); 2862 String& dot_name = String::Handle(String::New("."));
2858 String& constr_name = String::Handle(String::Concat(class_name, dot_name)); 2863 String& constr_name = String::Handle(String::Concat(class_name, dot_name));
2859 result = ResolveConstructor(CURRENT_FUNC, cls, class_name, constr_name, 1); 2864 result = ResolveConstructor(CURRENT_FUNC, cls, class_name, constr_name, 1);
2860 if (result.IsError()) return result.raw(); 2865 if (result.IsError()) return result.raw();
2861 ASSERT(result.IsFunction()); 2866 ASSERT(result.IsFunction());
2862 Function& constructor = Function::Handle(isolate); 2867 Function& constructor = Function::Handle(zone);
2863 constructor ^= result.raw(); 2868 constructor ^= result.raw();
2864 if (!constructor.IsGenerativeConstructor()) { 2869 if (!constructor.IsGenerativeConstructor()) {
2865 const String& message = String::Handle( 2870 const String& message = String::Handle(
2866 String::NewFormatted("%s: class '%s' is not a constructor.", 2871 String::NewFormatted("%s: class '%s' is not a constructor.",
2867 CURRENT_FUNC, class_name.ToCString())); 2872 CURRENT_FUNC, class_name.ToCString()));
2868 return ApiError::New(message); 2873 return ApiError::New(message);
2869 } 2874 }
2870 Instance& exception = Instance::Handle(isolate); 2875 Instance& exception = Instance::Handle(zone);
2871 exception = Instance::New(cls); 2876 exception = Instance::New(cls);
2872 const Array& args = Array::Handle(isolate, Array::New(3)); 2877 const Array& args = Array::Handle(zone, Array::New(3));
2873 args.SetAt(0, exception); 2878 args.SetAt(0, exception);
2874 args.SetAt(1, 2879 args.SetAt(1, Smi::Handle(zone, Smi::New(Function::kCtorPhaseAll)));
2875 Smi::Handle(isolate, Smi::New(Function::kCtorPhaseAll)));
2876 args.SetAt(2, String::Handle(String::New(exception_message))); 2880 args.SetAt(2, String::Handle(String::New(exception_message)));
2877 result = DartEntry::InvokeFunction(constructor, args); 2881 result = DartEntry::InvokeFunction(constructor, args);
2878 if (result.IsError()) return result.raw(); 2882 if (result.IsError()) return result.raw();
2879 ASSERT(result.IsNull()); 2883 ASSERT(result.IsNull());
2880 2884
2881 if (isolate->top_exit_frame_info() == 0) { 2885 if (isolate->top_exit_frame_info() == 0) {
2882 // There are no dart frames on the stack so it would be illegal to 2886 // There are no dart frames on the stack so it would be illegal to
2883 // throw an exception here. 2887 // throw an exception here.
2884 const String& message = String::Handle( 2888 const String& message = String::Handle(
2885 String::New("No Dart frames on stack, cannot throw exception")); 2889 String::New("No Dart frames on stack, cannot throw exception"));
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
3261 3265
3262 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfExternalTypedData( 3266 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfExternalTypedData(
3263 Dart_Handle object) { 3267 Dart_Handle object) {
3264 TRACE_API_CALL(CURRENT_FUNC); 3268 TRACE_API_CALL(CURRENT_FUNC);
3265 intptr_t class_id = Api::ClassId(object); 3269 intptr_t class_id = Api::ClassId(object);
3266 if (RawObject::IsExternalTypedDataClassId(class_id)) { 3270 if (RawObject::IsExternalTypedDataClassId(class_id)) {
3267 return GetType(class_id); 3271 return GetType(class_id);
3268 } 3272 }
3269 if (RawObject::IsTypedDataViewClassId(class_id)) { 3273 if (RawObject::IsTypedDataViewClassId(class_id)) {
3270 // Check if data object of the view is external. 3274 // Check if data object of the view is external.
3271 Isolate* isolate = Isolate::Current(); 3275 Zone* zone = Thread::Current()->zone();
3272 const Instance& view_obj = Api::UnwrapInstanceHandle(isolate, object); 3276 const Instance& view_obj = Api::UnwrapInstanceHandle(zone, object);
3273 ASSERT(!view_obj.IsNull()); 3277 ASSERT(!view_obj.IsNull());
3274 const Instance& data_obj = 3278 const Instance& data_obj =
3275 Instance::Handle(isolate, TypedDataView::Data(view_obj)); 3279 Instance::Handle(zone, TypedDataView::Data(view_obj));
3276 if (ExternalTypedData::IsExternalTypedData(data_obj)) { 3280 if (ExternalTypedData::IsExternalTypedData(data_obj)) {
3277 return GetType(class_id); 3281 return GetType(class_id);
3278 } 3282 }
3279 } 3283 }
3280 return Dart_TypedData_kInvalid; 3284 return Dart_TypedData_kInvalid;
3281 } 3285 }
3282 3286
3283 3287
3284 static RawObject* GetByteDataConstructor(Isolate* isolate, 3288 static RawObject* GetByteDataConstructor(Thread* thread,
3285 const String& constructor_name, 3289 const String& constructor_name,
3286 intptr_t num_args) { 3290 intptr_t num_args) {
3287 const Library& lib = 3291 const Library& lib =
3288 Library::Handle(isolate->object_store()->typed_data_library()); 3292 Library::Handle(thread->isolate()->object_store()->typed_data_library());
3289 ASSERT(!lib.IsNull()); 3293 ASSERT(!lib.IsNull());
3290 const Class& cls = Class::Handle( 3294 const Class& cls = Class::Handle(
3291 isolate, lib.LookupClassAllowPrivate(Symbols::ByteData())); 3295 thread->zone(), lib.LookupClassAllowPrivate(Symbols::ByteData()));
3292 ASSERT(!cls.IsNull()); 3296 ASSERT(!cls.IsNull());
3293 return ResolveConstructor(CURRENT_FUNC, 3297 return ResolveConstructor(CURRENT_FUNC,
3294 cls, 3298 cls,
3295 Symbols::ByteData(), 3299 Symbols::ByteData(),
3296 constructor_name, 3300 constructor_name,
3297 num_args); 3301 num_args);
3298 } 3302 }
3299 3303
3300 3304
3301 static Dart_Handle NewByteData(Isolate* isolate, intptr_t length) { 3305 static Dart_Handle NewByteData(Thread* thread, intptr_t length) {
3302 CHECK_LENGTH(length, TypedData::MaxElements(kTypedDataInt8ArrayCid)); 3306 CHECK_LENGTH(length, TypedData::MaxElements(kTypedDataInt8ArrayCid));
3303 Object& result = Object::Handle(isolate); 3307 Isolate* isolate = thread->isolate();
3304 result = GetByteDataConstructor(isolate, Symbols::ByteDataDot(), 1); 3308 Zone* zone = thread->zone();
3309 Object& result = Object::Handle(zone);
3310 result = GetByteDataConstructor(thread, Symbols::ByteDataDot(), 1);
3305 ASSERT(!result.IsNull()); 3311 ASSERT(!result.IsNull());
3306 ASSERT(result.IsFunction()); 3312 ASSERT(result.IsFunction());
3307 const Function& factory = Function::Cast(result); 3313 const Function& factory = Function::Cast(result);
3308 ASSERT(!factory.IsGenerativeConstructor()); 3314 ASSERT(!factory.IsGenerativeConstructor());
3309 3315
3310 // Create the argument list. 3316 // Create the argument list.
3311 const Array& args = Array::Handle(isolate, Array::New(2)); 3317 const Array& args = Array::Handle(zone, Array::New(2));
3312 // Factories get type arguments. 3318 // Factories get type arguments.
3313 args.SetAt(0, Object::null_type_arguments()); 3319 args.SetAt(0, Object::null_type_arguments());
3314 args.SetAt(1, Smi::Handle(isolate, Smi::New(length))); 3320 args.SetAt(1, Smi::Handle(zone, Smi::New(length)));
3315 3321
3316 // Invoke the constructor and return the new object. 3322 // Invoke the constructor and return the new object.
3317 result = DartEntry::InvokeFunction(factory, args); 3323 result = DartEntry::InvokeFunction(factory, args);
3318 ASSERT(result.IsInstance() || result.IsNull() || result.IsError()); 3324 ASSERT(result.IsInstance() || result.IsNull() || result.IsError());
3319 return Api::NewHandle(isolate, result.raw()); 3325 return Api::NewHandle(isolate, result.raw());
3320 } 3326 }
3321 3327
3322 3328
3323 static Dart_Handle NewTypedData(Isolate* isolate, 3329 static Dart_Handle NewTypedData(Isolate* isolate,
3324 intptr_t cid, 3330 intptr_t cid,
3325 intptr_t length) { 3331 intptr_t length) {
3326 CHECK_LENGTH(length, TypedData::MaxElements(cid)); 3332 CHECK_LENGTH(length, TypedData::MaxElements(cid));
3327 return Api::NewHandle(isolate, TypedData::New(cid, length)); 3333 return Api::NewHandle(isolate, TypedData::New(cid, length));
3328 } 3334 }
3329 3335
3330 3336
3331 static Dart_Handle NewExternalTypedData( 3337 static Dart_Handle NewExternalTypedData(
3332 Isolate* isolate, intptr_t cid, void* data, intptr_t length) { 3338 Thread* thread, intptr_t cid, void* data, intptr_t length) {
3333 CHECK_LENGTH(length, ExternalTypedData::MaxElements(cid)); 3339 CHECK_LENGTH(length, ExternalTypedData::MaxElements(cid));
3340 Isolate* isolate = thread->isolate();
3341 Zone* zone = thread->zone();
3334 intptr_t bytes = length * ExternalTypedData::ElementSizeInBytes(cid); 3342 intptr_t bytes = length * ExternalTypedData::ElementSizeInBytes(cid);
3335 const ExternalTypedData& result = ExternalTypedData::Handle( 3343 const ExternalTypedData& result = ExternalTypedData::Handle(
3336 isolate, 3344 zone,
3337 ExternalTypedData::New(cid, 3345 ExternalTypedData::New(cid,
3338 reinterpret_cast<uint8_t*>(data), 3346 reinterpret_cast<uint8_t*>(data),
3339 length, 3347 length,
3340 SpaceForExternal(isolate, bytes))); 3348 SpaceForExternal(isolate, bytes)));
3341 return Api::NewHandle(isolate, result.raw()); 3349 return Api::NewHandle(isolate, result.raw());
3342 } 3350 }
3343 3351
3344 3352
3345 static Dart_Handle NewExternalByteData( 3353 static Dart_Handle NewExternalByteData(
3346 Isolate* isolate, void* data, intptr_t length) { 3354 Thread* thread, void* data, intptr_t length) {
3355 Zone* zone = thread->zone();
3356 Isolate* isolate = thread->isolate();
3347 Dart_Handle ext_data = NewExternalTypedData( 3357 Dart_Handle ext_data = NewExternalTypedData(
3348 isolate, kExternalTypedDataUint8ArrayCid, data, length); 3358 thread, kExternalTypedDataUint8ArrayCid, data, length);
3349 if (::Dart_IsError(ext_data)) { 3359 if (::Dart_IsError(ext_data)) {
3350 return ext_data; 3360 return ext_data;
3351 } 3361 }
3352 Object& result = Object::Handle(isolate); 3362 Object& result = Object::Handle(zone);
3353 result = GetByteDataConstructor(isolate, Symbols::ByteDataDot_view(), 3); 3363 result = GetByteDataConstructor(thread, Symbols::ByteDataDot_view(), 3);
3354 ASSERT(!result.IsNull()); 3364 ASSERT(!result.IsNull());
3355 ASSERT(result.IsFunction()); 3365 ASSERT(result.IsFunction());
3356 const Function& factory = Function::Cast(result); 3366 const Function& factory = Function::Cast(result);
3357 ASSERT(!factory.IsGenerativeConstructor()); 3367 ASSERT(!factory.IsGenerativeConstructor());
3358 3368
3359 // Create the argument list. 3369 // Create the argument list.
3360 const intptr_t num_args = 3; 3370 const intptr_t num_args = 3;
3361 const Array& args = Array::Handle(isolate, Array::New(num_args + 1)); 3371 const Array& args = Array::Handle(zone, Array::New(num_args + 1));
3362 // Factories get type arguments. 3372 // Factories get type arguments.
3363 args.SetAt(0, Object::null_type_arguments()); 3373 args.SetAt(0, Object::null_type_arguments());
3364 const ExternalTypedData& array = 3374 const ExternalTypedData& array =
3365 Api::UnwrapExternalTypedDataHandle(isolate, ext_data); 3375 Api::UnwrapExternalTypedDataHandle(zone, ext_data);
3366 args.SetAt(1, array); 3376 args.SetAt(1, array);
3367 Smi& smi = Smi::Handle(isolate); 3377 Smi& smi = Smi::Handle(zone);
3368 smi = Smi::New(0); 3378 smi = Smi::New(0);
3369 args.SetAt(2, smi); 3379 args.SetAt(2, smi);
3370 smi = Smi::New(length); 3380 smi = Smi::New(length);
3371 args.SetAt(3, smi); 3381 args.SetAt(3, smi);
3372 3382
3373 // Invoke the constructor and return the new object. 3383 // Invoke the constructor and return the new object.
3374 result = DartEntry::InvokeFunction(factory, args); 3384 result = DartEntry::InvokeFunction(factory, args);
3375 ASSERT(result.IsNull() || result.IsInstance() || result.IsError()); 3385 ASSERT(result.IsNull() || result.IsInstance() || result.IsError());
3376 return Api::NewHandle(isolate, result.raw()); 3386 return Api::NewHandle(isolate, result.raw());
3377 } 3387 }
3378 3388
3379 3389
3380 DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, 3390 DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type,
3381 intptr_t length) { 3391 intptr_t length) {
3382 DARTSCOPE(Thread::Current()); 3392 DARTSCOPE(Thread::Current());
3383 CHECK_CALLBACK_STATE(I); 3393 CHECK_CALLBACK_STATE(I);
3384 switch (type) { 3394 switch (type) {
3385 case Dart_TypedData_kByteData : 3395 case Dart_TypedData_kByteData :
3386 return NewByteData(I, length); 3396 return NewByteData(T, length);
3387 case Dart_TypedData_kInt8 : 3397 case Dart_TypedData_kInt8 :
3388 return NewTypedData(I, kTypedDataInt8ArrayCid, length); 3398 return NewTypedData(I, kTypedDataInt8ArrayCid, length);
3389 case Dart_TypedData_kUint8 : 3399 case Dart_TypedData_kUint8 :
3390 return NewTypedData(I, kTypedDataUint8ArrayCid, length); 3400 return NewTypedData(I, kTypedDataUint8ArrayCid, length);
3391 case Dart_TypedData_kUint8Clamped : 3401 case Dart_TypedData_kUint8Clamped :
3392 return NewTypedData(I, kTypedDataUint8ClampedArrayCid, length); 3402 return NewTypedData(I, kTypedDataUint8ClampedArrayCid, length);
3393 case Dart_TypedData_kInt16 : 3403 case Dart_TypedData_kInt16 :
3394 return NewTypedData(I, kTypedDataInt16ArrayCid, length); 3404 return NewTypedData(I, kTypedDataInt16ArrayCid, length);
3395 case Dart_TypedData_kUint16 : 3405 case Dart_TypedData_kUint16 :
3396 return NewTypedData(I, kTypedDataUint16ArrayCid, length); 3406 return NewTypedData(I, kTypedDataUint16ArrayCid, length);
(...skipping 24 matching lines...) Expand all
3421 Dart_TypedData_Type type, 3431 Dart_TypedData_Type type,
3422 void* data, 3432 void* data,
3423 intptr_t length) { 3433 intptr_t length) {
3424 DARTSCOPE(Thread::Current()); 3434 DARTSCOPE(Thread::Current());
3425 if (data == NULL && length != 0) { 3435 if (data == NULL && length != 0) {
3426 RETURN_NULL_ERROR(data); 3436 RETURN_NULL_ERROR(data);
3427 } 3437 }
3428 CHECK_CALLBACK_STATE(I); 3438 CHECK_CALLBACK_STATE(I);
3429 switch (type) { 3439 switch (type) {
3430 case Dart_TypedData_kByteData: 3440 case Dart_TypedData_kByteData:
3431 return NewExternalByteData(I, data, length); 3441 return NewExternalByteData(T, data, length);
3432 case Dart_TypedData_kInt8: 3442 case Dart_TypedData_kInt8:
3433 return NewExternalTypedData(I, 3443 return NewExternalTypedData(T,
3434 kExternalTypedDataInt8ArrayCid, data, length); 3444 kExternalTypedDataInt8ArrayCid, data, length);
3435 case Dart_TypedData_kUint8: 3445 case Dart_TypedData_kUint8:
3436 return NewExternalTypedData(I, 3446 return NewExternalTypedData(T,
3437 kExternalTypedDataUint8ArrayCid, data, length); 3447 kExternalTypedDataUint8ArrayCid, data, length);
3438 case Dart_TypedData_kUint8Clamped: 3448 case Dart_TypedData_kUint8Clamped:
3439 return NewExternalTypedData(I, 3449 return NewExternalTypedData(T,
3440 kExternalTypedDataUint8ClampedArrayCid, data, length); 3450 kExternalTypedDataUint8ClampedArrayCid, data, length);
3441 case Dart_TypedData_kInt16: 3451 case Dart_TypedData_kInt16:
3442 return NewExternalTypedData(I, 3452 return NewExternalTypedData(T,
3443 kExternalTypedDataInt16ArrayCid, data, length); 3453 kExternalTypedDataInt16ArrayCid, data, length);
3444 case Dart_TypedData_kUint16: 3454 case Dart_TypedData_kUint16:
3445 return NewExternalTypedData(I, 3455 return NewExternalTypedData(T,
3446 kExternalTypedDataUint16ArrayCid, data, length); 3456 kExternalTypedDataUint16ArrayCid, data, length);
3447 case Dart_TypedData_kInt32: 3457 case Dart_TypedData_kInt32:
3448 return NewExternalTypedData(I, 3458 return NewExternalTypedData(T,
3449 kExternalTypedDataInt32ArrayCid, data, length); 3459 kExternalTypedDataInt32ArrayCid, data, length);
3450 case Dart_TypedData_kUint32: 3460 case Dart_TypedData_kUint32:
3451 return NewExternalTypedData(I, 3461 return NewExternalTypedData(T,
3452 kExternalTypedDataUint32ArrayCid, data, length); 3462 kExternalTypedDataUint32ArrayCid, data, length);
3453 case Dart_TypedData_kInt64: 3463 case Dart_TypedData_kInt64:
3454 return NewExternalTypedData(I, 3464 return NewExternalTypedData(T,
3455 kExternalTypedDataInt64ArrayCid, data, length); 3465 kExternalTypedDataInt64ArrayCid, data, length);
3456 case Dart_TypedData_kUint64: 3466 case Dart_TypedData_kUint64:
3457 return NewExternalTypedData(I, 3467 return NewExternalTypedData(T,
3458 kExternalTypedDataUint64ArrayCid, data, length); 3468 kExternalTypedDataUint64ArrayCid, data, length);
3459 case Dart_TypedData_kFloat32: 3469 case Dart_TypedData_kFloat32:
3460 return NewExternalTypedData(I, 3470 return NewExternalTypedData(T,
3461 kExternalTypedDataFloat32ArrayCid, data, length); 3471 kExternalTypedDataFloat32ArrayCid, data, length);
3462 case Dart_TypedData_kFloat64: 3472 case Dart_TypedData_kFloat64:
3463 return NewExternalTypedData(I, 3473 return NewExternalTypedData(T,
3464 kExternalTypedDataFloat64ArrayCid, data, length); 3474 kExternalTypedDataFloat64ArrayCid, data, length);
3465 case Dart_TypedData_kFloat32x4: 3475 case Dart_TypedData_kFloat32x4:
3466 return NewExternalTypedData(I, 3476 return NewExternalTypedData(T,
3467 kExternalTypedDataFloat32x4ArrayCid, data, length); 3477 kExternalTypedDataFloat32x4ArrayCid, data, length);
3468 default: 3478 default:
3469 return Api::NewError("%s expects argument 'type' to be of" 3479 return Api::NewError("%s expects argument 'type' to be of"
3470 " 'external TypedData'", CURRENT_FUNC); 3480 " 'external TypedData'", CURRENT_FUNC);
3471 } 3481 }
3472 UNREACHABLE(); 3482 UNREACHABLE();
3473 return Api::Null(); 3483 return Api::Null();
3474 } 3484 }
3475 3485
3476 3486
3477 static RawObject* GetByteBufferConstructor(Isolate* isolate, 3487 static RawObject* GetByteBufferConstructor(Thread* thread,
3478 const String& class_name, 3488 const String& class_name,
3479 const String& constructor_name, 3489 const String& constructor_name,
3480 intptr_t num_args) { 3490 intptr_t num_args) {
3481 const Library& lib = 3491 const Library& lib =
3482 Library::Handle(isolate->object_store()->typed_data_library()); 3492 Library::Handle(thread->isolate()->object_store()->typed_data_library());
3483 ASSERT(!lib.IsNull()); 3493 ASSERT(!lib.IsNull());
3484 const Class& cls = Class::Handle( 3494 const Class& cls = Class::Handle(
3485 isolate, lib.LookupClassAllowPrivate(class_name)); 3495 thread->zone(), lib.LookupClassAllowPrivate(class_name));
3486 ASSERT(!cls.IsNull()); 3496 ASSERT(!cls.IsNull());
3487 return ResolveConstructor(CURRENT_FUNC, 3497 return ResolveConstructor(CURRENT_FUNC,
3488 cls, 3498 cls,
3489 class_name, 3499 class_name,
3490 constructor_name, 3500 constructor_name,
3491 num_args); 3501 num_args);
3492 } 3502 }
3493 3503
3494 3504
3495 DART_EXPORT Dart_Handle Dart_NewByteBuffer(Dart_Handle typed_data) { 3505 DART_EXPORT Dart_Handle Dart_NewByteBuffer(Dart_Handle typed_data) {
3496 DARTSCOPE(Thread::Current()); 3506 DARTSCOPE(Thread::Current());
3497 intptr_t class_id = Api::ClassId(typed_data); 3507 intptr_t class_id = Api::ClassId(typed_data);
3498 if (!RawObject::IsExternalTypedDataClassId(class_id) && 3508 if (!RawObject::IsExternalTypedDataClassId(class_id) &&
3499 !RawObject::IsTypedDataViewClassId(class_id) && 3509 !RawObject::IsTypedDataViewClassId(class_id) &&
3500 !RawObject::IsTypedDataClassId(class_id)) { 3510 !RawObject::IsTypedDataClassId(class_id)) {
3501 RETURN_TYPE_ERROR(I, typed_data, 'TypedData'); 3511 RETURN_TYPE_ERROR(Z, typed_data, 'TypedData');
3502 } 3512 }
3503 Object& result = Object::Handle(Z); 3513 Object& result = Object::Handle(Z);
3504 result = GetByteBufferConstructor(I, 3514 result = GetByteBufferConstructor(T,
3505 Symbols::_ByteBuffer(), 3515 Symbols::_ByteBuffer(),
3506 Symbols::_ByteBufferDot_New(), 3516 Symbols::_ByteBufferDot_New(),
3507 1); 3517 1);
3508 ASSERT(!result.IsNull()); 3518 ASSERT(!result.IsNull());
3509 ASSERT(result.IsFunction()); 3519 ASSERT(result.IsFunction());
3510 const Function& factory = Function::Cast(result); 3520 const Function& factory = Function::Cast(result);
3511 ASSERT(!factory.IsGenerativeConstructor()); 3521 ASSERT(!factory.IsGenerativeConstructor());
3512 3522
3513 // Create the argument list. 3523 // Create the argument list.
3514 const Array& args = Array::Handle(Z, Array::New(2)); 3524 const Array& args = Array::Handle(Z, Array::New(2));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
3559 3569
3560 DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, 3570 DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object,
3561 Dart_TypedData_Type* type, 3571 Dart_TypedData_Type* type,
3562 void** data, 3572 void** data,
3563 intptr_t* len) { 3573 intptr_t* len) {
3564 DARTSCOPE(Thread::Current()); 3574 DARTSCOPE(Thread::Current());
3565 intptr_t class_id = Api::ClassId(object); 3575 intptr_t class_id = Api::ClassId(object);
3566 if (!RawObject::IsExternalTypedDataClassId(class_id) && 3576 if (!RawObject::IsExternalTypedDataClassId(class_id) &&
3567 !RawObject::IsTypedDataViewClassId(class_id) && 3577 !RawObject::IsTypedDataViewClassId(class_id) &&
3568 !RawObject::IsTypedDataClassId(class_id)) { 3578 !RawObject::IsTypedDataClassId(class_id)) {
3569 RETURN_TYPE_ERROR(I, object, 'TypedData'); 3579 RETURN_TYPE_ERROR(Z, object, 'TypedData');
3570 } 3580 }
3571 if (type == NULL) { 3581 if (type == NULL) {
3572 RETURN_NULL_ERROR(type); 3582 RETURN_NULL_ERROR(type);
3573 } 3583 }
3574 if (data == NULL) { 3584 if (data == NULL) {
3575 RETURN_NULL_ERROR(data); 3585 RETURN_NULL_ERROR(data);
3576 } 3586 }
3577 if (len == NULL) { 3587 if (len == NULL) {
3578 RETURN_NULL_ERROR(len); 3588 RETURN_NULL_ERROR(len);
3579 } 3589 }
3580 // Get the type of typed data object. 3590 // Get the type of typed data object.
3581 *type = GetType(class_id); 3591 *type = GetType(class_id);
3582 intptr_t length = 0; 3592 intptr_t length = 0;
3583 intptr_t size_in_bytes = 0; 3593 intptr_t size_in_bytes = 0;
3584 void* data_tmp = NULL; 3594 void* data_tmp = NULL;
3585 bool external = false; 3595 bool external = false;
3586 // If it is an external typed data object just return the data field. 3596 // If it is an external typed data object just return the data field.
3587 if (RawObject::IsExternalTypedDataClassId(class_id)) { 3597 if (RawObject::IsExternalTypedDataClassId(class_id)) {
3588 const ExternalTypedData& obj = 3598 const ExternalTypedData& obj =
3589 Api::UnwrapExternalTypedDataHandle(I, object); 3599 Api::UnwrapExternalTypedDataHandle(Z, object);
3590 ASSERT(!obj.IsNull()); 3600 ASSERT(!obj.IsNull());
3591 length = obj.Length(); 3601 length = obj.Length();
3592 size_in_bytes = length * ExternalTypedData::ElementSizeInBytes(class_id); 3602 size_in_bytes = length * ExternalTypedData::ElementSizeInBytes(class_id);
3593 data_tmp = obj.DataAddr(0); 3603 data_tmp = obj.DataAddr(0);
3594 external = true; 3604 external = true;
3595 } else if (RawObject::IsTypedDataClassId(class_id)) { 3605 } else if (RawObject::IsTypedDataClassId(class_id)) {
3596 // Regular typed data object, set up some GC and API callback guards. 3606 // Regular typed data object, set up some GC and API callback guards.
3597 const TypedData& obj = Api::UnwrapTypedDataHandle(I, object); 3607 const TypedData& obj = Api::UnwrapTypedDataHandle(Z, object);
3598 ASSERT(!obj.IsNull()); 3608 ASSERT(!obj.IsNull());
3599 length = obj.Length(); 3609 length = obj.Length();
3600 size_in_bytes = length * TypedData::ElementSizeInBytes(class_id); 3610 size_in_bytes = length * TypedData::ElementSizeInBytes(class_id);
3601 T->IncrementNoSafepointScopeDepth(); 3611 T->IncrementNoSafepointScopeDepth();
3602 START_NO_CALLBACK_SCOPE(I); 3612 START_NO_CALLBACK_SCOPE(I);
3603 data_tmp = obj.DataAddr(0); 3613 data_tmp = obj.DataAddr(0);
3604 } else { 3614 } else {
3605 ASSERT(RawObject::IsTypedDataViewClassId(class_id)); 3615 ASSERT(RawObject::IsTypedDataViewClassId(class_id));
3606 const Instance& view_obj = Api::UnwrapInstanceHandle(I, object); 3616 const Instance& view_obj = Api::UnwrapInstanceHandle(Z, object);
3607 ASSERT(!view_obj.IsNull()); 3617 ASSERT(!view_obj.IsNull());
3608 Smi& val = Smi::Handle(); 3618 Smi& val = Smi::Handle();
3609 val ^= TypedDataView::Length(view_obj); 3619 val ^= TypedDataView::Length(view_obj);
3610 length = val.Value(); 3620 length = val.Value();
3611 size_in_bytes = length * TypedDataView::ElementSizeInBytes(class_id); 3621 size_in_bytes = length * TypedDataView::ElementSizeInBytes(class_id);
3612 val ^= TypedDataView::OffsetInBytes(view_obj); 3622 val ^= TypedDataView::OffsetInBytes(view_obj);
3613 intptr_t offset_in_bytes = val.Value(); 3623 intptr_t offset_in_bytes = val.Value();
3614 const Instance& obj = Instance::Handle(TypedDataView::Data(view_obj)); 3624 const Instance& obj = Instance::Handle(TypedDataView::Data(view_obj));
3615 T->IncrementNoSafepointScopeDepth(); 3625 T->IncrementNoSafepointScopeDepth();
3616 START_NO_CALLBACK_SCOPE(I); 3626 START_NO_CALLBACK_SCOPE(I);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3648 return Api::Success(); 3658 return Api::Success();
3649 } 3659 }
3650 3660
3651 3661
3652 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) { 3662 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) {
3653 DARTSCOPE(Thread::Current()); 3663 DARTSCOPE(Thread::Current());
3654 intptr_t class_id = Api::ClassId(object); 3664 intptr_t class_id = Api::ClassId(object);
3655 if (!RawObject::IsExternalTypedDataClassId(class_id) && 3665 if (!RawObject::IsExternalTypedDataClassId(class_id) &&
3656 !RawObject::IsTypedDataViewClassId(class_id) && 3666 !RawObject::IsTypedDataViewClassId(class_id) &&
3657 !RawObject::IsTypedDataClassId(class_id)) { 3667 !RawObject::IsTypedDataClassId(class_id)) {
3658 RETURN_TYPE_ERROR(I, object, 'TypedData'); 3668 RETURN_TYPE_ERROR(Z, object, 'TypedData');
3659 } 3669 }
3660 if (!RawObject::IsExternalTypedDataClassId(class_id)) { 3670 if (!RawObject::IsExternalTypedDataClassId(class_id)) {
3661 T->DecrementNoSafepointScopeDepth(); 3671 T->DecrementNoSafepointScopeDepth();
3662 END_NO_CALLBACK_SCOPE(I); 3672 END_NO_CALLBACK_SCOPE(I);
3663 } 3673 }
3664 if (FLAG_verify_acquired_data) { 3674 if (FLAG_verify_acquired_data) {
3665 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); 3675 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object));
3666 WeakTable* table = I->api_state()->acquired_table(); 3676 WeakTable* table = I->api_state()->acquired_table();
3667 intptr_t current = table->GetValue(obj.raw()); 3677 intptr_t current = table->GetValue(obj.raw());
3668 if (current == 0) { 3678 if (current == 0) {
3669 return Api::NewError("Data was not acquired for this object."); 3679 return Api::NewError("Data was not acquired for this object.");
3670 } 3680 }
3671 AcquiredData* ad = reinterpret_cast<AcquiredData*>(current); 3681 AcquiredData* ad = reinterpret_cast<AcquiredData*>(current);
3672 table->SetValue(obj.raw(), 0); // Delete entry from table. 3682 table->SetValue(obj.raw(), 0); // Delete entry from table.
3673 delete ad; 3683 delete ad;
3674 } 3684 }
3675 return Api::Success(); 3685 return Api::Success();
3676 } 3686 }
3677 3687
3678 3688
3679 DART_EXPORT Dart_Handle Dart_GetDataFromByteBuffer(Dart_Handle object) { 3689 DART_EXPORT Dart_Handle Dart_GetDataFromByteBuffer(Dart_Handle object) {
3680 Isolate* isolate = Isolate::Current(); 3690 Thread* thread = Thread::Current();
3691 Zone* zone = thread->zone();
3692 Isolate* isolate = thread->isolate();
3681 CHECK_ISOLATE(isolate); 3693 CHECK_ISOLATE(isolate);
3682 intptr_t class_id = Api::ClassId(object); 3694 intptr_t class_id = Api::ClassId(object);
3683 if (class_id != kByteBufferCid) { 3695 if (class_id != kByteBufferCid) {
3684 RETURN_TYPE_ERROR(isolate, object, 'ByteBuffer'); 3696 RETURN_TYPE_ERROR(zone, object, 'ByteBuffer');
3685 } 3697 }
3686 const Instance& instance = Api::UnwrapInstanceHandle(isolate, object); 3698 const Instance& instance = Api::UnwrapInstanceHandle(zone, object);
3687 ASSERT(!instance.IsNull()); 3699 ASSERT(!instance.IsNull());
3688 return Api::NewHandle(isolate, ByteBuffer::Data(instance)); 3700 return Api::NewHandle(isolate, ByteBuffer::Data(instance));
3689 } 3701 }
3690 3702
3691 3703
3692 // --- Invoking Constructors, Methods, and Field accessors --- 3704 // --- Invoking Constructors, Methods, and Field accessors ---
3693 3705
3694 static RawObject* ResolveConstructor(const char* current_func, 3706 static RawObject* ResolveConstructor(const char* current_func,
3695 const Class& cls, 3707 const Class& cls,
3696 const String& class_name, 3708 const String& class_name,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3749 3761
3750 if (number_of_arguments < 0) { 3762 if (number_of_arguments < 0) {
3751 return Api::NewError( 3763 return Api::NewError(
3752 "%s expects argument 'number_of_arguments' to be non-negative.", 3764 "%s expects argument 'number_of_arguments' to be non-negative.",
3753 CURRENT_FUNC); 3765 CURRENT_FUNC);
3754 } 3766 }
3755 3767
3756 // Get the class to instantiate. 3768 // Get the class to instantiate.
3757 Object& unchecked_type = Object::Handle(Api::UnwrapHandle(type)); 3769 Object& unchecked_type = Object::Handle(Api::UnwrapHandle(type));
3758 if (unchecked_type.IsNull() || !unchecked_type.IsType()) { 3770 if (unchecked_type.IsNull() || !unchecked_type.IsType()) {
3759 RETURN_TYPE_ERROR(I, type, Type); 3771 RETURN_TYPE_ERROR(Z, type, Type);
3760 } 3772 }
3761 Type& type_obj = Type::Handle(); 3773 Type& type_obj = Type::Handle();
3762 type_obj ^= unchecked_type.raw(); 3774 type_obj ^= unchecked_type.raw();
3763 if (!type_obj.IsFinalized()) { 3775 if (!type_obj.IsFinalized()) {
3764 return Api::NewError( 3776 return Api::NewError(
3765 "%s expects argument 'type' to be a fully resolved type.", 3777 "%s expects argument 'type' to be a fully resolved type.",
3766 CURRENT_FUNC); 3778 CURRENT_FUNC);
3767 } 3779 }
3768 Class& cls = Class::Handle(Z, type_obj.type_class()); 3780 Class& cls = Class::Handle(Z, type_obj.type_class());
3769 TypeArguments& type_arguments = 3781 TypeArguments& type_arguments =
3770 TypeArguments::Handle(Z, type_obj.arguments()); 3782 TypeArguments::Handle(Z, type_obj.arguments());
3771 3783
3772 const String& base_constructor_name = String::Handle(Z, cls.Name()); 3784 const String& base_constructor_name = String::Handle(Z, cls.Name());
3773 3785
3774 // And get the name of the constructor to invoke. 3786 // And get the name of the constructor to invoke.
3775 String& dot_name = String::Handle(Z); 3787 String& dot_name = String::Handle(Z);
3776 result = Api::UnwrapHandle(constructor_name); 3788 result = Api::UnwrapHandle(constructor_name);
3777 if (result.IsNull()) { 3789 if (result.IsNull()) {
3778 dot_name = Symbols::Dot().raw(); 3790 dot_name = Symbols::Dot().raw();
3779 } else if (result.IsString()) { 3791 } else if (result.IsString()) {
3780 dot_name = String::Concat(Symbols::Dot(), String::Cast(result)); 3792 dot_name = String::Concat(Symbols::Dot(), String::Cast(result));
3781 } else { 3793 } else {
3782 RETURN_TYPE_ERROR(I, constructor_name, String); 3794 RETURN_TYPE_ERROR(Z, constructor_name, String);
3783 } 3795 }
3784 3796
3785 // Resolve the constructor. 3797 // Resolve the constructor.
3786 String& constr_name = 3798 String& constr_name =
3787 String::Handle(String::Concat(base_constructor_name, dot_name)); 3799 String::Handle(String::Concat(base_constructor_name, dot_name));
3788 result = ResolveConstructor("Dart_New", 3800 result = ResolveConstructor("Dart_New",
3789 cls, 3801 cls,
3790 base_constructor_name, 3802 base_constructor_name,
3791 constr_name, 3803 constr_name,
3792 number_of_arguments); 3804 number_of_arguments);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
3872 if (constructor.IsGenerativeConstructor()) { 3884 if (constructor.IsGenerativeConstructor()) {
3873 ASSERT(result.IsNull()); 3885 ASSERT(result.IsNull());
3874 } else { 3886 } else {
3875 ASSERT(result.IsNull() || result.IsInstance()); 3887 ASSERT(result.IsNull() || result.IsInstance());
3876 new_object ^= result.raw(); 3888 new_object ^= result.raw();
3877 } 3889 }
3878 return Api::NewHandle(I, new_object.raw()); 3890 return Api::NewHandle(I, new_object.raw());
3879 } 3891 }
3880 3892
3881 3893
3882 static RawInstance* AllocateObject(Isolate* isolate, const Class& cls) { 3894 static RawInstance* AllocateObject(Thread* thread, const Class& cls) {
3883 if (!cls.is_fields_marked_nullable()) { 3895 if (!cls.is_fields_marked_nullable()) {
3884 // Mark all fields as nullable. 3896 // Mark all fields as nullable.
3885 Class& iterate_cls = Class::Handle(isolate, cls.raw()); 3897 Zone* zone = thread->zone();
3886 Field& field = Field::Handle(isolate); 3898 Class& iterate_cls = Class::Handle(zone, cls.raw());
3887 Array& fields = Array::Handle(isolate); 3899 Field& field = Field::Handle(zone);
3900 Array& fields = Array::Handle(zone);
3888 while (!iterate_cls.IsNull()) { 3901 while (!iterate_cls.IsNull()) {
3889 ASSERT(iterate_cls.is_finalized()); 3902 ASSERT(iterate_cls.is_finalized());
3890 iterate_cls.set_is_fields_marked_nullable(); 3903 iterate_cls.set_is_fields_marked_nullable();
3891 fields = iterate_cls.fields(); 3904 fields = iterate_cls.fields();
3892 iterate_cls = iterate_cls.SuperClass(); 3905 iterate_cls = iterate_cls.SuperClass();
3893 for (int field_num = 0; field_num < fields.Length(); field_num++) { 3906 for (int field_num = 0; field_num < fields.Length(); field_num++) {
3894 field ^= fields.At(field_num); 3907 field ^= fields.At(field_num);
3895 if (field.is_static()) { 3908 if (field.is_static()) {
3896 continue; 3909 continue;
3897 } 3910 }
3898 field.RecordStore(Object::null_object()); 3911 field.RecordStore(Object::null_object());
3899 } 3912 }
3900 } 3913 }
3901 } 3914 }
3902 3915
3903 // Allocate an object for the given class. 3916 // Allocate an object for the given class.
3904 return Instance::New(cls); 3917 return Instance::New(cls);
3905 } 3918 }
3906 3919
3907 3920
3908 DART_EXPORT Dart_Handle Dart_Allocate(Dart_Handle type) { 3921 DART_EXPORT Dart_Handle Dart_Allocate(Dart_Handle type) {
3909 DARTSCOPE(Thread::Current()); 3922 DARTSCOPE(Thread::Current());
3910 CHECK_CALLBACK_STATE(I); 3923 CHECK_CALLBACK_STATE(I);
3911 3924
3912 const Type& type_obj = Api::UnwrapTypeHandle(I, type); 3925 const Type& type_obj = Api::UnwrapTypeHandle(Z, type);
3913 // Get the class to instantiate. 3926 // Get the class to instantiate.
3914 if (type_obj.IsNull()) { 3927 if (type_obj.IsNull()) {
3915 RETURN_TYPE_ERROR(I, type, Type); 3928 RETURN_TYPE_ERROR(Z, type, Type);
3916 } 3929 }
3917 const Class& cls = Class::Handle(Z, type_obj.type_class()); 3930 const Class& cls = Class::Handle(Z, type_obj.type_class());
3918 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); 3931 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T));
3919 if (!error.IsNull()) { 3932 if (!error.IsNull()) {
3920 // An error occurred, return error object. 3933 // An error occurred, return error object.
3921 return Api::NewHandle(I, error.raw()); 3934 return Api::NewHandle(I, error.raw());
3922 } 3935 }
3923 return Api::NewHandle(I, AllocateObject(I, cls)); 3936 return Api::NewHandle(I, AllocateObject(T, cls));
3924 } 3937 }
3925 3938
3926 3939
3927 DART_EXPORT Dart_Handle Dart_AllocateWithNativeFields( 3940 DART_EXPORT Dart_Handle Dart_AllocateWithNativeFields(
3928 Dart_Handle type, 3941 Dart_Handle type,
3929 intptr_t num_native_fields, 3942 intptr_t num_native_fields,
3930 const intptr_t* native_fields) { 3943 const intptr_t* native_fields) {
3931 DARTSCOPE(Thread::Current()); 3944 DARTSCOPE(Thread::Current());
3932 CHECK_CALLBACK_STATE(I); 3945 CHECK_CALLBACK_STATE(I);
3933 3946
3934 const Type& type_obj = Api::UnwrapTypeHandle(I, type); 3947 const Type& type_obj = Api::UnwrapTypeHandle(Z, type);
3935 // Get the class to instantiate. 3948 // Get the class to instantiate.
3936 if (type_obj.IsNull()) { 3949 if (type_obj.IsNull()) {
3937 RETURN_TYPE_ERROR(I, type, Type); 3950 RETURN_TYPE_ERROR(Z, type, Type);
3938 } 3951 }
3939 if (native_fields == NULL) { 3952 if (native_fields == NULL) {
3940 RETURN_NULL_ERROR(native_fields); 3953 RETURN_NULL_ERROR(native_fields);
3941 } 3954 }
3942 const Class& cls = Class::Handle(Z, type_obj.type_class()); 3955 const Class& cls = Class::Handle(Z, type_obj.type_class());
3943 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); 3956 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T));
3944 if (!error.IsNull()) { 3957 if (!error.IsNull()) {
3945 // An error occurred, return error object. 3958 // An error occurred, return error object.
3946 return Api::NewHandle(I, error.raw()); 3959 return Api::NewHandle(I, error.raw());
3947 } 3960 }
3948 if (num_native_fields != cls.num_native_fields()) { 3961 if (num_native_fields != cls.num_native_fields()) {
3949 return Api::NewError( 3962 return Api::NewError(
3950 "%s: invalid number of native fields %" Pd " passed in, expected %d", 3963 "%s: invalid number of native fields %" Pd " passed in, expected %d",
3951 CURRENT_FUNC, num_native_fields, cls.num_native_fields()); 3964 CURRENT_FUNC, num_native_fields, cls.num_native_fields());
3952 } 3965 }
3953 const Instance& instance = Instance::Handle(Z, AllocateObject(I, cls)); 3966 const Instance& instance = Instance::Handle(Z, AllocateObject(T, cls));
3954 instance.SetNativeFields(num_native_fields, native_fields); 3967 instance.SetNativeFields(num_native_fields, native_fields);
3955 return Api::NewHandle(I, instance.raw()); 3968 return Api::NewHandle(I, instance.raw());
3956 } 3969 }
3957 3970
3958 3971
3959 static Dart_Handle SetupArguments(Isolate* isolate, 3972 static Dart_Handle SetupArguments(Thread* thread,
3960 int num_args, 3973 int num_args,
3961 Dart_Handle* arguments, 3974 Dart_Handle* arguments,
3962 int extra_args, 3975 int extra_args,
3963 Array* args) { 3976 Array* args) {
3977 Zone* zone = thread->zone();
3978 Isolate* isolate = thread->isolate();
3964 // Check for malformed arguments in the arguments list. 3979 // Check for malformed arguments in the arguments list.
3965 *args = Array::New(num_args + extra_args); 3980 *args = Array::New(num_args + extra_args);
3966 Object& arg = Object::Handle(isolate); 3981 Object& arg = Object::Handle(zone);
3967 for (int i = 0; i < num_args; i++) { 3982 for (int i = 0; i < num_args; i++) {
3968 arg = Api::UnwrapHandle(arguments[i]); 3983 arg = Api::UnwrapHandle(arguments[i]);
3969 if (!arg.IsNull() && !arg.IsInstance()) { 3984 if (!arg.IsNull() && !arg.IsInstance()) {
3970 *args = Array::null(); 3985 *args = Array::null();
3971 if (arg.IsError()) { 3986 if (arg.IsError()) {
3972 return Api::NewHandle(isolate, arg.raw()); 3987 return Api::NewHandle(isolate, arg.raw());
3973 } else { 3988 } else {
3974 return Api::NewError( 3989 return Api::NewError(
3975 "%s expects arguments[%d] to be an Instance handle.", 3990 "%s expects arguments[%d] to be an Instance handle.",
3976 "Dart_Invoke", i); 3991 "Dart_Invoke", i);
(...skipping 10 matching lines...) Expand all
3987 int number_of_arguments, 4002 int number_of_arguments,
3988 Dart_Handle* arguments) { 4003 Dart_Handle* arguments) {
3989 DARTSCOPE(Thread::Current()); 4004 DARTSCOPE(Thread::Current());
3990 CHECK_CALLBACK_STATE(I); 4005 CHECK_CALLBACK_STATE(I);
3991 4006
3992 if (number_of_arguments < 0) { 4007 if (number_of_arguments < 0) {
3993 return Api::NewError( 4008 return Api::NewError(
3994 "%s expects argument 'number_of_arguments' to be non-negative.", 4009 "%s expects argument 'number_of_arguments' to be non-negative.",
3995 CURRENT_FUNC); 4010 CURRENT_FUNC);
3996 } 4011 }
3997 const String& constructor_name = Api::UnwrapStringHandle(I, name); 4012 const String& constructor_name = Api::UnwrapStringHandle(Z, name);
3998 if (constructor_name.IsNull()) { 4013 if (constructor_name.IsNull()) {
3999 RETURN_TYPE_ERROR(I, name, String); 4014 RETURN_TYPE_ERROR(Z, name, String);
4000 } 4015 }
4001 const Instance& instance = Api::UnwrapInstanceHandle(I, object); 4016 const Instance& instance = Api::UnwrapInstanceHandle(Z, object);
4002 if (instance.IsNull()) { 4017 if (instance.IsNull()) {
4003 RETURN_TYPE_ERROR(I, object, Instance); 4018 RETURN_TYPE_ERROR(Z, object, Instance);
4004 } 4019 }
4005 4020
4006 // Since we have allocated an object it would mean that the type 4021 // Since we have allocated an object it would mean that the type
4007 // is finalized. 4022 // is finalized.
4008 // TODO(asiva): How do we ensure that a constructor is not called more than 4023 // TODO(asiva): How do we ensure that a constructor is not called more than
4009 // once for the same object. 4024 // once for the same object.
4010 4025
4011 // Construct name of the constructor to invoke. 4026 // Construct name of the constructor to invoke.
4012 const Type& type_obj = Type::Handle(Z, instance.GetType()); 4027 const Type& type_obj = Type::Handle(Z, instance.GetType());
4013 const Class& cls = Class::Handle(Z, type_obj.type_class()); 4028 const Class& cls = Class::Handle(Z, type_obj.type_class());
(...skipping 17 matching lines...) Expand all
4031 // Constructors get the uninitialized object and a constructor phase. 4046 // Constructors get the uninitialized object and a constructor phase.
4032 if (!type_arguments.IsNull()) { 4047 if (!type_arguments.IsNull()) {
4033 // The type arguments will be null if the class has no type 4048 // The type arguments will be null if the class has no type
4034 // parameters, in which case the following call would fail 4049 // parameters, in which case the following call would fail
4035 // because there is no slot reserved in the object for the 4050 // because there is no slot reserved in the object for the
4036 // type vector. 4051 // type vector.
4037 instance.SetTypeArguments(type_arguments); 4052 instance.SetTypeArguments(type_arguments);
4038 } 4053 }
4039 Dart_Handle result; 4054 Dart_Handle result;
4040 Array& args = Array::Handle(Z); 4055 Array& args = Array::Handle(Z);
4041 result = SetupArguments(I, 4056 result = SetupArguments(T,
4042 number_of_arguments, arguments, extra_args, &args); 4057 number_of_arguments, arguments, extra_args, &args);
4043 if (!::Dart_IsError(result)) { 4058 if (!::Dart_IsError(result)) {
4044 args.SetAt(0, instance); 4059 args.SetAt(0, instance);
4045 args.SetAt(1, Smi::Handle(Z, Smi::New(Function::kCtorPhaseAll))); 4060 args.SetAt(1, Smi::Handle(Z, Smi::New(Function::kCtorPhaseAll)));
4046 const Object& retval = Object::Handle(Z, 4061 const Object& retval = Object::Handle(Z,
4047 DartEntry::InvokeFunction(constructor, args)); 4062 DartEntry::InvokeFunction(constructor, args));
4048 if (retval.IsError()) { 4063 if (retval.IsError()) {
4049 result = Api::NewHandle(I, retval.raw()); 4064 result = Api::NewHandle(I, retval.raw());
4050 } else { 4065 } else {
4051 result = Api::NewHandle(I, instance.raw()); 4066 result = Api::NewHandle(I, instance.raw());
4052 } 4067 }
4053 } 4068 }
4054 return result; 4069 return result;
4055 } 4070 }
4056 return Api::NewError( 4071 return Api::NewError(
4057 "%s expects argument 'name' to be a valid constructor.", 4072 "%s expects argument 'name' to be a valid constructor.",
4058 CURRENT_FUNC); 4073 CURRENT_FUNC);
4059 } 4074 }
4060 4075
4061 4076
4062 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, 4077 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target,
4063 Dart_Handle name, 4078 Dart_Handle name,
4064 int number_of_arguments, 4079 int number_of_arguments,
4065 Dart_Handle* arguments) { 4080 Dart_Handle* arguments) {
4066 DARTSCOPE(Thread::Current()); 4081 DARTSCOPE(Thread::Current());
4067 CHECK_CALLBACK_STATE(I); 4082 CHECK_CALLBACK_STATE(I);
4068 4083
4069 const String& function_name = Api::UnwrapStringHandle(I, name); 4084 const String& function_name = Api::UnwrapStringHandle(Z, name);
4070 if (function_name.IsNull()) { 4085 if (function_name.IsNull()) {
4071 RETURN_TYPE_ERROR(I, name, String); 4086 RETURN_TYPE_ERROR(Z, name, String);
4072 } 4087 }
4073 if (number_of_arguments < 0) { 4088 if (number_of_arguments < 0) {
4074 return Api::NewError( 4089 return Api::NewError(
4075 "%s expects argument 'number_of_arguments' to be non-negative.", 4090 "%s expects argument 'number_of_arguments' to be non-negative.",
4076 CURRENT_FUNC); 4091 CURRENT_FUNC);
4077 } 4092 }
4078 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(target)); 4093 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(target));
4079 if (obj.IsError()) { 4094 if (obj.IsError()) {
4080 return target; 4095 return target;
4081 } 4096 }
(...skipping 13 matching lines...) Expand all
4095 number_of_arguments, 4110 number_of_arguments,
4096 Object::empty_array())); 4111 Object::empty_array()));
4097 if (function.IsNull()) { 4112 if (function.IsNull()) {
4098 const String& cls_name = String::Handle(Z, cls.Name()); 4113 const String& cls_name = String::Handle(Z, cls.Name());
4099 return Api::NewError("%s: did not find static method '%s.%s'.", 4114 return Api::NewError("%s: did not find static method '%s.%s'.",
4100 CURRENT_FUNC, 4115 CURRENT_FUNC,
4101 cls_name.ToCString(), 4116 cls_name.ToCString(),
4102 function_name.ToCString()); 4117 function_name.ToCString());
4103 } 4118 }
4104 // Setup args and check for malformed arguments in the arguments list. 4119 // Setup args and check for malformed arguments in the arguments list.
4105 result = SetupArguments(I, number_of_arguments, arguments, 0, &args); 4120 result = SetupArguments(T, number_of_arguments, arguments, 0, &args);
4106 if (!::Dart_IsError(result)) { 4121 if (!::Dart_IsError(result)) {
4107 result = Api::NewHandle(I, DartEntry::InvokeFunction(function, args)); 4122 result = Api::NewHandle(I, DartEntry::InvokeFunction(function, args));
4108 } 4123 }
4109 return result; 4124 return result;
4110 } else if (obj.IsNull() || obj.IsInstance()) { 4125 } else if (obj.IsNull() || obj.IsInstance()) {
4111 // Since we have allocated an object it would mean that the type of the 4126 // Since we have allocated an object it would mean that the type of the
4112 // receiver is already resolved and finalized, hence it is not necessary 4127 // receiver is already resolved and finalized, hence it is not necessary
4113 // to check here. 4128 // to check here.
4114 Instance& instance = Instance::Handle(Z); 4129 Instance& instance = Instance::Handle(Z);
4115 instance ^= obj.raw(); 4130 instance ^= obj.raw();
4116 ArgumentsDescriptor args_desc( 4131 ArgumentsDescriptor args_desc(
4117 Array::Handle(Z, ArgumentsDescriptor::New(number_of_arguments + 1))); 4132 Array::Handle(Z, ArgumentsDescriptor::New(number_of_arguments + 1)));
4118 const Function& function = Function::Handle(Z, 4133 const Function& function = Function::Handle(Z,
4119 Resolver::ResolveDynamic(instance, function_name, args_desc)); 4134 Resolver::ResolveDynamic(instance, function_name, args_desc));
4120 if (function.IsNull()) { 4135 if (function.IsNull()) {
4121 // Setup args and check for malformed arguments in the arguments list. 4136 // Setup args and check for malformed arguments in the arguments list.
4122 result = SetupArguments(I, 4137 result = SetupArguments(T,
4123 number_of_arguments, 4138 number_of_arguments,
4124 arguments, 4139 arguments,
4125 1, 4140 1,
4126 &args); 4141 &args);
4127 if (!::Dart_IsError(result)) { 4142 if (!::Dart_IsError(result)) {
4128 args.SetAt(0, instance); 4143 args.SetAt(0, instance);
4129 const Array& args_descriptor = 4144 const Array& args_descriptor =
4130 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); 4145 Array::Handle(Z, ArgumentsDescriptor::New(args.Length()));
4131 result = Api::NewHandle(I, 4146 result = Api::NewHandle(I,
4132 DartEntry::InvokeNoSuchMethod(instance, 4147 DartEntry::InvokeNoSuchMethod(instance,
4133 function_name, 4148 function_name,
4134 args, 4149 args,
4135 args_descriptor)); 4150 args_descriptor));
4136 } 4151 }
4137 return result; 4152 return result;
4138 } 4153 }
4139 // Setup args and check for malformed arguments in the arguments list. 4154 // Setup args and check for malformed arguments in the arguments list.
4140 result = SetupArguments(I, number_of_arguments, arguments, 1, &args); 4155 result = SetupArguments(T, number_of_arguments, arguments, 1, &args);
4141 if (!::Dart_IsError(result)) { 4156 if (!::Dart_IsError(result)) {
4142 args.SetAt(0, instance); 4157 args.SetAt(0, instance);
4143 result = Api::NewHandle(I, DartEntry::InvokeFunction(function, args)); 4158 result = Api::NewHandle(I, DartEntry::InvokeFunction(function, args));
4144 } 4159 }
4145 return result; 4160 return result;
4146 } else if (obj.IsLibrary()) { 4161 } else if (obj.IsLibrary()) {
4147 // Check whether class finalization is needed. 4162 // Check whether class finalization is needed.
4148 const Library& lib = Library::Cast(obj); 4163 const Library& lib = Library::Cast(obj);
4149 4164
4150 // Check that the library is loaded. 4165 // Check that the library is loaded.
(...skipping 15 matching lines...) Expand all
4166 String& error_message = String::Handle(Z); 4181 String& error_message = String::Handle(Z);
4167 if (!function.AreValidArgumentCounts(number_of_arguments, 4182 if (!function.AreValidArgumentCounts(number_of_arguments,
4168 0, 4183 0,
4169 &error_message)) { 4184 &error_message)) {
4170 return Api::NewError("%s: wrong argument count for function '%s': %s.", 4185 return Api::NewError("%s: wrong argument count for function '%s': %s.",
4171 CURRENT_FUNC, 4186 CURRENT_FUNC,
4172 function_name.ToCString(), 4187 function_name.ToCString(),
4173 error_message.ToCString()); 4188 error_message.ToCString());
4174 } 4189 }
4175 // Setup args and check for malformed arguments in the arguments list. 4190 // Setup args and check for malformed arguments in the arguments list.
4176 result = SetupArguments(I, number_of_arguments, arguments, 0, &args); 4191 result = SetupArguments(T, number_of_arguments, arguments, 0, &args);
4177 if (!::Dart_IsError(result)) { 4192 if (!::Dart_IsError(result)) {
4178 result = Api::NewHandle(I, DartEntry::InvokeFunction(function, args)); 4193 result = Api::NewHandle(I, DartEntry::InvokeFunction(function, args));
4179 } 4194 }
4180 return result; 4195 return result;
4181 } else { 4196 } else {
4182 return Api::NewError( 4197 return Api::NewError(
4183 "%s expects argument 'target' to be an object, type, or library.", 4198 "%s expects argument 'target' to be an object, type, or library.",
4184 CURRENT_FUNC); 4199 CURRENT_FUNC);
4185 } 4200 }
4186 } 4201 }
4187 4202
4188 4203
4189 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, 4204 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure,
4190 int number_of_arguments, 4205 int number_of_arguments,
4191 Dart_Handle* arguments) { 4206 Dart_Handle* arguments) {
4192 DARTSCOPE(Thread::Current()); 4207 DARTSCOPE(Thread::Current());
4193 CHECK_CALLBACK_STATE(I); 4208 CHECK_CALLBACK_STATE(I);
4194 const Instance& closure_obj = Api::UnwrapInstanceHandle(I, closure); 4209 const Instance& closure_obj = Api::UnwrapInstanceHandle(Z, closure);
4195 if (closure_obj.IsNull() || !closure_obj.IsCallable(NULL)) { 4210 if (closure_obj.IsNull() || !closure_obj.IsCallable(NULL)) {
4196 RETURN_TYPE_ERROR(I, closure, Instance); 4211 RETURN_TYPE_ERROR(Z, closure, Instance);
4197 } 4212 }
4198 if (number_of_arguments < 0) { 4213 if (number_of_arguments < 0) {
4199 return Api::NewError( 4214 return Api::NewError(
4200 "%s expects argument 'number_of_arguments' to be non-negative.", 4215 "%s expects argument 'number_of_arguments' to be non-negative.",
4201 CURRENT_FUNC); 4216 CURRENT_FUNC);
4202 } 4217 }
4203 4218
4204 // Set up arguments to include the closure as the first argument. 4219 // Set up arguments to include the closure as the first argument.
4205 const Array& args = Array::Handle(Z, Array::New(number_of_arguments + 1)); 4220 const Array& args = Array::Handle(Z, Array::New(number_of_arguments + 1));
4206 Object& obj = Object::Handle(Z); 4221 Object& obj = Object::Handle(Z);
4207 args.SetAt(0, closure_obj); 4222 args.SetAt(0, closure_obj);
4208 for (int i = 0; i < number_of_arguments; i++) { 4223 for (int i = 0; i < number_of_arguments; i++) {
4209 obj = Api::UnwrapHandle(arguments[i]); 4224 obj = Api::UnwrapHandle(arguments[i]);
4210 if (!obj.IsNull() && !obj.IsInstance()) { 4225 if (!obj.IsNull() && !obj.IsInstance()) {
4211 RETURN_TYPE_ERROR(I, arguments[i], Instance); 4226 RETURN_TYPE_ERROR(Z, arguments[i], Instance);
4212 } 4227 }
4213 args.SetAt(i + 1, obj); 4228 args.SetAt(i + 1, obj);
4214 } 4229 }
4215 // Now try to invoke the closure. 4230 // Now try to invoke the closure.
4216 return Api::NewHandle(I, DartEntry::InvokeClosure(args)); 4231 return Api::NewHandle(I, DartEntry::InvokeClosure(args));
4217 } 4232 }
4218 4233
4219 4234
4220 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { 4235 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) {
4221 DARTSCOPE(Thread::Current()); 4236 DARTSCOPE(Thread::Current());
4222 CHECK_CALLBACK_STATE(I); 4237 CHECK_CALLBACK_STATE(I);
4223 4238
4224 const String& field_name = Api::UnwrapStringHandle(I, name); 4239 const String& field_name = Api::UnwrapStringHandle(Z, name);
4225 if (field_name.IsNull()) { 4240 if (field_name.IsNull()) {
4226 RETURN_TYPE_ERROR(I, name, String); 4241 RETURN_TYPE_ERROR(Z, name, String);
4227 } 4242 }
4228 4243
4229 Field& field = Field::Handle(Z); 4244 Field& field = Field::Handle(Z);
4230 Function& getter = Function::Handle(Z); 4245 Function& getter = Function::Handle(Z);
4231 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(container)); 4246 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(container));
4232 if (obj.IsNull()) { 4247 if (obj.IsNull()) {
4233 return Api::NewError("%s expects argument 'container' to be non-null.", 4248 return Api::NewError("%s expects argument 'container' to be non-null.",
4234 CURRENT_FUNC); 4249 CURRENT_FUNC);
4235 } else if (obj.IsType()) { 4250 } else if (obj.IsType()) {
4236 if (!Type::Cast(obj).IsFinalized()) { 4251 if (!Type::Cast(obj).IsFinalized()) {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
4335 } 4350 }
4336 } 4351 }
4337 4352
4338 4353
4339 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, 4354 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container,
4340 Dart_Handle name, 4355 Dart_Handle name,
4341 Dart_Handle value) { 4356 Dart_Handle value) {
4342 DARTSCOPE(Thread::Current()); 4357 DARTSCOPE(Thread::Current());
4343 CHECK_CALLBACK_STATE(I); 4358 CHECK_CALLBACK_STATE(I);
4344 4359
4345 const String& field_name = Api::UnwrapStringHandle(I, name); 4360 const String& field_name = Api::UnwrapStringHandle(Z, name);
4346 if (field_name.IsNull()) { 4361 if (field_name.IsNull()) {
4347 RETURN_TYPE_ERROR(I, name, String); 4362 RETURN_TYPE_ERROR(Z, name, String);
4348 } 4363 }
4349 4364
4350 // Since null is allowed for value, we don't use UnwrapInstanceHandle. 4365 // Since null is allowed for value, we don't use UnwrapInstanceHandle.
4351 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); 4366 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value));
4352 if (!value_obj.IsNull() && !value_obj.IsInstance()) { 4367 if (!value_obj.IsNull() && !value_obj.IsInstance()) {
4353 RETURN_TYPE_ERROR(I, value, Instance); 4368 RETURN_TYPE_ERROR(Z, value, Instance);
4354 } 4369 }
4355 Instance& value_instance = Instance::Handle(Z); 4370 Instance& value_instance = Instance::Handle(Z);
4356 value_instance ^= value_obj.raw(); 4371 value_instance ^= value_obj.raw();
4357 4372
4358 Field& field = Field::Handle(Z); 4373 Field& field = Field::Handle(Z);
4359 Function& setter = Function::Handle(Z); 4374 Function& setter = Function::Handle(Z);
4360 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(container)); 4375 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(container));
4361 if (obj.IsNull()) { 4376 if (obj.IsNull()) {
4362 return Api::NewError("%s expects argument 'container' to be non-null.", 4377 return Api::NewError("%s expects argument 'container' to be non-null.",
4363 CURRENT_FUNC); 4378 CURRENT_FUNC);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
4485 return Api::NewError( 4500 return Api::NewError(
4486 "%s expects argument 'container' to be an object, type, or library.", 4501 "%s expects argument 'container' to be an object, type, or library.",
4487 CURRENT_FUNC); 4502 CURRENT_FUNC);
4488 } 4503 }
4489 4504
4490 4505
4491 // --- Exceptions ---- 4506 // --- Exceptions ----
4492 4507
4493 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { 4508 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) {
4494 Thread* thread = Thread::Current(); 4509 Thread* thread = Thread::Current();
4510 Zone* zone = thread->zone();
4495 Isolate* isolate = thread->isolate(); 4511 Isolate* isolate = thread->isolate();
4496 CHECK_ISOLATE(isolate); 4512 CHECK_ISOLATE(isolate);
4497 CHECK_CALLBACK_STATE(isolate); 4513 CHECK_CALLBACK_STATE(isolate);
4498 { 4514 {
4499 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); 4515 const Instance& excp = Api::UnwrapInstanceHandle(zone, exception);
4500 if (excp.IsNull()) { 4516 if (excp.IsNull()) {
4501 RETURN_TYPE_ERROR(isolate, exception, Instance); 4517 RETURN_TYPE_ERROR(zone, exception, Instance);
4502 } 4518 }
4503 } 4519 }
4504 if (isolate->top_exit_frame_info() == 0) { 4520 if (isolate->top_exit_frame_info() == 0) {
4505 // There are no dart frames on the stack so it would be illegal to 4521 // There are no dart frames on the stack so it would be illegal to
4506 // throw an exception here. 4522 // throw an exception here.
4507 return Api::NewError("No Dart frames on stack, cannot throw exception"); 4523 return Api::NewError("No Dart frames on stack, cannot throw exception");
4508 } 4524 }
4509 4525
4510 // Unwind all the API scopes till the exit frame before throwing an 4526 // Unwind all the API scopes till the exit frame before throwing an
4511 // exception. 4527 // exception.
4512 ApiState* state = isolate->api_state(); 4528 ApiState* state = isolate->api_state();
4513 ASSERT(state != NULL); 4529 ASSERT(state != NULL);
4514 const Instance* saved_exception; 4530 const Instance* saved_exception;
4515 { 4531 {
4516 NoSafepointScope no_safepoint; 4532 NoSafepointScope no_safepoint;
4517 RawInstance* raw_exception = 4533 RawInstance* raw_exception =
4518 Api::UnwrapInstanceHandle(isolate, exception).raw(); 4534 Api::UnwrapInstanceHandle(zone, exception).raw();
4519 state->UnwindScopes(isolate->top_exit_frame_info()); 4535 state->UnwindScopes(isolate->top_exit_frame_info());
4520 saved_exception = &Instance::Handle(raw_exception); 4536 saved_exception = &Instance::Handle(raw_exception);
4521 } 4537 }
4522 Exceptions::Throw(thread, *saved_exception); 4538 Exceptions::Throw(thread, *saved_exception);
4523 return Api::NewError("Exception was not thrown, internal error"); 4539 return Api::NewError("Exception was not thrown, internal error");
4524 } 4540 }
4525 4541
4526 4542
4527 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, 4543 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception,
4528 Dart_Handle stacktrace) { 4544 Dart_Handle stacktrace) {
4529 Thread* thread = Thread::Current(); 4545 Thread* thread = Thread::Current();
4546 Zone* zone = thread->zone();
4530 Isolate* isolate = thread->isolate(); 4547 Isolate* isolate = thread->isolate();
4531 CHECK_ISOLATE(isolate); 4548 CHECK_ISOLATE(isolate);
4532 CHECK_CALLBACK_STATE(isolate); 4549 CHECK_CALLBACK_STATE(isolate);
4533 { 4550 {
4534 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); 4551 const Instance& excp = Api::UnwrapInstanceHandle(zone, exception);
4535 if (excp.IsNull()) { 4552 if (excp.IsNull()) {
4536 RETURN_TYPE_ERROR(isolate, exception, Instance); 4553 RETURN_TYPE_ERROR(zone, exception, Instance);
4537 } 4554 }
4538 const Instance& stk = Api::UnwrapInstanceHandle(isolate, stacktrace); 4555 const Instance& stk = Api::UnwrapInstanceHandle(zone, stacktrace);
4539 if (stk.IsNull()) { 4556 if (stk.IsNull()) {
4540 RETURN_TYPE_ERROR(isolate, stacktrace, Instance); 4557 RETURN_TYPE_ERROR(zone, stacktrace, Instance);
4541 } 4558 }
4542 } 4559 }
4543 if (isolate->top_exit_frame_info() == 0) { 4560 if (isolate->top_exit_frame_info() == 0) {
4544 // There are no dart frames on the stack so it would be illegal to 4561 // There are no dart frames on the stack so it would be illegal to
4545 // throw an exception here. 4562 // throw an exception here.
4546 return Api::NewError("No Dart frames on stack, cannot throw exception"); 4563 return Api::NewError("No Dart frames on stack, cannot throw exception");
4547 } 4564 }
4548 4565
4549 // Unwind all the API scopes till the exit frame before throwing an 4566 // Unwind all the API scopes till the exit frame before throwing an
4550 // exception. 4567 // exception.
4551 ApiState* state = isolate->api_state(); 4568 ApiState* state = isolate->api_state();
4552 ASSERT(state != NULL); 4569 ASSERT(state != NULL);
4553 const Instance* saved_exception; 4570 const Instance* saved_exception;
4554 const Stacktrace* saved_stacktrace; 4571 const Stacktrace* saved_stacktrace;
4555 { 4572 {
4556 NoSafepointScope no_safepoint; 4573 NoSafepointScope no_safepoint;
4557 RawInstance* raw_exception = 4574 RawInstance* raw_exception =
4558 Api::UnwrapInstanceHandle(isolate, exception).raw(); 4575 Api::UnwrapInstanceHandle(zone, exception).raw();
4559 RawStacktrace* raw_stacktrace = 4576 RawStacktrace* raw_stacktrace =
4560 Api::UnwrapStacktraceHandle(isolate, stacktrace).raw(); 4577 Api::UnwrapStacktraceHandle(zone, stacktrace).raw();
4561 state->UnwindScopes(isolate->top_exit_frame_info()); 4578 state->UnwindScopes(isolate->top_exit_frame_info());
4562 saved_exception = &Instance::Handle(raw_exception); 4579 saved_exception = &Instance::Handle(raw_exception);
4563 saved_stacktrace = &Stacktrace::Handle(raw_stacktrace); 4580 saved_stacktrace = &Stacktrace::Handle(raw_stacktrace);
4564 } 4581 }
4565 Exceptions::ReThrow(thread, *saved_exception, *saved_stacktrace); 4582 Exceptions::ReThrow(thread, *saved_exception, *saved_stacktrace);
4566 return Api::NewError("Exception was not re thrown, internal error"); 4583 return Api::NewError("Exception was not re thrown, internal error");
4567 } 4584 }
4568 4585
4569 4586
4570 // --- Native fields and functions --- 4587 // --- Native fields and functions ---
4571 4588
4572 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, 4589 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library,
4573 Dart_Handle name, 4590 Dart_Handle name,
4574 int field_count) { 4591 int field_count) {
4575 DARTSCOPE(Thread::Current()); 4592 DARTSCOPE(Thread::Current());
4576 const String& cls_name = Api::UnwrapStringHandle(I, name); 4593 const String& cls_name = Api::UnwrapStringHandle(Z, name);
4577 if (cls_name.IsNull()) { 4594 if (cls_name.IsNull()) {
4578 RETURN_TYPE_ERROR(I, name, String); 4595 RETURN_TYPE_ERROR(Z, name, String);
4579 } 4596 }
4580 const Library& lib = Api::UnwrapLibraryHandle(I, library); 4597 const Library& lib = Api::UnwrapLibraryHandle(Z, library);
4581 if (lib.IsNull()) { 4598 if (lib.IsNull()) {
4582 RETURN_TYPE_ERROR(I, library, Library); 4599 RETURN_TYPE_ERROR(Z, library, Library);
4583 } 4600 }
4584 if (!Utils::IsUint(16, field_count)) { 4601 if (!Utils::IsUint(16, field_count)) {
4585 return Api::NewError( 4602 return Api::NewError(
4586 "Invalid field_count passed to Dart_CreateNativeWrapperClass"); 4603 "Invalid field_count passed to Dart_CreateNativeWrapperClass");
4587 } 4604 }
4588 CHECK_CALLBACK_STATE(I); 4605 CHECK_CALLBACK_STATE(I);
4589 4606
4590 String& cls_symbol = String::Handle(Z, Symbols::New(cls_name)); 4607 String& cls_symbol = String::Handle(Z, Symbols::New(cls_name));
4591 const Class& cls = Class::Handle(Z, 4608 const Class& cls = Class::Handle(Z,
4592 Class::NewNativeWrapper(lib, cls_symbol, field_count)); 4609 Class::NewNativeWrapper(lib, cls_symbol, field_count));
4593 if (cls.IsNull()) { 4610 if (cls.IsNull()) {
4594 return Api::NewError( 4611 return Api::NewError(
4595 "Unable to create native wrapper class : already exists"); 4612 "Unable to create native wrapper class : already exists");
4596 } 4613 }
4597 return Api::NewHandle(I, cls.RareType()); 4614 return Api::NewHandle(I, cls.RareType());
4598 } 4615 }
4599 4616
4600 4617
4601 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, 4618 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj,
4602 int* count) { 4619 int* count) {
4603 Thread* thread = Thread::Current(); 4620 Thread* thread = Thread::Current();
4604 CHECK_ISOLATE(thread->isolate()); 4621 CHECK_ISOLATE(thread->isolate());
4605 ReusableObjectHandleScope reused_obj_handle(thread); 4622 ReusableObjectHandleScope reused_obj_handle(thread);
4606 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj); 4623 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj);
4607 if (instance.IsNull()) { 4624 if (instance.IsNull()) {
4608 RETURN_TYPE_ERROR(thread->isolate(), obj, Instance); 4625 RETURN_TYPE_ERROR(thread->zone(), obj, Instance);
4609 } 4626 }
4610 *count = instance.NumNativeFields(); 4627 *count = instance.NumNativeFields();
4611 return Api::Success(); 4628 return Api::Success();
4612 } 4629 }
4613 4630
4614 4631
4615 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, 4632 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj,
4616 int index, 4633 int index,
4617 intptr_t* value) { 4634 intptr_t* value) {
4618 Thread* thread = Thread::Current(); 4635 Thread* thread = Thread::Current();
4619 CHECK_ISOLATE(thread->isolate()); 4636 CHECK_ISOLATE(thread->isolate());
4620 ReusableObjectHandleScope reused_obj_handle(thread); 4637 ReusableObjectHandleScope reused_obj_handle(thread);
4621 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj); 4638 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj);
4622 if (instance.IsNull()) { 4639 if (instance.IsNull()) {
4623 RETURN_TYPE_ERROR(thread->isolate(), obj, Instance); 4640 RETURN_TYPE_ERROR(thread->zone(), obj, Instance);
4624 } 4641 }
4625 if (!instance.IsValidNativeIndex(index)) { 4642 if (!instance.IsValidNativeIndex(index)) {
4626 return Api::NewError( 4643 return Api::NewError(
4627 "%s: invalid index %d passed in to access native instance field", 4644 "%s: invalid index %d passed in to access native instance field",
4628 CURRENT_FUNC, index); 4645 CURRENT_FUNC, index);
4629 } 4646 }
4630 *value = instance.GetNativeField(index); 4647 *value = instance.GetNativeField(index);
4631 return Api::Success(); 4648 return Api::Success();
4632 } 4649 }
4633 4650
4634 4651
4635 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, 4652 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj,
4636 int index, 4653 int index,
4637 intptr_t value) { 4654 intptr_t value) {
4638 DARTSCOPE(Thread::Current()); 4655 DARTSCOPE(Thread::Current());
4639 const Instance& instance = Api::UnwrapInstanceHandle(I, obj); 4656 const Instance& instance = Api::UnwrapInstanceHandle(Z, obj);
4640 if (instance.IsNull()) { 4657 if (instance.IsNull()) {
4641 RETURN_TYPE_ERROR(I, obj, Instance); 4658 RETURN_TYPE_ERROR(Z, obj, Instance);
4642 } 4659 }
4643 if (!instance.IsValidNativeIndex(index)) { 4660 if (!instance.IsValidNativeIndex(index)) {
4644 return Api::NewError( 4661 return Api::NewError(
4645 "%s: invalid index %d passed in to set native instance field", 4662 "%s: invalid index %d passed in to set native instance field",
4646 CURRENT_FUNC, index); 4663 CURRENT_FUNC, index);
4647 } 4664 }
4648 instance.SetNativeField(index, value); 4665 instance.SetNativeField(index, value);
4649 return Api::Success(); 4666 return Api::Success();
4650 } 4667 }
4651 4668
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
4942 isolate->api_state()->IsValidPrologueWeakPersistentHandle(rval))); 4959 isolate->api_state()->IsValidPrologueWeakPersistentHandle(rval)));
4943 #endif 4960 #endif
4944 Api::SetWeakHandleReturnValue(arguments, rval); 4961 Api::SetWeakHandleReturnValue(arguments, rval);
4945 } 4962 }
4946 4963
4947 4964
4948 // --- Environment --- 4965 // --- Environment ---
4949 RawString* Api::CallEnvironmentCallback(Isolate* isolate, const String& name) { 4966 RawString* Api::CallEnvironmentCallback(Isolate* isolate, const String& name) {
4950 Scope api_scope(isolate); 4967 Scope api_scope(isolate);
4951 Dart_EnvironmentCallback callback = isolate->environment_callback(); 4968 Dart_EnvironmentCallback callback = isolate->environment_callback();
4952 String& result = String::Handle(isolate); 4969 String& result = String::Handle(isolate->current_zone());
4953 if (callback != NULL) { 4970 if (callback != NULL) {
4954 Dart_Handle response = callback(Api::NewHandle(isolate, name.raw())); 4971 Dart_Handle response = callback(Api::NewHandle(isolate, name.raw()));
4955 if (::Dart_IsString(response)) { 4972 if (::Dart_IsString(response)) {
4956 result ^= Api::UnwrapHandle(response); 4973 result ^= Api::UnwrapHandle(response);
4957 } else if (::Dart_IsError(response)) { 4974 } else if (::Dart_IsError(response)) {
4958 const Object& error = 4975 const Object& error =
4959 Object::Handle(isolate, Api::UnwrapHandle(response)); 4976 Object::Handle(isolate->current_zone(), Api::UnwrapHandle(response));
4960 Exceptions::ThrowArgumentError( 4977 Exceptions::ThrowArgumentError(
4961 String::Handle(String::New(Error::Cast(error).ToErrorCString()))); 4978 String::Handle(String::New(Error::Cast(error).ToErrorCString())));
4962 } else if (!::Dart_IsNull(response)) { 4979 } else if (!::Dart_IsNull(response)) {
4963 // At this point everything except null are invalid environment values. 4980 // At this point everything except null are invalid environment values.
4964 Exceptions::ThrowArgumentError( 4981 Exceptions::ThrowArgumentError(
4965 String::Handle(String::New("Illegal environment value"))); 4982 String::Handle(String::New("Illegal environment value")));
4966 } 4983 }
4967 } 4984 }
4968 if (result.IsNull()) { 4985 if (result.IsNull()) {
4969 // TODO(iposva): Determine whether builtin values can be overriden by the 4986 // TODO(iposva): Determine whether builtin values can be overriden by the
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
5039 static void CompileSource(Isolate* isolate, 5056 static void CompileSource(Isolate* isolate,
5040 const Library& lib, 5057 const Library& lib,
5041 const Script& script, 5058 const Script& script,
5042 Dart_Handle* result) { 5059 Dart_Handle* result) {
5043 bool update_lib_status = (script.kind() == RawScript::kScriptTag || 5060 bool update_lib_status = (script.kind() == RawScript::kScriptTag ||
5044 script.kind() == RawScript::kLibraryTag); 5061 script.kind() == RawScript::kLibraryTag);
5045 if (update_lib_status) { 5062 if (update_lib_status) {
5046 lib.SetLoadInProgress(); 5063 lib.SetLoadInProgress();
5047 } 5064 }
5048 ASSERT(isolate != NULL); 5065 ASSERT(isolate != NULL);
5049 const Error& error = Error::Handle(isolate, Compiler::Compile(lib, script)); 5066 const Error& error =
5067 Error::Handle(isolate->current_zone(), Compiler::Compile(lib, script));
5050 if (error.IsNull()) { 5068 if (error.IsNull()) {
5051 *result = Api::NewHandle(isolate, lib.raw()); 5069 *result = Api::NewHandle(isolate, lib.raw());
5052 } else { 5070 } else {
5053 *result = Api::NewHandle(isolate, error.raw()); 5071 *result = Api::NewHandle(isolate, error.raw());
5054 // Compilation errors are not Dart instances, so just mark the library 5072 // Compilation errors are not Dart instances, so just mark the library
5055 // as having failed to load without providing an error instance. 5073 // as having failed to load without providing an error instance.
5056 lib.SetLoadError(Object::null_instance()); 5074 lib.SetLoadError(Object::null_instance());
5057 } 5075 }
5058 } 5076 }
5059 5077
5060 5078
5061 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, 5079 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
5062 Dart_Handle source, 5080 Dart_Handle source,
5063 intptr_t line_offset, 5081 intptr_t line_offset,
5064 intptr_t column_offset) { 5082 intptr_t column_offset) {
5065 DARTSCOPE(Thread::Current()); 5083 DARTSCOPE(Thread::Current());
5066 const String& url_str = Api::UnwrapStringHandle(I, url); 5084 const String& url_str = Api::UnwrapStringHandle(Z, url);
5067 if (url_str.IsNull()) { 5085 if (url_str.IsNull()) {
5068 RETURN_TYPE_ERROR(I, url, String); 5086 RETURN_TYPE_ERROR(Z, url, String);
5069 } 5087 }
5070 const String& source_str = Api::UnwrapStringHandle(I, source); 5088 const String& source_str = Api::UnwrapStringHandle(Z, source);
5071 if (source_str.IsNull()) { 5089 if (source_str.IsNull()) {
5072 RETURN_TYPE_ERROR(I, source, String); 5090 RETURN_TYPE_ERROR(Z, source, String);
5073 } 5091 }
5074 Library& library = Library::Handle(Z, I->object_store()->root_library()); 5092 Library& library = Library::Handle(Z, I->object_store()->root_library());
5075 if (!library.IsNull()) { 5093 if (!library.IsNull()) {
5076 const String& library_url = String::Handle(Z, library.url()); 5094 const String& library_url = String::Handle(Z, library.url());
5077 return Api::NewError("%s: A script has already been loaded from '%s'.", 5095 return Api::NewError("%s: A script has already been loaded from '%s'.",
5078 CURRENT_FUNC, library_url.ToCString()); 5096 CURRENT_FUNC, library_url.ToCString());
5079 } 5097 }
5080 if (line_offset < 0) { 5098 if (line_offset < 0) {
5081 return Api::NewError("%s: argument 'line_offset' must be positive number", 5099 return Api::NewError("%s: argument 'line_offset' must be positive number",
5082 CURRENT_FUNC); 5100 CURRENT_FUNC);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
5148 DART_EXPORT Dart_Handle Dart_RootLibrary() { 5166 DART_EXPORT Dart_Handle Dart_RootLibrary() {
5149 Isolate* isolate = Isolate::Current(); 5167 Isolate* isolate = Isolate::Current();
5150 CHECK_ISOLATE(isolate); 5168 CHECK_ISOLATE(isolate);
5151 return Api::NewHandle(isolate, isolate->object_store()->root_library()); 5169 return Api::NewHandle(isolate, isolate->object_store()->root_library());
5152 } 5170 }
5153 5171
5154 5172
5155 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, 5173 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library,
5156 Dart_Handle class_name) { 5174 Dart_Handle class_name) {
5157 DARTSCOPE(Thread::Current()); 5175 DARTSCOPE(Thread::Current());
5158 const Library& lib = Api::UnwrapLibraryHandle(I, library); 5176 const Library& lib = Api::UnwrapLibraryHandle(Z, library);
5159 if (lib.IsNull()) { 5177 if (lib.IsNull()) {
5160 RETURN_TYPE_ERROR(I, library, Library); 5178 RETURN_TYPE_ERROR(Z, library, Library);
5161 } 5179 }
5162 const String& cls_name = Api::UnwrapStringHandle(I, class_name); 5180 const String& cls_name = Api::UnwrapStringHandle(Z, class_name);
5163 if (cls_name.IsNull()) { 5181 if (cls_name.IsNull()) {
5164 RETURN_TYPE_ERROR(I, class_name, String); 5182 RETURN_TYPE_ERROR(Z, class_name, String);
5165 } 5183 }
5166 const Class& cls = Class::Handle(Z, lib.LookupClassAllowPrivate(cls_name)); 5184 const Class& cls = Class::Handle(Z, lib.LookupClassAllowPrivate(cls_name));
5167 if (cls.IsNull()) { 5185 if (cls.IsNull()) {
5168 // TODO(turnidge): Return null or error in this case? 5186 // TODO(turnidge): Return null or error in this case?
5169 const String& lib_name = String::Handle(Z, lib.name()); 5187 const String& lib_name = String::Handle(Z, lib.name());
5170 return Api::NewError("Class '%s' not found in library '%s'.", 5188 return Api::NewError("Class '%s' not found in library '%s'.",
5171 cls_name.ToCString(), lib_name.ToCString()); 5189 cls_name.ToCString(), lib_name.ToCString());
5172 } 5190 }
5173 return Api::NewHandle(I, cls.RareType()); 5191 return Api::NewHandle(I, cls.RareType());
5174 } 5192 }
5175 5193
5176 5194
5177 DART_EXPORT Dart_Handle Dart_GetType(Dart_Handle library, 5195 DART_EXPORT Dart_Handle Dart_GetType(Dart_Handle library,
5178 Dart_Handle class_name, 5196 Dart_Handle class_name,
5179 intptr_t number_of_type_arguments, 5197 intptr_t number_of_type_arguments,
5180 Dart_Handle* type_arguments) { 5198 Dart_Handle* type_arguments) {
5181 DARTSCOPE(Thread::Current()); 5199 DARTSCOPE(Thread::Current());
5182 5200
5183 // Validate the input arguments. 5201 // Validate the input arguments.
5184 const Library& lib = Api::UnwrapLibraryHandle(I, library); 5202 const Library& lib = Api::UnwrapLibraryHandle(Z, library);
5185 if (lib.IsNull()) { 5203 if (lib.IsNull()) {
5186 RETURN_TYPE_ERROR(I, library, Library); 5204 RETURN_TYPE_ERROR(Z, library, Library);
5187 } 5205 }
5188 if (!lib.Loaded()) { 5206 if (!lib.Loaded()) {
5189 return Api::NewError( 5207 return Api::NewError(
5190 "%s expects library argument 'library' to be loaded.", 5208 "%s expects library argument 'library' to be loaded.",
5191 CURRENT_FUNC); 5209 CURRENT_FUNC);
5192 } 5210 }
5193 const String& name_str = Api::UnwrapStringHandle(I, class_name); 5211 const String& name_str = Api::UnwrapStringHandle(Z, class_name);
5194 if (name_str.IsNull()) { 5212 if (name_str.IsNull()) {
5195 RETURN_TYPE_ERROR(I, class_name, String); 5213 RETURN_TYPE_ERROR(Z, class_name, String);
5196 } 5214 }
5197 const Class& cls = Class::Handle(Z, lib.LookupClassAllowPrivate(name_str)); 5215 const Class& cls = Class::Handle(Z, lib.LookupClassAllowPrivate(name_str));
5198 if (cls.IsNull()) { 5216 if (cls.IsNull()) {
5199 const String& lib_name = String::Handle(Z, lib.name()); 5217 const String& lib_name = String::Handle(Z, lib.name());
5200 return Api::NewError("Type '%s' not found in library '%s'.", 5218 return Api::NewError("Type '%s' not found in library '%s'.",
5201 name_str.ToCString(), lib_name.ToCString()); 5219 name_str.ToCString(), lib_name.ToCString());
5202 } 5220 }
5203 if (cls.NumTypeArguments() == 0) { 5221 if (cls.NumTypeArguments() == 0) {
5204 if (number_of_type_arguments != 0) { 5222 if (number_of_type_arguments != 0) {
5205 return Api::NewError("Invalid number of type arguments specified, " 5223 return Api::NewError("Invalid number of type arguments specified, "
5206 "got %" Pd " expected 0", number_of_type_arguments); 5224 "got %" Pd " expected 0", number_of_type_arguments);
5207 } 5225 }
5208 return Api::NewHandle(I, Type::NewNonParameterizedType(cls)); 5226 return Api::NewHandle(I, Type::NewNonParameterizedType(cls));
5209 } 5227 }
5210 intptr_t num_expected_type_arguments = cls.NumTypeParameters(); 5228 intptr_t num_expected_type_arguments = cls.NumTypeParameters();
5211 TypeArguments& type_args_obj = TypeArguments::Handle(); 5229 TypeArguments& type_args_obj = TypeArguments::Handle();
5212 if (number_of_type_arguments > 0) { 5230 if (number_of_type_arguments > 0) {
5213 if (type_arguments == NULL) { 5231 if (type_arguments == NULL) {
5214 RETURN_NULL_ERROR(type_arguments); 5232 RETURN_NULL_ERROR(type_arguments);
5215 } 5233 }
5216 if (num_expected_type_arguments != number_of_type_arguments) { 5234 if (num_expected_type_arguments != number_of_type_arguments) {
5217 return Api::NewError("Invalid number of type arguments specified, " 5235 return Api::NewError("Invalid number of type arguments specified, "
5218 "got %" Pd " expected %" Pd, 5236 "got %" Pd " expected %" Pd,
5219 number_of_type_arguments, 5237 number_of_type_arguments,
5220 num_expected_type_arguments); 5238 num_expected_type_arguments);
5221 } 5239 }
5222 const Array& array = Api::UnwrapArrayHandle(I, *type_arguments); 5240 const Array& array = Api::UnwrapArrayHandle(Z, *type_arguments);
5223 if (array.IsNull()) { 5241 if (array.IsNull()) {
5224 RETURN_TYPE_ERROR(I, *type_arguments, Array); 5242 RETURN_TYPE_ERROR(Z, *type_arguments, Array);
5225 } 5243 }
5226 if (array.Length() != num_expected_type_arguments) { 5244 if (array.Length() != num_expected_type_arguments) {
5227 return Api::NewError("Invalid type arguments specified, expected an " 5245 return Api::NewError("Invalid type arguments specified, expected an "
5228 "array of len %" Pd " but got an array of len %" Pd, 5246 "array of len %" Pd " but got an array of len %" Pd,
5229 number_of_type_arguments, 5247 number_of_type_arguments,
5230 array.Length()); 5248 array.Length());
5231 } 5249 }
5232 // Set up the type arguments array. 5250 // Set up the type arguments array.
5233 type_args_obj ^= TypeArguments::New(num_expected_type_arguments); 5251 type_args_obj ^= TypeArguments::New(num_expected_type_arguments);
5234 AbstractType& type_arg = AbstractType::Handle(); 5252 AbstractType& type_arg = AbstractType::Handle();
5235 for (intptr_t i = 0; i < number_of_type_arguments; i++) { 5253 for (intptr_t i = 0; i < number_of_type_arguments; i++) {
5236 type_arg ^= array.At(i); 5254 type_arg ^= array.At(i);
5237 type_args_obj.SetTypeAt(i, type_arg); 5255 type_args_obj.SetTypeAt(i, type_arg);
5238 } 5256 }
5239 } 5257 }
5240 5258
5241 // Construct the type object, canonicalize it and return. 5259 // Construct the type object, canonicalize it and return.
5242 Type& instantiated_type = Type::Handle( 5260 Type& instantiated_type = Type::Handle(
5243 Type::New(cls, type_args_obj, Scanner::kNoSourcePos)); 5261 Type::New(cls, type_args_obj, Scanner::kNoSourcePos));
5244 instantiated_type ^= ClassFinalizer::FinalizeType( 5262 instantiated_type ^= ClassFinalizer::FinalizeType(
5245 cls, instantiated_type, ClassFinalizer::kCanonicalize); 5263 cls, instantiated_type, ClassFinalizer::kCanonicalize);
5246 return Api::NewHandle(I, instantiated_type.raw()); 5264 return Api::NewHandle(I, instantiated_type.raw());
5247 } 5265 }
5248 5266
5249 5267
5250 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { 5268 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) {
5251 DARTSCOPE(Thread::Current()); 5269 DARTSCOPE(Thread::Current());
5252 const Library& lib = Api::UnwrapLibraryHandle(I, library); 5270 const Library& lib = Api::UnwrapLibraryHandle(Z, library);
5253 if (lib.IsNull()) { 5271 if (lib.IsNull()) {
5254 RETURN_TYPE_ERROR(I, library, Library); 5272 RETURN_TYPE_ERROR(Z, library, Library);
5255 } 5273 }
5256 const String& url = String::Handle(Z, lib.url()); 5274 const String& url = String::Handle(Z, lib.url());
5257 ASSERT(!url.IsNull()); 5275 ASSERT(!url.IsNull());
5258 return Api::NewHandle(I, url.raw()); 5276 return Api::NewHandle(I, url.raw());
5259 } 5277 }
5260 5278
5261 5279
5262 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { 5280 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) {
5263 DARTSCOPE(Thread::Current()); 5281 DARTSCOPE(Thread::Current());
5264 const String& url_str = Api::UnwrapStringHandle(I, url); 5282 const String& url_str = Api::UnwrapStringHandle(Z, url);
5265 if (url_str.IsNull()) { 5283 if (url_str.IsNull()) {
5266 RETURN_TYPE_ERROR(I, url, String); 5284 RETURN_TYPE_ERROR(Z, url, String);
5267 } 5285 }
5268 const Library& library = Library::Handle(Z, Library::LookupLibrary(url_str)); 5286 const Library& library = Library::Handle(Z, Library::LookupLibrary(url_str));
5269 if (library.IsNull()) { 5287 if (library.IsNull()) {
5270 return Api::NewError("%s: library '%s' not found.", 5288 return Api::NewError("%s: library '%s' not found.",
5271 CURRENT_FUNC, url_str.ToCString()); 5289 CURRENT_FUNC, url_str.ToCString());
5272 } else { 5290 } else {
5273 return Api::NewHandle(I, library.raw()); 5291 return Api::NewHandle(I, library.raw());
5274 } 5292 }
5275 } 5293 }
5276 5294
5277 5295
5278 DART_EXPORT Dart_Handle Dart_LibraryHandleError(Dart_Handle library_in, 5296 DART_EXPORT Dart_Handle Dart_LibraryHandleError(Dart_Handle library_in,
5279 Dart_Handle error_in) { 5297 Dart_Handle error_in) {
5280 DARTSCOPE(Thread::Current()); 5298 DARTSCOPE(Thread::Current());
5281 5299
5282 const Library& lib = Api::UnwrapLibraryHandle(I, library_in); 5300 const Library& lib = Api::UnwrapLibraryHandle(Z, library_in);
5283 if (lib.IsNull()) { 5301 if (lib.IsNull()) {
5284 RETURN_TYPE_ERROR(I, library_in, Library); 5302 RETURN_TYPE_ERROR(Z, library_in, Library);
5285 } 5303 }
5286 const Instance& err = Api::UnwrapInstanceHandle(I, error_in); 5304 const Instance& err = Api::UnwrapInstanceHandle(Z, error_in);
5287 if (err.IsNull()) { 5305 if (err.IsNull()) {
5288 RETURN_TYPE_ERROR(I, error_in, Instance); 5306 RETURN_TYPE_ERROR(Z, error_in, Instance);
5289 } 5307 }
5290 CHECK_CALLBACK_STATE(I); 5308 CHECK_CALLBACK_STATE(I);
5291 5309
5292 const GrowableObjectArray& pending_deferred_loads = 5310 const GrowableObjectArray& pending_deferred_loads =
5293 GrowableObjectArray::Handle(Z, 5311 GrowableObjectArray::Handle(Z,
5294 I->object_store()->pending_deferred_loads()); 5312 I->object_store()->pending_deferred_loads());
5295 for (intptr_t i = 0; i < pending_deferred_loads.Length(); i++) { 5313 for (intptr_t i = 0; i < pending_deferred_loads.Length(); i++) {
5296 if (pending_deferred_loads.At(i) == lib.raw()) { 5314 if (pending_deferred_loads.At(i) == lib.raw()) {
5297 lib.SetLoadError(err); 5315 lib.SetLoadError(err);
5298 return Api::Null(); 5316 return Api::Null();
5299 } 5317 }
5300 } 5318 }
5301 return error_in; 5319 return error_in;
5302 } 5320 }
5303 5321
5304 5322
5305 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, 5323 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url,
5306 Dart_Handle source, 5324 Dart_Handle source,
5307 intptr_t line_offset, 5325 intptr_t line_offset,
5308 intptr_t column_offset) { 5326 intptr_t column_offset) {
5309 DARTSCOPE(Thread::Current()); 5327 DARTSCOPE(Thread::Current());
5310 const String& url_str = Api::UnwrapStringHandle(I, url); 5328 const String& url_str = Api::UnwrapStringHandle(Z, url);
5311 if (url_str.IsNull()) { 5329 if (url_str.IsNull()) {
5312 RETURN_TYPE_ERROR(I, url, String); 5330 RETURN_TYPE_ERROR(Z, url, String);
5313 } 5331 }
5314 const String& source_str = Api::UnwrapStringHandle(I, source); 5332 const String& source_str = Api::UnwrapStringHandle(Z, source);
5315 if (source_str.IsNull()) { 5333 if (source_str.IsNull()) {
5316 RETURN_TYPE_ERROR(I, source, String); 5334 RETURN_TYPE_ERROR(Z, source, String);
5317 } 5335 }
5318 if (line_offset < 0) { 5336 if (line_offset < 0) {
5319 return Api::NewError("%s: argument 'line_offset' must be positive number", 5337 return Api::NewError("%s: argument 'line_offset' must be positive number",
5320 CURRENT_FUNC); 5338 CURRENT_FUNC);
5321 } 5339 }
5322 if (column_offset < 0) { 5340 if (column_offset < 0) {
5323 return Api::NewError("%s: argument 'column_offset' must be positive number", 5341 return Api::NewError("%s: argument 'column_offset' must be positive number",
5324 CURRENT_FUNC); 5342 CURRENT_FUNC);
5325 } 5343 }
5326 CHECK_CALLBACK_STATE(I); 5344 CHECK_CALLBACK_STATE(I);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
5359 } 5377 }
5360 } 5378 }
5361 return result; 5379 return result;
5362 } 5380 }
5363 5381
5364 5382
5365 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library, 5383 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library,
5366 Dart_Handle import, 5384 Dart_Handle import,
5367 Dart_Handle prefix) { 5385 Dart_Handle prefix) {
5368 DARTSCOPE(Thread::Current()); 5386 DARTSCOPE(Thread::Current());
5369 const Library& library_vm = Api::UnwrapLibraryHandle(I, library); 5387 const Library& library_vm = Api::UnwrapLibraryHandle(Z, library);
5370 if (library_vm.IsNull()) { 5388 if (library_vm.IsNull()) {
5371 RETURN_TYPE_ERROR(I, library, Library); 5389 RETURN_TYPE_ERROR(Z, library, Library);
5372 } 5390 }
5373 const Library& import_vm = Api::UnwrapLibraryHandle(I, import); 5391 const Library& import_vm = Api::UnwrapLibraryHandle(Z, import);
5374 if (import_vm.IsNull()) { 5392 if (import_vm.IsNull()) {
5375 RETURN_TYPE_ERROR(I, import, Library); 5393 RETURN_TYPE_ERROR(Z, import, Library);
5376 } 5394 }
5377 const Object& prefix_object = Object::Handle(Z, Api::UnwrapHandle(prefix)); 5395 const Object& prefix_object = Object::Handle(Z, Api::UnwrapHandle(prefix));
5378 const String& prefix_vm = prefix_object.IsNull() 5396 const String& prefix_vm = prefix_object.IsNull()
5379 ? Symbols::Empty() 5397 ? Symbols::Empty()
5380 : String::Cast(prefix_object); 5398 : String::Cast(prefix_object);
5381 if (prefix_vm.IsNull()) { 5399 if (prefix_vm.IsNull()) {
5382 RETURN_TYPE_ERROR(I, prefix, String); 5400 RETURN_TYPE_ERROR(Z, prefix, String);
5383 } 5401 }
5384 CHECK_CALLBACK_STATE(I); 5402 CHECK_CALLBACK_STATE(I);
5385 CHECK_COMPILATION_ALLOWED(I); 5403 CHECK_COMPILATION_ALLOWED(I);
5386 5404
5387 const String& prefix_symbol = String::Handle(Z, Symbols::New(prefix_vm)); 5405 const String& prefix_symbol = String::Handle(Z, Symbols::New(prefix_vm));
5388 const Namespace& import_ns = Namespace::Handle(Z, 5406 const Namespace& import_ns = Namespace::Handle(Z,
5389 Namespace::New(import_vm, Object::null_array(), Object::null_array())); 5407 Namespace::New(import_vm, Object::null_array(), Object::null_array()));
5390 if (prefix_vm.Length() == 0) { 5408 if (prefix_vm.Length() == 0) {
5391 library_vm.AddImport(import_ns); 5409 library_vm.AddImport(import_ns);
5392 } else { 5410 } else {
(...skipping 10 matching lines...) Expand all
5403 return Api::Success(); 5421 return Api::Success();
5404 } 5422 }
5405 5423
5406 5424
5407 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, 5425 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library,
5408 Dart_Handle url, 5426 Dart_Handle url,
5409 Dart_Handle source, 5427 Dart_Handle source,
5410 intptr_t line_offset, 5428 intptr_t line_offset,
5411 intptr_t column_offset) { 5429 intptr_t column_offset) {
5412 DARTSCOPE(Thread::Current()); 5430 DARTSCOPE(Thread::Current());
5413 const Library& lib = Api::UnwrapLibraryHandle(I, library); 5431 const Library& lib = Api::UnwrapLibraryHandle(Z, library);
5414 if (lib.IsNull()) { 5432 if (lib.IsNull()) {
5415 RETURN_TYPE_ERROR(I, library, Library); 5433 RETURN_TYPE_ERROR(Z, library, Library);
5416 } 5434 }
5417 const String& url_str = Api::UnwrapStringHandle(I, url); 5435 const String& url_str = Api::UnwrapStringHandle(Z, url);
5418 if (url_str.IsNull()) { 5436 if (url_str.IsNull()) {
5419 RETURN_TYPE_ERROR(I, url, String); 5437 RETURN_TYPE_ERROR(Z, url, String);
5420 } 5438 }
5421 const String& source_str = Api::UnwrapStringHandle(I, source); 5439 const String& source_str = Api::UnwrapStringHandle(Z, source);
5422 if (source_str.IsNull()) { 5440 if (source_str.IsNull()) {
5423 RETURN_TYPE_ERROR(I, source, String); 5441 RETURN_TYPE_ERROR(Z, source, String);
5424 } 5442 }
5425 if (line_offset < 0) { 5443 if (line_offset < 0) {
5426 return Api::NewError("%s: argument 'line_offset' must be positive number", 5444 return Api::NewError("%s: argument 'line_offset' must be positive number",
5427 CURRENT_FUNC); 5445 CURRENT_FUNC);
5428 } 5446 }
5429 if (column_offset < 0) { 5447 if (column_offset < 0) {
5430 return Api::NewError("%s: argument 'column_offset' must be positive number", 5448 return Api::NewError("%s: argument 'column_offset' must be positive number",
5431 CURRENT_FUNC); 5449 CURRENT_FUNC);
5432 } 5450 }
5433 CHECK_CALLBACK_STATE(I); 5451 CHECK_CALLBACK_STATE(I);
5434 CHECK_COMPILATION_ALLOWED(I); 5452 CHECK_COMPILATION_ALLOWED(I);
5435 5453
5436 NoHeapGrowthControlScope no_growth_control; 5454 NoHeapGrowthControlScope no_growth_control;
5437 5455
5438 const Script& script = Script::Handle(Z, 5456 const Script& script = Script::Handle(Z,
5439 Script::New(url_str, source_str, RawScript::kSourceTag)); 5457 Script::New(url_str, source_str, RawScript::kSourceTag));
5440 script.SetLocationOffset(line_offset, column_offset); 5458 script.SetLocationOffset(line_offset, column_offset);
5441 Dart_Handle result; 5459 Dart_Handle result;
5442 CompileSource(I, lib, script, &result); 5460 CompileSource(I, lib, script, &result);
5443 return result; 5461 return result;
5444 } 5462 }
5445 5463
5446 5464
5447 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, 5465 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library,
5448 Dart_Handle url, 5466 Dart_Handle url,
5449 Dart_Handle patch_source) { 5467 Dart_Handle patch_source) {
5450 DARTSCOPE(Thread::Current()); 5468 DARTSCOPE(Thread::Current());
5451 const Library& lib = Api::UnwrapLibraryHandle(I, library); 5469 const Library& lib = Api::UnwrapLibraryHandle(Z, library);
5452 if (lib.IsNull()) { 5470 if (lib.IsNull()) {
5453 RETURN_TYPE_ERROR(I, library, Library); 5471 RETURN_TYPE_ERROR(Z, library, Library);
5454 } 5472 }
5455 const String& url_str = Api::UnwrapStringHandle(I, url); 5473 const String& url_str = Api::UnwrapStringHandle(Z, url);
5456 if (url_str.IsNull()) { 5474 if (url_str.IsNull()) {
5457 RETURN_TYPE_ERROR(I, url, String); 5475 RETURN_TYPE_ERROR(Z, url, String);
5458 } 5476 }
5459 const String& source_str = Api::UnwrapStringHandle(I, patch_source); 5477 const String& source_str = Api::UnwrapStringHandle(Z, patch_source);
5460 if (source_str.IsNull()) { 5478 if (source_str.IsNull()) {
5461 RETURN_TYPE_ERROR(I, patch_source, String); 5479 RETURN_TYPE_ERROR(Z, patch_source, String);
5462 } 5480 }
5463 CHECK_CALLBACK_STATE(I); 5481 CHECK_CALLBACK_STATE(I);
5464 CHECK_COMPILATION_ALLOWED(I); 5482 CHECK_COMPILATION_ALLOWED(I);
5465 5483
5466 NoHeapGrowthControlScope no_growth_control; 5484 NoHeapGrowthControlScope no_growth_control;
5467 5485
5468 const Script& script = Script::Handle(Z, 5486 const Script& script = Script::Handle(Z,
5469 Script::New(url_str, source_str, RawScript::kPatchTag)); 5487 Script::New(url_str, source_str, RawScript::kPatchTag));
5470 Dart_Handle result; 5488 Dart_Handle result;
5471 CompileSource(I, lib, script, &result); 5489 CompileSource(I, lib, script, &result);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
5522 } 5540 }
5523 return Api::Success(); 5541 return Api::Success();
5524 } 5542 }
5525 5543
5526 5544
5527 DART_EXPORT Dart_Handle Dart_SetNativeResolver( 5545 DART_EXPORT Dart_Handle Dart_SetNativeResolver(
5528 Dart_Handle library, 5546 Dart_Handle library,
5529 Dart_NativeEntryResolver resolver, 5547 Dart_NativeEntryResolver resolver,
5530 Dart_NativeEntrySymbol symbol) { 5548 Dart_NativeEntrySymbol symbol) {
5531 DARTSCOPE(Thread::Current()); 5549 DARTSCOPE(Thread::Current());
5532 const Library& lib = Api::UnwrapLibraryHandle(I, library); 5550 const Library& lib = Api::UnwrapLibraryHandle(Z, library);
5533 if (lib.IsNull()) { 5551 if (lib.IsNull()) {
5534 RETURN_TYPE_ERROR(I, library, Library); 5552 RETURN_TYPE_ERROR(Z, library, Library);
5535 } 5553 }
5536 lib.set_native_entry_resolver(resolver); 5554 lib.set_native_entry_resolver(resolver);
5537 lib.set_native_entry_symbol_resolver(symbol); 5555 lib.set_native_entry_symbol_resolver(symbol);
5538 return Api::Success(); 5556 return Api::Success();
5539 } 5557 }
5540 5558
5541 5559
5542 // --- Peer support --- 5560 // --- Peer support ---
5543 5561
5544 DART_EXPORT Dart_Handle Dart_GetPeer(Dart_Handle object, void** peer) { 5562 DART_EXPORT Dart_Handle Dart_GetPeer(Dart_Handle object, void** peer) {
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
6072 ApiReallocate); 6090 ApiReallocate);
6073 writer.WriteFullSnapshot(); 6091 writer.WriteFullSnapshot();
6074 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); 6092 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize();
6075 *isolate_snapshot_size = writer.IsolateSnapshotSize(); 6093 *isolate_snapshot_size = writer.IsolateSnapshotSize();
6076 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); 6094 *instructions_snapshot_size = writer.InstructionsSnapshotSize();
6077 6095
6078 return Api::Success(); 6096 return Api::Success();
6079 } 6097 }
6080 6098
6081 } // namespace dart 6099 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698