| OLD | NEW |
| 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 "bin/builtin.h" | 8 #include "bin/builtin.h" |
| 9 #include "bin/utils.h" | 9 #include "bin/utils.h" |
| 10 #include "include/dart_api.h" | 10 #include "include/dart_api.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 bool IsNull() { return type() == Dart_CObject::kNull; } | 124 bool IsNull() { return type() == Dart_CObject::kNull; } |
| 125 bool IsBool() { return type() == Dart_CObject::kBool; } | 125 bool IsBool() { return type() == Dart_CObject::kBool; } |
| 126 bool IsInt32() { return type() == Dart_CObject::kInt32; } | 126 bool IsInt32() { return type() == Dart_CObject::kInt32; } |
| 127 bool IsInt64() { return type() == Dart_CObject::kInt64; } | 127 bool IsInt64() { return type() == Dart_CObject::kInt64; } |
| 128 bool IsInt32OrInt64() { return IsInt32() || IsInt64(); } | 128 bool IsInt32OrInt64() { return IsInt32() || IsInt64(); } |
| 129 bool IsIntptr() { return IsInt32OrInt64(); } | 129 bool IsIntptr() { return IsInt32OrInt64(); } |
| 130 bool IsBigint() { return type() == Dart_CObject::kBigint; } | 130 bool IsBigint() { return type() == Dart_CObject::kBigint; } |
| 131 bool IsDouble() { return type() == Dart_CObject::kDouble; } | 131 bool IsDouble() { return type() == Dart_CObject::kDouble; } |
| 132 bool IsString() { return type() == Dart_CObject::kString; } | 132 bool IsString() { return type() == Dart_CObject::kString; } |
| 133 bool IsArray() { return type() == Dart_CObject::kArray; } | 133 bool IsArray() { return type() == Dart_CObject::kArray; } |
| 134 bool IsByteArray() { return type() == Dart_CObject::kByteArray; } | 134 bool IsUint8Array() { return type() == Dart_CObject::kUint8Array; } |
| 135 | 135 |
| 136 bool IsTrue() { | 136 bool IsTrue() { |
| 137 return type() == Dart_CObject::kBool && cobject_->value.as_bool; | 137 return type() == Dart_CObject::kBool && cobject_->value.as_bool; |
| 138 } | 138 } |
| 139 | 139 |
| 140 bool IsFalse() { | 140 bool IsFalse() { |
| 141 return type() == Dart_CObject::kBool && !cobject_->value.as_bool; | 141 return type() == Dart_CObject::kBool && !cobject_->value.as_bool; |
| 142 } | 142 } |
| 143 | 143 |
| 144 void* operator new(size_t size) { | 144 void* operator new(size_t size) { |
| 145 return Dart_ScopeAllocate(size); | 145 return Dart_ScopeAllocate(size); |
| 146 } | 146 } |
| 147 | 147 |
| 148 static CObject* Null(); | 148 static CObject* Null(); |
| 149 static CObject* True(); | 149 static CObject* True(); |
| 150 static CObject* False(); | 150 static CObject* False(); |
| 151 static CObject* Bool(bool value); | 151 static CObject* Bool(bool value); |
| 152 static Dart_CObject* NewInt32(int32_t value); | 152 static Dart_CObject* NewInt32(int32_t value); |
| 153 static Dart_CObject* NewInt64(int64_t value); | 153 static Dart_CObject* NewInt64(int64_t value); |
| 154 static Dart_CObject* NewIntptr(intptr_t value); | 154 static Dart_CObject* NewIntptr(intptr_t value); |
| 155 // TODO(sgjesse): Add support for kBigint. | 155 // TODO(sgjesse): Add support for kBigint. |
| 156 static Dart_CObject* NewDouble(double value); | 156 static Dart_CObject* NewDouble(double value); |
| 157 static Dart_CObject* NewString(int length); | 157 static Dart_CObject* NewString(int length); |
| 158 static Dart_CObject* NewString(const char* str); | 158 static Dart_CObject* NewString(const char* str); |
| 159 static Dart_CObject* NewArray(int length); | 159 static Dart_CObject* NewArray(int length); |
| 160 static Dart_CObject* NewByteArray(int length); | 160 static Dart_CObject* NewUint8Array(int length); |
| 161 | 161 |
| 162 Dart_CObject* AsApiCObject() { return cobject_; } | 162 Dart_CObject* AsApiCObject() { return cobject_; } |
| 163 | 163 |
| 164 // Create a new CObject array with an illegal arguments error. | 164 // Create a new CObject array with an illegal arguments error. |
| 165 static CObject* IllegalArgumentError(); | 165 static CObject* IllegalArgumentError(); |
| 166 // Create a new CObject array with a file closed error. | 166 // Create a new CObject array with a file closed error. |
| 167 static CObject* FileClosedError(); | 167 static CObject* FileClosedError(); |
| 168 // Create a new CObject array with the current OS error. | 168 // Create a new CObject array with the current OS error. |
| 169 static CObject* NewOSError(); | 169 static CObject* NewOSError(); |
| 170 // Create a new CObject array with the specified OS error. | 170 // Create a new CObject array with the specified OS error. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 int Length() const { return cobject_->value.as_array.length; } | 279 int Length() const { return cobject_->value.as_array.length; } |
| 280 CObject* operator[](int index) const { | 280 CObject* operator[](int index) const { |
| 281 return new CObject(cobject_->value.as_array.values[index]); | 281 return new CObject(cobject_->value.as_array.values[index]); |
| 282 } | 282 } |
| 283 void SetAt(int index, CObject* value) { | 283 void SetAt(int index, CObject* value) { |
| 284 cobject_->value.as_array.values[index] = value->AsApiCObject(); | 284 cobject_->value.as_array.values[index] = value->AsApiCObject(); |
| 285 } | 285 } |
| 286 }; | 286 }; |
| 287 | 287 |
| 288 | 288 |
| 289 class CObjectByteArray : public CObject { | 289 class CObjectUint8Array : public CObject { |
| 290 public: | 290 public: |
| 291 DECLARE_COBJECT_CONSTRUCTORS(ByteArray) | 291 DECLARE_COBJECT_CONSTRUCTORS(Uint8Array) |
| 292 | 292 |
| 293 int Length() const { return cobject_->value.as_byte_array.length; } | 293 int Length() const { return cobject_->value.as_byte_array.length; } |
| 294 uint8_t* Buffer() const { return cobject_->value.as_byte_array.values; } | 294 uint8_t* Buffer() const { return cobject_->value.as_byte_array.values; } |
| 295 }; | 295 }; |
| 296 | 296 |
| 297 #endif // BIN_DARTUTILS_H_ | 297 #endif // BIN_DARTUTILS_H_ |
| OLD | NEW |