From aec7f398865f31b6410fd4e32afaf3d6c52a58be Mon Sep 17 00:00:00 2001 From: Tamado Sitohang Date: Mon, 7 Nov 2022 08:52:37 +0700 Subject: [PATCH] Add docs to codes --- LICENSE | 4 ++-- eval-gjs@ramottamado.dev/extension.js | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/LICENSE b/LICENSE index eca7816..d159169 100644 --- a/LICENSE +++ b/LICENSE @@ -290,8 +290,8 @@ to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. - Eval GJS - Copyright (C) 2021 Tamado Sitohang + + Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/eval-gjs@ramottamado.dev/extension.js b/eval-gjs@ramottamado.dev/extension.js index 3ea9f8d..78e31e1 100644 --- a/eval-gjs@ramottamado.dev/extension.js +++ b/eval-gjs@ramottamado.dev/extension.js @@ -40,6 +40,22 @@ class EvalGjs { this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(EvalGjsIface, this); } + + /** + * Eval: + * @param {string} code: A string containing JavaScript code + * @returns {Array} + * + * This function executes arbitrary code in the main + * loop, and returns a boolean success and + * JSON representation of the object as a string. + * + * If evaluation completes without throwing an exception, + * then the return value will be [true, JSON.stringify(result)]. + * If evaluation fails, then the return value will be + * [false, JSON.stringify(exception)]; + * + */ Eval(code) { let returnValue; let success; @@ -47,9 +63,9 @@ class EvalGjs { try { returnValue = JSON.stringify(eval(code)); - returnValue = returnValue == undefined - ? '' - : returnValue; + // A hack; DBus doesn't have null/undefined + if (returnValue == undefined) + returnValue = ''; success = true; }