[gjs] modules/system: Add System.exit() API
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] modules/system: Add System.exit() API
- Date: Fri, 22 Feb 2013 04:50:38 +0000 (UTC)
commit 781ac29188df6330bcaada8ce8d0c6db86b1a17f
Author: Colin Walters <walters verbum org>
Date: Wed Jan 9 17:45:48 2013 -0500
modules/system: Add System.exit() API
Kind of lame we didn't have this before, since it's a lot harder to
write "scripts" that start and exit on error without it.
https://bugzilla.gnome.org/show_bug.cgi?id=691447
modules/system.c | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/modules/system.c b/modules/system.c
index 7ee9a2f..2d23285 100644
--- a/modules/system.c
+++ b/modules/system.c
@@ -104,6 +104,19 @@ gjs_gc(JSContext *context,
return JS_TRUE;
}
+static JSBool
+gjs_exit(JSContext *context,
+ unsigned argc,
+ jsval *vp)
+{
+ jsval *argv = JS_ARGV(cx, vp);
+ gint32 ecode;
+ if (!gjs_parse_args(context, "exit", "i", argc, argv, &ecode))
+ return JS_FALSE;
+ exit(ecode);
+ return JS_TRUE;
+}
+
JSBool
gjs_js_define_system_stuff(JSContext *context,
JSObject *module)
@@ -132,6 +145,12 @@ gjs_js_define_system_stuff(JSContext *context,
0, GJS_MODULE_PROP_FLAGS))
return JS_FALSE;
+ if (!JS_DefineFunction(context, module,
+ "exit",
+ (JSNative) gjs_exit,
+ 0, GJS_MODULE_PROP_FLAGS))
+ return JS_FALSE;
+
return JS_TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]