Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: bin/process_script.cc

Issue 8588016: When URL mapping was specified, library loads where not being called for the URLs that were mapped. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « bin/gen_snapshot.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 free(path); 42 free(path);
43 char* canonical_filename = File::GetCanonicalPath(absolute_filename); 43 char* canonical_filename = File::GetCanonicalPath(absolute_filename);
44 if (canonical_filename == NULL) { 44 if (canonical_filename == NULL) {
45 return absolute_filename; 45 return absolute_filename;
46 } 46 }
47 free(absolute_filename); 47 free(absolute_filename);
48 return canonical_filename; 48 return canonical_filename;
49 } 49 }
50 50
51 51
52 static const char* CanonicalizeUrl(const char* reference_dir,
53 const char* filename) {
54 static const char* kDartScheme = "dart:";
55 static const intptr_t kDartSchemeLen = strlen(kDartScheme);
56 // If the URL starts with "dart:" then it is not modified as it will be
57 // handled by the VM internally.
58 if (strncmp(filename, kDartScheme, kDartSchemeLen) == 0) {
59 return strdup(filename);
60 }
61 return GetCanonicalPath(reference_dir, filename);
62 }
63
64
65 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, 52 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag,
66 Dart_Handle library, 53 Dart_Handle library,
67 Dart_Handle url) { 54 Dart_Handle url) {
68 if (!Dart_IsLibrary(library)) { 55 if (!Dart_IsLibrary(library)) {
69 return Dart_Error("not a library"); 56 return Dart_Error("not a library");
70 } 57 }
71 if (!Dart_IsString8(url)) { 58 if (!Dart_IsString8(url)) {
72 return Dart_Error("url is not a string"); 59 return Dart_Error("url is not a string");
73 } 60 }
74 const char* url_chars = NULL; 61 const char* url_chars = NULL;
75 Dart_Handle result = Dart_StringToCString(url, &url_chars); 62 Dart_Handle result = Dart_StringToCString(url, &url_chars);
76 if (Dart_IsError(result)) { 63 if (Dart_IsError(result)) {
77 return Dart_Error("accessing url characters failed"); 64 return Dart_Error("accessing url characters failed");
78 } 65 }
79 66
67 static const char* kDartScheme = "dart:";
68 static const intptr_t kDartSchemeLen = strlen(kDartScheme);
69 // If the URL starts with "dart:" then it is not modified as it will be
70 // handled by the VM internally.
71 if (strncmp(url_chars, kDartScheme, kDartSchemeLen) == 0) {
72 if (tag == kCanonicalizeUrl) {
73 return url;
74 }
75 return Dart_Error("Do not know how to load '%s'", url_chars);
76 }
80 if (tag == kCanonicalizeUrl) { 77 if (tag == kCanonicalizeUrl) {
81 // Create the full path based on the including library and the current url. 78 // Create a canonical path based on the including library and current url.
82 79
83 // Get the url of the calling library. 80 // Get the url of the including library.
84 Dart_Handle library_url = Dart_LibraryUrl(library); 81 Dart_Handle library_url = Dart_LibraryUrl(library);
85 if (Dart_IsError(library_url)) { 82 if (Dart_IsError(library_url)) {
86 return Dart_Error("accessing library url failed"); 83 return Dart_Error("accessing library url failed");
87 } 84 }
88 if (!Dart_IsString8(library_url)) { 85 if (!Dart_IsString8(library_url)) {
89 return Dart_Error("library url is not a string"); 86 return Dart_Error("library url is not a string");
90 } 87 }
91 const char* library_url_chars = NULL; 88 const char* library_url_chars = NULL;
92 result = Dart_StringToCString(library_url, &library_url_chars); 89 result = Dart_StringToCString(library_url, &library_url_chars);
93 if (Dart_IsError(result)) { 90 if (Dart_IsError(result)) {
94 return Dart_Error("accessing library url characters failed"); 91 return Dart_Error("accessing library url characters failed");
95 } 92 }
96 93
97 // Calculate the path. 94 // Calculate the canonical path.
98 const char* canon_url_chars = CanonicalizeUrl(library_url_chars, url_chars); 95 const char* canon_url_chars = GetCanonicalPath(library_url_chars,
96 url_chars);
99 Dart_Handle canon_url = Dart_NewString(canon_url_chars); 97 Dart_Handle canon_url = Dart_NewString(canon_url_chars);
100 free(const_cast<char*>(canon_url_chars)); 98 free(const_cast<char*>(canon_url_chars));
101 99
102 return canon_url; 100 return canon_url;
103 } 101 }
104 102
105 // The tag is either an import or a source tag. Read the file based on the 103 // The tag is either an import or a source tag. Read the file based on the
106 // url chars. 104 // url chars.
107 Dart_Handle source = ReadStringFromFile(url_chars); 105 Dart_Handle source = ReadStringFromFile(url_chars);
108 if (Dart_IsError(source)) { 106 if (Dart_IsError(source)) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 150
153 Dart_Handle LoadScript(const char* script_name) { 151 Dart_Handle LoadScript(const char* script_name) {
154 Dart_Handle source = ReadStringFromFile(script_name); 152 Dart_Handle source = ReadStringFromFile(script_name);
155 if (Dart_IsError(source)) { 153 if (Dart_IsError(source)) {
156 return source; 154 return source;
157 } 155 }
158 Dart_Handle url = Dart_NewString(script_name); 156 Dart_Handle url = Dart_NewString(script_name);
159 157
160 return Dart_LoadScript(url, source, LibraryTagHandler); 158 return Dart_LoadScript(url, source, LibraryTagHandler);
161 } 159 }
OLDNEW
« no previous file with comments | « bin/gen_snapshot.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698