| 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 #include "bin/dartutils.h" | 5 #include "bin/dartutils.h" |
| 6 | 6 |
| 7 #include "bin/extensions.h" | 7 #include "bin/extensions.h" |
| 8 #include "bin/directory.h" | 8 #include "bin/directory.h" |
| 9 #include "bin/file.h" | 9 #include "bin/file.h" |
| 10 #include "include/dart_api.h" | 10 #include "include/dart_api.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 static bool IsWindowsHost() { | 31 static bool IsWindowsHost() { |
| 32 #if defined(TARGET_OS_WINDOWS) | 32 #if defined(TARGET_OS_WINDOWS) |
| 33 return true; | 33 return true; |
| 34 #else // defined(TARGET_OS_WINDOWS) | 34 #else // defined(TARGET_OS_WINDOWS) |
| 35 return false; | 35 return false; |
| 36 #endif // defined(TARGET_OS_WINDOWS) | 36 #endif // defined(TARGET_OS_WINDOWS) |
| 37 } | 37 } |
| 38 | 38 |
| 39 | 39 |
| 40 static const char* MapLibraryUrl(CommandLineOptions* url_mapping, | 40 const char* DartUtils::MapLibraryUrl(CommandLineOptions* url_mapping, |
| 41 const char* url_string) { | 41 const char* url_string) { |
| 42 ASSERT(url_mapping != NULL); | 42 ASSERT(url_mapping != NULL); |
| 43 // We need to check if the passed in url is found in the url_mapping array, | 43 // We need to check if the passed in url is found in the url_mapping array, |
| 44 // in that case use the mapped entry. | 44 // in that case use the mapped entry. |
| 45 int len = strlen(url_string); | 45 int len = strlen(url_string); |
| 46 for (int idx = 0; idx < url_mapping->count(); idx++) { | 46 for (int idx = 0; idx < url_mapping->count(); idx++) { |
| 47 const char* url_name = url_mapping->GetArgument(idx); | 47 const char* url_name = url_mapping->GetArgument(idx); |
| 48 if (!strncmp(url_string, url_name, len) && (url_name[len] == ',')) { | 48 if (!strncmp(url_string, url_name, len) && (url_name[len] == ',')) { |
| 49 const char* url_mapped_name = url_name + len + 1; | 49 const char* url_mapped_name = url_name + len + 1; |
| 50 if (strlen(url_mapped_name) != 0) { | 50 if (strlen(url_mapped_name) != 0) { |
| 51 return url_mapped_name; // Found a mapping for this URL. | 51 return url_mapped_name; // Found a mapping for this URL. |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 free(text_buffer); | 226 free(text_buffer); |
| 227 return Dart_Error("Unable to fully read contents"); | 227 return Dart_Error("Unable to fully read contents"); |
| 228 } | 228 } |
| 229 delete file; | 229 delete file; |
| 230 Dart_Handle str = Dart_NewStringFromUTF8(text_buffer, len); | 230 Dart_Handle str = Dart_NewStringFromUTF8(text_buffer, len); |
| 231 free(text_buffer); | 231 free(text_buffer); |
| 232 return str; | 232 return str; |
| 233 } | 233 } |
| 234 | 234 |
| 235 | 235 |
| 236 static Dart_Handle ResolveScriptUri(Dart_Handle script_uri, | 236 Dart_Handle DartUtils::ResolveScriptUri(Dart_Handle script_uri, |
| 237 Dart_Handle builtin_lib) { | 237 Dart_Handle builtin_lib) { |
| 238 const int kNumArgs = 3; | 238 const int kNumArgs = 3; |
| 239 Dart_Handle dart_args[kNumArgs]; | 239 Dart_Handle dart_args[kNumArgs]; |
| 240 dart_args[0] = DartUtils::NewString(DartUtils::original_working_directory); | 240 dart_args[0] = NewString(original_working_directory); |
| 241 dart_args[1] = script_uri; | 241 dart_args[1] = script_uri; |
| 242 dart_args[2] = (IsWindowsHost() ? Dart_True() : Dart_False()); | 242 dart_args[2] = (IsWindowsHost() ? Dart_True() : Dart_False()); |
| 243 return Dart_Invoke(builtin_lib, | 243 return Dart_Invoke(builtin_lib, |
| 244 DartUtils::NewString("_resolveScriptUri"), | 244 NewString("_resolveScriptUri"), |
| 245 kNumArgs, | 245 kNumArgs, |
| 246 dart_args); | 246 dart_args); |
| 247 } | 247 } |
| 248 | 248 |
| 249 | 249 |
| 250 static Dart_Handle FilePathFromUri(Dart_Handle script_uri, | 250 Dart_Handle DartUtils::FilePathFromUri(Dart_Handle script_uri, |
| 251 Dart_Handle builtin_lib) { | 251 Dart_Handle builtin_lib) { |
| 252 const int kNumArgs = 2; | 252 const int kNumArgs = 2; |
| 253 Dart_Handle dart_args[kNumArgs]; | 253 Dart_Handle dart_args[kNumArgs]; |
| 254 dart_args[0] = script_uri; | 254 dart_args[0] = script_uri; |
| 255 dart_args[1] = (IsWindowsHost() ? Dart_True() : Dart_False()); | 255 dart_args[1] = (IsWindowsHost() ? Dart_True() : Dart_False()); |
| 256 Dart_Handle script_path = Dart_Invoke( | 256 return Dart_Invoke(builtin_lib, |
| 257 builtin_lib, | 257 NewString("_filePathFromUri"), |
| 258 DartUtils::NewString("_filePathFromUri"), | 258 kNumArgs, |
| 259 kNumArgs, | 259 dart_args); |
| 260 dart_args); | |
| 261 return script_path; | |
| 262 } | 260 } |
| 263 | 261 |
| 264 | 262 |
| 263 Dart_Handle DartUtils::ResolveUri(Dart_Handle library_url, |
| 264 Dart_Handle url, |
| 265 Dart_Handle builtin_lib) { |
| 266 const int kNumArgs = 2; |
| 267 Dart_Handle dart_args[kNumArgs]; |
| 268 dart_args[0] = library_url; |
| 269 dart_args[1] = url; |
| 270 return Dart_Invoke( |
| 271 builtin_lib, NewString("_resolveUri"), kNumArgs, dart_args); |
| 272 } |
| 273 |
| 274 |
| 265 Dart_Handle DartUtils::LibraryTagHandler(Dart_LibraryTag tag, | 275 Dart_Handle DartUtils::LibraryTagHandler(Dart_LibraryTag tag, |
| 266 Dart_Handle library, | 276 Dart_Handle library, |
| 267 Dart_Handle url) { | 277 Dart_Handle url) { |
| 268 if (!Dart_IsLibrary(library)) { | 278 if (!Dart_IsLibrary(library)) { |
| 269 return Dart_Error("not a library"); | 279 return Dart_Error("not a library"); |
| 270 } | 280 } |
| 271 if (!Dart_IsString(url)) { | 281 if (!Dart_IsString(url)) { |
| 272 return Dart_Error("url is not a string"); | 282 return Dart_Error("url is not a string"); |
| 273 } | 283 } |
| 274 const char* url_string = NULL; | 284 const char* url_string = NULL; |
| 275 Dart_Handle result = Dart_StringToCString(url, &url_string); | 285 Dart_Handle result = Dart_StringToCString(url, &url_string); |
| 276 if (Dart_IsError(result)) { | 286 if (Dart_IsError(result)) { |
| 277 return result; | 287 return result; |
| 278 } | 288 } |
| 279 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); | 289 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); |
| 280 bool is_dart_extension_url = DartUtils::IsDartExtensionSchemeURL(url_string); | 290 bool is_dart_extension_url = DartUtils::IsDartExtensionSchemeURL(url_string); |
| 281 if (tag == kCanonicalizeUrl) { | 291 if (tag == kCanonicalizeUrl) { |
| 282 // If this is a Dart Scheme URL then it is not modified as it will be | 292 // If this is a Dart Scheme URL then it is not modified as it will be |
| 283 // handled by the VM internally. | 293 // handled by the VM internally. |
| 284 if (is_dart_scheme_url) { | 294 if (is_dart_scheme_url) { |
| 285 return url; | 295 return url; |
| 286 } | 296 } |
| 287 // Resolve the url within the context of the library's URL. | 297 // Resolve the url within the context of the library's URL. |
| 288 Dart_Handle builtin_lib = | 298 Dart_Handle builtin_lib = |
| 289 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 299 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 290 Dart_Handle library_url = Dart_LibraryUrl(library); | 300 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 291 if (Dart_IsError(library_url)) { | 301 if (Dart_IsError(library_url)) { |
| 292 return library_url; | 302 return library_url; |
| 293 } | 303 } |
| 294 const int kNumArgs = 2; | 304 return ResolveUri(library_url, url, builtin_lib); |
| 295 Dart_Handle dart_args[kNumArgs]; | |
| 296 dart_args[0] = library_url; | |
| 297 dart_args[1] = url; | |
| 298 return Dart_Invoke( | |
| 299 builtin_lib, NewString("_resolveUri"), kNumArgs, dart_args); | |
| 300 } | 305 } |
| 301 if (is_dart_scheme_url) { | 306 if (is_dart_scheme_url) { |
| 302 ASSERT(tag == kImportTag); | 307 ASSERT(tag == kImportTag); |
| 303 // Handle imports of other built-in libraries present in the SDK. | 308 // Handle imports of other built-in libraries present in the SDK. |
| 304 Builtin::BuiltinLibraryId id; | 309 Builtin::BuiltinLibraryId id; |
| 305 if (DartUtils::IsDartCryptoLibURL(url_string)) { | 310 if (DartUtils::IsDartCryptoLibURL(url_string)) { |
| 306 id = Builtin::kCryptoLibrary; | 311 id = Builtin::kCryptoLibrary; |
| 307 } else if (DartUtils::IsDartIOLibURL(url_string)) { | 312 } else if (DartUtils::IsDartIOLibURL(url_string)) { |
| 308 id = Builtin::kIOLibrary; | 313 id = Builtin::kIOLibrary; |
| 309 } else if (DartUtils::IsDartJsonLibURL(url_string)) { | 314 } else if (DartUtils::IsDartJsonLibURL(url_string)) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 336 library, | 341 library, |
| 337 url, | 342 url, |
| 338 tag, | 343 tag, |
| 339 url_string); | 344 url_string); |
| 340 return result; | 345 return result; |
| 341 } | 346 } |
| 342 | 347 |
| 343 | 348 |
| 344 static Dart_Handle ReadSource(Dart_Handle script_uri, | 349 static Dart_Handle ReadSource(Dart_Handle script_uri, |
| 345 Dart_Handle builtin_lib) { | 350 Dart_Handle builtin_lib) { |
| 346 Dart_Handle script_path = FilePathFromUri(script_uri, builtin_lib); | 351 Dart_Handle script_path = DartUtils::FilePathFromUri(script_uri, builtin_lib); |
| 347 if (Dart_IsError(script_path)) { | 352 if (Dart_IsError(script_path)) { |
| 348 return script_path; | 353 return script_path; |
| 349 } | 354 } |
| 350 const char* script_path_cstr; | 355 const char* script_path_cstr; |
| 351 Dart_StringToCString(script_path, &script_path_cstr); | 356 Dart_StringToCString(script_path, &script_path_cstr); |
| 352 Dart_Handle source = DartUtils::ReadStringFromFile(script_path_cstr); | 357 Dart_Handle source = DartUtils::ReadStringFromFile(script_path_cstr); |
| 353 return source; | 358 return source; |
| 354 } | 359 } |
| 355 | 360 |
| 356 | 361 |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 | 697 |
| 693 CObject* CObject::NewOSError(OSError* os_error) { | 698 CObject* CObject::NewOSError(OSError* os_error) { |
| 694 CObject* error_message = | 699 CObject* error_message = |
| 695 new CObjectString(CObject::NewString(os_error->message())); | 700 new CObjectString(CObject::NewString(os_error->message())); |
| 696 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 701 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 697 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 702 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
| 698 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 703 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
| 699 result->SetAt(2, error_message); | 704 result->SetAt(2, error_message); |
| 700 return result; | 705 return result; |
| 701 } | 706 } |
| OLD | NEW |