OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
8 | 8 |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 } | 444 } |
445 | 445 |
446 | 446 |
447 Dart_Isolate Api::CastIsolate(Isolate* isolate) { | 447 Dart_Isolate Api::CastIsolate(Isolate* isolate) { |
448 return reinterpret_cast<Dart_Isolate>(isolate); | 448 return reinterpret_cast<Dart_Isolate>(isolate); |
449 } | 449 } |
450 | 450 |
451 | 451 |
452 Dart_Handle Api::NewError(const char* format, ...) { | 452 Dart_Handle Api::NewError(const char* format, ...) { |
453 DARTSCOPE(Thread::Current()); | 453 DARTSCOPE(Thread::Current()); |
454 CHECK_CALLBACK_STATE(I); | 454 CHECK_CALLBACK_STATE(T); |
455 | 455 |
456 va_list args; | 456 va_list args; |
457 va_start(args, format); | 457 va_start(args, format); |
458 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 458 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
459 va_end(args); | 459 va_end(args); |
460 | 460 |
461 char* buffer = Z->Alloc<char>(len + 1); | 461 char* buffer = Z->Alloc<char>(len + 1); |
462 va_list args2; | 462 va_list args2; |
463 va_start(args2, format); | 463 va_start(args2, format); |
464 OS::VSNPrint(buffer, (len + 1), format, args2); | 464 OS::VSNPrint(buffer, (len + 1), format, args2); |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 } else { | 807 } else { |
808 return Api::NewError("Can only get stacktraces from error handles."); | 808 return Api::NewError("Can only get stacktraces from error handles."); |
809 } | 809 } |
810 } | 810 } |
811 | 811 |
812 | 812 |
813 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to | 813 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to |
814 // fix this but not sure if it available on all of our builds. | 814 // fix this but not sure if it available on all of our builds. |
815 DART_EXPORT Dart_Handle Dart_NewApiError(const char* error) { | 815 DART_EXPORT Dart_Handle Dart_NewApiError(const char* error) { |
816 DARTSCOPE(Thread::Current()); | 816 DARTSCOPE(Thread::Current()); |
817 CHECK_CALLBACK_STATE(I); | 817 CHECK_CALLBACK_STATE(T); |
818 | 818 |
819 const String& message = String::Handle(Z, String::New(error)); | 819 const String& message = String::Handle(Z, String::New(error)); |
820 return Api::NewHandle(I, ApiError::New(message)); | 820 return Api::NewHandle(I, ApiError::New(message)); |
821 } | 821 } |
822 | 822 |
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(T); |
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(Z, exception).raw(); | 833 obj = Api::UnwrapInstanceHandle(Z, exception).raw(); |
834 if (obj.IsNull()) { | 834 if (obj.IsNull()) { |
835 RETURN_TYPE_ERROR(Z, exception, Instance); | 835 RETURN_TYPE_ERROR(Z, exception, Instance); |
836 } | 836 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 OS::Abort(); | 890 OS::Abort(); |
891 } | 891 } |
892 | 892 |
893 | 893 |
894 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { | 894 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { |
895 DARTSCOPE(Thread::Current()); | 895 DARTSCOPE(Thread::Current()); |
896 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); | 896 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); |
897 if (obj.IsString()) { | 897 if (obj.IsString()) { |
898 return Api::NewHandle(I, obj.raw()); | 898 return Api::NewHandle(I, obj.raw()); |
899 } else if (obj.IsInstance()) { | 899 } else if (obj.IsInstance()) { |
900 CHECK_CALLBACK_STATE(I); | 900 CHECK_CALLBACK_STATE(T); |
901 const Instance& receiver = Instance::Cast(obj); | 901 const Instance& receiver = Instance::Cast(obj); |
902 return Api::NewHandle(I, DartLibraryCalls::ToString(receiver)); | 902 return Api::NewHandle(I, DartLibraryCalls::ToString(receiver)); |
903 } else { | 903 } else { |
904 CHECK_CALLBACK_STATE(I); | 904 CHECK_CALLBACK_STATE(T); |
905 // This is a VM internal object. Call the C++ method of printing. | 905 // This is a VM internal object. Call the C++ method of printing. |
906 return Api::NewHandle(I, String::New(obj.ToCString())); | 906 return Api::NewHandle(I, String::New(obj.ToCString())); |
907 } | 907 } |
908 } | 908 } |
909 | 909 |
910 | 910 |
911 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2) { | 911 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2) { |
912 DARTSCOPE(Thread::Current()); | 912 DARTSCOPE(Thread::Current()); |
913 { | 913 { |
914 NoSafepointScope no_safepoint_scope; | 914 NoSafepointScope no_safepoint_scope; |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1647 MonitorLocker ml(data->monitor); | 1647 MonitorLocker ml(data->monitor); |
1648 data->done = true; | 1648 data->done = true; |
1649 ml.Notify(); | 1649 ml.Notify(); |
1650 } | 1650 } |
1651 | 1651 |
1652 | 1652 |
1653 DART_EXPORT Dart_Handle Dart_RunLoop() { | 1653 DART_EXPORT Dart_Handle Dart_RunLoop() { |
1654 Thread* T = Thread::Current(); | 1654 Thread* T = Thread::Current(); |
1655 Isolate* I = T->isolate(); | 1655 Isolate* I = T->isolate(); |
1656 CHECK_ISOLATE_SCOPE(I); | 1656 CHECK_ISOLATE_SCOPE(I); |
1657 CHECK_CALLBACK_STATE(I); | 1657 CHECK_CALLBACK_STATE(T); |
1658 Monitor monitor; | 1658 Monitor monitor; |
1659 MonitorLocker ml(&monitor); | 1659 MonitorLocker ml(&monitor); |
1660 { | 1660 { |
1661 SwitchIsolateScope switch_scope(NULL); | 1661 SwitchIsolateScope switch_scope(NULL); |
1662 | 1662 |
1663 RunLoopData data; | 1663 RunLoopData data; |
1664 data.monitor = &monitor; | 1664 data.monitor = &monitor; |
1665 data.done = false; | 1665 data.done = false; |
1666 I->message_handler()->Run( | 1666 I->message_handler()->Run( |
1667 Dart::thread_pool(), | 1667 Dart::thread_pool(), |
1668 NULL, RunLoopDone, reinterpret_cast<uword>(&data)); | 1668 NULL, RunLoopDone, reinterpret_cast<uword>(&data)); |
1669 while (!data.done) { | 1669 while (!data.done) { |
1670 ml.Wait(); | 1670 ml.Wait(); |
1671 } | 1671 } |
1672 } | 1672 } |
1673 if (I->object_store()->sticky_error() != Object::null()) { | 1673 if (I->object_store()->sticky_error() != Object::null()) { |
1674 Dart_Handle error = Api::NewHandle(I, I->object_store()->sticky_error()); | 1674 Dart_Handle error = Api::NewHandle(I, I->object_store()->sticky_error()); |
1675 I->object_store()->clear_sticky_error(); | 1675 I->object_store()->clear_sticky_error(); |
1676 return error; | 1676 return error; |
1677 } | 1677 } |
1678 if (FLAG_print_class_table) { | 1678 if (FLAG_print_class_table) { |
1679 HANDLESCOPE(T); | 1679 HANDLESCOPE(T); |
1680 I->class_table()->Print(); | 1680 I->class_table()->Print(); |
1681 } | 1681 } |
1682 return Api::Success(); | 1682 return Api::Success(); |
1683 } | 1683 } |
1684 | 1684 |
1685 | 1685 |
1686 DART_EXPORT Dart_Handle Dart_HandleMessage() { | 1686 DART_EXPORT Dart_Handle Dart_HandleMessage() { |
1687 Isolate* isolate = Isolate::Current(); | 1687 Thread* thread = Thread::Current(); |
| 1688 Isolate* isolate = thread->isolate(); |
1688 CHECK_ISOLATE_SCOPE(isolate); | 1689 CHECK_ISOLATE_SCOPE(isolate); |
1689 CHECK_CALLBACK_STATE(isolate); | 1690 CHECK_CALLBACK_STATE(thread); |
1690 if (isolate->message_handler()->HandleNextMessage() != MessageHandler::kOK) { | 1691 if (isolate->message_handler()->HandleNextMessage() != MessageHandler::kOK) { |
1691 Dart_Handle error = Api::NewHandle(isolate, | 1692 Dart_Handle error = Api::NewHandle(isolate, |
1692 isolate->object_store()->sticky_error()); | 1693 isolate->object_store()->sticky_error()); |
1693 isolate->object_store()->clear_sticky_error(); | 1694 isolate->object_store()->clear_sticky_error(); |
1694 return error; | 1695 return error; |
1695 } | 1696 } |
1696 return Api::Success(); | 1697 return Api::Success(); |
1697 } | 1698 } |
1698 | 1699 |
1699 | 1700 |
1700 DART_EXPORT bool Dart_HandleServiceMessages() { | 1701 DART_EXPORT bool Dart_HandleServiceMessages() { |
1701 Isolate* isolate = Isolate::Current(); | 1702 Thread* thread = Thread::Current(); |
| 1703 Isolate* isolate = thread->isolate(); |
1702 CHECK_ISOLATE_SCOPE(isolate); | 1704 CHECK_ISOLATE_SCOPE(isolate); |
1703 CHECK_CALLBACK_STATE(isolate); | 1705 CHECK_CALLBACK_STATE(thread); |
1704 | 1706 |
1705 ASSERT(isolate->GetAndClearResumeRequest() == false); | 1707 ASSERT(isolate->GetAndClearResumeRequest() == false); |
1706 MessageHandler::MessageStatus status = | 1708 MessageHandler::MessageStatus status = |
1707 isolate->message_handler()->HandleOOBMessages(); | 1709 isolate->message_handler()->HandleOOBMessages(); |
1708 bool resume = isolate->GetAndClearResumeRequest(); | 1710 bool resume = isolate->GetAndClearResumeRequest(); |
1709 return (status != MessageHandler::kOK) || resume; | 1711 return (status != MessageHandler::kOK) || resume; |
1710 } | 1712 } |
1711 | 1713 |
1712 | 1714 |
1713 DART_EXPORT bool Dart_HasServiceMessages() { | 1715 DART_EXPORT bool Dart_HasServiceMessages() { |
(...skipping 26 matching lines...) Expand all Loading... |
1740 MessageWriter writer(&data, &allocator, false); | 1742 MessageWriter writer(&data, &allocator, false); |
1741 writer.WriteMessage(object); | 1743 writer.WriteMessage(object); |
1742 intptr_t len = writer.BytesWritten(); | 1744 intptr_t len = writer.BytesWritten(); |
1743 return PortMap::PostMessage(new Message( | 1745 return PortMap::PostMessage(new Message( |
1744 port_id, data, len, Message::kNormalPriority)); | 1746 port_id, data, len, Message::kNormalPriority)); |
1745 } | 1747 } |
1746 | 1748 |
1747 | 1749 |
1748 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { | 1750 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { |
1749 DARTSCOPE(Thread::Current()); | 1751 DARTSCOPE(Thread::Current()); |
1750 CHECK_CALLBACK_STATE(I); | 1752 CHECK_CALLBACK_STATE(T); |
1751 if (port_id == ILLEGAL_PORT) { | 1753 if (port_id == ILLEGAL_PORT) { |
1752 return Api::NewError("%s: illegal port_id %" Pd64 ".", | 1754 return Api::NewError("%s: illegal port_id %" Pd64 ".", |
1753 CURRENT_FUNC, | 1755 CURRENT_FUNC, |
1754 port_id); | 1756 port_id); |
1755 } | 1757 } |
1756 return Api::NewHandle(I, SendPort::New(port_id)); | 1758 return Api::NewHandle(I, SendPort::New(port_id)); |
1757 } | 1759 } |
1758 | 1760 |
1759 | 1761 |
1760 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, | 1762 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, |
1761 Dart_Port* port_id) { | 1763 Dart_Port* port_id) { |
1762 DARTSCOPE(Thread::Current()); | 1764 DARTSCOPE(Thread::Current()); |
1763 CHECK_CALLBACK_STATE(I); | 1765 CHECK_CALLBACK_STATE(T); |
1764 const SendPort& send_port = Api::UnwrapSendPortHandle(Z, port); | 1766 const SendPort& send_port = Api::UnwrapSendPortHandle(Z, port); |
1765 if (send_port.IsNull()) { | 1767 if (send_port.IsNull()) { |
1766 RETURN_TYPE_ERROR(Z, port, SendPort); | 1768 RETURN_TYPE_ERROR(Z, port, SendPort); |
1767 } | 1769 } |
1768 if (port_id == NULL) { | 1770 if (port_id == NULL) { |
1769 RETURN_NULL_ERROR(port_id); | 1771 RETURN_NULL_ERROR(port_id); |
1770 } | 1772 } |
1771 *port_id = send_port.Id(); | 1773 *port_id = send_port.Id(); |
1772 return Api::Success(); | 1774 return Api::Success(); |
1773 } | 1775 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1853 | 1855 |
1854 | 1856 |
1855 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { | 1857 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { |
1856 return Api::UnwrapHandle(object) == Object::null(); | 1858 return Api::UnwrapHandle(object) == Object::null(); |
1857 } | 1859 } |
1858 | 1860 |
1859 | 1861 |
1860 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, | 1862 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, |
1861 bool* value) { | 1863 bool* value) { |
1862 DARTSCOPE(Thread::Current()); | 1864 DARTSCOPE(Thread::Current()); |
1863 CHECK_CALLBACK_STATE(I); | 1865 CHECK_CALLBACK_STATE(T); |
1864 const Instance& expected = | 1866 const Instance& expected = |
1865 Instance::CheckedHandle(Z, Api::UnwrapHandle(obj1)); | 1867 Instance::CheckedHandle(Z, Api::UnwrapHandle(obj1)); |
1866 const Instance& actual = | 1868 const Instance& actual = |
1867 Instance::CheckedHandle(Z, Api::UnwrapHandle(obj2)); | 1869 Instance::CheckedHandle(Z, Api::UnwrapHandle(obj2)); |
1868 const Object& result = | 1870 const Object& result = |
1869 Object::Handle(Z, DartLibraryCalls::Equals(expected, actual)); | 1871 Object::Handle(Z, DartLibraryCalls::Equals(expected, actual)); |
1870 if (result.IsBool()) { | 1872 if (result.IsBool()) { |
1871 *value = Bool::Cast(result).value(); | 1873 *value = Bool::Cast(result).value(); |
1872 return Api::Success(); | 1874 return Api::Success(); |
1873 } else if (result.IsError()) { | 1875 } else if (result.IsError()) { |
(...skipping 24 matching lines...) Expand all Loading... |
1898 } | 1900 } |
1899 if (object == Api::Null()) { | 1901 if (object == Api::Null()) { |
1900 *value = false; | 1902 *value = false; |
1901 return Api::Success(); | 1903 return Api::Success(); |
1902 } | 1904 } |
1903 const Instance& instance = Api::UnwrapInstanceHandle(Z, object); | 1905 const Instance& instance = Api::UnwrapInstanceHandle(Z, object); |
1904 if (instance.IsNull()) { | 1906 if (instance.IsNull()) { |
1905 *value = false; | 1907 *value = false; |
1906 RETURN_TYPE_ERROR(Z, object, Instance); | 1908 RETURN_TYPE_ERROR(Z, object, Instance); |
1907 } | 1909 } |
1908 CHECK_CALLBACK_STATE(I); | 1910 CHECK_CALLBACK_STATE(T); |
1909 Error& malformed_type_error = Error::Handle(Z); | 1911 Error& malformed_type_error = Error::Handle(Z); |
1910 *value = instance.IsInstanceOf(type_obj, | 1912 *value = instance.IsInstanceOf(type_obj, |
1911 Object::null_type_arguments(), | 1913 Object::null_type_arguments(), |
1912 &malformed_type_error); | 1914 &malformed_type_error); |
1913 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. | 1915 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. |
1914 return Api::Success(); | 1916 return Api::Success(); |
1915 } | 1917 } |
1916 | 1918 |
1917 | 1919 |
1918 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { | 1920 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2135 // Fast path for Smis. | 2137 // Fast path for Smis. |
2136 Thread* thread = Thread::Current(); | 2138 Thread* thread = Thread::Current(); |
2137 Isolate* isolate = thread->isolate(); | 2139 Isolate* isolate = thread->isolate(); |
2138 CHECK_ISOLATE(isolate); | 2140 CHECK_ISOLATE(isolate); |
2139 if (Smi::IsValid(value)) { | 2141 if (Smi::IsValid(value)) { |
2140 NOHANDLESCOPE(thread); | 2142 NOHANDLESCOPE(thread); |
2141 return Api::NewHandle(isolate, Smi::New(static_cast<intptr_t>(value))); | 2143 return Api::NewHandle(isolate, Smi::New(static_cast<intptr_t>(value))); |
2142 } | 2144 } |
2143 // Slow path for Mints and Bigints. | 2145 // Slow path for Mints and Bigints. |
2144 DARTSCOPE(thread); | 2146 DARTSCOPE(thread); |
2145 CHECK_CALLBACK_STATE(isolate); | 2147 CHECK_CALLBACK_STATE(thread); |
2146 return Api::NewHandle(isolate, Integer::New(value)); | 2148 return Api::NewHandle(isolate, Integer::New(value)); |
2147 } | 2149 } |
2148 | 2150 |
2149 | 2151 |
2150 DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value) { | 2152 DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value) { |
2151 DARTSCOPE(Thread::Current()); | 2153 DARTSCOPE(Thread::Current()); |
2152 CHECK_CALLBACK_STATE(I); | 2154 CHECK_CALLBACK_STATE(T); |
2153 return Api::NewHandle(I, Integer::NewFromUint64(value)); | 2155 return Api::NewHandle(I, Integer::NewFromUint64(value)); |
2154 } | 2156 } |
2155 | 2157 |
2156 | 2158 |
2157 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { | 2159 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { |
2158 DARTSCOPE(Thread::Current()); | 2160 DARTSCOPE(Thread::Current()); |
2159 CHECK_CALLBACK_STATE(I); | 2161 CHECK_CALLBACK_STATE(T); |
2160 const String& str_obj = String::Handle(Z, String::New(str)); | 2162 const String& str_obj = String::Handle(Z, String::New(str)); |
2161 return Api::NewHandle(I, Integer::New(str_obj)); | 2163 return Api::NewHandle(I, Integer::New(str_obj)); |
2162 } | 2164 } |
2163 | 2165 |
2164 | 2166 |
2165 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, | 2167 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, |
2166 int64_t* value) { | 2168 int64_t* value) { |
2167 // Fast path for Smis. | 2169 // Fast path for Smis. |
2168 Thread* thread = Thread::Current(); | 2170 Thread* thread = Thread::Current(); |
2169 Isolate* isolate = thread->isolate(); | 2171 Isolate* isolate = thread->isolate(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2248 *value = bigint.ToHexCString(BigintAllocate); | 2250 *value = bigint.ToHexCString(BigintAllocate); |
2249 } else { | 2251 } else { |
2250 *value = Bigint::Cast(int_obj).ToHexCString(BigintAllocate); | 2252 *value = Bigint::Cast(int_obj).ToHexCString(BigintAllocate); |
2251 } | 2253 } |
2252 return Api::Success(); | 2254 return Api::Success(); |
2253 } | 2255 } |
2254 | 2256 |
2255 | 2257 |
2256 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { | 2258 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { |
2257 DARTSCOPE(Thread::Current()); | 2259 DARTSCOPE(Thread::Current()); |
2258 CHECK_CALLBACK_STATE(I); | 2260 CHECK_CALLBACK_STATE(T); |
2259 return Api::NewHandle(I, Double::New(value)); | 2261 return Api::NewHandle(I, Double::New(value)); |
2260 } | 2262 } |
2261 | 2263 |
2262 | 2264 |
2263 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, | 2265 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, |
2264 double* value) { | 2266 double* value) { |
2265 DARTSCOPE(Thread::Current()); | 2267 DARTSCOPE(Thread::Current()); |
2266 const Double& obj = Api::UnwrapDoubleHandle(Z, double_obj); | 2268 const Double& obj = Api::UnwrapDoubleHandle(Z, double_obj); |
2267 if (obj.IsNull()) { | 2269 if (obj.IsNull()) { |
2268 RETURN_TYPE_ERROR(Z, double_obj, Double); | 2270 RETURN_TYPE_ERROR(Z, double_obj, Double); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2319 *len = str_obj.Length(); | 2321 *len = str_obj.Length(); |
2320 return Api::Success(); | 2322 return Api::Success(); |
2321 } | 2323 } |
2322 | 2324 |
2323 | 2325 |
2324 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) { | 2326 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) { |
2325 DARTSCOPE(Thread::Current()); | 2327 DARTSCOPE(Thread::Current()); |
2326 if (str == NULL) { | 2328 if (str == NULL) { |
2327 RETURN_NULL_ERROR(str); | 2329 RETURN_NULL_ERROR(str); |
2328 } | 2330 } |
2329 CHECK_CALLBACK_STATE(I); | 2331 CHECK_CALLBACK_STATE(T); |
2330 return Api::NewHandle(I, String::New(str)); | 2332 return Api::NewHandle(I, String::New(str)); |
2331 } | 2333 } |
2332 | 2334 |
2333 | 2335 |
2334 DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array, | 2336 DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array, |
2335 intptr_t length) { | 2337 intptr_t length) { |
2336 DARTSCOPE(Thread::Current()); | 2338 DARTSCOPE(Thread::Current()); |
2337 if (utf8_array == NULL && length != 0) { | 2339 if (utf8_array == NULL && length != 0) { |
2338 RETURN_NULL_ERROR(utf8_array); | 2340 RETURN_NULL_ERROR(utf8_array); |
2339 } | 2341 } |
2340 CHECK_LENGTH(length, String::kMaxElements); | 2342 CHECK_LENGTH(length, String::kMaxElements); |
2341 if (!Utf8::IsValid(utf8_array, length)) { | 2343 if (!Utf8::IsValid(utf8_array, length)) { |
2342 return Api::NewError("%s expects argument 'str' to be valid UTF-8.", | 2344 return Api::NewError("%s expects argument 'str' to be valid UTF-8.", |
2343 CURRENT_FUNC); | 2345 CURRENT_FUNC); |
2344 } | 2346 } |
2345 CHECK_CALLBACK_STATE(I); | 2347 CHECK_CALLBACK_STATE(T); |
2346 return Api::NewHandle(I, String::FromUTF8(utf8_array, length)); | 2348 return Api::NewHandle(I, String::FromUTF8(utf8_array, length)); |
2347 } | 2349 } |
2348 | 2350 |
2349 | 2351 |
2350 DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array, | 2352 DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array, |
2351 intptr_t length) { | 2353 intptr_t length) { |
2352 DARTSCOPE(Thread::Current()); | 2354 DARTSCOPE(Thread::Current()); |
2353 if (utf16_array == NULL && length != 0) { | 2355 if (utf16_array == NULL && length != 0) { |
2354 RETURN_NULL_ERROR(utf16_array); | 2356 RETURN_NULL_ERROR(utf16_array); |
2355 } | 2357 } |
2356 CHECK_LENGTH(length, String::kMaxElements); | 2358 CHECK_LENGTH(length, String::kMaxElements); |
2357 CHECK_CALLBACK_STATE(I); | 2359 CHECK_CALLBACK_STATE(T); |
2358 return Api::NewHandle(I, String::FromUTF16(utf16_array, length)); | 2360 return Api::NewHandle(I, String::FromUTF16(utf16_array, length)); |
2359 } | 2361 } |
2360 | 2362 |
2361 | 2363 |
2362 DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const int32_t* utf32_array, | 2364 DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const int32_t* utf32_array, |
2363 intptr_t length) { | 2365 intptr_t length) { |
2364 DARTSCOPE(Thread::Current()); | 2366 DARTSCOPE(Thread::Current()); |
2365 if (utf32_array == NULL && length != 0) { | 2367 if (utf32_array == NULL && length != 0) { |
2366 RETURN_NULL_ERROR(utf32_array); | 2368 RETURN_NULL_ERROR(utf32_array); |
2367 } | 2369 } |
2368 CHECK_LENGTH(length, String::kMaxElements); | 2370 CHECK_LENGTH(length, String::kMaxElements); |
2369 CHECK_CALLBACK_STATE(I); | 2371 CHECK_CALLBACK_STATE(T); |
2370 return Api::NewHandle(I, String::FromUTF32(utf32_array, length)); | 2372 return Api::NewHandle(I, String::FromUTF32(utf32_array, length)); |
2371 } | 2373 } |
2372 | 2374 |
2373 | 2375 |
2374 DART_EXPORT Dart_Handle Dart_NewExternalLatin1String( | 2376 DART_EXPORT Dart_Handle Dart_NewExternalLatin1String( |
2375 const uint8_t* latin1_array, | 2377 const uint8_t* latin1_array, |
2376 intptr_t length, | 2378 intptr_t length, |
2377 void* peer, | 2379 void* peer, |
2378 Dart_PeerFinalizer cback) { | 2380 Dart_PeerFinalizer cback) { |
2379 DARTSCOPE(Thread::Current()); | 2381 DARTSCOPE(Thread::Current()); |
2380 if (latin1_array == NULL && length != 0) { | 2382 if (latin1_array == NULL && length != 0) { |
2381 RETURN_NULL_ERROR(latin1_array); | 2383 RETURN_NULL_ERROR(latin1_array); |
2382 } | 2384 } |
2383 CHECK_LENGTH(length, String::kMaxElements); | 2385 CHECK_LENGTH(length, String::kMaxElements); |
2384 CHECK_CALLBACK_STATE(I); | 2386 CHECK_CALLBACK_STATE(T); |
2385 return Api::NewHandle(I, | 2387 return Api::NewHandle(I, |
2386 String::NewExternal(latin1_array, | 2388 String::NewExternal(latin1_array, |
2387 length, | 2389 length, |
2388 peer, | 2390 peer, |
2389 cback, | 2391 cback, |
2390 SpaceForExternal(I, length))); | 2392 SpaceForExternal(I, length))); |
2391 } | 2393 } |
2392 | 2394 |
2393 | 2395 |
2394 DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array, | 2396 DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array, |
2395 intptr_t length, | 2397 intptr_t length, |
2396 void* peer, | 2398 void* peer, |
2397 Dart_PeerFinalizer cback) { | 2399 Dart_PeerFinalizer cback) { |
2398 DARTSCOPE(Thread::Current()); | 2400 DARTSCOPE(Thread::Current()); |
2399 if (utf16_array == NULL && length != 0) { | 2401 if (utf16_array == NULL && length != 0) { |
2400 RETURN_NULL_ERROR(utf16_array); | 2402 RETURN_NULL_ERROR(utf16_array); |
2401 } | 2403 } |
2402 CHECK_LENGTH(length, String::kMaxElements); | 2404 CHECK_LENGTH(length, String::kMaxElements); |
2403 CHECK_CALLBACK_STATE(I); | 2405 CHECK_CALLBACK_STATE(T); |
2404 intptr_t bytes = length * sizeof(*utf16_array); | 2406 intptr_t bytes = length * sizeof(*utf16_array); |
2405 return Api::NewHandle(I, | 2407 return Api::NewHandle(I, |
2406 String::NewExternal(utf16_array, | 2408 String::NewExternal(utf16_array, |
2407 length, | 2409 length, |
2408 peer, | 2410 peer, |
2409 cback, | 2411 cback, |
2410 SpaceForExternal(I, bytes))); | 2412 SpaceForExternal(I, bytes))); |
2411 } | 2413 } |
2412 | 2414 |
2413 | 2415 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2595 *str_len = str.Length(); | 2597 *str_len = str.Length(); |
2596 return Api::Success(); | 2598 return Api::Success(); |
2597 } | 2599 } |
2598 | 2600 |
2599 | 2601 |
2600 // --- Lists --- | 2602 // --- Lists --- |
2601 | 2603 |
2602 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { | 2604 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { |
2603 DARTSCOPE(Thread::Current()); | 2605 DARTSCOPE(Thread::Current()); |
2604 CHECK_LENGTH(length, Array::kMaxElements); | 2606 CHECK_LENGTH(length, Array::kMaxElements); |
2605 CHECK_CALLBACK_STATE(I); | 2607 CHECK_CALLBACK_STATE(T); |
2606 return Api::NewHandle(I, Array::New(length)); | 2608 return Api::NewHandle(I, Array::New(length)); |
2607 } | 2609 } |
2608 | 2610 |
2609 | 2611 |
2610 #define GET_LIST_LENGTH(zone, type, obj, len) \ | 2612 #define GET_LIST_LENGTH(zone, type, obj, len) \ |
2611 type& array = type::Handle(zone); \ | 2613 type& array = type::Handle(zone); \ |
2612 array ^= obj.raw(); \ | 2614 array ^= obj.raw(); \ |
2613 *len = array.Length(); \ | 2615 *len = array.Length(); \ |
2614 return Api::Success(); \ | 2616 return Api::Success(); \ |
2615 | 2617 |
(...skipping 10 matching lines...) Expand all Loading... |
2626 } | 2628 } |
2627 if (obj.IsArray()) { | 2629 if (obj.IsArray()) { |
2628 GET_LIST_LENGTH(Z, Array, obj, len); | 2630 GET_LIST_LENGTH(Z, Array, obj, len); |
2629 } | 2631 } |
2630 if (obj.IsGrowableObjectArray()) { | 2632 if (obj.IsGrowableObjectArray()) { |
2631 GET_LIST_LENGTH(Z, GrowableObjectArray, obj, len); | 2633 GET_LIST_LENGTH(Z, GrowableObjectArray, obj, len); |
2632 } | 2634 } |
2633 if (obj.IsExternalTypedData()) { | 2635 if (obj.IsExternalTypedData()) { |
2634 GET_LIST_LENGTH(Z, ExternalTypedData, obj, len); | 2636 GET_LIST_LENGTH(Z, ExternalTypedData, obj, len); |
2635 } | 2637 } |
2636 CHECK_CALLBACK_STATE(I); | 2638 CHECK_CALLBACK_STATE(T); |
2637 | 2639 |
2638 // Now check and handle a dart object that implements the List interface. | 2640 // Now check and handle a dart object that implements the List interface. |
2639 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); | 2641 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); |
2640 if (instance.IsNull()) { | 2642 if (instance.IsNull()) { |
2641 return Api::NewError("Object does not implement the List interface"); | 2643 return Api::NewError("Object does not implement the List interface"); |
2642 } | 2644 } |
2643 const String& name = String::Handle(Z, Field::GetterName(Symbols::Length())); | 2645 const String& name = String::Handle(Z, Field::GetterName(Symbols::Length())); |
2644 const int kNumArgs = 1; | 2646 const int kNumArgs = 1; |
2645 ArgumentsDescriptor args_desc( | 2647 ArgumentsDescriptor args_desc( |
2646 Array::Handle(Z, ArgumentsDescriptor::New(kNumArgs))); | 2648 Array::Handle(Z, ArgumentsDescriptor::New(kNumArgs))); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2695 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { | 2697 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { |
2696 DARTSCOPE(Thread::Current()); | 2698 DARTSCOPE(Thread::Current()); |
2697 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); | 2699 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
2698 if (obj.IsArray()) { | 2700 if (obj.IsArray()) { |
2699 GET_LIST_ELEMENT(I, Array, obj, index); | 2701 GET_LIST_ELEMENT(I, Array, obj, index); |
2700 } else if (obj.IsGrowableObjectArray()) { | 2702 } else if (obj.IsGrowableObjectArray()) { |
2701 GET_LIST_ELEMENT(I, GrowableObjectArray, obj, index); | 2703 GET_LIST_ELEMENT(I, GrowableObjectArray, obj, index); |
2702 } else if (obj.IsError()) { | 2704 } else if (obj.IsError()) { |
2703 return list; | 2705 return list; |
2704 } else { | 2706 } else { |
2705 CHECK_CALLBACK_STATE(I); | 2707 CHECK_CALLBACK_STATE(T); |
2706 // Check and handle a dart object that implements the List interface. | 2708 // Check and handle a dart object that implements the List interface. |
2707 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); | 2709 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); |
2708 if (!instance.IsNull()) { | 2710 if (!instance.IsNull()) { |
2709 return Api::NewHandle(I, Send1Arg( | 2711 return Api::NewHandle(I, Send1Arg( |
2710 instance, | 2712 instance, |
2711 Symbols::IndexToken(), | 2713 Symbols::IndexToken(), |
2712 Instance::Handle(Z, Integer::New(index)))); | 2714 Instance::Handle(Z, Integer::New(index)))); |
2713 } | 2715 } |
2714 return Api::NewError("Object does not implement the 'List' interface"); | 2716 return Api::NewError("Object does not implement the 'List' interface"); |
2715 } | 2717 } |
(...skipping 20 matching lines...) Expand all Loading... |
2736 RETURN_NULL_ERROR(result); | 2738 RETURN_NULL_ERROR(result); |
2737 } | 2739 } |
2738 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); | 2740 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
2739 if (obj.IsArray()) { | 2741 if (obj.IsArray()) { |
2740 GET_LIST_RANGE(I, Array, obj, offset, length); | 2742 GET_LIST_RANGE(I, Array, obj, offset, length); |
2741 } else if (obj.IsGrowableObjectArray()) { | 2743 } else if (obj.IsGrowableObjectArray()) { |
2742 GET_LIST_RANGE(I, GrowableObjectArray, obj, offset, length); | 2744 GET_LIST_RANGE(I, GrowableObjectArray, obj, offset, length); |
2743 } else if (obj.IsError()) { | 2745 } else if (obj.IsError()) { |
2744 return list; | 2746 return list; |
2745 } else { | 2747 } else { |
2746 CHECK_CALLBACK_STATE(I); | 2748 CHECK_CALLBACK_STATE(T); |
2747 // Check and handle a dart object that implements the List interface. | 2749 // Check and handle a dart object that implements the List interface. |
2748 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); | 2750 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); |
2749 if (!instance.IsNull()) { | 2751 if (!instance.IsNull()) { |
2750 const intptr_t kNumArgs = 2; | 2752 const intptr_t kNumArgs = 2; |
2751 ArgumentsDescriptor args_desc( | 2753 ArgumentsDescriptor args_desc( |
2752 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | 2754 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
2753 const Function& function = Function::Handle(Z, | 2755 const Function& function = Function::Handle(Z, |
2754 Resolver::ResolveDynamic(instance, | 2756 Resolver::ResolveDynamic(instance, |
2755 Symbols::AssignIndexToken(), | 2757 Symbols::AssignIndexToken(), |
2756 args_desc)); | 2758 args_desc)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2795 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); | 2797 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
2796 // If the list is immutable we call into Dart for the indexed setter to | 2798 // If the list is immutable we call into Dart for the indexed setter to |
2797 // get the unsupported operation exception as the result. | 2799 // get the unsupported operation exception as the result. |
2798 if (obj.IsArray() && !Array::Cast(obj).IsImmutable()) { | 2800 if (obj.IsArray() && !Array::Cast(obj).IsImmutable()) { |
2799 SET_LIST_ELEMENT(Array, obj, index, value); | 2801 SET_LIST_ELEMENT(Array, obj, index, value); |
2800 } else if (obj.IsGrowableObjectArray()) { | 2802 } else if (obj.IsGrowableObjectArray()) { |
2801 SET_LIST_ELEMENT(GrowableObjectArray, obj, index, value); | 2803 SET_LIST_ELEMENT(GrowableObjectArray, obj, index, value); |
2802 } else if (obj.IsError()) { | 2804 } else if (obj.IsError()) { |
2803 return list; | 2805 return list; |
2804 } else { | 2806 } else { |
2805 CHECK_CALLBACK_STATE(I); | 2807 CHECK_CALLBACK_STATE(T); |
2806 | 2808 |
2807 // Check and handle a dart object that implements the List interface. | 2809 // Check and handle a dart object that implements the List interface. |
2808 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); | 2810 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); |
2809 if (!instance.IsNull()) { | 2811 if (!instance.IsNull()) { |
2810 const intptr_t kNumArgs = 3; | 2812 const intptr_t kNumArgs = 3; |
2811 ArgumentsDescriptor args_desc( | 2813 ArgumentsDescriptor args_desc( |
2812 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | 2814 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
2813 const Function& function = Function::Handle(Z, | 2815 const Function& function = Function::Handle(Z, |
2814 Resolver::ResolveDynamic(instance, | 2816 Resolver::ResolveDynamic(instance, |
2815 Symbols::AssignIndexToken(), | 2817 Symbols::AssignIndexToken(), |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2990 if (obj.IsArray()) { | 2992 if (obj.IsArray()) { |
2991 GET_LIST_ELEMENT_AS_BYTES(Array, obj, native_array, offset, length); | 2993 GET_LIST_ELEMENT_AS_BYTES(Array, obj, native_array, offset, length); |
2992 } | 2994 } |
2993 if (obj.IsGrowableObjectArray()) { | 2995 if (obj.IsGrowableObjectArray()) { |
2994 GET_LIST_ELEMENT_AS_BYTES( | 2996 GET_LIST_ELEMENT_AS_BYTES( |
2995 GrowableObjectArray, obj, native_array, offset, length); | 2997 GrowableObjectArray, obj, native_array, offset, length); |
2996 } | 2998 } |
2997 if (obj.IsError()) { | 2999 if (obj.IsError()) { |
2998 return list; | 3000 return list; |
2999 } | 3001 } |
3000 CHECK_CALLBACK_STATE(I); | 3002 CHECK_CALLBACK_STATE(T); |
3001 | 3003 |
3002 // Check and handle a dart object that implements the List interface. | 3004 // Check and handle a dart object that implements the List interface. |
3003 const Instance& instance = | 3005 const Instance& instance = |
3004 Instance::Handle(Z, GetListInstance(Z, obj)); | 3006 Instance::Handle(Z, GetListInstance(Z, obj)); |
3005 if (!instance.IsNull()) { | 3007 if (!instance.IsNull()) { |
3006 const int kNumArgs = 2; | 3008 const int kNumArgs = 2; |
3007 ArgumentsDescriptor args_desc( | 3009 ArgumentsDescriptor args_desc( |
3008 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | 3010 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
3009 const Function& function = Function::Handle(Z, | 3011 const Function& function = Function::Handle(Z, |
3010 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), args_desc)); | 3012 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), args_desc)); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3076 // get the unsupported operation exception as the result. | 3078 // get the unsupported operation exception as the result. |
3077 SET_LIST_ELEMENT_AS_BYTES(Array, obj, native_array, offset, length); | 3079 SET_LIST_ELEMENT_AS_BYTES(Array, obj, native_array, offset, length); |
3078 } | 3080 } |
3079 if (obj.IsGrowableObjectArray()) { | 3081 if (obj.IsGrowableObjectArray()) { |
3080 SET_LIST_ELEMENT_AS_BYTES( | 3082 SET_LIST_ELEMENT_AS_BYTES( |
3081 GrowableObjectArray, obj, native_array, offset, length); | 3083 GrowableObjectArray, obj, native_array, offset, length); |
3082 } | 3084 } |
3083 if (obj.IsError()) { | 3085 if (obj.IsError()) { |
3084 return list; | 3086 return list; |
3085 } | 3087 } |
3086 CHECK_CALLBACK_STATE(I); | 3088 CHECK_CALLBACK_STATE(T); |
3087 | 3089 |
3088 // Check and handle a dart object that implements the List interface. | 3090 // Check and handle a dart object that implements the List interface. |
3089 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); | 3091 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); |
3090 if (!instance.IsNull()) { | 3092 if (!instance.IsNull()) { |
3091 const int kNumArgs = 3; | 3093 const int kNumArgs = 3; |
3092 ArgumentsDescriptor args_desc( | 3094 ArgumentsDescriptor args_desc( |
3093 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | 3095 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
3094 const Function& function = Function::Handle(Z, | 3096 const Function& function = Function::Handle(Z, |
3095 Resolver::ResolveDynamic(instance, | 3097 Resolver::ResolveDynamic(instance, |
3096 Symbols::AssignIndexToken(), | 3098 Symbols::AssignIndexToken(), |
(...skipping 18 matching lines...) Expand all Loading... |
3115 } | 3117 } |
3116 } | 3118 } |
3117 return Api::NewError("Object does not implement the 'List' interface"); | 3119 return Api::NewError("Object does not implement the 'List' interface"); |
3118 } | 3120 } |
3119 | 3121 |
3120 | 3122 |
3121 // --- Maps --- | 3123 // --- Maps --- |
3122 | 3124 |
3123 DART_EXPORT Dart_Handle Dart_MapGetAt(Dart_Handle map, Dart_Handle key) { | 3125 DART_EXPORT Dart_Handle Dart_MapGetAt(Dart_Handle map, Dart_Handle key) { |
3124 DARTSCOPE(Thread::Current()); | 3126 DARTSCOPE(Thread::Current()); |
3125 CHECK_CALLBACK_STATE(I); | 3127 CHECK_CALLBACK_STATE(T); |
3126 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); | 3128 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); |
3127 const Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); | 3129 const Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); |
3128 if (!instance.IsNull()) { | 3130 if (!instance.IsNull()) { |
3129 const Object& key_obj = Object::Handle(Api::UnwrapHandle(key)); | 3131 const Object& key_obj = Object::Handle(Api::UnwrapHandle(key)); |
3130 if (!(key_obj.IsInstance() || key_obj.IsNull())) { | 3132 if (!(key_obj.IsInstance() || key_obj.IsNull())) { |
3131 return Api::NewError("Key is not an instance"); | 3133 return Api::NewError("Key is not an instance"); |
3132 } | 3134 } |
3133 return Api::NewHandle(I, | 3135 return Api::NewHandle(I, |
3134 Send1Arg(instance, Symbols::IndexToken(), Instance::Cast(key_obj))); | 3136 Send1Arg(instance, Symbols::IndexToken(), Instance::Cast(key_obj))); |
3135 } | 3137 } |
3136 return Api::NewError("Object does not implement the 'Map' interface"); | 3138 return Api::NewError("Object does not implement the 'Map' interface"); |
3137 } | 3139 } |
3138 | 3140 |
3139 | 3141 |
3140 DART_EXPORT Dart_Handle Dart_MapContainsKey(Dart_Handle map, Dart_Handle key) { | 3142 DART_EXPORT Dart_Handle Dart_MapContainsKey(Dart_Handle map, Dart_Handle key) { |
3141 DARTSCOPE(Thread::Current()); | 3143 DARTSCOPE(Thread::Current()); |
3142 CHECK_CALLBACK_STATE(I); | 3144 CHECK_CALLBACK_STATE(T); |
3143 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); | 3145 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); |
3144 const Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); | 3146 const Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); |
3145 if (!instance.IsNull()) { | 3147 if (!instance.IsNull()) { |
3146 const Object& key_obj = Object::Handle(Z, Api::UnwrapHandle(key)); | 3148 const Object& key_obj = Object::Handle(Z, Api::UnwrapHandle(key)); |
3147 if (!(key_obj.IsInstance() || key_obj.IsNull())) { | 3149 if (!(key_obj.IsInstance() || key_obj.IsNull())) { |
3148 return Api::NewError("Key is not an instance"); | 3150 return Api::NewError("Key is not an instance"); |
3149 } | 3151 } |
3150 return Api::NewHandle(I, Send1Arg( | 3152 return Api::NewHandle(I, Send1Arg( |
3151 instance, | 3153 instance, |
3152 String::Handle(Z, String::New("containsKey")), | 3154 String::Handle(Z, String::New("containsKey")), |
3153 Instance::Cast(key_obj))); | 3155 Instance::Cast(key_obj))); |
3154 } | 3156 } |
3155 return Api::NewError("Object does not implement the 'Map' interface"); | 3157 return Api::NewError("Object does not implement the 'Map' interface"); |
3156 } | 3158 } |
3157 | 3159 |
3158 | 3160 |
3159 DART_EXPORT Dart_Handle Dart_MapKeys(Dart_Handle map) { | 3161 DART_EXPORT Dart_Handle Dart_MapKeys(Dart_Handle map) { |
3160 DARTSCOPE(Thread::Current()); | 3162 DARTSCOPE(Thread::Current()); |
3161 CHECK_CALLBACK_STATE(I); | 3163 CHECK_CALLBACK_STATE(T); |
3162 Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); | 3164 Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); |
3163 Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); | 3165 Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); |
3164 if (!instance.IsNull()) { | 3166 if (!instance.IsNull()) { |
3165 const Object& iterator = Object::Handle(Send0Arg( | 3167 const Object& iterator = Object::Handle(Send0Arg( |
3166 instance, String::Handle(Z, String::New("get:keys")))); | 3168 instance, String::Handle(Z, String::New("get:keys")))); |
3167 if (!iterator.IsInstance()) { | 3169 if (!iterator.IsInstance()) { |
3168 return Api::NewHandle(I, iterator.raw()); | 3170 return Api::NewHandle(I, iterator.raw()); |
3169 } | 3171 } |
3170 return Api::NewHandle(I, Send0Arg( | 3172 return Api::NewHandle(I, Send0Arg( |
3171 Instance::Cast(iterator), | 3173 Instance::Cast(iterator), |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3383 // Invoke the constructor and return the new object. | 3385 // Invoke the constructor and return the new object. |
3384 result = DartEntry::InvokeFunction(factory, args); | 3386 result = DartEntry::InvokeFunction(factory, args); |
3385 ASSERT(result.IsNull() || result.IsInstance() || result.IsError()); | 3387 ASSERT(result.IsNull() || result.IsInstance() || result.IsError()); |
3386 return Api::NewHandle(isolate, result.raw()); | 3388 return Api::NewHandle(isolate, result.raw()); |
3387 } | 3389 } |
3388 | 3390 |
3389 | 3391 |
3390 DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, | 3392 DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, |
3391 intptr_t length) { | 3393 intptr_t length) { |
3392 DARTSCOPE(Thread::Current()); | 3394 DARTSCOPE(Thread::Current()); |
3393 CHECK_CALLBACK_STATE(I); | 3395 CHECK_CALLBACK_STATE(T); |
3394 switch (type) { | 3396 switch (type) { |
3395 case Dart_TypedData_kByteData : | 3397 case Dart_TypedData_kByteData : |
3396 return NewByteData(T, length); | 3398 return NewByteData(T, length); |
3397 case Dart_TypedData_kInt8 : | 3399 case Dart_TypedData_kInt8 : |
3398 return NewTypedData(I, kTypedDataInt8ArrayCid, length); | 3400 return NewTypedData(I, kTypedDataInt8ArrayCid, length); |
3399 case Dart_TypedData_kUint8 : | 3401 case Dart_TypedData_kUint8 : |
3400 return NewTypedData(I, kTypedDataUint8ArrayCid, length); | 3402 return NewTypedData(I, kTypedDataUint8ArrayCid, length); |
3401 case Dart_TypedData_kUint8Clamped : | 3403 case Dart_TypedData_kUint8Clamped : |
3402 return NewTypedData(I, kTypedDataUint8ClampedArrayCid, length); | 3404 return NewTypedData(I, kTypedDataUint8ClampedArrayCid, length); |
3403 case Dart_TypedData_kInt16 : | 3405 case Dart_TypedData_kInt16 : |
(...skipping 24 matching lines...) Expand all Loading... |
3428 | 3430 |
3429 | 3431 |
3430 DART_EXPORT Dart_Handle Dart_NewExternalTypedData( | 3432 DART_EXPORT Dart_Handle Dart_NewExternalTypedData( |
3431 Dart_TypedData_Type type, | 3433 Dart_TypedData_Type type, |
3432 void* data, | 3434 void* data, |
3433 intptr_t length) { | 3435 intptr_t length) { |
3434 DARTSCOPE(Thread::Current()); | 3436 DARTSCOPE(Thread::Current()); |
3435 if (data == NULL && length != 0) { | 3437 if (data == NULL && length != 0) { |
3436 RETURN_NULL_ERROR(data); | 3438 RETURN_NULL_ERROR(data); |
3437 } | 3439 } |
3438 CHECK_CALLBACK_STATE(I); | 3440 CHECK_CALLBACK_STATE(T); |
3439 switch (type) { | 3441 switch (type) { |
3440 case Dart_TypedData_kByteData: | 3442 case Dart_TypedData_kByteData: |
3441 return NewExternalByteData(T, data, length); | 3443 return NewExternalByteData(T, data, length); |
3442 case Dart_TypedData_kInt8: | 3444 case Dart_TypedData_kInt8: |
3443 return NewExternalTypedData(T, | 3445 return NewExternalTypedData(T, |
3444 kExternalTypedDataInt8ArrayCid, data, length); | 3446 kExternalTypedDataInt8ArrayCid, data, length); |
3445 case Dart_TypedData_kUint8: | 3447 case Dart_TypedData_kUint8: |
3446 return NewExternalTypedData(T, | 3448 return NewExternalTypedData(T, |
3447 kExternalTypedDataUint8ArrayCid, data, length); | 3449 kExternalTypedDataUint8ArrayCid, data, length); |
3448 case Dart_TypedData_kUint8Clamped: | 3450 case Dart_TypedData_kUint8Clamped: |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3602 size_in_bytes = length * ExternalTypedData::ElementSizeInBytes(class_id); | 3604 size_in_bytes = length * ExternalTypedData::ElementSizeInBytes(class_id); |
3603 data_tmp = obj.DataAddr(0); | 3605 data_tmp = obj.DataAddr(0); |
3604 external = true; | 3606 external = true; |
3605 } else if (RawObject::IsTypedDataClassId(class_id)) { | 3607 } else if (RawObject::IsTypedDataClassId(class_id)) { |
3606 // Regular typed data object, set up some GC and API callback guards. | 3608 // Regular typed data object, set up some GC and API callback guards. |
3607 const TypedData& obj = Api::UnwrapTypedDataHandle(Z, object); | 3609 const TypedData& obj = Api::UnwrapTypedDataHandle(Z, object); |
3608 ASSERT(!obj.IsNull()); | 3610 ASSERT(!obj.IsNull()); |
3609 length = obj.Length(); | 3611 length = obj.Length(); |
3610 size_in_bytes = length * TypedData::ElementSizeInBytes(class_id); | 3612 size_in_bytes = length * TypedData::ElementSizeInBytes(class_id); |
3611 T->IncrementNoSafepointScopeDepth(); | 3613 T->IncrementNoSafepointScopeDepth(); |
3612 START_NO_CALLBACK_SCOPE(I); | 3614 START_NO_CALLBACK_SCOPE(T); |
3613 data_tmp = obj.DataAddr(0); | 3615 data_tmp = obj.DataAddr(0); |
3614 } else { | 3616 } else { |
3615 ASSERT(RawObject::IsTypedDataViewClassId(class_id)); | 3617 ASSERT(RawObject::IsTypedDataViewClassId(class_id)); |
3616 const Instance& view_obj = Api::UnwrapInstanceHandle(Z, object); | 3618 const Instance& view_obj = Api::UnwrapInstanceHandle(Z, object); |
3617 ASSERT(!view_obj.IsNull()); | 3619 ASSERT(!view_obj.IsNull()); |
3618 Smi& val = Smi::Handle(); | 3620 Smi& val = Smi::Handle(); |
3619 val ^= TypedDataView::Length(view_obj); | 3621 val ^= TypedDataView::Length(view_obj); |
3620 length = val.Value(); | 3622 length = val.Value(); |
3621 size_in_bytes = length * TypedDataView::ElementSizeInBytes(class_id); | 3623 size_in_bytes = length * TypedDataView::ElementSizeInBytes(class_id); |
3622 val ^= TypedDataView::OffsetInBytes(view_obj); | 3624 val ^= TypedDataView::OffsetInBytes(view_obj); |
3623 intptr_t offset_in_bytes = val.Value(); | 3625 intptr_t offset_in_bytes = val.Value(); |
3624 const Instance& obj = Instance::Handle(TypedDataView::Data(view_obj)); | 3626 const Instance& obj = Instance::Handle(TypedDataView::Data(view_obj)); |
3625 T->IncrementNoSafepointScopeDepth(); | 3627 T->IncrementNoSafepointScopeDepth(); |
3626 START_NO_CALLBACK_SCOPE(I); | 3628 START_NO_CALLBACK_SCOPE(T); |
3627 if (TypedData::IsTypedData(obj)) { | 3629 if (TypedData::IsTypedData(obj)) { |
3628 const TypedData& data_obj = TypedData::Cast(obj); | 3630 const TypedData& data_obj = TypedData::Cast(obj); |
3629 data_tmp = data_obj.DataAddr(offset_in_bytes); | 3631 data_tmp = data_obj.DataAddr(offset_in_bytes); |
3630 } else { | 3632 } else { |
3631 ASSERT(ExternalTypedData::IsExternalTypedData(obj)); | 3633 ASSERT(ExternalTypedData::IsExternalTypedData(obj)); |
3632 const ExternalTypedData& data_obj = ExternalTypedData::Cast(obj); | 3634 const ExternalTypedData& data_obj = ExternalTypedData::Cast(obj); |
3633 data_tmp = data_obj.DataAddr(offset_in_bytes); | 3635 data_tmp = data_obj.DataAddr(offset_in_bytes); |
3634 external = true; | 3636 external = true; |
3635 } | 3637 } |
3636 } | 3638 } |
(...skipping 25 matching lines...) Expand all Loading... |
3662 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) { | 3664 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) { |
3663 DARTSCOPE(Thread::Current()); | 3665 DARTSCOPE(Thread::Current()); |
3664 intptr_t class_id = Api::ClassId(object); | 3666 intptr_t class_id = Api::ClassId(object); |
3665 if (!RawObject::IsExternalTypedDataClassId(class_id) && | 3667 if (!RawObject::IsExternalTypedDataClassId(class_id) && |
3666 !RawObject::IsTypedDataViewClassId(class_id) && | 3668 !RawObject::IsTypedDataViewClassId(class_id) && |
3667 !RawObject::IsTypedDataClassId(class_id)) { | 3669 !RawObject::IsTypedDataClassId(class_id)) { |
3668 RETURN_TYPE_ERROR(Z, object, 'TypedData'); | 3670 RETURN_TYPE_ERROR(Z, object, 'TypedData'); |
3669 } | 3671 } |
3670 if (!RawObject::IsExternalTypedDataClassId(class_id)) { | 3672 if (!RawObject::IsExternalTypedDataClassId(class_id)) { |
3671 T->DecrementNoSafepointScopeDepth(); | 3673 T->DecrementNoSafepointScopeDepth(); |
3672 END_NO_CALLBACK_SCOPE(I); | 3674 END_NO_CALLBACK_SCOPE(T); |
3673 } | 3675 } |
3674 if (FLAG_verify_acquired_data) { | 3676 if (FLAG_verify_acquired_data) { |
3675 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); | 3677 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); |
3676 WeakTable* table = I->api_state()->acquired_table(); | 3678 WeakTable* table = I->api_state()->acquired_table(); |
3677 intptr_t current = table->GetValue(obj.raw()); | 3679 intptr_t current = table->GetValue(obj.raw()); |
3678 if (current == 0) { | 3680 if (current == 0) { |
3679 return Api::NewError("Data was not acquired for this object."); | 3681 return Api::NewError("Data was not acquired for this object."); |
3680 } | 3682 } |
3681 AcquiredData* ad = reinterpret_cast<AcquiredData*>(current); | 3683 AcquiredData* ad = reinterpret_cast<AcquiredData*>(current); |
3682 table->SetValue(obj.raw(), 0); // Delete entry from table. | 3684 table->SetValue(obj.raw(), 0); // Delete entry from table. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3749 } | 3751 } |
3750 return constructor.raw(); | 3752 return constructor.raw(); |
3751 } | 3753 } |
3752 | 3754 |
3753 | 3755 |
3754 DART_EXPORT Dart_Handle Dart_New(Dart_Handle type, | 3756 DART_EXPORT Dart_Handle Dart_New(Dart_Handle type, |
3755 Dart_Handle constructor_name, | 3757 Dart_Handle constructor_name, |
3756 int number_of_arguments, | 3758 int number_of_arguments, |
3757 Dart_Handle* arguments) { | 3759 Dart_Handle* arguments) { |
3758 DARTSCOPE(Thread::Current()); | 3760 DARTSCOPE(Thread::Current()); |
3759 CHECK_CALLBACK_STATE(I); | 3761 CHECK_CALLBACK_STATE(T); |
3760 Object& result = Object::Handle(Z); | 3762 Object& result = Object::Handle(Z); |
3761 | 3763 |
3762 if (number_of_arguments < 0) { | 3764 if (number_of_arguments < 0) { |
3763 return Api::NewError( | 3765 return Api::NewError( |
3764 "%s expects argument 'number_of_arguments' to be non-negative.", | 3766 "%s expects argument 'number_of_arguments' to be non-negative.", |
3765 CURRENT_FUNC); | 3767 CURRENT_FUNC); |
3766 } | 3768 } |
3767 | 3769 |
3768 // Get the class to instantiate. | 3770 // Get the class to instantiate. |
3769 Object& unchecked_type = Object::Handle(Api::UnwrapHandle(type)); | 3771 Object& unchecked_type = Object::Handle(Api::UnwrapHandle(type)); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3913 } | 3915 } |
3914 } | 3916 } |
3915 | 3917 |
3916 // Allocate an object for the given class. | 3918 // Allocate an object for the given class. |
3917 return Instance::New(cls); | 3919 return Instance::New(cls); |
3918 } | 3920 } |
3919 | 3921 |
3920 | 3922 |
3921 DART_EXPORT Dart_Handle Dart_Allocate(Dart_Handle type) { | 3923 DART_EXPORT Dart_Handle Dart_Allocate(Dart_Handle type) { |
3922 DARTSCOPE(Thread::Current()); | 3924 DARTSCOPE(Thread::Current()); |
3923 CHECK_CALLBACK_STATE(I); | 3925 CHECK_CALLBACK_STATE(T); |
3924 | 3926 |
3925 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); | 3927 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); |
3926 // Get the class to instantiate. | 3928 // Get the class to instantiate. |
3927 if (type_obj.IsNull()) { | 3929 if (type_obj.IsNull()) { |
3928 RETURN_TYPE_ERROR(Z, type, Type); | 3930 RETURN_TYPE_ERROR(Z, type, Type); |
3929 } | 3931 } |
3930 const Class& cls = Class::Handle(Z, type_obj.type_class()); | 3932 const Class& cls = Class::Handle(Z, type_obj.type_class()); |
3931 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); | 3933 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); |
3932 if (!error.IsNull()) { | 3934 if (!error.IsNull()) { |
3933 // An error occurred, return error object. | 3935 // An error occurred, return error object. |
3934 return Api::NewHandle(I, error.raw()); | 3936 return Api::NewHandle(I, error.raw()); |
3935 } | 3937 } |
3936 return Api::NewHandle(I, AllocateObject(T, cls)); | 3938 return Api::NewHandle(I, AllocateObject(T, cls)); |
3937 } | 3939 } |
3938 | 3940 |
3939 | 3941 |
3940 DART_EXPORT Dart_Handle Dart_AllocateWithNativeFields( | 3942 DART_EXPORT Dart_Handle Dart_AllocateWithNativeFields( |
3941 Dart_Handle type, | 3943 Dart_Handle type, |
3942 intptr_t num_native_fields, | 3944 intptr_t num_native_fields, |
3943 const intptr_t* native_fields) { | 3945 const intptr_t* native_fields) { |
3944 DARTSCOPE(Thread::Current()); | 3946 DARTSCOPE(Thread::Current()); |
3945 CHECK_CALLBACK_STATE(I); | 3947 CHECK_CALLBACK_STATE(T); |
3946 | 3948 |
3947 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); | 3949 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); |
3948 // Get the class to instantiate. | 3950 // Get the class to instantiate. |
3949 if (type_obj.IsNull()) { | 3951 if (type_obj.IsNull()) { |
3950 RETURN_TYPE_ERROR(Z, type, Type); | 3952 RETURN_TYPE_ERROR(Z, type, Type); |
3951 } | 3953 } |
3952 if (native_fields == NULL) { | 3954 if (native_fields == NULL) { |
3953 RETURN_NULL_ERROR(native_fields); | 3955 RETURN_NULL_ERROR(native_fields); |
3954 } | 3956 } |
3955 const Class& cls = Class::Handle(Z, type_obj.type_class()); | 3957 const Class& cls = Class::Handle(Z, type_obj.type_class()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3995 } | 3997 } |
3996 return Api::Success(); | 3998 return Api::Success(); |
3997 } | 3999 } |
3998 | 4000 |
3999 | 4001 |
4000 DART_EXPORT Dart_Handle Dart_InvokeConstructor(Dart_Handle object, | 4002 DART_EXPORT Dart_Handle Dart_InvokeConstructor(Dart_Handle object, |
4001 Dart_Handle name, | 4003 Dart_Handle name, |
4002 int number_of_arguments, | 4004 int number_of_arguments, |
4003 Dart_Handle* arguments) { | 4005 Dart_Handle* arguments) { |
4004 DARTSCOPE(Thread::Current()); | 4006 DARTSCOPE(Thread::Current()); |
4005 CHECK_CALLBACK_STATE(I); | 4007 CHECK_CALLBACK_STATE(T); |
4006 | 4008 |
4007 if (number_of_arguments < 0) { | 4009 if (number_of_arguments < 0) { |
4008 return Api::NewError( | 4010 return Api::NewError( |
4009 "%s expects argument 'number_of_arguments' to be non-negative.", | 4011 "%s expects argument 'number_of_arguments' to be non-negative.", |
4010 CURRENT_FUNC); | 4012 CURRENT_FUNC); |
4011 } | 4013 } |
4012 const String& constructor_name = Api::UnwrapStringHandle(Z, name); | 4014 const String& constructor_name = Api::UnwrapStringHandle(Z, name); |
4013 if (constructor_name.IsNull()) { | 4015 if (constructor_name.IsNull()) { |
4014 RETURN_TYPE_ERROR(Z, name, String); | 4016 RETURN_TYPE_ERROR(Z, name, String); |
4015 } | 4017 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4072 "%s expects argument 'name' to be a valid constructor.", | 4074 "%s expects argument 'name' to be a valid constructor.", |
4073 CURRENT_FUNC); | 4075 CURRENT_FUNC); |
4074 } | 4076 } |
4075 | 4077 |
4076 | 4078 |
4077 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, | 4079 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, |
4078 Dart_Handle name, | 4080 Dart_Handle name, |
4079 int number_of_arguments, | 4081 int number_of_arguments, |
4080 Dart_Handle* arguments) { | 4082 Dart_Handle* arguments) { |
4081 DARTSCOPE(Thread::Current()); | 4083 DARTSCOPE(Thread::Current()); |
4082 CHECK_CALLBACK_STATE(I); | 4084 CHECK_CALLBACK_STATE(T); |
4083 | 4085 |
4084 const String& function_name = Api::UnwrapStringHandle(Z, name); | 4086 const String& function_name = Api::UnwrapStringHandle(Z, name); |
4085 if (function_name.IsNull()) { | 4087 if (function_name.IsNull()) { |
4086 RETURN_TYPE_ERROR(Z, name, String); | 4088 RETURN_TYPE_ERROR(Z, name, String); |
4087 } | 4089 } |
4088 if (number_of_arguments < 0) { | 4090 if (number_of_arguments < 0) { |
4089 return Api::NewError( | 4091 return Api::NewError( |
4090 "%s expects argument 'number_of_arguments' to be non-negative.", | 4092 "%s expects argument 'number_of_arguments' to be non-negative.", |
4091 CURRENT_FUNC); | 4093 CURRENT_FUNC); |
4092 } | 4094 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4198 "%s expects argument 'target' to be an object, type, or library.", | 4200 "%s expects argument 'target' to be an object, type, or library.", |
4199 CURRENT_FUNC); | 4201 CURRENT_FUNC); |
4200 } | 4202 } |
4201 } | 4203 } |
4202 | 4204 |
4203 | 4205 |
4204 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, | 4206 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, |
4205 int number_of_arguments, | 4207 int number_of_arguments, |
4206 Dart_Handle* arguments) { | 4208 Dart_Handle* arguments) { |
4207 DARTSCOPE(Thread::Current()); | 4209 DARTSCOPE(Thread::Current()); |
4208 CHECK_CALLBACK_STATE(I); | 4210 CHECK_CALLBACK_STATE(T); |
4209 const Instance& closure_obj = Api::UnwrapInstanceHandle(Z, closure); | 4211 const Instance& closure_obj = Api::UnwrapInstanceHandle(Z, closure); |
4210 if (closure_obj.IsNull() || !closure_obj.IsCallable(NULL)) { | 4212 if (closure_obj.IsNull() || !closure_obj.IsCallable(NULL)) { |
4211 RETURN_TYPE_ERROR(Z, closure, Instance); | 4213 RETURN_TYPE_ERROR(Z, closure, Instance); |
4212 } | 4214 } |
4213 if (number_of_arguments < 0) { | 4215 if (number_of_arguments < 0) { |
4214 return Api::NewError( | 4216 return Api::NewError( |
4215 "%s expects argument 'number_of_arguments' to be non-negative.", | 4217 "%s expects argument 'number_of_arguments' to be non-negative.", |
4216 CURRENT_FUNC); | 4218 CURRENT_FUNC); |
4217 } | 4219 } |
4218 | 4220 |
4219 // Set up arguments to include the closure as the first argument. | 4221 // Set up arguments to include the closure as the first argument. |
4220 const Array& args = Array::Handle(Z, Array::New(number_of_arguments + 1)); | 4222 const Array& args = Array::Handle(Z, Array::New(number_of_arguments + 1)); |
4221 Object& obj = Object::Handle(Z); | 4223 Object& obj = Object::Handle(Z); |
4222 args.SetAt(0, closure_obj); | 4224 args.SetAt(0, closure_obj); |
4223 for (int i = 0; i < number_of_arguments; i++) { | 4225 for (int i = 0; i < number_of_arguments; i++) { |
4224 obj = Api::UnwrapHandle(arguments[i]); | 4226 obj = Api::UnwrapHandle(arguments[i]); |
4225 if (!obj.IsNull() && !obj.IsInstance()) { | 4227 if (!obj.IsNull() && !obj.IsInstance()) { |
4226 RETURN_TYPE_ERROR(Z, arguments[i], Instance); | 4228 RETURN_TYPE_ERROR(Z, arguments[i], Instance); |
4227 } | 4229 } |
4228 args.SetAt(i + 1, obj); | 4230 args.SetAt(i + 1, obj); |
4229 } | 4231 } |
4230 // Now try to invoke the closure. | 4232 // Now try to invoke the closure. |
4231 return Api::NewHandle(I, DartEntry::InvokeClosure(args)); | 4233 return Api::NewHandle(I, DartEntry::InvokeClosure(args)); |
4232 } | 4234 } |
4233 | 4235 |
4234 | 4236 |
4235 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { | 4237 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { |
4236 DARTSCOPE(Thread::Current()); | 4238 DARTSCOPE(Thread::Current()); |
4237 CHECK_CALLBACK_STATE(I); | 4239 CHECK_CALLBACK_STATE(T); |
4238 | 4240 |
4239 const String& field_name = Api::UnwrapStringHandle(Z, name); | 4241 const String& field_name = Api::UnwrapStringHandle(Z, name); |
4240 if (field_name.IsNull()) { | 4242 if (field_name.IsNull()) { |
4241 RETURN_TYPE_ERROR(Z, name, String); | 4243 RETURN_TYPE_ERROR(Z, name, String); |
4242 } | 4244 } |
4243 | 4245 |
4244 Field& field = Field::Handle(Z); | 4246 Field& field = Field::Handle(Z); |
4245 Function& getter = Function::Handle(Z); | 4247 Function& getter = Function::Handle(Z); |
4246 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(container)); | 4248 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(container)); |
4247 if (obj.IsNull()) { | 4249 if (obj.IsNull()) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4348 "%s expects argument 'container' to be an object, type, or library.", | 4350 "%s expects argument 'container' to be an object, type, or library.", |
4349 CURRENT_FUNC); | 4351 CURRENT_FUNC); |
4350 } | 4352 } |
4351 } | 4353 } |
4352 | 4354 |
4353 | 4355 |
4354 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, | 4356 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, |
4355 Dart_Handle name, | 4357 Dart_Handle name, |
4356 Dart_Handle value) { | 4358 Dart_Handle value) { |
4357 DARTSCOPE(Thread::Current()); | 4359 DARTSCOPE(Thread::Current()); |
4358 CHECK_CALLBACK_STATE(I); | 4360 CHECK_CALLBACK_STATE(T); |
4359 | 4361 |
4360 const String& field_name = Api::UnwrapStringHandle(Z, name); | 4362 const String& field_name = Api::UnwrapStringHandle(Z, name); |
4361 if (field_name.IsNull()) { | 4363 if (field_name.IsNull()) { |
4362 RETURN_TYPE_ERROR(Z, name, String); | 4364 RETURN_TYPE_ERROR(Z, name, String); |
4363 } | 4365 } |
4364 | 4366 |
4365 // Since null is allowed for value, we don't use UnwrapInstanceHandle. | 4367 // Since null is allowed for value, we don't use UnwrapInstanceHandle. |
4366 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); | 4368 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); |
4367 if (!value_obj.IsNull() && !value_obj.IsInstance()) { | 4369 if (!value_obj.IsNull() && !value_obj.IsInstance()) { |
4368 RETURN_TYPE_ERROR(Z, value, Instance); | 4370 RETURN_TYPE_ERROR(Z, value, Instance); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4503 } | 4505 } |
4504 | 4506 |
4505 | 4507 |
4506 // --- Exceptions ---- | 4508 // --- Exceptions ---- |
4507 | 4509 |
4508 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { | 4510 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { |
4509 Thread* thread = Thread::Current(); | 4511 Thread* thread = Thread::Current(); |
4510 Zone* zone = thread->zone(); | 4512 Zone* zone = thread->zone(); |
4511 Isolate* isolate = thread->isolate(); | 4513 Isolate* isolate = thread->isolate(); |
4512 CHECK_ISOLATE(isolate); | 4514 CHECK_ISOLATE(isolate); |
4513 CHECK_CALLBACK_STATE(isolate); | 4515 CHECK_CALLBACK_STATE(thread); |
4514 { | 4516 { |
4515 const Instance& excp = Api::UnwrapInstanceHandle(zone, exception); | 4517 const Instance& excp = Api::UnwrapInstanceHandle(zone, exception); |
4516 if (excp.IsNull()) { | 4518 if (excp.IsNull()) { |
4517 RETURN_TYPE_ERROR(zone, exception, Instance); | 4519 RETURN_TYPE_ERROR(zone, exception, Instance); |
4518 } | 4520 } |
4519 } | 4521 } |
4520 if (isolate->top_exit_frame_info() == 0) { | 4522 if (isolate->top_exit_frame_info() == 0) { |
4521 // There are no dart frames on the stack so it would be illegal to | 4523 // There are no dart frames on the stack so it would be illegal to |
4522 // throw an exception here. | 4524 // throw an exception here. |
4523 return Api::NewError("No Dart frames on stack, cannot throw exception"); | 4525 return Api::NewError("No Dart frames on stack, cannot throw exception"); |
(...skipping 15 matching lines...) Expand all Loading... |
4539 return Api::NewError("Exception was not thrown, internal error"); | 4541 return Api::NewError("Exception was not thrown, internal error"); |
4540 } | 4542 } |
4541 | 4543 |
4542 | 4544 |
4543 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, | 4545 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, |
4544 Dart_Handle stacktrace) { | 4546 Dart_Handle stacktrace) { |
4545 Thread* thread = Thread::Current(); | 4547 Thread* thread = Thread::Current(); |
4546 Zone* zone = thread->zone(); | 4548 Zone* zone = thread->zone(); |
4547 Isolate* isolate = thread->isolate(); | 4549 Isolate* isolate = thread->isolate(); |
4548 CHECK_ISOLATE(isolate); | 4550 CHECK_ISOLATE(isolate); |
4549 CHECK_CALLBACK_STATE(isolate); | 4551 CHECK_CALLBACK_STATE(thread); |
4550 { | 4552 { |
4551 const Instance& excp = Api::UnwrapInstanceHandle(zone, exception); | 4553 const Instance& excp = Api::UnwrapInstanceHandle(zone, exception); |
4552 if (excp.IsNull()) { | 4554 if (excp.IsNull()) { |
4553 RETURN_TYPE_ERROR(zone, exception, Instance); | 4555 RETURN_TYPE_ERROR(zone, exception, Instance); |
4554 } | 4556 } |
4555 const Instance& stk = Api::UnwrapInstanceHandle(zone, stacktrace); | 4557 const Instance& stk = Api::UnwrapInstanceHandle(zone, stacktrace); |
4556 if (stk.IsNull()) { | 4558 if (stk.IsNull()) { |
4557 RETURN_TYPE_ERROR(zone, stacktrace, Instance); | 4559 RETURN_TYPE_ERROR(zone, stacktrace, Instance); |
4558 } | 4560 } |
4559 } | 4561 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4595 RETURN_TYPE_ERROR(Z, name, String); | 4597 RETURN_TYPE_ERROR(Z, name, String); |
4596 } | 4598 } |
4597 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 4599 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
4598 if (lib.IsNull()) { | 4600 if (lib.IsNull()) { |
4599 RETURN_TYPE_ERROR(Z, library, Library); | 4601 RETURN_TYPE_ERROR(Z, library, Library); |
4600 } | 4602 } |
4601 if (!Utils::IsUint(16, field_count)) { | 4603 if (!Utils::IsUint(16, field_count)) { |
4602 return Api::NewError( | 4604 return Api::NewError( |
4603 "Invalid field_count passed to Dart_CreateNativeWrapperClass"); | 4605 "Invalid field_count passed to Dart_CreateNativeWrapperClass"); |
4604 } | 4606 } |
4605 CHECK_CALLBACK_STATE(I); | 4607 CHECK_CALLBACK_STATE(T); |
4606 | 4608 |
4607 String& cls_symbol = String::Handle(Z, Symbols::New(cls_name)); | 4609 String& cls_symbol = String::Handle(Z, Symbols::New(cls_name)); |
4608 const Class& cls = Class::Handle(Z, | 4610 const Class& cls = Class::Handle(Z, |
4609 Class::NewNativeWrapper(lib, cls_symbol, field_count)); | 4611 Class::NewNativeWrapper(lib, cls_symbol, field_count)); |
4610 if (cls.IsNull()) { | 4612 if (cls.IsNull()) { |
4611 return Api::NewError( | 4613 return Api::NewError( |
4612 "Unable to create native wrapper class : already exists"); | 4614 "Unable to create native wrapper class : already exists"); |
4613 } | 4615 } |
4614 return Api::NewHandle(I, cls.RareType()); | 4616 return Api::NewHandle(I, cls.RareType()); |
4615 } | 4617 } |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5014 | 5016 |
5015 | 5017 |
5016 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, | 5018 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, |
5017 int64_t retval) { | 5019 int64_t retval) { |
5018 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 5020 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
5019 ASSERT(arguments->thread()->isolate() == Isolate::Current()); | 5021 ASSERT(arguments->thread()->isolate() == Isolate::Current()); |
5020 if (Smi::IsValid(retval)) { | 5022 if (Smi::IsValid(retval)) { |
5021 Api::SetSmiReturnValue(arguments, static_cast<intptr_t>(retval)); | 5023 Api::SetSmiReturnValue(arguments, static_cast<intptr_t>(retval)); |
5022 } else { | 5024 } else { |
5023 // Slow path for Mints and Bigints. | 5025 // Slow path for Mints and Bigints. |
5024 ASSERT_CALLBACK_STATE(arguments->thread()->isolate()); | 5026 ASSERT_CALLBACK_STATE(arguments->thread()); |
5025 Api::SetIntegerReturnValue(arguments, retval); | 5027 Api::SetIntegerReturnValue(arguments, retval); |
5026 } | 5028 } |
5027 } | 5029 } |
5028 | 5030 |
5029 | 5031 |
5030 DART_EXPORT void Dart_SetDoubleReturnValue(Dart_NativeArguments args, | 5032 DART_EXPORT void Dart_SetDoubleReturnValue(Dart_NativeArguments args, |
5031 double retval) { | 5033 double retval) { |
5032 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 5034 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
5033 #if defined(DEBUG) | 5035 ASSERT_CALLBACK_STATE(arguments->thread()); |
5034 Isolate* isolate = arguments->thread()->isolate(); | |
5035 ASSERT(isolate == Isolate::Current()); | |
5036 ASSERT_CALLBACK_STATE(isolate); | |
5037 #endif | |
5038 Api::SetDoubleReturnValue(arguments, retval); | 5036 Api::SetDoubleReturnValue(arguments, retval); |
5039 } | 5037 } |
5040 | 5038 |
5041 | 5039 |
5042 // --- Scripts and Libraries --- | 5040 // --- Scripts and Libraries --- |
5043 | 5041 |
5044 DART_EXPORT Dart_Handle Dart_SetLibraryTagHandler( | 5042 DART_EXPORT Dart_Handle Dart_SetLibraryTagHandler( |
5045 Dart_LibraryTagHandler handler) { | 5043 Dart_LibraryTagHandler handler) { |
5046 Isolate* isolate = Isolate::Current(); | 5044 Isolate* isolate = Isolate::Current(); |
5047 CHECK_ISOLATE(isolate); | 5045 CHECK_ISOLATE(isolate); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5096 CURRENT_FUNC, library_url.ToCString()); | 5094 CURRENT_FUNC, library_url.ToCString()); |
5097 } | 5095 } |
5098 if (line_offset < 0) { | 5096 if (line_offset < 0) { |
5099 return Api::NewError("%s: argument 'line_offset' must be positive number", | 5097 return Api::NewError("%s: argument 'line_offset' must be positive number", |
5100 CURRENT_FUNC); | 5098 CURRENT_FUNC); |
5101 } | 5099 } |
5102 if (column_offset < 0) { | 5100 if (column_offset < 0) { |
5103 return Api::NewError("%s: argument 'column_offset' must be positive number", | 5101 return Api::NewError("%s: argument 'column_offset' must be positive number", |
5104 CURRENT_FUNC); | 5102 CURRENT_FUNC); |
5105 } | 5103 } |
5106 CHECK_CALLBACK_STATE(I); | 5104 CHECK_CALLBACK_STATE(T); |
5107 CHECK_COMPILATION_ALLOWED(I); | 5105 CHECK_COMPILATION_ALLOWED(I); |
5108 | 5106 |
5109 NoHeapGrowthControlScope no_growth_control; | 5107 NoHeapGrowthControlScope no_growth_control; |
5110 | 5108 |
5111 library = Library::New(url_str); | 5109 library = Library::New(url_str); |
5112 library.set_debuggable(true); | 5110 library.set_debuggable(true); |
5113 library.Register(); | 5111 library.Register(); |
5114 I->object_store()->set_root_library(library); | 5112 I->object_store()->set_root_library(library); |
5115 | 5113 |
5116 const Script& script = Script::Handle(Z, | 5114 const Script& script = Script::Handle(Z, |
(...skipping 23 matching lines...) Expand all Loading... |
5140 return Api::NewError("%s: 'buffer_len' of %" Pd " is not equal to %" Pd | 5138 return Api::NewError("%s: 'buffer_len' of %" Pd " is not equal to %" Pd |
5141 " which is the expected length in the snapshot.", | 5139 " which is the expected length in the snapshot.", |
5142 CURRENT_FUNC, buffer_len, snapshot->length()); | 5140 CURRENT_FUNC, buffer_len, snapshot->length()); |
5143 } | 5141 } |
5144 Library& library = Library::Handle(Z, I->object_store()->root_library()); | 5142 Library& library = Library::Handle(Z, I->object_store()->root_library()); |
5145 if (!library.IsNull()) { | 5143 if (!library.IsNull()) { |
5146 const String& library_url = String::Handle(Z, library.url()); | 5144 const String& library_url = String::Handle(Z, library.url()); |
5147 return Api::NewError("%s: A script has already been loaded from '%s'.", | 5145 return Api::NewError("%s: A script has already been loaded from '%s'.", |
5148 CURRENT_FUNC, library_url.ToCString()); | 5146 CURRENT_FUNC, library_url.ToCString()); |
5149 } | 5147 } |
5150 CHECK_CALLBACK_STATE(I); | 5148 CHECK_CALLBACK_STATE(T); |
5151 CHECK_COMPILATION_ALLOWED(I); | 5149 CHECK_COMPILATION_ALLOWED(I); |
5152 | 5150 |
5153 ASSERT(snapshot->kind() == Snapshot::kScript); | 5151 ASSERT(snapshot->kind() == Snapshot::kScript); |
5154 ScriptSnapshotReader reader(snapshot->content(), snapshot->length(), T); | 5152 ScriptSnapshotReader reader(snapshot->content(), snapshot->length(), T); |
5155 const Object& tmp = Object::Handle(Z, reader.ReadScriptSnapshot()); | 5153 const Object& tmp = Object::Handle(Z, reader.ReadScriptSnapshot()); |
5156 if (tmp.IsError()) { | 5154 if (tmp.IsError()) { |
5157 return Api::NewHandle(I, tmp.raw()); | 5155 return Api::NewHandle(I, tmp.raw()); |
5158 } | 5156 } |
5159 library ^= tmp.raw(); | 5157 library ^= tmp.raw(); |
5160 library.set_debuggable(true); | 5158 library.set_debuggable(true); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5298 DARTSCOPE(Thread::Current()); | 5296 DARTSCOPE(Thread::Current()); |
5299 | 5297 |
5300 const Library& lib = Api::UnwrapLibraryHandle(Z, library_in); | 5298 const Library& lib = Api::UnwrapLibraryHandle(Z, library_in); |
5301 if (lib.IsNull()) { | 5299 if (lib.IsNull()) { |
5302 RETURN_TYPE_ERROR(Z, library_in, Library); | 5300 RETURN_TYPE_ERROR(Z, library_in, Library); |
5303 } | 5301 } |
5304 const Instance& err = Api::UnwrapInstanceHandle(Z, error_in); | 5302 const Instance& err = Api::UnwrapInstanceHandle(Z, error_in); |
5305 if (err.IsNull()) { | 5303 if (err.IsNull()) { |
5306 RETURN_TYPE_ERROR(Z, error_in, Instance); | 5304 RETURN_TYPE_ERROR(Z, error_in, Instance); |
5307 } | 5305 } |
5308 CHECK_CALLBACK_STATE(I); | 5306 CHECK_CALLBACK_STATE(T); |
5309 | 5307 |
5310 const GrowableObjectArray& pending_deferred_loads = | 5308 const GrowableObjectArray& pending_deferred_loads = |
5311 GrowableObjectArray::Handle(Z, | 5309 GrowableObjectArray::Handle(Z, |
5312 I->object_store()->pending_deferred_loads()); | 5310 I->object_store()->pending_deferred_loads()); |
5313 for (intptr_t i = 0; i < pending_deferred_loads.Length(); i++) { | 5311 for (intptr_t i = 0; i < pending_deferred_loads.Length(); i++) { |
5314 if (pending_deferred_loads.At(i) == lib.raw()) { | 5312 if (pending_deferred_loads.At(i) == lib.raw()) { |
5315 lib.SetLoadError(err); | 5313 lib.SetLoadError(err); |
5316 return Api::Null(); | 5314 return Api::Null(); |
5317 } | 5315 } |
5318 } | 5316 } |
(...skipping 15 matching lines...) Expand all Loading... |
5334 RETURN_TYPE_ERROR(Z, source, String); | 5332 RETURN_TYPE_ERROR(Z, source, String); |
5335 } | 5333 } |
5336 if (line_offset < 0) { | 5334 if (line_offset < 0) { |
5337 return Api::NewError("%s: argument 'line_offset' must be positive number", | 5335 return Api::NewError("%s: argument 'line_offset' must be positive number", |
5338 CURRENT_FUNC); | 5336 CURRENT_FUNC); |
5339 } | 5337 } |
5340 if (column_offset < 0) { | 5338 if (column_offset < 0) { |
5341 return Api::NewError("%s: argument 'column_offset' must be positive number", | 5339 return Api::NewError("%s: argument 'column_offset' must be positive number", |
5342 CURRENT_FUNC); | 5340 CURRENT_FUNC); |
5343 } | 5341 } |
5344 CHECK_CALLBACK_STATE(I); | 5342 CHECK_CALLBACK_STATE(T); |
5345 CHECK_COMPILATION_ALLOWED(I); | 5343 CHECK_COMPILATION_ALLOWED(I); |
5346 | 5344 |
5347 NoHeapGrowthControlScope no_growth_control; | 5345 NoHeapGrowthControlScope no_growth_control; |
5348 | 5346 |
5349 Library& library = Library::Handle(Z, Library::LookupLibrary(url_str)); | 5347 Library& library = Library::Handle(Z, Library::LookupLibrary(url_str)); |
5350 if (library.IsNull()) { | 5348 if (library.IsNull()) { |
5351 library = Library::New(url_str); | 5349 library = Library::New(url_str); |
5352 library.Register(); | 5350 library.Register(); |
5353 } else if (library.LoadInProgress() || | 5351 } else if (library.LoadInProgress() || |
5354 library.Loaded() || | 5352 library.Loaded() || |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5392 if (import_vm.IsNull()) { | 5390 if (import_vm.IsNull()) { |
5393 RETURN_TYPE_ERROR(Z, import, Library); | 5391 RETURN_TYPE_ERROR(Z, import, Library); |
5394 } | 5392 } |
5395 const Object& prefix_object = Object::Handle(Z, Api::UnwrapHandle(prefix)); | 5393 const Object& prefix_object = Object::Handle(Z, Api::UnwrapHandle(prefix)); |
5396 const String& prefix_vm = prefix_object.IsNull() | 5394 const String& prefix_vm = prefix_object.IsNull() |
5397 ? Symbols::Empty() | 5395 ? Symbols::Empty() |
5398 : String::Cast(prefix_object); | 5396 : String::Cast(prefix_object); |
5399 if (prefix_vm.IsNull()) { | 5397 if (prefix_vm.IsNull()) { |
5400 RETURN_TYPE_ERROR(Z, prefix, String); | 5398 RETURN_TYPE_ERROR(Z, prefix, String); |
5401 } | 5399 } |
5402 CHECK_CALLBACK_STATE(I); | 5400 CHECK_CALLBACK_STATE(T); |
5403 CHECK_COMPILATION_ALLOWED(I); | 5401 CHECK_COMPILATION_ALLOWED(I); |
5404 | 5402 |
5405 const String& prefix_symbol = String::Handle(Z, Symbols::New(prefix_vm)); | 5403 const String& prefix_symbol = String::Handle(Z, Symbols::New(prefix_vm)); |
5406 const Namespace& import_ns = Namespace::Handle(Z, | 5404 const Namespace& import_ns = Namespace::Handle(Z, |
5407 Namespace::New(import_vm, Object::null_array(), Object::null_array())); | 5405 Namespace::New(import_vm, Object::null_array(), Object::null_array())); |
5408 if (prefix_vm.Length() == 0) { | 5406 if (prefix_vm.Length() == 0) { |
5409 library_vm.AddImport(import_ns); | 5407 library_vm.AddImport(import_ns); |
5410 } else { | 5408 } else { |
5411 LibraryPrefix& library_prefix = LibraryPrefix::Handle(); | 5409 LibraryPrefix& library_prefix = LibraryPrefix::Handle(); |
5412 library_prefix = library_vm.LookupLocalLibraryPrefix(prefix_symbol); | 5410 library_prefix = library_vm.LookupLocalLibraryPrefix(prefix_symbol); |
(...skipping 28 matching lines...) Expand all Loading... |
5441 RETURN_TYPE_ERROR(Z, source, String); | 5439 RETURN_TYPE_ERROR(Z, source, String); |
5442 } | 5440 } |
5443 if (line_offset < 0) { | 5441 if (line_offset < 0) { |
5444 return Api::NewError("%s: argument 'line_offset' must be positive number", | 5442 return Api::NewError("%s: argument 'line_offset' must be positive number", |
5445 CURRENT_FUNC); | 5443 CURRENT_FUNC); |
5446 } | 5444 } |
5447 if (column_offset < 0) { | 5445 if (column_offset < 0) { |
5448 return Api::NewError("%s: argument 'column_offset' must be positive number", | 5446 return Api::NewError("%s: argument 'column_offset' must be positive number", |
5449 CURRENT_FUNC); | 5447 CURRENT_FUNC); |
5450 } | 5448 } |
5451 CHECK_CALLBACK_STATE(I); | 5449 CHECK_CALLBACK_STATE(T); |
5452 CHECK_COMPILATION_ALLOWED(I); | 5450 CHECK_COMPILATION_ALLOWED(I); |
5453 | 5451 |
5454 NoHeapGrowthControlScope no_growth_control; | 5452 NoHeapGrowthControlScope no_growth_control; |
5455 | 5453 |
5456 const Script& script = Script::Handle(Z, | 5454 const Script& script = Script::Handle(Z, |
5457 Script::New(url_str, source_str, RawScript::kSourceTag)); | 5455 Script::New(url_str, source_str, RawScript::kSourceTag)); |
5458 script.SetLocationOffset(line_offset, column_offset); | 5456 script.SetLocationOffset(line_offset, column_offset); |
5459 Dart_Handle result; | 5457 Dart_Handle result; |
5460 CompileSource(I, lib, script, &result); | 5458 CompileSource(I, lib, script, &result); |
5461 return result; | 5459 return result; |
5462 } | 5460 } |
5463 | 5461 |
5464 | 5462 |
5465 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, | 5463 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, |
5466 Dart_Handle url, | 5464 Dart_Handle url, |
5467 Dart_Handle patch_source) { | 5465 Dart_Handle patch_source) { |
5468 DARTSCOPE(Thread::Current()); | 5466 DARTSCOPE(Thread::Current()); |
5469 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5467 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
5470 if (lib.IsNull()) { | 5468 if (lib.IsNull()) { |
5471 RETURN_TYPE_ERROR(Z, library, Library); | 5469 RETURN_TYPE_ERROR(Z, library, Library); |
5472 } | 5470 } |
5473 const String& url_str = Api::UnwrapStringHandle(Z, url); | 5471 const String& url_str = Api::UnwrapStringHandle(Z, url); |
5474 if (url_str.IsNull()) { | 5472 if (url_str.IsNull()) { |
5475 RETURN_TYPE_ERROR(Z, url, String); | 5473 RETURN_TYPE_ERROR(Z, url, String); |
5476 } | 5474 } |
5477 const String& source_str = Api::UnwrapStringHandle(Z, patch_source); | 5475 const String& source_str = Api::UnwrapStringHandle(Z, patch_source); |
5478 if (source_str.IsNull()) { | 5476 if (source_str.IsNull()) { |
5479 RETURN_TYPE_ERROR(Z, patch_source, String); | 5477 RETURN_TYPE_ERROR(Z, patch_source, String); |
5480 } | 5478 } |
5481 CHECK_CALLBACK_STATE(I); | 5479 CHECK_CALLBACK_STATE(T); |
5482 CHECK_COMPILATION_ALLOWED(I); | 5480 CHECK_COMPILATION_ALLOWED(I); |
5483 | 5481 |
5484 NoHeapGrowthControlScope no_growth_control; | 5482 NoHeapGrowthControlScope no_growth_control; |
5485 | 5483 |
5486 const Script& script = Script::Handle(Z, | 5484 const Script& script = Script::Handle(Z, |
5487 Script::New(url_str, source_str, RawScript::kPatchTag)); | 5485 Script::New(url_str, source_str, RawScript::kPatchTag)); |
5488 Dart_Handle result; | 5486 Dart_Handle result; |
5489 CompileSource(I, lib, script, &result); | 5487 CompileSource(I, lib, script, &result); |
5490 return result; | 5488 return result; |
5491 } | 5489 } |
5492 | 5490 |
5493 | 5491 |
5494 // Finalizes classes and invokes Dart core library function that completes | 5492 // Finalizes classes and invokes Dart core library function that completes |
5495 // futures of loadLibrary calls (deferred library loading). | 5493 // futures of loadLibrary calls (deferred library loading). |
5496 DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures) { | 5494 DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures) { |
5497 DARTSCOPE(Thread::Current()); | 5495 DARTSCOPE(Thread::Current()); |
5498 CHECK_CALLBACK_STATE(I); | 5496 CHECK_CALLBACK_STATE(T); |
5499 | 5497 |
5500 I->DoneLoading(); | 5498 I->DoneLoading(); |
5501 | 5499 |
5502 // TODO(hausner): move the remaining code below (finalization and | 5500 // TODO(hausner): move the remaining code below (finalization and |
5503 // invoing of _completeDeferredLoads) into Isolate::DoneLoading(). | 5501 // invoing of _completeDeferredLoads) into Isolate::DoneLoading(). |
5504 | 5502 |
5505 // Finalize all classes if needed. | 5503 // Finalize all classes if needed. |
5506 Dart_Handle state = Api::CheckAndFinalizePendingClasses(I); | 5504 Dart_Handle state = Api::CheckAndFinalizePendingClasses(I); |
5507 if (::Dart_IsError(state)) { | 5505 if (::Dart_IsError(state)) { |
5508 return state; | 5506 return state; |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6034 | 6032 |
6035 | 6033 |
6036 DART_EXPORT Dart_Handle Dart_Precompile( | 6034 DART_EXPORT Dart_Handle Dart_Precompile( |
6037 Dart_QualifiedFunctionName entry_points[], | 6035 Dart_QualifiedFunctionName entry_points[], |
6038 bool reset_fields) { | 6036 bool reset_fields) { |
6039 DARTSCOPE(Thread::Current()); | 6037 DARTSCOPE(Thread::Current()); |
6040 Dart_Handle result = Api::CheckAndFinalizePendingClasses(I); | 6038 Dart_Handle result = Api::CheckAndFinalizePendingClasses(I); |
6041 if (::Dart_IsError(result)) { | 6039 if (::Dart_IsError(result)) { |
6042 return result; | 6040 return result; |
6043 } | 6041 } |
6044 CHECK_CALLBACK_STATE(I); | 6042 CHECK_CALLBACK_STATE(T); |
6045 const Error& error = Error::Handle(Precompiler::CompileAll(entry_points, | 6043 const Error& error = Error::Handle(Precompiler::CompileAll(entry_points, |
6046 reset_fields)); | 6044 reset_fields)); |
6047 if (!error.IsNull()) { | 6045 if (!error.IsNull()) { |
6048 return Api::NewHandle(I, error.raw()); | 6046 return Api::NewHandle(I, error.raw()); |
6049 } | 6047 } |
6050 return Api::Success(); | 6048 return Api::Success(); |
6051 } | 6049 } |
6052 | 6050 |
6053 | 6051 |
6054 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshot( | 6052 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshot( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6090 ApiReallocate); | 6088 ApiReallocate); |
6091 writer.WriteFullSnapshot(); | 6089 writer.WriteFullSnapshot(); |
6092 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 6090 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
6093 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 6091 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
6094 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); | 6092 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); |
6095 | 6093 |
6096 return Api::Success(); | 6094 return Api::Success(); |
6097 } | 6095 } |
6098 | 6096 |
6099 } // namespace dart | 6097 } // namespace dart |
OLD | NEW |