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

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

Issue 1526463005: Emit Timeline events for most Dart_API calls (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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/timeline.h » ('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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 53
54 DECLARE_FLAG(bool, load_deferred_eagerly); 54 DECLARE_FLAG(bool, load_deferred_eagerly);
55 DECLARE_FLAG(bool, precompilation); 55 DECLARE_FLAG(bool, precompilation);
56 DECLARE_FLAG(bool, print_class_table); 56 DECLARE_FLAG(bool, print_class_table);
57 DECLARE_FLAG(bool, verify_handles); 57 DECLARE_FLAG(bool, verify_handles);
58 #if defined(DART_NO_SNAPSHOT) 58 #if defined(DART_NO_SNAPSHOT)
59 DEFINE_FLAG(bool, check_function_fingerprints, true, 59 DEFINE_FLAG(bool, check_function_fingerprints, true,
60 "Check function fingerprints"); 60 "Check function fingerprints");
61 #endif // defined(DART_NO_SNAPSHOT). 61 #endif // defined(DART_NO_SNAPSHOT).
62 DEFINE_FLAG(bool, trace_api, false,
63 "Trace invocation of API calls (debug mode only)");
64 DEFINE_FLAG(bool, verify_acquired_data, false, 62 DEFINE_FLAG(bool, verify_acquired_data, false,
65 "Verify correct API acquire/release of typed data."); 63 "Verify correct API acquire/release of typed data.");
66 64
67 ThreadLocalKey Api::api_native_key_ = kUnsetThreadLocalKey; 65 ThreadLocalKey Api::api_native_key_ = kUnsetThreadLocalKey;
68 Dart_Handle Api::true_handle_ = NULL; 66 Dart_Handle Api::true_handle_ = NULL;
69 Dart_Handle Api::false_handle_ = NULL; 67 Dart_Handle Api::false_handle_ = NULL;
70 Dart_Handle Api::null_handle_ = NULL; 68 Dart_Handle Api::null_handle_ = NULL;
71 Dart_Handle Api::empty_string_handle_ = NULL; 69 Dart_Handle Api::empty_string_handle_ = NULL;
72 70
73 71
74 const char* CanonicalFunction(const char* func) { 72 const char* CanonicalFunction(const char* func) {
75 if (strncmp(func, "dart::", 6) == 0) { 73 if (strncmp(func, "dart::", 6) == 0) {
76 return func + 6; 74 return func + 6;
77 } else { 75 } else {
78 return func; 76 return func;
79 } 77 }
80 } 78 }
81 79
80 #define API_TIMELINE_DURATION \
81 TimelineDurationScope tds(Thread::Current(), \
82 Timeline::GetVMApiStream(), \
83 CURRENT_FUNC)
84
85 #define API_TIMELINE_BEGIN_END \
86 TimelineBeginEndScope tbes(Thread::Current(), \
87 Timeline::GetVMApiStream(), \
88 CURRENT_FUNC)
82 89
83 #if defined(DEBUG) 90 #if defined(DEBUG)
84 // An object visitor which will iterate over all the function objects in the 91 // An object visitor which will iterate over all the function objects in the
85 // heap and check if the result type and parameter types are canonicalized 92 // heap and check if the result type and parameter types are canonicalized
86 // or not. An assertion is raised if a type is not canonicalized. 93 // or not. An assertion is raised if a type is not canonicalized.
87 class FunctionVisitor : public ObjectVisitor { 94 class FunctionVisitor : public ObjectVisitor {
88 public: 95 public:
89 explicit FunctionVisitor(Thread* thread) : 96 explicit FunctionVisitor(Thread* thread) :
90 ObjectVisitor(thread->isolate()), 97 ObjectVisitor(thread->isolate()),
91 classHandle_(Class::Handle(thread->zone())), 98 classHandle_(Class::Handle(thread->zone())),
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 (*callback)(isolate->init_callback_data(), object, peer); 701 (*callback)(isolate->init_callback_data(), object, peer);
695 ApiState* state = isolate->api_state(); 702 ApiState* state = isolate->api_state();
696 ASSERT(state != NULL); 703 ASSERT(state != NULL);
697 state->weak_persistent_handles().FreeHandle(handle); 704 state->weak_persistent_handles().FreeHandle(handle);
698 } 705 }
699 706
700 707
701 // --- Handles --- 708 // --- Handles ---
702 709
703 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { 710 DART_EXPORT bool Dart_IsError(Dart_Handle handle) {
704 TRACE_API_CALL(CURRENT_FUNC);
705 return RawObject::IsErrorClassId(Api::ClassId(handle)); 711 return RawObject::IsErrorClassId(Api::ClassId(handle));
706 } 712 }
707 713
708 714
709 DART_EXPORT bool Dart_IsApiError(Dart_Handle object) { 715 DART_EXPORT bool Dart_IsApiError(Dart_Handle object) {
710 TRACE_API_CALL(CURRENT_FUNC);
711 return Api::ClassId(object) == kApiErrorCid; 716 return Api::ClassId(object) == kApiErrorCid;
712 } 717 }
713 718
714 719
715 DART_EXPORT bool Dart_IsUnhandledExceptionError(Dart_Handle object) { 720 DART_EXPORT bool Dart_IsUnhandledExceptionError(Dart_Handle object) {
716 TRACE_API_CALL(CURRENT_FUNC);
717 return Api::ClassId(object) == kUnhandledExceptionCid; 721 return Api::ClassId(object) == kUnhandledExceptionCid;
718 } 722 }
719 723
720 724
721 DART_EXPORT bool Dart_IsCompilationError(Dart_Handle object) { 725 DART_EXPORT bool Dart_IsCompilationError(Dart_Handle object) {
722 TRACE_API_CALL(CURRENT_FUNC);
723 return Api::ClassId(object) == kLanguageErrorCid; 726 return Api::ClassId(object) == kLanguageErrorCid;
724 } 727 }
725 728
726 729
727 DART_EXPORT bool Dart_IsFatalError(Dart_Handle object) { 730 DART_EXPORT bool Dart_IsFatalError(Dart_Handle object) {
728 TRACE_API_CALL(CURRENT_FUNC);
729 return Api::ClassId(object) == kUnwindErrorCid; 731 return Api::ClassId(object) == kUnwindErrorCid;
730 } 732 }
731 733
732 734
733 DART_EXPORT bool Dart_IsVMRestartRequest(Dart_Handle handle) { 735 DART_EXPORT bool Dart_IsVMRestartRequest(Dart_Handle handle) {
734 DARTSCOPE(Thread::Current()); 736 DARTSCOPE(Thread::Current());
735 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); 737 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle));
736 return (obj.IsUnwindError() && UnwindError::Cast(obj).is_vm_restart()); 738 return (obj.IsUnwindError() && UnwindError::Cast(obj).is_vm_restart());
737 } 739 }
738 740
739 741
740 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { 742 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) {
743 API_TIMELINE_DURATION;
741 DARTSCOPE(Thread::Current()); 744 DARTSCOPE(Thread::Current());
742 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); 745 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle));
743 if (obj.IsError()) { 746 if (obj.IsError()) {
744 const Error& error = Error::Cast(obj); 747 const Error& error = Error::Cast(obj);
745 const char* str = error.ToErrorCString(); 748 const char* str = error.ToErrorCString();
746 intptr_t len = strlen(str) + 1; 749 intptr_t len = strlen(str) + 1;
747 char* str_copy = Api::TopScope(T)->zone()->Alloc<char>(len); 750 char* str_copy = Api::TopScope(T)->zone()->Alloc<char>(len);
748 strncpy(str_copy, str, len); 751 strncpy(str_copy, str, len);
749 // Strip a possible trailing '\n'. 752 // Strip a possible trailing '\n'.
750 if ((len > 1) && (str_copy[len - 2] == '\n')) { 753 if ((len > 1) && (str_copy[len - 2] == '\n')) {
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 1276
1274 1277
1275 DART_EXPORT void* Dart_CurrentIsolateData() { 1278 DART_EXPORT void* Dart_CurrentIsolateData() {
1276 Isolate* isolate = Isolate::Current(); 1279 Isolate* isolate = Isolate::Current();
1277 CHECK_ISOLATE(isolate); 1280 CHECK_ISOLATE(isolate);
1278 return isolate->init_callback_data(); 1281 return isolate->init_callback_data();
1279 } 1282 }
1280 1283
1281 1284
1282 DART_EXPORT void* Dart_IsolateData(Dart_Isolate isolate) { 1285 DART_EXPORT void* Dart_IsolateData(Dart_Isolate isolate) {
1283 TRACE_API_CALL(CURRENT_FUNC);
1284 if (isolate == NULL) { 1286 if (isolate == NULL) {
1285 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); 1287 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC);
1286 } 1288 }
1287 // TODO(16615): Validate isolate parameter. 1289 // TODO(16615): Validate isolate parameter.
1288 Isolate* iso = reinterpret_cast<Isolate*>(isolate); 1290 Isolate* iso = reinterpret_cast<Isolate*>(isolate);
1289 return iso->init_callback_data(); 1291 return iso->init_callback_data();
1290 } 1292 }
1291 1293
1292 1294
1293 DART_EXPORT Dart_Handle Dart_DebugName() { 1295 DART_EXPORT Dart_Handle Dart_DebugName() {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 1444
1443 1445
1444 DART_EXPORT Dart_Handle Dart_CreateLibrarySnapshot(Dart_Handle library, 1446 DART_EXPORT Dart_Handle Dart_CreateLibrarySnapshot(Dart_Handle library,
1445 uint8_t** buffer, 1447 uint8_t** buffer,
1446 intptr_t* size) { 1448 intptr_t* size) {
1447 return createLibrarySnapshot(library, buffer, size); 1449 return createLibrarySnapshot(library, buffer, size);
1448 } 1450 }
1449 1451
1450 1452
1451 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { 1453 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) {
1452 TRACE_API_CALL(CURRENT_FUNC);
1453 if (isolate == NULL) { 1454 if (isolate == NULL) {
1454 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); 1455 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC);
1455 } 1456 }
1456 // TODO(16615): Validate isolate parameter. 1457 // TODO(16615): Validate isolate parameter.
1457 Isolate* iso = reinterpret_cast<Isolate*>(isolate); 1458 Isolate* iso = reinterpret_cast<Isolate*>(isolate);
1458 iso->SendInternalLibMessage(Isolate::kInterruptMsg, iso->pause_capability()); 1459 iso->SendInternalLibMessage(Isolate::kInterruptMsg, iso->pause_capability());
1459 } 1460 }
1460 1461
1461 1462
1462 DART_EXPORT bool Dart_IsolateMakeRunnable(Dart_Isolate isolate) { 1463 DART_EXPORT bool Dart_IsolateMakeRunnable(Dart_Isolate isolate) {
1463 CHECK_NO_ISOLATE(Isolate::Current()); 1464 CHECK_NO_ISOLATE(Isolate::Current());
1465 API_TIMELINE_DURATION;
1464 if (isolate == NULL) { 1466 if (isolate == NULL) {
1465 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); 1467 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC);
1466 } 1468 }
1467 // TODO(16615): Validate isolate parameter. 1469 // TODO(16615): Validate isolate parameter.
1468 Isolate* iso = reinterpret_cast<Isolate*>(isolate); 1470 Isolate* iso = reinterpret_cast<Isolate*>(isolate);
1469 if (iso->object_store()->root_library() == Library::null()) { 1471 if (iso->object_store()->root_library() == Library::null()) {
1470 // The embedder should have called Dart_LoadScript by now. 1472 // The embedder should have called Dart_LoadScript by now.
1471 return false; 1473 return false;
1472 } 1474 }
1473 return iso->MakeRunnable(); 1475 return iso->MakeRunnable();
(...skipping 23 matching lines...) Expand all
1497 data->done = true; 1499 data->done = true;
1498 ml.Notify(); 1500 ml.Notify();
1499 } 1501 }
1500 1502
1501 1503
1502 DART_EXPORT Dart_Handle Dart_RunLoop() { 1504 DART_EXPORT Dart_Handle Dart_RunLoop() {
1503 Thread* T = Thread::Current(); 1505 Thread* T = Thread::Current();
1504 Isolate* I = T->isolate(); 1506 Isolate* I = T->isolate();
1505 CHECK_API_SCOPE(T); 1507 CHECK_API_SCOPE(T);
1506 CHECK_CALLBACK_STATE(T); 1508 CHECK_CALLBACK_STATE(T);
1509 API_TIMELINE_BEGIN_END;
1507 Monitor monitor; 1510 Monitor monitor;
1508 MonitorLocker ml(&monitor); 1511 MonitorLocker ml(&monitor);
1509 { 1512 {
1510 // The message handler run loop does not expect to have a current isolate 1513 // The message handler run loop does not expect to have a current isolate
1511 // so we exit the isolate here and enter it again after the runloop is done. 1514 // so we exit the isolate here and enter it again after the runloop is done.
1512 Thread::ExitIsolate(); 1515 Thread::ExitIsolate();
1513 RunLoopData data; 1516 RunLoopData data;
1514 data.monitor = &monitor; 1517 data.monitor = &monitor;
1515 data.done = false; 1518 data.done = false;
1516 I->message_handler()->Run( 1519 I->message_handler()->Run(
(...skipping 15 matching lines...) Expand all
1532 } 1535 }
1533 return Api::Success(); 1536 return Api::Success();
1534 } 1537 }
1535 1538
1536 1539
1537 DART_EXPORT Dart_Handle Dart_HandleMessage() { 1540 DART_EXPORT Dart_Handle Dart_HandleMessage() {
1538 Thread* T = Thread::Current(); 1541 Thread* T = Thread::Current();
1539 Isolate* I = T->isolate(); 1542 Isolate* I = T->isolate();
1540 CHECK_API_SCOPE(T); 1543 CHECK_API_SCOPE(T);
1541 CHECK_CALLBACK_STATE(T); 1544 CHECK_CALLBACK_STATE(T);
1545 API_TIMELINE_BEGIN_END;
1542 if (I->message_handler()->HandleNextMessage() != MessageHandler::kOK) { 1546 if (I->message_handler()->HandleNextMessage() != MessageHandler::kOK) {
1543 Dart_Handle error = Api::NewHandle(T, I->object_store()->sticky_error()); 1547 Dart_Handle error = Api::NewHandle(T, I->object_store()->sticky_error());
1544 I->object_store()->clear_sticky_error(); 1548 I->object_store()->clear_sticky_error();
1545 return error; 1549 return error;
1546 } 1550 }
1547 return Api::Success(); 1551 return Api::Success();
1548 } 1552 }
1549 1553
1550 1554
1551 DART_EXPORT bool Dart_HandleServiceMessages() { 1555 DART_EXPORT bool Dart_HandleServiceMessages() {
1552 Thread* T = Thread::Current(); 1556 Thread* T = Thread::Current();
1553 Isolate* I = T->isolate(); 1557 Isolate* I = T->isolate();
1554 CHECK_API_SCOPE(T); 1558 CHECK_API_SCOPE(T);
1555 CHECK_CALLBACK_STATE(T); 1559 CHECK_CALLBACK_STATE(T);
1556 1560 API_TIMELINE_DURATION;
1557 ASSERT(I->GetAndClearResumeRequest() == false); 1561 ASSERT(I->GetAndClearResumeRequest() == false);
1558 MessageHandler::MessageStatus status = 1562 MessageHandler::MessageStatus status =
1559 I->message_handler()->HandleOOBMessages(); 1563 I->message_handler()->HandleOOBMessages();
1560 bool resume = I->GetAndClearResumeRequest(); 1564 bool resume = I->GetAndClearResumeRequest();
1561 return (status != MessageHandler::kOK) || resume; 1565 return (status != MessageHandler::kOK) || resume;
1562 } 1566 }
1563 1567
1564 1568
1565 DART_EXPORT bool Dart_HasServiceMessages() { 1569 DART_EXPORT bool Dart_HasServiceMessages() {
1566 Isolate* isolate = Isolate::Current(); 1570 Isolate* isolate = Isolate::Current();
(...skipping 10 matching lines...) Expand all
1577 1581
1578 1582
1579 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 1583 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
1580 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); 1584 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
1581 return reinterpret_cast<uint8_t*>(new_ptr); 1585 return reinterpret_cast<uint8_t*>(new_ptr);
1582 } 1586 }
1583 1587
1584 1588
1585 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { 1589 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) {
1586 DARTSCOPE(Thread::Current()); 1590 DARTSCOPE(Thread::Current());
1591 API_TIMELINE_DURATION;
1587 NoSafepointScope no_safepoint_scope; 1592 NoSafepointScope no_safepoint_scope;
1588 if (port_id == ILLEGAL_PORT) { 1593 if (port_id == ILLEGAL_PORT) {
1589 return false; 1594 return false;
1590 } 1595 }
1591 1596
1592 // Smis and null can be sent without serialization. 1597 // Smis and null can be sent without serialization.
1593 RawObject* raw_obj = Api::UnwrapHandle(handle); 1598 RawObject* raw_obj = Api::UnwrapHandle(handle);
1594 if (ApiObjectConverter::CanConvert(raw_obj)) { 1599 if (ApiObjectConverter::CanConvert(raw_obj)) {
1595 return PortMap::PostMessage(new Message( 1600 return PortMap::PostMessage(new Message(
1596 port_id, raw_obj, Message::kNormalPriority)); 1601 port_id, raw_obj, Message::kNormalPriority));
(...skipping 18 matching lines...) Expand all
1615 port_id); 1620 port_id);
1616 } 1621 }
1617 return Api::NewHandle(T, SendPort::New(port_id)); 1622 return Api::NewHandle(T, SendPort::New(port_id));
1618 } 1623 }
1619 1624
1620 1625
1621 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, 1626 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port,
1622 Dart_Port* port_id) { 1627 Dart_Port* port_id) {
1623 DARTSCOPE(Thread::Current()); 1628 DARTSCOPE(Thread::Current());
1624 CHECK_CALLBACK_STATE(T); 1629 CHECK_CALLBACK_STATE(T);
1630 API_TIMELINE_DURATION;
1625 const SendPort& send_port = Api::UnwrapSendPortHandle(Z, port); 1631 const SendPort& send_port = Api::UnwrapSendPortHandle(Z, port);
1626 if (send_port.IsNull()) { 1632 if (send_port.IsNull()) {
1627 RETURN_TYPE_ERROR(Z, port, SendPort); 1633 RETURN_TYPE_ERROR(Z, port, SendPort);
1628 } 1634 }
1629 if (port_id == NULL) { 1635 if (port_id == NULL) {
1630 RETURN_NULL_ERROR(port_id); 1636 RETURN_NULL_ERROR(port_id);
1631 } 1637 }
1632 *port_id = send_port.Id(); 1638 *port_id = send_port.Id();
1633 return Api::Success(); 1639 return Api::Success();
1634 } 1640 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1774 Thread* thread = Thread::Current(); 1780 Thread* thread = Thread::Current();
1775 CHECK_ISOLATE(thread->isolate()); 1781 CHECK_ISOLATE(thread->isolate());
1776 REUSABLE_OBJECT_HANDLESCOPE(thread); 1782 REUSABLE_OBJECT_HANDLESCOPE(thread);
1777 Object& ref = thread->ObjectHandle(); 1783 Object& ref = thread->ObjectHandle();
1778 ref = Api::UnwrapHandle(object); 1784 ref = Api::UnwrapHandle(object);
1779 return ref.IsInstance(); 1785 return ref.IsInstance();
1780 } 1786 }
1781 1787
1782 1788
1783 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { 1789 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) {
1784 TRACE_API_CALL(CURRENT_FUNC);
1785 return RawObject::IsNumberClassId(Api::ClassId(object)); 1790 return RawObject::IsNumberClassId(Api::ClassId(object));
1786 } 1791 }
1787 1792
1788 1793
1789 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { 1794 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) {
1790 TRACE_API_CALL(CURRENT_FUNC);
1791 return RawObject::IsIntegerClassId(Api::ClassId(object)); 1795 return RawObject::IsIntegerClassId(Api::ClassId(object));
1792 } 1796 }
1793 1797
1794 1798
1795 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) { 1799 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) {
1796 TRACE_API_CALL(CURRENT_FUNC);
1797 return Api::ClassId(object) == kDoubleCid; 1800 return Api::ClassId(object) == kDoubleCid;
1798 } 1801 }
1799 1802
1800 1803
1801 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) { 1804 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) {
1802 TRACE_API_CALL(CURRENT_FUNC);
1803 return Api::ClassId(object) == kBoolCid; 1805 return Api::ClassId(object) == kBoolCid;
1804 } 1806 }
1805 1807
1806 1808
1807 DART_EXPORT bool Dart_IsString(Dart_Handle object) { 1809 DART_EXPORT bool Dart_IsString(Dart_Handle object) {
1808 TRACE_API_CALL(CURRENT_FUNC);
1809 return RawObject::IsStringClassId(Api::ClassId(object)); 1810 return RawObject::IsStringClassId(Api::ClassId(object));
1810 } 1811 }
1811 1812
1812 1813
1813 DART_EXPORT bool Dart_IsStringLatin1(Dart_Handle object) { 1814 DART_EXPORT bool Dart_IsStringLatin1(Dart_Handle object) {
1814 TRACE_API_CALL(CURRENT_FUNC);
1815 return RawObject::IsOneByteStringClassId(Api::ClassId(object)); 1815 return RawObject::IsOneByteStringClassId(Api::ClassId(object));
1816 } 1816 }
1817 1817
1818 1818
1819 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { 1819 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) {
1820 TRACE_API_CALL(CURRENT_FUNC);
1821 return RawObject::IsExternalStringClassId(Api::ClassId(object)); 1820 return RawObject::IsExternalStringClassId(Api::ClassId(object));
1822 } 1821 }
1823 1822
1824 1823
1825 DART_EXPORT bool Dart_IsList(Dart_Handle object) { 1824 DART_EXPORT bool Dart_IsList(Dart_Handle object) {
1826 if (RawObject::IsBuiltinListClassId(Api::ClassId(object))) { 1825 if (RawObject::IsBuiltinListClassId(Api::ClassId(object))) {
1827 TRACE_API_CALL(CURRENT_FUNC);
1828 return true; 1826 return true;
1829 } 1827 }
1830 1828
1831 DARTSCOPE(Thread::Current()); 1829 DARTSCOPE(Thread::Current());
1832 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); 1830 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object));
1833 return GetListInstance(Z, obj) != Instance::null(); 1831 return GetListInstance(Z, obj) != Instance::null();
1834 } 1832 }
1835 1833
1836 1834
1837 DART_EXPORT bool Dart_IsMap(Dart_Handle object) { 1835 DART_EXPORT bool Dart_IsMap(Dart_Handle object) {
1838 DARTSCOPE(Thread::Current()); 1836 DARTSCOPE(Thread::Current());
1839 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); 1837 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object));
1840 return GetMapInstance(Z, obj) != Instance::null(); 1838 return GetMapInstance(Z, obj) != Instance::null();
1841 } 1839 }
1842 1840
1843 1841
1844 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { 1842 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) {
1845 TRACE_API_CALL(CURRENT_FUNC);
1846 return Api::ClassId(object) == kLibraryCid; 1843 return Api::ClassId(object) == kLibraryCid;
1847 } 1844 }
1848 1845
1849 1846
1850 DART_EXPORT bool Dart_IsType(Dart_Handle handle) { 1847 DART_EXPORT bool Dart_IsType(Dart_Handle handle) {
1851 TRACE_API_CALL(CURRENT_FUNC);
1852 return Api::ClassId(handle) == kTypeCid; 1848 return Api::ClassId(handle) == kTypeCid;
1853 } 1849 }
1854 1850
1855 1851
1856 DART_EXPORT bool Dart_IsFunction(Dart_Handle handle) { 1852 DART_EXPORT bool Dart_IsFunction(Dart_Handle handle) {
1857 TRACE_API_CALL(CURRENT_FUNC);
1858 return Api::ClassId(handle) == kFunctionCid; 1853 return Api::ClassId(handle) == kFunctionCid;
1859 } 1854 }
1860 1855
1861 1856
1862 DART_EXPORT bool Dart_IsVariable(Dart_Handle handle) { 1857 DART_EXPORT bool Dart_IsVariable(Dart_Handle handle) {
1863 TRACE_API_CALL(CURRENT_FUNC);
1864 return Api::ClassId(handle) == kFieldCid; 1858 return Api::ClassId(handle) == kFieldCid;
1865 } 1859 }
1866 1860
1867 1861
1868 DART_EXPORT bool Dart_IsTypeVariable(Dart_Handle handle) { 1862 DART_EXPORT bool Dart_IsTypeVariable(Dart_Handle handle) {
1869 TRACE_API_CALL(CURRENT_FUNC);
1870 return Api::ClassId(handle) == kTypeParameterCid; 1863 return Api::ClassId(handle) == kTypeParameterCid;
1871 } 1864 }
1872 1865
1873 1866
1874 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { 1867 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) {
1875 // We can't use a fast class index check here because there are many 1868 // We can't use a fast class index check here because there are many
1876 // different signature classes for closures. 1869 // different signature classes for closures.
1877 Thread* thread = Thread::Current(); 1870 Thread* thread = Thread::Current();
1878 CHECK_ISOLATE(thread->isolate()); 1871 CHECK_ISOLATE(thread->isolate());
1879 ReusableObjectHandleScope reused_obj_handle(thread); 1872 ReusableObjectHandleScope reused_obj_handle(thread);
1880 const Instance& closure_obj = 1873 const Instance& closure_obj =
1881 Api::UnwrapInstanceHandle(reused_obj_handle, object); 1874 Api::UnwrapInstanceHandle(reused_obj_handle, object);
1882 return (!closure_obj.IsNull() && closure_obj.IsClosure()); 1875 return (!closure_obj.IsNull() && closure_obj.IsClosure());
1883 } 1876 }
1884 1877
1885 1878
1886 DART_EXPORT bool Dart_IsTypedData(Dart_Handle handle) { 1879 DART_EXPORT bool Dart_IsTypedData(Dart_Handle handle) {
1887 TRACE_API_CALL(CURRENT_FUNC);
1888 intptr_t cid = Api::ClassId(handle); 1880 intptr_t cid = Api::ClassId(handle);
1889 return RawObject::IsTypedDataClassId(cid) || 1881 return RawObject::IsTypedDataClassId(cid) ||
1890 RawObject::IsExternalTypedDataClassId(cid) || 1882 RawObject::IsExternalTypedDataClassId(cid) ||
1891 RawObject::IsTypedDataViewClassId(cid); 1883 RawObject::IsTypedDataViewClassId(cid);
1892 } 1884 }
1893 1885
1894 1886
1895 DART_EXPORT bool Dart_IsByteBuffer(Dart_Handle handle) { 1887 DART_EXPORT bool Dart_IsByteBuffer(Dart_Handle handle) {
1896 TRACE_API_CALL(CURRENT_FUNC);
1897 return Api::ClassId(handle) == kByteBufferCid; 1888 return Api::ClassId(handle) == kByteBufferCid;
1898 } 1889 }
1899 1890
1900 1891
1901 DART_EXPORT bool Dart_IsFuture(Dart_Handle handle) { 1892 DART_EXPORT bool Dart_IsFuture(Dart_Handle handle) {
1902 TRACE_API_CALL(CURRENT_FUNC); 1893 API_TIMELINE_DURATION;
1903 DARTSCOPE(Thread::Current()); 1894 DARTSCOPE(Thread::Current());
1904 Isolate* I = T->isolate(); 1895 Isolate* I = T->isolate();
1905 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); 1896 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle));
1906 if (obj.IsInstance()) { 1897 if (obj.IsInstance()) {
1907 const Class& future_class = 1898 const Class& future_class =
1908 Class::Handle(I->object_store()->future_class()); 1899 Class::Handle(I->object_store()->future_class());
1909 ASSERT(!future_class.IsNull()); 1900 ASSERT(!future_class.IsNull());
1910 const Class& obj_class = Class::Handle(Z, obj.clazz()); 1901 const Class& obj_class = Class::Handle(Z, obj.clazz());
1911 Error& malformed_type_error = Error::Handle(Z); 1902 Error& malformed_type_error = Error::Handle(Z);
1912 bool is_future = obj_class.IsSubtypeOf(Object::null_type_arguments(), 1903 bool is_future = obj_class.IsSubtypeOf(Object::null_type_arguments(),
1913 future_class, 1904 future_class,
1914 Object::null_type_arguments(), 1905 Object::null_type_arguments(),
1915 &malformed_type_error); 1906 &malformed_type_error);
1916 ASSERT(malformed_type_error.IsNull()); // Type is a raw Future. 1907 ASSERT(malformed_type_error.IsNull()); // Type is a raw Future.
1917 return is_future; 1908 return is_future;
1918 } 1909 }
1919 return false; 1910 return false;
1920 } 1911 }
1921 1912
1922 1913
1923 // --- Instances ---- 1914 // --- Instances ----
1924 1915
1925 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) { 1916 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) {
1917 API_TIMELINE_DURATION;
1926 DARTSCOPE(Thread::Current()); 1918 DARTSCOPE(Thread::Current());
1927 Isolate* I = T->isolate(); 1919 Isolate* I = T->isolate();
1928 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(instance)); 1920 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(instance));
1929 if (obj.IsNull()) { 1921 if (obj.IsNull()) {
1930 return Api::NewHandle(T, I->object_store()->null_type()); 1922 return Api::NewHandle(T, I->object_store()->null_type());
1931 } 1923 }
1932 if (!obj.IsInstance()) { 1924 if (!obj.IsInstance()) {
1933 RETURN_TYPE_ERROR(Z, instance, Instance); 1925 RETURN_TYPE_ERROR(Z, instance, Instance);
1934 } 1926 }
1935 const Type& type = Type::Handle(Instance::Cast(obj).GetType()); 1927 const Type& type = Type::Handle(Instance::Cast(obj).GetType());
1936 return Api::NewHandle(T, type.Canonicalize()); 1928 return Api::NewHandle(T, type.Canonicalize());
1937 } 1929 }
1938 1930
1939 1931
1940 // --- Numbers, Integers and Doubles ---- 1932 // --- Numbers, Integers and Doubles ----
1941 1933
1942 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, 1934 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer,
1943 bool* fits) { 1935 bool* fits) {
1936 API_TIMELINE_DURATION;
1944 // Fast path for Smis and Mints. 1937 // Fast path for Smis and Mints.
1945 Thread* thread = Thread::Current(); 1938 Thread* thread = Thread::Current();
1946 Isolate* isolate = thread->isolate(); 1939 Isolate* isolate = thread->isolate();
1947 CHECK_ISOLATE(isolate); 1940 CHECK_ISOLATE(isolate);
1948 intptr_t class_id = Api::ClassId(integer); 1941 intptr_t class_id = Api::ClassId(integer);
1949 if (class_id == kSmiCid || class_id == kMintCid) { 1942 if (class_id == kSmiCid || class_id == kMintCid) {
1950 *fits = true; 1943 *fits = true;
1951 return Api::Success(); 1944 return Api::Success();
1952 } 1945 }
1953 // Slow path for Mints and Bigints. 1946 // Slow path for Mints and Bigints.
1954 DARTSCOPE(thread); 1947 DARTSCOPE(thread);
1955 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); 1948 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer);
1956 if (int_obj.IsNull()) { 1949 if (int_obj.IsNull()) {
1957 RETURN_TYPE_ERROR(Z, integer, Integer); 1950 RETURN_TYPE_ERROR(Z, integer, Integer);
1958 } 1951 }
1959 ASSERT(!Bigint::Cast(int_obj).FitsIntoInt64()); 1952 ASSERT(!Bigint::Cast(int_obj).FitsIntoInt64());
1960 *fits = false; 1953 *fits = false;
1961 return Api::Success(); 1954 return Api::Success();
1962 } 1955 }
1963 1956
1964 1957
1965 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, 1958 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer,
1966 bool* fits) { 1959 bool* fits) {
1967 // Fast path for Smis. 1960 // Fast path for Smis.
1968 Thread* thread = Thread::Current(); 1961 Thread* thread = Thread::Current();
1969 Isolate* isolate = thread->isolate(); 1962 Isolate* isolate = thread->isolate();
1970 CHECK_ISOLATE(isolate); 1963 CHECK_ISOLATE(isolate);
1964 API_TIMELINE_DURATION;
1971 if (Api::IsSmi(integer)) { 1965 if (Api::IsSmi(integer)) {
1972 *fits = (Api::SmiValue(integer) >= 0); 1966 *fits = (Api::SmiValue(integer) >= 0);
1973 return Api::Success(); 1967 return Api::Success();
1974 } 1968 }
1975 // Slow path for Mints and Bigints. 1969 // Slow path for Mints and Bigints.
1976 DARTSCOPE(thread); 1970 DARTSCOPE(thread);
1977 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); 1971 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer);
1978 if (int_obj.IsNull()) { 1972 if (int_obj.IsNull()) {
1979 RETURN_TYPE_ERROR(Z, integer, Integer); 1973 RETURN_TYPE_ERROR(Z, integer, Integer);
1980 } 1974 }
1981 ASSERT(!int_obj.IsSmi()); 1975 ASSERT(!int_obj.IsSmi());
1982 if (int_obj.IsMint()) { 1976 if (int_obj.IsMint()) {
1983 *fits = !int_obj.IsNegative(); 1977 *fits = !int_obj.IsNegative();
1984 } else { 1978 } else {
1985 *fits = Bigint::Cast(int_obj).FitsIntoUint64(); 1979 *fits = Bigint::Cast(int_obj).FitsIntoUint64();
1986 } 1980 }
1987 return Api::Success(); 1981 return Api::Success();
1988 } 1982 }
1989 1983
1990 1984
1991 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { 1985 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) {
1992 // Fast path for Smis. 1986 // Fast path for Smis.
1993 Thread* thread = Thread::Current(); 1987 Thread* thread = Thread::Current();
1994 Isolate* isolate = thread->isolate(); 1988 Isolate* isolate = thread->isolate();
1995 CHECK_ISOLATE(isolate); 1989 CHECK_ISOLATE(isolate);
1990 API_TIMELINE_DURATION;
1996 if (Smi::IsValid(value)) { 1991 if (Smi::IsValid(value)) {
1997 NOHANDLESCOPE(thread); 1992 NOHANDLESCOPE(thread);
1998 return Api::NewHandle(thread, Smi::New(static_cast<intptr_t>(value))); 1993 return Api::NewHandle(thread, Smi::New(static_cast<intptr_t>(value)));
1999 } 1994 }
2000 // Slow path for Mints and Bigints. 1995 // Slow path for Mints and Bigints.
2001 DARTSCOPE(thread); 1996 DARTSCOPE(thread);
2002 CHECK_CALLBACK_STATE(thread); 1997 CHECK_CALLBACK_STATE(thread);
2003 return Api::NewHandle(thread, Integer::New(value)); 1998 return Api::NewHandle(thread, Integer::New(value));
2004 } 1999 }
2005 2000
2006 2001
2007 DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value) { 2002 DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value) {
2008 DARTSCOPE(Thread::Current()); 2003 DARTSCOPE(Thread::Current());
2009 CHECK_CALLBACK_STATE(T); 2004 CHECK_CALLBACK_STATE(T);
2005 API_TIMELINE_DURATION;
2010 return Api::NewHandle(T, Integer::NewFromUint64(value)); 2006 return Api::NewHandle(T, Integer::NewFromUint64(value));
2011 } 2007 }
2012 2008
2013 2009
2014 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { 2010 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) {
2015 DARTSCOPE(Thread::Current()); 2011 DARTSCOPE(Thread::Current());
2016 CHECK_CALLBACK_STATE(T); 2012 CHECK_CALLBACK_STATE(T);
2013 API_TIMELINE_DURATION;
2017 const String& str_obj = String::Handle(Z, String::New(str)); 2014 const String& str_obj = String::Handle(Z, String::New(str));
2018 return Api::NewHandle(T, Integer::New(str_obj)); 2015 return Api::NewHandle(T, Integer::New(str_obj));
2019 } 2016 }
2020 2017
2021 2018
2022 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, 2019 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer,
2023 int64_t* value) { 2020 int64_t* value) {
2024 // Fast path for Smis. 2021 // Fast path for Smis.
2025 Thread* thread = Thread::Current(); 2022 Thread* thread = Thread::Current();
2026 Isolate* isolate = thread->isolate(); 2023 Isolate* isolate = thread->isolate();
2027 CHECK_ISOLATE(isolate); 2024 CHECK_ISOLATE(isolate);
2025 API_TIMELINE_DURATION;
2028 if (Api::IsSmi(integer)) { 2026 if (Api::IsSmi(integer)) {
2029 *value = Api::SmiValue(integer); 2027 *value = Api::SmiValue(integer);
2030 return Api::Success(); 2028 return Api::Success();
2031 } 2029 }
2032 // Slow path for Mints and Bigints. 2030 // Slow path for Mints and Bigints.
2033 DARTSCOPE(thread); 2031 DARTSCOPE(thread);
2034 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); 2032 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer);
2035 if (int_obj.IsNull()) { 2033 if (int_obj.IsNull()) {
2036 RETURN_TYPE_ERROR(Z, integer, Integer); 2034 RETURN_TYPE_ERROR(Z, integer, Integer);
2037 } 2035 }
2038 ASSERT(!int_obj.IsSmi()); 2036 ASSERT(!int_obj.IsSmi());
2039 if (int_obj.IsMint()) { 2037 if (int_obj.IsMint()) {
2040 *value = int_obj.AsInt64Value(); 2038 *value = int_obj.AsInt64Value();
2041 return Api::Success(); 2039 return Api::Success();
2042 } else { 2040 } else {
2043 const Bigint& bigint = Bigint::Cast(int_obj); 2041 const Bigint& bigint = Bigint::Cast(int_obj);
2044 if (bigint.FitsIntoInt64()) { 2042 if (bigint.FitsIntoInt64()) {
2045 *value = bigint.AsInt64Value(); 2043 *value = bigint.AsInt64Value();
2046 return Api::Success(); 2044 return Api::Success();
2047 } 2045 }
2048 } 2046 }
2049 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.", 2047 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.",
2050 CURRENT_FUNC, int_obj.ToCString()); 2048 CURRENT_FUNC, int_obj.ToCString());
2051 } 2049 }
2052 2050
2053 2051
2054 DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer, 2052 DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer,
2055 uint64_t* value) { 2053 uint64_t* value) {
2054 API_TIMELINE_DURATION;
2056 // Fast path for Smis. 2055 // Fast path for Smis.
2057 Thread* thread = Thread::Current(); 2056 Thread* thread = Thread::Current();
2058 Isolate* isolate = thread->isolate(); 2057 Isolate* isolate = thread->isolate();
2059 CHECK_ISOLATE(isolate); 2058 CHECK_ISOLATE(isolate);
2060 if (Api::IsSmi(integer)) { 2059 if (Api::IsSmi(integer)) {
2061 intptr_t smi_value = Api::SmiValue(integer); 2060 intptr_t smi_value = Api::SmiValue(integer);
2062 if (smi_value >= 0) { 2061 if (smi_value >= 0) {
2063 *value = smi_value; 2062 *value = smi_value;
2064 return Api::Success(); 2063 return Api::Success();
2065 } 2064 }
(...skipping 21 matching lines...) Expand all
2087 } 2086 }
2088 2087
2089 2088
2090 static uword BigintAllocate(intptr_t size) { 2089 static uword BigintAllocate(intptr_t size) {
2091 return Api::TopScope(Thread::Current())->zone()->AllocUnsafe(size); 2090 return Api::TopScope(Thread::Current())->zone()->AllocUnsafe(size);
2092 } 2091 }
2093 2092
2094 2093
2095 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, 2094 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer,
2096 const char** value) { 2095 const char** value) {
2096 API_TIMELINE_DURATION;
2097 DARTSCOPE(Thread::Current()); 2097 DARTSCOPE(Thread::Current());
2098 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); 2098 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer);
2099 if (int_obj.IsNull()) { 2099 if (int_obj.IsNull()) {
2100 RETURN_TYPE_ERROR(Z, integer, Integer); 2100 RETURN_TYPE_ERROR(Z, integer, Integer);
2101 } 2101 }
2102 if (int_obj.IsSmi() || int_obj.IsMint()) { 2102 if (int_obj.IsSmi() || int_obj.IsMint()) {
2103 const Bigint& bigint = Bigint::Handle(Z, 2103 const Bigint& bigint = Bigint::Handle(Z,
2104 Bigint::NewFromInt64(int_obj.AsInt64Value())); 2104 Bigint::NewFromInt64(int_obj.AsInt64Value()));
2105 *value = bigint.ToHexCString(BigintAllocate); 2105 *value = bigint.ToHexCString(BigintAllocate);
2106 } else { 2106 } else {
2107 *value = Bigint::Cast(int_obj).ToHexCString(BigintAllocate); 2107 *value = Bigint::Cast(int_obj).ToHexCString(BigintAllocate);
2108 } 2108 }
2109 return Api::Success(); 2109 return Api::Success();
2110 } 2110 }
2111 2111
2112 2112
2113 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { 2113 DART_EXPORT Dart_Handle Dart_NewDouble(double value) {
2114 API_TIMELINE_DURATION;
2114 DARTSCOPE(Thread::Current()); 2115 DARTSCOPE(Thread::Current());
2115 CHECK_CALLBACK_STATE(T); 2116 CHECK_CALLBACK_STATE(T);
2116 return Api::NewHandle(T, Double::New(value)); 2117 return Api::NewHandle(T, Double::New(value));
2117 } 2118 }
2118 2119
2119 2120
2120 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, 2121 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj,
2121 double* value) { 2122 double* value) {
2123 API_TIMELINE_DURATION;
2122 DARTSCOPE(Thread::Current()); 2124 DARTSCOPE(Thread::Current());
2123 const Double& obj = Api::UnwrapDoubleHandle(Z, double_obj); 2125 const Double& obj = Api::UnwrapDoubleHandle(Z, double_obj);
2124 if (obj.IsNull()) { 2126 if (obj.IsNull()) {
2125 RETURN_TYPE_ERROR(Z, double_obj, Double); 2127 RETURN_TYPE_ERROR(Z, double_obj, Double);
2126 } 2128 }
2127 *value = obj.value(); 2129 *value = obj.value();
2128 return Api::Success(); 2130 return Api::Success();
2129 } 2131 }
2130 2132
2131 2133
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2172 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str); 2174 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str);
2173 if (str_obj.IsNull()) { 2175 if (str_obj.IsNull()) {
2174 RETURN_TYPE_ERROR(thread->zone(), str, String); 2176 RETURN_TYPE_ERROR(thread->zone(), str, String);
2175 } 2177 }
2176 *len = str_obj.Length(); 2178 *len = str_obj.Length();
2177 return Api::Success(); 2179 return Api::Success();
2178 } 2180 }
2179 2181
2180 2182
2181 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) { 2183 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) {
2184 API_TIMELINE_DURATION;
2182 DARTSCOPE(Thread::Current()); 2185 DARTSCOPE(Thread::Current());
2183 if (str == NULL) { 2186 if (str == NULL) {
2184 RETURN_NULL_ERROR(str); 2187 RETURN_NULL_ERROR(str);
2185 } 2188 }
2186 CHECK_CALLBACK_STATE(T); 2189 CHECK_CALLBACK_STATE(T);
2187 return Api::NewHandle(T, String::New(str)); 2190 return Api::NewHandle(T, String::New(str));
2188 } 2191 }
2189 2192
2190 2193
2191 DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array, 2194 DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array,
2192 intptr_t length) { 2195 intptr_t length) {
2196 API_TIMELINE_DURATION;
2193 DARTSCOPE(Thread::Current()); 2197 DARTSCOPE(Thread::Current());
2194 if (utf8_array == NULL && length != 0) { 2198 if (utf8_array == NULL && length != 0) {
2195 RETURN_NULL_ERROR(utf8_array); 2199 RETURN_NULL_ERROR(utf8_array);
2196 } 2200 }
2197 CHECK_LENGTH(length, String::kMaxElements); 2201 CHECK_LENGTH(length, String::kMaxElements);
2198 if (!Utf8::IsValid(utf8_array, length)) { 2202 if (!Utf8::IsValid(utf8_array, length)) {
2199 return Api::NewError("%s expects argument 'str' to be valid UTF-8.", 2203 return Api::NewError("%s expects argument 'str' to be valid UTF-8.",
2200 CURRENT_FUNC); 2204 CURRENT_FUNC);
2201 } 2205 }
2202 CHECK_CALLBACK_STATE(T); 2206 CHECK_CALLBACK_STATE(T);
2203 return Api::NewHandle(T, String::FromUTF8(utf8_array, length)); 2207 return Api::NewHandle(T, String::FromUTF8(utf8_array, length));
2204 } 2208 }
2205 2209
2206 2210
2207 DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array, 2211 DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array,
2208 intptr_t length) { 2212 intptr_t length) {
2209 DARTSCOPE(Thread::Current()); 2213 DARTSCOPE(Thread::Current());
2210 if (utf16_array == NULL && length != 0) { 2214 if (utf16_array == NULL && length != 0) {
2211 RETURN_NULL_ERROR(utf16_array); 2215 RETURN_NULL_ERROR(utf16_array);
2212 } 2216 }
2213 CHECK_LENGTH(length, String::kMaxElements); 2217 CHECK_LENGTH(length, String::kMaxElements);
2214 CHECK_CALLBACK_STATE(T); 2218 CHECK_CALLBACK_STATE(T);
2215 return Api::NewHandle(T, String::FromUTF16(utf16_array, length)); 2219 return Api::NewHandle(T, String::FromUTF16(utf16_array, length));
2216 } 2220 }
2217 2221
2218 2222
2219 DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const int32_t* utf32_array, 2223 DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const int32_t* utf32_array,
2220 intptr_t length) { 2224 intptr_t length) {
2225 API_TIMELINE_DURATION;
2221 DARTSCOPE(Thread::Current()); 2226 DARTSCOPE(Thread::Current());
2222 if (utf32_array == NULL && length != 0) { 2227 if (utf32_array == NULL && length != 0) {
2223 RETURN_NULL_ERROR(utf32_array); 2228 RETURN_NULL_ERROR(utf32_array);
2224 } 2229 }
2225 CHECK_LENGTH(length, String::kMaxElements); 2230 CHECK_LENGTH(length, String::kMaxElements);
2226 CHECK_CALLBACK_STATE(T); 2231 CHECK_CALLBACK_STATE(T);
2227 return Api::NewHandle(T, String::FromUTF32(utf32_array, length)); 2232 return Api::NewHandle(T, String::FromUTF32(utf32_array, length));
2228 } 2233 }
2229 2234
2230 2235
2231 DART_EXPORT Dart_Handle Dart_NewExternalLatin1String( 2236 DART_EXPORT Dart_Handle Dart_NewExternalLatin1String(
2232 const uint8_t* latin1_array, 2237 const uint8_t* latin1_array,
2233 intptr_t length, 2238 intptr_t length,
2234 void* peer, 2239 void* peer,
2235 Dart_PeerFinalizer cback) { 2240 Dart_PeerFinalizer cback) {
2241 API_TIMELINE_DURATION;
2236 DARTSCOPE(Thread::Current()); 2242 DARTSCOPE(Thread::Current());
2237 if (latin1_array == NULL && length != 0) { 2243 if (latin1_array == NULL && length != 0) {
2238 RETURN_NULL_ERROR(latin1_array); 2244 RETURN_NULL_ERROR(latin1_array);
2239 } 2245 }
2240 CHECK_LENGTH(length, String::kMaxElements); 2246 CHECK_LENGTH(length, String::kMaxElements);
2241 CHECK_CALLBACK_STATE(T); 2247 CHECK_CALLBACK_STATE(T);
2242 return Api::NewHandle(T, String::NewExternal(latin1_array, 2248 return Api::NewHandle(T, String::NewExternal(latin1_array,
2243 length, 2249 length,
2244 peer, 2250 peer,
2245 cback, 2251 cback,
(...skipping 15 matching lines...) Expand all
2261 return Api::NewHandle(T, String::NewExternal(utf16_array, 2267 return Api::NewHandle(T, String::NewExternal(utf16_array,
2262 length, 2268 length,
2263 peer, 2269 peer,
2264 cback, 2270 cback,
2265 SpaceForExternal(T, bytes))); 2271 SpaceForExternal(T, bytes)));
2266 } 2272 }
2267 2273
2268 2274
2269 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, 2275 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object,
2270 const char** cstr) { 2276 const char** cstr) {
2277 API_TIMELINE_DURATION;
2271 DARTSCOPE(Thread::Current()); 2278 DARTSCOPE(Thread::Current());
2272 if (cstr == NULL) { 2279 if (cstr == NULL) {
2273 RETURN_NULL_ERROR(cstr); 2280 RETURN_NULL_ERROR(cstr);
2274 } 2281 }
2275 const String& str_obj = Api::UnwrapStringHandle(Z, object); 2282 const String& str_obj = Api::UnwrapStringHandle(Z, object);
2276 if (str_obj.IsNull()) { 2283 if (str_obj.IsNull()) {
2277 RETURN_TYPE_ERROR(Z, object, String); 2284 RETURN_TYPE_ERROR(Z, object, String);
2278 } 2285 }
2279 intptr_t string_length = Utf8::Length(str_obj); 2286 intptr_t string_length = Utf8::Length(str_obj);
2280 char* res = Api::TopScope(T)->zone()->Alloc<char>(string_length + 1); 2287 char* res = Api::TopScope(T)->zone()->Alloc<char>(string_length + 1);
2281 if (res == NULL) { 2288 if (res == NULL) {
2282 return Api::NewError("Unable to allocate memory"); 2289 return Api::NewError("Unable to allocate memory");
2283 } 2290 }
2284 const char* string_value = str_obj.ToCString(); 2291 const char* string_value = str_obj.ToCString();
2285 memmove(res, string_value, string_length + 1); 2292 memmove(res, string_value, string_length + 1);
2286 ASSERT(res[string_length] == '\0'); 2293 ASSERT(res[string_length] == '\0');
2287 *cstr = res; 2294 *cstr = res;
2288 return Api::Success(); 2295 return Api::Success();
2289 } 2296 }
2290 2297
2291 2298
2292 DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str, 2299 DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str,
2293 uint8_t** utf8_array, 2300 uint8_t** utf8_array,
2294 intptr_t* length) { 2301 intptr_t* length) {
2302 API_TIMELINE_DURATION;
2295 DARTSCOPE(Thread::Current()); 2303 DARTSCOPE(Thread::Current());
2296 if (utf8_array == NULL) { 2304 if (utf8_array == NULL) {
2297 RETURN_NULL_ERROR(utf8_array); 2305 RETURN_NULL_ERROR(utf8_array);
2298 } 2306 }
2299 if (length == NULL) { 2307 if (length == NULL) {
2300 RETURN_NULL_ERROR(length); 2308 RETURN_NULL_ERROR(length);
2301 } 2309 }
2302 const String& str_obj = Api::UnwrapStringHandle(Z, str); 2310 const String& str_obj = Api::UnwrapStringHandle(Z, str);
2303 if (str_obj.IsNull()) { 2311 if (str_obj.IsNull()) {
2304 RETURN_TYPE_ERROR(Z, str, String); 2312 RETURN_TYPE_ERROR(Z, str, String);
2305 } 2313 }
2306 intptr_t str_len = Utf8::Length(str_obj); 2314 intptr_t str_len = Utf8::Length(str_obj);
2307 *utf8_array = Api::TopScope(T)->zone()->Alloc<uint8_t>(str_len); 2315 *utf8_array = Api::TopScope(T)->zone()->Alloc<uint8_t>(str_len);
2308 if (*utf8_array == NULL) { 2316 if (*utf8_array == NULL) {
2309 return Api::NewError("Unable to allocate memory"); 2317 return Api::NewError("Unable to allocate memory");
2310 } 2318 }
2311 str_obj.ToUTF8(*utf8_array, str_len); 2319 str_obj.ToUTF8(*utf8_array, str_len);
2312 *length = str_len; 2320 *length = str_len;
2313 return Api::Success(); 2321 return Api::Success();
2314 } 2322 }
2315 2323
2316 2324
2317 DART_EXPORT Dart_Handle Dart_StringToLatin1(Dart_Handle str, 2325 DART_EXPORT Dart_Handle Dart_StringToLatin1(Dart_Handle str,
2318 uint8_t* latin1_array, 2326 uint8_t* latin1_array,
2319 intptr_t* length) { 2327 intptr_t* length) {
2328 API_TIMELINE_DURATION;
2320 DARTSCOPE(Thread::Current()); 2329 DARTSCOPE(Thread::Current());
2321 if (latin1_array == NULL) { 2330 if (latin1_array == NULL) {
2322 RETURN_NULL_ERROR(latin1_array); 2331 RETURN_NULL_ERROR(latin1_array);
2323 } 2332 }
2324 if (length == NULL) { 2333 if (length == NULL) {
2325 RETURN_NULL_ERROR(length); 2334 RETURN_NULL_ERROR(length);
2326 } 2335 }
2327 const String& str_obj = Api::UnwrapStringHandle(Z, str); 2336 const String& str_obj = Api::UnwrapStringHandle(Z, str);
2328 if (str_obj.IsNull() || !str_obj.IsOneByteString()) { 2337 if (str_obj.IsNull() || !str_obj.IsOneByteString()) {
2329 RETURN_TYPE_ERROR(Z, str, String); 2338 RETURN_TYPE_ERROR(Z, str, String);
2330 } 2339 }
2331 intptr_t str_len = str_obj.Length(); 2340 intptr_t str_len = str_obj.Length();
2332 intptr_t copy_len = (str_len > *length) ? *length : str_len; 2341 intptr_t copy_len = (str_len > *length) ? *length : str_len;
2333 2342
2334 // We have already asserted that the string object is a Latin-1 string 2343 // We have already asserted that the string object is a Latin-1 string
2335 // so we can copy the characters over using a simple loop. 2344 // so we can copy the characters over using a simple loop.
2336 for (intptr_t i = 0; i < copy_len; i++) { 2345 for (intptr_t i = 0; i < copy_len; i++) {
2337 latin1_array[i] = str_obj.CharAt(i); 2346 latin1_array[i] = str_obj.CharAt(i);
2338 } 2347 }
2339 *length = copy_len; 2348 *length = copy_len;
2340 return Api::Success(); 2349 return Api::Success();
2341 } 2350 }
2342 2351
2343 2352
2344 DART_EXPORT Dart_Handle Dart_StringToUTF16(Dart_Handle str, 2353 DART_EXPORT Dart_Handle Dart_StringToUTF16(Dart_Handle str,
2345 uint16_t* utf16_array, 2354 uint16_t* utf16_array,
2346 intptr_t* length) { 2355 intptr_t* length) {
2356 API_TIMELINE_DURATION;
2347 DARTSCOPE(Thread::Current()); 2357 DARTSCOPE(Thread::Current());
2348 const String& str_obj = Api::UnwrapStringHandle(Z, str); 2358 const String& str_obj = Api::UnwrapStringHandle(Z, str);
2349 if (str_obj.IsNull()) { 2359 if (str_obj.IsNull()) {
2350 RETURN_TYPE_ERROR(Z, str, String); 2360 RETURN_TYPE_ERROR(Z, str, String);
2351 } 2361 }
2352 intptr_t str_len = str_obj.Length(); 2362 intptr_t str_len = str_obj.Length();
2353 intptr_t copy_len = (str_len > *length) ? *length : str_len; 2363 intptr_t copy_len = (str_len > *length) ? *length : str_len;
2354 for (intptr_t i = 0; i < copy_len; i++) { 2364 for (intptr_t i = 0; i < copy_len; i++) {
2355 utf16_array[i] = str_obj.CharAt(i); 2365 utf16_array[i] = str_obj.CharAt(i);
2356 } 2366 }
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
3098 break; 3108 break;
3099 default: 3109 default:
3100 type = Dart_TypedData_kInvalid; 3110 type = Dart_TypedData_kInvalid;
3101 break; 3111 break;
3102 } 3112 }
3103 return type; 3113 return type;
3104 } 3114 }
3105 3115
3106 3116
3107 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfTypedData(Dart_Handle object) { 3117 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfTypedData(Dart_Handle object) {
3108 TRACE_API_CALL(CURRENT_FUNC); 3118 API_TIMELINE_DURATION;
3109 intptr_t class_id = Api::ClassId(object); 3119 intptr_t class_id = Api::ClassId(object);
3110 if (RawObject::IsTypedDataClassId(class_id) || 3120 if (RawObject::IsTypedDataClassId(class_id) ||
3111 RawObject::IsTypedDataViewClassId(class_id)) { 3121 RawObject::IsTypedDataViewClassId(class_id)) {
3112 return GetType(class_id); 3122 return GetType(class_id);
3113 } 3123 }
3114 return Dart_TypedData_kInvalid; 3124 return Dart_TypedData_kInvalid;
3115 } 3125 }
3116 3126
3117 3127
3118 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfExternalTypedData( 3128 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfExternalTypedData(
3119 Dart_Handle object) { 3129 Dart_Handle object) {
3120 TRACE_API_CALL(CURRENT_FUNC); 3130 API_TIMELINE_DURATION;
3121 intptr_t class_id = Api::ClassId(object); 3131 intptr_t class_id = Api::ClassId(object);
3122 if (RawObject::IsExternalTypedDataClassId(class_id)) { 3132 if (RawObject::IsExternalTypedDataClassId(class_id)) {
3123 return GetType(class_id); 3133 return GetType(class_id);
3124 } 3134 }
3125 if (RawObject::IsTypedDataViewClassId(class_id)) { 3135 if (RawObject::IsTypedDataViewClassId(class_id)) {
3126 // Check if data object of the view is external. 3136 // Check if data object of the view is external.
3127 Zone* zone = Thread::Current()->zone(); 3137 Zone* zone = Thread::Current()->zone();
3128 const Instance& view_obj = Api::UnwrapInstanceHandle(zone, object); 3138 const Instance& view_obj = Api::UnwrapInstanceHandle(zone, object);
3129 ASSERT(!view_obj.IsNull()); 3139 ASSERT(!view_obj.IsNull());
3130 const Instance& data_obj = 3140 const Instance& data_obj =
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
3859 args->SetAt((i + extra_args), arg); 3869 args->SetAt((i + extra_args), arg);
3860 } 3870 }
3861 return Api::Success(); 3871 return Api::Success();
3862 } 3872 }
3863 3873
3864 3874
3865 DART_EXPORT Dart_Handle Dart_InvokeConstructor(Dart_Handle object, 3875 DART_EXPORT Dart_Handle Dart_InvokeConstructor(Dart_Handle object,
3866 Dart_Handle name, 3876 Dart_Handle name,
3867 int number_of_arguments, 3877 int number_of_arguments,
3868 Dart_Handle* arguments) { 3878 Dart_Handle* arguments) {
3879 API_TIMELINE_DURATION;
3869 DARTSCOPE(Thread::Current()); 3880 DARTSCOPE(Thread::Current());
3870 CHECK_CALLBACK_STATE(T); 3881 CHECK_CALLBACK_STATE(T);
3871 3882
3872 if (number_of_arguments < 0) { 3883 if (number_of_arguments < 0) {
3873 return Api::NewError( 3884 return Api::NewError(
3874 "%s expects argument 'number_of_arguments' to be non-negative.", 3885 "%s expects argument 'number_of_arguments' to be non-negative.",
3875 CURRENT_FUNC); 3886 CURRENT_FUNC);
3876 } 3887 }
3877 const Instance& instance = Api::UnwrapInstanceHandle(Z, object); 3888 const Instance& instance = Api::UnwrapInstanceHandle(Z, object);
3878 if (instance.IsNull()) { 3889 if (instance.IsNull()) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3937 return Api::NewError( 3948 return Api::NewError(
3938 "%s expects argument 'name' to be a valid constructor.", 3949 "%s expects argument 'name' to be a valid constructor.",
3939 CURRENT_FUNC); 3950 CURRENT_FUNC);
3940 } 3951 }
3941 3952
3942 3953
3943 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, 3954 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target,
3944 Dart_Handle name, 3955 Dart_Handle name,
3945 int number_of_arguments, 3956 int number_of_arguments,
3946 Dart_Handle* arguments) { 3957 Dart_Handle* arguments) {
3958 API_TIMELINE_DURATION;
3947 DARTSCOPE(Thread::Current()); 3959 DARTSCOPE(Thread::Current());
3948 CHECK_CALLBACK_STATE(T); 3960 CHECK_CALLBACK_STATE(T);
3949 3961
3950 const String& function_name = Api::UnwrapStringHandle(Z, name); 3962 const String& function_name = Api::UnwrapStringHandle(Z, name);
3951 if (function_name.IsNull()) { 3963 if (function_name.IsNull()) {
3952 RETURN_TYPE_ERROR(Z, name, String); 3964 RETURN_TYPE_ERROR(Z, name, String);
3953 } 3965 }
3954 if (number_of_arguments < 0) { 3966 if (number_of_arguments < 0) {
3955 return Api::NewError( 3967 return Api::NewError(
3956 "%s expects argument 'number_of_arguments' to be non-negative.", 3968 "%s expects argument 'number_of_arguments' to be non-negative.",
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
4063 return Api::NewError( 4075 return Api::NewError(
4064 "%s expects argument 'target' to be an object, type, or library.", 4076 "%s expects argument 'target' to be an object, type, or library.",
4065 CURRENT_FUNC); 4077 CURRENT_FUNC);
4066 } 4078 }
4067 } 4079 }
4068 4080
4069 4081
4070 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, 4082 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure,
4071 int number_of_arguments, 4083 int number_of_arguments,
4072 Dart_Handle* arguments) { 4084 Dart_Handle* arguments) {
4085 API_TIMELINE_DURATION;
4073 DARTSCOPE(Thread::Current()); 4086 DARTSCOPE(Thread::Current());
4074 CHECK_CALLBACK_STATE(T); 4087 CHECK_CALLBACK_STATE(T);
4075 const Instance& closure_obj = Api::UnwrapInstanceHandle(Z, closure); 4088 const Instance& closure_obj = Api::UnwrapInstanceHandle(Z, closure);
4076 if (closure_obj.IsNull() || !closure_obj.IsCallable(NULL)) { 4089 if (closure_obj.IsNull() || !closure_obj.IsCallable(NULL)) {
4077 RETURN_TYPE_ERROR(Z, closure, Instance); 4090 RETURN_TYPE_ERROR(Z, closure, Instance);
4078 } 4091 }
4079 if (number_of_arguments < 0) { 4092 if (number_of_arguments < 0) {
4080 return Api::NewError( 4093 return Api::NewError(
4081 "%s expects argument 'number_of_arguments' to be non-negative.", 4094 "%s expects argument 'number_of_arguments' to be non-negative.",
4082 CURRENT_FUNC); 4095 CURRENT_FUNC);
4083 } 4096 }
4084 4097
4085 // Set up arguments to include the closure as the first argument. 4098 // Set up arguments to include the closure as the first argument.
4086 const Array& args = Array::Handle(Z, Array::New(number_of_arguments + 1)); 4099 const Array& args = Array::Handle(Z, Array::New(number_of_arguments + 1));
4087 Object& obj = Object::Handle(Z); 4100 Object& obj = Object::Handle(Z);
4088 args.SetAt(0, closure_obj); 4101 args.SetAt(0, closure_obj);
4089 for (int i = 0; i < number_of_arguments; i++) { 4102 for (int i = 0; i < number_of_arguments; i++) {
4090 obj = Api::UnwrapHandle(arguments[i]); 4103 obj = Api::UnwrapHandle(arguments[i]);
4091 if (!obj.IsNull() && !obj.IsInstance()) { 4104 if (!obj.IsNull() && !obj.IsInstance()) {
4092 RETURN_TYPE_ERROR(Z, arguments[i], Instance); 4105 RETURN_TYPE_ERROR(Z, arguments[i], Instance);
4093 } 4106 }
4094 args.SetAt(i + 1, obj); 4107 args.SetAt(i + 1, obj);
4095 } 4108 }
4096 // Now try to invoke the closure. 4109 // Now try to invoke the closure.
4097 return Api::NewHandle(T, DartEntry::InvokeClosure(args)); 4110 return Api::NewHandle(T, DartEntry::InvokeClosure(args));
4098 } 4111 }
4099 4112
4100 4113
4101 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { 4114 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) {
4115 API_TIMELINE_DURATION;
4102 DARTSCOPE(Thread::Current()); 4116 DARTSCOPE(Thread::Current());
4103 CHECK_CALLBACK_STATE(T); 4117 CHECK_CALLBACK_STATE(T);
4104 4118
4105 const String& field_name = Api::UnwrapStringHandle(Z, name); 4119 const String& field_name = Api::UnwrapStringHandle(Z, name);
4106 if (field_name.IsNull()) { 4120 if (field_name.IsNull()) {
4107 RETURN_TYPE_ERROR(Z, name, String); 4121 RETURN_TYPE_ERROR(Z, name, String);
4108 } 4122 }
4109 4123
4110 Field& field = Field::Handle(Z); 4124 Field& field = Field::Handle(Z);
4111 Function& getter = Function::Handle(Z); 4125 Function& getter = Function::Handle(Z);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
4212 return Api::NewError( 4226 return Api::NewError(
4213 "%s expects argument 'container' to be an object, type, or library.", 4227 "%s expects argument 'container' to be an object, type, or library.",
4214 CURRENT_FUNC); 4228 CURRENT_FUNC);
4215 } 4229 }
4216 } 4230 }
4217 4231
4218 4232
4219 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, 4233 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container,
4220 Dart_Handle name, 4234 Dart_Handle name,
4221 Dart_Handle value) { 4235 Dart_Handle value) {
4236 API_TIMELINE_DURATION;
4222 DARTSCOPE(Thread::Current()); 4237 DARTSCOPE(Thread::Current());
4223 CHECK_CALLBACK_STATE(T); 4238 CHECK_CALLBACK_STATE(T);
4224 4239
4225 const String& field_name = Api::UnwrapStringHandle(Z, name); 4240 const String& field_name = Api::UnwrapStringHandle(Z, name);
4226 if (field_name.IsNull()) { 4241 if (field_name.IsNull()) {
4227 RETURN_TYPE_ERROR(Z, name, String); 4242 RETURN_TYPE_ERROR(Z, name, String);
4228 } 4243 }
4229 4244
4230 // Since null is allowed for value, we don't use UnwrapInstanceHandle. 4245 // Since null is allowed for value, we don't use UnwrapInstanceHandle.
4231 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); 4246 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value));
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
4663 return Api::NewError("%s: invalid argument type %d.", 4678 return Api::NewError("%s: invalid argument type %d.",
4664 CURRENT_FUNC, arg_type); 4679 CURRENT_FUNC, arg_type);
4665 } 4680 }
4666 } 4681 }
4667 return Api::Success(); 4682 return Api::Success();
4668 } 4683 }
4669 4684
4670 4685
4671 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, 4686 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args,
4672 int index) { 4687 int index) {
4673 TRACE_API_CALL(CURRENT_FUNC); 4688 API_TIMELINE_DURATION;
4674 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 4689 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4675 if ((index < 0) || (index >= arguments->NativeArgCount())) { 4690 if ((index < 0) || (index >= arguments->NativeArgCount())) {
4676 return Api::NewError( 4691 return Api::NewError(
4677 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", 4692 "%s: argument 'index' out of range. Expected 0..%d but saw %d.",
4678 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); 4693 CURRENT_FUNC, arguments->NativeArgCount() - 1, index);
4679 } 4694 }
4680 return Api::NewHandle(arguments->thread(), 4695 return Api::NewHandle(arguments->thread(),
4681 arguments->NativeArgAt(index)); 4696 arguments->NativeArgAt(index));
4682 } 4697 }
4683 4698
4684 4699
4685 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { 4700 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) {
4686 TRACE_API_CALL(CURRENT_FUNC); 4701 API_TIMELINE_DURATION;
4687 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 4702 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4688 return arguments->NativeArgCount(); 4703 return arguments->NativeArgCount();
4689 } 4704 }
4690 4705
4691 4706
4692 DART_EXPORT Dart_Handle Dart_GetNativeFieldsOfArgument( 4707 DART_EXPORT Dart_Handle Dart_GetNativeFieldsOfArgument(
4693 Dart_NativeArguments args, 4708 Dart_NativeArguments args,
4694 int arg_index, 4709 int arg_index,
4695 int num_fields, 4710 int num_fields,
4696 intptr_t* field_values) { 4711 intptr_t* field_values) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
4735 return Api::NewError("%s expects argument at %d to be of" 4750 return Api::NewError("%s expects argument at %d to be of"
4736 " type String.", CURRENT_FUNC, arg_index); 4751 " type String.", CURRENT_FUNC, arg_index);
4737 } 4752 }
4738 return result; 4753 return result;
4739 } 4754 }
4740 4755
4741 4756
4742 DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, 4757 DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args,
4743 int index, 4758 int index,
4744 int64_t* value) { 4759 int64_t* value) {
4745 TRACE_API_CALL(CURRENT_FUNC); 4760 API_TIMELINE_DURATION;
4746 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 4761 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4747 if ((index < 0) || (index >= arguments->NativeArgCount())) { 4762 if ((index < 0) || (index >= arguments->NativeArgCount())) {
4748 return Api::NewError( 4763 return Api::NewError(
4749 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", 4764 "%s: argument 'index' out of range. Expected 0..%d but saw %d.",
4750 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); 4765 CURRENT_FUNC, arguments->NativeArgCount() - 1, index);
4751 } 4766 }
4752 if (!GetNativeIntegerArgument(arguments, index, value)) { 4767 if (!GetNativeIntegerArgument(arguments, index, value)) {
4753 return Api::NewError("%s: expects argument at %d to be of" 4768 return Api::NewError("%s: expects argument at %d to be of"
4754 " type Integer.", CURRENT_FUNC, index); 4769 " type Integer.", CURRENT_FUNC, index);
4755 } 4770 }
4756 return Api::Success(); 4771 return Api::Success();
4757 } 4772 }
4758 4773
4759 4774
4760 DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, 4775 DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args,
4761 int index, 4776 int index,
4762 bool* value) { 4777 bool* value) {
4763 TRACE_API_CALL(CURRENT_FUNC); 4778 API_TIMELINE_DURATION;
4764 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 4779 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4765 if ((index < 0) || (index >= arguments->NativeArgCount())) { 4780 if ((index < 0) || (index >= arguments->NativeArgCount())) {
4766 return Api::NewError( 4781 return Api::NewError(
4767 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", 4782 "%s: argument 'index' out of range. Expected 0..%d but saw %d.",
4768 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); 4783 CURRENT_FUNC, arguments->NativeArgCount() - 1, index);
4769 } 4784 }
4770 if (!Api::GetNativeBooleanArgument(arguments, index, value)) { 4785 if (!Api::GetNativeBooleanArgument(arguments, index, value)) {
4771 return Api::NewError("%s: expects argument at %d to be of type Boolean.", 4786 return Api::NewError("%s: expects argument at %d to be of type Boolean.",
4772 CURRENT_FUNC, index); 4787 CURRENT_FUNC, index);
4773 } 4788 }
4774 return Api::Success(); 4789 return Api::Success();
4775 } 4790 }
4776 4791
4777 4792
4778 DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args, 4793 DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args,
4779 int index, 4794 int index,
4780 double* value) { 4795 double* value) {
4781 TRACE_API_CALL(CURRENT_FUNC); 4796 API_TIMELINE_DURATION;
4782 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 4797 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4783 if ((index < 0) || (index >= arguments->NativeArgCount())) { 4798 if ((index < 0) || (index >= arguments->NativeArgCount())) {
4784 return Api::NewError( 4799 return Api::NewError(
4785 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", 4800 "%s: argument 'index' out of range. Expected 0..%d but saw %d.",
4786 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); 4801 CURRENT_FUNC, arguments->NativeArgCount() - 1, index);
4787 } 4802 }
4788 if (!GetNativeDoubleArgument(arguments, index, value)) { 4803 if (!GetNativeDoubleArgument(arguments, index, value)) {
4789 return Api::NewError("%s: expects argument at %d to be of" 4804 return Api::NewError("%s: expects argument at %d to be of"
4790 " type Double.", CURRENT_FUNC, index); 4805 " type Double.", CURRENT_FUNC, index);
4791 } 4806 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
4859 Isolate* isolate = Isolate::Current(); 4874 Isolate* isolate = Isolate::Current();
4860 CHECK_ISOLATE(isolate); 4875 CHECK_ISOLATE(isolate);
4861 isolate->set_environment_callback(callback); 4876 isolate->set_environment_callback(callback);
4862 return Api::Success(); 4877 return Api::Success();
4863 } 4878 }
4864 4879
4865 4880
4866 // --- Scripts and Libraries --- 4881 // --- Scripts and Libraries ---
4867 DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, 4882 DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args,
4868 bool retval) { 4883 bool retval) {
4869 TRACE_API_CALL(CURRENT_FUNC); 4884 API_TIMELINE_DURATION;
4870 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 4885 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4871 arguments->SetReturn(Bool::Get(retval)); 4886 arguments->SetReturn(Bool::Get(retval));
4872 } 4887 }
4873 4888
4874 4889
4875 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, 4890 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args,
4876 int64_t retval) { 4891 int64_t retval) {
4877 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 4892 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4878 ASSERT(arguments->thread()->isolate() == Isolate::Current()); 4893 ASSERT(arguments->thread()->isolate() == Isolate::Current());
4879 if (Smi::IsValid(retval)) { 4894 if (Smi::IsValid(retval)) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
4928 // as having failed to load without providing an error instance. 4943 // as having failed to load without providing an error instance.
4929 lib.SetLoadError(Object::null_instance()); 4944 lib.SetLoadError(Object::null_instance());
4930 } 4945 }
4931 } 4946 }
4932 4947
4933 4948
4934 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, 4949 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
4935 Dart_Handle source, 4950 Dart_Handle source,
4936 intptr_t line_offset, 4951 intptr_t line_offset,
4937 intptr_t column_offset) { 4952 intptr_t column_offset) {
4953 API_TIMELINE_DURATION;
4938 DARTSCOPE(Thread::Current()); 4954 DARTSCOPE(Thread::Current());
4939 Isolate* I = T->isolate(); 4955 Isolate* I = T->isolate();
4940 const String& url_str = Api::UnwrapStringHandle(Z, url); 4956 const String& url_str = Api::UnwrapStringHandle(Z, url);
4941 if (url_str.IsNull()) { 4957 if (url_str.IsNull()) {
4942 RETURN_TYPE_ERROR(Z, url, String); 4958 RETURN_TYPE_ERROR(Z, url, String);
4943 } 4959 }
4944 const String& source_str = Api::UnwrapStringHandle(Z, source); 4960 const String& source_str = Api::UnwrapStringHandle(Z, source);
4945 if (source_str.IsNull()) { 4961 if (source_str.IsNull()) {
4946 RETURN_TYPE_ERROR(Z, source, String); 4962 RETURN_TYPE_ERROR(Z, source, String);
4947 } 4963 }
(...skipping 25 matching lines...) Expand all
4973 Script::New(url_str, source_str, RawScript::kScriptTag)); 4989 Script::New(url_str, source_str, RawScript::kScriptTag));
4974 script.SetLocationOffset(line_offset, column_offset); 4990 script.SetLocationOffset(line_offset, column_offset);
4975 Dart_Handle result; 4991 Dart_Handle result;
4976 CompileSource(T, library, script, &result); 4992 CompileSource(T, library, script, &result);
4977 return result; 4993 return result;
4978 } 4994 }
4979 4995
4980 4996
4981 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, 4997 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer,
4982 intptr_t buffer_len) { 4998 intptr_t buffer_len) {
4999 API_TIMELINE_DURATION;
4983 DARTSCOPE(Thread::Current()); 5000 DARTSCOPE(Thread::Current());
4984 Isolate* I = T->isolate(); 5001 Isolate* I = T->isolate();
4985 StackZone zone(T); 5002 StackZone zone(T);
4986 if (buffer == NULL) { 5003 if (buffer == NULL) {
4987 RETURN_NULL_ERROR(buffer); 5004 RETURN_NULL_ERROR(buffer);
4988 } 5005 }
4989 NoHeapGrowthControlScope no_growth_control; 5006 NoHeapGrowthControlScope no_growth_control;
4990 5007
4991 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); 5008 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
4992 if (!snapshot->IsScriptSnapshot()) { 5009 if (!snapshot->IsScriptSnapshot()) {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
5188 } 5205 }
5189 } 5206 }
5190 return error_in; 5207 return error_in;
5191 } 5208 }
5192 5209
5193 5210
5194 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, 5211 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url,
5195 Dart_Handle source, 5212 Dart_Handle source,
5196 intptr_t line_offset, 5213 intptr_t line_offset,
5197 intptr_t column_offset) { 5214 intptr_t column_offset) {
5215 API_TIMELINE_DURATION;
5198 DARTSCOPE(Thread::Current()); 5216 DARTSCOPE(Thread::Current());
5199 Isolate* I = T->isolate(); 5217 Isolate* I = T->isolate();
5200 const String& url_str = Api::UnwrapStringHandle(Z, url); 5218 const String& url_str = Api::UnwrapStringHandle(Z, url);
5201 if (url_str.IsNull()) { 5219 if (url_str.IsNull()) {
5202 RETURN_TYPE_ERROR(Z, url, String); 5220 RETURN_TYPE_ERROR(Z, url, String);
5203 } 5221 }
5204 const String& source_str = Api::UnwrapStringHandle(Z, source); 5222 const String& source_str = Api::UnwrapStringHandle(Z, source);
5205 if (source_str.IsNull()) { 5223 if (source_str.IsNull()) {
5206 RETURN_TYPE_ERROR(Z, source, String); 5224 RETURN_TYPE_ERROR(Z, source, String);
5207 } 5225 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
5293 } 5311 }
5294 return Api::Success(); 5312 return Api::Success();
5295 } 5313 }
5296 5314
5297 5315
5298 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, 5316 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library,
5299 Dart_Handle url, 5317 Dart_Handle url,
5300 Dart_Handle source, 5318 Dart_Handle source,
5301 intptr_t line_offset, 5319 intptr_t line_offset,
5302 intptr_t column_offset) { 5320 intptr_t column_offset) {
5321 API_TIMELINE_DURATION;
5303 DARTSCOPE(Thread::Current()); 5322 DARTSCOPE(Thread::Current());
5304 Isolate* I = T->isolate(); 5323 Isolate* I = T->isolate();
5305 const Library& lib = Api::UnwrapLibraryHandle(Z, library); 5324 const Library& lib = Api::UnwrapLibraryHandle(Z, library);
5306 if (lib.IsNull()) { 5325 if (lib.IsNull()) {
5307 RETURN_TYPE_ERROR(Z, library, Library); 5326 RETURN_TYPE_ERROR(Z, library, Library);
5308 } 5327 }
5309 const String& url_str = Api::UnwrapStringHandle(Z, url); 5328 const String& url_str = Api::UnwrapStringHandle(Z, url);
5310 if (url_str.IsNull()) { 5329 if (url_str.IsNull()) {
5311 RETURN_TYPE_ERROR(Z, url, String); 5330 RETURN_TYPE_ERROR(Z, url, String);
5312 } 5331 }
(...skipping 19 matching lines...) Expand all
5332 script.SetLocationOffset(line_offset, column_offset); 5351 script.SetLocationOffset(line_offset, column_offset);
5333 Dart_Handle result; 5352 Dart_Handle result;
5334 CompileSource(T, lib, script, &result); 5353 CompileSource(T, lib, script, &result);
5335 return result; 5354 return result;
5336 } 5355 }
5337 5356
5338 5357
5339 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, 5358 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library,
5340 Dart_Handle url, 5359 Dart_Handle url,
5341 Dart_Handle patch_source) { 5360 Dart_Handle patch_source) {
5361 API_TIMELINE_DURATION;
5342 DARTSCOPE(Thread::Current()); 5362 DARTSCOPE(Thread::Current());
5343 Isolate* I = T->isolate(); 5363 Isolate* I = T->isolate();
5344 const Library& lib = Api::UnwrapLibraryHandle(Z, library); 5364 const Library& lib = Api::UnwrapLibraryHandle(Z, library);
5345 if (lib.IsNull()) { 5365 if (lib.IsNull()) {
5346 RETURN_TYPE_ERROR(Z, library, Library); 5366 RETURN_TYPE_ERROR(Z, library, Library);
5347 } 5367 }
5348 const String& url_str = Api::UnwrapStringHandle(Z, url); 5368 const String& url_str = Api::UnwrapStringHandle(Z, url);
5349 if (url_str.IsNull()) { 5369 if (url_str.IsNull()) {
5350 RETURN_TYPE_ERROR(Z, url, String); 5370 RETURN_TYPE_ERROR(Z, url, String);
5351 } 5371 }
(...skipping 10 matching lines...) Expand all
5362 Script::New(url_str, source_str, RawScript::kPatchTag)); 5382 Script::New(url_str, source_str, RawScript::kPatchTag));
5363 Dart_Handle result; 5383 Dart_Handle result;
5364 CompileSource(T, lib, script, &result); 5384 CompileSource(T, lib, script, &result);
5365 return result; 5385 return result;
5366 } 5386 }
5367 5387
5368 5388
5369 // Finalizes classes and invokes Dart core library function that completes 5389 // Finalizes classes and invokes Dart core library function that completes
5370 // futures of loadLibrary calls (deferred library loading). 5390 // futures of loadLibrary calls (deferred library loading).
5371 DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures) { 5391 DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures) {
5392 API_TIMELINE_DURATION;
5372 DARTSCOPE(Thread::Current()); 5393 DARTSCOPE(Thread::Current());
5373 Isolate* I = T->isolate(); 5394 Isolate* I = T->isolate();
5374 CHECK_CALLBACK_STATE(T); 5395 CHECK_CALLBACK_STATE(T);
5375 5396
5376 I->DoneLoading(); 5397 I->DoneLoading();
5377 5398
5378 // TODO(hausner): move the remaining code below (finalization and 5399 // TODO(hausner): move the remaining code below (finalization and
5379 // invoing of _completeDeferredLoads) into Isolate::DoneLoading(). 5400 // invoing of _completeDeferredLoads) into Isolate::DoneLoading().
5380 5401
5381 // Finalize all classes if needed. 5402 // Finalize all classes if needed.
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
5867 event->AsyncEnd(label, async_id); 5888 event->AsyncEnd(label, async_id);
5868 event->Complete(); 5889 event->Complete();
5869 } 5890 }
5870 return Api::Success(); 5891 return Api::Success();
5871 } 5892 }
5872 5893
5873 5894
5874 DART_EXPORT Dart_Handle Dart_Precompile( 5895 DART_EXPORT Dart_Handle Dart_Precompile(
5875 Dart_QualifiedFunctionName entry_points[], 5896 Dart_QualifiedFunctionName entry_points[],
5876 bool reset_fields) { 5897 bool reset_fields) {
5898 API_TIMELINE_BEGIN_END;
5877 DARTSCOPE(Thread::Current()); 5899 DARTSCOPE(Thread::Current());
5878 if (!FLAG_precompilation) { 5900 if (!FLAG_precompilation) {
5879 return Dart_NewApiError("Flag --precompilation was not specified."); 5901 return Dart_NewApiError("Flag --precompilation was not specified.");
5880 } 5902 }
5881 Dart_Handle result = Api::CheckAndFinalizePendingClasses(T); 5903 Dart_Handle result = Api::CheckAndFinalizePendingClasses(T);
5882 if (::Dart_IsError(result)) { 5904 if (::Dart_IsError(result)) {
5883 return result; 5905 return result;
5884 } 5906 }
5885 CHECK_CALLBACK_STATE(T); 5907 CHECK_CALLBACK_STATE(T);
5886 const Error& error = Error::Handle(Precompiler::CompileAll(entry_points, 5908 const Error& error = Error::Handle(Precompiler::CompileAll(entry_points,
5887 reset_fields)); 5909 reset_fields));
5888 if (!error.IsNull()) { 5910 if (!error.IsNull()) {
5889 return Api::NewHandle(T, error.raw()); 5911 return Api::NewHandle(T, error.raw());
5890 } 5912 }
5891 return Api::Success(); 5913 return Api::Success();
5892 } 5914 }
5893 5915
5894 5916
5895 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshot( 5917 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshot(
5896 uint8_t** vm_isolate_snapshot_buffer, 5918 uint8_t** vm_isolate_snapshot_buffer,
5897 intptr_t* vm_isolate_snapshot_size, 5919 intptr_t* vm_isolate_snapshot_size,
5898 uint8_t** isolate_snapshot_buffer, 5920 uint8_t** isolate_snapshot_buffer,
5899 intptr_t* isolate_snapshot_size, 5921 intptr_t* isolate_snapshot_size,
5900 uint8_t** instructions_snapshot_buffer, 5922 uint8_t** instructions_snapshot_buffer,
5901 intptr_t* instructions_snapshot_size) { 5923 intptr_t* instructions_snapshot_size) {
5902 ASSERT(FLAG_load_deferred_eagerly); 5924 ASSERT(FLAG_load_deferred_eagerly);
5925 API_TIMELINE_DURATION;
5903 DARTSCOPE(Thread::Current()); 5926 DARTSCOPE(Thread::Current());
5904 Isolate* I = T->isolate(); 5927 Isolate* I = T->isolate();
5905 if (I->compilation_allowed()) { 5928 if (I->compilation_allowed()) {
5906 return Dart_NewApiError("Isolate is not precompiled. " 5929 return Dart_NewApiError("Isolate is not precompiled. "
5907 "Did you forget to call Dart_Precompile?"); 5930 "Did you forget to call Dart_Precompile?");
5908 } 5931 }
5909 if (vm_isolate_snapshot_buffer == NULL) { 5932 if (vm_isolate_snapshot_buffer == NULL) {
5910 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); 5933 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer);
5911 } 5934 }
5912 if (vm_isolate_snapshot_size == NULL) { 5935 if (vm_isolate_snapshot_size == NULL) {
(...skipping 23 matching lines...) Expand all
5936 ApiReallocate); 5959 ApiReallocate);
5937 writer.WriteFullSnapshot(); 5960 writer.WriteFullSnapshot();
5938 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); 5961 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize();
5939 *isolate_snapshot_size = writer.IsolateSnapshotSize(); 5962 *isolate_snapshot_size = writer.IsolateSnapshotSize();
5940 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); 5963 *instructions_snapshot_size = writer.InstructionsSnapshotSize();
5941 5964
5942 return Api::Success(); 5965 return Api::Success();
5943 } 5966 }
5944 5967
5945 } // namespace dart 5968 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/timeline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698