michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: function TestObject () michael@0: { michael@0: /* A warm, dry place for properties and methods to live */ michael@0: } michael@0: michael@0: TestObject.prototype._y = ""; michael@0: michael@0: Object.defineProperty(TestObject.prototype, "y", michael@0: { michael@0: enumerable: true, configurable: true, michael@0: get: function get_y () michael@0: { michael@0: var rv; michael@0: if (typeof this._y == "string") michael@0: rv = "got " + this._y; michael@0: else michael@0: rv = this._y; michael@0: return rv; michael@0: }, michael@0: set: function set_y (newVal) { this._y = newVal; } michael@0: }); michael@0: michael@0: michael@0: test(new TestObject()); michael@0: michael@0: function test(t) michael@0: { michael@0: enterFunc ("test"); michael@0: michael@0: printStatus ("Basic Getter/ Setter test"); michael@0: reportCompare ("", t._y, "y prototype check"); michael@0: michael@0: reportCompare ("got ", t.y, "y getter, before set"); michael@0: michael@0: t.y = "new y"; michael@0: reportCompare ("got new y", t.y, "y getter, after set"); michael@0: michael@0: t.y = 2; michael@0: reportCompare (2, t.y, "y getter, after numeric set"); michael@0: michael@0: var d = new Date(); michael@0: t.y = d; michael@0: reportCompare (d, t.y, "y getter, after date set"); michael@0: michael@0: }