Open Bug 1639648 Opened 4 years ago Updated 1 year ago

Support eagerly evaluating getters

Categories

(DevTools :: Console, enhancement)

enhancement

Tracking

(Not tracked)

People

(Reporter: jlast, Unassigned)

References

(Depends on 1 open bug, Blocks 1 open bug)

Details

Attachments

(1 file)

We currently show a button next to getters to evaluate them. It would be nice if we could first try to eagerly evaluate them so that we don't hide the value unnecessarily.

Something like Element.prototype.children can be eagerly evaluated, but if I inspect Element.prototype in the console, showing

TypeError: "'get children' called on an object that does not implement interface Element.

for every single getter will just be distracting IMO.

diff --git a/devtools/server/actors/webconsole/eval-with-debugger.js b/devtools/server/actors/webconsole/eval-with-debugger.js
index 9d24ec2be8ef1..61a71d17451fb 100644
--- a/devtools/server/actors/webconsole/eval-with-debugger.js
+++ b/devtools/server/actors/webconsole/eval-with-debugger.js
@@ -53,6 +53,27 @@ function isObject(value) {
   return Object(value) === value;
 }

+exports.eagerlyEvaluateGetter = function({ value, frame, dbgWindow }) {
+  const noSideEffectDebugger = makeSideeffectFreeDebugger();
+
+  let result;
+  try {
+    const global = Cu.getGlobalForObject(value);
+    const dbgGlobal = noSideEffectDebugger.makeGlobalObjectReference(global);
+    const dbgObject = dbgGlobal.makeDebuggeeValue(value);
+    result = dbgObject.apply(frame);
+  } finally {
+    // We need to be absolutely sure that the sideeffect-free debugger's
+    // debuggees are removed because otherwise we risk them terminating
+    // execution of later code in the case of unexpected exceptions.
+    if (noSideEffectDebugger) {
+      noSideEffectDebugger.removeAllDebuggees();
+    }
+  }
+
+  return result;
+};
+

I agree. we should not show errors.

Assignee: nobody → wartmanm
Status: NEW → ASSIGNED
See Also: → 1443782

Sorry, there was a problem with the detection of inactive users. I'm reverting the change.

Assignee: nobody → wartmanm
Status: NEW → ASSIGNED
No longer blocks: console-instant-eval
Depends on: 1806595
Assignee: wartmanm → nobody
Status: ASSIGNED → NEW
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: