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

Side by Side Diff: bin/builtin.cc

Issue 9417012: - Add dart:json, dart:uri and dart:utf8 to the known and builtin libraries. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 10 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
« no previous file with comments | « bin/builtin.h ('k') | bin/builtin_in.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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(BuiltinLibraryId id) { 26 Dart_Handle Builtin::Source(BuiltinLibraryId id) {
27 Dart_Handle source; 27 Dart_Handle source;
28 if (id == kBuiltinLibrary) { 28 switch (id) {
29 source = Dart_NewString(Builtin::builtin_source_); 29 case kBuiltinLibrary:
30 } else { 30 source = Dart_NewString(Builtin::builtin_source_);
31 ASSERT(id == kIOLibrary); 31 break;
32 source = Dart_NewString(Builtin::io_source_); 32 case kIOLibrary:
33 source = Dart_NewString(Builtin::io_source_);
34 break;
35 case kJsonLibrary:
36 source = Dart_NewString(Builtin::json_source_);
37 break;
38 case kUriLibrary:
39 source = Dart_NewString(Builtin::uri_source_);
40 break;
41 case kUtf8Library:
42 source = Dart_NewString(Builtin::utf8_source_);
43 break;
44 default:
45 return Dart_Error("Unknown builtin source requested.");
33 } 46 }
34 return source; 47 return source;
35 } 48 }
36 49
37 50
38 void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) { 51 void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) {
39 if (id == kBuiltinLibrary) { 52 if ((id == kJsonLibrary) || (id == kUriLibrary) || (id == kUtf8Library)) {
53 // No native resolver for these pure Dart libraries.
54 return;
55 } else if (id == kBuiltinLibrary) {
40 // Setup core lib, builtin import structure. 56 // Setup core lib, builtin import structure.
41 SetupCorelibImports(library); 57 SetupCorelibImports(library);
42 } 58 }
43 // Setup the native resolver for built in library functions. 59 // Setup the native resolver for built in library functions.
44 DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup)); 60 DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup));
45 } 61 }
46 62
47 63
48 Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) { 64 Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) {
49 Dart_Handle url; 65 Dart_Handle url;
50 if (id == kBuiltinLibrary) { 66 switch (id) {
51 url = Dart_NewString(DartUtils::kBuiltinLibURL); 67 case kBuiltinLibrary:
52 } else { 68 url = Dart_NewString(DartUtils::kBuiltinLibURL);
53 ASSERT(id == kIOLibrary); 69 break;
54 url = Dart_NewString(DartUtils::kIOLibURL); 70 case kIOLibrary:
71 url = Dart_NewString(DartUtils::kIOLibURL);
72 break;
73 case kJsonLibrary:
74 url = Dart_NewString(DartUtils::kJsonLibURL);
75 break;
76 case kUriLibrary:
77 url = Dart_NewString(DartUtils::kUriLibURL);
78 break;
79 case kUtf8Library:
80 url = Dart_NewString(DartUtils::kUtf8LibURL);
81 break;
82 default:
83 return Dart_Error("Unknown builtin library requested.");
55 } 84 }
56 Dart_Handle library = Dart_LookupLibrary(url); 85 Dart_Handle library = Dart_LookupLibrary(url);
57 if (Dart_IsError(library)) { 86 if (Dart_IsError(library)) {
58 Dart_Handle import_map = Dart_NewList(0); 87 Dart_Handle import_map = Dart_NewList(0);
59 library = Dart_LoadLibrary(url, Source(id), import_map); 88 library = Dart_LoadLibrary(url, Source(id), import_map);
60 if (!Dart_IsError(library)) { 89 if (!Dart_IsError(library)) {
61 SetupLibrary(library, id); 90 SetupLibrary(library, id);
62 } 91 }
63 } 92 }
64 DART_CHECK_VALID(library); 93 DART_CHECK_VALID(library);
65 return library; 94 return library;
66 } 95 }
67 96
68 97
69 void Builtin::ImportLibrary(Dart_Handle library, BuiltinLibraryId id) { 98 void Builtin::ImportLibrary(Dart_Handle library, BuiltinLibraryId id) {
70 Dart_Handle imported_library = LoadLibrary(id); 99 Dart_Handle imported_library = LoadLibrary(id);
71 // Import the library into current library. 100 // Import the library into current library.
72 DART_CHECK_VALID(Dart_LibraryImportLibrary(library, imported_library)); 101 DART_CHECK_VALID(Dart_LibraryImportLibrary(library, imported_library));
73 } 102 }
OLDNEW
« no previous file with comments | « bin/builtin.h ('k') | bin/builtin_in.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698