newexpr.js revision 6:5a1b0714df0e
1171425Sroberto/* 2171425Sroberto * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3171425Sroberto * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4171425Sroberto * 5171425Sroberto * This code is free software; you can redistribute it and/or modify it 6171425Sroberto * under the terms of the GNU General Public License version 2 only, as 7171425Sroberto * published by the Free Software Foundation. 8171425Sroberto * 9171425Sroberto * This code is distributed in the hope that it will be useful, but WITHOUT 10171425Sroberto * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11171425Sroberto * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12171425Sroberto * version 2 for more details (a copy is included in the LICENSE file that 13171425Sroberto * accompanied this code). 14171425Sroberto * 15171425Sroberto * You should have received a copy of the GNU General Public License version 16171425Sroberto * 2 along with this work; if not, write to the Free Software Foundation, 17171425Sroberto * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18171425Sroberto * 19171425Sroberto * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20171425Sroberto * or visit www.oracle.com if you need additional information or have any 21171425Sroberto * questions. 22171425Sroberto */ 23171425Sroberto 24171425Sroberto/** 25171425Sroberto * Various kinds of "new" usage. 26171425Sroberto * 27171425Sroberto * @test 28171425Sroberto * @run 29171425Sroberto */ 30171425Sroberto 31171425Srobertovar File = java.io.File; 32171425Srobertoprint(new File(".").isDirectory()); 33171425Sroberto 34171425Srobertovar obj = { 35171425Sroberto foo : function (x) { 36171425Sroberto this.bar = x; 37171425Sroberto } 38171425Sroberto} 39171425Sroberto 40171425Srobertoprint(new obj.foo(23).bar); 41171425Sroberto 42171425Srobertofunction func() { 43171425Sroberto this.foo = 42; 44171425Sroberto} 45171425Sroberto 46171425Srobertoprint(new func().foo); 47171425Sroberto 48171425Srobertoprint ((new function() { this.x = "hello" }).x); 49171425Sroberto 50171425Srobertovar abc = { 51171425Sroberto bar: function() { 52171425Sroberto return { x : "hello world" }; 53171425Sroberto } 54171425Sroberto}; 55171425Sroberto 56171425Srobertoprint(new abc.bar().x); 57171425Sroberto 58171425Srobertofunction func2() { 59171425Sroberto return { 60171425Sroberto foo: function() { 61171425Sroberto print("foo"); 62171425Sroberto } 63171425Sroberto }; 64171425Sroberto}; 65171425Sroberto 66171425Srobertoprint(new func2().foo()); 67171425Sroberto