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

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

Issue 11414293: Fix a number of int type issues in dart:io File implementation to avoid implicit conversions that c… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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 "bin/utils.h" 9 #include "bin/utils.h"
10 #include "include/dart_api.h" 10 #include "include/dart_api.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 70
71 class DartUtils { 71 class DartUtils {
72 public: 72 public:
73 // TODO(turnidge): Clean up the implementations of these so that 73 // TODO(turnidge): Clean up the implementations of these so that
74 // they allow for proper error propagation. 74 // they allow for proper error propagation.
75 75
76 // Assumes that the value object is known to be an integer object 76 // Assumes that the value object is known to be an integer object
77 // that fits in a signed 64-bit integer. 77 // that fits in a signed 64-bit integer.
78 static int64_t GetIntegerValue(Dart_Handle value_obj); 78 static int64_t GetIntegerValue(Dart_Handle value_obj);
79 // Assumes that the value object is known to be an intptr_t. This should
80 // only be known when the value has been put into Dart as a pointer encoded
81 // in a 64-bit integer. This is the case for file and directory operations.
82 static intptr_t GetIntptrValue(Dart_Handle value_obj);
79 // Checks that the value object is an integer object that fits in a 83 // Checks that the value object is an integer object that fits in a
80 // signed 64-bit integer. If it is, the value is returned in the 84 // signed 64-bit integer. If it is, the value is returned in the
81 // value out parameter and true is returned. Otherwise, false is 85 // value out parameter and true is returned. Otherwise, false is
82 // returned. 86 // returned.
83 static bool GetInt64Value(Dart_Handle value_obj, int64_t* value); 87 static bool GetInt64Value(Dart_Handle value_obj, int64_t* value);
84 static const char* GetStringValue(Dart_Handle str_obj); 88 static const char* GetStringValue(Dart_Handle str_obj);
85 static bool GetBooleanValue(Dart_Handle bool_obj); 89 static bool GetBooleanValue(Dart_Handle bool_obj);
86 static void SetIntegerField(Dart_Handle handle, 90 static void SetIntegerField(Dart_Handle handle,
87 const char* name, 91 const char* name,
88 intptr_t val); 92 intptr_t val);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 static CObject* Bool(bool value); 207 static CObject* Bool(bool value);
204 static Dart_CObject* NewInt32(int32_t value); 208 static Dart_CObject* NewInt32(int32_t value);
205 static Dart_CObject* NewInt64(int64_t value); 209 static Dart_CObject* NewInt64(int64_t value);
206 static Dart_CObject* NewIntptr(intptr_t value); 210 static Dart_CObject* NewIntptr(intptr_t value);
207 // TODO(sgjesse): Add support for kBigint. 211 // TODO(sgjesse): Add support for kBigint.
208 static Dart_CObject* NewDouble(double value); 212 static Dart_CObject* NewDouble(double value);
209 static Dart_CObject* NewString(int length); 213 static Dart_CObject* NewString(int length);
210 static Dart_CObject* NewString(const char* str); 214 static Dart_CObject* NewString(const char* str);
211 static Dart_CObject* NewArray(int length); 215 static Dart_CObject* NewArray(int length);
212 static Dart_CObject* NewUint8Array(int length); 216 static Dart_CObject* NewUint8Array(int length);
213 static Dart_CObject* NewExternalUint8Array(int length, 217 static Dart_CObject* NewExternalUint8Array(int64_t length,
214 uint8_t* data, 218 uint8_t* data,
215 void* peer, 219 void* peer,
216 Dart_PeerFinalizer callback); 220 Dart_PeerFinalizer callback);
217 221
218 Dart_CObject* AsApiCObject() { return cobject_; } 222 Dart_CObject* AsApiCObject() { return cobject_; }
219 223
220 // Create a new CObject array with an illegal arguments error. 224 // Create a new CObject array with an illegal arguments error.
221 static CObject* IllegalArgumentError(); 225 static CObject* IllegalArgumentError();
222 // Create a new CObject array with a file closed error. 226 // Create a new CObject array with a file closed error.
223 static CObject* FileClosedError(); 227 static CObject* FileClosedError();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 ASSERT(cobject->type() == Dart_CObject::kInt64 || 305 ASSERT(cobject->type() == Dart_CObject::kInt64 ||
302 cobject->type() == Dart_CObject::kInt32); 306 cobject->type() == Dart_CObject::kInt32);
303 cobject_ = cobject->AsApiCObject(); 307 cobject_ = cobject->AsApiCObject();
304 } 308 }
305 309
306 intptr_t Value() { 310 intptr_t Value() {
307 intptr_t result; 311 intptr_t result;
308 if (type() == Dart_CObject::kInt32) { 312 if (type() == Dart_CObject::kInt32) {
309 result = cobject_->value.as_int32; 313 result = cobject_->value.as_int32;
310 } else { 314 } else {
311 result = cobject_->value.as_int64; 315 ASSERT(sizeof(result) == 8);
316 result = static_cast<intptr_t>(cobject_->value.as_int64);
312 } 317 }
313 return result; 318 return result;
314 } 319 }
315 320
316 private: 321 private:
317 DISALLOW_COPY_AND_ASSIGN(CObjectIntptr); 322 DISALLOW_COPY_AND_ASSIGN(CObjectIntptr);
318 }; 323 };
319 324
320 325
321 class CObjectBigint : public CObject { 326 class CObjectBigint : public CObject {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 void* Peer() const { return cobject_->value.as_external_byte_array.peer; } 395 void* Peer() const { return cobject_->value.as_external_byte_array.peer; }
391 Dart_PeerFinalizer Callback() const { 396 Dart_PeerFinalizer Callback() const {
392 return cobject_->value.as_external_byte_array.callback; 397 return cobject_->value.as_external_byte_array.callback;
393 } 398 }
394 399
395 private: 400 private:
396 DISALLOW_COPY_AND_ASSIGN(CObjectExternalUint8Array); 401 DISALLOW_COPY_AND_ASSIGN(CObjectExternalUint8Array);
397 }; 402 };
398 403
399 #endif // BIN_DARTUTILS_H_ 404 #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