nashorn/test/script/basic/JDK-8130853.js
author hannesw
Fri, 03 Feb 2017 13:28:00 +0100
changeset 43555 1bb10bccf057
parent 32049 af8f6292d54d
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:
31739
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
     1
/*
32049
af8f6292d54d 8133119: Error message associated with TypeError for call and new should include stringified Node
sundar
parents: 31739
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
31739
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
     4
 * 
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
     8
 * 
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    13
 * accompanied this code).
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    14
 * 
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    18
 * 
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    21
 * questions.
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    22
 */
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    23
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    24
/**
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    25
 * JDK-8130853: Non-extensible global is not handled property
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    26
 *
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    27
 * @test
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    28
 * @run
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    29
 */
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    30
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    31
// don't allow extensions to global
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    32
Object.preventExtensions(this);
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    33
try {
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    34
    eval("var x = 34;");
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    35
    throw new Error("should have thrown TypeError");
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    36
} catch (e) {
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    37
    if (! (e instanceof TypeError)) {
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    38
        throw e;
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    39
    }
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    40
}
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    41
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    42
try {
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    43
    eval("function func() {}");
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    44
    throw new Error("should have thrown TypeError");
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    45
} catch (e) {
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    46
    if (! (e instanceof TypeError)) {
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    47
        throw e;
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    48
    }
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    49
}
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    50
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    51
function checkLoad(code) {
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    52
    try {
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    53
        load({ name: "test", script: code });
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    54
        throw new Error("should have thrown TypeError for load: " + code);
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    55
    } catch (e) {
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    56
        if (! (e instanceof TypeError)) {
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    57
            throw e;
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    58
        }
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    59
    }
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    60
}
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    61
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    62
checkLoad("var y = 55");
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    63
checkLoad("function f() {}");
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    64
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    65
// check script engine eval
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    66
var ScriptEngineManager = Java.type("javax.script.ScriptEngineManager");
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    67
var e = new ScriptEngineManager().getEngineByName("nashorn");
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    68
var global = e.eval("this");
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    69
e.eval("Object.preventExtensions(this);");
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    70
try {
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    71
    e.eval("var myVar = 33;");
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    72
    throw new Error("should have thrown TypeError");
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    73
} catch (e) {
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    74
    if (! (e.cause.ecmaError instanceof global.TypeError)) {
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    75
        throw e;
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    76
    }
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    77
}
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    78
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    79
// Object.bindProperties on arbitrary non-extensible object
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    80
var obj = {};
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    81
Object.preventExtensions(obj);
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    82
try {
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    83
    Object.bindProperties(obj, { foo: 434 });
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    84
    throw new Error("should have thrown TypeError");
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    85
} catch (e) {
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    86
    if (! (e instanceof TypeError)) {
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    87
        throw e;
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    88
    }
ce2f5ee2202b 8130853: Non-extensible global is not handled property
sundar
parents:
diff changeset
    89
}