js/src/tests/js1_5/GetSet/getset-002.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_5/GetSet/getset-002.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,50 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +
    1.10 +var t = {   
    1.11 +  _y: "<initial y>",
    1.12 +
    1.13 +  get y()
    1.14 +  {
    1.15 +    var rv;
    1.16 +    if (typeof this._y == "string")
    1.17 +      rv = "got " + this._y;
    1.18 +    else
    1.19 +      rv = this._y;
    1.20 +
    1.21 +    return rv;
    1.22 +  },
    1.23 +
    1.24 +  set y(newVal)
    1.25 +  {
    1.26 +    this._y = newVal;
    1.27 +  }
    1.28 +}
    1.29 +
    1.30 +
    1.31 +  test(t);
    1.32 +
    1.33 +function test(t)
    1.34 +{
    1.35 +  enterFunc ("test");
    1.36 +   
    1.37 +  printStatus ("Basic Getter/ Setter test (object literal notation)");
    1.38 +
    1.39 +  reportCompare ("<initial y>", t._y, "y prototype check");
    1.40 +
    1.41 +  reportCompare ("got <initial y>", t.y, "y getter, before set");
    1.42 +
    1.43 +  t.y = "new y";
    1.44 +  reportCompare ("got new y", t.y, "y getter, after set");
    1.45 +
    1.46 +  t.y = 2;
    1.47 +  reportCompare (2, t.y, "y getter, after numeric set");
    1.48 +
    1.49 +  var d = new Date();
    1.50 +  t.y = d;
    1.51 +  reportCompare (d, t.y, "y getter, after date set");
    1.52 +
    1.53 +}       

mercurial