Index: runtime/bin/dartutils.h |
diff --git a/runtime/bin/dartutils.h b/runtime/bin/dartutils.h |
index da7653e1f1730c9f6c20fb7569764e46118fae66..722c5c97fdf0100463566da57cf900aedd161d8a 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::ByteArrayType byte_array_type() { |
Mads Ager (google)
2013/04/12 09:03:46
Instead of ByteArray maybe we should use TypedData
Søren Gjesse
2013/04/15 09:14:34
You are right. Done.
|
+ ASSERT(type() == Dart_CObject::kByteArray); |
+ return cobject_->value.as_byte_array.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 IsByteArray() { return type() == Dart_CObject::kByteArray; } |
+ bool IsUint8Array() { |
+ return type() == Dart_CObject::kByteArray && |
+ 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_BYTE_ARRAY_CONSTRUCTORS(t) \ |
+ explicit CObject##t(Dart_CObject *cobject) : CObject(cobject) { \ |
+ ASSERT(type() == Dart_CObject::kByteArray); \ |
+ ASSERT(byte_array_type() == Dart_CObject::k##t); \ |
+ cobject_ = cobject; \ |
+ } \ |
+ explicit CObject##t(CObject* cobject) : CObject() { \ |
+ ASSERT(cobject != NULL); \ |
+ ASSERT(cobject->type() == Dart_CObject::kByteArray); \ |
+ ASSERT(cobject->byte_array_type() == Dart_CObject::k##t); \ |
+ cobject_ = cobject->AsApiCObject(); \ |
+ } \ |
+ |
+ |
+#define DECLARE_COBJECT_EXTERNAL_BYTE_ARRAY_CONSTRUCTORS(t) \ |
+ explicit CObjectExternal##t(Dart_CObject *cobject) : CObject(cobject) { \ |
+ ASSERT(type() == Dart_CObject::kExternalByteArray); \ |
+ ASSERT(byte_array_type() == Dart_CObject::k##t); \ |
+ cobject_ = cobject; \ |
+ } \ |
+ explicit CObjectExternal##t(CObject* cobject) : CObject() { \ |
+ ASSERT(cobject != NULL); \ |
+ ASSERT(cobject->type() == Dart_CObject::kExternalByteArray); \ |
+ ASSERT(cobject->byte_array_type() == Dart_CObject::k##t); \ |
+ cobject_ = cobject->AsApiCObject(); \ |
+ } \ |
class CObjectBool : public CObject { |
@@ -404,9 +440,32 @@ class CObjectArray : public CObject { |
}; |
+class CObjectByteArray : public CObject { |
+ public: |
+ explicit CObjectByteArray(Dart_CObject *cobject) : CObject(cobject) { |
+ ASSERT(type() == Dart_CObject::kByteArray); |
+ cobject_ = cobject; |
+ } |
+ explicit CObjectByteArray(CObject* cobject) : CObject() { |
+ ASSERT(cobject != NULL); |
+ ASSERT(cobject->type() == Dart_CObject::kByteArray); |
+ cobject_ = cobject->AsApiCObject(); |
+ } |
+ |
+ Dart_CObject::ByteArrayType Type() const { |
+ return cobject_->value.as_byte_array.type; |
+ } |
+ int Length() const { return cobject_->value.as_byte_array.length; } |
+ uint8_t* Buffer() const { return cobject_->value.as_byte_array.values; } |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(CObjectByteArray); |
+}; |
+ |
+ |
class CObjectUint8Array : public CObject { |
public: |
- DECLARE_COBJECT_CONSTRUCTORS(Uint8Array) |
+ DECLARE_COBJECT_BYTE_ARRAY_CONSTRUCTORS(Uint8Array) |
int Length() const { return cobject_->value.as_byte_array.length; } |
uint8_t* Buffer() const { return cobject_->value.as_byte_array.values; } |
@@ -418,7 +477,7 @@ class CObjectUint8Array : public CObject { |
class CObjectExternalUint8Array : public CObject { |
public: |
- DECLARE_COBJECT_CONSTRUCTORS(ExternalUint8Array) |
+ DECLARE_COBJECT_EXTERNAL_BYTE_ARRAY_CONSTRUCTORS(Uint8Array) |
int Length() const { return cobject_->value.as_external_byte_array.length; } |
void SetLength(uint64_t length) { |