1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/lib/asserts.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 + 1.9 +load(libdir + "../../tests/ecma_6/shell.js"); 1.10 + 1.11 +if (typeof assertWarning === 'undefined') { 1.12 + var assertWarning = function assertWarning(f, errorClass, msg) { 1.13 + var hadWerror = options().split(",").indexOf("werror") !== -1; 1.14 + 1.15 + // Ensure the "werror" option is disabled. 1.16 + if (hadWerror) 1.17 + options("werror"); 1.18 + 1.19 + try { 1.20 + f(); 1.21 + } catch (exc) { 1.22 + if (hadWerror) 1.23 + options("werror"); 1.24 + 1.25 + // print() rather than throw a different exception value, in case 1.26 + // the caller wants exc.stack. 1.27 + if (msg) 1.28 + print("assertWarning: " + msg); 1.29 + print("assertWarning: Unexpected exception calling " + f + 1.30 + " with warnings-as-errors disabled"); 1.31 + throw exc; 1.32 + } 1.33 + 1.34 + // Enable the "werror" option. 1.35 + options("werror"); 1.36 + 1.37 + try { 1.38 + assertThrowsInstanceOf(f, errorClass, msg); 1.39 + } catch (exc) { 1.40 + if (msg) 1.41 + print("assertWarning: " + msg); 1.42 + throw exc; 1.43 + } finally { 1.44 + if (!hadWerror) 1.45 + options("werror"); 1.46 + } 1.47 + }; 1.48 +} 1.49 + 1.50 +if (typeof assertNoWarning === 'undefined') { 1.51 + var assertNoWarning = function assertWarning(f, msg) { 1.52 + // Ensure the "werror" option is enabled. 1.53 + var hadWerror = options().split(",").indexOf("werror") !== -1; 1.54 + if (!hadWerror) 1.55 + options("werror"); 1.56 + 1.57 + try { 1.58 + f(); 1.59 + } catch (exc) { 1.60 + if (msg) 1.61 + print("assertNoWarning: " + msg); 1.62 + print("assertNoWarning: Unexpected exception calling " + f + 1.63 + "with warnings-as-errors enabled"); 1.64 + throw exc; 1.65 + } finally { 1.66 + if (!hadWerror) 1.67 + options("werror"); 1.68 + } 1.69 + }; 1.70 +}