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

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: 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
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_IsExternalByteArray(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
2185
cshapiro 2012/11/01 00:40:19 Remove this addition. Only 2 spaces between defin
Søren Gjesse 2012/11/01 07:46:03 Done.
2182 DART_EXPORT Dart_Handle Dart_NewExternalByteArray(uint8_t* data, 2186 DART_EXPORT Dart_Handle Dart_NewExternalByteArray(uint8_t* data,
2183 intptr_t length, 2187 intptr_t length,
2184 void* peer, 2188 void* peer,
2185 Dart_PeerFinalizer callback) { 2189 Dart_PeerFinalizer callback) {
2186 Isolate* isolate = Isolate::Current(); 2190 Isolate* isolate = Isolate::Current();
2187 DARTSCOPE(isolate); 2191 DARTSCOPE(isolate);
2188 if (data == NULL && length != 0) { 2192 if (data == NULL && length != 0) {
2189 RETURN_NULL_ERROR(data); 2193 RETURN_NULL_ERROR(data);
2190 } 2194 }
2191 CHECK_LENGTH(length, ExternalUint8Array::kMaxElements); 2195 CHECK_LENGTH(length, ExternalUint8Array::kMaxElements);
2192 return Api::NewHandle( 2196 return Api::NewHandle(
2193 isolate, ExternalUint8Array::New(data, length, peer, callback)); 2197 isolate, ExternalUint8Array::New(data, length, peer, callback));
2194 } 2198 }
2195 2199
2196 2200
2201 DART_EXPORT Dart_Handle Dart_ExternalByteArrayGetData(Dart_Handle object,
2202 void** data) {
2203 Isolate* isolate = Isolate::Current();
2204 DARTSCOPE(isolate);
2205 const ExternalUint8Array& array =
2206 Api::UnwrapExternalUint8ArrayHandle(isolate, object);
2207 if (array.IsNull()) {
2208 RETURN_TYPE_ERROR(isolate, object, ExternalUint8Array);
2209 }
2210 if (data == NULL) {
2211 RETURN_NULL_ERROR(data);
2212 }
2213 *data = array.GetData();
2214 return Api::Success(isolate);
2215 }
2216
2217
2197 DART_EXPORT Dart_Handle Dart_ExternalByteArrayGetPeer(Dart_Handle object, 2218 DART_EXPORT Dart_Handle Dart_ExternalByteArrayGetPeer(Dart_Handle object,
2198 void** peer) { 2219 void** peer) {
2199 Isolate* isolate = Isolate::Current(); 2220 Isolate* isolate = Isolate::Current();
2200 DARTSCOPE(isolate); 2221 DARTSCOPE(isolate);
2201 const ExternalUint8Array& array = 2222 const ExternalUint8Array& array =
2202 Api::UnwrapExternalUint8ArrayHandle(isolate, object); 2223 Api::UnwrapExternalUint8ArrayHandle(isolate, object);
2203 if (array.IsNull()) { 2224 if (array.IsNull()) {
2204 RETURN_TYPE_ERROR(isolate, object, ExternalUint8Array); 2225 RETURN_TYPE_ERROR(isolate, object, ExternalUint8Array);
2205 } 2226 }
2206 if (peer == NULL) { 2227 if (peer == NULL) {
(...skipping 2330 matching lines...) Expand 10 before | Expand all | Expand 10 after
4537 } 4558 }
4538 { 4559 {
4539 NoGCScope no_gc; 4560 NoGCScope no_gc;
4540 RawObject* raw_obj = obj.raw(); 4561 RawObject* raw_obj = obj.raw();
4541 isolate->heap()->SetPeer(raw_obj, peer); 4562 isolate->heap()->SetPeer(raw_obj, peer);
4542 } 4563 }
4543 return Api::Success(isolate); 4564 return Api::Success(isolate);
4544 } 4565 }
4545 4566
4546 } // namespace dart 4567 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698