gettersetter.js revision 1437:678db05f13ba
1147191Sjkoshy/*
2147191Sjkoshy * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3147191Sjkoshy * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4147191Sjkoshy *
5147191Sjkoshy * This code is free software; you can redistribute it and/or modify it
6147191Sjkoshy * under the terms of the GNU General Public License version 2 only, as
7147191Sjkoshy * published by the Free Software Foundation.
8147191Sjkoshy *
9147191Sjkoshy * This code is distributed in the hope that it will be useful, but WITHOUT
10147191Sjkoshy * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11147191Sjkoshy * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12147191Sjkoshy * version 2 for more details (a copy is included in the LICENSE file that
13147191Sjkoshy * accompanied this code).
14147191Sjkoshy *
15147191Sjkoshy * You should have received a copy of the GNU General Public License version
16147191Sjkoshy * 2 along with this work; if not, write to the Free Software Foundation,
17147191Sjkoshy * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18147191Sjkoshy *
19147191Sjkoshy * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20147191Sjkoshy * or visit www.oracle.com if you need additional information or have any
21147191Sjkoshy * questions.
22147191Sjkoshy */
23147191Sjkoshy
24147191Sjkoshy/**
25147191Sjkoshy * @test
26147191Sjkoshy * @option -Dnashorn.debug=true
27147191Sjkoshy * @fork
28147191Sjkoshy */
29147191Sjkoshy
30147191Sjkoshyload(__DIR__ + "maputil.js");
31147191Sjkoshy
32147191Sjkoshyfunction Foo() {
33147191Sjkoshy    return {
34147191Sjkoshy       get foo() { return 42; },
35147191Sjkoshy       set foo(x) {}
36147191Sjkoshy    }
37147191Sjkoshy}
38147191Sjkoshy
39147191Sjkoshyvar obj1 = Foo();
40147191Sjkoshyvar obj2 = Foo();
41174410Sjkoshy
42174410SjkoshyassertSameMap(obj1, obj2, "Object literals before change");
43174410Sjkoshy
44174410SjkoshyObject.defineProperty(obj2, "foo", { get: function() { return 'hello' } });
45174410SjkoshyassertSameMap(obj1, obj2);
46174410Sjkoshy
47174410SjkoshyObject.defineProperty(obj2, "foo", { set: function(x) { print(x) } });
48174410SjkoshyassertSameMap(obj1, obj2);
49174410Sjkoshy