Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(458)

Side by Side Diff: samples/android_embedder/builtin_nolib.cc

Issue 11419237: Shared library for embedding VM in Android apps. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 #include "bin/io_natives.h"
12
13 Builtin::builtin_lib_props Builtin::builtin_libraries_[] = {
14 /* { url_, source_, patch_url_, patch_source_, has_natives_ } */
15 { DartUtils::kBuiltinLibURL, NULL, NULL, NULL, true },
16 { DartUtils::kJsonLibURL, NULL, NULL, NULL, false },
17 { DartUtils::kUriLibURL, NULL, NULL, NULL, false },
18 { DartUtils::kCryptoLibURL, NULL, NULL, NULL, false },
19 { DartUtils::kIOLibURL, NULL, NULL, NULL, true },
20 { DartUtils::kUtfLibURL, NULL, NULL, NULL, false }
21 };
22
23
24 Dart_Handle Builtin::Source(BuiltinLibraryId id) {
25 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) ==
26 kInvalidLibrary);
27 return Dart_NewApiError("Unreachable code in Builtin::Source (%d).", id);
28 }
29
30 /**
31 * Looks up native functions in both libdart_builtin and libdart_io.
32 */
33 Dart_NativeFunction Builtin::NativeLookup(Dart_Handle name,
34 int argument_count) {
35 return BuiltinNativeLookup(name, argument_count);
36 }
37
38 void Builtin::SetNativeResolver(BuiltinLibraryId id) {
39 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) ==
40 kInvalidLibrary);
41 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary);
42 if (builtin_libraries_[id].has_natives_) {
43 Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_);
44 Dart_Handle library = Dart_LookupLibrary(url);
45 ASSERT(!Dart_IsError(library));
46 // Setup the native resolver for built in library functions.
47 DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup));
48 }
49 }
50
51
52 Dart_Handle Builtin::LoadAndCheckLibrary(BuiltinLibraryId id) {
53 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) ==
54 kInvalidLibrary);
55 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary);
56 Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_);
57 Dart_Handle library = Dart_LookupLibrary(url);
58 if (Dart_IsError(library)) {
59 ASSERT(id > kUtfLibrary);
60 library = Dart_LoadLibrary(url, Source(id));
61 if (!Dart_IsError(library) && (builtin_libraries_[id].has_natives_)) {
62 // Setup the native resolver for built in library functions.
63 DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup));
64 }
65 }
66 DART_CHECK_VALID(library);
67 return library;
68 }
OLDNEW
« no previous file with comments | « samples/android_embedder/android_embedder.gyp ('k') | samples/android_embedder/support_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698