Index: runtime/bin/builtin.cc |
diff --git a/runtime/bin/builtin.cc b/runtime/bin/builtin.cc |
index 14c954f72e38add3191bf5a34a82574318ce8902..02d298235d540b97bd01561535bc9bc917f199a5 100644 |
--- a/runtime/bin/builtin.cc |
+++ b/runtime/bin/builtin.cc |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
@@ -23,30 +23,50 @@ static void SetupCorelibImports(Dart_Handle builtin_lib) { |
} |
-Dart_Handle Builtin::Source() { |
- Dart_Handle source = Dart_NewString(Builtin::Builtin_source_); |
+Dart_Handle Builtin::Source(BuiltinLibraryId id) { |
+ Dart_Handle source; |
+ if (id == kBuiltinLibrary) { |
+ source = Dart_NewString(Builtin::builtin_source_); |
+ } else { |
+ ASSERT(id == kIOLibrary); |
+ source = Dart_NewString(Builtin::io_source_); |
+ } |
return source; |
} |
-void Builtin::SetupLibrary(Dart_Handle builtin_lib) { |
- // Setup core lib, builtin import structure. |
- SetupCorelibImports(builtin_lib); |
+void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) { |
+ if (id == kBuiltinLibrary) { |
+ // Setup core lib, builtin import structure. |
+ SetupCorelibImports(library); |
+ } |
// Setup the native resolver for built in library functions. |
- DART_CHECK_VALID(Dart_SetNativeResolver(builtin_lib, NativeLookup)); |
+ DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup)); |
} |
-void Builtin::ImportLibrary(Dart_Handle library) { |
- Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); |
- Dart_Handle builtin_lib = Dart_LookupLibrary(url); |
- if (Dart_IsError(builtin_lib)) { |
- builtin_lib = Dart_LoadLibrary(url, Source()); |
- if (!Dart_IsError(builtin_lib)) { |
- SetupLibrary(builtin_lib); |
+Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) { |
+ Dart_Handle url; |
+ if (id == kBuiltinLibrary) { |
+ url = Dart_NewString(DartUtils::kBuiltinLibURL); |
+ } else { |
+ ASSERT(id == kIOLibrary); |
+ url = Dart_NewString(DartUtils::kIOLibURL); |
+ } |
+ Dart_Handle library = Dart_LookupLibrary(url); |
+ if (Dart_IsError(library)) { |
+ library = Dart_LoadLibrary(url, Source(id)); |
+ if (!Dart_IsError(library)) { |
+ SetupLibrary(library, id); |
} |
} |
- // Import the builtin library into current library. |
- DART_CHECK_VALID(builtin_lib); |
- DART_CHECK_VALID(Dart_LibraryImportLibrary(library, builtin_lib)); |
+ DART_CHECK_VALID(library); |
+ return library; |
+} |
+ |
+ |
+void Builtin::ImportLibrary(Dart_Handle library, BuiltinLibraryId id) { |
+ Dart_Handle imported_library = LoadLibrary(id); |
+ // Import the library into current library. |
+ DART_CHECK_VALID(Dart_LibraryImportLibrary(library, imported_library)); |
} |