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

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

Issue 23479010: Add length checks to ApiMessageWriter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 static Dart_CObject* NewIOBuffer(int64_t length); 281 static Dart_CObject* NewIOBuffer(intptr_t length);
282 static void FreeIOBufferData(Dart_CObject* object); 282 static void FreeIOBufferData(Dart_CObject* object);
283 283
284 Dart_CObject* AsApiCObject() { return cobject_; } 284 Dart_CObject* AsApiCObject() { return cobject_; }
285 285
286 // Create a new CObject array with an illegal arguments error. 286 // Create a new CObject array with an illegal arguments error.
287 static CObject* IllegalArgumentError(); 287 static CObject* IllegalArgumentError();
288 // Create a new CObject array with a file closed error. 288 // Create a new CObject array with a file closed error.
289 static CObject* FileClosedError(); 289 static CObject* FileClosedError();
290 // Create a new CObject array with the current OS error. 290 // Create a new CObject array with the current OS error.
291 static CObject* NewOSError(); 291 static CObject* NewOSError();
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 445
446 private: 446 private:
447 DISALLOW_COPY_AND_ASSIGN(CObjectString); 447 DISALLOW_COPY_AND_ASSIGN(CObjectString);
448 }; 448 };
449 449
450 450
451 class CObjectArray : public CObject { 451 class CObjectArray : public CObject {
452 public: 452 public:
453 DECLARE_COBJECT_CONSTRUCTORS(Array) 453 DECLARE_COBJECT_CONSTRUCTORS(Array)
454 454
455 int Length() const { return cobject_->value.as_array.length; } 455 intptr_t Length() const { return cobject_->value.as_array.length; }
456 CObject* operator[](int index) const { 456 CObject* operator[](intptr_t index) const {
457 return new CObject(cobject_->value.as_array.values[index]); 457 return new CObject(cobject_->value.as_array.values[index]);
458 } 458 }
459 void SetAt(int index, CObject* value) { 459 void SetAt(intptr_t index, CObject* value) {
460 cobject_->value.as_array.values[index] = value->AsApiCObject(); 460 cobject_->value.as_array.values[index] = value->AsApiCObject();
461 } 461 }
462 462
463 private: 463 private:
464 DISALLOW_COPY_AND_ASSIGN(CObjectArray); 464 DISALLOW_COPY_AND_ASSIGN(CObjectArray);
465 }; 465 };
466 466
467 467
468 class CObjectTypedData : public CObject { 468 class CObjectTypedData : public CObject {
469 public: 469 public:
470 explicit CObjectTypedData(Dart_CObject *cobject) : CObject(cobject) { 470 explicit CObjectTypedData(Dart_CObject *cobject) : CObject(cobject) {
471 ASSERT(type() == Dart_CObject_kTypedData); 471 ASSERT(type() == Dart_CObject_kTypedData);
472 cobject_ = cobject; 472 cobject_ = cobject;
473 } 473 }
474 explicit CObjectTypedData(CObject* cobject) : CObject() { 474 explicit CObjectTypedData(CObject* cobject) : CObject() {
475 ASSERT(cobject != NULL); 475 ASSERT(cobject != NULL);
476 ASSERT(cobject->type() == Dart_CObject_kTypedData); 476 ASSERT(cobject->type() == Dart_CObject_kTypedData);
477 cobject_ = cobject->AsApiCObject(); 477 cobject_ = cobject->AsApiCObject();
478 } 478 }
479 479
480 Dart_TypedData_Type Type() const { 480 Dart_TypedData_Type Type() const {
481 return cobject_->value.as_typed_data.type; 481 return cobject_->value.as_typed_data.type;
482 } 482 }
483 int Length() const { return cobject_->value.as_typed_data.length; } 483 intptr_t Length() const { return cobject_->value.as_typed_data.length; }
484 uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; } 484 uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; }
485 485
486 private: 486 private:
487 DISALLOW_COPY_AND_ASSIGN(CObjectTypedData); 487 DISALLOW_COPY_AND_ASSIGN(CObjectTypedData);
488 }; 488 };
489 489
490 490
491 class CObjectUint8Array : public CObject { 491 class CObjectUint8Array : public CObject {
492 public: 492 public:
493 DECLARE_COBJECT_TYPED_DATA_CONSTRUCTORS(Uint8) 493 DECLARE_COBJECT_TYPED_DATA_CONSTRUCTORS(Uint8)
494 494
495 int Length() const { return cobject_->value.as_typed_data.length; } 495 intptr_t Length() const { return cobject_->value.as_typed_data.length; }
496 uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; } 496 uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; }
497 497
498 private: 498 private:
499 DISALLOW_COPY_AND_ASSIGN(CObjectUint8Array); 499 DISALLOW_COPY_AND_ASSIGN(CObjectUint8Array);
500 }; 500 };
501 501
502 502
503 class CObjectExternalUint8Array : public CObject { 503 class CObjectExternalUint8Array : public CObject {
504 public: 504 public:
505 DECLARE_COBJECT_EXTERNAL_TYPED_DATA_CONSTRUCTORS(Uint8) 505 DECLARE_COBJECT_EXTERNAL_TYPED_DATA_CONSTRUCTORS(Uint8)
506 506
507 int Length() const { return cobject_->value.as_external_typed_data.length; } 507 intptr_t Length() const {
508 void SetLength(uint64_t length) { 508 return cobject_->value.as_external_typed_data.length;
509 }
510 void SetLength(intptr_t length) {
509 cobject_->value.as_external_typed_data.length = length; 511 cobject_->value.as_external_typed_data.length = length;
510 } 512 }
511 uint8_t* Data() const { return cobject_->value.as_external_typed_data.data; } 513 uint8_t* Data() const { return cobject_->value.as_external_typed_data.data; }
512 void* Peer() const { return cobject_->value.as_external_typed_data.peer; } 514 void* Peer() const { return cobject_->value.as_external_typed_data.peer; }
513 Dart_WeakPersistentHandleFinalizer Callback() const { 515 Dart_WeakPersistentHandleFinalizer Callback() const {
514 return cobject_->value.as_external_typed_data.callback; 516 return cobject_->value.as_external_typed_data.callback;
515 } 517 }
516 518
517 private: 519 private:
518 DISALLOW_COPY_AND_ASSIGN(CObjectExternalUint8Array); 520 DISALLOW_COPY_AND_ASSIGN(CObjectExternalUint8Array);
519 }; 521 };
520 522
521 } // namespace bin 523 } // namespace bin
522 } // namespace dart 524 } // namespace dart
523 525
524 #endif // BIN_DARTUTILS_H_ 526 #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