nashorn/test/script/basic/JDK-8068985.js
author hannesw
Fri, 03 Feb 2017 13:28:00 +0100
changeset 43555 1bb10bccf057
parent 31925 85c87bc2f1f3
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:
28441
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
     1
/*
31925
85c87bc2f1f3 8132092: Nashorn copyright has to be updated
sundar
parents: 28441
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
28441
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
31925
85c87bc2f1f3 8132092: Nashorn copyright has to be updated
sundar
parents: 28441
diff changeset
     4
 *
28441
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
31925
85c87bc2f1f3 8132092: Nashorn copyright has to be updated
sundar
parents: 28441
diff changeset
     8
 *
28441
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    13
 * accompanied this code).
31925
85c87bc2f1f3 8132092: Nashorn copyright has to be updated
sundar
parents: 28441
diff changeset
    14
 *
28441
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
31925
85c87bc2f1f3 8132092: Nashorn copyright has to be updated
sundar
parents: 28441
diff changeset
    18
 *
28441
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    21
 * questions.
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    22
 */
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    23
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    24
/**
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    25
 * JDK-8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    26
 *
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    27
 * @test
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    28
 * @run
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    29
 */
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    30
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    31
function func(arg) {
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    32
  (function() { print(eval('this')); }).call(arg);
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    33
}
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    34
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    35
// primitives
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    36
func(undefined);
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    37
func(null);
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    38
func(34.23);
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    39
func("hello");
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    40
func(false);
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    41
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    42
// script objects
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    43
func(this);
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    44
func({});
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    45
func({ toString: function() { return "foo" } });
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    46
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    47
// java objects
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    48
func(new java.util.Vector());
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    49
var m = new java.util.HashMap();
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    50
m.put("foo", "bar");
beb75d5da248 8068985: Wrong 'this' bound to eval call within a function when caller's 'this' is a Java object
sundar
parents:
diff changeset
    51
func(m);