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_IsValid(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_IsValid(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_IsValid(core_lib)); | 99 ASSERT(Dart_IsValid(core_lib)); |
Anton Muhin
2011/11/13 16:19:32
you probably need rebase to new API.
siva
2011/11/15 02:16:52
Done.
| |
111 result = Dart_LibraryImportLibrary(core_lib, builtin_lib); | 100 Dart_Handle result = Dart_LibraryImportLibrary(core_lib, builtin_lib); |
112 ASSERT(Dart_IsValid(result)); | 101 ASSERT(Dart_IsValid(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_IsValid(coreimpl_lib)); | 105 ASSERT(Dart_IsValid(coreimpl_lib)); |
117 result = Dart_LibraryImportLibrary(coreimpl_lib, builtin_lib); | 106 result = Dart_LibraryImportLibrary(coreimpl_lib, builtin_lib); |
118 ASSERT(Dart_IsValid(result)); | 107 ASSERT(Dart_IsValid(result)); |
119 result = Dart_LibraryImportLibrary(builtin_lib, coreimpl_lib); | 108 result = Dart_LibraryImportLibrary(builtin_lib, coreimpl_lib); |
120 ASSERT(Dart_IsValid(result)); | 109 ASSERT(Dart_IsValid(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(Dart_LibraryTagHandler handler) { |
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_LoadScript(url, source, handler); |
Anton Muhin
2011/11/13 16:19:32
why Dart_LoadScript here? why not Dart_LoadLibrar
siva
2011/11/15 02:16:52
Yes this is Dart_LoadLibrary.
On 2011/11/13 16:19
| |
127 result = Dart_CreateNativeWrapperClass(builtin_lib, | 117 if (Dart_IsValid(builtin_lib)) { |
128 name, | 118 // Setup the native resolver for built in library functions. |
129 kNumEventHandlerFields); | 119 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup); |
130 ASSERT(Dart_IsValid(result)); | 120 ASSERT(Dart_IsValid(result)); |
121 SetupCorelibImports(builtin_lib); | |
122 } | |
123 return builtin_lib; | |
131 } | 124 } |
132 | 125 |
133 | 126 |
134 void Builtin_ImportLibrary(Dart_Handle library) { | 127 void Builtin_ImportLibrary(Dart_Handle library) { |
135 Builtin_LoadLibrary(); | |
136 | |
137 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); | 128 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); |
138 Dart_Handle builtin_lib = Dart_LookupLibrary(url); | 129 Dart_Handle builtin_lib = Dart_LookupLibrary(url); |
139 ASSERT(Dart_IsValid(builtin_lib)); | 130 if (!Dart_IsValid(builtin_lib)) { |
131 // Load the Builtin library. | |
132 Dart_Handle source = Dart_NewString(Builtin_source_); | |
133 builtin_lib = Dart_LoadLibrary(url, source); | |
134 ASSERT(Dart_IsValid(builtin_lib)); | |
135 // Setup the native resolver for built in library functions. | |
136 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup); | |
137 ASSERT(Dart_IsValid(result)); | |
138 SetupCorelibImports(builtin_lib); | |
139 } | |
140 // Import the builtin library into current library. | |
140 Dart_Handle result = Dart_LibraryImportLibrary(library, builtin_lib); | 141 Dart_Handle result = Dart_LibraryImportLibrary(library, builtin_lib); |
141 ASSERT(Dart_IsValid(result)); | 142 ASSERT(Dart_IsValid(result)); |
142 } | 143 } |
143 | 144 |
144 | 145 |
145 void Builtin_SetNativeResolver() { | 146 void Builtin_SetNativeResolver() { |
146 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); | 147 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); |
147 Dart_Handle builtin_lib = Dart_LookupLibrary(url); | 148 Dart_Handle builtin_lib = Dart_LookupLibrary(url); |
148 ASSERT(Dart_IsValid(builtin_lib)); | 149 if (Dart_IsValid(builtin_lib)) { |
Anton Muhin
2011/11/13 16:19:32
isn't it an error if one invokes Builtin_SetNative
siva
2011/11/15 02:16:52
True, converted to an assert.
On 2011/11/13 16:19
| |
149 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup); | 150 // Setup the native resolver for built in library functions. |
150 ASSERT(Dart_IsValid(result)); | 151 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup); |
152 ASSERT(Dart_IsValid(result)); | |
153 } | |
151 } | 154 } |
OLD | NEW |