[seed] Add missing log and logError functions to global object
- From: Alan Knowles <alank src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seed] Add missing log and logError functions to global object
- Date: Wed, 9 Dec 2015 03:10:23 +0000 (UTC)
commit 478153d22c8a615af019dc5d7e8885752253a4f2
Author: Peter Rustler <peter rustler basyskom com>
Date: Mon Dec 7 15:51:27 2015 +0000
Add missing log and logError functions to global object
Gjs has log and logError functions on global object.
To make seed more compatible to gjs, this function were added
to the global object.
https://bugzilla.gnome.org/show_bug.cgi?id=759171
libseed/seed-builtins.c | 39 +++++++++++++++++++++++++++++++++++++++
1 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/libseed/seed-builtins.c b/libseed/seed-builtins.c
index 3988a3d..0b949f8 100644
--- a/libseed/seed-builtins.c
+++ b/libseed/seed-builtins.c
@@ -25,6 +25,7 @@
JSValueRef seed_print_ref;
JSValueRef seed_printerr_ref;
+JSValueRef seed_log_error_ref;
static JSValueRef
seed_include (JSContextRef ctx,
@@ -232,6 +233,36 @@ seed_print (JSContextRef ctx,
}
static JSValueRef
+seed_log_error (JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[], JSValueRef * exception)
+{
+ gchar *buf1;
+ gchar *buf2 = NULL;
+ if (argumentCount != 1 && argumentCount != 2)
+ {
+ seed_make_exception (ctx, exception, "ArgumentError",
+ "logError expected 1 or 2 argument, got %zd",
+ argumentCount);
+ return JSValueMakeNull (ctx);
+ }
+
+ buf1 = seed_value_to_string (ctx, arguments[0], exception);
+ if (argumentCount == 2) {
+ buf2 = seed_value_to_string (ctx, arguments[1], exception);
+ g_print ("%s - %s\n", buf1, buf2);
+ } else {
+ g_print ("%s\n", buf1);
+ }
+ g_free (buf1);
+ g_free (buf2);
+
+ return JSValueMakeUndefined (ctx);
+}
+
+static JSValueRef
seed_printerr (JSContextRef ctx,
JSObjectRef function,
JSObjectRef this_object,
@@ -534,6 +565,8 @@ seed_init_builtins (SeedEngine * local_eng, gint * argc, gchar *** argv)
seed_object_set_property (local_eng->context, obj, "print", seed_print_ref);
seed_object_set_property (local_eng->context, local_eng->global, "print",
seed_print_ref);
+ seed_object_set_property (local_eng->context, local_eng->global, "log",
+ seed_print_ref);
JSValueProtect (local_eng->context, seed_print_ref);
seed_printerr_ref =
@@ -543,6 +576,12 @@ seed_init_builtins (SeedEngine * local_eng, gint * argc, gchar *** argv)
seed_printerr_ref);
JSValueProtect (local_eng->context, seed_printerr_ref);
+ seed_log_error_ref =
+ JSObjectMakeFunctionWithCallback (local_eng->context, NULL, &seed_log_error);
+ seed_object_set_property (local_eng->context, local_eng->global, "logError",
+ seed_log_error_ref);
+ JSValueProtect (local_eng->context, seed_log_error_ref);
+
seed_create_function (local_eng->context,
"check_syntax", &seed_check_syntax, obj);
seed_create_function (local_eng->context,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]