OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include <stdio.h> | 5 #include <stdio.h> |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 | 8 |
9 #include "bin/builtin.h" | 9 #include "bin/builtin.h" |
10 #include "bin/dartutils.h" | 10 #include "bin/dartutils.h" |
11 | 11 |
12 static void SetupCorelibImports(Dart_Handle builtin_lib) { | 12 static void SetupCorelibImports(Dart_Handle builtin_lib) { |
13 // Lookup the core libraries and import the builtin library into them. | 13 // Lookup the core libraries and import the builtin library into them. |
14 Dart_Handle url = Dart_NewString(DartUtils::kCoreLibURL); | 14 Dart_Handle url = Dart_NewString(DartUtils::kCoreLibURL); |
15 Dart_Handle core_lib = Dart_LookupLibrary(url); | 15 Dart_Handle core_lib = Dart_LookupLibrary(url); |
16 DART_CHECK_VALID(core_lib); | 16 DART_CHECK_VALID(core_lib); |
17 DART_CHECK_VALID(Dart_LibraryImportLibrary(core_lib, builtin_lib)); | 17 DART_CHECK_VALID(Dart_LibraryImportLibrary(core_lib, builtin_lib)); |
18 | 18 |
19 url = Dart_NewString(DartUtils::kCoreImplLibURL); | 19 url = Dart_NewString(DartUtils::kCoreImplLibURL); |
20 Dart_Handle coreimpl_lib = Dart_LookupLibrary(url); | 20 Dart_Handle coreimpl_lib = Dart_LookupLibrary(url); |
21 DART_CHECK_VALID(coreimpl_lib); | 21 DART_CHECK_VALID(coreimpl_lib); |
22 DART_CHECK_VALID(Dart_LibraryImportLibrary(coreimpl_lib, builtin_lib)); | 22 DART_CHECK_VALID(Dart_LibraryImportLibrary(coreimpl_lib, builtin_lib)); |
23 } | 23 } |
24 | 24 |
25 | 25 |
26 Dart_Handle Builtin::Source() { | 26 Dart_Handle Builtin::Source(BuiltinLibraryId id) { |
27 Dart_Handle source = Dart_NewString(Builtin::Builtin_source_); | 27 Dart_Handle source; |
| 28 if (id == kBuiltinLibrary) { |
| 29 source = Dart_NewString(Builtin::builtin_source_); |
| 30 } else { |
| 31 ASSERT(id == kIOLibrary); |
| 32 source = Dart_NewString(Builtin::io_source_); |
| 33 } |
28 return source; | 34 return source; |
29 } | 35 } |
30 | 36 |
31 | 37 |
32 void Builtin::SetupLibrary(Dart_Handle builtin_lib) { | 38 void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) { |
33 // Setup core lib, builtin import structure. | 39 if (id == kBuiltinLibrary) { |
34 SetupCorelibImports(builtin_lib); | 40 // Setup core lib, builtin import structure. |
| 41 SetupCorelibImports(library); |
| 42 } |
35 // Setup the native resolver for built in library functions. | 43 // Setup the native resolver for built in library functions. |
36 DART_CHECK_VALID(Dart_SetNativeResolver(builtin_lib, NativeLookup)); | 44 DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup)); |
37 } | 45 } |
38 | 46 |
39 | 47 |
40 void Builtin::ImportLibrary(Dart_Handle library) { | 48 Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) { |
41 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); | 49 Dart_Handle url; |
42 Dart_Handle builtin_lib = Dart_LookupLibrary(url); | 50 if (id == kBuiltinLibrary) { |
43 if (Dart_IsError(builtin_lib)) { | 51 url = Dart_NewString(DartUtils::kBuiltinLibURL); |
44 builtin_lib = Dart_LoadLibrary(url, Source()); | 52 } else { |
45 if (!Dart_IsError(builtin_lib)) { | 53 ASSERT(id == kIOLibrary); |
46 SetupLibrary(builtin_lib); | 54 url = Dart_NewString(DartUtils::kIOLibURL); |
| 55 } |
| 56 Dart_Handle library = Dart_LookupLibrary(url); |
| 57 if (Dart_IsError(library)) { |
| 58 library = Dart_LoadLibrary(url, Source(id)); |
| 59 if (!Dart_IsError(library)) { |
| 60 SetupLibrary(library, id); |
47 } | 61 } |
48 } | 62 } |
49 // Import the builtin library into current library. | 63 DART_CHECK_VALID(library); |
50 DART_CHECK_VALID(builtin_lib); | 64 return library; |
51 DART_CHECK_VALID(Dart_LibraryImportLibrary(library, builtin_lib)); | |
52 } | 65 } |
| 66 |
| 67 |
| 68 void Builtin::ImportLibrary(Dart_Handle library, BuiltinLibraryId id) { |
| 69 Dart_Handle imported_library = LoadLibrary(id); |
| 70 // Import the library into current library. |
| 71 DART_CHECK_VALID(Dart_LibraryImportLibrary(library, imported_library)); |
| 72 } |
OLD | NEW |