Debian Codegraph @

rhino/testsrc/tests/js1_5/extensions/getset-001.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 var gTestfile = 'getset-001.js';
8
9 function TestObject ()
10 {
11 /* A warm, dry place for properties and methods to live */
12 }
13
14 TestObject.prototype._y = "<initial y>";
15
16 TestObject.prototype.y getter =
17 function get_y ()
18 {
19 var rv;
20
21 if (typeof this._y == "string")
22 rv = "got " + this._y;
23 else
24 rv = this._y;
25
26 return rv;
27 }
28
29 TestObject.prototype.y setter =
30 function set_y (newVal)
31 {
32 this._y = newVal;
33 }
34
35 test(new TestObject());
36
37 function test(t)
38 {
39 enterFunc ("test");
40
41 printStatus ("Basic Getter/ Setter test");
42 reportCompare ("<initial y>", t._y, "y prototype check");
43
44 reportCompare ("got <initial y>", t.y, "y getter, before set");
45
46 t.y = "new y";
47 reportCompare ("got new y", t.y, "y getter, after set");
48
49 t.y = 2;
50 reportCompare (2, t.y, "y getter, after numeric set");
51
52 var d = new Date();
53 t.y = d;
54 reportCompare (d, t.y, "y getter, after date set");
55
56 }