Add docs to codes

This commit is contained in:
Tamado Sitohang 2022-11-07 08:52:37 +07:00
parent dbdf93ab6f
commit aec7f39886
No known key found for this signature in database
GPG key ID: 5DA9790BE7223553
2 changed files with 21 additions and 5 deletions

View file

@ -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 <ramot@ramottamado.dev>
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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

View file

@ -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;
}