test/script/basic/JDK-8068985.js

Tue, 28 Jul 2015 14:52:34 +0530

author
sundar
date
Tue, 28 Jul 2015 14:52:34 +0530
changeset 1482
58791cd01bc9
parent 1351
1088408b1c02
permissions
-rw-r--r--

8132092: Nashorn copyright has to be updated
Reviewed-by: jlaskey, hannesw, mhaupt

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

mercurial