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

Unified Diff: bin/main.cc

Issue 8549009: Refactor the library tag handler to share code between standalone dart and the snapshot generator. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bin/gen_snapshot.cc ('k') | bin/process_script.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bin/main.cc
===================================================================
--- bin/main.cc (revision 1664)
+++ bin/main.cc (working copy)
@@ -9,9 +9,9 @@
#include "include/dart_api.h"
#include "bin/builtin.h"
+#include "bin/dartutils.h"
#include "bin/file.h"
#include "bin/globals.h"
-#include "bin/process_script.h"
// snapshot_buffer points to a snapshot if we link in a snapshot otherwise
// it is initialized to NULL.
@@ -157,6 +157,52 @@
}
+static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag,
+ Dart_Handle library,
+ Dart_Handle url) {
+ if (!Dart_IsLibrary(library)) {
+ return Dart_Error("not a library");
+ }
+ if (!Dart_IsString8(url)) {
+ return Dart_Error("url is not a string");
+ }
+ const char* url_string = NULL;
+ Dart_Handle result = Dart_StringToCString(url, &url_string);
+ if (Dart_IsError(result)) {
+ return Dart_Error("accessing url characters failed");
+ }
+ bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string);
+ if (tag == kCanonicalizeUrl) {
+ // If this is a Dart Scheme URL then it is not modified as it will be
+ // handled by the VM internally.
+ if (is_dart_scheme_url) {
+ return url;
+ }
+ // Create a canonical path based on the including library and current url.
+ return DartUtils::CanonicalizeURL(NULL, library, url_string);
+ }
+ if (is_dart_scheme_url) {
+ return Dart_Error("Do not know how to load '%s'", url_string);
+ }
+ result = DartUtils::LoadSource(NULL, library, url, tag, url_string);
+ if (!Dart_IsError(result) && (tag == kImportTag)) {
+ Builtin_ImportLibrary(result);
+ }
+ return result;
+}
+
+
+static Dart_Handle LoadScript(const char* script_name) {
+ Dart_Handle source = DartUtils::ReadStringFromFile(script_name);
+ if (Dart_IsError(source)) {
+ return source;
+ }
+ Dart_Handle url = Dart_NewString(script_name);
+
+ return Dart_LoadScript(url, source, LibraryTagHandler);
+}
+
+
static void* MainIsolateInitCallback(void* data) {
const char* script_name = reinterpret_cast<const char*>(data);
Dart_Handle library;
« no previous file with comments | « bin/gen_snapshot.cc ('k') | bin/process_script.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698