From 3dd998447a102a32c2131f98f6919b4179c9a166 Mon Sep 17 00:00:00 2001 From: Athijegannathan Sundararajan Date: Thu, 6 Feb 2014 17:44:37 +0530 Subject: [PATCH 1/3] 8033763: Add tests to assert map identity of certain objects Reviewed-by: hannesw, lagergren --- nashorn/make/build.xml | 5 ++ nashorn/make/project.properties | 5 +- .../script/currently-failing/gettersetter.js | 48 +++++++++++++++ nashorn/test/script/maptests/builtins.js | 58 +++++++++++++++++++ nashorn/test/script/maptests/constructor.js | 36 ++++++++++++ nashorn/test/script/maptests/maputil.js | 38 ++++++++++++ nashorn/test/script/maptests/object_create.js | 40 +++++++++++++ .../test/script/maptests/object_literals.js | 46 +++++++++++++++ nashorn/test/script/maptests/point.js | 49 ++++++++++++++++ nashorn/test/script/maptests/property_add.js | 46 +++++++++++++++ .../test/script/maptests/property_delete.js | 48 +++++++++++++++ nashorn/test/script/maptests/proto.js | 56 ++++++++++++++++++ 12 files changed, 473 insertions(+), 2 deletions(-) create mode 100644 nashorn/test/script/currently-failing/gettersetter.js create mode 100644 nashorn/test/script/maptests/builtins.js create mode 100644 nashorn/test/script/maptests/constructor.js create mode 100644 nashorn/test/script/maptests/maputil.js create mode 100644 nashorn/test/script/maptests/object_create.js create mode 100644 nashorn/test/script/maptests/object_literals.js create mode 100644 nashorn/test/script/maptests/point.js create mode 100644 nashorn/test/script/maptests/property_add.js create mode 100644 nashorn/test/script/maptests/property_delete.js create mode 100644 nashorn/test/script/maptests/proto.js diff --git a/nashorn/make/build.xml b/nashorn/make/build.xml index 93342248de5..78a713bfc46 100644 --- a/nashorn/make/build.xml +++ b/nashorn/make/build.xml @@ -282,6 +282,11 @@ grant codeBase "file:/${basedir}/test/script/trusted/*" { permission java.security.AllPermission; }; +grant codeBase "file:/${basedir}/test/script/maptests/*" { + permission java.io.FilePermission "${basedir}/test/script/maptests/*","read"; + permission java.lang.RuntimePermission "nashorn.debugMode"; +}; + grant codeBase "file:/${basedir}/test/script/basic/*" { permission java.io.FilePermission "${basedir}/test/script/-", "read"; permission java.io.FilePermission "$${user.dir}", "read"; diff --git a/nashorn/make/project.properties b/nashorn/make/project.properties index ad36744836b..d51e72e4180 100644 --- a/nashorn/make/project.properties +++ b/nashorn/make/project.properties @@ -115,6 +115,7 @@ run.classpath=\ test.dir=test test.script.dir=test/script test.basic.dir=test/script/basic +test.maptests.dir=test/script/maptests test.error.dir=test/script/error test.sandbox.dir=test/script/sandbox test.trusted.dir=test/script/trusted @@ -125,7 +126,7 @@ testjfx.dir=${test.script.dir}/jfx testmarkdown.dir=${test.script.dir}/markdown test-sys-prop.test.dir=${test.dir} -test-sys-prop.test.js.roots=${test.basic.dir} ${test.error.dir} ${test.sandbox.dir} ${test.trusted.dir} +test-sys-prop.test.js.roots=${test.basic.dir} ${test.maptests.dir} ${test.error.dir} ${test.sandbox.dir} ${test.trusted.dir} test-sys-prop.test262.suite.dir=${test262.suite.dir} test-sys-prop.es5conform.testcases.dir=${test.external.dir}/ES5Conform/TestCases test-sys-prop.test.basic.dir=${test.basic.dir} @@ -278,7 +279,7 @@ run.test.jvmargs.octane.main=${run.test.jvmargs.common} run.test.jvmsecurityargs=-Xverify:all -Djava.security.manager -Djava.security.policy=${basedir}/build/nashorn.policy # VM options for script tests with @fork option -test-sys-prop.test.fork.jvm.options=${run.test.jvmargs.main} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} +test-sys-prop.test.fork.jvm.options=${run.test.jvmargs.main} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -cp ${run.test.classpath} # path of rhino.jar for benchmarks rhino.jar= diff --git a/nashorn/test/script/currently-failing/gettersetter.js b/nashorn/test/script/currently-failing/gettersetter.js new file mode 100644 index 00000000000..88f6949233c --- /dev/null +++ b/nashorn/test/script/currently-failing/gettersetter.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @option -Dnashorn.debug=true + * @fork + */ + +load(__DIR__ + "maputil.js"); + +function Foo() { + return { + get foo() { return 42; }, + set foo(x) {} + } +} + +var obj1 = Foo(); +var obj2 = Foo(); + +assertSameMap(obj1, obj2, "Object literals before change"); + +Object.defineProperty(obj2, "foo", { get: function() { return 'hello' } }); +assertSameMap(obj1, obj2); + +Object.defineProperty(obj2, "foo", { set: function(x) { print(x) } }); +assertSameMap(obj1, obj2); diff --git a/nashorn/test/script/maptests/builtins.js b/nashorn/test/script/maptests/builtins.js new file mode 100644 index 00000000000..4de2ec9a8da --- /dev/null +++ b/nashorn/test/script/maptests/builtins.js @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @option -Dnashorn.debug=true + * @fork + */ + +load(__DIR__ + "maputil.js"); + +// check that builtin objects share property map + +assertSameMap(new Boolean(true), new Boolean(false)); +assertSameMap(new Number(3), new Number(Math.PI)); +assertSameMap(new String('hello'), new String('world')); +assertSameMap(new Object(), new Object()); +assertSameMap(/hello/, /world/); +// try w/without regexp flags +assertSameMap(/hello/i, /world/g); +assertSameMap(new Date(), new Date()); +assertSameMap(new Date(2000, 1, 1), new Date(1972, 5, 6)); +assertSameMap(Function(), Function()); +assertSameMap(Function("x", "return x"), Function("x", "return x*x")); +assertSameMap(new Error(), new Error()); +assertSameMap(new Error('foo'), new Error('bar')); +assertSameMap(new EvalError(), new EvalError()); +assertSameMap(new EvalError('foo'), new EvalError('bar')); +assertSameMap(new RangeError(), new RangeError()); +assertSameMap(new RangeError('foo'), new RangeError('bar')); +assertSameMap(new ReferenceError(), new ReferenceError()); +assertSameMap(new ReferenceError('foo'), new ReferenceError('bar')); +assertSameMap(new SyntaxError(), new SyntaxError()); +assertSameMap(new SyntaxError('foo'), new SyntaxError('bar')); +assertSameMap(new TypeError(), new TypeError()); +assertSameMap(new TypeError('foo'), new TypeError('bar')); +assertSameMap(new URIError(), new URIError()); +assertSameMap(new URIError('foo'), new URIError('bar')); diff --git a/nashorn/test/script/maptests/constructor.js b/nashorn/test/script/maptests/constructor.js new file mode 100644 index 00000000000..5722a3c15b9 --- /dev/null +++ b/nashorn/test/script/maptests/constructor.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @option -Dnashorn.debug=true + * @fork + */ + +load(__DIR__ + "point.js"); + +// use constructor defined in a different script file +// These objects should share the map +assertSameMap(new Point(2, 3), new Point(43, 23)); +assertSameMap(new Point(), new Point()); +assertSameMap(new Point(), new Point(3, 1)); diff --git a/nashorn/test/script/maptests/maputil.js b/nashorn/test/script/maptests/maputil.js new file mode 100644 index 00000000000..aa85d7f1220 --- /dev/null +++ b/nashorn/test/script/maptests/maputil.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @subtest + */ + +function assertSameMap(obj1, obj2, msg) { + if (! Debug.identical(Debug.map(obj1), Debug.map(obj2))) { + fail(obj1.constructor + " instances don't share map"); + } +} + +function assertNotSameMap(obj1, obj2, msg) { + if (Debug.identical(Debug.map(obj1), Debug.map(obj2))) { + fail(obj1.constructor + " and " + obj2.constructor + " instances share map"); + } +} diff --git a/nashorn/test/script/maptests/object_create.js b/nashorn/test/script/maptests/object_create.js new file mode 100644 index 00000000000..1b1bd604c85 --- /dev/null +++ b/nashorn/test/script/maptests/object_create.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @option -Dnashorn.debug=true + * @fork + */ + +load(__DIR__ + "maputil.js"); + +// Objects created by Object.create +var obj1 = Object.create(Object.prototype); +var obj2 = Object.create(Object.prototype); +assertSameMap(obj1, obj2); + +var proto = { foo: 233 }; +obj1 = Object.create(proto); +obj2 = Object.create(proto); +assertSameMap(obj1, obj2); diff --git a/nashorn/test/script/maptests/object_literals.js b/nashorn/test/script/maptests/object_literals.js new file mode 100644 index 00000000000..c73d80140c7 --- /dev/null +++ b/nashorn/test/script/maptests/object_literals.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @option -Dnashorn.debug=true + * @fork + */ + +load(__DIR__ + "maputil.js"); + +// Object literals created at the same callsite +function makeObject() { + return { foo: 34 } +} +assertSameMap(makeObject(), makeObject()); + +function makeObject2() { + return { foo: 42, bar: 'hello' } +} +assertSameMap(makeObject2(), makeObject2()); + +// Object literals created at different callsites +assertSameMap({}, {}); +assertSameMap({foo: 4}, {foo: 'hello'}); +assertSameMap({foo: 34, bar: 'fdgd'}, {foo: 'world', bar: 54}); diff --git a/nashorn/test/script/maptests/point.js b/nashorn/test/script/maptests/point.js new file mode 100644 index 00000000000..38b8fa2513a --- /dev/null +++ b/nashorn/test/script/maptests/point.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +/** + * @subtest + */ + +function Point(x, y) { + this.x =x; this.y =y; +} + +Point.prototype.toString = function() { + return "(" + this.x + "," + this.y + ")"; +} + +Point.prototype.modulus = function() { + return Math.sqrt(this.x*this.x + this.y*this.y); +} + +Point.prototype.argument = function() { + return Math.atan2(this.y, this.x); +} + +load(__DIR__ + "maputil.js"); + +assertSameMap(new Point(2, 3), new Point(43, 23)); +assertSameMap(new Point(), new Point()); +assertSameMap(new Point(), new Point(3, 1)); diff --git a/nashorn/test/script/maptests/property_add.js b/nashorn/test/script/maptests/property_add.js new file mode 100644 index 00000000000..2026455459d --- /dev/null +++ b/nashorn/test/script/maptests/property_add.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @option -Dnashorn.debug=true + * @fork + */ + +load(__DIR__ + "maputil.js"); + +function Foo() {} + +var obj1 = new Foo(); +var obj2 = new Foo(); + +assertSameMap(obj1, obj2); + +// property addition at same callsite +function addX(obj, val) { + obj.x = val; +} +addX(obj1, 3); +addX(obj2, 'hello'); + +assertSameMap(obj1, obj2); diff --git a/nashorn/test/script/maptests/property_delete.js b/nashorn/test/script/maptests/property_delete.js new file mode 100644 index 00000000000..e2824dd6315 --- /dev/null +++ b/nashorn/test/script/maptests/property_delete.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @option -Dnashorn.debug=true + * @fork + */ + +load(__DIR__ + "maputil.js"); + +function Foo() { + this.x = 33; +} + +var obj1 = new Foo(); +var obj2 = new Foo(); + +assertSameMap(obj1, obj2); + +// property deletion at same callsite +function deleteX(obj) { + delete obj.x; +} +deleteX(obj1); +deleteX(obj2); + +assertSameMap(obj1, obj2); diff --git a/nashorn/test/script/maptests/proto.js b/nashorn/test/script/maptests/proto.js new file mode 100644 index 00000000000..afb59509a0a --- /dev/null +++ b/nashorn/test/script/maptests/proto.js @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @option -Dnashorn.debug=true + * @fork + */ + +load(__DIR__ + "maputil.js"); + +// add/delete property to proto (direct/indirect) should +// not affect the property map of the objects + +var proto2 = { foo: 334 } +var proto = Object.create(proto2); +proto.bar = "hello"; + +var obj1 = Object.create(proto); +var obj2 = Object.create(proto); + +assertSameMap(obj1, obj2); + +proto.newX = 'world'; +assertSameMap(obj1, obj2); + +delete proto.newX; +assertSameMap(obj1, obj2); + +proto2.newX = "foo"; +assertSameMap(obj1, obj2); + +delete proto2.newX; +assertSameMap(obj1, obj2); + + From 118cf2ba60204d7870f5d4e42d3623670ede714a Mon Sep 17 00:00:00 2001 From: Athijegannathan Sundararajan Date: Fri, 7 Feb 2014 18:47:46 +0530 Subject: [PATCH 2/3] 8033924: Default permissions are not given for eval code Reviewed-by: lagergren, jlaskey --- .../jdk/nashorn/internal/runtime/Context.java | 2 +- .../internal/runtime/ScriptLoader.java | 5 +- nashorn/test/script/sandbox/safeprops.js | 65 +++++++++++++++++++ .../api/scripting/ScriptEngineTest.java | 41 ++++++++++++ 4 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 nashorn/test/script/sandbox/safeprops.js diff --git a/nashorn/src/jdk/nashorn/internal/runtime/Context.java b/nashorn/src/jdk/nashorn/internal/runtime/Context.java index e15ddd2c8fb..3e6a1488fa3 100644 --- a/nashorn/src/jdk/nashorn/internal/runtime/Context.java +++ b/nashorn/src/jdk/nashorn/internal/runtime/Context.java @@ -956,7 +956,7 @@ public final class Context { final URL url = source.getURL(); final ScriptLoader loader = env._loader_per_compile ? createNewLoader() : scriptLoader; - final CodeSource cs = url == null ? null : new CodeSource(url, (CodeSigner[])null); + final CodeSource cs = new CodeSource(url, (CodeSigner[])null); final CodeInstaller installer = new ContextCodeInstaller(this, loader, cs); final Compiler compiler = new Compiler(installer, strict); diff --git a/nashorn/src/jdk/nashorn/internal/runtime/ScriptLoader.java b/nashorn/src/jdk/nashorn/internal/runtime/ScriptLoader.java index 78185b1c416..52c98d40734 100644 --- a/nashorn/src/jdk/nashorn/internal/runtime/ScriptLoader.java +++ b/nashorn/src/jdk/nashorn/internal/runtime/ScriptLoader.java @@ -70,9 +70,8 @@ final class ScriptLoader extends NashornLoader { * @return Installed class. */ synchronized Class installClass(final String name, final byte[] data, final CodeSource cs) { - if (cs == null) { - return defineClass(name, data, 0, data.length, new ProtectionDomain(null, getPermissions(null))); - } + // null check + cs.getClass(); return defineClass(name, data, 0, data.length, cs); } } diff --git a/nashorn/test/script/sandbox/safeprops.js b/nashorn/test/script/sandbox/safeprops.js new file mode 100644 index 00000000000..dc12e74f9be --- /dev/null +++ b/nashorn/test/script/sandbox/safeprops.js @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Try to access System properties safe to read for any code. + * No security exception expected. + * + * @test + * @security + * @run + * @bug 8033924: Default permissions are not given for eval code + */ + +var propNames = [ + "java.version", + "java.vendor", + "java.vendor.url", + "java.class.version", + "os.name", + "os.version", + "os.arch", + "file.separator", + "path.separator", + "line.separator", + "java.specification.version", + "java.specification.vendor", + "java.specification.name", + "java.vm.specification.version", + "java.vm.specification.vendor", + "java.vm.specification.name", + "java.vm.version", + "java.vm.vendor", + "java.vm.name" +]; + +// no security exception expected +for (var p in propNames) { + java.lang.System.getProperty(propNames[p]); +} + +// no security exception expected +for (var p in propNames) { + var name = propNames[p]; + eval('java.lang.System.getProperty(name)'); +} diff --git a/nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java b/nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java index df8696d8e4c..5219914519f 100644 --- a/nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java +++ b/nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java @@ -560,6 +560,47 @@ public class ScriptEngineTest { assertTrue(reached[0]); } + // properties that can be read by any code + private static String[] propNames = { + "java.version", + "java.vendor", + "java.vendor.url", + "java.class.version", + "os.name", + "os.version", + "os.arch", + "file.separator", + "path.separator", + "line.separator", + "java.specification.version", + "java.specification.vendor", + "java.specification.name", + "java.vm.specification.version", + "java.vm.specification.vendor", + "java.vm.specification.name", + "java.vm.version", + "java.vm.vendor", + "java.vm.name" + }; + + // @bug 8033924: Default permissions are not given for eval code + @Test + public void checkPropertyReadPermissions() throws ScriptException { + final ScriptEngineManager m = new ScriptEngineManager(); + final ScriptEngine e = m.getEngineByName("nashorn"); + + for (final String name : propNames) { + checkProperty(e, name); + } + } + + private static void checkProperty(final ScriptEngine e, final String name) + throws ScriptException { + String value = System.getProperty(name); + e.put("name", name); + assertEquals(value, e.eval("java.lang.System.getProperty(name)")); + } + private static final String LINE_SEPARATOR = System.getProperty("line.separator"); // Returns String that would be the result of calling PrintWriter.println From 615623c47378996b7750496be2c2e1190c92d245 Mon Sep 17 00:00:00 2001 From: Matherey Nunez Date: Tue, 11 Feb 2014 12:05:22 +0100 Subject: [PATCH 3/3] 8033231: test fails with java.lang.UnsatisfiedLinkError Reviewed-by: attila, sundar --- nashorn/test/script/basic/JDK-8026161.js | 6 ++-- .../test/script/basic/JDK-8026161.js.EXPECTED | 4 +-- .../models/IntFloatOverloadSelection.java | 36 +++++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 nashorn/test/src/jdk/nashorn/test/models/IntFloatOverloadSelection.java diff --git a/nashorn/test/script/basic/JDK-8026161.js b/nashorn/test/script/basic/JDK-8026161.js index 49f888b71ee..e3e88486402 100644 --- a/nashorn/test/script/basic/JDK-8026161.js +++ b/nashorn/test/script/basic/JDK-8026161.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,5 +28,5 @@ * @run */ -print(new java.awt.Color(1, 1, 1)) // creates Color[r=1,g=1,b=1] -print(new java.awt.Color(1.0, 1.0, 1.0)) // Color[r=255,g=255,b=255] +print(Java.type("jdk.nashorn.test.models.IntFloatOverloadSelection").overloadedMethod(1)) +print(Java.type("jdk.nashorn.test.models.IntFloatOverloadSelection").overloadedMethod(1.0)) diff --git a/nashorn/test/script/basic/JDK-8026161.js.EXPECTED b/nashorn/test/script/basic/JDK-8026161.js.EXPECTED index c7b00b083f1..ac032cff452 100644 --- a/nashorn/test/script/basic/JDK-8026161.js.EXPECTED +++ b/nashorn/test/script/basic/JDK-8026161.js.EXPECTED @@ -1,2 +1,2 @@ -java.awt.Color[r=1,g=1,b=1] -java.awt.Color[r=255,g=255,b=255] +int +float diff --git a/nashorn/test/src/jdk/nashorn/test/models/IntFloatOverloadSelection.java b/nashorn/test/src/jdk/nashorn/test/models/IntFloatOverloadSelection.java new file mode 100644 index 00000000000..947896b362a --- /dev/null +++ b/nashorn/test/src/jdk/nashorn/test/models/IntFloatOverloadSelection.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.nashorn.test.models; + +public class IntFloatOverloadSelection { + + public static String overloadedMethod(int i) { + return "int"; + } + + public static String overloadedMethod(float f) { + return "float"; + } +}