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