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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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); | 711 API_TIMELINE_DURATION; |
rmacnak
2015/12/15 17:42:04
For all the Dart_IsX, I don't think it makes sense
Cutch
2015/12/15 18:06:40
Done here and elsewhere.
| |
705 return RawObject::IsErrorClassId(Api::ClassId(handle)); | 712 return RawObject::IsErrorClassId(Api::ClassId(handle)); |
706 } | 713 } |
707 | 714 |
708 | 715 |
709 DART_EXPORT bool Dart_IsApiError(Dart_Handle object) { | 716 DART_EXPORT bool Dart_IsApiError(Dart_Handle object) { |
710 TRACE_API_CALL(CURRENT_FUNC); | 717 API_TIMELINE_DURATION; |
711 return Api::ClassId(object) == kApiErrorCid; | 718 return Api::ClassId(object) == kApiErrorCid; |
712 } | 719 } |
713 | 720 |
714 | 721 |
715 DART_EXPORT bool Dart_IsUnhandledExceptionError(Dart_Handle object) { | 722 DART_EXPORT bool Dart_IsUnhandledExceptionError(Dart_Handle object) { |
716 TRACE_API_CALL(CURRENT_FUNC); | 723 API_TIMELINE_DURATION; |
717 return Api::ClassId(object) == kUnhandledExceptionCid; | 724 return Api::ClassId(object) == kUnhandledExceptionCid; |
718 } | 725 } |
719 | 726 |
720 | 727 |
721 DART_EXPORT bool Dart_IsCompilationError(Dart_Handle object) { | 728 DART_EXPORT bool Dart_IsCompilationError(Dart_Handle object) { |
722 TRACE_API_CALL(CURRENT_FUNC); | 729 API_TIMELINE_DURATION; |
723 return Api::ClassId(object) == kLanguageErrorCid; | 730 return Api::ClassId(object) == kLanguageErrorCid; |
724 } | 731 } |
725 | 732 |
726 | 733 |
727 DART_EXPORT bool Dart_IsFatalError(Dart_Handle object) { | 734 DART_EXPORT bool Dart_IsFatalError(Dart_Handle object) { |
728 TRACE_API_CALL(CURRENT_FUNC); | 735 API_TIMELINE_DURATION; |
729 return Api::ClassId(object) == kUnwindErrorCid; | 736 return Api::ClassId(object) == kUnwindErrorCid; |
730 } | 737 } |
731 | 738 |
732 | 739 |
733 DART_EXPORT bool Dart_IsVMRestartRequest(Dart_Handle handle) { | 740 DART_EXPORT bool Dart_IsVMRestartRequest(Dart_Handle handle) { |
741 API_TIMELINE_DURATION; | |
734 DARTSCOPE(Thread::Current()); | 742 DARTSCOPE(Thread::Current()); |
735 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); | 743 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
736 return (obj.IsUnwindError() && UnwindError::Cast(obj).is_vm_restart()); | 744 return (obj.IsUnwindError() && UnwindError::Cast(obj).is_vm_restart()); |
737 } | 745 } |
738 | 746 |
739 | 747 |
740 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { | 748 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { |
749 API_TIMELINE_DURATION; | |
741 DARTSCOPE(Thread::Current()); | 750 DARTSCOPE(Thread::Current()); |
742 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); | 751 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
743 if (obj.IsError()) { | 752 if (obj.IsError()) { |
744 const Error& error = Error::Cast(obj); | 753 const Error& error = Error::Cast(obj); |
745 const char* str = error.ToErrorCString(); | 754 const char* str = error.ToErrorCString(); |
746 intptr_t len = strlen(str) + 1; | 755 intptr_t len = strlen(str) + 1; |
747 char* str_copy = Api::TopScope(T)->zone()->Alloc<char>(len); | 756 char* str_copy = Api::TopScope(T)->zone()->Alloc<char>(len); |
748 strncpy(str_copy, str, len); | 757 strncpy(str_copy, str, len); |
749 // Strip a possible trailing '\n'. | 758 // Strip a possible trailing '\n'. |
750 if ((len > 1) && (str_copy[len - 2] == '\n')) { | 759 if ((len > 1) && (str_copy[len - 2] == '\n')) { |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1273 | 1282 |
1274 | 1283 |
1275 DART_EXPORT void* Dart_CurrentIsolateData() { | 1284 DART_EXPORT void* Dart_CurrentIsolateData() { |
1276 Isolate* isolate = Isolate::Current(); | 1285 Isolate* isolate = Isolate::Current(); |
1277 CHECK_ISOLATE(isolate); | 1286 CHECK_ISOLATE(isolate); |
1278 return isolate->init_callback_data(); | 1287 return isolate->init_callback_data(); |
1279 } | 1288 } |
1280 | 1289 |
1281 | 1290 |
1282 DART_EXPORT void* Dart_IsolateData(Dart_Isolate isolate) { | 1291 DART_EXPORT void* Dart_IsolateData(Dart_Isolate isolate) { |
1283 TRACE_API_CALL(CURRENT_FUNC); | 1292 API_TIMELINE_DURATION; |
rmacnak
2015/12/15 17:42:04
Too small.
Cutch
2015/12/15 18:06:40
Done.
| |
1284 if (isolate == NULL) { | 1293 if (isolate == NULL) { |
1285 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 1294 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
1286 } | 1295 } |
1287 // TODO(16615): Validate isolate parameter. | 1296 // TODO(16615): Validate isolate parameter. |
1288 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1297 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
1289 return iso->init_callback_data(); | 1298 return iso->init_callback_data(); |
1290 } | 1299 } |
1291 | 1300 |
1292 | 1301 |
1293 DART_EXPORT Dart_Handle Dart_DebugName() { | 1302 DART_EXPORT Dart_Handle Dart_DebugName() { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1442 | 1451 |
1443 | 1452 |
1444 DART_EXPORT Dart_Handle Dart_CreateLibrarySnapshot(Dart_Handle library, | 1453 DART_EXPORT Dart_Handle Dart_CreateLibrarySnapshot(Dart_Handle library, |
1445 uint8_t** buffer, | 1454 uint8_t** buffer, |
1446 intptr_t* size) { | 1455 intptr_t* size) { |
1447 return createLibrarySnapshot(library, buffer, size); | 1456 return createLibrarySnapshot(library, buffer, size); |
1448 } | 1457 } |
1449 | 1458 |
1450 | 1459 |
1451 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { | 1460 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { |
1452 TRACE_API_CALL(CURRENT_FUNC); | 1461 API_TIMELINE_DURATION; |
1453 if (isolate == NULL) { | 1462 if (isolate == NULL) { |
1454 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 1463 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
1455 } | 1464 } |
1456 // TODO(16615): Validate isolate parameter. | 1465 // TODO(16615): Validate isolate parameter. |
1457 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1466 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
1458 iso->SendInternalLibMessage(Isolate::kInterruptMsg, iso->pause_capability()); | 1467 iso->SendInternalLibMessage(Isolate::kInterruptMsg, iso->pause_capability()); |
1459 } | 1468 } |
1460 | 1469 |
1461 | 1470 |
1462 DART_EXPORT bool Dart_IsolateMakeRunnable(Dart_Isolate isolate) { | 1471 DART_EXPORT bool Dart_IsolateMakeRunnable(Dart_Isolate isolate) { |
1463 CHECK_NO_ISOLATE(Isolate::Current()); | 1472 CHECK_NO_ISOLATE(Isolate::Current()); |
1473 API_TIMELINE_DURATION; | |
1464 if (isolate == NULL) { | 1474 if (isolate == NULL) { |
1465 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 1475 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
1466 } | 1476 } |
1467 // TODO(16615): Validate isolate parameter. | 1477 // TODO(16615): Validate isolate parameter. |
1468 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1478 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
1469 if (iso->object_store()->root_library() == Library::null()) { | 1479 if (iso->object_store()->root_library() == Library::null()) { |
1470 // The embedder should have called Dart_LoadScript by now. | 1480 // The embedder should have called Dart_LoadScript by now. |
1471 return false; | 1481 return false; |
1472 } | 1482 } |
1473 return iso->MakeRunnable(); | 1483 return iso->MakeRunnable(); |
(...skipping 23 matching lines...) Expand all Loading... | |
1497 data->done = true; | 1507 data->done = true; |
1498 ml.Notify(); | 1508 ml.Notify(); |
1499 } | 1509 } |
1500 | 1510 |
1501 | 1511 |
1502 DART_EXPORT Dart_Handle Dart_RunLoop() { | 1512 DART_EXPORT Dart_Handle Dart_RunLoop() { |
1503 Thread* T = Thread::Current(); | 1513 Thread* T = Thread::Current(); |
1504 Isolate* I = T->isolate(); | 1514 Isolate* I = T->isolate(); |
1505 CHECK_API_SCOPE(T); | 1515 CHECK_API_SCOPE(T); |
1506 CHECK_CALLBACK_STATE(T); | 1516 CHECK_CALLBACK_STATE(T); |
1517 API_TIMELINE_BEGIN_END; | |
1507 Monitor monitor; | 1518 Monitor monitor; |
1508 MonitorLocker ml(&monitor); | 1519 MonitorLocker ml(&monitor); |
1509 { | 1520 { |
1510 // The message handler run loop does not expect to have a current isolate | 1521 // 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. | 1522 // so we exit the isolate here and enter it again after the runloop is done. |
1512 Thread::ExitIsolate(); | 1523 Thread::ExitIsolate(); |
1513 RunLoopData data; | 1524 RunLoopData data; |
1514 data.monitor = &monitor; | 1525 data.monitor = &monitor; |
1515 data.done = false; | 1526 data.done = false; |
1516 I->message_handler()->Run( | 1527 I->message_handler()->Run( |
(...skipping 15 matching lines...) Expand all Loading... | |
1532 } | 1543 } |
1533 return Api::Success(); | 1544 return Api::Success(); |
1534 } | 1545 } |
1535 | 1546 |
1536 | 1547 |
1537 DART_EXPORT Dart_Handle Dart_HandleMessage() { | 1548 DART_EXPORT Dart_Handle Dart_HandleMessage() { |
1538 Thread* T = Thread::Current(); | 1549 Thread* T = Thread::Current(); |
1539 Isolate* I = T->isolate(); | 1550 Isolate* I = T->isolate(); |
1540 CHECK_API_SCOPE(T); | 1551 CHECK_API_SCOPE(T); |
1541 CHECK_CALLBACK_STATE(T); | 1552 CHECK_CALLBACK_STATE(T); |
1553 API_TIMELINE_BEGIN_END; | |
1542 if (I->message_handler()->HandleNextMessage() != MessageHandler::kOK) { | 1554 if (I->message_handler()->HandleNextMessage() != MessageHandler::kOK) { |
1543 Dart_Handle error = Api::NewHandle(T, I->object_store()->sticky_error()); | 1555 Dart_Handle error = Api::NewHandle(T, I->object_store()->sticky_error()); |
1544 I->object_store()->clear_sticky_error(); | 1556 I->object_store()->clear_sticky_error(); |
1545 return error; | 1557 return error; |
1546 } | 1558 } |
1547 return Api::Success(); | 1559 return Api::Success(); |
1548 } | 1560 } |
1549 | 1561 |
1550 | 1562 |
1551 DART_EXPORT bool Dart_HandleServiceMessages() { | 1563 DART_EXPORT bool Dart_HandleServiceMessages() { |
1552 Thread* T = Thread::Current(); | 1564 Thread* T = Thread::Current(); |
1553 Isolate* I = T->isolate(); | 1565 Isolate* I = T->isolate(); |
1554 CHECK_API_SCOPE(T); | 1566 CHECK_API_SCOPE(T); |
1555 CHECK_CALLBACK_STATE(T); | 1567 CHECK_CALLBACK_STATE(T); |
1556 | 1568 API_TIMELINE_DURATION; |
1557 ASSERT(I->GetAndClearResumeRequest() == false); | 1569 ASSERT(I->GetAndClearResumeRequest() == false); |
1558 MessageHandler::MessageStatus status = | 1570 MessageHandler::MessageStatus status = |
1559 I->message_handler()->HandleOOBMessages(); | 1571 I->message_handler()->HandleOOBMessages(); |
1560 bool resume = I->GetAndClearResumeRequest(); | 1572 bool resume = I->GetAndClearResumeRequest(); |
1561 return (status != MessageHandler::kOK) || resume; | 1573 return (status != MessageHandler::kOK) || resume; |
1562 } | 1574 } |
1563 | 1575 |
1564 | 1576 |
1565 DART_EXPORT bool Dart_HasServiceMessages() { | 1577 DART_EXPORT bool Dart_HasServiceMessages() { |
1566 Isolate* isolate = Isolate::Current(); | 1578 Isolate* isolate = Isolate::Current(); |
(...skipping 10 matching lines...) Expand all Loading... | |
1577 | 1589 |
1578 | 1590 |
1579 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 1591 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); | 1592 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
1581 return reinterpret_cast<uint8_t*>(new_ptr); | 1593 return reinterpret_cast<uint8_t*>(new_ptr); |
1582 } | 1594 } |
1583 | 1595 |
1584 | 1596 |
1585 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { | 1597 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { |
1586 DARTSCOPE(Thread::Current()); | 1598 DARTSCOPE(Thread::Current()); |
1599 API_TIMELINE_DURATION; | |
1587 NoSafepointScope no_safepoint_scope; | 1600 NoSafepointScope no_safepoint_scope; |
1588 if (port_id == ILLEGAL_PORT) { | 1601 if (port_id == ILLEGAL_PORT) { |
1589 return false; | 1602 return false; |
1590 } | 1603 } |
1591 | 1604 |
1592 // Smis and null can be sent without serialization. | 1605 // Smis and null can be sent without serialization. |
1593 RawObject* raw_obj = Api::UnwrapHandle(handle); | 1606 RawObject* raw_obj = Api::UnwrapHandle(handle); |
1594 if (ApiObjectConverter::CanConvert(raw_obj)) { | 1607 if (ApiObjectConverter::CanConvert(raw_obj)) { |
1595 return PortMap::PostMessage(new Message( | 1608 return PortMap::PostMessage(new Message( |
1596 port_id, raw_obj, Message::kNormalPriority)); | 1609 port_id, raw_obj, Message::kNormalPriority)); |
(...skipping 18 matching lines...) Expand all Loading... | |
1615 port_id); | 1628 port_id); |
1616 } | 1629 } |
1617 return Api::NewHandle(T, SendPort::New(port_id)); | 1630 return Api::NewHandle(T, SendPort::New(port_id)); |
1618 } | 1631 } |
1619 | 1632 |
1620 | 1633 |
1621 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, | 1634 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, |
1622 Dart_Port* port_id) { | 1635 Dart_Port* port_id) { |
1623 DARTSCOPE(Thread::Current()); | 1636 DARTSCOPE(Thread::Current()); |
1624 CHECK_CALLBACK_STATE(T); | 1637 CHECK_CALLBACK_STATE(T); |
1638 API_TIMELINE_DURATION; | |
1625 const SendPort& send_port = Api::UnwrapSendPortHandle(Z, port); | 1639 const SendPort& send_port = Api::UnwrapSendPortHandle(Z, port); |
1626 if (send_port.IsNull()) { | 1640 if (send_port.IsNull()) { |
1627 RETURN_TYPE_ERROR(Z, port, SendPort); | 1641 RETURN_TYPE_ERROR(Z, port, SendPort); |
1628 } | 1642 } |
1629 if (port_id == NULL) { | 1643 if (port_id == NULL) { |
1630 RETURN_NULL_ERROR(port_id); | 1644 RETURN_NULL_ERROR(port_id); |
1631 } | 1645 } |
1632 *port_id = send_port.Id(); | 1646 *port_id = send_port.Id(); |
1633 return Api::Success(); | 1647 return Api::Success(); |
1634 } | 1648 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1774 Thread* thread = Thread::Current(); | 1788 Thread* thread = Thread::Current(); |
1775 CHECK_ISOLATE(thread->isolate()); | 1789 CHECK_ISOLATE(thread->isolate()); |
1776 REUSABLE_OBJECT_HANDLESCOPE(thread); | 1790 REUSABLE_OBJECT_HANDLESCOPE(thread); |
1777 Object& ref = thread->ObjectHandle(); | 1791 Object& ref = thread->ObjectHandle(); |
1778 ref = Api::UnwrapHandle(object); | 1792 ref = Api::UnwrapHandle(object); |
1779 return ref.IsInstance(); | 1793 return ref.IsInstance(); |
1780 } | 1794 } |
1781 | 1795 |
1782 | 1796 |
1783 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { | 1797 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { |
1784 TRACE_API_CALL(CURRENT_FUNC); | 1798 API_TIMELINE_DURATION; |
1785 return RawObject::IsNumberClassId(Api::ClassId(object)); | 1799 return RawObject::IsNumberClassId(Api::ClassId(object)); |
1786 } | 1800 } |
1787 | 1801 |
1788 | 1802 |
1789 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { | 1803 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { |
1790 TRACE_API_CALL(CURRENT_FUNC); | 1804 API_TIMELINE_DURATION; |
1791 return RawObject::IsIntegerClassId(Api::ClassId(object)); | 1805 return RawObject::IsIntegerClassId(Api::ClassId(object)); |
1792 } | 1806 } |
1793 | 1807 |
1794 | 1808 |
1795 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) { | 1809 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) { |
1796 TRACE_API_CALL(CURRENT_FUNC); | 1810 API_TIMELINE_DURATION; |
1797 return Api::ClassId(object) == kDoubleCid; | 1811 return Api::ClassId(object) == kDoubleCid; |
1798 } | 1812 } |
1799 | 1813 |
1800 | 1814 |
1801 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) { | 1815 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) { |
1802 TRACE_API_CALL(CURRENT_FUNC); | 1816 API_TIMELINE_DURATION; |
1803 return Api::ClassId(object) == kBoolCid; | 1817 return Api::ClassId(object) == kBoolCid; |
1804 } | 1818 } |
1805 | 1819 |
1806 | 1820 |
1807 DART_EXPORT bool Dart_IsString(Dart_Handle object) { | 1821 DART_EXPORT bool Dart_IsString(Dart_Handle object) { |
1808 TRACE_API_CALL(CURRENT_FUNC); | 1822 API_TIMELINE_DURATION; |
1809 return RawObject::IsStringClassId(Api::ClassId(object)); | 1823 return RawObject::IsStringClassId(Api::ClassId(object)); |
1810 } | 1824 } |
1811 | 1825 |
1812 | 1826 |
1813 DART_EXPORT bool Dart_IsStringLatin1(Dart_Handle object) { | 1827 DART_EXPORT bool Dart_IsStringLatin1(Dart_Handle object) { |
1814 TRACE_API_CALL(CURRENT_FUNC); | 1828 API_TIMELINE_DURATION; |
1815 return RawObject::IsOneByteStringClassId(Api::ClassId(object)); | 1829 return RawObject::IsOneByteStringClassId(Api::ClassId(object)); |
1816 } | 1830 } |
1817 | 1831 |
1818 | 1832 |
1819 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { | 1833 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { |
1820 TRACE_API_CALL(CURRENT_FUNC); | 1834 API_TIMELINE_DURATION; |
1821 return RawObject::IsExternalStringClassId(Api::ClassId(object)); | 1835 return RawObject::IsExternalStringClassId(Api::ClassId(object)); |
1822 } | 1836 } |
1823 | 1837 |
1824 | 1838 |
1825 DART_EXPORT bool Dart_IsList(Dart_Handle object) { | 1839 DART_EXPORT bool Dart_IsList(Dart_Handle object) { |
1840 API_TIMELINE_DURATION; | |
1826 if (RawObject::IsBuiltinListClassId(Api::ClassId(object))) { | 1841 if (RawObject::IsBuiltinListClassId(Api::ClassId(object))) { |
1827 TRACE_API_CALL(CURRENT_FUNC); | |
1828 return true; | 1842 return true; |
1829 } | 1843 } |
1830 | 1844 |
1831 DARTSCOPE(Thread::Current()); | 1845 DARTSCOPE(Thread::Current()); |
1832 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); | 1846 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); |
1833 return GetListInstance(Z, obj) != Instance::null(); | 1847 return GetListInstance(Z, obj) != Instance::null(); |
1834 } | 1848 } |
1835 | 1849 |
1836 | 1850 |
1837 DART_EXPORT bool Dart_IsMap(Dart_Handle object) { | 1851 DART_EXPORT bool Dart_IsMap(Dart_Handle object) { |
1838 DARTSCOPE(Thread::Current()); | 1852 DARTSCOPE(Thread::Current()); |
1839 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); | 1853 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); |
1840 return GetMapInstance(Z, obj) != Instance::null(); | 1854 return GetMapInstance(Z, obj) != Instance::null(); |
1841 } | 1855 } |
1842 | 1856 |
1843 | 1857 |
1844 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { | 1858 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { |
1845 TRACE_API_CALL(CURRENT_FUNC); | 1859 API_TIMELINE_DURATION; |
1846 return Api::ClassId(object) == kLibraryCid; | 1860 return Api::ClassId(object) == kLibraryCid; |
1847 } | 1861 } |
1848 | 1862 |
1849 | 1863 |
1850 DART_EXPORT bool Dart_IsType(Dart_Handle handle) { | 1864 DART_EXPORT bool Dart_IsType(Dart_Handle handle) { |
1851 TRACE_API_CALL(CURRENT_FUNC); | 1865 API_TIMELINE_DURATION; |
1852 return Api::ClassId(handle) == kTypeCid; | 1866 return Api::ClassId(handle) == kTypeCid; |
1853 } | 1867 } |
1854 | 1868 |
1855 | 1869 |
1856 DART_EXPORT bool Dart_IsFunction(Dart_Handle handle) { | 1870 DART_EXPORT bool Dart_IsFunction(Dart_Handle handle) { |
1857 TRACE_API_CALL(CURRENT_FUNC); | 1871 API_TIMELINE_DURATION; |
1858 return Api::ClassId(handle) == kFunctionCid; | 1872 return Api::ClassId(handle) == kFunctionCid; |
1859 } | 1873 } |
1860 | 1874 |
1861 | 1875 |
1862 DART_EXPORT bool Dart_IsVariable(Dart_Handle handle) { | 1876 DART_EXPORT bool Dart_IsVariable(Dart_Handle handle) { |
1863 TRACE_API_CALL(CURRENT_FUNC); | 1877 API_TIMELINE_DURATION; |
1864 return Api::ClassId(handle) == kFieldCid; | 1878 return Api::ClassId(handle) == kFieldCid; |
1865 } | 1879 } |
1866 | 1880 |
1867 | 1881 |
1868 DART_EXPORT bool Dart_IsTypeVariable(Dart_Handle handle) { | 1882 DART_EXPORT bool Dart_IsTypeVariable(Dart_Handle handle) { |
1869 TRACE_API_CALL(CURRENT_FUNC); | 1883 API_TIMELINE_DURATION; |
1870 return Api::ClassId(handle) == kTypeParameterCid; | 1884 return Api::ClassId(handle) == kTypeParameterCid; |
1871 } | 1885 } |
1872 | 1886 |
1873 | 1887 |
1874 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { | 1888 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { |
1875 // We can't use a fast class index check here because there are many | 1889 // We can't use a fast class index check here because there are many |
1876 // different signature classes for closures. | 1890 // different signature classes for closures. |
1877 Thread* thread = Thread::Current(); | 1891 Thread* thread = Thread::Current(); |
1878 CHECK_ISOLATE(thread->isolate()); | 1892 CHECK_ISOLATE(thread->isolate()); |
1893 API_TIMELINE_DURATION; | |
1879 ReusableObjectHandleScope reused_obj_handle(thread); | 1894 ReusableObjectHandleScope reused_obj_handle(thread); |
1880 const Instance& closure_obj = | 1895 const Instance& closure_obj = |
1881 Api::UnwrapInstanceHandle(reused_obj_handle, object); | 1896 Api::UnwrapInstanceHandle(reused_obj_handle, object); |
1882 return (!closure_obj.IsNull() && closure_obj.IsClosure()); | 1897 return (!closure_obj.IsNull() && closure_obj.IsClosure()); |
1883 } | 1898 } |
1884 | 1899 |
1885 | 1900 |
1886 DART_EXPORT bool Dart_IsTypedData(Dart_Handle handle) { | 1901 DART_EXPORT bool Dart_IsTypedData(Dart_Handle handle) { |
1887 TRACE_API_CALL(CURRENT_FUNC); | 1902 API_TIMELINE_DURATION; |
1888 intptr_t cid = Api::ClassId(handle); | 1903 intptr_t cid = Api::ClassId(handle); |
1889 return RawObject::IsTypedDataClassId(cid) || | 1904 return RawObject::IsTypedDataClassId(cid) || |
1890 RawObject::IsExternalTypedDataClassId(cid) || | 1905 RawObject::IsExternalTypedDataClassId(cid) || |
1891 RawObject::IsTypedDataViewClassId(cid); | 1906 RawObject::IsTypedDataViewClassId(cid); |
1892 } | 1907 } |
1893 | 1908 |
1894 | 1909 |
1895 DART_EXPORT bool Dart_IsByteBuffer(Dart_Handle handle) { | 1910 DART_EXPORT bool Dart_IsByteBuffer(Dart_Handle handle) { |
1896 TRACE_API_CALL(CURRENT_FUNC); | 1911 API_TIMELINE_DURATION; |
1897 return Api::ClassId(handle) == kByteBufferCid; | 1912 return Api::ClassId(handle) == kByteBufferCid; |
1898 } | 1913 } |
1899 | 1914 |
1900 | 1915 |
1901 DART_EXPORT bool Dart_IsFuture(Dart_Handle handle) { | 1916 DART_EXPORT bool Dart_IsFuture(Dart_Handle handle) { |
1902 TRACE_API_CALL(CURRENT_FUNC); | 1917 API_TIMELINE_DURATION; |
1903 DARTSCOPE(Thread::Current()); | 1918 DARTSCOPE(Thread::Current()); |
1904 Isolate* I = T->isolate(); | 1919 Isolate* I = T->isolate(); |
1905 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); | 1920 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
1906 if (obj.IsInstance()) { | 1921 if (obj.IsInstance()) { |
1907 const Class& future_class = | 1922 const Class& future_class = |
1908 Class::Handle(I->object_store()->future_class()); | 1923 Class::Handle(I->object_store()->future_class()); |
1909 ASSERT(!future_class.IsNull()); | 1924 ASSERT(!future_class.IsNull()); |
1910 const Class& obj_class = Class::Handle(Z, obj.clazz()); | 1925 const Class& obj_class = Class::Handle(Z, obj.clazz()); |
1911 Error& malformed_type_error = Error::Handle(Z); | 1926 Error& malformed_type_error = Error::Handle(Z); |
1912 bool is_future = obj_class.IsSubtypeOf(Object::null_type_arguments(), | 1927 bool is_future = obj_class.IsSubtypeOf(Object::null_type_arguments(), |
1913 future_class, | 1928 future_class, |
1914 Object::null_type_arguments(), | 1929 Object::null_type_arguments(), |
1915 &malformed_type_error); | 1930 &malformed_type_error); |
1916 ASSERT(malformed_type_error.IsNull()); // Type is a raw Future. | 1931 ASSERT(malformed_type_error.IsNull()); // Type is a raw Future. |
1917 return is_future; | 1932 return is_future; |
1918 } | 1933 } |
1919 return false; | 1934 return false; |
1920 } | 1935 } |
1921 | 1936 |
1922 | 1937 |
1923 // --- Instances ---- | 1938 // --- Instances ---- |
1924 | 1939 |
1925 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) { | 1940 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) { |
1941 API_TIMELINE_DURATION; | |
1926 DARTSCOPE(Thread::Current()); | 1942 DARTSCOPE(Thread::Current()); |
1927 Isolate* I = T->isolate(); | 1943 Isolate* I = T->isolate(); |
1928 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(instance)); | 1944 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(instance)); |
1929 if (obj.IsNull()) { | 1945 if (obj.IsNull()) { |
1930 return Api::NewHandle(T, I->object_store()->null_type()); | 1946 return Api::NewHandle(T, I->object_store()->null_type()); |
1931 } | 1947 } |
1932 if (!obj.IsInstance()) { | 1948 if (!obj.IsInstance()) { |
1933 RETURN_TYPE_ERROR(Z, instance, Instance); | 1949 RETURN_TYPE_ERROR(Z, instance, Instance); |
1934 } | 1950 } |
1935 const Type& type = Type::Handle(Instance::Cast(obj).GetType()); | 1951 const Type& type = Type::Handle(Instance::Cast(obj).GetType()); |
1936 return Api::NewHandle(T, type.Canonicalize()); | 1952 return Api::NewHandle(T, type.Canonicalize()); |
1937 } | 1953 } |
1938 | 1954 |
1939 | 1955 |
1940 // --- Numbers, Integers and Doubles ---- | 1956 // --- Numbers, Integers and Doubles ---- |
1941 | 1957 |
1942 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, | 1958 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, |
1943 bool* fits) { | 1959 bool* fits) { |
1960 API_TIMELINE_DURATION; | |
1944 // Fast path for Smis and Mints. | 1961 // Fast path for Smis and Mints. |
1945 Thread* thread = Thread::Current(); | 1962 Thread* thread = Thread::Current(); |
1946 Isolate* isolate = thread->isolate(); | 1963 Isolate* isolate = thread->isolate(); |
1947 CHECK_ISOLATE(isolate); | 1964 CHECK_ISOLATE(isolate); |
1948 intptr_t class_id = Api::ClassId(integer); | 1965 intptr_t class_id = Api::ClassId(integer); |
1949 if (class_id == kSmiCid || class_id == kMintCid) { | 1966 if (class_id == kSmiCid || class_id == kMintCid) { |
1950 *fits = true; | 1967 *fits = true; |
1951 return Api::Success(); | 1968 return Api::Success(); |
1952 } | 1969 } |
1953 // Slow path for Mints and Bigints. | 1970 // Slow path for Mints and Bigints. |
1954 DARTSCOPE(thread); | 1971 DARTSCOPE(thread); |
1955 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); | 1972 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); |
1956 if (int_obj.IsNull()) { | 1973 if (int_obj.IsNull()) { |
1957 RETURN_TYPE_ERROR(Z, integer, Integer); | 1974 RETURN_TYPE_ERROR(Z, integer, Integer); |
1958 } | 1975 } |
1959 ASSERT(!Bigint::Cast(int_obj).FitsIntoInt64()); | 1976 ASSERT(!Bigint::Cast(int_obj).FitsIntoInt64()); |
1960 *fits = false; | 1977 *fits = false; |
1961 return Api::Success(); | 1978 return Api::Success(); |
1962 } | 1979 } |
1963 | 1980 |
1964 | 1981 |
1965 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, | 1982 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, |
1966 bool* fits) { | 1983 bool* fits) { |
1967 // Fast path for Smis. | 1984 // Fast path for Smis. |
1968 Thread* thread = Thread::Current(); | 1985 Thread* thread = Thread::Current(); |
1969 Isolate* isolate = thread->isolate(); | 1986 Isolate* isolate = thread->isolate(); |
1970 CHECK_ISOLATE(isolate); | 1987 CHECK_ISOLATE(isolate); |
1988 API_TIMELINE_DURATION; | |
1971 if (Api::IsSmi(integer)) { | 1989 if (Api::IsSmi(integer)) { |
1972 *fits = (Api::SmiValue(integer) >= 0); | 1990 *fits = (Api::SmiValue(integer) >= 0); |
1973 return Api::Success(); | 1991 return Api::Success(); |
1974 } | 1992 } |
1975 // Slow path for Mints and Bigints. | 1993 // Slow path for Mints and Bigints. |
1976 DARTSCOPE(thread); | 1994 DARTSCOPE(thread); |
1977 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); | 1995 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); |
1978 if (int_obj.IsNull()) { | 1996 if (int_obj.IsNull()) { |
1979 RETURN_TYPE_ERROR(Z, integer, Integer); | 1997 RETURN_TYPE_ERROR(Z, integer, Integer); |
1980 } | 1998 } |
1981 ASSERT(!int_obj.IsSmi()); | 1999 ASSERT(!int_obj.IsSmi()); |
1982 if (int_obj.IsMint()) { | 2000 if (int_obj.IsMint()) { |
1983 *fits = !int_obj.IsNegative(); | 2001 *fits = !int_obj.IsNegative(); |
1984 } else { | 2002 } else { |
1985 *fits = Bigint::Cast(int_obj).FitsIntoUint64(); | 2003 *fits = Bigint::Cast(int_obj).FitsIntoUint64(); |
1986 } | 2004 } |
1987 return Api::Success(); | 2005 return Api::Success(); |
1988 } | 2006 } |
1989 | 2007 |
1990 | 2008 |
1991 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { | 2009 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { |
1992 // Fast path for Smis. | 2010 // Fast path for Smis. |
1993 Thread* thread = Thread::Current(); | 2011 Thread* thread = Thread::Current(); |
1994 Isolate* isolate = thread->isolate(); | 2012 Isolate* isolate = thread->isolate(); |
1995 CHECK_ISOLATE(isolate); | 2013 CHECK_ISOLATE(isolate); |
2014 API_TIMELINE_DURATION; | |
1996 if (Smi::IsValid(value)) { | 2015 if (Smi::IsValid(value)) { |
1997 NOHANDLESCOPE(thread); | 2016 NOHANDLESCOPE(thread); |
1998 return Api::NewHandle(thread, Smi::New(static_cast<intptr_t>(value))); | 2017 return Api::NewHandle(thread, Smi::New(static_cast<intptr_t>(value))); |
1999 } | 2018 } |
2000 // Slow path for Mints and Bigints. | 2019 // Slow path for Mints and Bigints. |
2001 DARTSCOPE(thread); | 2020 DARTSCOPE(thread); |
2002 CHECK_CALLBACK_STATE(thread); | 2021 CHECK_CALLBACK_STATE(thread); |
2003 return Api::NewHandle(thread, Integer::New(value)); | 2022 return Api::NewHandle(thread, Integer::New(value)); |
2004 } | 2023 } |
2005 | 2024 |
2006 | 2025 |
2007 DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value) { | 2026 DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value) { |
2008 DARTSCOPE(Thread::Current()); | 2027 DARTSCOPE(Thread::Current()); |
2009 CHECK_CALLBACK_STATE(T); | 2028 CHECK_CALLBACK_STATE(T); |
2029 API_TIMELINE_DURATION; | |
2010 return Api::NewHandle(T, Integer::NewFromUint64(value)); | 2030 return Api::NewHandle(T, Integer::NewFromUint64(value)); |
2011 } | 2031 } |
2012 | 2032 |
2013 | 2033 |
2014 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { | 2034 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { |
2015 DARTSCOPE(Thread::Current()); | 2035 DARTSCOPE(Thread::Current()); |
2016 CHECK_CALLBACK_STATE(T); | 2036 CHECK_CALLBACK_STATE(T); |
2037 API_TIMELINE_DURATION; | |
2017 const String& str_obj = String::Handle(Z, String::New(str)); | 2038 const String& str_obj = String::Handle(Z, String::New(str)); |
2018 return Api::NewHandle(T, Integer::New(str_obj)); | 2039 return Api::NewHandle(T, Integer::New(str_obj)); |
2019 } | 2040 } |
2020 | 2041 |
2021 | 2042 |
2022 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, | 2043 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, |
2023 int64_t* value) { | 2044 int64_t* value) { |
2024 // Fast path for Smis. | 2045 // Fast path for Smis. |
2025 Thread* thread = Thread::Current(); | 2046 Thread* thread = Thread::Current(); |
2026 Isolate* isolate = thread->isolate(); | 2047 Isolate* isolate = thread->isolate(); |
2027 CHECK_ISOLATE(isolate); | 2048 CHECK_ISOLATE(isolate); |
2049 API_TIMELINE_DURATION; | |
2028 if (Api::IsSmi(integer)) { | 2050 if (Api::IsSmi(integer)) { |
2029 *value = Api::SmiValue(integer); | 2051 *value = Api::SmiValue(integer); |
2030 return Api::Success(); | 2052 return Api::Success(); |
2031 } | 2053 } |
2032 // Slow path for Mints and Bigints. | 2054 // Slow path for Mints and Bigints. |
2033 DARTSCOPE(thread); | 2055 DARTSCOPE(thread); |
2034 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); | 2056 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); |
2035 if (int_obj.IsNull()) { | 2057 if (int_obj.IsNull()) { |
2036 RETURN_TYPE_ERROR(Z, integer, Integer); | 2058 RETURN_TYPE_ERROR(Z, integer, Integer); |
2037 } | 2059 } |
2038 ASSERT(!int_obj.IsSmi()); | 2060 ASSERT(!int_obj.IsSmi()); |
2039 if (int_obj.IsMint()) { | 2061 if (int_obj.IsMint()) { |
2040 *value = int_obj.AsInt64Value(); | 2062 *value = int_obj.AsInt64Value(); |
2041 return Api::Success(); | 2063 return Api::Success(); |
2042 } else { | 2064 } else { |
2043 const Bigint& bigint = Bigint::Cast(int_obj); | 2065 const Bigint& bigint = Bigint::Cast(int_obj); |
2044 if (bigint.FitsIntoInt64()) { | 2066 if (bigint.FitsIntoInt64()) { |
2045 *value = bigint.AsInt64Value(); | 2067 *value = bigint.AsInt64Value(); |
2046 return Api::Success(); | 2068 return Api::Success(); |
2047 } | 2069 } |
2048 } | 2070 } |
2049 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.", | 2071 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.", |
2050 CURRENT_FUNC, int_obj.ToCString()); | 2072 CURRENT_FUNC, int_obj.ToCString()); |
2051 } | 2073 } |
2052 | 2074 |
2053 | 2075 |
2054 DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer, | 2076 DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer, |
2055 uint64_t* value) { | 2077 uint64_t* value) { |
2078 API_TIMELINE_DURATION; | |
2056 // Fast path for Smis. | 2079 // Fast path for Smis. |
2057 Thread* thread = Thread::Current(); | 2080 Thread* thread = Thread::Current(); |
2058 Isolate* isolate = thread->isolate(); | 2081 Isolate* isolate = thread->isolate(); |
2059 CHECK_ISOLATE(isolate); | 2082 CHECK_ISOLATE(isolate); |
2060 if (Api::IsSmi(integer)) { | 2083 if (Api::IsSmi(integer)) { |
2061 intptr_t smi_value = Api::SmiValue(integer); | 2084 intptr_t smi_value = Api::SmiValue(integer); |
2062 if (smi_value >= 0) { | 2085 if (smi_value >= 0) { |
2063 *value = smi_value; | 2086 *value = smi_value; |
2064 return Api::Success(); | 2087 return Api::Success(); |
2065 } | 2088 } |
(...skipping 21 matching lines...) Expand all Loading... | |
2087 } | 2110 } |
2088 | 2111 |
2089 | 2112 |
2090 static uword BigintAllocate(intptr_t size) { | 2113 static uword BigintAllocate(intptr_t size) { |
2091 return Api::TopScope(Thread::Current())->zone()->AllocUnsafe(size); | 2114 return Api::TopScope(Thread::Current())->zone()->AllocUnsafe(size); |
2092 } | 2115 } |
2093 | 2116 |
2094 | 2117 |
2095 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, | 2118 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, |
2096 const char** value) { | 2119 const char** value) { |
2120 API_TIMELINE_DURATION; | |
2097 DARTSCOPE(Thread::Current()); | 2121 DARTSCOPE(Thread::Current()); |
2098 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); | 2122 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); |
2099 if (int_obj.IsNull()) { | 2123 if (int_obj.IsNull()) { |
2100 RETURN_TYPE_ERROR(Z, integer, Integer); | 2124 RETURN_TYPE_ERROR(Z, integer, Integer); |
2101 } | 2125 } |
2102 if (int_obj.IsSmi() || int_obj.IsMint()) { | 2126 if (int_obj.IsSmi() || int_obj.IsMint()) { |
2103 const Bigint& bigint = Bigint::Handle(Z, | 2127 const Bigint& bigint = Bigint::Handle(Z, |
2104 Bigint::NewFromInt64(int_obj.AsInt64Value())); | 2128 Bigint::NewFromInt64(int_obj.AsInt64Value())); |
2105 *value = bigint.ToHexCString(BigintAllocate); | 2129 *value = bigint.ToHexCString(BigintAllocate); |
2106 } else { | 2130 } else { |
2107 *value = Bigint::Cast(int_obj).ToHexCString(BigintAllocate); | 2131 *value = Bigint::Cast(int_obj).ToHexCString(BigintAllocate); |
2108 } | 2132 } |
2109 return Api::Success(); | 2133 return Api::Success(); |
2110 } | 2134 } |
2111 | 2135 |
2112 | 2136 |
2113 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { | 2137 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { |
2138 API_TIMELINE_DURATION; | |
2114 DARTSCOPE(Thread::Current()); | 2139 DARTSCOPE(Thread::Current()); |
2115 CHECK_CALLBACK_STATE(T); | 2140 CHECK_CALLBACK_STATE(T); |
2116 return Api::NewHandle(T, Double::New(value)); | 2141 return Api::NewHandle(T, Double::New(value)); |
2117 } | 2142 } |
2118 | 2143 |
2119 | 2144 |
2120 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, | 2145 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, |
2121 double* value) { | 2146 double* value) { |
2147 API_TIMELINE_DURATION; | |
2122 DARTSCOPE(Thread::Current()); | 2148 DARTSCOPE(Thread::Current()); |
2123 const Double& obj = Api::UnwrapDoubleHandle(Z, double_obj); | 2149 const Double& obj = Api::UnwrapDoubleHandle(Z, double_obj); |
2124 if (obj.IsNull()) { | 2150 if (obj.IsNull()) { |
2125 RETURN_TYPE_ERROR(Z, double_obj, Double); | 2151 RETURN_TYPE_ERROR(Z, double_obj, Double); |
2126 } | 2152 } |
2127 *value = obj.value(); | 2153 *value = obj.value(); |
2128 return Api::Success(); | 2154 return Api::Success(); |
2129 } | 2155 } |
2130 | 2156 |
2131 | 2157 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2172 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str); | 2198 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str); |
2173 if (str_obj.IsNull()) { | 2199 if (str_obj.IsNull()) { |
2174 RETURN_TYPE_ERROR(thread->zone(), str, String); | 2200 RETURN_TYPE_ERROR(thread->zone(), str, String); |
2175 } | 2201 } |
2176 *len = str_obj.Length(); | 2202 *len = str_obj.Length(); |
2177 return Api::Success(); | 2203 return Api::Success(); |
2178 } | 2204 } |
2179 | 2205 |
2180 | 2206 |
2181 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) { | 2207 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) { |
2208 API_TIMELINE_DURATION; | |
2182 DARTSCOPE(Thread::Current()); | 2209 DARTSCOPE(Thread::Current()); |
2183 if (str == NULL) { | 2210 if (str == NULL) { |
2184 RETURN_NULL_ERROR(str); | 2211 RETURN_NULL_ERROR(str); |
2185 } | 2212 } |
2186 CHECK_CALLBACK_STATE(T); | 2213 CHECK_CALLBACK_STATE(T); |
2187 return Api::NewHandle(T, String::New(str)); | 2214 return Api::NewHandle(T, String::New(str)); |
2188 } | 2215 } |
2189 | 2216 |
2190 | 2217 |
2191 DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array, | 2218 DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array, |
2192 intptr_t length) { | 2219 intptr_t length) { |
2220 API_TIMELINE_DURATION; | |
2193 DARTSCOPE(Thread::Current()); | 2221 DARTSCOPE(Thread::Current()); |
2194 if (utf8_array == NULL && length != 0) { | 2222 if (utf8_array == NULL && length != 0) { |
2195 RETURN_NULL_ERROR(utf8_array); | 2223 RETURN_NULL_ERROR(utf8_array); |
2196 } | 2224 } |
2197 CHECK_LENGTH(length, String::kMaxElements); | 2225 CHECK_LENGTH(length, String::kMaxElements); |
2198 if (!Utf8::IsValid(utf8_array, length)) { | 2226 if (!Utf8::IsValid(utf8_array, length)) { |
2199 return Api::NewError("%s expects argument 'str' to be valid UTF-8.", | 2227 return Api::NewError("%s expects argument 'str' to be valid UTF-8.", |
2200 CURRENT_FUNC); | 2228 CURRENT_FUNC); |
2201 } | 2229 } |
2202 CHECK_CALLBACK_STATE(T); | 2230 CHECK_CALLBACK_STATE(T); |
2203 return Api::NewHandle(T, String::FromUTF8(utf8_array, length)); | 2231 return Api::NewHandle(T, String::FromUTF8(utf8_array, length)); |
2204 } | 2232 } |
2205 | 2233 |
2206 | 2234 |
2207 DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array, | 2235 DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array, |
2208 intptr_t length) { | 2236 intptr_t length) { |
2209 DARTSCOPE(Thread::Current()); | 2237 DARTSCOPE(Thread::Current()); |
2210 if (utf16_array == NULL && length != 0) { | 2238 if (utf16_array == NULL && length != 0) { |
2211 RETURN_NULL_ERROR(utf16_array); | 2239 RETURN_NULL_ERROR(utf16_array); |
2212 } | 2240 } |
2213 CHECK_LENGTH(length, String::kMaxElements); | 2241 CHECK_LENGTH(length, String::kMaxElements); |
2214 CHECK_CALLBACK_STATE(T); | 2242 CHECK_CALLBACK_STATE(T); |
2215 return Api::NewHandle(T, String::FromUTF16(utf16_array, length)); | 2243 return Api::NewHandle(T, String::FromUTF16(utf16_array, length)); |
2216 } | 2244 } |
2217 | 2245 |
2218 | 2246 |
2219 DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const int32_t* utf32_array, | 2247 DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const int32_t* utf32_array, |
2220 intptr_t length) { | 2248 intptr_t length) { |
2249 API_TIMELINE_DURATION; | |
2221 DARTSCOPE(Thread::Current()); | 2250 DARTSCOPE(Thread::Current()); |
2222 if (utf32_array == NULL && length != 0) { | 2251 if (utf32_array == NULL && length != 0) { |
2223 RETURN_NULL_ERROR(utf32_array); | 2252 RETURN_NULL_ERROR(utf32_array); |
2224 } | 2253 } |
2225 CHECK_LENGTH(length, String::kMaxElements); | 2254 CHECK_LENGTH(length, String::kMaxElements); |
2226 CHECK_CALLBACK_STATE(T); | 2255 CHECK_CALLBACK_STATE(T); |
2227 return Api::NewHandle(T, String::FromUTF32(utf32_array, length)); | 2256 return Api::NewHandle(T, String::FromUTF32(utf32_array, length)); |
2228 } | 2257 } |
2229 | 2258 |
2230 | 2259 |
2231 DART_EXPORT Dart_Handle Dart_NewExternalLatin1String( | 2260 DART_EXPORT Dart_Handle Dart_NewExternalLatin1String( |
2232 const uint8_t* latin1_array, | 2261 const uint8_t* latin1_array, |
2233 intptr_t length, | 2262 intptr_t length, |
2234 void* peer, | 2263 void* peer, |
2235 Dart_PeerFinalizer cback) { | 2264 Dart_PeerFinalizer cback) { |
2265 API_TIMELINE_DURATION; | |
2236 DARTSCOPE(Thread::Current()); | 2266 DARTSCOPE(Thread::Current()); |
2237 if (latin1_array == NULL && length != 0) { | 2267 if (latin1_array == NULL && length != 0) { |
2238 RETURN_NULL_ERROR(latin1_array); | 2268 RETURN_NULL_ERROR(latin1_array); |
2239 } | 2269 } |
2240 CHECK_LENGTH(length, String::kMaxElements); | 2270 CHECK_LENGTH(length, String::kMaxElements); |
2241 CHECK_CALLBACK_STATE(T); | 2271 CHECK_CALLBACK_STATE(T); |
2242 return Api::NewHandle(T, String::NewExternal(latin1_array, | 2272 return Api::NewHandle(T, String::NewExternal(latin1_array, |
2243 length, | 2273 length, |
2244 peer, | 2274 peer, |
2245 cback, | 2275 cback, |
(...skipping 15 matching lines...) Expand all Loading... | |
2261 return Api::NewHandle(T, String::NewExternal(utf16_array, | 2291 return Api::NewHandle(T, String::NewExternal(utf16_array, |
2262 length, | 2292 length, |
2263 peer, | 2293 peer, |
2264 cback, | 2294 cback, |
2265 SpaceForExternal(T, bytes))); | 2295 SpaceForExternal(T, bytes))); |
2266 } | 2296 } |
2267 | 2297 |
2268 | 2298 |
2269 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, | 2299 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, |
2270 const char** cstr) { | 2300 const char** cstr) { |
2301 API_TIMELINE_DURATION; | |
2271 DARTSCOPE(Thread::Current()); | 2302 DARTSCOPE(Thread::Current()); |
2272 if (cstr == NULL) { | 2303 if (cstr == NULL) { |
2273 RETURN_NULL_ERROR(cstr); | 2304 RETURN_NULL_ERROR(cstr); |
2274 } | 2305 } |
2275 const String& str_obj = Api::UnwrapStringHandle(Z, object); | 2306 const String& str_obj = Api::UnwrapStringHandle(Z, object); |
2276 if (str_obj.IsNull()) { | 2307 if (str_obj.IsNull()) { |
2277 RETURN_TYPE_ERROR(Z, object, String); | 2308 RETURN_TYPE_ERROR(Z, object, String); |
2278 } | 2309 } |
2279 intptr_t string_length = Utf8::Length(str_obj); | 2310 intptr_t string_length = Utf8::Length(str_obj); |
2280 char* res = Api::TopScope(T)->zone()->Alloc<char>(string_length + 1); | 2311 char* res = Api::TopScope(T)->zone()->Alloc<char>(string_length + 1); |
2281 if (res == NULL) { | 2312 if (res == NULL) { |
2282 return Api::NewError("Unable to allocate memory"); | 2313 return Api::NewError("Unable to allocate memory"); |
2283 } | 2314 } |
2284 const char* string_value = str_obj.ToCString(); | 2315 const char* string_value = str_obj.ToCString(); |
2285 memmove(res, string_value, string_length + 1); | 2316 memmove(res, string_value, string_length + 1); |
2286 ASSERT(res[string_length] == '\0'); | 2317 ASSERT(res[string_length] == '\0'); |
2287 *cstr = res; | 2318 *cstr = res; |
2288 return Api::Success(); | 2319 return Api::Success(); |
2289 } | 2320 } |
2290 | 2321 |
2291 | 2322 |
2292 DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str, | 2323 DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str, |
2293 uint8_t** utf8_array, | 2324 uint8_t** utf8_array, |
2294 intptr_t* length) { | 2325 intptr_t* length) { |
2326 API_TIMELINE_DURATION; | |
2295 DARTSCOPE(Thread::Current()); | 2327 DARTSCOPE(Thread::Current()); |
2296 if (utf8_array == NULL) { | 2328 if (utf8_array == NULL) { |
2297 RETURN_NULL_ERROR(utf8_array); | 2329 RETURN_NULL_ERROR(utf8_array); |
2298 } | 2330 } |
2299 if (length == NULL) { | 2331 if (length == NULL) { |
2300 RETURN_NULL_ERROR(length); | 2332 RETURN_NULL_ERROR(length); |
2301 } | 2333 } |
2302 const String& str_obj = Api::UnwrapStringHandle(Z, str); | 2334 const String& str_obj = Api::UnwrapStringHandle(Z, str); |
2303 if (str_obj.IsNull()) { | 2335 if (str_obj.IsNull()) { |
2304 RETURN_TYPE_ERROR(Z, str, String); | 2336 RETURN_TYPE_ERROR(Z, str, String); |
2305 } | 2337 } |
2306 intptr_t str_len = Utf8::Length(str_obj); | 2338 intptr_t str_len = Utf8::Length(str_obj); |
2307 *utf8_array = Api::TopScope(T)->zone()->Alloc<uint8_t>(str_len); | 2339 *utf8_array = Api::TopScope(T)->zone()->Alloc<uint8_t>(str_len); |
2308 if (*utf8_array == NULL) { | 2340 if (*utf8_array == NULL) { |
2309 return Api::NewError("Unable to allocate memory"); | 2341 return Api::NewError("Unable to allocate memory"); |
2310 } | 2342 } |
2311 str_obj.ToUTF8(*utf8_array, str_len); | 2343 str_obj.ToUTF8(*utf8_array, str_len); |
2312 *length = str_len; | 2344 *length = str_len; |
2313 return Api::Success(); | 2345 return Api::Success(); |
2314 } | 2346 } |
2315 | 2347 |
2316 | 2348 |
2317 DART_EXPORT Dart_Handle Dart_StringToLatin1(Dart_Handle str, | 2349 DART_EXPORT Dart_Handle Dart_StringToLatin1(Dart_Handle str, |
2318 uint8_t* latin1_array, | 2350 uint8_t* latin1_array, |
2319 intptr_t* length) { | 2351 intptr_t* length) { |
2352 API_TIMELINE_DURATION; | |
2320 DARTSCOPE(Thread::Current()); | 2353 DARTSCOPE(Thread::Current()); |
2321 if (latin1_array == NULL) { | 2354 if (latin1_array == NULL) { |
2322 RETURN_NULL_ERROR(latin1_array); | 2355 RETURN_NULL_ERROR(latin1_array); |
2323 } | 2356 } |
2324 if (length == NULL) { | 2357 if (length == NULL) { |
2325 RETURN_NULL_ERROR(length); | 2358 RETURN_NULL_ERROR(length); |
2326 } | 2359 } |
2327 const String& str_obj = Api::UnwrapStringHandle(Z, str); | 2360 const String& str_obj = Api::UnwrapStringHandle(Z, str); |
2328 if (str_obj.IsNull() || !str_obj.IsOneByteString()) { | 2361 if (str_obj.IsNull() || !str_obj.IsOneByteString()) { |
2329 RETURN_TYPE_ERROR(Z, str, String); | 2362 RETURN_TYPE_ERROR(Z, str, String); |
2330 } | 2363 } |
2331 intptr_t str_len = str_obj.Length(); | 2364 intptr_t str_len = str_obj.Length(); |
2332 intptr_t copy_len = (str_len > *length) ? *length : str_len; | 2365 intptr_t copy_len = (str_len > *length) ? *length : str_len; |
2333 | 2366 |
2334 // We have already asserted that the string object is a Latin-1 string | 2367 // 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. | 2368 // so we can copy the characters over using a simple loop. |
2336 for (intptr_t i = 0; i < copy_len; i++) { | 2369 for (intptr_t i = 0; i < copy_len; i++) { |
2337 latin1_array[i] = str_obj.CharAt(i); | 2370 latin1_array[i] = str_obj.CharAt(i); |
2338 } | 2371 } |
2339 *length = copy_len; | 2372 *length = copy_len; |
2340 return Api::Success(); | 2373 return Api::Success(); |
2341 } | 2374 } |
2342 | 2375 |
2343 | 2376 |
2344 DART_EXPORT Dart_Handle Dart_StringToUTF16(Dart_Handle str, | 2377 DART_EXPORT Dart_Handle Dart_StringToUTF16(Dart_Handle str, |
2345 uint16_t* utf16_array, | 2378 uint16_t* utf16_array, |
2346 intptr_t* length) { | 2379 intptr_t* length) { |
2380 API_TIMELINE_DURATION; | |
2347 DARTSCOPE(Thread::Current()); | 2381 DARTSCOPE(Thread::Current()); |
2348 const String& str_obj = Api::UnwrapStringHandle(Z, str); | 2382 const String& str_obj = Api::UnwrapStringHandle(Z, str); |
2349 if (str_obj.IsNull()) { | 2383 if (str_obj.IsNull()) { |
2350 RETURN_TYPE_ERROR(Z, str, String); | 2384 RETURN_TYPE_ERROR(Z, str, String); |
2351 } | 2385 } |
2352 intptr_t str_len = str_obj.Length(); | 2386 intptr_t str_len = str_obj.Length(); |
2353 intptr_t copy_len = (str_len > *length) ? *length : str_len; | 2387 intptr_t copy_len = (str_len > *length) ? *length : str_len; |
2354 for (intptr_t i = 0; i < copy_len; i++) { | 2388 for (intptr_t i = 0; i < copy_len; i++) { |
2355 utf16_array[i] = str_obj.CharAt(i); | 2389 utf16_array[i] = str_obj.CharAt(i); |
2356 } | 2390 } |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3098 break; | 3132 break; |
3099 default: | 3133 default: |
3100 type = Dart_TypedData_kInvalid; | 3134 type = Dart_TypedData_kInvalid; |
3101 break; | 3135 break; |
3102 } | 3136 } |
3103 return type; | 3137 return type; |
3104 } | 3138 } |
3105 | 3139 |
3106 | 3140 |
3107 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfTypedData(Dart_Handle object) { | 3141 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfTypedData(Dart_Handle object) { |
3108 TRACE_API_CALL(CURRENT_FUNC); | 3142 API_TIMELINE_DURATION; |
3109 intptr_t class_id = Api::ClassId(object); | 3143 intptr_t class_id = Api::ClassId(object); |
3110 if (RawObject::IsTypedDataClassId(class_id) || | 3144 if (RawObject::IsTypedDataClassId(class_id) || |
3111 RawObject::IsTypedDataViewClassId(class_id)) { | 3145 RawObject::IsTypedDataViewClassId(class_id)) { |
3112 return GetType(class_id); | 3146 return GetType(class_id); |
3113 } | 3147 } |
3114 return Dart_TypedData_kInvalid; | 3148 return Dart_TypedData_kInvalid; |
3115 } | 3149 } |
3116 | 3150 |
3117 | 3151 |
3118 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfExternalTypedData( | 3152 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfExternalTypedData( |
3119 Dart_Handle object) { | 3153 Dart_Handle object) { |
3120 TRACE_API_CALL(CURRENT_FUNC); | 3154 API_TIMELINE_DURATION; |
3121 intptr_t class_id = Api::ClassId(object); | 3155 intptr_t class_id = Api::ClassId(object); |
3122 if (RawObject::IsExternalTypedDataClassId(class_id)) { | 3156 if (RawObject::IsExternalTypedDataClassId(class_id)) { |
3123 return GetType(class_id); | 3157 return GetType(class_id); |
3124 } | 3158 } |
3125 if (RawObject::IsTypedDataViewClassId(class_id)) { | 3159 if (RawObject::IsTypedDataViewClassId(class_id)) { |
3126 // Check if data object of the view is external. | 3160 // Check if data object of the view is external. |
3127 Zone* zone = Thread::Current()->zone(); | 3161 Zone* zone = Thread::Current()->zone(); |
3128 const Instance& view_obj = Api::UnwrapInstanceHandle(zone, object); | 3162 const Instance& view_obj = Api::UnwrapInstanceHandle(zone, object); |
3129 ASSERT(!view_obj.IsNull()); | 3163 ASSERT(!view_obj.IsNull()); |
3130 const Instance& data_obj = | 3164 const Instance& data_obj = |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3859 args->SetAt((i + extra_args), arg); | 3893 args->SetAt((i + extra_args), arg); |
3860 } | 3894 } |
3861 return Api::Success(); | 3895 return Api::Success(); |
3862 } | 3896 } |
3863 | 3897 |
3864 | 3898 |
3865 DART_EXPORT Dart_Handle Dart_InvokeConstructor(Dart_Handle object, | 3899 DART_EXPORT Dart_Handle Dart_InvokeConstructor(Dart_Handle object, |
3866 Dart_Handle name, | 3900 Dart_Handle name, |
3867 int number_of_arguments, | 3901 int number_of_arguments, |
3868 Dart_Handle* arguments) { | 3902 Dart_Handle* arguments) { |
3903 API_TIMELINE_DURATION; | |
3869 DARTSCOPE(Thread::Current()); | 3904 DARTSCOPE(Thread::Current()); |
3870 CHECK_CALLBACK_STATE(T); | 3905 CHECK_CALLBACK_STATE(T); |
3871 | 3906 |
3872 if (number_of_arguments < 0) { | 3907 if (number_of_arguments < 0) { |
3873 return Api::NewError( | 3908 return Api::NewError( |
3874 "%s expects argument 'number_of_arguments' to be non-negative.", | 3909 "%s expects argument 'number_of_arguments' to be non-negative.", |
3875 CURRENT_FUNC); | 3910 CURRENT_FUNC); |
3876 } | 3911 } |
3877 const Instance& instance = Api::UnwrapInstanceHandle(Z, object); | 3912 const Instance& instance = Api::UnwrapInstanceHandle(Z, object); |
3878 if (instance.IsNull()) { | 3913 if (instance.IsNull()) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3937 return Api::NewError( | 3972 return Api::NewError( |
3938 "%s expects argument 'name' to be a valid constructor.", | 3973 "%s expects argument 'name' to be a valid constructor.", |
3939 CURRENT_FUNC); | 3974 CURRENT_FUNC); |
3940 } | 3975 } |
3941 | 3976 |
3942 | 3977 |
3943 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, | 3978 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, |
3944 Dart_Handle name, | 3979 Dart_Handle name, |
3945 int number_of_arguments, | 3980 int number_of_arguments, |
3946 Dart_Handle* arguments) { | 3981 Dart_Handle* arguments) { |
3982 API_TIMELINE_DURATION; | |
3947 DARTSCOPE(Thread::Current()); | 3983 DARTSCOPE(Thread::Current()); |
3948 CHECK_CALLBACK_STATE(T); | 3984 CHECK_CALLBACK_STATE(T); |
3949 | 3985 |
3950 const String& function_name = Api::UnwrapStringHandle(Z, name); | 3986 const String& function_name = Api::UnwrapStringHandle(Z, name); |
3951 if (function_name.IsNull()) { | 3987 if (function_name.IsNull()) { |
3952 RETURN_TYPE_ERROR(Z, name, String); | 3988 RETURN_TYPE_ERROR(Z, name, String); |
3953 } | 3989 } |
3954 if (number_of_arguments < 0) { | 3990 if (number_of_arguments < 0) { |
3955 return Api::NewError( | 3991 return Api::NewError( |
3956 "%s expects argument 'number_of_arguments' to be non-negative.", | 3992 "%s expects argument 'number_of_arguments' to be non-negative.", |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4063 return Api::NewError( | 4099 return Api::NewError( |
4064 "%s expects argument 'target' to be an object, type, or library.", | 4100 "%s expects argument 'target' to be an object, type, or library.", |
4065 CURRENT_FUNC); | 4101 CURRENT_FUNC); |
4066 } | 4102 } |
4067 } | 4103 } |
4068 | 4104 |
4069 | 4105 |
4070 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, | 4106 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, |
4071 int number_of_arguments, | 4107 int number_of_arguments, |
4072 Dart_Handle* arguments) { | 4108 Dart_Handle* arguments) { |
4109 API_TIMELINE_DURATION; | |
4073 DARTSCOPE(Thread::Current()); | 4110 DARTSCOPE(Thread::Current()); |
4074 CHECK_CALLBACK_STATE(T); | 4111 CHECK_CALLBACK_STATE(T); |
4075 const Instance& closure_obj = Api::UnwrapInstanceHandle(Z, closure); | 4112 const Instance& closure_obj = Api::UnwrapInstanceHandle(Z, closure); |
4076 if (closure_obj.IsNull() || !closure_obj.IsCallable(NULL)) { | 4113 if (closure_obj.IsNull() || !closure_obj.IsCallable(NULL)) { |
4077 RETURN_TYPE_ERROR(Z, closure, Instance); | 4114 RETURN_TYPE_ERROR(Z, closure, Instance); |
4078 } | 4115 } |
4079 if (number_of_arguments < 0) { | 4116 if (number_of_arguments < 0) { |
4080 return Api::NewError( | 4117 return Api::NewError( |
4081 "%s expects argument 'number_of_arguments' to be non-negative.", | 4118 "%s expects argument 'number_of_arguments' to be non-negative.", |
4082 CURRENT_FUNC); | 4119 CURRENT_FUNC); |
4083 } | 4120 } |
4084 | 4121 |
4085 // Set up arguments to include the closure as the first argument. | 4122 // Set up arguments to include the closure as the first argument. |
4086 const Array& args = Array::Handle(Z, Array::New(number_of_arguments + 1)); | 4123 const Array& args = Array::Handle(Z, Array::New(number_of_arguments + 1)); |
4087 Object& obj = Object::Handle(Z); | 4124 Object& obj = Object::Handle(Z); |
4088 args.SetAt(0, closure_obj); | 4125 args.SetAt(0, closure_obj); |
4089 for (int i = 0; i < number_of_arguments; i++) { | 4126 for (int i = 0; i < number_of_arguments; i++) { |
4090 obj = Api::UnwrapHandle(arguments[i]); | 4127 obj = Api::UnwrapHandle(arguments[i]); |
4091 if (!obj.IsNull() && !obj.IsInstance()) { | 4128 if (!obj.IsNull() && !obj.IsInstance()) { |
4092 RETURN_TYPE_ERROR(Z, arguments[i], Instance); | 4129 RETURN_TYPE_ERROR(Z, arguments[i], Instance); |
4093 } | 4130 } |
4094 args.SetAt(i + 1, obj); | 4131 args.SetAt(i + 1, obj); |
4095 } | 4132 } |
4096 // Now try to invoke the closure. | 4133 // Now try to invoke the closure. |
4097 return Api::NewHandle(T, DartEntry::InvokeClosure(args)); | 4134 return Api::NewHandle(T, DartEntry::InvokeClosure(args)); |
4098 } | 4135 } |
4099 | 4136 |
4100 | 4137 |
4101 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { | 4138 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { |
4139 API_TIMELINE_DURATION; | |
4102 DARTSCOPE(Thread::Current()); | 4140 DARTSCOPE(Thread::Current()); |
4103 CHECK_CALLBACK_STATE(T); | 4141 CHECK_CALLBACK_STATE(T); |
4104 | 4142 |
4105 const String& field_name = Api::UnwrapStringHandle(Z, name); | 4143 const String& field_name = Api::UnwrapStringHandle(Z, name); |
4106 if (field_name.IsNull()) { | 4144 if (field_name.IsNull()) { |
4107 RETURN_TYPE_ERROR(Z, name, String); | 4145 RETURN_TYPE_ERROR(Z, name, String); |
4108 } | 4146 } |
4109 | 4147 |
4110 Field& field = Field::Handle(Z); | 4148 Field& field = Field::Handle(Z); |
4111 Function& getter = Function::Handle(Z); | 4149 Function& getter = Function::Handle(Z); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4212 return Api::NewError( | 4250 return Api::NewError( |
4213 "%s expects argument 'container' to be an object, type, or library.", | 4251 "%s expects argument 'container' to be an object, type, or library.", |
4214 CURRENT_FUNC); | 4252 CURRENT_FUNC); |
4215 } | 4253 } |
4216 } | 4254 } |
4217 | 4255 |
4218 | 4256 |
4219 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, | 4257 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, |
4220 Dart_Handle name, | 4258 Dart_Handle name, |
4221 Dart_Handle value) { | 4259 Dart_Handle value) { |
4260 API_TIMELINE_DURATION; | |
4222 DARTSCOPE(Thread::Current()); | 4261 DARTSCOPE(Thread::Current()); |
4223 CHECK_CALLBACK_STATE(T); | 4262 CHECK_CALLBACK_STATE(T); |
4224 | 4263 |
4225 const String& field_name = Api::UnwrapStringHandle(Z, name); | 4264 const String& field_name = Api::UnwrapStringHandle(Z, name); |
4226 if (field_name.IsNull()) { | 4265 if (field_name.IsNull()) { |
4227 RETURN_TYPE_ERROR(Z, name, String); | 4266 RETURN_TYPE_ERROR(Z, name, String); |
4228 } | 4267 } |
4229 | 4268 |
4230 // Since null is allowed for value, we don't use UnwrapInstanceHandle. | 4269 // Since null is allowed for value, we don't use UnwrapInstanceHandle. |
4231 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); | 4270 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4663 return Api::NewError("%s: invalid argument type %d.", | 4702 return Api::NewError("%s: invalid argument type %d.", |
4664 CURRENT_FUNC, arg_type); | 4703 CURRENT_FUNC, arg_type); |
4665 } | 4704 } |
4666 } | 4705 } |
4667 return Api::Success(); | 4706 return Api::Success(); |
4668 } | 4707 } |
4669 | 4708 |
4670 | 4709 |
4671 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, | 4710 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, |
4672 int index) { | 4711 int index) { |
4673 TRACE_API_CALL(CURRENT_FUNC); | 4712 API_TIMELINE_DURATION; |
4674 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4713 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
4675 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 4714 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
4676 return Api::NewError( | 4715 return Api::NewError( |
4677 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 4716 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
4678 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 4717 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
4679 } | 4718 } |
4680 return Api::NewHandle(arguments->thread(), | 4719 return Api::NewHandle(arguments->thread(), |
4681 arguments->NativeArgAt(index)); | 4720 arguments->NativeArgAt(index)); |
4682 } | 4721 } |
4683 | 4722 |
4684 | 4723 |
4685 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { | 4724 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { |
4686 TRACE_API_CALL(CURRENT_FUNC); | 4725 API_TIMELINE_DURATION; |
4687 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4726 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
4688 return arguments->NativeArgCount(); | 4727 return arguments->NativeArgCount(); |
4689 } | 4728 } |
4690 | 4729 |
4691 | 4730 |
4692 DART_EXPORT Dart_Handle Dart_GetNativeFieldsOfArgument( | 4731 DART_EXPORT Dart_Handle Dart_GetNativeFieldsOfArgument( |
4693 Dart_NativeArguments args, | 4732 Dart_NativeArguments args, |
4694 int arg_index, | 4733 int arg_index, |
4695 int num_fields, | 4734 int num_fields, |
4696 intptr_t* field_values) { | 4735 intptr_t* field_values) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4735 return Api::NewError("%s expects argument at %d to be of" | 4774 return Api::NewError("%s expects argument at %d to be of" |
4736 " type String.", CURRENT_FUNC, arg_index); | 4775 " type String.", CURRENT_FUNC, arg_index); |
4737 } | 4776 } |
4738 return result; | 4777 return result; |
4739 } | 4778 } |
4740 | 4779 |
4741 | 4780 |
4742 DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, | 4781 DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, |
4743 int index, | 4782 int index, |
4744 int64_t* value) { | 4783 int64_t* value) { |
4745 TRACE_API_CALL(CURRENT_FUNC); | 4784 API_TIMELINE_DURATION; |
4746 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4785 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
4747 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 4786 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
4748 return Api::NewError( | 4787 return Api::NewError( |
4749 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 4788 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
4750 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 4789 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
4751 } | 4790 } |
4752 if (!GetNativeIntegerArgument(arguments, index, value)) { | 4791 if (!GetNativeIntegerArgument(arguments, index, value)) { |
4753 return Api::NewError("%s: expects argument at %d to be of" | 4792 return Api::NewError("%s: expects argument at %d to be of" |
4754 " type Integer.", CURRENT_FUNC, index); | 4793 " type Integer.", CURRENT_FUNC, index); |
4755 } | 4794 } |
4756 return Api::Success(); | 4795 return Api::Success(); |
4757 } | 4796 } |
4758 | 4797 |
4759 | 4798 |
4760 DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, | 4799 DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, |
4761 int index, | 4800 int index, |
4762 bool* value) { | 4801 bool* value) { |
4763 TRACE_API_CALL(CURRENT_FUNC); | 4802 API_TIMELINE_DURATION; |
4764 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4803 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
4765 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 4804 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
4766 return Api::NewError( | 4805 return Api::NewError( |
4767 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 4806 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
4768 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 4807 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
4769 } | 4808 } |
4770 if (!Api::GetNativeBooleanArgument(arguments, index, value)) { | 4809 if (!Api::GetNativeBooleanArgument(arguments, index, value)) { |
4771 return Api::NewError("%s: expects argument at %d to be of type Boolean.", | 4810 return Api::NewError("%s: expects argument at %d to be of type Boolean.", |
4772 CURRENT_FUNC, index); | 4811 CURRENT_FUNC, index); |
4773 } | 4812 } |
4774 return Api::Success(); | 4813 return Api::Success(); |
4775 } | 4814 } |
4776 | 4815 |
4777 | 4816 |
4778 DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args, | 4817 DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args, |
4779 int index, | 4818 int index, |
4780 double* value) { | 4819 double* value) { |
4781 TRACE_API_CALL(CURRENT_FUNC); | 4820 API_TIMELINE_DURATION; |
4782 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4821 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
4783 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 4822 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
4784 return Api::NewError( | 4823 return Api::NewError( |
4785 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 4824 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
4786 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 4825 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
4787 } | 4826 } |
4788 if (!GetNativeDoubleArgument(arguments, index, value)) { | 4827 if (!GetNativeDoubleArgument(arguments, index, value)) { |
4789 return Api::NewError("%s: expects argument at %d to be of" | 4828 return Api::NewError("%s: expects argument at %d to be of" |
4790 " type Double.", CURRENT_FUNC, index); | 4829 " type Double.", CURRENT_FUNC, index); |
4791 } | 4830 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4859 Isolate* isolate = Isolate::Current(); | 4898 Isolate* isolate = Isolate::Current(); |
4860 CHECK_ISOLATE(isolate); | 4899 CHECK_ISOLATE(isolate); |
4861 isolate->set_environment_callback(callback); | 4900 isolate->set_environment_callback(callback); |
4862 return Api::Success(); | 4901 return Api::Success(); |
4863 } | 4902 } |
4864 | 4903 |
4865 | 4904 |
4866 // --- Scripts and Libraries --- | 4905 // --- Scripts and Libraries --- |
4867 DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, | 4906 DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, |
4868 bool retval) { | 4907 bool retval) { |
4869 TRACE_API_CALL(CURRENT_FUNC); | 4908 API_TIMELINE_DURATION; |
4870 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4909 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
4871 arguments->SetReturn(Bool::Get(retval)); | 4910 arguments->SetReturn(Bool::Get(retval)); |
4872 } | 4911 } |
4873 | 4912 |
4874 | 4913 |
4875 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, | 4914 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, |
4876 int64_t retval) { | 4915 int64_t retval) { |
4877 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4916 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
4878 ASSERT(arguments->thread()->isolate() == Isolate::Current()); | 4917 ASSERT(arguments->thread()->isolate() == Isolate::Current()); |
4879 if (Smi::IsValid(retval)) { | 4918 if (Smi::IsValid(retval)) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4928 // as having failed to load without providing an error instance. | 4967 // as having failed to load without providing an error instance. |
4929 lib.SetLoadError(Object::null_instance()); | 4968 lib.SetLoadError(Object::null_instance()); |
4930 } | 4969 } |
4931 } | 4970 } |
4932 | 4971 |
4933 | 4972 |
4934 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, | 4973 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, |
4935 Dart_Handle source, | 4974 Dart_Handle source, |
4936 intptr_t line_offset, | 4975 intptr_t line_offset, |
4937 intptr_t column_offset) { | 4976 intptr_t column_offset) { |
4938 DARTSCOPE(Thread::Current()); | 4977 DARTSCOPE(Thread::Current()); |
rmacnak
2015/12/15 17:42:04
API_TIMELINE_DURATION
Cutch
2015/12/15 18:06:40
Done.
| |
4939 Isolate* I = T->isolate(); | 4978 Isolate* I = T->isolate(); |
4940 const String& url_str = Api::UnwrapStringHandle(Z, url); | 4979 const String& url_str = Api::UnwrapStringHandle(Z, url); |
4941 if (url_str.IsNull()) { | 4980 if (url_str.IsNull()) { |
4942 RETURN_TYPE_ERROR(Z, url, String); | 4981 RETURN_TYPE_ERROR(Z, url, String); |
4943 } | 4982 } |
4944 const String& source_str = Api::UnwrapStringHandle(Z, source); | 4983 const String& source_str = Api::UnwrapStringHandle(Z, source); |
4945 if (source_str.IsNull()) { | 4984 if (source_str.IsNull()) { |
4946 RETURN_TYPE_ERROR(Z, source, String); | 4985 RETURN_TYPE_ERROR(Z, source, String); |
4947 } | 4986 } |
4948 Library& library = Library::Handle(Z, I->object_store()->root_library()); | 4987 Library& library = Library::Handle(Z, I->object_store()->root_library()); |
(...skipping 24 matching lines...) Expand all Loading... | |
4973 Script::New(url_str, source_str, RawScript::kScriptTag)); | 5012 Script::New(url_str, source_str, RawScript::kScriptTag)); |
4974 script.SetLocationOffset(line_offset, column_offset); | 5013 script.SetLocationOffset(line_offset, column_offset); |
4975 Dart_Handle result; | 5014 Dart_Handle result; |
4976 CompileSource(T, library, script, &result); | 5015 CompileSource(T, library, script, &result); |
4977 return result; | 5016 return result; |
4978 } | 5017 } |
4979 | 5018 |
4980 | 5019 |
4981 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, | 5020 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, |
4982 intptr_t buffer_len) { | 5021 intptr_t buffer_len) { |
4983 DARTSCOPE(Thread::Current()); | 5022 DARTSCOPE(Thread::Current()); |
rmacnak
2015/12/15 17:42:04
API_TIMELINE_DURATION
Cutch
2015/12/15 18:06:40
Done.
| |
4984 Isolate* I = T->isolate(); | 5023 Isolate* I = T->isolate(); |
4985 StackZone zone(T); | 5024 StackZone zone(T); |
4986 if (buffer == NULL) { | 5025 if (buffer == NULL) { |
4987 RETURN_NULL_ERROR(buffer); | 5026 RETURN_NULL_ERROR(buffer); |
4988 } | 5027 } |
4989 NoHeapGrowthControlScope no_growth_control; | 5028 NoHeapGrowthControlScope no_growth_control; |
4990 | 5029 |
4991 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 5030 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
4992 if (!snapshot->IsScriptSnapshot()) { | 5031 if (!snapshot->IsScriptSnapshot()) { |
4993 return Api::NewError("%s expects parameter 'buffer' to be a script type" | 5032 return Api::NewError("%s expects parameter 'buffer' to be a script type" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5188 } | 5227 } |
5189 } | 5228 } |
5190 return error_in; | 5229 return error_in; |
5191 } | 5230 } |
5192 | 5231 |
5193 | 5232 |
5194 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, | 5233 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, |
5195 Dart_Handle source, | 5234 Dart_Handle source, |
5196 intptr_t line_offset, | 5235 intptr_t line_offset, |
5197 intptr_t column_offset) { | 5236 intptr_t column_offset) { |
5198 DARTSCOPE(Thread::Current()); | 5237 DARTSCOPE(Thread::Current()); |
rmacnak
2015/12/15 17:42:04
API_TIMELINE_DURATION
Cutch
2015/12/15 18:06:39
Done.
| |
5199 Isolate* I = T->isolate(); | 5238 Isolate* I = T->isolate(); |
5200 const String& url_str = Api::UnwrapStringHandle(Z, url); | 5239 const String& url_str = Api::UnwrapStringHandle(Z, url); |
5201 if (url_str.IsNull()) { | 5240 if (url_str.IsNull()) { |
5202 RETURN_TYPE_ERROR(Z, url, String); | 5241 RETURN_TYPE_ERROR(Z, url, String); |
5203 } | 5242 } |
5204 const String& source_str = Api::UnwrapStringHandle(Z, source); | 5243 const String& source_str = Api::UnwrapStringHandle(Z, source); |
5205 if (source_str.IsNull()) { | 5244 if (source_str.IsNull()) { |
5206 RETURN_TYPE_ERROR(Z, source, String); | 5245 RETURN_TYPE_ERROR(Z, source, String); |
5207 } | 5246 } |
5208 if (line_offset < 0) { | 5247 if (line_offset < 0) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5293 } | 5332 } |
5294 return Api::Success(); | 5333 return Api::Success(); |
5295 } | 5334 } |
5296 | 5335 |
5297 | 5336 |
5298 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, | 5337 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, |
5299 Dart_Handle url, | 5338 Dart_Handle url, |
5300 Dart_Handle source, | 5339 Dart_Handle source, |
5301 intptr_t line_offset, | 5340 intptr_t line_offset, |
5302 intptr_t column_offset) { | 5341 intptr_t column_offset) { |
5303 DARTSCOPE(Thread::Current()); | 5342 DARTSCOPE(Thread::Current()); |
rmacnak
2015/12/15 17:42:04
API_TIMELINE_DURATION
Cutch
2015/12/15 18:06:40
Done.
| |
5304 Isolate* I = T->isolate(); | 5343 Isolate* I = T->isolate(); |
5305 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5344 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
5306 if (lib.IsNull()) { | 5345 if (lib.IsNull()) { |
5307 RETURN_TYPE_ERROR(Z, library, Library); | 5346 RETURN_TYPE_ERROR(Z, library, Library); |
5308 } | 5347 } |
5309 const String& url_str = Api::UnwrapStringHandle(Z, url); | 5348 const String& url_str = Api::UnwrapStringHandle(Z, url); |
5310 if (url_str.IsNull()) { | 5349 if (url_str.IsNull()) { |
5311 RETURN_TYPE_ERROR(Z, url, String); | 5350 RETURN_TYPE_ERROR(Z, url, String); |
5312 } | 5351 } |
5313 const String& source_str = Api::UnwrapStringHandle(Z, source); | 5352 const String& source_str = Api::UnwrapStringHandle(Z, source); |
(...skipping 18 matching lines...) Expand all Loading... | |
5332 script.SetLocationOffset(line_offset, column_offset); | 5371 script.SetLocationOffset(line_offset, column_offset); |
5333 Dart_Handle result; | 5372 Dart_Handle result; |
5334 CompileSource(T, lib, script, &result); | 5373 CompileSource(T, lib, script, &result); |
5335 return result; | 5374 return result; |
5336 } | 5375 } |
5337 | 5376 |
5338 | 5377 |
5339 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, | 5378 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, |
5340 Dart_Handle url, | 5379 Dart_Handle url, |
5341 Dart_Handle patch_source) { | 5380 Dart_Handle patch_source) { |
5342 DARTSCOPE(Thread::Current()); | 5381 DARTSCOPE(Thread::Current()); |
rmacnak
2015/12/15 17:42:04
API_TIMELINE_DURATION
Cutch
2015/12/15 18:06:40
Done.
| |
5343 Isolate* I = T->isolate(); | 5382 Isolate* I = T->isolate(); |
5344 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5383 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
5345 if (lib.IsNull()) { | 5384 if (lib.IsNull()) { |
5346 RETURN_TYPE_ERROR(Z, library, Library); | 5385 RETURN_TYPE_ERROR(Z, library, Library); |
5347 } | 5386 } |
5348 const String& url_str = Api::UnwrapStringHandle(Z, url); | 5387 const String& url_str = Api::UnwrapStringHandle(Z, url); |
5349 if (url_str.IsNull()) { | 5388 if (url_str.IsNull()) { |
5350 RETURN_TYPE_ERROR(Z, url, String); | 5389 RETURN_TYPE_ERROR(Z, url, String); |
5351 } | 5390 } |
5352 const String& source_str = Api::UnwrapStringHandle(Z, patch_source); | 5391 const String& source_str = Api::UnwrapStringHandle(Z, patch_source); |
5353 if (source_str.IsNull()) { | 5392 if (source_str.IsNull()) { |
5354 RETURN_TYPE_ERROR(Z, patch_source, String); | 5393 RETURN_TYPE_ERROR(Z, patch_source, String); |
5355 } | 5394 } |
5356 CHECK_CALLBACK_STATE(T); | 5395 CHECK_CALLBACK_STATE(T); |
5357 CHECK_COMPILATION_ALLOWED(I); | 5396 CHECK_COMPILATION_ALLOWED(I); |
5358 | 5397 |
5359 NoHeapGrowthControlScope no_growth_control; | 5398 NoHeapGrowthControlScope no_growth_control; |
5360 | 5399 |
5361 const Script& script = Script::Handle(Z, | 5400 const Script& script = Script::Handle(Z, |
5362 Script::New(url_str, source_str, RawScript::kPatchTag)); | 5401 Script::New(url_str, source_str, RawScript::kPatchTag)); |
5363 Dart_Handle result; | 5402 Dart_Handle result; |
5364 CompileSource(T, lib, script, &result); | 5403 CompileSource(T, lib, script, &result); |
5365 return result; | 5404 return result; |
5366 } | 5405 } |
5367 | 5406 |
5368 | 5407 |
5369 // Finalizes classes and invokes Dart core library function that completes | 5408 // Finalizes classes and invokes Dart core library function that completes |
5370 // futures of loadLibrary calls (deferred library loading). | 5409 // futures of loadLibrary calls (deferred library loading). |
5371 DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures) { | 5410 DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures) { |
5372 DARTSCOPE(Thread::Current()); | 5411 DARTSCOPE(Thread::Current()); |
rmacnak
2015/12/15 17:42:04
API_TIMELINE_DURATION
Cutch
2015/12/15 18:06:39
Done.
| |
5373 Isolate* I = T->isolate(); | 5412 Isolate* I = T->isolate(); |
5374 CHECK_CALLBACK_STATE(T); | 5413 CHECK_CALLBACK_STATE(T); |
5375 | 5414 |
5376 I->DoneLoading(); | 5415 I->DoneLoading(); |
5377 | 5416 |
5378 // TODO(hausner): move the remaining code below (finalization and | 5417 // TODO(hausner): move the remaining code below (finalization and |
5379 // invoing of _completeDeferredLoads) into Isolate::DoneLoading(). | 5418 // invoing of _completeDeferredLoads) into Isolate::DoneLoading(). |
5380 | 5419 |
5381 // Finalize all classes if needed. | 5420 // Finalize all classes if needed. |
5382 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); | 5421 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5867 event->AsyncEnd(label, async_id); | 5906 event->AsyncEnd(label, async_id); |
5868 event->Complete(); | 5907 event->Complete(); |
5869 } | 5908 } |
5870 return Api::Success(); | 5909 return Api::Success(); |
5871 } | 5910 } |
5872 | 5911 |
5873 | 5912 |
5874 DART_EXPORT Dart_Handle Dart_Precompile( | 5913 DART_EXPORT Dart_Handle Dart_Precompile( |
5875 Dart_QualifiedFunctionName entry_points[], | 5914 Dart_QualifiedFunctionName entry_points[], |
5876 bool reset_fields) { | 5915 bool reset_fields) { |
5877 DARTSCOPE(Thread::Current()); | 5916 DARTSCOPE(Thread::Current()); |
rmacnak
2015/12/15 17:42:04
API_TIMELINE_BEGIN_END
Cutch
2015/12/15 18:06:40
Done.
| |
5878 if (!FLAG_precompilation) { | 5917 if (!FLAG_precompilation) { |
5879 return Dart_NewApiError("Flag --precompilation was not specified."); | 5918 return Dart_NewApiError("Flag --precompilation was not specified."); |
5880 } | 5919 } |
5881 Dart_Handle result = Api::CheckAndFinalizePendingClasses(T); | 5920 Dart_Handle result = Api::CheckAndFinalizePendingClasses(T); |
5882 if (::Dart_IsError(result)) { | 5921 if (::Dart_IsError(result)) { |
5883 return result; | 5922 return result; |
5884 } | 5923 } |
5885 CHECK_CALLBACK_STATE(T); | 5924 CHECK_CALLBACK_STATE(T); |
5886 const Error& error = Error::Handle(Precompiler::CompileAll(entry_points, | 5925 const Error& error = Error::Handle(Precompiler::CompileAll(entry_points, |
5887 reset_fields)); | 5926 reset_fields)); |
5888 if (!error.IsNull()) { | 5927 if (!error.IsNull()) { |
5889 return Api::NewHandle(T, error.raw()); | 5928 return Api::NewHandle(T, error.raw()); |
5890 } | 5929 } |
5891 return Api::Success(); | 5930 return Api::Success(); |
5892 } | 5931 } |
5893 | 5932 |
5894 | 5933 |
5895 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshot( | 5934 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshot( |
5896 uint8_t** vm_isolate_snapshot_buffer, | 5935 uint8_t** vm_isolate_snapshot_buffer, |
5897 intptr_t* vm_isolate_snapshot_size, | 5936 intptr_t* vm_isolate_snapshot_size, |
5898 uint8_t** isolate_snapshot_buffer, | 5937 uint8_t** isolate_snapshot_buffer, |
5899 intptr_t* isolate_snapshot_size, | 5938 intptr_t* isolate_snapshot_size, |
5900 uint8_t** instructions_snapshot_buffer, | 5939 uint8_t** instructions_snapshot_buffer, |
5901 intptr_t* instructions_snapshot_size) { | 5940 intptr_t* instructions_snapshot_size) { |
5902 ASSERT(FLAG_load_deferred_eagerly); | 5941 ASSERT(FLAG_load_deferred_eagerly); |
rmacnak
2015/12/15 17:42:04
API_TIMELINE_DURATION
Cutch
2015/12/15 18:06:40
Done.
| |
5903 DARTSCOPE(Thread::Current()); | 5942 DARTSCOPE(Thread::Current()); |
5904 Isolate* I = T->isolate(); | 5943 Isolate* I = T->isolate(); |
5905 if (I->compilation_allowed()) { | 5944 if (I->compilation_allowed()) { |
5906 return Dart_NewApiError("Isolate is not precompiled. " | 5945 return Dart_NewApiError("Isolate is not precompiled. " |
5907 "Did you forget to call Dart_Precompile?"); | 5946 "Did you forget to call Dart_Precompile?"); |
5908 } | 5947 } |
5909 if (vm_isolate_snapshot_buffer == NULL) { | 5948 if (vm_isolate_snapshot_buffer == NULL) { |
5910 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); | 5949 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); |
5911 } | 5950 } |
5912 if (vm_isolate_snapshot_size == NULL) { | 5951 if (vm_isolate_snapshot_size == NULL) { |
(...skipping 23 matching lines...) Expand all Loading... | |
5936 ApiReallocate); | 5975 ApiReallocate); |
5937 writer.WriteFullSnapshot(); | 5976 writer.WriteFullSnapshot(); |
5938 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 5977 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
5939 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 5978 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
5940 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); | 5979 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); |
5941 | 5980 |
5942 return Api::Success(); | 5981 return Api::Success(); |
5943 } | 5982 } |
5944 | 5983 |
5945 } // namespace dart | 5984 } // namespace dart |
OLD | NEW |