JDK-8015959.js revision 375:51a5ee93d6bc
1236834Sadrian/* 2236834Sadrian * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3236834Sadrian * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4236834Sadrian * 5236834Sadrian * This code is free software; you can redistribute it and/or modify it 6236834Sadrian * under the terms of the GNU General Public License version 2 only, as 7236834Sadrian * published by the Free Software Foundation. 8236834Sadrian * 9236834Sadrian * This code is distributed in the hope that it will be useful, but WITHOUT 10236834Sadrian * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11236834Sadrian * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12236834Sadrian * version 2 for more details (a copy is included in the LICENSE file that 13236834Sadrian * accompanied this code). 14236834Sadrian * 15236834Sadrian * You should have received a copy of the GNU General Public License version 16236834Sadrian * 2 along with this work; if not, write to the Free Software Foundation, 17236834Sadrian * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18236834Sadrian * 19236834Sadrian * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20236834Sadrian * or visit www.oracle.com if you need additional information or have any 21236834Sadrian * questions. 22236834Sadrian */ 23236834Sadrian 24236834Sadrian/** 25236834Sadrian * JDK-8015959: Can't call foreign constructor 26236834Sadrian * 27236834Sadrian * @test 28236834Sadrian * @run 29236834Sadrian */ 30236834Sadrian 31236834Sadrianfunction check(global) { 32236834Sadrian var obj = new global.Point(344, 12); 33236834Sadrian print("obj.x " + obj.x); 34236834Sadrian print("obj.y " + obj.y); 35236834Sadrian print("obj instanceof global.Point? " + (obj instanceof global.Point)) 36236834Sadrian 37236834Sadrian var P = global.Point; 38236834Sadrian var p = new P(343, 54); 39236834Sadrian print("p.x " + p.x); 40236834Sadrian print("p.y " + p.y); 41236834Sadrian print("p instanceof P? " + (p instanceof P)) 42236834Sadrian} 43236834Sadrian 44236834Sadrianprint("check with loadWithNewGlobal"); 45236834Sadriancheck(loadWithNewGlobal({ 46236834Sadrian name: "myscript", 47236834Sadrian script: "function Point(x, y) { this.x = x; this.y = y }; this" 48236834Sadrian})); 49236834Sadrian 50236834Sadrianprint("check with script engine"); 51236834Sadrianvar m = new javax.script.ScriptEngineManager(); 52236834Sadrianvar e = m.getEngineByName('nashorn'); 53236834Sadriancheck(e.eval("function Point(x, y) { this.x = x; this.y = y }; this")); 54236834Sadrian 55236834Sadrian