nashorn/test/script/basic/JDK-8042364.js
author hannesw
Fri, 03 Feb 2017 13:28:00 +0100
changeset 43555 1bb10bccf057
parent 24778 2ff5d7041566
permissions -rw-r--r--
8173888: Test for JDK-8169481 causes stack overflows in parser tests Reviewed-by: jlaskey, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24281
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
     1
/*
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24281
diff changeset
     4
 *
24281
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24281
diff changeset
     8
 *
24281
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    13
 * accompanied this code).
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24281
diff changeset
    14
 *
24281
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24281
diff changeset
    18
 *
24281
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    21
 * questions.
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    22
 */
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    23
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    24
/**
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    25
 * JDK-8042364: Make __proto__ ES6 draft compliant
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24281
diff changeset
    26
 *
24281
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    27
 * @test
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    28
 * @run
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    29
 */
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    30
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    31
// check for Object.prototype.__proto__ accessor property
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    32
print("Object.prototype has __proto__?",
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    33
    Object.prototype.hasOwnProperty("__proto__"))
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    34
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    35
var desc = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__")
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    36
print("descriptor");
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    37
print(JSON.stringify(desc))
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    38
print("getter", desc.get)
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    39
print("setter", desc.set)
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    40
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    41
// no computed "__proto__" name, only identifier!
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    42
var p = {}
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    43
var obj = {
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    44
    "__proto__" : p
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    45
}
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    46
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    47
if (Object.getPrototypeOf(obj) === p) {
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    48
    fail("obj has wrong __proto__, allows computed __proto__!")
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    49
}
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    50
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    51
if (obj.__proto__ !== p) {
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    52
    fail("__proto__ not created as normal property!")
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    53
}
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    54
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    55
if (Object.getPrototypeOf(obj) !== Object.prototype) {
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    56
    fail("obj has wrong __proto__")
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    57
}
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    58
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    59
var obj2 = {
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    60
    __proto__: p
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    61
}
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    62
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    63
if (Object.getPrototypeOf(obj2) !== p) {
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    64
    fail("can't set __proto__ in object literal")
58ed42a1ebc6 8042364: Make __proto__ ES6 draft compliant
sundar
parents:
diff changeset
    65
}