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 result = Dart_LibraryImportLibrary(builtin_lib, coreimpl_lib); |
122 DART_CHECK_VALID(result); | 111 DART_CHECK_VALID(result); |
| 112 } |
123 | 113 |
124 // Create a native wrapper "EventHandlerNativeWrapper" so that we can add a | 114 |
125 // native field to store the event handle for implementing all | 115 Dart_Handle Builtin_Source() { |
126 // event operations. | 116 Dart_Handle str = Dart_NewString(Builtin_source_); |
127 Dart_Handle name = Dart_NewString("EventHandlerNativeWrapper"); | 117 return str; |
128 const int kNumEventHandlerFields = 1; | 118 } |
129 result = Dart_CreateNativeWrapperClass(builtin_lib, | 119 |
130 name, | 120 |
131 kNumEventHandlerFields); | 121 void Builtin_SetupLibrary(Dart_Handle builtin_lib) { |
| 122 // Setup core lib, builtin import structure. |
| 123 SetupCorelibImports(builtin_lib); |
| 124 // Setup the native resolver for built in library functions. |
| 125 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup); |
132 DART_CHECK_VALID(result); | 126 DART_CHECK_VALID(result); |
133 } | 127 } |
134 | 128 |
135 | 129 |
136 void Builtin_ImportLibrary(Dart_Handle library) { | 130 void Builtin_ImportLibrary(Dart_Handle library) { |
137 Builtin_LoadLibrary(); | |
138 | |
139 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); | 131 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); |
140 Dart_Handle builtin_lib = Dart_LookupLibrary(url); | 132 Dart_Handle builtin_lib = Dart_LookupLibrary(url); |
| 133 if (Dart_IsError(builtin_lib)) { |
| 134 Dart_Handle source = Dart_NewString(Builtin_source_); |
| 135 builtin_lib = Dart_LoadLibrary(url, source); |
| 136 if (!Dart_IsError(builtin_lib)) { |
| 137 Builtin_SetupLibrary(builtin_lib); |
| 138 } |
| 139 } |
| 140 // Import the builtin library into current library. |
141 DART_CHECK_VALID(builtin_lib); | 141 DART_CHECK_VALID(builtin_lib); |
142 Dart_Handle result = Dart_LibraryImportLibrary(library, builtin_lib); | 142 Dart_Handle result = Dart_LibraryImportLibrary(library, builtin_lib); |
143 DART_CHECK_VALID(result); | 143 DART_CHECK_VALID(result); |
144 } | 144 } |
145 | 145 |
146 | 146 |
147 void Builtin_SetNativeResolver() { | 147 void Builtin_SetNativeResolver() { |
148 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); | 148 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); |
149 Dart_Handle builtin_lib = Dart_LookupLibrary(url); | 149 Dart_Handle builtin_lib = Dart_LookupLibrary(url); |
150 DART_CHECK_VALID(builtin_lib); | 150 DART_CHECK_VALID(builtin_lib); |
| 151 // Setup the native resolver for built in library functions. |
151 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup); | 152 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup); |
152 DART_CHECK_VALID(result); | 153 DART_CHECK_VALID(result); |
153 } | 154 } |
OLD | NEW |