assertion.js 572 B

1234567891011121314151617181920212223242526
  1. /**
  2. * Internal Assertion
  3. *
  4. * Mechanics to prevent unexpected value from being spread
  5. * by the weak type system of JavaScript.
  6. * When an unexcepted value is detected, the execution of script
  7. * terminates immediately due to an AssertionFailed error.
  8. */
  9. class AssertionFailed extends Error {
  10. constructor () {
  11. super('Internal Assertion Failed')
  12. this.name = 'RuntimeError'
  13. }
  14. }
  15. function assert (value) {
  16. if(!value) {
  17. throw new AssertionFailed()
  18. }
  19. // this `return` is intentional, don't remove it
  20. return true
  21. }