| 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 "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
| 10 | 10 |
| 11 #include "platform/assert.h" | 11 #include "platform/assert.h" |
| 12 #include "platform/globals.h" | 12 #include "platform/globals.h" |
| 13 | 13 |
| 14 #include "bin/isolate_data.h" |
| 15 |
| 14 namespace dart { | 16 namespace dart { |
| 15 namespace bin { | 17 namespace bin { |
| 16 | 18 |
| 17 // Forward declarations. | 19 // Forward declarations. |
| 18 class File; | 20 class File; |
| 19 class OSError; | 21 class OSError; |
| 20 | 22 |
| 21 /* Handles error handles returned from Dart API functions. If a value | 23 /* Handles error handles returned from Dart API functions. If a value |
| 22 * is an error, uses Dart_PropagateError to throw it to the enclosing | 24 * is an error, uses Dart_PropagateError to throw it to the enclosing |
| 23 * Dart activation. Otherwise, returns the original handle. | 25 * Dart activation. Otherwise, returns the original handle. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 static void* OpenFile(const char* name, bool write); | 118 static void* OpenFile(const char* name, bool write); |
| 117 static void ReadFile(const uint8_t** data, intptr_t* file_len, void* stream); | 119 static void ReadFile(const uint8_t** data, intptr_t* file_len, void* stream); |
| 118 static void WriteFile(const void* buffer, intptr_t num_bytes, void* stream); | 120 static void WriteFile(const void* buffer, intptr_t num_bytes, void* stream); |
| 119 static void CloseFile(void* stream); | 121 static void CloseFile(void* stream); |
| 120 static bool EntropySource(uint8_t* buffer, intptr_t length); | 122 static bool EntropySource(uint8_t* buffer, intptr_t length); |
| 121 static Dart_Handle ReadStringFromFile(const char* filename); | 123 static Dart_Handle ReadStringFromFile(const char* filename); |
| 122 static Dart_Handle MakeUint8Array(const uint8_t* buffer, intptr_t length); | 124 static Dart_Handle MakeUint8Array(const uint8_t* buffer, intptr_t length); |
| 123 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, | 125 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, |
| 124 Dart_Handle library, | 126 Dart_Handle library, |
| 125 Dart_Handle url); | 127 Dart_Handle url); |
| 126 static Dart_Handle LoadScript(const char* script_uri, | 128 static Dart_Handle LoadScript(const char* script_uri); |
| 127 Dart_Handle builtin_lib); | 129 static Dart_Handle PrepareForScriptLoading(bool is_service_isolate, |
| 128 static Dart_Handle PrepareBuiltinLibrary(Dart_Handle builtin_lib, | 130 bool trace_loading); |
| 129 Dart_Handle internal_lib, | 131 static Dart_Handle SetupServiceLoadPort(); |
| 130 bool is_service_isolate, | 132 static Dart_Handle SetupPackageRoot(const char* package_root, |
| 131 bool trace_loading, | 133 const char* packages_file); |
| 132 const char* package_root, | |
| 133 const char* packages_file); | |
| 134 static Dart_Handle PrepareCoreLibrary(Dart_Handle core_lib, | |
| 135 Dart_Handle builtin_lib, | |
| 136 bool is_service_isolate); | |
| 137 static Dart_Handle PrepareAsyncLibrary(Dart_Handle async_lib, | |
| 138 Dart_Handle isolate_lib); | |
| 139 static Dart_Handle PrepareIOLibrary(Dart_Handle io_lib); | |
| 140 static Dart_Handle PrepareIsolateLibrary(Dart_Handle isolate_lib); | |
| 141 static Dart_Handle PrepareForScriptLoading(const char* package_root, | |
| 142 const char* packages_file, | |
| 143 bool is_service_isolate, | |
| 144 bool trace_loading, | |
| 145 Dart_Handle builtin_lib); | |
| 146 static Dart_Handle SetupIOLibrary(const char* script_uri); | 134 static Dart_Handle SetupIOLibrary(const char* script_uri); |
| 147 | 135 |
| 148 static bool PostNull(Dart_Port port_id); | 136 static bool PostNull(Dart_Port port_id); |
| 149 static bool PostInt32(Dart_Port port_id, int32_t value); | 137 static bool PostInt32(Dart_Port port_id, int32_t value); |
| 150 static bool PostInt64(Dart_Port port_id, int64_t value); | 138 static bool PostInt64(Dart_Port port_id, int64_t value); |
| 151 | 139 |
| 152 static Dart_Handle GetDartType(const char* library_url, | 140 static Dart_Handle GetDartType(const char* library_url, |
| 153 const char* class_name); | 141 const char* class_name); |
| 154 // Create a new Dart OSError object with the current OS error. | 142 // Create a new Dart OSError object with the current OS error. |
| 155 static Dart_Handle NewDartOSError(); | 143 static Dart_Handle NewDartOSError(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 172 static Dart_Handle NewString(const char* str) { | 160 static Dart_Handle NewString(const char* str) { |
| 173 ASSERT(str != NULL); | 161 ASSERT(str != NULL); |
| 174 return Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(str), | 162 return Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(str), |
| 175 strlen(str)); | 163 strlen(str)); |
| 176 } | 164 } |
| 177 | 165 |
| 178 // Create a new Dart InternalError object with the provided message. | 166 // Create a new Dart InternalError object with the provided message. |
| 179 static Dart_Handle NewError(const char* format, ...); | 167 static Dart_Handle NewError(const char* format, ...); |
| 180 static Dart_Handle NewInternalError(const char* message); | 168 static Dart_Handle NewInternalError(const char* message); |
| 181 | 169 |
| 170 static Dart_Handle BuiltinLib() { |
| 171 IsolateData* isolate_data = |
| 172 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
| 173 return isolate_data->builtin_lib(); |
| 174 } |
| 175 |
| 182 static bool SetOriginalWorkingDirectory(); | 176 static bool SetOriginalWorkingDirectory(); |
| 183 | 177 |
| 184 static const char* MapLibraryUrl(CommandLineOptions* url_mapping, | 178 static const char* MapLibraryUrl(CommandLineOptions* url_mapping, |
| 185 const char* url_string); | 179 const char* url_string); |
| 186 | 180 |
| 187 static Dart_Handle SetWorkingDirectory(Dart_Handle builtin_lib); | 181 static Dart_Handle ResolveUriInWorkingDirectory(Dart_Handle script_uri); |
| 188 | 182 static Dart_Handle FilePathFromUri(Dart_Handle script_uri); |
| 189 static Dart_Handle ResolveUriInWorkingDirectory(Dart_Handle script_uri, | 183 static Dart_Handle ResolveUri(Dart_Handle library_url, Dart_Handle url); |
| 190 Dart_Handle builtin_lib); | |
| 191 | |
| 192 static Dart_Handle FilePathFromUri(Dart_Handle script_uri, | |
| 193 Dart_Handle builtin_lib); | |
| 194 | |
| 195 static Dart_Handle ExtensionPathFromUri(Dart_Handle extension_uri, | |
| 196 Dart_Handle builtin_lib); | |
| 197 | |
| 198 static Dart_Handle ResolveUri(Dart_Handle library_url, | |
| 199 Dart_Handle url, | |
| 200 Dart_Handle builtin_lib); | |
| 201 | 184 |
| 202 // Sniffs the specified text_buffer to see if it contains the magic number | 185 // Sniffs the specified text_buffer to see if it contains the magic number |
| 203 // representing a script snapshot. If the text_buffer is a script snapshot | 186 // representing a script snapshot. If the text_buffer is a script snapshot |
| 204 // the return value is an updated pointer to the text_buffer pointing past | 187 // the return value is an updated pointer to the text_buffer pointing past |
| 205 // the magic number value. The 'buffer_len' parameter is also appropriately | 188 // the magic number value. The 'buffer_len' parameter is also appropriately |
| 206 // adjusted. | 189 // adjusted. |
| 207 static const uint8_t* SniffForMagicNumber(const uint8_t* text_buffer, | 190 static const uint8_t* SniffForMagicNumber(const uint8_t* text_buffer, |
| 208 intptr_t* buffer_len, | 191 intptr_t* buffer_len, |
| 209 bool* is_snapshot); | 192 bool* is_snapshot); |
| 210 | 193 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 223 static const char* const kIsolateLibURL; | 206 static const char* const kIsolateLibURL; |
| 224 static const char* const kIOLibURL; | 207 static const char* const kIOLibURL; |
| 225 static const char* const kIOLibPatchURL; | 208 static const char* const kIOLibPatchURL; |
| 226 static const char* const kUriLibURL; | 209 static const char* const kUriLibURL; |
| 227 static const char* const kHttpScheme; | 210 static const char* const kHttpScheme; |
| 228 static const char* const kVMServiceLibURL; | 211 static const char* const kVMServiceLibURL; |
| 229 | 212 |
| 230 static const uint8_t magic_number[]; | 213 static const uint8_t magic_number[]; |
| 231 | 214 |
| 232 private: | 215 private: |
| 216 static Dart_Handle SetWorkingDirectory(); |
| 217 static Dart_Handle ExtensionPathFromUri(Dart_Handle extension_uri); |
| 218 |
| 219 static Dart_Handle PrepareBuiltinLibrary(Dart_Handle builtin_lib, |
| 220 Dart_Handle internal_lib, |
| 221 bool is_service_isolate, |
| 222 bool trace_loading); |
| 223 static Dart_Handle PrepareCoreLibrary(Dart_Handle core_lib, |
| 224 Dart_Handle builtin_lib, |
| 225 bool is_service_isolate); |
| 226 static Dart_Handle PrepareAsyncLibrary(Dart_Handle async_lib, |
| 227 Dart_Handle isolate_lib); |
| 228 static Dart_Handle PrepareIOLibrary(Dart_Handle io_lib); |
| 229 static Dart_Handle PrepareIsolateLibrary(Dart_Handle isolate_lib); |
| 230 |
| 233 DISALLOW_ALLOCATION(); | 231 DISALLOW_ALLOCATION(); |
| 234 DISALLOW_IMPLICIT_CONSTRUCTORS(DartUtils); | 232 DISALLOW_IMPLICIT_CONSTRUCTORS(DartUtils); |
| 235 }; | 233 }; |
| 236 | 234 |
| 237 | 235 |
| 238 class CObject { | 236 class CObject { |
| 239 public: | 237 public: |
| 240 // These match the constants in sdk/lib/io/common.dart. | 238 // These match the constants in sdk/lib/io/common.dart. |
| 241 static const int kSuccess = 0; | 239 static const int kSuccess = 0; |
| 242 static const int kArgumentError = 1; | 240 static const int kArgumentError = 1; |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 | 582 |
| 585 ~ScopedBlockingCall() { | 583 ~ScopedBlockingCall() { |
| 586 Dart_ThreadEnableProfiling(); | 584 Dart_ThreadEnableProfiling(); |
| 587 } | 585 } |
| 588 }; | 586 }; |
| 589 | 587 |
| 590 } // namespace bin | 588 } // namespace bin |
| 591 } // namespace dart | 589 } // namespace dart |
| 592 | 590 |
| 593 #endif // BIN_DARTUTILS_H_ | 591 #endif // BIN_DARTUTILS_H_ |
| OLD | NEW |