Strawman: `Function.prototype.try` (or `Function.try`)
Mike Samuel
mikesamuel at gmail.com
Tue Aug 22 19:46:44 UTC 2017
On Tue, Aug 22, 2017 at 2:08 PM, Sebastian Malton <sebastian at malton.name>
wrote:
> 1. What is the difference between "normal" and "return"?
>
Noone's answered yet, so I'll take a stab.
An instruction that completes normally transfers control to the "next"
instruction analogous to incrementing the program counter.
An instruction that returns pops (modulo yield) a stackframe which includes
resetting the program counter to its state prior to the call, unless there
are protected regions containing the program counter in which case it jumps
to the innermost. Protected regions in EcmaScript correspond to try{...}
for the most part.
> 2. As previously stated a new type would probably be best since this can
> be made much better then what is essentially a try/catch.
> Since try catching is not very efficient it would be better to have some
> sort of type. However, this leads to how to implement, it could just be a
> class but then it could just be added manually. The real benefit to this
> would be great integration with async/await and pattern matching
>
Others are much more familiar with VM performance constraints, but IIRC,
its not the catching that is inefficient, but associating the stackframe
with the exception.
Dispatching an exception within a stack frame just involves finding the
innermost protected region containing the PC which is a binary search over
a fairly small list of instruction indices.
It sometimes matters whether you associate stack information with an Error
on `new Error()` as in Java, or on throw as in Python but IIRC EcmaScript
doesn't yet take a position on that.
Throwing a non-Error-value also needn't incur the stack walk.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170822/e34d59bd/attachment.html>
More information about the es-discuss
mailing list