mirror of
https://github.com/openjdk/jdk.git
synced 2026-07-17 14:38:55 +00:00
Merge
This commit is contained in:
commit
752a14ca48
File diff suppressed because it is too large
Load Diff
@ -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";
|
||||
|
||||
@ -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=
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
|
||||
package jdk.nashorn.api.scripting;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.AccessControlContext;
|
||||
import java.security.AccessController;
|
||||
import java.security.Permissions;
|
||||
@ -41,6 +42,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import javax.script.Bindings;
|
||||
import jdk.nashorn.internal.runtime.arrays.ArrayData;
|
||||
import jdk.nashorn.internal.runtime.ConsString;
|
||||
import jdk.nashorn.internal.runtime.Context;
|
||||
import jdk.nashorn.internal.runtime.GlobalObject;
|
||||
@ -259,6 +261,22 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Nashorn extension: setIndexedPropertiesToExternalArrayData.
|
||||
* set indexed properties be exposed from a given nio ByteBuffer.
|
||||
*
|
||||
* @param buf external buffer - should be a nio ByteBuffer
|
||||
*/
|
||||
public void setIndexedPropertiesToExternalArrayData(final ByteBuffer buf) {
|
||||
inGlobal(new Callable<Void>() {
|
||||
@Override public Void call() {
|
||||
sobj.setArray(ArrayData.allocate(buf));
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isInstance(final Object obj) {
|
||||
if (! (obj instanceof ScriptObjectMirror)) {
|
||||
|
||||
@ -31,6 +31,7 @@ import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@ -58,6 +59,7 @@ import jdk.nashorn.internal.runtime.Property;
|
||||
import jdk.nashorn.internal.runtime.PropertyMap;
|
||||
import jdk.nashorn.internal.runtime.ScriptObject;
|
||||
import jdk.nashorn.internal.runtime.ScriptRuntime;
|
||||
import jdk.nashorn.internal.runtime.arrays.ArrayData;
|
||||
import jdk.nashorn.internal.runtime.linker.Bootstrap;
|
||||
import jdk.nashorn.internal.runtime.linker.InvokeByName;
|
||||
import jdk.nashorn.internal.runtime.linker.NashornBeansLinker;
|
||||
@ -100,6 +102,27 @@ public final class NativeObject {
|
||||
return typeError("not.an.object", ScriptRuntime.safeToString(obj));
|
||||
}
|
||||
|
||||
/**
|
||||
* Nashorn extension: setIndexedPropertiesToExternalArrayData
|
||||
*
|
||||
* @param self self reference
|
||||
* @param obj object whose index properties are backed by buffer
|
||||
* @param buf external buffer - should be a nio ByteBuffer
|
||||
* @return the 'obj' object
|
||||
*/
|
||||
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
|
||||
public static Object setIndexedPropertiesToExternalArrayData(final Object self, final Object obj, final Object buf) {
|
||||
Global.checkObject(obj);
|
||||
final ScriptObject sobj = (ScriptObject)obj;
|
||||
if (buf instanceof ByteBuffer) {
|
||||
sobj.setArray(ArrayData.allocate((ByteBuffer)buf));
|
||||
} else {
|
||||
throw typeError("not.a.bytebuffer", "setIndexedPropertiesToExternalArrayData's buf argument");
|
||||
}
|
||||
return sobj;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ECMA 15.2.3.2 Object.getPrototypeOf ( O )
|
||||
*
|
||||
|
||||
@ -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<ScriptEnvironment> installer = new ContextCodeInstaller(this, loader, cs);
|
||||
|
||||
final Compiler compiler = new Compiler(installer, strict);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
package jdk.nashorn.internal.runtime.arrays;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.nio.ByteBuffer;
|
||||
import jdk.nashorn.internal.runtime.GlobalObject;
|
||||
import jdk.nashorn.internal.runtime.JSType;
|
||||
import jdk.nashorn.internal.runtime.PropertyDescriptor;
|
||||
@ -143,6 +144,16 @@ public abstract class ArrayData {
|
||||
return new ObjectArrayData(array, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate an ArrayData wrapping a given nio ByteBuffer
|
||||
*
|
||||
* @param buf the nio ByteBuffer to wrap
|
||||
* @return the ArrayData
|
||||
*/
|
||||
public static ArrayData allocate(final ByteBuffer buf) {
|
||||
return new ByteBufferArrayData((ByteBuffer)buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a freeze filter to an ArrayData.
|
||||
*
|
||||
|
||||
@ -0,0 +1,203 @@
|
||||
/*
|
||||
* 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.internal.runtime.arrays;
|
||||
|
||||
import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import jdk.nashorn.internal.runtime.GlobalObject;
|
||||
import jdk.nashorn.internal.runtime.PropertyDescriptor;
|
||||
import jdk.nashorn.internal.runtime.ScriptRuntime;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ArrayData} that wraps a nio ByteBuffer
|
||||
*/
|
||||
final class ByteBufferArrayData extends ArrayData {
|
||||
private final ByteBuffer buf;
|
||||
|
||||
ByteBufferArrayData(final int length) {
|
||||
super(length);
|
||||
this.buf = ByteBuffer.allocateDirect(length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param buf ByteBuffer to create array data with.
|
||||
*/
|
||||
ByteBufferArrayData(final ByteBuffer buf) {
|
||||
super(buf.capacity());
|
||||
this.buf = buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns property descriptor for element at a given index
|
||||
*
|
||||
* @param global the global object
|
||||
* @param index the index
|
||||
*
|
||||
* @return property descriptor for element
|
||||
*/
|
||||
public PropertyDescriptor getDescriptor(final GlobalObject global, final int index) {
|
||||
// make the index properties not configurable
|
||||
return global.newDataDescriptor(getObject(index), false, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayData copy() {
|
||||
throw unsupported("copy");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] asObjectArray() {
|
||||
throw unsupported("asObjectArray");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLength(final long length) {
|
||||
throw new UnsupportedOperationException("setLength");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shiftLeft(int by) {
|
||||
throw unsupported("shiftLeft");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayData shiftRight(int by) {
|
||||
throw unsupported("shiftRight");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayData ensure(long safeIndex) {
|
||||
if (safeIndex < buf.capacity()) {
|
||||
return this;
|
||||
}
|
||||
|
||||
throw unsupported("ensure");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayData shrink(long newLength) {
|
||||
throw unsupported("shrink");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayData set(int index, Object value, boolean strict) {
|
||||
if (value instanceof Number) {
|
||||
buf.put(index, ((Number)value).byteValue());
|
||||
return this;
|
||||
}
|
||||
|
||||
throw typeError("not.a.number", ScriptRuntime.safeToString(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayData set(int index, int value, boolean strict) {
|
||||
buf.put(index, (byte)value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayData set(int index, long value, boolean strict) {
|
||||
buf.put(index, (byte)value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayData set(int index, double value, boolean strict) {
|
||||
buf.put(index, (byte)value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(int index) {
|
||||
return 0x0ff & buf.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLong(int index) {
|
||||
return 0x0ff & buf.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDouble(int index) {
|
||||
return 0x0ff & buf.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObject(int index) {
|
||||
return (int)(0x0ff & buf.get(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(int index) {
|
||||
return index > -1 && index < buf.capacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDelete(final int index, final boolean strict) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDelete(final long fromIndex, final long toIndex, final boolean strict) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayData delete(int index) {
|
||||
throw unsupported("delete");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayData delete(long fromIndex, long toIndex) {
|
||||
throw unsupported("delete");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayData push(final boolean strict, final Object... items) {
|
||||
throw unsupported("push");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object pop() {
|
||||
throw unsupported("pop");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayData slice(long from, long to) {
|
||||
throw unsupported("slice");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayData convert(final Class<?> type) {
|
||||
throw unsupported("convert");
|
||||
}
|
||||
|
||||
private UnsupportedOperationException unsupported(final String method) {
|
||||
return new UnsupportedOperationException(method);
|
||||
}
|
||||
}
|
||||
@ -78,6 +78,7 @@ type.error.not.a.string={0} is not a String
|
||||
type.error.not.a.function={0} is not a function
|
||||
type.error.not.a.constructor={0} is not a constructor function
|
||||
type.error.not.a.file={0} is not a File
|
||||
type.error.not.a.bytebuffer={0} is not a java.nio.ByteBuffer
|
||||
|
||||
# operations not permitted on undefined
|
||||
type.error.cant.call.undefined=Cannot call undefined
|
||||
|
||||
60
nashorn/test/script/basic/JDK-8011964.js
Normal file
60
nashorn/test/script/basic/JDK-8011964.js
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* JDK-8011964: need indexed access to externally-managed ByteBuffer
|
||||
*
|
||||
* @test
|
||||
* @run
|
||||
*/
|
||||
|
||||
|
||||
var ByteBuffer = Java.type("java.nio.ByteBuffer");
|
||||
var buf = ByteBuffer.allocate(5);
|
||||
|
||||
var obj = {}
|
||||
Object.setIndexedPropertiesToExternalArrayData(obj, buf);
|
||||
|
||||
obj[0] = 'A'.charCodeAt(0);
|
||||
obj[1] = 'B'.charCodeAt(0);
|
||||
obj[2] = 'C'.charCodeAt(0);
|
||||
obj[3] = 'D'.charCodeAt(0);
|
||||
obj[4] = 'E'.charCodeAt(0);
|
||||
|
||||
for (var i = 0; i < buf.capacity(); i++) {
|
||||
print("obj[" + i + "] = " + obj[i]);
|
||||
print("buf.get(" + i + ") = " + buf.get(i));
|
||||
}
|
||||
|
||||
var arr = [];
|
||||
Object.setIndexedPropertiesToExternalArrayData(arr, buf);
|
||||
obj[0] = 'a'.charCodeAt(0);
|
||||
obj[1] = 'b'.charCodeAt(0);
|
||||
obj[2] = 'c'.charCodeAt(0);
|
||||
obj[3] = 'd'.charCodeAt(0);
|
||||
obj[4] = 'e'.charCodeAt(0);
|
||||
|
||||
for (var i in arr) {
|
||||
print("arr[" + i + "] = " + arr[i]);
|
||||
print("buf.get(" + i + ") = " + buf.get(i));
|
||||
}
|
||||
20
nashorn/test/script/basic/JDK-8011964.js.EXPECTED
Normal file
20
nashorn/test/script/basic/JDK-8011964.js.EXPECTED
Normal file
@ -0,0 +1,20 @@
|
||||
obj[0] = 65
|
||||
buf.get(0) = 65
|
||||
obj[1] = 66
|
||||
buf.get(1) = 66
|
||||
obj[2] = 67
|
||||
buf.get(2) = 67
|
||||
obj[3] = 68
|
||||
buf.get(3) = 68
|
||||
obj[4] = 69
|
||||
buf.get(4) = 69
|
||||
arr[0] = 97
|
||||
buf.get(0) = 97
|
||||
arr[1] = 98
|
||||
buf.get(1) = 98
|
||||
arr[2] = 99
|
||||
buf.get(2) = 99
|
||||
arr[3] = 100
|
||||
buf.get(3) = 100
|
||||
arr[4] = 101
|
||||
buf.get(4) = 101
|
||||
@ -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))
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
java.awt.Color[r=1,g=1,b=1]
|
||||
java.awt.Color[r=255,g=255,b=255]
|
||||
int
|
||||
float
|
||||
|
||||
48
nashorn/test/script/currently-failing/gettersetter.js
Normal file
48
nashorn/test/script/currently-failing/gettersetter.js
Normal file
@ -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);
|
||||
58
nashorn/test/script/maptests/builtins.js
Normal file
58
nashorn/test/script/maptests/builtins.js
Normal file
@ -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'));
|
||||
36
nashorn/test/script/maptests/constructor.js
Normal file
36
nashorn/test/script/maptests/constructor.js
Normal file
@ -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));
|
||||
38
nashorn/test/script/maptests/maputil.js
Normal file
38
nashorn/test/script/maptests/maputil.js
Normal file
@ -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");
|
||||
}
|
||||
}
|
||||
40
nashorn/test/script/maptests/object_create.js
Normal file
40
nashorn/test/script/maptests/object_create.js
Normal file
@ -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);
|
||||
46
nashorn/test/script/maptests/object_literals.js
Normal file
46
nashorn/test/script/maptests/object_literals.js
Normal file
@ -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});
|
||||
49
nashorn/test/script/maptests/point.js
Normal file
49
nashorn/test/script/maptests/point.js
Normal file
@ -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));
|
||||
46
nashorn/test/script/maptests/property_add.js
Normal file
46
nashorn/test/script/maptests/property_add.js
Normal file
@ -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);
|
||||
48
nashorn/test/script/maptests/property_delete.js
Normal file
48
nashorn/test/script/maptests/property_delete.js
Normal file
@ -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);
|
||||
56
nashorn/test/script/maptests/proto.js
Normal file
56
nashorn/test/script/maptests/proto.js
Normal file
@ -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);
|
||||
|
||||
|
||||
65
nashorn/test/script/sandbox/safeprops.js
Normal file
65
nashorn/test/script/sandbox/safeprops.js
Normal file
@ -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)');
|
||||
}
|
||||
@ -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
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
|
||||
package jdk.nashorn.api.scripting;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -229,6 +230,29 @@ public class ScriptObjectMirrorTest {
|
||||
assertTrue(newObj instanceof ScriptObjectMirror);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void indexPropertiesExternalBufferTest() throws ScriptException {
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
final ScriptObjectMirror obj = (ScriptObjectMirror)e.eval("var obj = {}; obj");
|
||||
final ByteBuffer buf = ByteBuffer.allocate(5);
|
||||
int i;
|
||||
for (i = 0; i < 5; i++) {
|
||||
buf.put(i, (byte)(i+10));
|
||||
}
|
||||
obj.setIndexedPropertiesToExternalArrayData(buf);
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
assertEquals((byte)(i+10), ((Number)e.eval("obj[" + i + "]")).byteValue());
|
||||
}
|
||||
|
||||
e.eval("for (i = 0; i < 5; i++) obj[i] = 0");
|
||||
for (i = 0; i < 5; i++) {
|
||||
assertEquals((byte)0, ((Number)e.eval("obj[" + i + "]")).byteValue());
|
||||
assertEquals((byte)0, buf.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void conversionTest() throws ScriptException {
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
|
||||
@ -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";
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user