tc39 / proposal-shadowrealm

ECMAScript Proposal, specs, and reference implementation for Realms
https://tc39.es/proposal-shadowrealm/
1.41k stars 67 forks source link

Incorrect `result` handling in "2.1 [[Call]]"? #371

Closed linusg closed 5 months ago

linusg commented 1 year ago

I'm specifically concerned about these three steps from https://tc39.es/proposal-shadowrealm/#sec-wrapped-function-exotic-objects-call-thisargument-argumentslist:

6. If result.[[Type]] is return, return result.[[Value]].
7. ReturnIfAbrupt(result).
8. Return undefined.

Given https://tc39.es/ecma262/#sec-implicit-normal-completion and https://tc39.es/ecma262/#sec-returnifabrupt-shorthands, I don't think OrdinaryWrappedFunctionCall (which produces result) would ever return a return completion; only normal or throw as a simple N. Return foo. does not create a return completion. Downstream of that, neither GetWrappedValue nor WrappedFunctionCreate look like they could create return completions according to the linked spec sections.

leobalter commented 1 year ago

cc @caridy @rwaldron can you take a look on this? Thanks!

legendecas commented 1 year ago

I think the assumption is correct that in this case the Completion Record of type return produced by the function [Call]() is already processed in OrdinaryWrappedFunctionCall (step 10) by GetWrappedValue, which can only produce completion record typed with normal or throw.

caridy commented 1 year ago

@legendecas that was my assumption as well when writing that.

legendecas commented 1 year ago

@caridy sorry I may not be clear. I'm suggesting we should fix this spec issue. Is that what you are suggesting too?

linusg commented 1 year ago

The linked PR fixed absolutely nothing described here, @leobalter please reopen.

linusg commented 1 year ago

ping @leobalter

caridy commented 5 months ago

@ptomato can you take a look at this?