JDK-8042364.js revision 877:cf4d2252d444
1254885Sdumbbell/*
2254885Sdumbbell * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3254885Sdumbbell * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4254885Sdumbbell *
5254885Sdumbbell * This code is free software; you can redistribute it and/or modify it
6254885Sdumbbell * under the terms of the GNU General Public License version 2 only, as
7254885Sdumbbell * published by the Free Software Foundation.
8254885Sdumbbell *
9254885Sdumbbell * This code is distributed in the hope that it will be useful, but WITHOUT
10254885Sdumbbell * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11254885Sdumbbell * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12254885Sdumbbell * version 2 for more details (a copy is included in the LICENSE file that
13254885Sdumbbell * accompanied this code).
14254885Sdumbbell *
15254885Sdumbbell * You should have received a copy of the GNU General Public License version
16254885Sdumbbell * 2 along with this work; if not, write to the Free Software Foundation,
17254885Sdumbbell * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18254885Sdumbbell *
19254885Sdumbbell * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20254885Sdumbbell * or visit www.oracle.com if you need additional information or have any
21254885Sdumbbell * questions.
22254885Sdumbbell */
23254885Sdumbbell
24254885Sdumbbell/**
25254885Sdumbbell * JDK-8042364: Make __proto__ ES6 draft compliant
26254885Sdumbbell *
27254885Sdumbbell * @test
28254885Sdumbbell * @run
29254885Sdumbbell */
30254885Sdumbbell
31254885Sdumbbell// check for Object.prototype.__proto__ accessor property
32254885Sdumbbellprint("Object.prototype has __proto__?",
33254885Sdumbbell    Object.prototype.hasOwnProperty("__proto__"))
34254885Sdumbbell
35254885Sdumbbellvar desc = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__")
36254885Sdumbbellprint("descriptor");
37254885Sdumbbellprint(JSON.stringify(desc))
38254885Sdumbbellprint("getter", desc.get)
39254885Sdumbbellprint("setter", desc.set)
40254885Sdumbbell
41254885Sdumbbell// no computed "__proto__" name, only identifier!
42254885Sdumbbellvar p = {}
43254885Sdumbbellvar obj = {
44254885Sdumbbell    "__proto__" : p
45254885Sdumbbell}
46254885Sdumbbell
47254885Sdumbbellif (Object.getPrototypeOf(obj) === p) {
48254885Sdumbbell    fail("obj has wrong __proto__, allows computed __proto__!")
49254885Sdumbbell}
50254885Sdumbbell
51254885Sdumbbellif (obj.__proto__ !== p) {
52254885Sdumbbell    fail("__proto__ not created as normal property!")
53254885Sdumbbell}
54254885Sdumbbell
55254885Sdumbbellif (Object.getPrototypeOf(obj) !== Object.prototype) {
56254885Sdumbbell    fail("obj has wrong __proto__")
57254885Sdumbbell}
58254885Sdumbbell
59254885Sdumbbellvar obj2 = {
60254885Sdumbbell    __proto__: p
61254885Sdumbbell}
62254885Sdumbbell
63254885Sdumbbellif (Object.getPrototypeOf(obj2) !== p) {
64254885Sdumbbell    fail("can't set __proto__ in object literal")
65254885Sdumbbell}
66254885Sdumbbell