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

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: Implemented all file operations using native ports 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
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 bool IsFalse() { 128 bool IsFalse() {
127 return type() == Dart_CObject::kBool && !cobject_->value.as_bool; 129 return type() == Dart_CObject::kBool && !cobject_->value.as_bool;
128 } 130 }
129 131
130 void* operator new(size_t size) { 132 void* operator new(size_t size) {
131 return Dart_ScopeAllocate(size); 133 return Dart_ScopeAllocate(size);
132 } 134 }
133 135
134 static CObject* Null(); 136 static CObject* Null();
135 static CObject* True(); 137 static CObject* True();
136 static CObject* False(); 138 static CObject* False();
137 static CObject* Bool(bool value); 139 static CObject* Bool(bool value);
138 static Dart_CObject* New(Dart_CObject::Type type, int additional_bytes = 0); 140 static Dart_CObject* New(Dart_CObject::Type type, int additional_bytes = 0);
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 // kBigint, 144 // 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 // 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 api_null_; 158 static Dart_CObject api_null_;
156 static Dart_CObject api_true_; 159 static Dart_CObject api_true_;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 193
191 194
192 class CObjectInt64 : public CObject { 195 class CObjectInt64 : public CObject {
193 public: 196 public:
194 DECLARE_COBJECT_CONSTRUCTORS(Int64) 197 DECLARE_COBJECT_CONSTRUCTORS(Int64)
195 198
196 int64_t Value() const { return cobject_->value.as_int64; } 199 int64_t Value() const { return cobject_->value.as_int64; }
197 }; 200 };
198 201
199 202
203 class CObjectIntptr : public CObject {
204 public:
205 explicit CObjectIntptr(Dart_CObject *cobject) : CObject(cobject) {
206 ASSERT(type() == Dart_CObject::kInt32 || type() == Dart_CObject::kInt64);
207 cobject_ = cobject;
208 }
209 explicit CObjectIntptr(CObject* cobject) : CObject() {
210 ASSERT(cobject != NULL);
211 ASSERT(cobject->type() == Dart_CObject::kInt64 ||
212 cobject->type() == Dart_CObject::kInt32);
213 cobject_ = cobject->AsApiCObject();
214 }
215
216 intptr_t Value() {
217 intptr_t result;
218 if (type() == Dart_CObject::kInt32) {
219 result = cobject_->value.as_int32;
220 } else {
221 result = cobject_->value.as_int64;
222 }
223 return result;
224 }
225 };
226
227
200 class CObjectBigint : public CObject { 228 class CObjectBigint : public CObject {
201 public: 229 public:
202 DECLARE_COBJECT_CONSTRUCTORS(Bigint) 230 DECLARE_COBJECT_CONSTRUCTORS(Bigint)
203 231
204 char* Value() const { return cobject_->value.as_bigint; } 232 char* Value() const { return cobject_->value.as_bigint; }
205 }; 233 };
206 234
207 235
208 class CObjectDouble : public CObject { 236 class CObjectDouble : public CObject {
209 public: 237 public:
(...skipping 18 matching lines...) Expand all
228 256
229 int Length() const { return cobject_->value.as_array.length; } 257 int Length() const { return cobject_->value.as_array.length; }
230 CObject* operator[](int index) const { 258 CObject* operator[](int index) const {
231 return new CObject(cobject_->value.as_array.values[index]); 259 return new CObject(cobject_->value.as_array.values[index]);
232 } 260 }
233 void SetAt(int index, CObject* value) { 261 void SetAt(int index, CObject* value) {
234 cobject_->value.as_array.values[index] = value->AsApiCObject(); 262 cobject_->value.as_array.values[index] = value->AsApiCObject();
235 } 263 }
236 }; 264 };
237 265
266
267 class CObjectByteArray : public CObject {
268 public:
269 DECLARE_COBJECT_CONSTRUCTORS(ByteArray)
270
271 int Length() const { return cobject_->value.as_byte_array.length; }
272 uint8_t* Buffer() const { return cobject_->value.as_byte_array.values; }
273 };
274
238 #endif // BIN_DARTUTILS_H_ 275 #endif // BIN_DARTUTILS_H_
OLDNEW
« no previous file with comments | « runtime/bin/builtin_natives.cc ('k') | runtime/bin/dartutils.cc » ('j') | runtime/bin/file.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698