abrupt-is-a-short-circuit.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (C) 2019 Leo Balter. All rights reserved.
  2. // This code is governed by the BSD license found in the LICENSE file.
  3. /*---
  4. description: >
  5. Abrupt completions are also a Short circuit and prevent evaluation of the right-side expressions
  6. esid: sec-conditional-operator
  7. info: |
  8. ConditionalExpression :
  9. ShortCircuitExpression
  10. ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
  11. ShortCircuitExpression :
  12. LogicalORExpression
  13. CoalesceExpression
  14. CoalesceExpression :
  15. CoalesceExpressionHead ?? BitwiseORExpression
  16. CoalesceExpressionHead :
  17. CoalesceExpression
  18. BitwiseORExpression
  19. Runtime Semantics: Evaluation
  20. CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
  21. 1. Let lref be the result of evaluating CoalesceExpressionHead.
  22. 2. Let lval be ? GetValue(lref).
  23. 3. If lval is undefined or null,
  24. a. Let rref be the result of evaluating BitwiseORExpression.
  25. b. Return ? GetValue(rref).
  26. 4. Otherwise, return lval.
  27. features: [coalesce-expression]
  28. ---*/
  29. var x;
  30. function poison() {
  31. throw new Test262Error('poison handled');
  32. }
  33. function morePoison() {
  34. throw 'poison!!!!';
  35. }
  36. x = undefined;
  37. assert.throws(Test262Error, function() {
  38. undefined ?? poison() ?? morePoison();
  39. }, 'undefined ?? poison() ?? morePoison();');
  40. x = undefined;
  41. assert.throws(Test262Error, function() {
  42. null ?? poison() ?? morePoison();
  43. }, 'null ?? poison() ?? morePoison();');
  44. assert.throws(Test262Error, function() {
  45. poison() ?? morePoison();
  46. }, 'poison() ?? morePoison();');