Wed, 30 Jan 2013 17:52:54 +0530
8007132: Java objects returned from constructor functions are lost
Reviewed-by: hannesw, lagergren, attila
src/jdk/nashorn/internal/runtime/ScriptFunction.java | file | annotate | diff | comparison | revisions | |
test/script/basic/JDK-8007132.js | file | annotate | diff | comparison | revisions |
1.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunction.java Wed Jan 30 12:26:45 2013 +0100 1.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunction.java Wed Jan 30 17:52:54 2013 +0530 1.3 @@ -892,7 +892,7 @@ 1.4 1.5 @SuppressWarnings("unused") 1.6 private static Object newFilter(final Object result, final Object allocation) { 1.7 - return result instanceof ScriptObject ? result : allocation; 1.8 + return (result instanceof ScriptObject || !JSType.isPrimitive(result))? result : allocation; 1.9 } 1.10 1.11 /**
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/script/basic/JDK-8007132.js Wed Jan 30 17:52:54 2013 +0530 2.3 @@ -0,0 +1,54 @@ 2.4 +/* 2.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 + 2.28 +/** 2.29 + * JDK-8007232: Java objects returned from constructor functions are lost 2.30 + * 2.31 + * @test 2.32 + * @run 2.33 + */ 2.34 + 2.35 +function Func() { 2.36 + return new java.util.HashMap(); 2.37 +} 2.38 + 2.39 +var f = new Func(); 2.40 +if (! (f instanceof java.util.Map)) { 2.41 + fail("instance of java.util.Map expected") 2.42 +} 2.43 + 2.44 +function check(obj) { 2.45 + if (typeof obj != 'object') { 2.46 + fail("expected 'object' but got " + (typeof obj)); 2.47 + } 2.48 +} 2.49 + 2.50 +// check primitive returning constructors 2.51 +check(new (function() { return 22; })); 2.52 +check(new (function() { return false })); 2.53 +check(new (function() { return "hello" })); 2.54 + 2.55 +// check null and undefined returning constructors 2.56 +check(new (function() { return null; })); 2.57 +check(new (function() { return undefined; }));