Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflating obj[Symbol.result] with func[Symbol.result] breaks functions returning functions #23

Closed
andersk opened this issue Aug 19, 2024 · 2 comments

Comments

@andersk
Copy link

andersk commented Aug 19, 2024

The meanings of Symbol.result in obj[Symbol.result] and func[Symbol.result] are very different. obj[Symbol.result]() is a result corresponding to obj itself, while func[Symbol.result]() is a result corresponding to the return value of func.

Using the same symbol for both of these meanings, along with recursive unwrapping (#6), completely breaks functions that return other functions.

const inner = () => console.log("inner() called");
const outer = () => inner;

try {
    const f = outer(); // returns inner without calling inner()
} catch {}

const [error, data] ?= outer(); // unexpectedly calls inner()

This evaluates as outer[Symbol.result]()inner[Symbol.result]()[null, console.log("inner called")].

Even if you think recursive unwrapping is a good idea, it should only recurse through obj[Symbol.result], not func[Symbol.result]. So we need to use two different symbols for these different meanings.

@anacierdem
Copy link

This relates to #12

@andersk
Copy link
Author

andersk commented Aug 19, 2024

Oh I see the polyfill checks typeof result === "object" before recursing. That’s not clear from the description but this hasn’t reached the stage where specification wordsmithing is helpful, so closing for now.

@andersk andersk closed this as completed Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants