1// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
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.
4
5#include <stdio.h>
6
7#include "include/dart_api.h"
8
9#include "bin/builtin.h"
10#include "bin/dartutils.h"
11
12namespace dart {
13namespace bin {
14
15Builtin::builtin_lib_props Builtin::builtin_libraries_[] = {
16 /* { url_, has_natives_ } */
17 {DartUtils::kBuiltinLibURL, true},
18 {DartUtils::kIOLibURL, true},
19 {DartUtils::kHttpLibURL, false},
20 {DartUtils::kCLILibURL, true},
21
22 // End marker.
23 {NULL, false}};
24
25const int Builtin::num_libs_ =
26 sizeof(Builtin::builtin_libraries_) / sizeof(Builtin::builtin_lib_props);
27
28void Builtin::SetNativeResolver(BuiltinLibraryId id) {
29 ASSERT(static_cast<int>(id) >= 0);
30 ASSERT(static_cast<int>(id) < num_libs_);
31
32 if (builtin_libraries_[id].has_natives_) {
33 Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_);
34 Dart_Handle library = Dart_LookupLibrary(url);
35 ASSERT(!Dart_IsError(library));
36 // Setup the native resolver for built in library functions.
37 Dart_Handle result =
38 Dart_SetNativeResolver(library, NativeLookup, NativeSymbol);
39 ASSERT(!Dart_IsError(result));
40 }
41}
42
43Dart_Handle Builtin::LoadAndCheckLibrary(BuiltinLibraryId id) {
44 ASSERT(static_cast<int>(id) >= 0);
45 ASSERT(static_cast<int>(id) < num_libs_);
46
47 Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_);
48 return Dart_LookupLibrary(url);
49}
50
51} // namespace bin
52} // namespace dart
53