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

Unified 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, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samples/android_embedder/android_embedder.gyp ('k') | samples/android_embedder/support_android.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/android_embedder/builtin_nolib.cc
===================================================================
--- samples/android_embedder/builtin_nolib.cc (revision 0)
+++ samples/android_embedder/builtin_nolib.cc (revision 0)
@@ -0,0 +1,68 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include <stdio.h>
+
+#include "include/dart_api.h"
+
+#include "bin/builtin.h"
+#include "bin/dartutils.h"
+#include "bin/io_natives.h"
+
+Builtin::builtin_lib_props Builtin::builtin_libraries_[] = {
+ /* { url_, source_, patch_url_, patch_source_, has_natives_ } */
+ { DartUtils::kBuiltinLibURL, NULL, NULL, NULL, true },
+ { DartUtils::kJsonLibURL, NULL, NULL, NULL, false },
+ { DartUtils::kUriLibURL, NULL, NULL, NULL, false },
+ { DartUtils::kCryptoLibURL, NULL, NULL, NULL, false },
+ { DartUtils::kIOLibURL, NULL, NULL, NULL, true },
+ { DartUtils::kUtfLibURL, NULL, NULL, NULL, false }
+};
+
+
+Dart_Handle Builtin::Source(BuiltinLibraryId id) {
+ ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) ==
+ kInvalidLibrary);
+ return Dart_NewApiError("Unreachable code in Builtin::Source (%d).", id);
+}
+
+/**
+ * Looks up native functions in both libdart_builtin and libdart_io.
+ */
+Dart_NativeFunction Builtin::NativeLookup(Dart_Handle name,
+ int argument_count) {
+ return BuiltinNativeLookup(name, argument_count);
+}
+
+void Builtin::SetNativeResolver(BuiltinLibraryId id) {
+ ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) ==
+ kInvalidLibrary);
+ ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary);
+ if (builtin_libraries_[id].has_natives_) {
+ Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_);
+ Dart_Handle library = Dart_LookupLibrary(url);
+ ASSERT(!Dart_IsError(library));
+ // Setup the native resolver for built in library functions.
+ DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup));
+ }
+}
+
+
+Dart_Handle Builtin::LoadAndCheckLibrary(BuiltinLibraryId id) {
+ ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) ==
+ kInvalidLibrary);
+ ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary);
+ Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_);
+ Dart_Handle library = Dart_LookupLibrary(url);
+ if (Dart_IsError(library)) {
+ ASSERT(id > kUtfLibrary);
+ library = Dart_LoadLibrary(url, Source(id));
+ if (!Dart_IsError(library) && (builtin_libraries_[id].has_natives_)) {
+ // Setup the native resolver for built in library functions.
+ DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup));
+ }
+ }
+ DART_CHECK_VALID(library);
+ return library;
+}
« 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