OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 | 9 |
10 #include "bin/builtin.h" | 10 #include "bin/builtin.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // Wrong number of arguments. | 87 // Wrong number of arguments. |
88 // TODO(regis): Should we pass a buffer for error reporting? | 88 // TODO(regis): Should we pass a buffer for error reporting? |
89 return NULL; | 89 return NULL; |
90 } | 90 } |
91 } | 91 } |
92 } | 92 } |
93 return NULL; | 93 return NULL; |
94 } | 94 } |
95 | 95 |
96 | 96 |
97 void Builtin_LoadLibrary() { | 97 static void SetupCorelibImports(Dart_Handle builtin_lib) { |
98 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); | 98 // Lookup the core libraries and import the builtin library into them. |
99 Dart_Handle result = Dart_LookupLibrary(url); | 99 Dart_Handle url = Dart_NewString(DartUtils::kCoreLibURL); |
100 if (!Dart_IsError(result)) { | 100 Dart_Handle core_lib = Dart_LookupLibrary(url); |
101 // Builtin library already loaded. | |
102 return; | |
103 } | |
104 | |
105 // Load the library. | |
106 Dart_Handle source = Dart_NewString(Builtin_source_); | |
107 Dart_Handle builtin_lib = Dart_LoadLibrary(url, source); | |
108 DART_CHECK_VALID(builtin_lib); | |
109 | |
110 // Lookup the core libraries and inject the builtin library into them. | |
111 Dart_Handle core_lib = Dart_LookupLibrary(Dart_NewString("dart:core")); | |
112 DART_CHECK_VALID(core_lib); | 101 DART_CHECK_VALID(core_lib); |
113 result = Dart_LibraryImportLibrary(core_lib, builtin_lib); | 102 Dart_Handle result = Dart_LibraryImportLibrary(core_lib, builtin_lib); |
114 DART_CHECK_VALID(result); | 103 DART_CHECK_VALID(result); |
115 | 104 |
116 Dart_Handle coreimpl_lib = | 105 url = Dart_NewString(DartUtils::kCoreImplLibURL); |
117 Dart_LookupLibrary(Dart_NewString("dart:coreimpl")); | 106 Dart_Handle coreimpl_lib = Dart_LookupLibrary(url); |
118 DART_CHECK_VALID(coreimpl_lib); | 107 DART_CHECK_VALID(coreimpl_lib); |
119 result = Dart_LibraryImportLibrary(coreimpl_lib, builtin_lib); | 108 result = Dart_LibraryImportLibrary(coreimpl_lib, builtin_lib); |
120 DART_CHECK_VALID(result); | 109 DART_CHECK_VALID(result); |
121 result = Dart_LibraryImportLibrary(builtin_lib, coreimpl_lib); | 110 } |
122 DART_CHECK_VALID(result); | |
123 | 111 |
124 // Create a native wrapper "EventHandlerNativeWrapper" so that we can add a | 112 |
125 // native field to store the event handle for implementing all | 113 Dart_Handle Builtin_Source() { |
126 // event operations. | 114 Dart_Handle str = Dart_NewString(Builtin_source_); |
127 Dart_Handle name = Dart_NewString("EventHandlerNativeWrapper"); | 115 return str; |
128 const int kNumEventHandlerFields = 1; | 116 } |
129 result = Dart_CreateNativeWrapperClass(builtin_lib, | 117 |
130 name, | 118 |
131 kNumEventHandlerFields); | 119 void Builtin_SetupLibrary(Dart_Handle builtin_lib) { |
| 120 // Setup core lib, builtin import structure. |
| 121 SetupCorelibImports(builtin_lib); |
| 122 // Setup the native resolver for built in library functions. |
| 123 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup); |
132 DART_CHECK_VALID(result); | 124 DART_CHECK_VALID(result); |
133 } | 125 } |
134 | 126 |
135 | 127 |
136 void Builtin_ImportLibrary(Dart_Handle library) { | 128 void Builtin_ImportLibrary(Dart_Handle library) { |
137 Builtin_LoadLibrary(); | |
138 | |
139 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); | 129 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); |
140 Dart_Handle builtin_lib = Dart_LookupLibrary(url); | 130 Dart_Handle builtin_lib = Dart_LookupLibrary(url); |
| 131 if (Dart_IsError(builtin_lib)) { |
| 132 Dart_Handle source = Dart_NewString(Builtin_source_); |
| 133 builtin_lib = Dart_LoadLibrary(url, source); |
| 134 if (!Dart_IsError(builtin_lib)) { |
| 135 Builtin_SetupLibrary(builtin_lib); |
| 136 } |
| 137 } |
| 138 // Import the builtin library into current library. |
141 DART_CHECK_VALID(builtin_lib); | 139 DART_CHECK_VALID(builtin_lib); |
142 Dart_Handle result = Dart_LibraryImportLibrary(library, builtin_lib); | 140 Dart_Handle result = Dart_LibraryImportLibrary(library, builtin_lib); |
143 DART_CHECK_VALID(result); | 141 DART_CHECK_VALID(result); |
144 } | 142 } |
145 | 143 |
146 | 144 |
147 void Builtin_SetNativeResolver() { | 145 void Builtin_SetNativeResolver() { |
148 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); | 146 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); |
149 Dart_Handle builtin_lib = Dart_LookupLibrary(url); | 147 Dart_Handle builtin_lib = Dart_LookupLibrary(url); |
150 DART_CHECK_VALID(builtin_lib); | 148 DART_CHECK_VALID(builtin_lib); |
| 149 // Setup the native resolver for built in library functions. |
151 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup); | 150 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup); |
152 DART_CHECK_VALID(result); | 151 DART_CHECK_VALID(result); |
153 } | 152 } |
OLD | NEW |