[gnome-shell/wip/fmuellner/fix-perf-tool: 3/3] scripting: Don't use legacy API
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/fmuellner/fix-perf-tool: 3/3] scripting: Don't use legacy API
- Date: Tue, 5 Mar 2019 22:35:40 +0000 (UTC)
commit ce33f0e357ece4289cdaf129bcb14a01c6a5531c
Author: Florian Müllner <fmuellner gnome org>
Date: Tue Feb 12 17:11:24 2019 +0100
scripting: Don't use legacy API
The current scripting module makes heavy use of pre-standardized
iterator/generator/promise APIs, at least for some of those support
was pulled in SpiderMonkey 58.
Port to the new standardized replacements to get the module back into
a working state.
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/439
js/ui/scripting.js | 106 +++++++++++++++++------------------------------------
1 file changed, 34 insertions(+), 72 deletions(-)
---
diff --git a/js/ui/scripting.js b/js/ui/scripting.js
index 01bc2dd38..d227b9ef4 100644
--- a/js/ui/scripting.js
+++ b/js/ui/scripting.js
@@ -37,16 +37,13 @@ const { loadInterfaceXML } = imports.misc.fileUtils;
* 'yield Scripting.sleep(500);'
*/
function sleep(milliseconds) {
- let cb;
-
- let id = Mainloop.timeout_add(milliseconds, () => {
- if (cb)
- cb();
- return GLib.SOURCE_REMOVE;
+ return new Promise(resolve => {
+ let id = Mainloop.timeout_add(milliseconds, () => {
+ resolve();
+ return GLib.SOURCE_REMOVE;
+ });
+ GLib.Source.set_name_by_id(id, '[gnome-shell] sleep');
});
- GLib.Source.set_name_by_id(id, '[gnome-shell] sleep');
-
- return callback => { cb = callback; };
}
/**
@@ -57,14 +54,9 @@ function sleep(milliseconds) {
* 'yield Scripting.waitLeisure();'
*/
function waitLeisure() {
- let cb;
-
- global.run_at_leisure(() => {
- if (cb)
- cb();
+ return new Promise(resolve => {
+ global.run_at_leisure(resolve);
});
-
- return callback => { cb = callback; };
}
const PerfHelperIface = loadInterfaceXML('org.gnome.Shell.PerfHelper');
@@ -82,25 +74,16 @@ function _getPerfHelper() {
}
function _callRemote(obj, method, ...args) {
- let cb;
- let errcb;
-
- args.push((result, excp) => {
- if (excp) {
- if (errcb)
- errcb(excp);
- } else {
- if (cb)
- cb();
- }
- });
-
- method.apply(obj, args);
+ return new Promise((resolve, reject) => {
+ args.push((result, excp) => {
+ if (excp)
+ reject(excp);
+ else
+ resolve();
+ });
- return (callback, error_callback) => {
- cb = callback;
- errcb = error_callback;
- };
+ method.apply(obj, args);
+ });
}
/**
@@ -192,27 +175,6 @@ function collectStatistics() {
Shell.PerfLog.get_default().collect_statistics();
}
-function _step(g, finish, onError) {
- try {
- let waitFunction = g.next();
- waitFunction(() => {
- _step(g, finish, onError);
- },
- err => {
- if (onError)
- onError(err);
- });
- } catch (err) {
- if (err instanceof StopIteration) {
- if (finish)
- finish();
- } else {
- if (onError)
- onError(err);
- }
- }
-}
-
function _collect(scriptModule, outputFile) {
let eventHandlers = {};
@@ -348,23 +310,23 @@ function _collect(scriptModule, outputFile) {
* After running the script and collecting statistics from the
* event log, GNOME Shell will exit.
**/
-function runPerfScript(scriptModule, outputFile) {
+async function runPerfScript(scriptModule, outputFile) {
Shell.PerfLog.get_default().set_enabled(true);
- let g = scriptModule.run();
-
- _step(g,
- () => {
- try {
- _collect(scriptModule, outputFile);
- } catch (err) {
- log("Script failed: " + err + "\n" + err.stack);
- Meta.exit(Meta.ExitCode.ERROR);
- }
- Meta.exit(Meta.ExitCode.SUCCESS);
- },
- err => {
- log("Script failed: " + err + "\n" + err.stack);
- Meta.exit(Meta.ExitCode.ERROR);
- });
+ for (let step of scriptModule.run()) {
+ try {
+ await step;
+ } catch (err) {
+ log(`Script failed: ${err}\n${err.stack}`);
+ Meta.exit(Meta.ExitCode.ERROR);
+ }
+ }
+
+ try {
+ _collect(scriptModule, outputFile);
+ } catch (err) {
+ log(`Script failed: ${err}\n${err.stack}`);
+ Meta.exit(Meta.ExitCode.ERROR);
+ }
+ Meta.exit(Meta.ExitCode.SUCCESS);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]