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

Convert the various ...Exceptions to proper classes, to reduce code duplication #11185

Merged
merged 1 commit into from
Sep 29, 2019

Conversation

Snuffleupagus
Copy link
Collaborator

By utilizing a base "class", things become significantly simpler. Unfortunately the new BaseException cannot be a proper ES6 class and just extend Error, since the SystemJS dependency doesn't seem to play well with that.
Note also that we (generally) need to keep the name property on the actual ...Exception object, rather than on its prototype, since the property will otherwise be dropped during the structured cloning used with postMessage.

@Snuffleupagus Snuffleupagus changed the title Convert the various ...Exceptions to proper classes, to reduced code duplication Convert the various ...Exceptions to proper classes, to reduce code duplication Sep 28, 2019
@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_unittest from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.215.176.217:8877/848c0e96affcbbe/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_unittest from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/ef26e4c37bd802f/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/ef26e4c37bd802f/output.txt

Total script time: 2.61 mins

  • Unit Tests: FAILED

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.215.176.217:8877/848c0e96affcbbe/output.txt

Total script time: 5.15 mins

  • Unit Tests: Passed

this.name = 'PasswordException';
this.message = msg;
this.code = code;
const BaseException = (function BaseExceptionClosure() {
Copy link
Collaborator Author

@Snuffleupagus Snuffleupagus Sep 29, 2019

Choose a reason for hiding this comment

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

Once extending Error isn't a problem any more, when SystemJS has been updated/replaced, it should be possible to simplify this even further to e.g.

class BaseException extends Error {
  constructor(message) {
    if (this.constructor === BaseException) {
      unreachable('Cannot initialize BaseException.');
    }
    super(message);
    this.name = this.constructor.name;
  }
}

… duplication

By utilizing a base "class", things become significantly simpler. Unfortunately the new `BaseException` cannot be a proper ES6 class and just extend `Error`, since the SystemJS dependency doesn't seem to play well with that.
Note also that we (generally) need to keep the `name` property on the actual `...Exception` object, rather than on its prototype, since the property will otherwise be dropped during the structured cloning used with `postMessage`.
@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_unittest from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.215.176.217:8877/ffaced9df7fdf54/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_unittest from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/9f81b958e4c51e2/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/9f81b958e4c51e2/output.txt

Total script time: 2.58 mins

  • Unit Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.215.176.217:8877/ffaced9df7fdf54/output.txt

Total script time: 4.97 mins

  • Unit Tests: Passed

@timvandermeij timvandermeij merged commit 06e4eb4 into mozilla:master Sep 29, 2019
@timvandermeij
Copy link
Contributor

Looks much cleaner. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants