Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Switch to options bag #25

Merged
merged 1 commit into from Jan 25, 2021
Merged

Switch to options bag #25

merged 1 commit into from Jan 25, 2021

Conversation

mmkal
Copy link
Contributor

@mmkal mmkal commented Jan 8, 2021

Fixes #11

@legendecas since #11 was reopened, I thought why not create a PR to update the proposal itself. Not sure if this process can be quite as simple as this for a Stage 2 proposal (this is one way to find out I guess)!

Note that this also fixes the backwards-compatibility concern with Firefox.

Previously, this proposal could run into trouble if raw strings are thrown. Say you're using a function like:

const foo = () => {
  if (Math.random() < 0.5) {
    throw 'bad luck'
  }
}

Before this change, the proposal would have users do something like:

try {
  foo()
} catch (e) {
  throw new Error('Do something failed!', e)
}

Which in most environments, would create an Error with cause: 'bad luck'. But in Firefox it'd be fileName: 'bad luck'. The suggested usage would now be:

try {
  foo()
} catch (e) {
  throw new Error('Do something failed!', { cause: e })
}

Switching to an options bag will allow Firefox to continue to interpret the second parameter as fileName if it's a string, and an options bag if it's an object (with a cause property).

CC @00ff0000red

@ghost
Copy link

ghost commented Jan 9, 2021

Seems like a lot of others would agree,

Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contribution. LGTM

@hemanth
Copy link
Member

hemanth commented Jan 25, 2021

Thanks, this adds more clarity!

@hemanth hemanth merged commit 96e7506 into tc39:main Jan 25, 2021
@mmkal mmkal deleted the patch-1 branch August 7, 2021 17:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Options bag parameter
3 participants