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

Unified Diff: runtime/bin/dartutils.cc

Issue 10871092: Added option --script-snapshot in gen_snapshot to generate the snapshot of a scipt into the file. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 months 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
Index: runtime/bin/dartutils.cc
===================================================================
--- runtime/bin/dartutils.cc (revision 11672)
+++ runtime/bin/dartutils.cc (working copy)
@@ -4,11 +4,14 @@
#include "bin/dartutils.h"
+#include "bin/extensions.h"
+#include "bin/directory.h"
#include "bin/file.h"
#include "include/dart_api.h"
#include "platform/assert.h"
#include "platform/globals.h"
+const char* DartUtils::original_working_directory = NULL;
const char* DartUtils::kDartScheme = "dart:";
const char* DartUtils::kDartExtensionScheme = "dart-ext:";
const char* DartUtils::kBuiltinLibURL = "dart:builtin";
@@ -26,6 +29,15 @@
const char* DartUtils::kIdFieldName = "_id";
+static bool IsWindowsHost() {
+#if defined(TARGET_OS_WINDOWS)
+ return true;
+#else // defined(TARGET_OS_WINDOWS)
+ return false;
+#endif // defined(TARGET_OS_WINDOWS)
+}
+
+
static const char* MapLibraryUrl(CommandLineOptions* url_mapping,
const char* url_string) {
ASSERT(url_mapping != NULL);
@@ -220,6 +232,146 @@
}
+static Dart_Handle ResolveScriptUri(Dart_Handle script_uri,
+ Dart_Handle builtin_lib) {
+ const int kNumArgs = 3;
+ Dart_Handle dart_args[kNumArgs];
+ dart_args[0] = Dart_NewString(DartUtils::original_working_directory);
+ dart_args[1] = script_uri;
+ dart_args[2] = (IsWindowsHost() ? Dart_True() : Dart_False());
+ return Dart_Invoke(
+ builtin_lib, Dart_NewString("_resolveScriptUri"), kNumArgs, dart_args);
+}
+
+
+static Dart_Handle FilePathFromUri(Dart_Handle script_uri,
+ Dart_Handle builtin_lib) {
+ const int kNumArgs = 2;
+ Dart_Handle dart_args[kNumArgs];
+ dart_args[0] = script_uri;
+ dart_args[1] = (IsWindowsHost() ? Dart_True() : Dart_False());
+ Dart_Handle script_path = Dart_Invoke(
+ builtin_lib, Dart_NewString("_filePathFromUri"), kNumArgs, dart_args);
+ return script_path;
+}
+
+
+Dart_Handle DartUtils::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 result;
+ }
+ bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string);
+ bool is_dart_extension_url = DartUtils::IsDartExtensionSchemeURL(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;
+ }
+ // Resolve the url within the context of the library's URL.
+ Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary);
+ Dart_Handle library_url = Dart_LibraryUrl(library);
+ if (Dart_IsError(library_url)) {
+ return library_url;
+ }
+ const int kNumArgs = 2;
+ Dart_Handle dart_args[kNumArgs];
+ dart_args[0] = library_url;
+ dart_args[1] = url;
+ return Dart_Invoke(
+ builtin_lib, Dart_NewString("_resolveUri"), kNumArgs, dart_args);
+ }
+ if (is_dart_scheme_url) {
+ ASSERT(tag == kImportTag);
+ // Handle imports of other built-in libraries present in the SDK.
+ Builtin::BuiltinLibraryId id;
+ if (DartUtils::IsDartCryptoLibURL(url_string)) {
+ id = Builtin::kCryptoLibrary;
+ } else if (DartUtils::IsDartIOLibURL(url_string)) {
+ id = Builtin::kIOLibrary;
+ } else if (DartUtils::IsDartJsonLibURL(url_string)) {
+ id = Builtin::kJsonLibrary;
+ } else if (DartUtils::IsDartUriLibURL(url_string)) {
+ id = Builtin::kUriLibrary;
+ } else if (DartUtils::IsDartUtfLibURL(url_string)) {
+ id = Builtin::kUtfLibrary;
+ } else if (DartUtils::IsDartWebLibURL(url_string)) {
+ id = Builtin::kWebLibrary;
+ } else {
+ return Dart_Error("Do not know how to load '%s'", url_string);
+ }
+ return Builtin::LoadLibrary(id);
+ } else {
+ // Get the file path out of the url.
+ Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary);
+ Dart_Handle file_path = FilePathFromUri(url, builtin_lib);
+ if (Dart_IsError(file_path)) {
+ return file_path;
+ }
+ Dart_StringToCString(file_path, &url_string);
+ }
+ if (is_dart_extension_url) {
+ if (tag != kImportTag) {
+ return Dart_Error("Dart extensions must use import: '%s'", url_string);
+ }
+ return Extensions::LoadExtension(url_string, library);
+ }
+ result = DartUtils::LoadSource(NULL,
+ library,
+ url,
+ tag,
+ url_string);
+ if (!Dart_IsError(result) && (tag == kImportTag)) {
+ Builtin::ImportLibrary(result, Builtin::kBuiltinLibrary);
+ }
+ return result;
+}
+
+
+static Dart_Handle ReadSource(Dart_Handle script_uri,
+ Dart_Handle builtin_lib) {
+ Dart_Handle script_path = FilePathFromUri(script_uri, builtin_lib);
+ if (Dart_IsError(script_path)) {
+ return script_path;
+ }
+ const char* script_path_cstr;
+ Dart_StringToCString(script_path, &script_path_cstr);
+ Dart_Handle source = DartUtils::ReadStringFromFile(script_path_cstr);
+ return source;
+}
+
+
+Dart_Handle DartUtils::LoadScript(const char* script_uri,
+ bool resolve_script,
+ Dart_Handle builtin_lib) {
+ Dart_Handle resolved_script_uri;
+ if (resolve_script) {
+ resolved_script_uri = ResolveScriptUri(Dart_NewString(script_uri),
+ builtin_lib);
+ if (Dart_IsError(resolved_script_uri)) {
+ return resolved_script_uri;
+ }
+ } else {
+ resolved_script_uri = Dart_NewString(script_uri);
+ }
+ Dart_Handle source = ReadSource(resolved_script_uri, builtin_lib);
+ if (Dart_IsError(source)) {
+ return source;
+ }
+ return Dart_LoadScript(resolved_script_uri, source);
+}
+
+
Dart_Handle DartUtils::LoadSource(CommandLineOptions* url_mapping,
Dart_Handle library,
Dart_Handle url,
@@ -331,6 +483,11 @@
}
+void DartUtils::SetOriginalWorkingDirectory() {
+ original_working_directory = Directory::Current();
+}
+
+
// Statically allocated Dart_CObject instances for immutable
// objects. As these will be used by different threads the use of
// these depends on the fact that the marking internally in the
« no previous file with comments | « runtime/bin/dartutils.h ('k') | runtime/bin/gen_snapshot.cc » ('j') | runtime/bin/main.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698