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

Side by Side Diff: runtime/bin/dartutils.h

Issue 23532048: Checks for valid CObject lengths in native API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments. Created 7 years, 3 months 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 | « no previous file | runtime/bin/dartutils.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 #ifndef BIN_DARTUTILS_H_ 5 #ifndef BIN_DARTUTILS_H_
6 #define BIN_DARTUTILS_H_ 6 #define BIN_DARTUTILS_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "include/dart_native_api.h" 9 #include "include/dart_native_api.h"
10 10
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 264
265 static CObject* Null(); 265 static CObject* Null();
266 static CObject* True(); 266 static CObject* True();
267 static CObject* False(); 267 static CObject* False();
268 static CObject* Bool(bool value); 268 static CObject* Bool(bool value);
269 static Dart_CObject* NewInt32(int32_t value); 269 static Dart_CObject* NewInt32(int32_t value);
270 static Dart_CObject* NewInt64(int64_t value); 270 static Dart_CObject* NewInt64(int64_t value);
271 static Dart_CObject* NewIntptr(intptr_t value); 271 static Dart_CObject* NewIntptr(intptr_t value);
272 // TODO(sgjesse): Add support for kBigint. 272 // TODO(sgjesse): Add support for kBigint.
273 static Dart_CObject* NewDouble(double value); 273 static Dart_CObject* NewDouble(double value);
274 static Dart_CObject* NewString(int length); 274 static Dart_CObject* NewString(intptr_t length);
275 static Dart_CObject* NewString(const char* str); 275 static Dart_CObject* NewString(const char* str);
276 static Dart_CObject* NewArray(int length); 276 static Dart_CObject* NewArray(intptr_t length);
277 static Dart_CObject* NewUint8Array(int length); 277 static Dart_CObject* NewUint8Array(intptr_t length);
278 static Dart_CObject* NewExternalUint8Array( 278 static Dart_CObject* NewExternalUint8Array(
279 int64_t length, uint8_t* data, void* peer, 279 intptr_t length, uint8_t* data, void* peer,
280 Dart_WeakPersistentHandleFinalizer callback); 280 Dart_WeakPersistentHandleFinalizer callback);
281
281 static Dart_CObject* NewIOBuffer(int64_t length); 282 static Dart_CObject* NewIOBuffer(int64_t length);
282 static void FreeIOBufferData(Dart_CObject* object); 283 static void FreeIOBufferData(Dart_CObject* object);
283 284
284 Dart_CObject* AsApiCObject() { return cobject_; } 285 Dart_CObject* AsApiCObject() { return cobject_; }
285 286
286 // Create a new CObject array with an illegal arguments error. 287 // Create a new CObject array with an illegal arguments error.
287 static CObject* IllegalArgumentError(); 288 static CObject* IllegalArgumentError();
288 // Create a new CObject array with a file closed error. 289 // Create a new CObject array with a file closed error.
289 static CObject* FileClosedError(); 290 static CObject* FileClosedError();
290 // Create a new CObject array with the current OS error. 291 // Create a new CObject array with the current OS error.
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 446
446 private: 447 private:
447 DISALLOW_COPY_AND_ASSIGN(CObjectString); 448 DISALLOW_COPY_AND_ASSIGN(CObjectString);
448 }; 449 };
449 450
450 451
451 class CObjectArray : public CObject { 452 class CObjectArray : public CObject {
452 public: 453 public:
453 DECLARE_COBJECT_CONSTRUCTORS(Array) 454 DECLARE_COBJECT_CONSTRUCTORS(Array)
454 455
455 int Length() const { return cobject_->value.as_array.length; } 456 intptr_t Length() const { return cobject_->value.as_array.length; }
456 CObject* operator[](int index) const { 457 CObject* operator[](intptr_t index) const {
457 return new CObject(cobject_->value.as_array.values[index]); 458 return new CObject(cobject_->value.as_array.values[index]);
458 } 459 }
459 void SetAt(int index, CObject* value) { 460 void SetAt(intptr_t index, CObject* value) {
460 cobject_->value.as_array.values[index] = value->AsApiCObject(); 461 cobject_->value.as_array.values[index] = value->AsApiCObject();
461 } 462 }
462 463
463 private: 464 private:
464 DISALLOW_COPY_AND_ASSIGN(CObjectArray); 465 DISALLOW_COPY_AND_ASSIGN(CObjectArray);
465 }; 466 };
466 467
467 468
468 class CObjectTypedData : public CObject { 469 class CObjectTypedData : public CObject {
469 public: 470 public:
470 explicit CObjectTypedData(Dart_CObject *cobject) : CObject(cobject) { 471 explicit CObjectTypedData(Dart_CObject *cobject) : CObject(cobject) {
471 ASSERT(type() == Dart_CObject_kTypedData); 472 ASSERT(type() == Dart_CObject_kTypedData);
472 cobject_ = cobject; 473 cobject_ = cobject;
473 } 474 }
474 explicit CObjectTypedData(CObject* cobject) : CObject() { 475 explicit CObjectTypedData(CObject* cobject) : CObject() {
475 ASSERT(cobject != NULL); 476 ASSERT(cobject != NULL);
476 ASSERT(cobject->type() == Dart_CObject_kTypedData); 477 ASSERT(cobject->type() == Dart_CObject_kTypedData);
477 cobject_ = cobject->AsApiCObject(); 478 cobject_ = cobject->AsApiCObject();
478 } 479 }
479 480
480 Dart_TypedData_Type Type() const { 481 Dart_TypedData_Type Type() const {
481 return cobject_->value.as_typed_data.type; 482 return cobject_->value.as_typed_data.type;
482 } 483 }
483 int Length() const { return cobject_->value.as_typed_data.length; } 484 intptr_t Length() const { return cobject_->value.as_typed_data.length; }
484 uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; } 485 uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; }
485 486
486 private: 487 private:
487 DISALLOW_COPY_AND_ASSIGN(CObjectTypedData); 488 DISALLOW_COPY_AND_ASSIGN(CObjectTypedData);
488 }; 489 };
489 490
490 491
491 class CObjectUint8Array : public CObject { 492 class CObjectUint8Array : public CObject {
492 public: 493 public:
493 DECLARE_COBJECT_TYPED_DATA_CONSTRUCTORS(Uint8) 494 DECLARE_COBJECT_TYPED_DATA_CONSTRUCTORS(Uint8)
494 495
495 int Length() const { return cobject_->value.as_typed_data.length; } 496 intptr_t Length() const { return cobject_->value.as_typed_data.length; }
496 uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; } 497 uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; }
497 498
498 private: 499 private:
499 DISALLOW_COPY_AND_ASSIGN(CObjectUint8Array); 500 DISALLOW_COPY_AND_ASSIGN(CObjectUint8Array);
500 }; 501 };
501 502
502 503
503 class CObjectExternalUint8Array : public CObject { 504 class CObjectExternalUint8Array : public CObject {
504 public: 505 public:
505 DECLARE_COBJECT_EXTERNAL_TYPED_DATA_CONSTRUCTORS(Uint8) 506 DECLARE_COBJECT_EXTERNAL_TYPED_DATA_CONSTRUCTORS(Uint8)
506 507
507 int Length() const { return cobject_->value.as_external_typed_data.length; } 508 intptr_t Length() const {
508 void SetLength(uint64_t length) { 509 return cobject_->value.as_external_typed_data.length;
510 }
511 void SetLength(intptr_t length) {
509 cobject_->value.as_external_typed_data.length = length; 512 cobject_->value.as_external_typed_data.length = length;
510 } 513 }
511 uint8_t* Data() const { return cobject_->value.as_external_typed_data.data; } 514 uint8_t* Data() const { return cobject_->value.as_external_typed_data.data; }
512 void* Peer() const { return cobject_->value.as_external_typed_data.peer; } 515 void* Peer() const { return cobject_->value.as_external_typed_data.peer; }
513 Dart_WeakPersistentHandleFinalizer Callback() const { 516 Dart_WeakPersistentHandleFinalizer Callback() const {
514 return cobject_->value.as_external_typed_data.callback; 517 return cobject_->value.as_external_typed_data.callback;
515 } 518 }
516 519
517 private: 520 private:
518 DISALLOW_COPY_AND_ASSIGN(CObjectExternalUint8Array); 521 DISALLOW_COPY_AND_ASSIGN(CObjectExternalUint8Array);
519 }; 522 };
520 523
521 } // namespace bin 524 } // namespace bin
522 } // namespace dart 525 } // namespace dart
523 526
524 #endif // BIN_DARTUTILS_H_ 527 #endif // BIN_DARTUTILS_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/dartutils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698