Home | History | Annotate | Download | only in GetSet
      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
      2  *
      3  * The contents of this file are subject to the Netscape Public
      4  * License Version 1.1 (the "License"); you may not use this file
      5  * except in compliance with the License. You may obtain a copy of
      6  * the License at http://www.mozilla.org/NPL/
      7  *
      8  * Software distributed under the License is distributed on an "AS
      9  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
     10  * implied. See the License for the specific language governing
     11  * rights and limitations under the License.
     12  *
     13  * The Original Code is Mozilla Communicator client code, released March
     14  * 31, 1998.
     15  *
     16  * The Initial Developer of the Original Code is Netscape Communications
     17  * Corporation. Portions created by Netscape are
     18  * Copyright (C) 1998 Netscape Communications Corporation. All
     19  * Rights Reserved.
     20  *
     21  * Contributor(s):
     22  * Rob Ginda rginda (at) netscape.com
     23  */
     24 
     25 function TestObject ()
     26 {
     27     /* A warm, dry place for properties and methods to live */
     28 }
     29 
     30 TestObject.prototype._y = "<initial y>";
     31 
     32 TestObject.prototype.y getter =
     33 function get_y ()
     34 {
     35     var rv;
     36 
     37     if (typeof this._y == "string")
     38         rv = "got " + this._y;
     39     else
     40         rv = this._y;
     41 
     42     return rv;
     43 }
     44 
     45 TestObject.prototype.y setter =
     46 function set_y (newVal)
     47 {
     48     this._y = newVal;
     49 }
     50 
     51 test(new TestObject());
     52 
     53 function test(t)
     54 {
     55     enterFunc ("test");
     56 
     57     printStatus ("Basic Getter/ Setter test");
     58     reportCompare ("<initial y>", t._y, "y prototype check");
     59 
     60     reportCompare ("got <initial y>", t.y, "y getter, before set");
     61 
     62     t.y = "new y";
     63     reportCompare ("got new y", t.y, "y getter, after set");
     64 
     65     t.y = 2;
     66     reportCompare (2, t.y, "y getter, after numeric set");
     67 
     68     var d = new Date();
     69     t.y = d;
     70     reportCompare (d, t.y, "y getter, after date set");
     71 
     72 }
     73