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

Side by Side Diff: runtime/bin/builtin.cc

Issue 10887024: Move print to corelib. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Get rid of more builtin importing that is no longer needed. Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 12
13 Builtin::builtin_lib_props Builtin::builtin_libraries_[] = { 13 Builtin::builtin_lib_props Builtin::builtin_libraries_[] = {
14 /* url_ source_ has_natives_ */ 14 /* url_ source_ has_natives_ */
15 { DartUtils::kBuiltinLibURL, builtin_source_, true }, 15 { DartUtils::kBuiltinLibURL, builtin_source_, true },
16 { DartUtils::kJsonLibURL, json_source_, false }, 16 { DartUtils::kJsonLibURL, json_source_, false },
17 { DartUtils::kUriLibURL, uri_source_, false }, 17 { DartUtils::kUriLibURL, uri_source_, false },
18 { DartUtils::kCryptoLibURL, crypto_source_, false }, 18 { DartUtils::kCryptoLibURL, crypto_source_, false },
19 { DartUtils::kIOLibURL, io_source_, true }, 19 { DartUtils::kIOLibURL, io_source_, true },
20 { DartUtils::kUtfLibURL, utf_source_, false }, 20 { DartUtils::kUtfLibURL, utf_source_, false },
21 { DartUtils::kWebLibURL, web_source_, false } 21 { DartUtils::kWebLibURL, web_source_, false }
22 }; 22 };
23 23
24 24
25 static void ImportBuiltinLibIntoLib(
26 const char* liburl, Dart_Handle builtin_lib) {
27 Dart_Handle url = Dart_NewString(liburl);
28 Dart_Handle lib = Dart_LookupLibrary(url);
29 DART_CHECK_VALID(lib);
30 DART_CHECK_VALID(Dart_LibraryImportLibrary(lib, builtin_lib, Dart_Null()));
31 }
32
33
34 Dart_Handle Builtin::Source(BuiltinLibraryId id) { 25 Dart_Handle Builtin::Source(BuiltinLibraryId id) {
35 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) == 26 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) ==
36 kInvalidLibrary); 27 kInvalidLibrary);
37 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary); 28 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary);
38 return Dart_NewString(builtin_libraries_[id].source_); 29 return Dart_NewString(builtin_libraries_[id].source_);
39 } 30 }
40 31
41 32
42 void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) { 33 void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) {
43 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) == 34 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) ==
44 kInvalidLibrary); 35 kInvalidLibrary);
45 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary); 36 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary);
46 if (builtin_libraries_[id].has_natives_) { 37 if (builtin_libraries_[id].has_natives_) {
47 // Setup the native resolver for built in library functions. 38 // Setup the native resolver for built in library functions.
48 DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup)); 39 DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup));
49 } 40 }
50 if (id == kBuiltinLibrary) {
51 // Import the builtin library into the core and isolate libraries.
52 ImportBuiltinLibIntoLib(DartUtils::kCoreLibURL, library);
53 ImportBuiltinLibIntoLib(DartUtils::kCoreImplLibURL, library);
54 ImportBuiltinLibIntoLib(DartUtils::kIsolateLibURL, library);
55 }
56 } 41 }
57 42
58 43
59 Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) { 44 Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) {
60 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) == 45 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) ==
61 kInvalidLibrary); 46 kInvalidLibrary);
62 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary); 47 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary);
63 Dart_Handle url = Dart_NewString(builtin_libraries_[id].url_); 48 Dart_Handle url = Dart_NewString(builtin_libraries_[id].url_);
64 Dart_Handle library = Dart_LookupLibrary(url); 49 Dart_Handle library = Dart_LookupLibrary(url);
65 if (Dart_IsError(library)) { 50 if (Dart_IsError(library)) {
66 library = Dart_LoadLibrary(url, Source(id)); 51 library = Dart_LoadLibrary(url, Source(id));
67 if (!Dart_IsError(library)) { 52 if (!Dart_IsError(library)) {
68 SetupLibrary(library, id); 53 SetupLibrary(library, id);
69 } 54 }
70 } 55 }
71 DART_CHECK_VALID(library); 56 DART_CHECK_VALID(library);
72 return library; 57 return library;
73 } 58 }
74 59
75 60
76 void Builtin::ImportLibrary(Dart_Handle library, BuiltinLibraryId id) { 61 void Builtin::ImportLibrary(Dart_Handle library, BuiltinLibraryId id) {
77 Dart_Handle imported_library = LoadLibrary(id); 62 Dart_Handle imported_library = LoadLibrary(id);
78 // Import the library into current library. 63 // Import the library into current library.
79 DART_CHECK_VALID(Dart_LibraryImportLibrary(library, 64 DART_CHECK_VALID(Dart_LibraryImportLibrary(library,
80 imported_library, 65 imported_library,
81 Dart_Null())); 66 Dart_Null()));
82 } 67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698