JDK-8160034.js revision 1754:79a0622e5826
1139804Simp/* 2177957Sattilio * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3177957Sattilio * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 424269Speter * 524269Speter * This code is free software; you can redistribute it and/or modify it 624269Speter * under the terms of the GNU General Public License version 2 only, as 724269Speter * published by the Free Software Foundation. 824269Speter * 9177957Sattilio * This code is distributed in the hope that it will be useful, but WITHOUT 10177957Sattilio * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11177957Sattilio * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1224269Speter * version 2 for more details (a copy is included in the LICENSE file that 13177957Sattilio * accompanied this code). 1424269Speter * 1524269Speter * You should have received a copy of the GNU General Public License version 16177957Sattilio * 2 along with this work; if not, write to the Free Software Foundation, 17177957Sattilio * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18177957Sattilio * 19177957Sattilio * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20177957Sattilio * or visit www.oracle.com if you need additional information or have any 21177957Sattilio * questions. 22177957Sattilio */ 23177957Sattilio 2424269Speter/** 25177957Sattilio * JDK-8160034: The `this` value in the `with` is broken by the repetition of a function call 26177957Sattilio * 2724269Speter * @test 2824269Speter * @option --unstable-relink-threshold=4 29177957Sattilio * @run 30177957Sattilio */ 31116182Sobrien 32116182Sobrien 33116182Sobrienvar bar = "BAR"; 3424269Speter 3584812Sjhbfunction Foo() { 3624269Speter this.bar = "bar"; 37177957Sattilio this.baz = "baz"; 38102477Sbde} 3967353Sjhb 40102477Sbdefunction foo_proto_h() { 41177957Sattilio print(this.bar); 42148668Sjeff delete Foo.prototype._h; 43148668Sjeff} 44148668Sjeff 45177957Sattiliofunction foo_proto_e() { 4624269Speter print(this.baz); 47177957Sattilio} 48176014Sattilio 49161322Sjhbfunction _h() { 50161322Sjhb print(this.bar); 51161322Sjhb Foo.prototype._h = foo_proto_h; 52161322Sjhb} 53177957Sattilio 54177957SattilioFoo.prototype._e = foo_proto_e; 55177957SattilioFoo.prototype._h = foo_proto_h; 56177957Sattilio 57177957Sattilio 58177957Sattiliovar fn = new Function("with(this) { _h(); _e(); }"); 59177957Sattilio 60177957Sattiliofor (var i = 0; i < 20; i++) { 61177957Sattilio fn.call(new Foo()); 62177957Sattilio} 63177957Sattilio 64177957Sattiliofor (var i = 0; i < 20; i++) { 65177957Sattilio foo = new Foo(); 66177957Sattilio foo['e' + Math.random()] = 1; // force new map 67177957Sattilio fn.call(foo); 68177957Sattilio} 69177957Sattilio 70177957Sattilio