Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, 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 static void SetupAdditionalImports(Dart_Handle builtin_lib) { | |
| 26 // Lookup the isolate library and import the builtin library into them. | |
| 27 Dart_Handle url = Dart_NewString(DartUtils::kIsolateLibURL); | |
| 28 Dart_Handle isolate_lib = Dart_LookupLibrary(url); | |
| 29 DART_CHECK_VALID(isolate_lib); | |
| 30 DART_CHECK_VALID(Dart_LibraryImportLibrary(isolate_lib, builtin_lib)); | |
|
siva
2012/02/22 00:58:20
These 4 lines seem to be repeated a number of time
Siggi Cherem (dart-lang)
2012/02/22 19:18:50
Done.
| |
| 31 } | |
| 32 | |
| 25 | 33 |
| 26 Dart_Handle Builtin::Source(BuiltinLibraryId id) { | 34 Dart_Handle Builtin::Source(BuiltinLibraryId id) { |
| 27 Dart_Handle source; | 35 Dart_Handle source; |
| 28 switch (id) { | 36 switch (id) { |
| 29 case kBuiltinLibrary: | 37 case kBuiltinLibrary: |
| 30 source = Dart_NewString(Builtin::builtin_source_); | 38 source = Dart_NewString(Builtin::builtin_source_); |
| 31 break; | 39 break; |
| 32 case kIOLibrary: | 40 case kIOLibrary: |
| 33 source = Dart_NewString(Builtin::io_source_); | 41 source = Dart_NewString(Builtin::io_source_); |
| 34 break; | 42 break; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 48 } | 56 } |
| 49 | 57 |
| 50 | 58 |
| 51 void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) { | 59 void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) { |
| 52 if ((id == kJsonLibrary) || (id == kUriLibrary) || (id == kUtf8Library)) { | 60 if ((id == kJsonLibrary) || (id == kUriLibrary) || (id == kUtf8Library)) { |
| 53 // No native resolver for these pure Dart libraries. | 61 // No native resolver for these pure Dart libraries. |
| 54 return; | 62 return; |
| 55 } else if (id == kBuiltinLibrary) { | 63 } else if (id == kBuiltinLibrary) { |
| 56 // Setup core lib, builtin import structure. | 64 // Setup core lib, builtin import structure. |
| 57 SetupCorelibImports(library); | 65 SetupCorelibImports(library); |
| 66 SetupAdditionalImports(library); | |
|
siva
2012/02/22 00:58:20
Are we sure that all these additional libraries wi
Siggi Cherem (dart-lang)
2012/02/22 19:18:50
yes - we are currently loading/compiling them imme
| |
| 58 } | 67 } |
| 59 // Setup the native resolver for built in library functions. | 68 // Setup the native resolver for built in library functions. |
| 60 DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup)); | 69 DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup)); |
| 61 } | 70 } |
| 62 | 71 |
| 63 | 72 |
| 64 Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) { | 73 Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) { |
| 65 Dart_Handle url; | 74 Dart_Handle url; |
| 66 switch (id) { | 75 switch (id) { |
| 67 case kBuiltinLibrary: | 76 case kBuiltinLibrary: |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 93 DART_CHECK_VALID(library); | 102 DART_CHECK_VALID(library); |
| 94 return library; | 103 return library; |
| 95 } | 104 } |
| 96 | 105 |
| 97 | 106 |
| 98 void Builtin::ImportLibrary(Dart_Handle library, BuiltinLibraryId id) { | 107 void Builtin::ImportLibrary(Dart_Handle library, BuiltinLibraryId id) { |
| 99 Dart_Handle imported_library = LoadLibrary(id); | 108 Dart_Handle imported_library = LoadLibrary(id); |
| 100 // Import the library into current library. | 109 // Import the library into current library. |
| 101 DART_CHECK_VALID(Dart_LibraryImportLibrary(library, imported_library)); | 110 DART_CHECK_VALID(Dart_LibraryImportLibrary(library, imported_library)); |
| 102 } | 111 } |
| OLD | NEW |