diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/tests/ecma_5/JSON/stringify-boxed-primitives.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/ecma_5/JSON/stringify-boxed-primitives.js')
-rw-r--r-- | js/src/tests/ecma_5/JSON/stringify-boxed-primitives.js | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/js/src/tests/ecma_5/JSON/stringify-boxed-primitives.js b/js/src/tests/ecma_5/JSON/stringify-boxed-primitives.js new file mode 100644 index 000000000..0769c2ec6 --- /dev/null +++ b/js/src/tests/ecma_5/JSON/stringify-boxed-primitives.js @@ -0,0 +1,127 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +var gTestfile = 'stringify-boxed-primitives.js'; +//----------------------------------------------------------------------------- +var BUGNUMBER = 584909; +var summary = "Stringification of Boolean/String/Number objects"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +function redefine(obj, prop, fun) +{ + var desc = + { value: fun, writable: true, configurable: true, enumerable: false }; + Object.defineProperty(obj, prop, desc); +} + +assertEq(JSON.stringify(new Boolean(false)), "false"); + +assertEq(JSON.stringify(new Number(5)), "5"); + +assertEq(JSON.stringify(new String("foopy")), '"foopy"'); + + +var numToString = Number.prototype.toString; +var numValueOf = Number.prototype.valueOf; +var objToString = Object.prototype.toString; +var objValueOf = Object.prototype.valueOf; +var boolToString = Boolean.prototype.toString; +var boolValueOf = Boolean.prototype.valueOf; + +redefine(Boolean.prototype, "toString", function() { return 17; }); +assertEq(JSON.stringify(new Boolean(false)), "false") +delete Boolean.prototype.toString; +assertEq(JSON.stringify(new Boolean(false)), "false"); +delete Object.prototype.toString; +assertEq(JSON.stringify(new Boolean(false)), "false"); +delete Boolean.prototype.valueOf; +assertEq(JSON.stringify(new Boolean(false)), "false"); +delete Object.prototype.valueOf; +assertEq(JSON.stringify(new Boolean(false)), "false"); + + +redefine(Boolean.prototype, "toString", boolToString); +redefine(Boolean.prototype, "valueOf", boolValueOf); +redefine(Object.prototype, "toString", objToString); +redefine(Object.prototype, "valueOf", objValueOf); + +redefine(Number.prototype, "toString", function() { return 42; }); +assertEq(JSON.stringify(new Number(5)), "5"); +redefine(Number.prototype, "valueOf", function() { return 17; }); +assertEq(JSON.stringify(new Number(5)), "17"); +delete Number.prototype.toString; +assertEq(JSON.stringify(new Number(5)), "17"); +delete Number.prototype.valueOf; +assertEq(JSON.stringify(new Number(5)), "null"); // isNaN(Number("[object Number]")) +delete Object.prototype.toString; +try +{ + JSON.stringify(new Number(5)); + throw new Error("didn't throw"); +} +catch (e) +{ + assertEq(e instanceof TypeError, true, + "ToNumber failure, should throw TypeError"); +} +delete Object.prototype.valueOf; +try +{ + JSON.stringify(new Number(5)); + throw new Error("didn't throw"); +} +catch (e) +{ + assertEq(e instanceof TypeError, true, + "ToNumber failure, should throw TypeError"); +} + + +redefine(Number.prototype, "toString", numToString); +redefine(Number.prototype, "valueOf", numValueOf); +redefine(Object.prototype, "toString", objToString); +redefine(Object.prototype, "valueOf", objValueOf); + + +redefine(String.prototype, "valueOf", function() { return 17; }); +assertEq(JSON.stringify(new String(5)), '"5"'); +redefine(String.prototype, "toString", function() { return 42; }); +assertEq(JSON.stringify(new String(5)), '"42"'); +delete String.prototype.toString; +assertEq(JSON.stringify(new String(5)), '"[object String]"'); +delete Object.prototype.toString; +assertEq(JSON.stringify(new String(5)), '"17"'); +delete String.prototype.valueOf; +try +{ + JSON.stringify(new String(5)); + throw new Error("didn't throw"); +} +catch (e) +{ + assertEq(e instanceof TypeError, true, + "ToString failure, should throw TypeError"); +} +delete Object.prototype.valueOf; +try +{ + JSON.stringify(new String(5)); + throw new Error("didn't throw"); +} +catch (e) +{ + assertEq(e instanceof TypeError, true, + "ToString failure, should throw TypeError"); +} + +/******************************************************************************/ + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("All tests passed!"); |