OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 | 5 |
6 #include "bin/loader.h" | 6 #include "bin/loader.h" |
7 | 7 |
8 #include "bin/builtin.h" | 8 #include "bin/builtin.h" |
9 #include "bin/dartutils.h" | 9 #include "bin/dartutils.h" |
10 #include "bin/extensions.h" | 10 #include "bin/extensions.h" |
| 11 #include "bin/file.h" |
11 #include "bin/lockers.h" | 12 #include "bin/lockers.h" |
12 #include "bin/utils.h" | 13 #include "bin/utils.h" |
13 | 14 |
14 namespace dart { | 15 namespace dart { |
15 namespace bin { | 16 namespace bin { |
16 | 17 |
17 // Development flag. | 18 // Development flag. |
18 static bool trace_loader = false; | 19 static bool trace_loader = false; |
19 // Keep in sync with loader.dart. | 20 // Keep in sync with loader.dart. |
20 static const intptr_t _Dart_kImportExtension = 9; | 21 static const intptr_t _Dart_kImportExtension = 9; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 Dart_Handle res = Dart_LibraryHandleError(library, error); | 255 Dart_Handle res = Dart_LibraryHandleError(library, error); |
255 if (Dart_IsNull(res)) { | 256 if (Dart_IsNull(res)) { |
256 // Error was handled by library. | 257 // Error was handled by library. |
257 return true; | 258 return true; |
258 } | 259 } |
259 } | 260 } |
260 return false; | 261 return false; |
261 } | 262 } |
262 | 263 |
263 | 264 |
264 static bool IsWindowsHost() { | 265 static bool PathContainsSeparator(const char* path) { |
265 #if defined(TARGET_OS_WINDOWS) | 266 return (strchr(path, '/') != NULL) || |
266 return true; | 267 ((strncmp(File::PathSeparator(), "/", 1) != 0) && |
267 #else // defined(TARGET_OS_WINDOWS) | 268 (strstr(path, File::PathSeparator()) != NULL)); |
268 return false; | |
269 #endif // defined(TARGET_OS_WINDOWS) | |
270 } | 269 } |
271 | 270 |
272 | 271 |
273 bool Loader::ProcessResultLocked(Loader* loader, Loader::IOResult* result) { | 272 bool Loader::ProcessResultLocked(Loader* loader, Loader::IOResult* result) { |
274 // We have to copy everything we care about out of |result| because after | 273 // We have to copy everything we care about out of |result| because after |
275 // dropping the lock below |result| may no longer valid. | 274 // dropping the lock below |result| may no longer valid. |
276 Dart_Handle uri = | 275 Dart_Handle uri = |
277 Dart_NewStringFromCString(reinterpret_cast<char*>(result->uri)); | 276 Dart_NewStringFromCString(reinterpret_cast<char*>(result->uri)); |
278 Dart_Handle resolved_uri = | 277 Dart_Handle resolved_uri = |
279 Dart_NewStringFromCString(reinterpret_cast<char*>(result->resolved_uri)); | 278 Dart_NewStringFromCString(reinterpret_cast<char*>(result->resolved_uri)); |
(...skipping 13 matching lines...) Expand all Loading... |
293 // the error. If the load requests stems from a deferred library load, | 292 // the error. If the load requests stems from a deferred library load, |
294 // an IO error is not fatal. | 293 // an IO error is not fatal. |
295 if (LibraryHandleError(library, error)) { | 294 if (LibraryHandleError(library, error)) { |
296 return true; | 295 return true; |
297 } | 296 } |
298 // Fall through | 297 // Fall through |
299 loader->error_ = Dart_NewUnhandledExceptionError(error); | 298 loader->error_ = Dart_NewUnhandledExceptionError(error); |
300 return false; | 299 return false; |
301 } | 300 } |
302 | 301 |
303 | |
304 if (result->tag == _Dart_kImportExtension) { | 302 if (result->tag == _Dart_kImportExtension) { |
305 ASSERT(library_uri != Dart_Null()); | 303 ASSERT(library_uri != Dart_Null()); |
306 Dart_Handle library = Dart_LookupLibrary(library_uri); | 304 Dart_Handle library = Dart_LookupLibrary(library_uri); |
307 ASSERT(!Dart_IsError(library)); | 305 ASSERT(!Dart_IsError(library)); |
308 const char* lib_uri = reinterpret_cast<const char*>(result->payload); | 306 const char* lib_uri = reinterpret_cast<const char*>(result->payload); |
309 if (strncmp(lib_uri, "http://", 7) == 0 || | 307 if (strncmp(lib_uri, "http://", 7) == 0 || |
310 strncmp(lib_uri, "https://", 8) == 0) { | 308 strncmp(lib_uri, "https://", 8) == 0) { |
311 loader->error_ = | 309 loader->error_ = |
312 Dart_NewApiError("Cannot load native extensions over http: or https:"); | 310 Dart_NewApiError("Cannot load native extensions over http: or https:"); |
313 return false; | 311 return false; |
314 } | 312 } |
315 const char* extension_uri = reinterpret_cast<const char*>(result->uri); | 313 const char* extension_uri = reinterpret_cast<const char*>(result->uri); |
316 const char* lib_path = NULL; | 314 const char* lib_path = NULL; |
317 if (strncmp(lib_uri, "file://", 7) == 0) { | 315 if (strncmp(lib_uri, "file://", 7) == 0) { |
318 lib_path = DartUtils::RemoveScheme(lib_uri); | 316 lib_path = DartUtils::RemoveScheme(lib_uri); |
319 } else { | 317 } else { |
320 lib_path = lib_uri; | 318 lib_path = lib_uri; |
321 } | 319 } |
322 const char* extension_path = DartUtils::RemoveScheme(extension_uri); | 320 const char* extension_path = DartUtils::RemoveScheme(extension_uri); |
323 if (strchr(extension_path, '/') != NULL || | 321 if (!File::IsAbsolutePath(extension_path) && |
324 (IsWindowsHost() && strchr(extension_path, '\\') != NULL)) { | 322 PathContainsSeparator(extension_path)) { |
325 loader->error_ = DartUtils::NewError( | 323 loader->error_ = DartUtils::NewError( |
326 "Relative paths for dart extensions are not supported: '%s'", | 324 "Native extension path must be absolute, or simply the file name: %s", |
327 extension_path); | 325 extension_path); |
328 return false; | 326 return false; |
329 } | 327 } |
330 Dart_Handle result = Extensions::LoadExtension(lib_path, | 328 Dart_Handle result = Extensions::LoadExtension(lib_path, |
331 extension_path, | 329 extension_path, |
332 library); | 330 library); |
333 if (Dart_IsError(result)) { | 331 if (Dart_IsError(result)) { |
334 loader->error_ = result; | 332 loader->error_ = result; |
335 return false; | 333 return false; |
336 } | 334 } |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 MutexLocker ml(loader_infos_lock_); | 756 MutexLocker ml(loader_infos_lock_); |
759 Loader* loader = LoaderForLocked(dest_port_id); | 757 Loader* loader = LoaderForLocked(dest_port_id); |
760 if (loader == NULL) { | 758 if (loader == NULL) { |
761 return; | 759 return; |
762 } | 760 } |
763 loader->QueueMessage(message); | 761 loader->QueueMessage(message); |
764 } | 762 } |
765 | 763 |
766 } // namespace bin | 764 } // namespace bin |
767 } // namespace dart | 765 } // namespace dart |
OLD | NEW |