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

Unified Diff: runtime/bin/dartutils.h

Issue 14142008: Add support for more typed data types on native ports (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/bin/dartutils.cc » ('j') | runtime/include/dart_api.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/dartutils.h
diff --git a/runtime/bin/dartutils.h b/runtime/bin/dartutils.h
index da7653e1f1730c9f6c20fb7569764e46118fae66..aca80013d7e7871614e798a677b20f6dad97a02d 100644
--- a/runtime/bin/dartutils.h
+++ b/runtime/bin/dartutils.h
@@ -205,6 +205,10 @@ class CObject {
public:
explicit CObject(Dart_CObject *cobject) : cobject_(cobject) {}
Dart_CObject::Type type() { return cobject_->type; }
+ Dart_CObject::TypedDataType byte_array_type() {
siva 2013/04/15 23:28:45 for consistency should we name this typed_data_typ
+ ASSERT(type() == Dart_CObject::kTypedData);
+ return cobject_->value.as_typed_data.type;
+ }
bool IsNull() { return type() == Dart_CObject::kNull; }
bool IsBool() { return type() == Dart_CObject::kBool; }
@@ -216,7 +220,11 @@ class CObject {
bool IsDouble() { return type() == Dart_CObject::kDouble; }
bool IsString() { return type() == Dart_CObject::kString; }
bool IsArray() { return type() == Dart_CObject::kArray; }
- bool IsUint8Array() { return type() == Dart_CObject::kUint8Array; }
+ bool IsTypedData() { return type() == Dart_CObject::kTypedData; }
+ bool IsUint8Array() {
+ return type() == Dart_CObject::kTypedData &&
+ byte_array_type() == Dart_CObject::kUint8Array;
+ }
bool IsTrue() {
return type() == Dart_CObject::kBool && cobject_->value.as_bool;
@@ -288,7 +296,35 @@ class CObject {
ASSERT(cobject != NULL); \
ASSERT(cobject->type() == Dart_CObject::k##t); \
cobject_ = cobject->AsApiCObject(); \
- }
+ } \
+
+
+#define DECLARE_COBJECT_TYPED_DATA_CONSTRUCTORS(t) \
+ explicit CObject##t(Dart_CObject *cobject) : CObject(cobject) { \
+ ASSERT(type() == Dart_CObject::kTypedData); \
+ ASSERT(byte_array_type() == Dart_CObject::k##t); \
+ cobject_ = cobject; \
+ } \
+ explicit CObject##t(CObject* cobject) : CObject() { \
+ ASSERT(cobject != NULL); \
+ ASSERT(cobject->type() == Dart_CObject::kTypedData); \
+ ASSERT(cobject->byte_array_type() == Dart_CObject::k##t); \
+ cobject_ = cobject->AsApiCObject(); \
+ } \
+
+
+#define DECLARE_COBJECT_EXTERNAL_TYPED_DATA_CONSTRUCTORS(t) \
+ explicit CObjectExternal##t(Dart_CObject *cobject) : CObject(cobject) { \
+ ASSERT(type() == Dart_CObject::kExternalTypedData); \
+ ASSERT(byte_array_type() == Dart_CObject::k##t); \
+ cobject_ = cobject; \
+ } \
+ explicit CObjectExternal##t(CObject* cobject) : CObject() { \
+ ASSERT(cobject != NULL); \
+ ASSERT(cobject->type() == Dart_CObject::kExternalTypedData); \
+ ASSERT(cobject->byte_array_type() == Dart_CObject::k##t); \
+ cobject_ = cobject->AsApiCObject(); \
+ } \
class CObjectBool : public CObject {
@@ -404,12 +440,35 @@ class CObjectArray : public CObject {
};
+class CObjectTypedData : public CObject {
+ public:
+ explicit CObjectTypedData(Dart_CObject *cobject) : CObject(cobject) {
+ ASSERT(type() == Dart_CObject::kTypedData);
+ cobject_ = cobject;
+ }
+ explicit CObjectTypedData(CObject* cobject) : CObject() {
+ ASSERT(cobject != NULL);
+ ASSERT(cobject->type() == Dart_CObject::kTypedData);
+ cobject_ = cobject->AsApiCObject();
+ }
+
+ Dart_CObject::TypedDataType Type() const {
+ return cobject_->value.as_typed_data.type;
+ }
+ int Length() const { return cobject_->value.as_typed_data.length; }
+ uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; }
siva 2013/04/15 23:28:45 probably need accessors: Peer Callback etc. for
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(CObjectTypedData);
+};
+
+
class CObjectUint8Array : public CObject {
public:
- DECLARE_COBJECT_CONSTRUCTORS(Uint8Array)
+ DECLARE_COBJECT_TYPED_DATA_CONSTRUCTORS(Uint8Array)
- int Length() const { return cobject_->value.as_byte_array.length; }
- uint8_t* Buffer() const { return cobject_->value.as_byte_array.values; }
+ int Length() const { return cobject_->value.as_typed_data.length; }
+ uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; }
private:
DISALLOW_COPY_AND_ASSIGN(CObjectUint8Array);
@@ -418,16 +477,16 @@ class CObjectUint8Array : public CObject {
class CObjectExternalUint8Array : public CObject {
public:
- DECLARE_COBJECT_CONSTRUCTORS(ExternalUint8Array)
+ DECLARE_COBJECT_EXTERNAL_TYPED_DATA_CONSTRUCTORS(Uint8Array)
- int Length() const { return cobject_->value.as_external_byte_array.length; }
+ int Length() const { return cobject_->value.as_external_typed_data.length; }
void SetLength(uint64_t length) {
- cobject_->value.as_external_byte_array.length = length;
+ cobject_->value.as_external_typed_data.length = length;
}
- uint8_t* Data() const { return cobject_->value.as_external_byte_array.data; }
- void* Peer() const { return cobject_->value.as_external_byte_array.peer; }
+ uint8_t* Data() const { return cobject_->value.as_external_typed_data.data; }
+ void* Peer() const { return cobject_->value.as_external_typed_data.peer; }
Dart_WeakPersistentHandleFinalizer Callback() const {
- return cobject_->value.as_external_byte_array.callback;
+ return cobject_->value.as_external_typed_data.callback;
}
private:
« no previous file with comments | « no previous file | runtime/bin/dartutils.cc » ('j') | runtime/include/dart_api.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698