| OLD | NEW |
| 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- | 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 * | 2 * |
| 3 * ***** BEGIN LICENSE BLOCK ***** | 3 * ***** BEGIN LICENSE BLOCK ***** |
| 4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 5 * | 5 * |
| 6 * The contents of this file are subject to the Mozilla Public License Version | 6 * The contents of this file are subject to the Mozilla Public License Version |
| 7 * 1.1 (the "License"); you may not use this file except in compliance with | 7 * 1.1 (the "License"); you may not use this file except in compliance with |
| 8 * the License. You may obtain a copy of the License at | 8 * the License. You may obtain a copy of the License at |
| 9 * http://www.mozilla.org/MPL/ | 9 * http://www.mozilla.org/MPL/ |
| 10 * | 10 * |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 var actual = ''; | 68 var actual = ''; |
| 69 var msg = ''; | 69 var msg = ''; |
| 70 | 70 |
| 71 var SECTION = ""; | 71 var SECTION = ""; |
| 72 var VERSION = ""; | 72 var VERSION = ""; |
| 73 var BUGNUMBER = ""; | 73 var BUGNUMBER = ""; |
| 74 | 74 |
| 75 /* | 75 /* |
| 76 * constant strings | 76 * constant strings |
| 77 */ | 77 */ |
| 78 var GLOBAL = "[object global]"; | 78 var GLOBAL = this + ''; |
| 79 var PASSED = " PASSED! "; | 79 var PASSED = " PASSED! "; |
| 80 var FAILED = " FAILED! "; | 80 var FAILED = " FAILED! "; |
| 81 | 81 |
| 82 var DEBUG = false; | 82 var DEBUG = false; |
| 83 | 83 |
| 84 var DESCRIPTION; | 84 var DESCRIPTION; |
| 85 var EXPECTED; | 85 var EXPECTED; |
| 86 | 86 |
| 87 /* | 87 /* |
| 88 * wrapper for test case constructor that doesn't require the SECTION | 88 * wrapper for test case constructor that doesn't require the SECTION |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 else | 267 else |
| 268 { | 268 { |
| 269 result += "\\x" + b + a; | 269 result += "\\x" + b + a; |
| 270 } | 270 } |
| 271 } | 271 } |
| 272 | 272 |
| 273 return result; | 273 return result; |
| 274 } | 274 } |
| 275 | 275 |
| 276 /* | 276 /* |
| 277 * assertEq(actual, expected) |
| 278 * Throw if the two arguments are not === |
| 279 * see https://bugzilla.mozilla.org/show_bug.cgi?id=480199 |
| 280 */ |
| 281 if (typeof assertEq == 'undefined') |
| 282 { |
| 283 var assertEq = |
| 284 function (actual, expected) |
| 285 { |
| 286 if (actual !== expected) |
| 287 { |
| 288 throw new TypeError('Assertion failed: got "' + actual + '", expected "'
+ expected); |
| 289 } |
| 290 }; |
| 291 } |
| 292 |
| 293 /* |
| 277 * Compare expected result to actual result, if they differ (in value and/or | 294 * Compare expected result to actual result, if they differ (in value and/or |
| 278 * type) report a failure. If description is provided, include it in the | 295 * type) report a failure. If description is provided, include it in the |
| 279 * failure report. | 296 * failure report. |
| 280 */ | 297 */ |
| 281 function reportCompare (expected, actual, description) { | 298 function reportCompare (expected, actual, description) { |
| 282 var expected_t = typeof expected; | 299 var expected_t = typeof expected; |
| 283 var actual_t = typeof actual; | 300 var actual_t = typeof actual; |
| 284 var output = ""; | 301 var output = ""; |
| 285 | 302 |
| 286 if (typeof description == "undefined") | 303 if (typeof description == "undefined") |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 | 686 |
| 670 for (optionName in optionsframe) | 687 for (optionName in optionsframe) |
| 671 { | 688 { |
| 672 options(optionName); | 689 options(optionName); |
| 673 } | 690 } |
| 674 | 691 |
| 675 } | 692 } |
| 676 | 693 |
| 677 function optionsReset() { | 694 function optionsReset() { |
| 678 | 695 |
| 679 optionsClear(); | 696 try |
| 697 { |
| 698 optionsClear(); |
| 680 | 699 |
| 681 // turn on initial settings | 700 // turn on initial settings |
| 682 for (optionName in options.initvalues) | 701 for (optionName in options.initvalues) |
| 702 { |
| 703 options(optionName); |
| 704 } |
| 705 } |
| 706 catch(ex) |
| 683 { | 707 { |
| 684 options(optionName); | 708 print('optionsReset: caught ' + ex); |
| 685 } | 709 } |
| 710 |
| 686 } | 711 } |
| 687 | 712 |
| 688 if (typeof options == 'function') | 713 if (typeof options == 'function') |
| 689 { | 714 { |
| 690 optionsInit(); | 715 optionsInit(); |
| 691 optionsClear(); | 716 optionsClear(); |
| 692 } | 717 } |
| 693 | 718 |
| 694 function getTestCaseResult(expected, actual) | 719 function getTestCaseResult(expected, actual) |
| 695 { | 720 { |
| 696 var expected_t = typeof expected; | 721 if (typeof expected != typeof actual) |
| 697 var actual_t = typeof actual; | 722 return false; |
| 698 var passed = true; | 723 if (typeof expected != 'number') |
| 699 | 724 // Note that many tests depend on the use of '==' here, not '==='. |
| 700 // because ( NaN == NaN ) always returns false, need to do | 725 return actual == expected; |
| 701 // a special compare to see if we got the right result. | |
| 702 if ( actual != actual ) | |
| 703 { | |
| 704 if ( actual_t == "object" ) | |
| 705 { | |
| 706 actual = "NaN object"; | |
| 707 } | |
| 708 else | |
| 709 { | |
| 710 actual = "NaN number"; | |
| 711 } | |
| 712 } | |
| 713 if ( expected != expected ) | |
| 714 { | |
| 715 if ( expected_t == "object" ) | |
| 716 { | |
| 717 expected = "NaN object"; | |
| 718 } | |
| 719 else | |
| 720 { | |
| 721 expected = "NaN number"; | |
| 722 } | |
| 723 } | |
| 724 | 726 |
| 725 if (expected_t != actual_t) | 727 // Distinguish NaN from other values. Using x != x comparisons here |
| 726 { | 728 // works even if tests redefine isNaN. |
| 727 passed = false; | 729 if (actual != actual) |
| 728 } | 730 return expected != expected; |
| 729 else if (expected != actual) | 731 if (expected != expected) |
| 730 { | 732 return false; |
| 731 if (expected_t != 'number' || (Math.abs(actual - expected) > 1E-10)) | 733 |
| 732 { | 734 // Tolerate a certain degree of error. |
| 733 passed = false; | 735 if (actual != expected) |
| 734 } | 736 return Math.abs(actual - expected) <= 1E-10; |
| 735 } | 737 |
| 736 | 738 // Here would be a good place to distinguish 0 and -0, if we wanted |
| 737 return passed; | 739 // to. However, doing so would introduce a number of failures in |
| 740 // areas where they don't seem important. For example, the WeekDay |
| 741 // function in ECMA-262 returns -0 for Sundays before the epoch, but |
| 742 // the Date functions in SpiderMonkey specified in terms of WeekDay |
| 743 // often don't. This seems unimportant. |
| 744 return true; |
| 738 } | 745 } |
| 739 | 746 |
| 740 if (typeof dump == 'undefined') | 747 if (typeof dump == 'undefined') |
| 741 { | 748 { |
| 742 if (typeof window == 'undefined' && | 749 if (typeof window == 'undefined' && |
| 743 typeof print == 'function') | 750 typeof print == 'function') |
| 744 { | 751 { |
| 745 dump = print; | 752 dump = print; |
| 746 } | 753 } |
| 747 else | 754 else |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 dump('jsTestDriverEnd ' + ex); | 851 dump('jsTestDriverEnd ' + ex); |
| 845 } | 852 } |
| 846 | 853 |
| 847 for (var i = 0; i < gTestcases.length; i++) | 854 for (var i = 0; i < gTestcases.length; i++) |
| 848 { | 855 { |
| 849 gTestcases[i].dump(); | 856 gTestcases[i].dump(); |
| 850 } | 857 } |
| 851 | 858 |
| 852 } | 859 } |
| 853 | 860 |
| 861 function jit(on) |
| 862 { |
| 863 if (on && !options().match(/jit/)) |
| 864 { |
| 865 options('jit'); |
| 866 } |
| 867 else if (!on && options().match(/jit/)) |
| 868 { |
| 869 options('jit'); |
| 870 } |
| 871 } |
| 872 |
| 854 /* | 873 /* |
| 855 * Some tests need to know if we are in Rhino as opposed to SpiderMonkey | 874 * Some tests need to know if we are in Rhino as opposed to SpiderMonkey |
| 856 */ | 875 */ |
| 857 function inRhino() | 876 function inRhino() |
| 858 { | 877 { |
| 859 return (typeof defineClass == "function"); | 878 return (typeof defineClass == "function"); |
| 860 } | 879 } |
| 861 | 880 |
| 862 /* these functions are useful for running tests manually in Rhino */ | 881 /* these functions are useful for running tests manually in Rhino */ |
| 863 | 882 |
| 864 function GetContext() { | 883 function GetContext() { |
| 865 return Packages.com.netscape.javascript.Context.getCurrentContext(); | 884 return Packages.com.netscape.javascript.Context.getCurrentContext(); |
| 866 } | 885 } |
| 867 function OptLevel( i ) { | 886 function OptLevel( i ) { |
| 868 i = Number(i); | 887 i = Number(i); |
| 869 var cx = GetContext(); | 888 var cx = GetContext(); |
| 870 cx.setOptimizationLevel(i); | 889 cx.setOptimizationLevel(i); |
| 871 } | 890 } |
| 872 /* end of Rhino functions */ | 891 /* end of Rhino functions */ |
| 873 | 892 |
| 874 | 893 |
| OLD | NEW |