biops.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved.
  4. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  5. //-------------------------------------------------------------------------------------------------------
  6. function write(v) {
  7. v = (v + "").replace(/\(PST\)/g, "(Pacific Standard Time)")
  8. .replace(/\(PDT\)/g, "(Pacific Daylight Time)");
  9. WScript.Echo(v);
  10. }
  11. function foo() {}
  12. var d = new Date("Thu Aug 5 05:30:00 PDT 2010");
  13. var all = [ undefined, null,
  14. true, false,
  15. Boolean(true), Boolean(false),
  16. new Boolean(true), new Boolean(false),
  17. NaN, +0, -0, 0, 0.0, -0.0, +0.0,
  18. 1, 10, 10.0, 10.1, -1,
  19. -10, -10.0, -10.1,
  20. Number.MAX_VALUE, Number.MIN_VALUE, Number.NaN, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY,
  21. new Number(NaN), new Number(+0), new Number(-0), new Number(0),
  22. new Number(0.0), new Number(-0.0), new Number(+0.0),
  23. new Number(1), new Number(10), new Number(10.0), new Number(10.1), new Number(-1),
  24. new Number(-10), new Number(-10.0), new Number(-10.1),
  25. new Number(Number.MAX_VALUE), new Number(Number.MIN_VALUE), new Number(Number.NaN),
  26. new Number(Number.POSITIVE_INFINITY), new Number(Number.NEGATIVE_INFINITY),
  27. "", "0xa", "04", "hello", "hel" + "lo",
  28. String(""), String("hello"), String("h" + "ello"),
  29. new String(""), new String("hello"), new String("he" + "llo"),
  30. new Object(), new Object(),
  31. [1,2,3], [1,2,3],
  32. new Array(3), Array(3), new Array(1, 2, 3), Array(1),
  33. foo, d, 1281011400000, d
  34. ];
  35. var biops = [
  36. "*", "/", "%", // 11.5 Multiplicative operators
  37. "+", "-", // 11.6 Addtitive operators
  38. "<<", ">>", ">>>", // 11.7 Bitwise shift operators
  39. "<", ">", "<=", ">=", // 11.8 Relational operators
  40. "==", "!=", "===", "!==", // 11.9 Equality operators
  41. "&", "^", "|", // 11.10 Binary bitwise operators
  42. "&&", "||" // 11.11 Binary logical operators
  43. ];
  44. for (var op in biops) {
  45. for (var i=0; i<all.length; ++i) {
  46. for (var j=0; j<all.length; ++j) {
  47. write("a["+i+"]("+all[i]+") "+biops[op]+" a["+j+"]("+all[j]+") = " + eval("all[i] " + biops[op] + " all[j];"));
  48. }
  49. }
  50. }