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