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

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

Issue 11364134: Merge libv1. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Reupload due to error Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/flow_graph_inliner.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 135
136 #define DEFINE_UNWRAP(type) \ 136 #define DEFINE_UNWRAP(type) \
137 const type& Api::Unwrap##type##Handle(Isolate* iso, \ 137 const type& Api::Unwrap##type##Handle(Isolate* iso, \
138 Dart_Handle dart_handle) { \ 138 Dart_Handle dart_handle) { \
139 const Object& obj = Object::Handle(iso, Api::UnwrapHandle(dart_handle)); \ 139 const Object& obj = Object::Handle(iso, Api::UnwrapHandle(dart_handle)); \
140 if (obj.Is##type()) { \ 140 if (obj.Is##type()) { \
141 return type::Cast(obj); \ 141 return type::Cast(obj); \
142 } \ 142 } \
143 return type::Handle(iso); \ 143 return type::Handle(iso); \
144 } 144 }
145 CLASS_LIST_NO_OBJECT(DEFINE_UNWRAP) 145 CLASS_LIST_FOR_HANDLES(DEFINE_UNWRAP)
146 #undef DEFINE_UNWRAP 146 #undef DEFINE_UNWRAP
147 147
148 148
149 LocalHandle* Api::UnwrapAsLocalHandle(const ApiState& state, 149 LocalHandle* Api::UnwrapAsLocalHandle(const ApiState& state,
150 Dart_Handle object) { 150 Dart_Handle object) {
151 ASSERT(state.IsValidLocalHandle(object)); 151 ASSERT(state.IsValidLocalHandle(object));
152 return reinterpret_cast<LocalHandle*>(object); 152 return reinterpret_cast<LocalHandle*>(object);
153 } 153 }
154 154
155 155
(...skipping 1479 matching lines...) Expand 10 before | Expand all | Expand 10 after
1635 CHECK_LENGTH(length, String::kMaxElements); 1635 CHECK_LENGTH(length, String::kMaxElements);
1636 return Api::NewHandle(isolate, 1636 return Api::NewHandle(isolate,
1637 String::NewExternal(utf16_array, length, peer, cback)); 1637 String::NewExternal(utf16_array, length, peer, cback));
1638 } 1638 }
1639 1639
1640 1640
1641 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, 1641 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object,
1642 const char** cstr) { 1642 const char** cstr) {
1643 Isolate* isolate = Isolate::Current(); 1643 Isolate* isolate = Isolate::Current();
1644 DARTSCOPE(isolate); 1644 DARTSCOPE(isolate);
1645 if (cstr == NULL) {
1646 RETURN_NULL_ERROR(cstr);
1647 }
1645 const String& str_obj = Api::UnwrapStringHandle(isolate, object); 1648 const String& str_obj = Api::UnwrapStringHandle(isolate, object);
1646 if (str_obj.IsNull()) { 1649 if (str_obj.IsNull()) {
1647 RETURN_TYPE_ERROR(isolate, object, String); 1650 RETURN_TYPE_ERROR(isolate, object, String);
1648 } 1651 }
1649 intptr_t string_length = Utf8::Length(str_obj); 1652 intptr_t string_length = Utf8::Length(str_obj);
1650 char* res = Api::TopScope(isolate)->zone()->Alloc<char>(string_length + 1); 1653 char* res = Api::TopScope(isolate)->zone()->Alloc<char>(string_length + 1);
1651 if (res == NULL) { 1654 if (res == NULL) {
1652 return Api::NewError("Unable to allocate memory"); 1655 return Api::NewError("Unable to allocate memory");
1653 } 1656 }
1654 const char* string_value = str_obj.ToCString(); 1657 const char* string_value = str_obj.ToCString();
1655 memmove(res, string_value, string_length + 1); 1658 memmove(res, string_value, string_length + 1);
1656 ASSERT(res[string_length] == '\0'); 1659 ASSERT(res[string_length] == '\0');
1657 *cstr = res; 1660 *cstr = res;
1658 return Api::Success(isolate); 1661 return Api::Success(isolate);
1659 } 1662 }
1660 1663
1661 1664
1662 DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str, 1665 DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str,
1663 uint8_t* utf8_array, 1666 uint8_t** utf8_array,
1664 intptr_t* length) { 1667 intptr_t* length) {
1665 Isolate* isolate = Isolate::Current(); 1668 Isolate* isolate = Isolate::Current();
1666 DARTSCOPE(isolate); 1669 DARTSCOPE(isolate);
1670 if (utf8_array == NULL) {
1671 RETURN_NULL_ERROR(utf8_array);
1672 }
1673 if (length == NULL) {
1674 RETURN_NULL_ERROR(length);
1675 }
1667 const String& str_obj = Api::UnwrapStringHandle(isolate, str); 1676 const String& str_obj = Api::UnwrapStringHandle(isolate, str);
1668 if (str_obj.IsNull()) { 1677 if (str_obj.IsNull()) {
1669 RETURN_TYPE_ERROR(isolate, str, String); 1678 RETURN_TYPE_ERROR(isolate, str, String);
1670 } 1679 }
1671 intptr_t str_len = str_obj.Length(); 1680 intptr_t str_len = Utf8::Length(str_obj);
1672 if (str_len > *length) { 1681 *utf8_array = Api::TopScope(isolate)->zone()->Alloc<uint8_t>(str_len);
1673 return Api::NewError("Input array is not large enough to hold the result"); 1682 if (*utf8_array == NULL) {
1683 return Api::NewError("Unable to allocate memory");
1674 } 1684 }
1675 str_obj.ToUTF8(utf8_array, str_len); 1685 str_obj.ToUTF8(*utf8_array, str_len);
1676 *length= str_len; 1686 *length = str_len;
1677 return Api::Success(isolate); 1687 return Api::Success(isolate);
1678 } 1688 }
1679 1689
1680 1690
1681 DART_EXPORT Dart_Handle Dart_StringToUTF16(Dart_Handle str, 1691 DART_EXPORT Dart_Handle Dart_StringToUTF16(Dart_Handle str,
1682 uint16_t* utf16_array, 1692 uint16_t* utf16_array,
1683 intptr_t* length) { 1693 intptr_t* length) {
1684 Isolate* isolate = Isolate::Current(); 1694 Isolate* isolate = Isolate::Current();
1685 DARTSCOPE(isolate); 1695 DARTSCOPE(isolate);
1686 const String& str_obj = Api::UnwrapStringHandle(isolate, str); 1696 const String& str_obj = Api::UnwrapStringHandle(isolate, str);
(...skipping 2747 matching lines...) Expand 10 before | Expand all | Expand 10 after
4434 } 4444 }
4435 { 4445 {
4436 NoGCScope no_gc; 4446 NoGCScope no_gc;
4437 RawObject* raw_obj = obj.raw(); 4447 RawObject* raw_obj = obj.raw();
4438 isolate->heap()->SetPeer(raw_obj, peer); 4448 isolate->heap()->SetPeer(raw_obj, peer);
4439 } 4449 }
4440 return Api::Success(isolate); 4450 return Api::Success(isolate);
4441 } 4451 }
4442 4452
4443 } // namespace dart 4453 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/flow_graph_inliner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698