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" |
11 #include "platform/globals.h" | 11 #include "platform/globals.h" |
12 | 12 |
| 13 /* Handles error handles returned from Dart API functions. If a value |
| 14 * is an error, uses Dart_PropagateError to throw it to the enclosing |
| 15 * Dart activation. Otherwise, returns the original handle. |
| 16 * |
| 17 * This function can be used to wrap most API functions, but API |
| 18 * functions can also be nested without this error check, since all |
| 19 * API functions return any error handles passed in as arguments, unchanged. |
| 20 */ |
| 21 static inline Dart_Handle ThrowIfError(Dart_Handle handle) { |
| 22 if (Dart_IsError(handle)) Dart_PropagateError(handle); |
| 23 return handle; |
| 24 } |
| 25 |
13 class CommandLineOptions { | 26 class CommandLineOptions { |
14 public: | 27 public: |
15 explicit CommandLineOptions(int max_count) | 28 explicit CommandLineOptions(int max_count) |
16 : count_(0), max_count_(max_count), arguments_(NULL) { | 29 : count_(0), max_count_(max_count), arguments_(NULL) { |
17 static const int kWordSize = sizeof(intptr_t); | 30 static const int kWordSize = sizeof(intptr_t); |
18 arguments_ = reinterpret_cast<const char **>(malloc(max_count * kWordSize)); | 31 arguments_ = reinterpret_cast<const char **>(malloc(max_count * kWordSize)); |
19 if (arguments_ == NULL) { | 32 if (arguments_ == NULL) { |
20 max_count_ = 0; | 33 max_count_ = 0; |
21 } | 34 } |
22 } | 35 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 Dart_Handle library, | 111 Dart_Handle library, |
99 Dart_Handle url, | 112 Dart_Handle url, |
100 Dart_LibraryTag tag, | 113 Dart_LibraryTag tag, |
101 const char* filename); | 114 const char* filename); |
102 static Dart_Handle PrepareForScriptLoading(const char* package_root, | 115 static Dart_Handle PrepareForScriptLoading(const char* package_root, |
103 Dart_Handle builtin_lib); | 116 Dart_Handle builtin_lib); |
104 | 117 |
105 static bool PostNull(Dart_Port port_id); | 118 static bool PostNull(Dart_Port port_id); |
106 static bool PostInt32(Dart_Port port_id, int32_t value); | 119 static bool PostInt32(Dart_Port port_id, int32_t value); |
107 | 120 |
| 121 static Dart_Handle GetDartClass(const char* library_url, |
| 122 const char* class_name); |
108 // Create a new Dart OSError object with the current OS error. | 123 // Create a new Dart OSError object with the current OS error. |
109 static Dart_Handle NewDartOSError(); | 124 static Dart_Handle NewDartOSError(); |
110 // Create a new Dart OSError object with the provided OS error. | 125 // Create a new Dart OSError object with the provided OS error. |
111 static Dart_Handle NewDartOSError(OSError* os_error); | 126 static Dart_Handle NewDartOSError(OSError* os_error); |
| 127 static Dart_Handle NewDartExceptionWithMessage(const char* library_url, |
| 128 const char* exception_name, |
| 129 const char* message); |
| 130 static Dart_Handle NewDartArgumentError(const char* message); |
112 | 131 |
113 // Create a new Dart String object from a C String. | 132 // Create a new Dart String object from a C String. |
114 static Dart_Handle NewString(const char* str) { | 133 static Dart_Handle NewString(const char* str) { |
115 ASSERT((str != NULL) && (strlen(str) != 0)); | 134 ASSERT((str != NULL) && (strlen(str) != 0)); |
116 return Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(str), | 135 return Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(str), |
117 strlen(str)); | 136 strlen(str)); |
118 } | 137 } |
119 | 138 |
120 static void SetOriginalWorkingDirectory(); | 139 static void SetOriginalWorkingDirectory(); |
121 | 140 |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 void* Peer() const { return cobject_->value.as_external_byte_array.peer; } | 389 void* Peer() const { return cobject_->value.as_external_byte_array.peer; } |
371 Dart_PeerFinalizer Callback() const { | 390 Dart_PeerFinalizer Callback() const { |
372 return cobject_->value.as_external_byte_array.callback; | 391 return cobject_->value.as_external_byte_array.callback; |
373 } | 392 } |
374 | 393 |
375 private: | 394 private: |
376 DISALLOW_COPY_AND_ASSIGN(CObjectExternalUint8Array); | 395 DISALLOW_COPY_AND_ASSIGN(CObjectExternalUint8Array); |
377 }; | 396 }; |
378 | 397 |
379 #endif // BIN_DARTUTILS_H_ | 398 #endif // BIN_DARTUTILS_H_ |
OLD | NEW |