| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Handle dart scripts. | 5 // Handle dart scripts. |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 char* canonical_filename = File::GetCanonicalPath(absolute_filename); | 51 char* canonical_filename = File::GetCanonicalPath(absolute_filename); |
| 52 if (canonical_filename == NULL) { | 52 if (canonical_filename == NULL) { |
| 53 return absolute_filename; | 53 return absolute_filename; |
| 54 } | 54 } |
| 55 free(absolute_filename); | 55 free(absolute_filename); |
| 56 return canonical_filename; | 56 return canonical_filename; |
| 57 } | 57 } |
| 58 | 58 |
| 59 | 59 |
| 60 static Dart_Handle ReadStringFromFile(const char* filename) { | 60 static Dart_Handle ReadStringFromFile(const char* filename) { |
| 61 File* file = File::OpenFile(filename, false); | 61 File* file = File::Open(filename, false); |
| 62 if (file == NULL) { | 62 if (file == NULL) { |
| 63 const char* format = "Unable to open file: %s"; | 63 const char* format = "Unable to open file: %s"; |
| 64 intptr_t len = snprintf(NULL, 0, format, filename); | 64 intptr_t len = snprintf(NULL, 0, format, filename); |
| 65 // TODO(iposva): Allocate from the zone instead of leaking error string | 65 // TODO(iposva): Allocate from the zone instead of leaking error string |
| 66 // here. On the other hand the binary is about the exit anyway. | 66 // here. On the other hand the binary is about the exit anyway. |
| 67 char* error_msg = reinterpret_cast<char*>(malloc(len + 1)); | 67 char* error_msg = reinterpret_cast<char*>(malloc(len + 1)); |
| 68 snprintf(error_msg, len + 1, format, filename); | 68 snprintf(error_msg, len + 1, format, filename); |
| 69 return Dart_Error(error_msg); | 69 return Dart_Error(error_msg); |
| 70 } | 70 } |
| 71 intptr_t len = file->Length(); | 71 intptr_t len = file->Length(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 174 |
| 175 Dart_Handle LoadSnapshotCreationScript(const char* script_name) { | 175 Dart_Handle LoadSnapshotCreationScript(const char* script_name) { |
| 176 Dart_Handle source = ReadStringFromFile(script_name); | 176 Dart_Handle source = ReadStringFromFile(script_name); |
| 177 if (!Dart_IsValid(source)) { | 177 if (!Dart_IsValid(source)) { |
| 178 return source; | 178 return source; |
| 179 } | 179 } |
| 180 Dart_Handle url = Dart_NewString(script_name); | 180 Dart_Handle url = Dart_NewString(script_name); |
| 181 | 181 |
| 182 return Dart_LoadScript(url, source, CreateSnapshotLibraryTagHandler); | 182 return Dart_LoadScript(url, source, CreateSnapshotLibraryTagHandler); |
| 183 } | 183 } |
| OLD | NEW |