Would it be possible to add setTimeout-equivalent function to JS shell?

NEW
Unassigned

Status

()

Core
JavaScript Engine
P3
enhancement
6 months ago
3 months ago

People

(Reporter: arai, Unassigned)

Tracking

({triage-deferred})

Trunk
triage-deferred
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

6 months ago
while testing Promise, async functions, and async generators, sometimes I want to use timer in test script (not for automated test tho).
would it be possible to add setTimeout or similar thing to JS shell so that we can test such cases in shell?

main concern is that JS shell version of setTimeout might behave differently than DOM setTimeout...

Comment 1

6 months ago
Presumably what you are looking for is a function that does "run this code when there are no promises pending"?

This doesn't seem too hard to implement in the abstract, mostly the shell main program becomes a loop with a deadline-sorted list of callbacks instead of the straight-line code it already is.

(BTW, it is my understanding that both V8 and Chakra have more DOM-like interfaces in their JS shells - Worker objects, postMessage channels.  It's possible we should think about moving in that direction too, to allow simpler testing.)
(Reporter)

Comment 2

6 months ago
yeah, indeed, it's not required to wait long time, but just execute the function (or just resolve the Promise) in specified order, after performing all pending jobs.

I'll look into that direction, and also V8/Chakra shells' implementation.
Keywords: triage-deferred
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.