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

Unified Diff: runtime/bin/test_extension_linux.cc

Issue 9430051: Add native extensions to the Dart shell, on the linux platform. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix Windows bugs Created 8 years, 10 months 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 | « runtime/bin/main.cc ('k') | runtime/dart-runtime.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/test_extension_linux.cc
diff --git a/runtime/bin/test_extension_linux.cc b/runtime/bin/test_extension_linux.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dc3a67be7e096de3f1adb3da5892ea70c66a2d3e
--- /dev/null
+++ b/runtime/bin/test_extension_linux.cc
@@ -0,0 +1,40 @@
+// 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 <string.h>
+
+#include "../include/dart_api.h"
+
+#define EXPORT_SYMBOL __attribute__ ((visibility ("default")))
+
+extern "C" Dart_NativeFunction ResolveName(Dart_Handle name, int argc);
+
+extern "C" EXPORT_SYMBOL Dart_Handle test_extension_Init(Dart_Handle library) {
+ if (Dart_IsError(library)) return library;
+ Dart_Handle check_return = Dart_SetNativeResolver(library, ResolveName);
+ if (Dart_IsError(check_return)) return check_return;
+ return Dart_Null();
+}
+
+extern "C" void IfNull(Dart_NativeArguments arguments) {
+ Dart_Handle object = Dart_GetNativeArgument(arguments, 0);
+ if (Dart_IsNull(object)) {
+ Dart_SetReturnValue(arguments, Dart_GetNativeArgument(arguments, 1));
+ } else {
+ Dart_SetReturnValue(arguments, object);
+ }
+}
+
+extern "C" Dart_NativeFunction ResolveName(Dart_Handle name, int argc) {
+ assert(Dart_IsString8(name));
+ const char* cname;
+ Dart_Handle check_error;
+
+ check_error = Dart_StringToCString(name, &cname);
+ if (Dart_IsError(check_error)) return NULL;
+ if (!strcmp("Cat_IfNull", cname) && argc == 2) {
+ return IfNull;
+ }
+ return NULL;
+}
« no previous file with comments | « runtime/bin/main.cc ('k') | runtime/dart-runtime.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698