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

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

Issue 11362009: New APIs for external byte arrays (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments 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/include/dart_api.h ('k') | runtime/vm/dart_api_impl_test.cc » ('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 1592 matching lines...) Expand 10 before | Expand all | Expand 10 after
1603 void** peer) { 1603 void** peer) {
1604 if (peer == NULL) { 1604 if (peer == NULL) {
1605 RETURN_NULL_ERROR(peer); 1605 RETURN_NULL_ERROR(peer);
1606 } 1606 }
1607 1607
1608 if (Api::ExternalStringGetPeerHelper(object, peer)) { 1608 if (Api::ExternalStringGetPeerHelper(object, peer)) {
1609 return Api::Success(Isolate::Current()); 1609 return Api::Success(Isolate::Current());
1610 } 1610 }
1611 1611
1612 // It's not an external string, return appropriate error. 1612 // It's not an external string, return appropriate error.
1613 // Note: this is invoked outside of the NoGCScope'd block above, since
1614 // error messages allocate new handles.
1615 if (!RawObject::IsStringClassId(Api::ClassId(object))) { 1613 if (!RawObject::IsStringClassId(Api::ClassId(object))) {
1616 RETURN_TYPE_ERROR(Isolate::Current(), object, String); 1614 RETURN_TYPE_ERROR(Isolate::Current(), object, String);
1617 } else { 1615 } else {
1618 return 1616 return
1619 Api::NewError( 1617 Api::NewError(
1620 "%s expects argument 'object' to be an external String.", 1618 "%s expects argument 'object' to be an external String.",
1621 CURRENT_FUNC); 1619 CURRENT_FUNC);
1622 } 1620 }
1623 } 1621 }
1624 1622
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
2164 2162
2165 2163
2166 // --- Byte Arrays --- 2164 // --- Byte Arrays ---
2167 2165
2168 2166
2169 DART_EXPORT bool Dart_IsByteArray(Dart_Handle object) { 2167 DART_EXPORT bool Dart_IsByteArray(Dart_Handle object) {
2170 return RawObject::IsByteArrayClassId(Api::ClassId(object)); 2168 return RawObject::IsByteArrayClassId(Api::ClassId(object));
2171 } 2169 }
2172 2170
2173 2171
2172 DART_EXPORT bool Dart_IsByteArrayExternal(Dart_Handle object) {
2173 return RawObject::IsExternalByteArrayClassId(Api::ClassId(object));
2174 }
2175
2176
2174 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) { 2177 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) {
2175 Isolate* isolate = Isolate::Current(); 2178 Isolate* isolate = Isolate::Current();
2176 DARTSCOPE(isolate); 2179 DARTSCOPE(isolate);
2177 CHECK_LENGTH(length, Uint8Array::kMaxElements); 2180 CHECK_LENGTH(length, Uint8Array::kMaxElements);
2178 return Api::NewHandle(isolate, Uint8Array::New(length)); 2181 return Api::NewHandle(isolate, Uint8Array::New(length));
2179 } 2182 }
2180 2183
2181 2184
2182 DART_EXPORT Dart_Handle Dart_NewExternalByteArray(uint8_t* data, 2185 DART_EXPORT Dart_Handle Dart_NewExternalByteArray(uint8_t* data,
2183 intptr_t length, 2186 intptr_t length,
2184 void* peer, 2187 void* peer,
2185 Dart_PeerFinalizer callback) { 2188 Dart_PeerFinalizer callback) {
2186 Isolate* isolate = Isolate::Current(); 2189 Isolate* isolate = Isolate::Current();
2187 DARTSCOPE(isolate); 2190 DARTSCOPE(isolate);
2188 if (data == NULL && length != 0) { 2191 if (data == NULL && length != 0) {
2189 RETURN_NULL_ERROR(data); 2192 RETURN_NULL_ERROR(data);
2190 } 2193 }
2191 CHECK_LENGTH(length, ExternalUint8Array::kMaxElements); 2194 CHECK_LENGTH(length, ExternalUint8Array::kMaxElements);
2192 return Api::NewHandle( 2195 return Api::NewHandle(
2193 isolate, ExternalUint8Array::New(data, length, peer, callback)); 2196 isolate, ExternalUint8Array::New(data, length, peer, callback));
2194 } 2197 }
2195 2198
2196 2199
2200 DART_EXPORT Dart_Handle Dart_ExternalByteArrayGetData(Dart_Handle object,
2201 void** data) {
2202 Isolate* isolate = Isolate::Current();
2203 DARTSCOPE(isolate);
2204 const ExternalUint8Array& array =
2205 Api::UnwrapExternalUint8ArrayHandle(isolate, object);
2206 if (array.IsNull()) {
2207 RETURN_TYPE_ERROR(isolate, object, ExternalUint8Array);
2208 }
2209 if (data == NULL) {
2210 RETURN_NULL_ERROR(data);
2211 }
2212 *data = array.GetData();
2213 return Api::Success(isolate);
2214 }
2215
2216
2197 DART_EXPORT Dart_Handle Dart_ExternalByteArrayGetPeer(Dart_Handle object, 2217 DART_EXPORT Dart_Handle Dart_ExternalByteArrayGetPeer(Dart_Handle object,
2198 void** peer) { 2218 void** peer) {
2199 Isolate* isolate = Isolate::Current(); 2219 Isolate* isolate = Isolate::Current();
2200 DARTSCOPE(isolate); 2220 DARTSCOPE(isolate);
2201 const ExternalUint8Array& array = 2221 const ExternalUint8Array& array =
2202 Api::UnwrapExternalUint8ArrayHandle(isolate, object); 2222 Api::UnwrapExternalUint8ArrayHandle(isolate, object);
2203 if (array.IsNull()) { 2223 if (array.IsNull()) {
2204 RETURN_TYPE_ERROR(isolate, object, ExternalUint8Array); 2224 RETURN_TYPE_ERROR(isolate, object, ExternalUint8Array);
2205 } 2225 }
2206 if (peer == NULL) { 2226 if (peer == NULL) {
(...skipping 2330 matching lines...) Expand 10 before | Expand all | Expand 10 after
4537 } 4557 }
4538 { 4558 {
4539 NoGCScope no_gc; 4559 NoGCScope no_gc;
4540 RawObject* raw_obj = obj.raw(); 4560 RawObject* raw_obj = obj.raw();
4541 isolate->heap()->SetPeer(raw_obj, peer); 4561 isolate->heap()->SetPeer(raw_obj, peer);
4542 } 4562 }
4543 return Api::Success(isolate); 4563 return Api::Success(isolate);
4544 } 4564 }
4545 4565
4546 } // namespace dart 4566 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698