Chromium Code Reviews| Index: runtime/bin/builtin.cc |
| diff --git a/runtime/bin/builtin.cc b/runtime/bin/builtin.cc |
| index 14c954f72e38add3191bf5a34a82574318ce8902..6d6d418e0cf0146eec297b5d3a13bdfe88312029 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,62 @@ 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; |
| + switch (id) { |
| + case kBuiltinLibrary: |
| + url = Dart_NewString(DartUtils::kBuiltinLibURL); |
| + break; |
| + case kIOLibrary: |
| + url = Dart_NewString(DartUtils::kIOLibURL); |
| + break; |
| + case kNativeWrappersLibrary: |
| + url = Dart_NewString(DartUtils::kNativeWrappersLibURL); |
| + break; |
| + case kCoreImplLibrary: |
|
Ivan Posva
2012/01/21 20:24:55
Why are the native wrappers and the coreimpl libra
Mads Ager (google)
2012/01/23 11:35:38
You are absolutely right. Thanks.
This was a resu
|
| + url = Dart_NewString(DartUtils::kCoreImplLibURL); |
| + break; |
| + default: |
| + url = Dart_Error("unknown builtin library id: %d", id); |
| + break; |
| + } |
| + DART_CHECK_VALID(url); |
| + 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)); |
| } |