unaryOps.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. function write(v) { WScript.Echo(v + ""); }
  6. function foo() {}
  7. var all = [ undefined, null, //1
  8. true, false, // 3
  9. Boolean(true), Boolean(false), // 5
  10. new Boolean(true), new Boolean(false), //7
  11. NaN, +0, -0, 0, 0.0, -0.0, +0.0, // 14
  12. 1, 10, 10.0, 10.1, -1, // 19
  13. -10, -10.0, -10.1, // 22
  14. Number.MAX_VALUE, Number.MIN_VALUE, Number.NaN, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY, //27
  15. new Number(NaN), new Number(+0), new Number(-0), new Number(0), // 31
  16. new Number(0.0), new Number(-0.0), new Number(+0.0), //34
  17. new Number(1), new Number(10), new Number(10.0), new Number(10.1), new Number(-1), // 39
  18. new Number(-10), new Number(-10.0), new Number(-10.1), // 42
  19. new Number(Number.MAX_VALUE), new Number(Number.MIN_VALUE), new Number(Number.NaN), // 45
  20. new Number(Number.POSITIVE_INFINITY), new Number(Number.NEGATIVE_INFINITY), // 47
  21. "", "hello", "hel" + "lo", // 50
  22. String(""), String("hello"), String("h" + "ello"),
  23. new String(""), new String("hello"), new String("he" + "llo"),
  24. new Object(), new Object(),
  25. [1,2,3], [1,2,3],
  26. new Array(3), Array(3), new Array(1,2,3),
  27. Array(1),
  28. foo,
  29. Math.pow(2,29)-2,Math.pow(2,29)-1,Math.pow(2,29),Math.pow(2,29)+1,Math.pow(2,29)+2,
  30. Math.pow(2,30)-2,Math.pow(2,30)-1,Math.pow(2,30),Math.pow(2,30)+1,Math.pow(2,30)+2,
  31. Math.pow(2,31)-2,Math.pow(2,31)-1,Math.pow(2,31),Math.pow(2,31)+1,Math.pow(2,31)+2,
  32. Math.pow(2,32)-2,Math.pow(2,32)-1,Math.pow(2,32),Math.pow(2,32)+1,Math.pow(2,32)+2,
  33. -(Math.pow(2,29)-2),-(Math.pow(2,29)-1),-(Math.pow(2,29)),-(Math.pow(2,29)+1),-(Math.pow(2,29)+2),
  34. -(Math.pow(2,30)-2),-(Math.pow(2,30)-1),-(Math.pow(2,30)),-(Math.pow(2,30)+1),-(Math.pow(2,30)+2),
  35. -(Math.pow(2,31)-2),-(Math.pow(2,31)-1),-(Math.pow(2,31)),-(Math.pow(2,31)+1),-(Math.pow(2,31)+2),
  36. -(Math.pow(2,32)-2),-(Math.pow(2,32)-1),-(Math.pow(2,32)),-(Math.pow(2,32)+1),-(Math.pow(2,32)+2)
  37. ];
  38. var uops = [
  39. // commented pre-incr/decr and moved out of eval due to bug 407
  40. "typeof", /*"++", "--",*/ "+", "-", "~", "!", "void"
  41. ];
  42. var val = 0;
  43. for (var op in uops) {
  44. for (var i=0; i<all.length; ++i) {
  45. val = all[i];
  46. write(uops[op]+ " a["+i+"]("+all[i]+") = " + eval(uops[op] + " val;") + ". Value: " + val);
  47. }
  48. }
  49. // Pre/post Incr/Decr
  50. for (var i=0; i<all.length; ++i) {
  51. val = all[i];
  52. write(" ++a["+i+"]("+all[i]+") = " + (++val) + ". Value: " + val);
  53. val = all[i];
  54. write(" --a["+i+"]("+all[i]+") = " + (--val) + ". Value: " + val);
  55. val = all[i];
  56. write(" a["+i+"]("+all[i]+")++ = " + (val++) + ". Value: " + val);
  57. val = all[i];
  58. write(" a["+i+"]("+all[i]+")-- = " + (val--) + ". Value: " + val);
  59. }