[gjs: 1/2] debugger: Make '$$' mean the last value
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 1/2] debugger: Make '$$' mean the last value
- Date: Mon, 7 Dec 2020 04:29:57 +0000 (UTC)
commit f85940fe05b4ce99d77ce796b4f693a50d772e82
Author: Philip Chimento <philip chimento gmail com>
Date: Tue Nov 24 21:55:52 2020 -0800
debugger: Make '$$' mean the last value
The debugger already stores the result of each printed expression in
variables named $1, $2, etc., so you can refer to them later. This change
makes the variable '$$' always refer to the last printed value.
Adds a bit of documentation explaining how these variables can be printed,
and adds a test for $$ as well as $1, $2, etc.
Based on a commit from Mozilla's original jorendb:
https://hg.mozilla.org/mozilla-central/rev/fe52996292bb6d1acd51a983f9a7ac6faa7724f6
(The GJS debugger was originally based on jorendb and I was looking to see
if any new improvements had been made since I had forked it)
installed-tests/debugger/lastvalues.debugger | 13 +++++++++++
installed-tests/debugger/lastvalues.debugger.js | 7 ++++++
.../debugger/lastvalues.debugger.output | 25 ++++++++++++++++++++++
installed-tests/meson.build | 1 +
modules/script/_bootstrap/debugger.js | 6 +++++-
5 files changed, 51 insertions(+), 1 deletion(-)
---
diff --git a/installed-tests/debugger/lastvalues.debugger b/installed-tests/debugger/lastvalues.debugger
new file mode 100644
index 00000000..c978fbd6
--- /dev/null
+++ b/installed-tests/debugger/lastvalues.debugger
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
+# SPDX-FileCopyrightText: 2020 Philip Chimento <philip chimento gmail com>
+c
+p a
+p b
+p c
+p $1
+p $2
+p $3
+p $$
+p $6*3
+p $$*3
+c
diff --git a/installed-tests/debugger/lastvalues.debugger.js b/installed-tests/debugger/lastvalues.debugger.js
new file mode 100644
index 00000000..fd17efd3
--- /dev/null
+++ b/installed-tests/debugger/lastvalues.debugger.js
@@ -0,0 +1,7 @@
+// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
+// SPDX-FileCopyrightText: 2020 Philip Chimento <philip chimento gmail com>
+const a = undefined;
+const b = null;
+const c = 42;
+debugger;
+void (a, b, c);
diff --git a/installed-tests/debugger/lastvalues.debugger.output
b/installed-tests/debugger/lastvalues.debugger.output
new file mode 100644
index 00000000..3d509f08
--- /dev/null
+++ b/installed-tests/debugger/lastvalues.debugger.output
@@ -0,0 +1,25 @@
+GJS debugger. Type "help" for help
+db> # SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
+db> # SPDX-FileCopyrightText: 2020 Philip Chimento <philip chimento gmail com>
+db> c
+Debugger statement, toplevel at lastvalues.debugger.js:6:0
+db> p a
+$1 = undefined
+db> p b
+$2 = null
+db> p c
+$3 = 42
+db> p $1
+$4 = undefined
+db> p $2
+$5 = null
+db> p $3
+$6 = 42
+db> p $$
+$7 = 42
+db> p $6*3
+$8 = 126
+db> p $$*3
+$9 = 378
+db> c
+Program exited with code 0
diff --git a/installed-tests/meson.build b/installed-tests/meson.build
index d256f93a..11acbe4e 100644
--- a/installed-tests/meson.build
+++ b/installed-tests/meson.build
@@ -56,6 +56,7 @@ debugger_tests = [
'finish',
'frame',
'keys',
+ 'lastvalues',
'next',
'print',
'quit',
diff --git a/modules/script/_bootstrap/debugger.js b/modules/script/_bootstrap/debugger.js
index ddf13ddc..601035cd 100644
--- a/modules/script/_bootstrap/debugger.js
+++ b/modules/script/_bootstrap/debugger.js
@@ -79,6 +79,7 @@ function debuggeeValueToString(dv, style = {pretty: options.pretty}) {
function showDebuggeeValue(dv, style = {pretty: options.pretty}) {
const i = nextDebuggeeValueIndex++;
debuggeeValues[`$${i}`] = dv;
+ debuggeeValues['$$'] = dv;
const [brief, full] = debuggeeValueToString(dv, style);
print(`$${i} = ${brief}`);
if (full !== undefined)
@@ -263,7 +264,10 @@ printCommand.helpText = `USAGE
PARAMETER
· expr: expression to be printed
· pretty|p: prettify the output
- · brief|b: brief output`;
+ · brief|b: brief output
+
+expr may also reference the variables $1, $2, ... for already printed
+expressions, or $$ for the most recently printed expression.`;
function keysCommand(rest) {
return doPrint(`Object.keys(${rest})`);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]