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

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

Issue 9415043: Port async file operations to be using native ports instead or an isolate (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Forgot to remove #import from op.dart Created 8 years, 10 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 | « runtime/bin/builtin_natives.cc ('k') | 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 "bin/builtin.h" 8 #include "bin/builtin.h"
9 #include "include/dart_api.h" 9 #include "include/dart_api.h"
10 #include "platform/globals.h" 10 #include "platform/globals.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 class CObject { 108 class CObject {
109 public: 109 public:
110 explicit CObject(Dart_CObject *cobject) : cobject_(cobject) {} 110 explicit CObject(Dart_CObject *cobject) : cobject_(cobject) {}
111 Dart_CObject::Type type() { return cobject_->type; } 111 Dart_CObject::Type type() { return cobject_->type; }
112 112
113 bool IsNull() { return type() == Dart_CObject::kNull; } 113 bool IsNull() { return type() == Dart_CObject::kNull; }
114 bool IsBool() { return type() == Dart_CObject::kBool; } 114 bool IsBool() { return type() == Dart_CObject::kBool; }
115 bool IsInt32() { return type() == Dart_CObject::kInt32; } 115 bool IsInt32() { return type() == Dart_CObject::kInt32; }
116 bool IsInt64() { return type() == Dart_CObject::kInt64; } 116 bool IsInt64() { return type() == Dart_CObject::kInt64; }
117 bool IsInt32OrInt64() { return IsInt32() || IsInt64(); }
118 bool IsIntptr() { return IsInt32OrInt64(); }
117 bool IsBigint() { return type() == Dart_CObject::kBigint; } 119 bool IsBigint() { return type() == Dart_CObject::kBigint; }
118 bool IsDouble() { return type() == Dart_CObject::kDouble; } 120 bool IsDouble() { return type() == Dart_CObject::kDouble; }
119 bool IsString() { return type() == Dart_CObject::kString; } 121 bool IsString() { return type() == Dart_CObject::kString; }
120 bool IsArray() { return type() == Dart_CObject::kArray; } 122 bool IsArray() { return type() == Dart_CObject::kArray; }
121 bool IsByteArray() { return type() == Dart_CObject::kByteArray; } 123 bool IsByteArray() { return type() == Dart_CObject::kByteArray; }
122 124
123 bool IsTrue() { 125 bool IsTrue() {
124 return type() == Dart_CObject::kBool && cobject_->value.as_bool; 126 return type() == Dart_CObject::kBool && cobject_->value.as_bool;
125 } 127 }
126 128
127 bool IsFalse() { 129 bool IsFalse() {
128 return type() == Dart_CObject::kBool && !cobject_->value.as_bool; 130 return type() == Dart_CObject::kBool && !cobject_->value.as_bool;
129 } 131 }
130 132
131 void* operator new(size_t size) { 133 void* operator new(size_t size) {
132 return Dart_ScopeAllocate(size); 134 return Dart_ScopeAllocate(size);
133 } 135 }
134 136
135 static CObject* Null(); 137 static CObject* Null();
136 static CObject* True(); 138 static CObject* True();
137 static CObject* False(); 139 static CObject* False();
138 static CObject* Bool(bool value); 140 static CObject* Bool(bool value);
139 static Dart_CObject* NewInt32(int32_t value); 141 static Dart_CObject* NewInt32(int32_t value);
140 static Dart_CObject* NewInt64(int64_t value); 142 static Dart_CObject* NewInt64(int64_t value);
143 static Dart_CObject* NewIntptr(intptr_t value);
141 // TODO(sgjesse): Add support for kBigint. 144 // TODO(sgjesse): Add support for kBigint.
142 static Dart_CObject* NewDouble(double value); 145 static Dart_CObject* NewDouble(double value);
143 static Dart_CObject* NewString(int length); 146 static Dart_CObject* NewString(int length);
144 static Dart_CObject* NewString(const char* str); 147 static Dart_CObject* NewString(const char* str);
145 static Dart_CObject* NewArray(int length); 148 static Dart_CObject* NewArray(int length);
146 // TODO(sgjesse): Add support for kByteArray. 149 static Dart_CObject* NewByteArray(int length);
147 150
148 Dart_CObject* AsApiCObject() { return cobject_; } 151 Dart_CObject* AsApiCObject() { return cobject_; }
149 152
150 protected: 153 protected:
151 CObject() : cobject_(NULL) {} 154 CObject() : cobject_(NULL) {}
152 Dart_CObject* cobject_; 155 Dart_CObject* cobject_;
153 156
154 private: 157 private:
155 static Dart_CObject* New(Dart_CObject::Type type, int additional_bytes = 0); 158 static Dart_CObject* New(Dart_CObject::Type type, int additional_bytes = 0);
156 159
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 195
193 196
194 class CObjectInt64 : public CObject { 197 class CObjectInt64 : public CObject {
195 public: 198 public:
196 DECLARE_COBJECT_CONSTRUCTORS(Int64) 199 DECLARE_COBJECT_CONSTRUCTORS(Int64)
197 200
198 int64_t Value() const { return cobject_->value.as_int64; } 201 int64_t Value() const { return cobject_->value.as_int64; }
199 }; 202 };
200 203
201 204
205 class CObjectIntptr : public CObject {
206 public:
207 explicit CObjectIntptr(Dart_CObject *cobject) : CObject(cobject) {
208 ASSERT(type() == Dart_CObject::kInt32 || type() == Dart_CObject::kInt64);
209 cobject_ = cobject;
210 }
211 explicit CObjectIntptr(CObject* cobject) : CObject() {
212 ASSERT(cobject != NULL);
213 ASSERT(cobject->type() == Dart_CObject::kInt64 ||
214 cobject->type() == Dart_CObject::kInt32);
215 cobject_ = cobject->AsApiCObject();
216 }
217
218 intptr_t Value() {
219 intptr_t result;
220 if (type() == Dart_CObject::kInt32) {
221 result = cobject_->value.as_int32;
222 } else {
223 result = cobject_->value.as_int64;
224 }
225 return result;
226 }
227 };
228
229
202 class CObjectBigint : public CObject { 230 class CObjectBigint : public CObject {
203 public: 231 public:
204 DECLARE_COBJECT_CONSTRUCTORS(Bigint) 232 DECLARE_COBJECT_CONSTRUCTORS(Bigint)
205 233
206 char* Value() const { return cobject_->value.as_bigint; } 234 char* Value() const { return cobject_->value.as_bigint; }
207 }; 235 };
208 236
209 237
210 class CObjectDouble : public CObject { 238 class CObjectDouble : public CObject {
211 public: 239 public:
(...skipping 18 matching lines...) Expand all
230 258
231 int Length() const { return cobject_->value.as_array.length; } 259 int Length() const { return cobject_->value.as_array.length; }
232 CObject* operator[](int index) const { 260 CObject* operator[](int index) const {
233 return new CObject(cobject_->value.as_array.values[index]); 261 return new CObject(cobject_->value.as_array.values[index]);
234 } 262 }
235 void SetAt(int index, CObject* value) { 263 void SetAt(int index, CObject* value) {
236 cobject_->value.as_array.values[index] = value->AsApiCObject(); 264 cobject_->value.as_array.values[index] = value->AsApiCObject();
237 } 265 }
238 }; 266 };
239 267
268
269 class CObjectByteArray : public CObject {
270 public:
271 DECLARE_COBJECT_CONSTRUCTORS(ByteArray)
272
273 int Length() const { return cobject_->value.as_byte_array.length; }
274 uint8_t* Buffer() const { return cobject_->value.as_byte_array.values; }
275 };
276
240 #endif // BIN_DARTUTILS_H_ 277 #endif // BIN_DARTUTILS_H_
OLDNEW
« no previous file with comments | « runtime/bin/builtin_natives.cc ('k') | runtime/bin/dartutils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698