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

Side by Side Diff: bin/builtin_nolib.cc

Issue 10388242: Minor restructure some of the builtin library processing code (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 6 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_[] = {
14 /* url_ source_ has_natives_ */
15 { DartUtils::kBuiltinLibURL, NULL, true },
16 { DartUtils::kJsonLibURL, NULL, false },
17 { DartUtils::kUriLibURL, NULL, false },
18 { DartUtils::kCryptoLibURL, NULL, false },
19 { DartUtils::kIOLibURL, NULL, true },
20 { DartUtils::kUtfLibURL, NULL, false }
21 };
22
23
13 Dart_Handle Builtin::Source(BuiltinLibraryId id) { 24 Dart_Handle Builtin::Source(BuiltinLibraryId id) {
14 UNREACHABLE(); 25 ASSERT(id >= kCryptoLibrary && id < kInvalidLibrary);
hausner 2012/05/31 15:57:11 Also assumes a certain order in the enum. Add a co
siva 2012/05/31 20:57:19 Done.
15 return Dart_Null(); 26 return Dart_NewString(builtin_libraries_[id].source_);
16 } 27 }
17 28
18 29
19 void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) { 30 void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) {
20 UNREACHABLE(); 31 ASSERT(id >= kCryptoLibrary && id < kInvalidLibrary);
32 if (builtin_libraries_[id].has_natives_) {
33 // Setup the native resolver for built in library functions.
34 DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup));
35 }
21 } 36 }
22 37
23 38
24 Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) { 39 Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) {
25 Dart_Handle url; 40 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary);
26 switch (id) { 41 Dart_Handle url = Dart_NewString(builtin_libraries_[id].url_);
27 case kBuiltinLibrary:
28 url = Dart_NewString(DartUtils::kBuiltinLibURL);
29 break;
30 case kCryptoLibrary:
31 url = Dart_NewString(DartUtils::kCryptoLibURL);
32 break;
33 case kIOLibrary:
34 url = Dart_NewString(DartUtils::kIOLibURL);
35 break;
36 case kJsonLibrary:
37 url = Dart_NewString(DartUtils::kJsonLibURL);
38 break;
39 case kUriLibrary:
40 url = Dart_NewString(DartUtils::kUriLibURL);
41 break;
42 case kUtfLibrary:
43 url = Dart_NewString(DartUtils::kUtfLibURL);
44 break;
45 default:
46 return Dart_Error("Unknown builtin library requested.");
47 }
48 Dart_Handle library = Dart_LookupLibrary(url); 42 Dart_Handle library = Dart_LookupLibrary(url);
49 if (Dart_IsError(library)) { 43 if (Dart_IsError(library)) {
50 UNREACHABLE(); 44 ASSERT(id >= kCryptoLibrary && id < kInvalidLibrary);
45 library = Dart_LoadLibrary(url, Source(id));
46 if (!Dart_IsError(library)) {
47 SetupLibrary(library, id);
48 }
51 } 49 }
52 DART_CHECK_VALID(library); 50 DART_CHECK_VALID(library);
53 return library; 51 return library;
54 } 52 }
55 53
56 54
57 void Builtin::ImportLibrary(Dart_Handle library, BuiltinLibraryId id) { 55 void Builtin::ImportLibrary(Dart_Handle library, BuiltinLibraryId id) {
58 Dart_Handle imported_library = LoadLibrary(id); 56 Dart_Handle imported_library = LoadLibrary(id);
59 // Import the library into current library. 57 // Import the library into current library.
60 DART_CHECK_VALID(Dart_LibraryImportLibrary(library, imported_library)); 58 DART_CHECK_VALID(Dart_LibraryImportLibrary(library, imported_library));
61 } 59 }
OLDNEW
« bin/builtin.cc ('K') | « bin/builtin.cc ('k') | bin/gen_snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698