JDK-8160034.js revision 1754:79a0622e5826
1/*
2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/**
25 * JDK-8160034: The `this` value in the `with` is broken by the repetition of a function call
26 *
27 * @test
28 * @option --unstable-relink-threshold=4
29 * @run
30 */
31
32
33var bar = "BAR";
34
35function Foo() {
36    this.bar = "bar";
37    this.baz = "baz";
38}
39
40function foo_proto_h() {
41    print(this.bar);
42    delete Foo.prototype._h;
43}
44
45function foo_proto_e() {
46    print(this.baz);
47}
48
49function _h() {
50    print(this.bar);
51    Foo.prototype._h = foo_proto_h;
52}
53
54Foo.prototype._e = foo_proto_e;
55Foo.prototype._h = foo_proto_h;
56
57
58var fn = new Function("with(this) { _h(); _e(); }");
59
60for (var i = 0; i < 20; i++) {
61    fn.call(new Foo());
62}
63
64for (var i = 0; i < 20; i++) {
65    foo = new Foo();
66    foo['e' + Math.random()] = 1; // force new map
67    fn.call(foo);
68}
69
70