Chromium Code Reviews| 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 1689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1700 intptr_t str_len = str_obj.Length(); | 1700 intptr_t str_len = str_obj.Length(); |
| 1701 intptr_t copy_len = (str_len > *length) ? *length : str_len; | 1701 intptr_t copy_len = (str_len > *length) ? *length : str_len; |
| 1702 for (intptr_t i = 0; i < copy_len; i++) { | 1702 for (intptr_t i = 0; i < copy_len; i++) { |
| 1703 utf16_array[i] = static_cast<uint16_t>(str_obj.CharAt(i)); | 1703 utf16_array[i] = static_cast<uint16_t>(str_obj.CharAt(i)); |
| 1704 } | 1704 } |
| 1705 *length = copy_len; | 1705 *length = copy_len; |
| 1706 return Api::Success(isolate); | 1706 return Api::Success(isolate); |
| 1707 } | 1707 } |
| 1708 | 1708 |
| 1709 | 1709 |
| 1710 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str, | |
| 1711 void* array, | |
| 1712 intptr_t length, | |
| 1713 void* peer, | |
| 1714 Dart_PeerFinalizer cback) { | |
| 1715 Isolate* isolate = Isolate::Current(); | |
| 1716 DARTSCOPE(isolate); | |
| 1717 const String& str_obj = Api::UnwrapStringHandle(isolate, str); | |
| 1718 if (str_obj.IsNull() || str_obj.IsExternal()) { | |
| 1719 RETURN_TYPE_ERROR(isolate, str, String); | |
|
Tom Ball
2012/11/07 00:38:43
Is passing in an external string necessarily an er
siva
2012/11/07 21:43:27
Yes we could.
Does that make sense however, it se
| |
| 1720 } | |
| 1721 if (array == NULL) { | |
| 1722 RETURN_NULL_ERROR(array); | |
| 1723 } | |
| 1724 intptr_t str_length = (str_obj.Length() * str_obj.CharSize()); | |
| 1725 if ((length < str_length) || (length > String::kMaxElements)) { | |
| 1726 return Api::NewError("Dart_MakeExternalString " | |
| 1727 "expects argument length to be in the range" | |
| 1728 "[%"Pd"..%"Pd"].", | |
| 1729 str_length, String::kMaxElements); | |
| 1730 } | |
| 1731 return Api::NewHandle(isolate, | |
| 1732 str_obj.MakeExternal(array, length, peer, cback)); | |
| 1733 } | |
| 1734 | |
| 1735 | |
| 1710 // --- Lists --- | 1736 // --- Lists --- |
| 1711 | 1737 |
| 1712 | 1738 |
| 1713 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) { | 1739 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) { |
| 1714 if (obj.IsInstance()) { | 1740 if (obj.IsInstance()) { |
| 1715 const Instance& instance = Instance::Cast(obj); | 1741 const Instance& instance = Instance::Cast(obj); |
| 1716 const Type& type = | 1742 const Type& type = |
| 1717 Type::Handle(isolate, isolate->object_store()->list_interface()); | 1743 Type::Handle(isolate, isolate->object_store()->list_interface()); |
| 1718 Error& malformed_type_error = Error::Handle(isolate); | 1744 Error& malformed_type_error = Error::Handle(isolate); |
| 1719 if (instance.IsInstanceOf(type, | 1745 if (instance.IsInstanceOf(type, |
| (...skipping 2724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4444 } | 4470 } |
| 4445 { | 4471 { |
| 4446 NoGCScope no_gc; | 4472 NoGCScope no_gc; |
| 4447 RawObject* raw_obj = obj.raw(); | 4473 RawObject* raw_obj = obj.raw(); |
| 4448 isolate->heap()->SetPeer(raw_obj, peer); | 4474 isolate->heap()->SetPeer(raw_obj, peer); |
| 4449 } | 4475 } |
| 4450 return Api::Success(isolate); | 4476 return Api::Success(isolate); |
| 4451 } | 4477 } |
| 4452 | 4478 |
| 4453 } // namespace dart | 4479 } // namespace dart |
| OLD | NEW |