forin2.js revision 877:cf4d2252d444
175584Sru/* 275584Sru * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 375584Sru * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 475584Sru * 5114402Sru * This code is free software; you can redistribute it and/or modify it 6114402Sru * under the terms of the GNU General Public License version 2 only, as 7114402Sru * published by the Free Software Foundation. 8114402Sru * 9114402Sru * This code is distributed in the hope that it will be useful, but WITHOUT 10114402Sru * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11114402Sru * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12114402Sru * version 2 for more details (a copy is included in the LICENSE file that 13114402Sru * accompanied this code). 14114402Sru * 15114402Sru * You should have received a copy of the GNU General Public License version 16114402Sru * 2 along with this work; if not, write to the Free Software Foundation, 17114402Sru * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18114402Sru * 19114402Sru * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20114402Sru * or visit www.oracle.com if you need additional information or have any 21114402Sru * questions. 22114402Sru */ 23114402Sru 24114402Sru/** 25114402Sru * Mostly for-in iterations through esoteric collections 26114402Sru * 27114402Sru * @test 28114402Sru * @run 29114402Sru */ 30114402Sru 31114402Srufor (y in {}) { 32114402Sru y = 2; 33114402Sru} 34114402Sru 35114402Srutry { 36114402Sru null['foo']; 37114402Sru print("error 1"); 3875584Sru} catch(e) { 3975584Sru if ((e instanceof TypeError) !== true) { 4075584Sru print(e); 4175584Sru } 4275584Sru} 4375584Sru 4475584Srutry { 4575584Sru with(null) x = 2; 4675584Sru print("error 2"); 4775584Sru} catch(e) { 4875584Sru if((e instanceof TypeError) !== true) { 4975584Sru print(e); 5075584Sru } 5175584Sru} 5275584Sru 5375584Srutry { 5475584Sru for (var y in null) { 5575584Sru y = 2; 5675584Sru } 5775584Sru print("this is ok 1"); 5875584Sru} catch(e) { 5975584Sru if ((e instanceof TypeError) !== true) { 6075584Sru print(e); 6175584Sru } 6275584Sru} 6375584Sru 6475584Sru// CHECK#4 6575584Srutry { 6675584Sru for (var z in 'bbb'.match(/aaa/)) { 6775584Sru z = 2; 6875584Sru } 6975584Sru print("this is ok 2"); 7075584Sru} catch(e) { 7175584Sru if((e instanceof TypeError) !== true) { 7275584Sru print(e); 7375584Sru } 7475584Sru} 7575584Sru 7675584Sru 7775584Srutry { 7875584Sru undefined['foo']; 7975584Sru print("error 5"); 8075584Sru} catch(e) { 8175584Sru if ((e instanceof TypeError) !== true) { 8275584Sru print(e); 8375584Sru } 8475584Sru} 8575584Sru 8675584Srutry { 8775584Sru with(undefined) x = 2; 8875584Sru print("error 6"); 8975584Sru} catch (e) { 9075584Sru if ((e instanceof TypeError) !== true) { 9175584Sru print(e); 9275584Sru } 9375584Sru} 9475584Sru 9575584Sru// CHECK#3 9675584Srutry { 9775584Sru for (var y in undefined) { 9875584Sru y = 2; 9975584Sru } 10075584Sru print("this is ok 3"); 10175584Sru} catch (e) { 10275584Sru if ((e instanceof TypeError) !== true) { 10375584Sru print(e); 10475584Sru } 10575584Sru} 10675584Sru 10775584Srutry { 10875584Sru for (var z in this.foo) { 10975584Sru z = 2; 11075584Sru } 11175584Sru print("this is ok 4"); 11275584Sru} catch (e) { 11375584Sru if ((e instanceof TypeError) !== true) { 11475584Sru print(e); 11575584Sru } 11675584Sru} 11775584Sru