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 RUNTIME_BIN_DARTUTILS_H_ | 5 #ifndef RUNTIME_BIN_DARTUTILS_H_ |
6 #define RUNTIME_BIN_DARTUTILS_H_ | 6 #define RUNTIME_BIN_DARTUTILS_H_ |
7 | 7 |
8 #include "bin/isolate_data.h" | 8 #include "bin/isolate_data.h" |
9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
10 #include "include/dart_native_api.h" | 10 #include "include/dart_native_api.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 // The caller is responsible for free()ing [kernel_file] if `true` was returned. | 40 // The caller is responsible for free()ing [kernel_file] if `true` was returned. |
41 bool TryReadKernel(const char* script_uri, | 41 bool TryReadKernel(const char* script_uri, |
42 const uint8_t** kernel_file, | 42 const uint8_t** kernel_file, |
43 intptr_t* kernel_length); | 43 intptr_t* kernel_length); |
44 | 44 |
45 class CommandLineOptions { | 45 class CommandLineOptions { |
46 public: | 46 public: |
47 explicit CommandLineOptions(int max_count) | 47 explicit CommandLineOptions(int max_count) |
48 : count_(0), max_count_(max_count), arguments_(NULL) { | 48 : count_(0), max_count_(max_count), arguments_(NULL) { |
49 static const int kWordSize = sizeof(intptr_t); | 49 static const int kWordSize = sizeof(intptr_t); |
50 arguments_ = reinterpret_cast<const char **>(malloc(max_count * kWordSize)); | 50 arguments_ = reinterpret_cast<const char**>(malloc(max_count * kWordSize)); |
51 if (arguments_ == NULL) { | 51 if (arguments_ == NULL) { |
52 max_count_ = 0; | 52 max_count_ = 0; |
53 } | 53 } |
54 } | 54 } |
55 ~CommandLineOptions() { | 55 ~CommandLineOptions() { |
56 free(arguments_); | 56 free(arguments_); |
57 count_ = 0; | 57 count_ = 0; |
58 max_count_ = 0; | 58 max_count_ = 0; |
59 arguments_ = NULL; | 59 arguments_ = NULL; |
60 } | 60 } |
(...skipping 27 matching lines...) Expand all Loading... |
88 | 88 |
89 | 89 |
90 class DartUtils { | 90 class DartUtils { |
91 public: | 91 public: |
92 // Returns the integer value of a Dart object. If the object is not | 92 // Returns the integer value of a Dart object. If the object is not |
93 // an integer value an API error is propagated. | 93 // an integer value an API error is propagated. |
94 static int64_t GetIntegerValue(Dart_Handle value_obj); | 94 static int64_t GetIntegerValue(Dart_Handle value_obj); |
95 // Returns the integer value of a Dart object. If the object is not | 95 // Returns the integer value of a Dart object. If the object is not |
96 // an integer value or outside the requested range an API error is | 96 // an integer value or outside the requested range an API error is |
97 // propagated. | 97 // propagated. |
98 static int64_t GetInt64ValueCheckRange( | 98 static int64_t GetInt64ValueCheckRange(Dart_Handle value_obj, |
99 Dart_Handle value_obj, int64_t lower, int64_t upper); | 99 int64_t lower, |
| 100 int64_t upper); |
100 // Returns the intptr_t value of a Dart object. If the object is not | 101 // Returns the intptr_t value of a Dart object. If the object is not |
101 // an integer value or the value is outside the intptr_t range an | 102 // an integer value or the value is outside the intptr_t range an |
102 // API error is propagated. | 103 // API error is propagated. |
103 static intptr_t GetIntptrValue(Dart_Handle value_obj); | 104 static intptr_t GetIntptrValue(Dart_Handle value_obj); |
104 // Checks that the value object is an integer object that fits in a | 105 // Checks that the value object is an integer object that fits in a |
105 // signed 64-bit integer. If it is, the value is returned in the | 106 // signed 64-bit integer. If it is, the value is returned in the |
106 // value out parameter and true is returned. Otherwise, false is | 107 // value out parameter and true is returned. Otherwise, false is |
107 // returned. | 108 // returned. |
108 static bool GetInt64Value(Dart_Handle value_obj, int64_t* value); | 109 static bool GetInt64Value(Dart_Handle value_obj, int64_t* value); |
109 // Returns the string value of a Dart object. If the object is not | 110 // Returns the string value of a Dart object. If the object is not |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 // Create a new Dart String object from a C String. | 171 // Create a new Dart String object from a C String. |
171 static Dart_Handle NewString(const char* str) { | 172 static Dart_Handle NewString(const char* str) { |
172 ASSERT(str != NULL); | 173 ASSERT(str != NULL); |
173 return Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(str), | 174 return Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(str), |
174 strlen(str)); | 175 strlen(str)); |
175 } | 176 } |
176 | 177 |
177 // Allocate length bytes for a C string with Dart_ScopeAllocate. | 178 // Allocate length bytes for a C string with Dart_ScopeAllocate. |
178 static char* ScopedCString(intptr_t length) { | 179 static char* ScopedCString(intptr_t length) { |
179 char* result = NULL; | 180 char* result = NULL; |
180 result = reinterpret_cast<char*>( | 181 result = |
181 Dart_ScopeAllocate(length * sizeof(*result))); | 182 reinterpret_cast<char*>(Dart_ScopeAllocate(length * sizeof(*result))); |
182 return result; | 183 return result; |
183 } | 184 } |
184 | 185 |
185 // Copy str into a buffer allocated with Dart_ScopeAllocate. | 186 // Copy str into a buffer allocated with Dart_ScopeAllocate. |
186 static char* ScopedCopyCString(const char* str) { | 187 static char* ScopedCopyCString(const char* str) { |
187 size_t str_len = strlen(str); | 188 size_t str_len = strlen(str); |
188 char* result = ScopedCString(str_len + 1); | 189 char* result = ScopedCString(str_len + 1); |
189 memmove(result, str, str_len); | 190 memmove(result, str, str_len); |
190 result[str_len] = '\0'; | 191 result[str_len] = '\0'; |
191 return result; | 192 return result; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 250 |
250 static Dart_Handle LibraryFilePath(Dart_Handle library_uri); | 251 static Dart_Handle LibraryFilePath(Dart_Handle library_uri); |
251 | 252 |
252 private: | 253 private: |
253 static Dart_Handle SetWorkingDirectory(); | 254 static Dart_Handle SetWorkingDirectory(); |
254 static Dart_Handle PrepareBuiltinLibrary(Dart_Handle builtin_lib, | 255 static Dart_Handle PrepareBuiltinLibrary(Dart_Handle builtin_lib, |
255 Dart_Handle internal_lib, | 256 Dart_Handle internal_lib, |
256 bool is_service_isolate, | 257 bool is_service_isolate, |
257 bool trace_loading); | 258 bool trace_loading); |
258 static Dart_Handle PrepareCoreLibrary(Dart_Handle core_lib, | 259 static Dart_Handle PrepareCoreLibrary(Dart_Handle core_lib, |
259 Dart_Handle builtin_lib, | 260 Dart_Handle builtin_lib, |
260 bool is_service_isolate); | 261 bool is_service_isolate); |
261 static Dart_Handle PrepareAsyncLibrary(Dart_Handle async_lib, | 262 static Dart_Handle PrepareAsyncLibrary(Dart_Handle async_lib, |
262 Dart_Handle isolate_lib); | 263 Dart_Handle isolate_lib); |
263 static Dart_Handle PrepareIOLibrary(Dart_Handle io_lib); | 264 static Dart_Handle PrepareIOLibrary(Dart_Handle io_lib); |
264 static Dart_Handle PrepareIsolateLibrary(Dart_Handle isolate_lib); | 265 static Dart_Handle PrepareIsolateLibrary(Dart_Handle isolate_lib); |
265 | 266 |
266 DISALLOW_ALLOCATION(); | 267 DISALLOW_ALLOCATION(); |
267 DISALLOW_IMPLICIT_CONSTRUCTORS(DartUtils); | 268 DISALLOW_IMPLICIT_CONSTRUCTORS(DartUtils); |
268 }; | 269 }; |
269 | 270 |
270 | 271 |
271 class CObject { | 272 class CObject { |
272 public: | 273 public: |
273 // These match the constants in sdk/lib/io/common.dart. | 274 // These match the constants in sdk/lib/io/common.dart. |
274 static const int kSuccess = 0; | 275 static const int kSuccess = 0; |
275 static const int kArgumentError = 1; | 276 static const int kArgumentError = 1; |
276 static const int kOSError = 2; | 277 static const int kOSError = 2; |
277 static const int kFileClosedError = 3; | 278 static const int kFileClosedError = 3; |
278 | 279 |
279 explicit CObject(Dart_CObject *cobject) : cobject_(cobject) {} | 280 explicit CObject(Dart_CObject* cobject) : cobject_(cobject) {} |
280 Dart_CObject_Type type() { return cobject_->type; } | 281 Dart_CObject_Type type() { return cobject_->type; } |
281 Dart_TypedData_Type byte_array_type() { | 282 Dart_TypedData_Type byte_array_type() { |
282 ASSERT(type() == Dart_CObject_kTypedData || | 283 ASSERT(type() == Dart_CObject_kTypedData || |
283 type() == Dart_CObject_kExternalTypedData); | 284 type() == Dart_CObject_kExternalTypedData); |
284 return cobject_->value.as_typed_data.type; | 285 return cobject_->value.as_typed_data.type; |
285 } | 286 } |
286 | 287 |
287 bool IsNull() { return type() == Dart_CObject_kNull; } | 288 bool IsNull() { return type() == Dart_CObject_kNull; } |
288 bool IsBool() { return type() == Dart_CObject_kBool; } | 289 bool IsBool() { return type() == Dart_CObject_kBool; } |
289 bool IsInt32() { return type() == Dart_CObject_kInt32; } | 290 bool IsInt32() { return type() == Dart_CObject_kInt32; } |
(...skipping 12 matching lines...) Expand all Loading... |
302 bool IsSendPort() { return type() == Dart_CObject_kSendPort; } | 303 bool IsSendPort() { return type() == Dart_CObject_kSendPort; } |
303 | 304 |
304 bool IsTrue() { | 305 bool IsTrue() { |
305 return type() == Dart_CObject_kBool && cobject_->value.as_bool; | 306 return type() == Dart_CObject_kBool && cobject_->value.as_bool; |
306 } | 307 } |
307 | 308 |
308 bool IsFalse() { | 309 bool IsFalse() { |
309 return type() == Dart_CObject_kBool && !cobject_->value.as_bool; | 310 return type() == Dart_CObject_kBool && !cobject_->value.as_bool; |
310 } | 311 } |
311 | 312 |
312 void* operator new(size_t size) { | 313 void* operator new(size_t size) { return Dart_ScopeAllocate(size); } |
313 return Dart_ScopeAllocate(size); | |
314 } | |
315 | 314 |
316 static CObject* Null(); | 315 static CObject* Null(); |
317 static CObject* True(); | 316 static CObject* True(); |
318 static CObject* False(); | 317 static CObject* False(); |
319 static CObject* Bool(bool value); | 318 static CObject* Bool(bool value); |
320 static Dart_CObject* NewInt32(int32_t value); | 319 static Dart_CObject* NewInt32(int32_t value); |
321 static Dart_CObject* NewInt64(int64_t value); | 320 static Dart_CObject* NewInt64(int64_t value); |
322 static Dart_CObject* NewIntptr(intptr_t value); | 321 static Dart_CObject* NewIntptr(intptr_t value); |
323 static Dart_CObject* NewBigint(const char* hex_value); | 322 static Dart_CObject* NewBigint(const char* hex_value); |
324 static char* BigintToHexValue(Dart_CObject* bigint); | 323 static char* BigintToHexValue(Dart_CObject* bigint); |
325 static Dart_CObject* NewDouble(double value); | 324 static Dart_CObject* NewDouble(double value); |
326 static Dart_CObject* NewString(intptr_t length); | 325 static Dart_CObject* NewString(intptr_t length); |
327 static Dart_CObject* NewString(const char* str); | 326 static Dart_CObject* NewString(const char* str); |
328 static Dart_CObject* NewArray(intptr_t length); | 327 static Dart_CObject* NewArray(intptr_t length); |
329 static Dart_CObject* NewUint8Array(intptr_t length); | 328 static Dart_CObject* NewUint8Array(intptr_t length); |
330 static Dart_CObject* NewUint32Array(intptr_t length); | 329 static Dart_CObject* NewUint32Array(intptr_t length); |
331 static Dart_CObject* NewExternalUint8Array( | 330 static Dart_CObject* NewExternalUint8Array( |
332 intptr_t length, uint8_t* data, void* peer, | 331 intptr_t length, |
| 332 uint8_t* data, |
| 333 void* peer, |
333 Dart_WeakPersistentHandleFinalizer callback); | 334 Dart_WeakPersistentHandleFinalizer callback); |
334 | 335 |
335 static Dart_CObject* NewIOBuffer(int64_t length); | 336 static Dart_CObject* NewIOBuffer(int64_t length); |
336 static void FreeIOBufferData(Dart_CObject* object); | 337 static void FreeIOBufferData(Dart_CObject* object); |
337 | 338 |
338 Dart_CObject* AsApiCObject() { return cobject_; } | 339 Dart_CObject* AsApiCObject() { return cobject_; } |
339 | 340 |
340 // Create a new CObject array with an illegal arguments error. | 341 // Create a new CObject array with an illegal arguments error. |
341 static CObject* IllegalArgumentError(); | 342 static CObject* IllegalArgumentError(); |
342 // Create a new CObject array with a file closed error. | 343 // Create a new CObject array with a file closed error. |
(...skipping 16 matching lines...) Expand all Loading... |
359 static CObject null_; | 360 static CObject null_; |
360 static CObject true_; | 361 static CObject true_; |
361 static CObject false_; | 362 static CObject false_; |
362 | 363 |
363 private: | 364 private: |
364 DISALLOW_COPY_AND_ASSIGN(CObject); | 365 DISALLOW_COPY_AND_ASSIGN(CObject); |
365 }; | 366 }; |
366 | 367 |
367 | 368 |
368 #define DECLARE_COBJECT_CONSTRUCTORS(t) \ | 369 #define DECLARE_COBJECT_CONSTRUCTORS(t) \ |
369 explicit CObject##t(Dart_CObject *cobject) : CObject(cobject) { \ | 370 explicit CObject##t(Dart_CObject* cobject) : CObject(cobject) { \ |
370 ASSERT(type() == Dart_CObject_k##t); \ | 371 ASSERT(type() == Dart_CObject_k##t); \ |
371 cobject_ = cobject; \ | 372 cobject_ = cobject; \ |
372 } \ | 373 } \ |
373 explicit CObject##t(CObject* cobject) : CObject() { \ | 374 explicit CObject##t(CObject* cobject) : CObject() { \ |
374 ASSERT(cobject != NULL); \ | 375 ASSERT(cobject != NULL); \ |
375 ASSERT(cobject->type() == Dart_CObject_k##t); \ | 376 ASSERT(cobject->type() == Dart_CObject_k##t); \ |
376 cobject_ = cobject->AsApiCObject(); \ | 377 cobject_ = cobject->AsApiCObject(); \ |
377 } \ | 378 } |
378 | 379 |
379 | 380 |
380 #define DECLARE_COBJECT_TYPED_DATA_CONSTRUCTORS(t) \ | 381 #define DECLARE_COBJECT_TYPED_DATA_CONSTRUCTORS(t) \ |
381 explicit CObject##t##Array(Dart_CObject *cobject) : CObject(cobject) { \ | 382 explicit CObject##t##Array(Dart_CObject* cobject) : CObject(cobject) { \ |
382 ASSERT(type() == Dart_CObject_kTypedData); \ | 383 ASSERT(type() == Dart_CObject_kTypedData); \ |
383 ASSERT(byte_array_type() == Dart_TypedData_k##t); \ | 384 ASSERT(byte_array_type() == Dart_TypedData_k##t); \ |
384 cobject_ = cobject; \ | 385 cobject_ = cobject; \ |
385 } \ | 386 } \ |
386 explicit CObject##t##Array(CObject* cobject) : CObject() { \ | 387 explicit CObject##t##Array(CObject* cobject) : CObject() { \ |
387 ASSERT(cobject != NULL); \ | 388 ASSERT(cobject != NULL); \ |
388 ASSERT(cobject->type() == Dart_CObject_kTypedData); \ | 389 ASSERT(cobject->type() == Dart_CObject_kTypedData); \ |
389 ASSERT(cobject->byte_array_type() == Dart_TypedData_k##t); \ | 390 ASSERT(cobject->byte_array_type() == Dart_TypedData_k##t); \ |
390 cobject_ = cobject->AsApiCObject(); \ | 391 cobject_ = cobject->AsApiCObject(); \ |
391 } \ | 392 } |
392 | 393 |
393 | 394 |
394 #define DECLARE_COBJECT_EXTERNAL_TYPED_DATA_CONSTRUCTORS(t) \ | 395 #define DECLARE_COBJECT_EXTERNAL_TYPED_DATA_CONSTRUCTORS(t) \ |
395 explicit CObjectExternal##t##Array(Dart_CObject *cobject) \ | 396 explicit CObjectExternal##t##Array(Dart_CObject* cobject) \ |
396 : CObject(cobject) { \ | 397 : CObject(cobject) { \ |
397 ASSERT(type() == Dart_CObject_kExternalTypedData); \ | 398 ASSERT(type() == Dart_CObject_kExternalTypedData); \ |
398 ASSERT(byte_array_type() == Dart_TypedData_k##t); \ | 399 ASSERT(byte_array_type() == Dart_TypedData_k##t); \ |
399 cobject_ = cobject; \ | 400 cobject_ = cobject; \ |
400 } \ | 401 } \ |
401 explicit CObjectExternal##t##Array(CObject* cobject) : CObject() { \ | 402 explicit CObjectExternal##t##Array(CObject* cobject) : CObject() { \ |
402 ASSERT(cobject != NULL); \ | 403 ASSERT(cobject != NULL); \ |
403 ASSERT(cobject->type() == Dart_CObject_kExternalTypedData); \ | 404 ASSERT(cobject->type() == Dart_CObject_kExternalTypedData); \ |
404 ASSERT(cobject->byte_array_type() == Dart_TypedData_k##t); \ | 405 ASSERT(cobject->byte_array_type() == Dart_TypedData_k##t); \ |
405 cobject_ = cobject->AsApiCObject(); \ | 406 cobject_ = cobject->AsApiCObject(); \ |
406 } \ | 407 } |
407 | 408 |
408 | 409 |
409 class CObjectBool : public CObject { | 410 class CObjectBool : public CObject { |
410 public: | 411 public: |
411 DECLARE_COBJECT_CONSTRUCTORS(Bool) | 412 DECLARE_COBJECT_CONSTRUCTORS(Bool) |
412 | 413 |
413 bool Value() const { return cobject_->value.as_bool; } | 414 bool Value() const { return cobject_->value.as_bool; } |
414 | 415 |
415 private: | 416 private: |
416 DISALLOW_COPY_AND_ASSIGN(CObjectBool); | 417 DISALLOW_COPY_AND_ASSIGN(CObjectBool); |
(...skipping 17 matching lines...) Expand all Loading... |
434 | 435 |
435 int64_t Value() const { return cobject_->value.as_int64; } | 436 int64_t Value() const { return cobject_->value.as_int64; } |
436 | 437 |
437 private: | 438 private: |
438 DISALLOW_COPY_AND_ASSIGN(CObjectInt64); | 439 DISALLOW_COPY_AND_ASSIGN(CObjectInt64); |
439 }; | 440 }; |
440 | 441 |
441 | 442 |
442 class CObjectIntptr : public CObject { | 443 class CObjectIntptr : public CObject { |
443 public: | 444 public: |
444 explicit CObjectIntptr(Dart_CObject *cobject) : CObject(cobject) { | 445 explicit CObjectIntptr(Dart_CObject* cobject) : CObject(cobject) { |
445 ASSERT(type() == Dart_CObject_kInt32 || type() == Dart_CObject_kInt64); | 446 ASSERT(type() == Dart_CObject_kInt32 || type() == Dart_CObject_kInt64); |
446 cobject_ = cobject; | 447 cobject_ = cobject; |
447 } | 448 } |
448 explicit CObjectIntptr(CObject* cobject) : CObject() { | 449 explicit CObjectIntptr(CObject* cobject) : CObject() { |
449 ASSERT(cobject != NULL); | 450 ASSERT(cobject != NULL); |
450 ASSERT(cobject->type() == Dart_CObject_kInt64 || | 451 ASSERT(cobject->type() == Dart_CObject_kInt64 || |
451 cobject->type() == Dart_CObject_kInt32); | 452 cobject->type() == Dart_CObject_kInt32); |
452 cobject_ = cobject->AsApiCObject(); | 453 cobject_ = cobject->AsApiCObject(); |
453 } | 454 } |
454 | 455 |
455 intptr_t Value() { | 456 intptr_t Value() { |
456 intptr_t result; | 457 intptr_t result; |
457 if (type() == Dart_CObject_kInt32) { | 458 if (type() == Dart_CObject_kInt32) { |
458 result = cobject_->value.as_int32; | 459 result = cobject_->value.as_int32; |
459 } else { | 460 } else { |
460 ASSERT(sizeof(result) == 8); | 461 ASSERT(sizeof(result) == 8); |
461 result = static_cast<intptr_t>(cobject_->value.as_int64); | 462 result = static_cast<intptr_t>(cobject_->value.as_int64); |
462 } | 463 } |
463 return result; | 464 return result; |
464 } | 465 } |
465 | 466 |
466 private: | 467 private: |
467 DISALLOW_COPY_AND_ASSIGN(CObjectIntptr); | 468 DISALLOW_COPY_AND_ASSIGN(CObjectIntptr); |
468 }; | 469 }; |
469 | 470 |
470 | 471 |
471 class CObjectBigint : public CObject { | 472 class CObjectBigint : public CObject { |
472 public: | 473 public: |
473 // DECLARE_COBJECT_CONSTRUCTORS(Bigint) would miss hex_value_ initialization. | 474 // DECLARE_COBJECT_CONSTRUCTORS(Bigint) would miss hex_value_ initialization. |
474 explicit CObjectBigint(Dart_CObject *cobject) : CObject(cobject) { | 475 explicit CObjectBigint(Dart_CObject* cobject) : CObject(cobject) { |
475 ASSERT(type() == Dart_CObject_kBigint); | 476 ASSERT(type() == Dart_CObject_kBigint); |
476 cobject_ = cobject; | 477 cobject_ = cobject; |
477 hex_value_ = NULL; | 478 hex_value_ = NULL; |
478 } | 479 } |
479 explicit CObjectBigint(CObject* cobject) : CObject() { | 480 explicit CObjectBigint(CObject* cobject) : CObject() { |
480 ASSERT(cobject != NULL); | 481 ASSERT(cobject != NULL); |
481 ASSERT(cobject->type() == Dart_CObject_kBigint); | 482 ASSERT(cobject->type() == Dart_CObject_kBigint); |
482 cobject_ = cobject->AsApiCObject(); | 483 cobject_ = cobject->AsApiCObject(); |
483 hex_value_ = NULL; | 484 hex_value_ = NULL; |
484 } | 485 } |
485 | 486 |
486 char* Value() { | 487 char* Value() { |
487 if (hex_value_ == NULL) { | 488 if (hex_value_ == NULL) { |
488 hex_value_ = BigintToHexValue(cobject_); | 489 hex_value_ = BigintToHexValue(cobject_); |
489 } | 490 } |
490 ASSERT(hex_value_ != NULL); | 491 ASSERT(hex_value_ != NULL); |
491 return hex_value_; | 492 return hex_value_; |
492 } | 493 } |
493 | 494 |
494 ~CObjectBigint() { | 495 ~CObjectBigint() { free(hex_value_); } |
495 free(hex_value_); | |
496 } | |
497 | 496 |
498 private: | 497 private: |
499 char* hex_value_; | 498 char* hex_value_; |
500 DISALLOW_COPY_AND_ASSIGN(CObjectBigint); | 499 DISALLOW_COPY_AND_ASSIGN(CObjectBigint); |
501 }; | 500 }; |
502 | 501 |
503 | 502 |
504 class CObjectDouble : public CObject { | 503 class CObjectDouble : public CObject { |
505 public: | 504 public: |
506 DECLARE_COBJECT_CONSTRUCTORS(Double) | 505 DECLARE_COBJECT_CONSTRUCTORS(Double) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 Dart_Port Value() const { return cobject_->value.as_send_port.id; } | 547 Dart_Port Value() const { return cobject_->value.as_send_port.id; } |
549 Dart_Port OriginId() const { return cobject_->value.as_send_port.origin_id; } | 548 Dart_Port OriginId() const { return cobject_->value.as_send_port.origin_id; } |
550 | 549 |
551 private: | 550 private: |
552 DISALLOW_COPY_AND_ASSIGN(CObjectSendPort); | 551 DISALLOW_COPY_AND_ASSIGN(CObjectSendPort); |
553 }; | 552 }; |
554 | 553 |
555 | 554 |
556 class CObjectTypedData : public CObject { | 555 class CObjectTypedData : public CObject { |
557 public: | 556 public: |
558 explicit CObjectTypedData(Dart_CObject *cobject) : CObject(cobject) { | 557 explicit CObjectTypedData(Dart_CObject* cobject) : CObject(cobject) { |
559 ASSERT(type() == Dart_CObject_kTypedData); | 558 ASSERT(type() == Dart_CObject_kTypedData); |
560 cobject_ = cobject; | 559 cobject_ = cobject; |
561 } | 560 } |
562 explicit CObjectTypedData(CObject* cobject) : CObject() { | 561 explicit CObjectTypedData(CObject* cobject) : CObject() { |
563 ASSERT(cobject != NULL); | 562 ASSERT(cobject != NULL); |
564 ASSERT(cobject->type() == Dart_CObject_kTypedData); | 563 ASSERT(cobject->type() == Dart_CObject_kTypedData); |
565 cobject_ = cobject->AsApiCObject(); | 564 cobject_ = cobject->AsApiCObject(); |
566 } | 565 } |
567 | 566 |
568 Dart_TypedData_Type Type() const { | 567 Dart_TypedData_Type Type() const { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 return cobject_->value.as_external_typed_data.callback; | 603 return cobject_->value.as_external_typed_data.callback; |
605 } | 604 } |
606 | 605 |
607 private: | 606 private: |
608 DISALLOW_COPY_AND_ASSIGN(CObjectExternalUint8Array); | 607 DISALLOW_COPY_AND_ASSIGN(CObjectExternalUint8Array); |
609 }; | 608 }; |
610 | 609 |
611 | 610 |
612 class ScopedBlockingCall { | 611 class ScopedBlockingCall { |
613 public: | 612 public: |
614 ScopedBlockingCall() { | 613 ScopedBlockingCall() { Dart_ThreadDisableProfiling(); } |
615 Dart_ThreadDisableProfiling(); | |
616 } | |
617 | 614 |
618 ~ScopedBlockingCall() { | 615 ~ScopedBlockingCall() { Dart_ThreadEnableProfiling(); } |
619 Dart_ThreadEnableProfiling(); | |
620 } | |
621 | 616 |
622 private: | 617 private: |
623 DISALLOW_ALLOCATION(); | 618 DISALLOW_ALLOCATION(); |
624 DISALLOW_COPY_AND_ASSIGN(ScopedBlockingCall); | 619 DISALLOW_COPY_AND_ASSIGN(ScopedBlockingCall); |
625 }; | 620 }; |
626 | 621 |
627 | 622 |
628 // Where the argument to the constructor is the handle for an object | 623 // Where the argument to the constructor is the handle for an object |
629 // implementing List<int>, this class creates a scope in which the memory | 624 // implementing List<int>, this class creates a scope in which the memory |
630 // backing the list can be accessed. | 625 // backing the list can be accessed. |
631 // | 626 // |
632 // Do not make Dart_ API calls while in a ScopedMemBuffer. | 627 // Do not make Dart_ API calls while in a ScopedMemBuffer. |
633 // Do not call Dart_PropagateError while in a ScopedMemBuffer. | 628 // Do not call Dart_PropagateError while in a ScopedMemBuffer. |
634 class ScopedMemBuffer { | 629 class ScopedMemBuffer { |
635 public: | 630 public: |
636 explicit ScopedMemBuffer(Dart_Handle object) { | 631 explicit ScopedMemBuffer(Dart_Handle object) { |
637 if (!Dart_IsTypedData(object) && !Dart_IsList(object)) { | 632 if (!Dart_IsTypedData(object) && !Dart_IsList(object)) { |
638 Dart_ThrowException(DartUtils::NewDartArgumentError( | 633 Dart_ThrowException( |
639 "Argument is not a List<int>")); | 634 DartUtils::NewDartArgumentError("Argument is not a List<int>")); |
640 } | 635 } |
641 | 636 |
642 uint8_t* bytes = NULL; | 637 uint8_t* bytes = NULL; |
643 intptr_t bytes_len = 0; | 638 intptr_t bytes_len = 0; |
644 bool is_typed_data = false; | 639 bool is_typed_data = false; |
645 if (Dart_IsTypedData(object)) { | 640 if (Dart_IsTypedData(object)) { |
646 is_typed_data = true; | 641 is_typed_data = true; |
647 Dart_TypedData_Type typ; | 642 Dart_TypedData_Type typ; |
648 ThrowIfError(Dart_TypedDataAcquireData( | 643 ThrowIfError(Dart_TypedDataAcquireData( |
649 object, | 644 object, &typ, reinterpret_cast<void**>(&bytes), &bytes_len)); |
650 &typ, | |
651 reinterpret_cast<void**>(&bytes), | |
652 &bytes_len)); | |
653 } else { | 645 } else { |
654 ASSERT(Dart_IsList(object)); | 646 ASSERT(Dart_IsList(object)); |
655 ThrowIfError(Dart_ListLength(object, &bytes_len)); | 647 ThrowIfError(Dart_ListLength(object, &bytes_len)); |
656 bytes = Dart_ScopeAllocate(bytes_len); | 648 bytes = Dart_ScopeAllocate(bytes_len); |
657 ASSERT(bytes != NULL); | 649 ASSERT(bytes != NULL); |
658 ThrowIfError(Dart_ListGetAsBytes(object, 0, bytes, bytes_len)); | 650 ThrowIfError(Dart_ListGetAsBytes(object, 0, bytes, bytes_len)); |
659 } | 651 } |
660 | 652 |
661 object_ = object; | 653 object_ = object; |
662 bytes_ = bytes; | 654 bytes_ = bytes; |
(...skipping 17 matching lines...) Expand all Loading... |
680 bool is_typed_data_; | 672 bool is_typed_data_; |
681 | 673 |
682 DISALLOW_ALLOCATION(); | 674 DISALLOW_ALLOCATION(); |
683 DISALLOW_COPY_AND_ASSIGN(ScopedMemBuffer); | 675 DISALLOW_COPY_AND_ASSIGN(ScopedMemBuffer); |
684 }; | 676 }; |
685 | 677 |
686 } // namespace bin | 678 } // namespace bin |
687 } // namespace dart | 679 } // namespace dart |
688 | 680 |
689 #endif // RUNTIME_BIN_DARTUTILS_H_ | 681 #endif // RUNTIME_BIN_DARTUTILS_H_ |
OLD | NEW |