| 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" |
| 11 #include "vm/dart_api_impl.h" | 11 #include "vm/dart_api_impl.h" |
| 12 #include "vm/dart_api_message.h" | 12 #include "vm/dart_api_message.h" |
| 13 #include "vm/dart_api_state.h" | 13 #include "vm/dart_api_state.h" |
| 14 #include "vm/dart_entry.h" | 14 #include "vm/dart_entry.h" |
| 15 #include "vm/debuginfo.h" | 15 #include "vm/debuginfo.h" |
| 16 #include "vm/exceptions.h" | 16 #include "vm/exceptions.h" |
| 17 #include "vm/flags.h" | 17 #include "vm/flags.h" |
| 18 #include "vm/growable_array.h" | 18 #include "vm/growable_array.h" |
| 19 #include "vm/message.h" | 19 #include "vm/message.h" |
| 20 #include "vm/native_entry.h" | 20 #include "vm/native_entry.h" |
| 21 #include "vm/native_message_handler.h" | 21 #include "vm/native_message_handler.h" |
| 22 #include "vm/object.h" | 22 #include "vm/object.h" |
| 23 #include "vm/object_store.h" | 23 #include "vm/object_store.h" |
| 24 #include "vm/port.h" | 24 #include "vm/port.h" |
| 25 #include "vm/resolver.h" | 25 #include "vm/resolver.h" |
| 26 #include "vm/stack_frame.h" | 26 #include "vm/stack_frame.h" |
| 27 #include "vm/timer.h" | 27 #include "vm/timer.h" |
| 28 #include "vm/unicode.h" |
| 28 #include "vm/verifier.h" | 29 #include "vm/verifier.h" |
| 29 | 30 |
| 30 namespace dart { | 31 namespace dart { |
| 31 | 32 |
| 32 DECLARE_FLAG(bool, print_class_table); | 33 DECLARE_FLAG(bool, print_class_table); |
| 33 | 34 |
| 34 ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey; | 35 ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey; |
| 35 | 36 |
| 36 const char* CanonicalFunction(const char* func) { | 37 const char* CanonicalFunction(const char* func) { |
| 37 if (strncmp(func, "dart::", 6) == 0) { | 38 if (strncmp(func, "dart::", 6) == 0) { |
| (...skipping 1566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1604 } | 1605 } |
| 1605 strncpy(res, string_value, string_length + 1); | 1606 strncpy(res, string_value, string_length + 1); |
| 1606 ASSERT(res[string_length] == '\0'); | 1607 ASSERT(res[string_length] == '\0'); |
| 1607 *result = res; | 1608 *result = res; |
| 1608 return Api::Success(isolate); | 1609 return Api::Success(isolate); |
| 1609 } | 1610 } |
| 1610 return Api::NewError("Object is not a String"); | 1611 return Api::NewError("Object is not a String"); |
| 1611 } | 1612 } |
| 1612 | 1613 |
| 1613 | 1614 |
| 1615 DART_EXPORT Dart_Handle Dart_StringToBytes(Dart_Handle object, |
| 1616 const uint8_t** bytes, |
| 1617 intptr_t *length) { |
| 1618 Isolate* isolate = Isolate::Current(); |
| 1619 DARTSCOPE(isolate); |
| 1620 const String& str = Api::UnwrapStringHandle(isolate, object); |
| 1621 if (str.IsNull()) { |
| 1622 RETURN_TYPE_ERROR(isolate, object, String); |
| 1623 } |
| 1624 if (bytes == NULL) { |
| 1625 return Api::NewError("%s expects argument 'bytes' to be non-null.", |
| 1626 CURRENT_FUNC); |
| 1627 } |
| 1628 if (length == NULL) { |
| 1629 return Api::NewError("%s expects argument 'length' to be non-null.", |
| 1630 CURRENT_FUNC); |
| 1631 } |
| 1632 const char* cstring = str.ToCString(); |
| 1633 *length = Utf8::Length(str); |
| 1634 char* result = reinterpret_cast<char*>(Api::Allocate(isolate, *length)); |
| 1635 if (result == NULL) { |
| 1636 return Api::NewError("Unable to allocate memory"); |
| 1637 } |
| 1638 memmove(result, cstring, *length); |
| 1639 *bytes = result; |
| 1640 return Api::Success(isolate); |
| 1641 } |
| 1642 |
| 1643 |
| 1614 // --- Lists --- | 1644 // --- Lists --- |
| 1615 | 1645 |
| 1616 | 1646 |
| 1617 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) { | 1647 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) { |
| 1618 if (obj.IsInstance()) { | 1648 if (obj.IsInstance()) { |
| 1619 Instance& instance = Instance::Handle(isolate); | 1649 Instance& instance = Instance::Handle(isolate); |
| 1620 instance ^= obj.raw(); | 1650 instance ^= obj.raw(); |
| 1621 const Type& type = | 1651 const Type& type = |
| 1622 Type::Handle(isolate, isolate->object_store()->list_interface()); | 1652 Type::Handle(isolate, isolate->object_store()->list_interface()); |
| 1623 Error& malformed_type_error = Error::Handle(isolate); | 1653 Error& malformed_type_error = Error::Handle(isolate); |
| (...skipping 1668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3292 *buffer = NULL; | 3322 *buffer = NULL; |
| 3293 } | 3323 } |
| 3294 delete debug_region; | 3324 delete debug_region; |
| 3295 } else { | 3325 } else { |
| 3296 *buffer = NULL; | 3326 *buffer = NULL; |
| 3297 *buffer_size = 0; | 3327 *buffer_size = 0; |
| 3298 } | 3328 } |
| 3299 } | 3329 } |
| 3300 | 3330 |
| 3301 } // namespace dart | 3331 } // namespace dart |
| OLD | NEW |