JDK-8160034.js revision 1754:79a0622e5826
1194676Sthompsa/*
2194676Sthompsa * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3194676Sthompsa * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4194676Sthompsa *
5194676Sthompsa * This code is free software; you can redistribute it and/or modify it
6194676Sthompsa * under the terms of the GNU General Public License version 2 only, as
7194676Sthompsa * published by the Free Software Foundation.
8194676Sthompsa *
9194676Sthompsa * This code is distributed in the hope that it will be useful, but WITHOUT
10194676Sthompsa * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11194676Sthompsa * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12194676Sthompsa * version 2 for more details (a copy is included in the LICENSE file that
13194676Sthompsa * accompanied this code).
14194676Sthompsa *
15194676Sthompsa * You should have received a copy of the GNU General Public License version
16194676Sthompsa * 2 along with this work; if not, write to the Free Software Foundation,
17194676Sthompsa * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18194676Sthompsa *
19194676Sthompsa * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20194676Sthompsa * or visit www.oracle.com if you need additional information or have any
21194676Sthompsa * questions.
22194676Sthompsa */
23194676Sthompsa
24194676Sthompsa/**
25194676Sthompsa * JDK-8160034: The `this` value in the `with` is broken by the repetition of a function call
26194676Sthompsa *
27248236Shselasky * @test
28248236Shselasky * @option --unstable-relink-threshold=4
29248236Shselasky * @run
30203815Swkoszek */
31203815Swkoszek
32248236Shselasky
33248236Shselaskyvar bar = "BAR";
34248236Shselasky
35248236Shselaskyfunction Foo() {
36203815Swkoszek    this.bar = "bar";
37208020Sthompsa    this.baz = "baz";
38208020Sthompsa}
39194676Sthompsa
40194676Sthompsafunction foo_proto_h() {
41194676Sthompsa    print(this.bar);
42194676Sthompsa    delete Foo.prototype._h;
43194676Sthompsa}
44194676Sthompsa
45199055Sthompsafunction foo_proto_e() {
46199055Sthompsa    print(this.baz);
47194676Sthompsa}
48194676Sthompsa
49194676Sthompsafunction _h() {
50195957Salfred    print(this.bar);
51194676Sthompsa    Foo.prototype._h = foo_proto_h;
52194676Sthompsa}
53194676Sthompsa
54194676SthompsaFoo.prototype._e = foo_proto_e;
55194676SthompsaFoo.prototype._h = foo_proto_h;
56194676Sthompsa
57194676Sthompsa
58194676Sthompsavar fn = new Function("with(this) { _h(); _e(); }");
59194676Sthompsa
60194676Sthompsafor (var i = 0; i < 20; i++) {
61194676Sthompsa    fn.call(new Foo());
62194676Sthompsa}
63194676Sthompsa
64194676Sthompsafor (var i = 0; i < 20; i++) {
65194676Sthompsa    foo = new Foo();
66194676Sthompsa    foo['e' + Math.random()] = 1; // force new map
67194676Sthompsa    fn.call(foo);
68194676Sthompsa}
69194676Sthompsa
70194676Sthompsa