[seed] Add support for the global ARGV object
- From: Alan Knowles <alank src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seed] Add support for the global ARGV object
- Date: Wed, 9 Dec 2015 03:10:33 +0000 (UTC)
commit 15fcda0eee42ea1aa31ed149aad85064ceacaada
Author: Peter Rustler <peter rustler basyskom com>
Date: Tue Dec 8 09:32:14 2015 +0000
Add support for the global ARGV object
In seed command line parameter will be provided by the Seed.argv
object. In gjs this is done with the global ARGV object. Also,
the count of parameter is different. While in seed the command
line is completly provided, in gjs the first 2 parameter are obmitted.
This patch add support for the ARGV object in seed.
https://bugzilla.gnome.org/show_bug.cgi?id=759171
libseed/seed-builtins.c | 66 ++++++++++++++++++++++++++++++++++++++++++++--
libseed/seed-engine.c | 1 +
2 files changed, 64 insertions(+), 3 deletions(-)
---
diff --git a/libseed/seed-builtins.c b/libseed/seed-builtins.c
index 0b949f8..caaacee 100644
--- a/libseed/seed-builtins.c
+++ b/libseed/seed-builtins.c
@@ -546,11 +546,66 @@ JSClassDefinition seed_argv_def = {
JSClassRef seed_argv_class;
+static JSValueRef
+seed_ARGV_get_property (JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef property_name, JSValueRef * exception)
+{
+ SeedArgvPrivates *priv;
+ gchar *cproperty_name;
+ gsize length;
+ gint index;
+
+ priv = JSObjectGetPrivate (object);
+ if (!priv->argc)
+ return JSValueMakeUndefined (ctx);
+ length = JSStringGetMaximumUTF8CStringSize (property_name);
+ cproperty_name = g_alloca (length * sizeof (gchar));
+ JSStringGetUTF8CString (property_name, cproperty_name, length);
+
+ if (!g_strcmp0 (cproperty_name, "length"))
+ {
+ return seed_value_from_int (ctx, priv->argc-2, exception);
+ }
+ index = atoi (cproperty_name);
+ if (index >= 0 && index < priv->argc-2) {
+ return seed_value_from_string (ctx, priv->argv[index+2], exception);
+ } else {
+ seed_make_exception (ctx, exception, "ArgumentError",
+ "ArgumentCount "
+ "%d, got %d", priv->argc-2, index);
+ return JSValueMakeNull (ctx);
+ }
+}
+
+JSClassDefinition seed_ARGV_def = {
+ 0, /* Version, always 0 */
+ kJSClassAttributeNoAutomaticPrototype, /* JSClassAttributes */
+ "argv_array", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* Has Property */
+ seed_ARGV_get_property, /* Get Property */
+ NULL,
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
+};
+
+JSClassRef seed_ARGV_class;
+
void
seed_init_builtins (SeedEngine * local_eng, gint * argc, gchar *** argv)
{
SeedArgvPrivates *priv;
- JSObjectRef arrayObj;
+ JSObjectRef argvArrayObj;
+ JSObjectRef ARGVArrayObj;
JSObjectRef obj =
(JSObjectRef) seed_object_get_property (local_eng->context,
local_eng->global,
@@ -596,8 +651,13 @@ seed_init_builtins (SeedEngine * local_eng, gint * argc, gchar *** argv)
priv->argc = argc ? *argc : 0;
seed_argv_class = JSClassCreate (&seed_argv_def);
- arrayObj = JSObjectMake (local_eng->context, seed_argv_class, priv);
+ argvArrayObj = JSObjectMake (local_eng->context, seed_argv_class, priv);
+
+ seed_object_set_property (local_eng->context, obj, "argv", argvArrayObj);
+
+ seed_ARGV_class = JSClassCreate (&seed_ARGV_def);
+ ARGVArrayObj = JSObjectMake (local_eng->context, seed_ARGV_class, priv);
- seed_object_set_property (local_eng->context, obj, "argv", arrayObj);
+ seed_object_set_property (local_eng->context, local_eng->global, "ARGV", ARGVArrayObj);
}
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index d72a341..95489ee 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -32,6 +32,7 @@
JSObjectRef function_proto;
JSObjectRef seed_obj_ref;
+JSObjectRef ARGV_obj_ref;
GQuark qname;
GQuark qprototype;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]