| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 | 6 |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| (...skipping 1510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1521 } | 1521 } |
| 1522 | 1522 |
| 1523 | 1523 |
| 1524 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { | 1524 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { |
| 1525 return RawObject::IsExternalStringClassId(Api::ClassId(object)); | 1525 return RawObject::IsExternalStringClassId(Api::ClassId(object)); |
| 1526 } | 1526 } |
| 1527 | 1527 |
| 1528 | 1528 |
| 1529 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, | 1529 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, |
| 1530 void** peer) { | 1530 void** peer) { |
| 1531 Isolate* isolate = Isolate::Current(); | 1531 intptr_t class_id = Api::ClassId(object); |
| 1532 DARTSCOPE(isolate); | |
| 1533 const String& str = Api::UnwrapStringHandle(isolate, object); | |
| 1534 if (str.IsNull()) { | |
| 1535 RETURN_TYPE_ERROR(isolate, object, String); | |
| 1536 } | |
| 1537 if (!str.IsExternal()) { | |
| 1538 return | |
| 1539 Api::NewError("%s expects argument 'object' to be an external String.", | |
| 1540 CURRENT_FUNC); | |
| 1541 } | |
| 1542 if (peer == NULL) { | 1532 if (peer == NULL) { |
| 1543 RETURN_NULL_ERROR(peer); | 1533 RETURN_NULL_ERROR(peer); |
| 1534 } else { |
| 1535 NoGCScope no_gc_scope; |
| 1536 RawObject* raw_obj = Api::UnwrapHandle(object); |
| 1537 switch (class_id) { |
| 1538 case kExternalOneByteStringCid: { |
| 1539 RawExternalOneByteString* raw_string = |
| 1540 reinterpret_cast<RawExternalOneByteString*>(raw_obj)->ptr(); |
| 1541 ExternalStringData<uint8_t>* data = raw_string->external_data_; |
| 1542 *peer = data->peer(); |
| 1543 return Api::Success(Isolate::Current()); |
| 1544 } |
| 1545 case kExternalTwoByteStringCid: { |
| 1546 RawExternalTwoByteString* raw_string = |
| 1547 reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr(); |
| 1548 ExternalStringData<uint16_t>* data = raw_string->external_data_; |
| 1549 *peer = data->peer(); |
| 1550 return Api::Success(Isolate::Current()); |
| 1551 } |
| 1552 case kExternalFourByteStringCid: { |
| 1553 RawExternalFourByteString* raw_string = |
| 1554 reinterpret_cast<RawExternalFourByteString*>(raw_obj)->ptr(); |
| 1555 ExternalStringData<uint32_t>* data = raw_string->external_data_; |
| 1556 *peer = data->peer(); |
| 1557 return Api::Success(Isolate::Current()); |
| 1558 } |
| 1559 } |
| 1544 } | 1560 } |
| 1545 *peer = str.GetPeer(); | 1561 |
| 1546 return Api::Success(isolate); | 1562 // It's not an external string, return appropriate error. |
| 1563 // Note: this is invoked outside of the NoGCScope'd block above, since |
| 1564 // error messages allocate new handles. |
| 1565 if (!RawObject::IsStringClassId(class_id)) { |
| 1566 RETURN_TYPE_ERROR(Isolate::Current(), object, String); |
| 1567 } else { |
| 1568 return |
| 1569 Api::NewError( |
| 1570 "%s expects argument 'object' to be an external String.", |
| 1571 CURRENT_FUNC); |
| 1572 } |
| 1547 } | 1573 } |
| 1548 | 1574 |
| 1549 | 1575 |
| 1550 DART_EXPORT Dart_Handle Dart_NewExternalString8(const uint8_t* codepoints, | 1576 DART_EXPORT Dart_Handle Dart_NewExternalString8(const uint8_t* codepoints, |
| 1551 intptr_t length, | 1577 intptr_t length, |
| 1552 void* peer, | 1578 void* peer, |
| 1553 Dart_PeerFinalizer callback) { | 1579 Dart_PeerFinalizer callback) { |
| 1554 Isolate* isolate = Isolate::Current(); | 1580 Isolate* isolate = Isolate::Current(); |
| 1555 DARTSCOPE(isolate); | 1581 DARTSCOPE(isolate); |
| 1556 if (codepoints == NULL && length != 0) { | 1582 if (codepoints == NULL && length != 0) { |
| (...skipping 2596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4153 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { | 4179 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { |
| 4154 Dart::set_perf_events_writer(function); | 4180 Dart::set_perf_events_writer(function); |
| 4155 } | 4181 } |
| 4156 | 4182 |
| 4157 | 4183 |
| 4158 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { | 4184 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { |
| 4159 Dart::set_flow_graph_writer(function); | 4185 Dart::set_flow_graph_writer(function); |
| 4160 } | 4186 } |
| 4161 | 4187 |
| 4162 } // namespace dart | 4188 } // namespace dart |
| OLD | NEW |