JDK-8029667.js revision 702:18eccb9656e0
11592Srgrimes/*
21592Srgrimes * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
31592Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41592Srgrimes *
51592Srgrimes * This code is free software; you can redistribute it and/or modify it
61592Srgrimes * under the terms of the GNU General Public License version 2 only, as
71592Srgrimes * published by the Free Software Foundation.
81592Srgrimes *
91592Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT
101592Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
111592Srgrimes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
121592Srgrimes * version 2 for more details (a copy is included in the LICENSE file that
131592Srgrimes * accompanied this code).
141592Srgrimes *
151592Srgrimes * You should have received a copy of the GNU General Public License version
161592Srgrimes * 2 along with this work; if not, write to the Free Software Foundation,
171592Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
181592Srgrimes *
191592Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
201592Srgrimes * or visit www.oracle.com if you need additional information or have any
211592Srgrimes * questions.
221592Srgrimes */
231592Srgrimes
241592Srgrimes/**
251592Srgrimes * JDK-8029667: Prototype linking is incorrect
261592Srgrimes *
271592Srgrimes * @test
281592Srgrimes * @run
291592Srgrimes */
301592Srgrimes
311592Srgrimesfunction f(x) {
321592Srgrimes  return (function inner() {
331592Srgrimes      var y; (function dummy() { return y })() // force own scope for the inner function
341592Srgrimes      with({}) { // 'with' block turns off fast scopes
351592Srgrimes          return x
361592Srgrimes      }
371592Srgrimes  })();
381592Srgrimes}
391592Srgrimesprint(f(1));
401592Srgrimesprint(f(2));
411592Srgrimes
421592Srgrimesfunction g(x) {
431592Srgrimes  (function inner() {
441592Srgrimes      var y; (function dummy() { return y })() // force own scope for the inner function
451592Srgrimes      with({}) { // 'with' block turns off fast scopes
461592Srgrimes          // Test setter as well as getter
471592Srgrimes          x = x + 2;
481592Srgrimes      }
491592Srgrimes  })();
501592Srgrimes  print(x);
511592Srgrimes}
521592Srgrimes
531592Srgrimesg(1);
541592Srgrimesg(2);
551592Srgrimes
561592Srgrimesvar withScopes = [{ func: function() { print("called 1");} }, { func: function() { print("called 2");} }];
571592Srgrimes
581592Srgrimesfor(var i in withScopes) {
591592Srgrimes    with (withScopes[i]) {
601592Srgrimes        var main = function() {
611592Srgrimes            var frame; // <---- this local variable caused scope to be not set properly prior to fix
621592Srgrimes
631592Srgrimes            function callFunc() {
641592Srgrimes                frame = func();
651592Srgrimes            }
661592Srgrimes
671592Srgrimes            callFunc();
681592Srgrimes        }
691592Srgrimes    }
701592Srgrimes    main();
711592Srgrimes}
721592Srgrimes
731592Srgrimesfor(var i in withScopes) {
741592Srgrimes    with (withScopes[i]) {
751592Srgrimes        var main = function() {
761592Srgrimes            var frame; // <---- this local variable caused scope to be not set properly prior to fix
771592Srgrimes
781592Srgrimes            function callFunc() {
791592Srgrimes                frame = func = i;
801592Srgrimes            }
811592Srgrimes
821592Srgrimes            callFunc();
831592Srgrimes        }
841592Srgrimes    }
851592Srgrimes    main();
861592Srgrimes}
871592Srgrimes
881592Srgrimesprint(withScopes[0].func);
891592Srgrimesprint(withScopes[1].func);
901592Srgrimes
911592Srgrimes
921592Srgrimes