nashorn/test/script/basic/JDK-8010924.js
author hannesw
Fri, 03 May 2013 22:48:53 +0200
changeset 17521 0522325da5ef
parent 16755 1db736812802
permissions -rw-r--r--
8013873: Regexp regression for escaped dash in character class Reviewed-by: jlaskey
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16755
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
     1
/*
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
     4
 *
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
     8
 *
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    13
 * accompanied this code).
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    14
 *
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    18
 *
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    21
 * questions.
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    22
 */
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    23
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    24
/**
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    25
 * JDK-8010924:  Dealing with undefined property gets you a fatal stack
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    26
 *
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    27
 * @test
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    28
 * @run
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    29
 * @option -scripting
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    30
 */
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    31
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    32
load("nashorn:mozilla_compat.js");
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    33
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    34
if (this.non_existent_foo !== undefined) {
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    35
    fail("this.non_existent_foo is defined!");
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    36
}
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    37
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    38
try {
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    39
    non_existent_foo;
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    40
    fail("should have thrown ReferenceError");
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    41
} catch (e) {
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    42
    if (! (e instanceof ReferenceError)) {
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    43
        fail("ReferenceError expected, got " + e);
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    44
    }
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    45
}
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    46
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    47
// try the same via script engine
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    48
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    49
var ScriptEngineManager = Java.type("javax.script.ScriptEngineManager");
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    50
var engine = new ScriptEngineManager().getEngineByName("nashorn");
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    51
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    52
engine.eval("load('nashorn:mozilla_compat.js')");
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    53
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    54
if (! engine.eval("this.non_existent_foo === undefined")) {
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    55
    fail("this.non_existent_foo is not undefined");
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    56
}
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    57
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    58
engine.eval(<<EOF
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    59
    try {
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    60
        non_existent_foo;
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    61
        throw new Error("should have thrown ReferenceError");
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    62
    } catch (e) {
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    63
        if (! (e instanceof ReferenceError)) {
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    64
            throw new Error("ReferenceError expected, got " + e);
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    65
        }
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    66
    }
1db736812802 8010924: Dealing with undefined property gets you a fatal stack
sundar
parents:
diff changeset
    67
EOF);