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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 // Wrong number of arguments. | 85 // Wrong number of arguments. |
86 // TODO(regis): Should we pass a buffer for error reporting? | 86 // TODO(regis): Should we pass a buffer for error reporting? |
87 return NULL; | 87 return NULL; |
88 } | 88 } |
89 } | 89 } |
90 } | 90 } |
91 return NULL; | 91 return NULL; |
92 } | 92 } |
93 | 93 |
94 | 94 |
95 void Builtin_LoadLibrary() { | 95 static void SetupCorelibImports(Dart_Handle builtin_lib) { |
96 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); | 96 // Lookup the core libraries and import the builtin library into them. |
97 Dart_Handle result = Dart_LookupLibrary(url); | 97 Dart_Handle url = Dart_NewString(DartUtils::kCoreLibURL); |
98 if (!Dart_IsError(result)) { | 98 Dart_Handle core_lib = Dart_LookupLibrary(url); |
99 // Builtin library already loaded. | |
100 return; | |
101 } | |
102 | |
103 // Load the library. | |
104 Dart_Handle source = Dart_NewString(Builtin_source_); | |
105 Dart_Handle builtin_lib = Dart_LoadLibrary(url, source); | |
106 ASSERT(!Dart_IsError(builtin_lib)); | |
107 | |
108 // Lookup the core libraries and inject the builtin library into them. | |
109 Dart_Handle core_lib = Dart_LookupLibrary(Dart_NewString("dart:core")); | |
110 ASSERT(!Dart_IsError(core_lib)); | 99 ASSERT(!Dart_IsError(core_lib)); |
111 result = Dart_LibraryImportLibrary(core_lib, builtin_lib); | 100 Dart_Handle result = Dart_LibraryImportLibrary(core_lib, builtin_lib); |
112 ASSERT(!Dart_IsError(result)); | 101 ASSERT(!Dart_IsError(result)); |
113 | 102 |
114 Dart_Handle coreimpl_lib = | 103 url = Dart_NewString(DartUtils::kCoreImplLibURL); |
115 Dart_LookupLibrary(Dart_NewString("dart:coreimpl")); | 104 Dart_Handle coreimpl_lib = Dart_LookupLibrary(url); |
116 ASSERT(!Dart_IsError(coreimpl_lib)); | 105 ASSERT(!Dart_IsError(coreimpl_lib)); |
117 result = Dart_LibraryImportLibrary(coreimpl_lib, builtin_lib); | 106 result = Dart_LibraryImportLibrary(coreimpl_lib, builtin_lib); |
118 ASSERT(!Dart_IsError(result)); | 107 ASSERT(!Dart_IsError(result)); |
119 result = Dart_LibraryImportLibrary(builtin_lib, coreimpl_lib); | 108 result = Dart_LibraryImportLibrary(builtin_lib, coreimpl_lib); |
120 ASSERT(!Dart_IsError(result)); | 109 ASSERT(!Dart_IsError(result)); |
110 } | |
121 | 111 |
122 // Create a native wrapper "EventHandlerNativeWrapper" so that we can add a | 112 |
123 // native field to store the event handle for implementing all | 113 Dart_Handle Builtin_LoadLibrary() { |
124 // event operations. | 114 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); |
125 Dart_Handle name = Dart_NewString("EventHandlerNativeWrapper"); | 115 Dart_Handle source = Dart_NewString(Builtin_source_); |
126 const int kNumEventHandlerFields = 1; | 116 Dart_Handle builtin_lib = Dart_LoadLibrary(url, source); |
127 result = Dart_CreateNativeWrapperClass(builtin_lib, | 117 if (!Dart_IsError(builtin_lib)) { |
128 name, | 118 // Setup core lib, builtin import structure. |
129 kNumEventHandlerFields); | 119 SetupCorelibImports(builtin_lib); |
130 ASSERT(!Dart_IsError(result)); | 120 // Setup the native resolver for built in library functions. |
121 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup); | |
122 ASSERT(!Dart_IsError(result)); | |
123 } | |
124 return builtin_lib; | |
131 } | 125 } |
132 | 126 |
133 | 127 |
134 void Builtin_ImportLibrary(Dart_Handle library) { | 128 void Builtin_ImportLibrary(Dart_Handle library) { |
135 Builtin_LoadLibrary(); | |
136 | |
137 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); | 129 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); |
138 Dart_Handle builtin_lib = Dart_LookupLibrary(url); | 130 Dart_Handle builtin_lib = Dart_LookupLibrary(url); |
139 ASSERT(!Dart_IsError(builtin_lib)); | 131 if (Dart_IsError(builtin_lib)) { |
Anton Muhin
2011/11/15 12:22:23
this then clause looks pretty much like a copy of
siva
2011/11/15 19:42:49
Yes, the helper is needed as it is called from the
| |
132 // Load the Builtin library. | |
133 Dart_Handle source = Dart_NewString(Builtin_source_); | |
134 builtin_lib = Dart_LoadLibrary(url, source); | |
135 ASSERT(!Dart_IsError(builtin_lib)); | |
136 // Setup core lib, builtin import structure. | |
137 SetupCorelibImports(builtin_lib); | |
138 // Setup the native resolver for built in library functions. | |
139 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup); | |
140 ASSERT(!Dart_IsError(result)); | |
141 } | |
142 // Import the builtin library into current library. | |
140 Dart_Handle result = Dart_LibraryImportLibrary(library, builtin_lib); | 143 Dart_Handle result = Dart_LibraryImportLibrary(library, builtin_lib); |
141 ASSERT(!Dart_IsError(result)); | 144 ASSERT(!Dart_IsError(result)); |
142 } | 145 } |
143 | 146 |
144 | 147 |
145 void Builtin_SetNativeResolver() { | 148 void Builtin_SetNativeResolver() { |
146 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); | 149 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); |
147 Dart_Handle builtin_lib = Dart_LookupLibrary(url); | 150 Dart_Handle builtin_lib = Dart_LookupLibrary(url); |
148 ASSERT(!Dart_IsError(builtin_lib)); | 151 ASSERT(!Dart_IsError(builtin_lib)); |
152 // Setup the native resolver for built in library functions. | |
149 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup); | 153 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup); |
150 ASSERT(!Dart_IsError(result)); | 154 ASSERT(!Dart_IsError(result)); |
151 } | 155 } |
OLD | NEW |