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

Set decorationState.[[Finished]] to true when decorator throws #13

Open
wants to merge 2 commits into
base: decorators
Choose a base branch
from

Conversation

nicolo-ribaudo
Copy link

Decorators have a "finished" state that is set when the decorator call is done, to prevent addInitializer to be called after the decorator is done.

The current proposed spec sets it to true only if the decorator call does not throw:

class A {
  @((_, ctx) => {
    setTimeout(() => /* throws */ ctx.addInitializer(() => {}), 1000);
  })
  method() {}
}

try {
  class A {
    @((_, ctx) => {
      setTimeout(() => /* throws */ ctx.addInitializer(() => {}), 1000);
      return 3;
    })
    method() {}
  }
} finally {} // Decorating the class throws, because the decorator returns an invalid value

try {
  class A {
    @((_, ctx) => {
      setTimeout(() => /* does not throw */ ctx.addInitializer(() => {}), 1000);
      throw {}
    })
    method() {}
  }
} finally {} // Decorating the class throws, because the decorator throws

This PR updates the third case to also throw.

Fixes tc39/proposal-decorators#500.

@nicolo-ribaudo
Copy link
Author

I was too quick to push -- I updated also the other place where we set [[Finished]] to true.

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

Successfully merging this pull request may close these issues.

2 participants