js/src/tests/ecma_5/Expressions/primitive-this-boxing-behavior.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_5/Expressions/primitive-this-boxing-behavior.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,106 @@
     1.4 +// Any copyright is dedicated to the Public Domain.
     1.5 +// http://creativecommons.org/licenses/publicdomain/
     1.6 +
     1.7 +//-----------------------------------------------------------------------------
     1.8 +var BUGNUMBER = 732669;
     1.9 +var summary = "Primitive values don't box correctly";
    1.10 +
    1.11 +print(BUGNUMBER + ": " + summary);
    1.12 +
    1.13 +/**************
    1.14 + * BEGIN TEST *
    1.15 + **************/
    1.16 +
    1.17 +var t;
    1.18 +function returnThis() { return this; }
    1.19 +
    1.20 +// Boolean
    1.21 +
    1.22 +Boolean.prototype.method = returnThis;
    1.23 +t = true.method();
    1.24 +assertEq(t !== Boolean.prototype, true);
    1.25 +assertEq(t.toString(), "true");
    1.26 +
    1.27 +Object.defineProperty(Boolean.prototype, "property", { get: returnThis, configurable: true });
    1.28 +t = false.property;
    1.29 +assertEq(t !== Boolean.prototype, true);
    1.30 +assertEq(t.toString(), "false");
    1.31 +
    1.32 +delete Boolean.prototype.method;
    1.33 +delete Boolean.prototype.property;
    1.34 +
    1.35 +
    1.36 +// Number
    1.37 +
    1.38 +Number.prototype.method = returnThis;
    1.39 +t = 5..method();
    1.40 +assertEq(t !== Number.prototype, true);
    1.41 +assertEq(t.toString(), "5");
    1.42 +
    1.43 +Object.defineProperty(Number.prototype, "property", { get: returnThis, configurable: true });
    1.44 +t = 17..property;
    1.45 +assertEq(t !== Number.prototype, true);
    1.46 +assertEq(t.toString(), "17");
    1.47 +
    1.48 +delete Number.prototype.method;
    1.49 +delete Number.prototype.property;
    1.50 +
    1.51 +
    1.52 +// String
    1.53 +
    1.54 +String.prototype.method = returnThis;
    1.55 +t = "foo".method();
    1.56 +assertEq(t !== String.prototype, true);
    1.57 +assertEq(t.toString(), "foo");
    1.58 +
    1.59 +Object.defineProperty(String.prototype, "property", { get: returnThis, configurable: true });
    1.60 +t = "bar".property;
    1.61 +assertEq(t !== String.prototype, true);
    1.62 +assertEq(t.toString(), "bar");
    1.63 +
    1.64 +delete String.prototype.method;
    1.65 +delete String.prototype.property;
    1.66 +
    1.67 +
    1.68 +// Object
    1.69 +
    1.70 +Object.prototype.method = returnThis;
    1.71 +
    1.72 +t = true.method();
    1.73 +assertEq(t !== Object.prototype, true);
    1.74 +assertEq(t !== Boolean.prototype, true);
    1.75 +assertEq(t.toString(), "true");
    1.76 +
    1.77 +t = 42..method();
    1.78 +assertEq(t !== Object.prototype, true);
    1.79 +assertEq(t !== Number.prototype, true);
    1.80 +assertEq(t.toString(), "42");
    1.81 +
    1.82 +t = "foo".method();
    1.83 +assertEq(t !== Object.prototype, true);
    1.84 +assertEq(t !== String.prototype, true);
    1.85 +assertEq(t.toString(), "foo");
    1.86 +
    1.87 +Object.defineProperty(Object.prototype, "property", { get: returnThis, configurable: true });
    1.88 +
    1.89 +t = false.property;
    1.90 +assertEq(t !== Object.prototype, true);
    1.91 +assertEq(t !== Boolean.prototype, true);
    1.92 +assertEq(t.toString(), "false");
    1.93 +
    1.94 +t = 8675309..property;
    1.95 +assertEq(t !== Object.prototype, true);
    1.96 +assertEq(t !== Number.prototype, true);
    1.97 +assertEq(t.toString(), "8675309");
    1.98 +
    1.99 +t = "bar".property;
   1.100 +assertEq(t !== Object.prototype, true);
   1.101 +assertEq(t !== String.prototype, true);
   1.102 +assertEq(t.toString(), "bar");
   1.103 +
   1.104 +/******************************************************************************/
   1.105 +
   1.106 +if (typeof reportCompare === "function")
   1.107 +  reportCompare(true, true);
   1.108 +
   1.109 +print("Tests complete");

mercurial