Merge
This commit is contained in:
commit
e4302b0b2d
@ -231,7 +231,7 @@ public abstract class FieldObjectCreator<T> extends ObjectCreator<T> {
|
||||
if (symbol != null) {
|
||||
if (hasArguments() && symbol.isParam()) {
|
||||
symbol.setFieldIndex(paramCount++);
|
||||
} else {
|
||||
} else if (!isValidArrayIndex(getArrayIndex(tuple.key))) {
|
||||
symbol.setFieldIndex(fieldCount++);
|
||||
}
|
||||
}
|
||||
|
@ -439,8 +439,8 @@ public final class Global extends ScriptObject implements Scope {
|
||||
|
||||
// current ScriptContext to use - can be null.
|
||||
private ScriptContext scontext;
|
||||
// associated Property object for "context" property.
|
||||
private jdk.nashorn.internal.runtime.Property scontextProperty;
|
||||
// current ScriptEngine associated - can be null.
|
||||
private ScriptEngine engine;
|
||||
|
||||
/**
|
||||
* Set the current script context
|
||||
@ -448,7 +448,6 @@ public final class Global extends ScriptObject implements Scope {
|
||||
*/
|
||||
public void setScriptContext(final ScriptContext scontext) {
|
||||
this.scontext = scontext;
|
||||
scontextProperty.setValue(this, this, scontext, false);
|
||||
}
|
||||
|
||||
// global constants for this global - they can be replaced with MethodHandle.constant until invalidated
|
||||
@ -581,6 +580,7 @@ public final class Global extends ScriptObject implements Scope {
|
||||
return;
|
||||
}
|
||||
|
||||
this.engine = engine;
|
||||
init(engine);
|
||||
}
|
||||
|
||||
@ -917,6 +917,13 @@ public final class Global extends ScriptObject implements Scope {
|
||||
}
|
||||
}
|
||||
|
||||
switch (nameStr) {
|
||||
case "context":
|
||||
return sctxt;
|
||||
case "engine":
|
||||
return global.engine;
|
||||
}
|
||||
|
||||
if (self == UNDEFINED) {
|
||||
// scope access and so throw ReferenceError
|
||||
throw referenceError(global, "not.defined", nameStr);
|
||||
@ -1789,9 +1796,6 @@ public final class Global extends ScriptObject implements Scope {
|
||||
}
|
||||
|
||||
if (engine != null) {
|
||||
final int NOT_ENUMERABLE_NOT_CONFIG = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE;
|
||||
scontextProperty = addOwnProperty("context", NOT_ENUMERABLE_NOT_CONFIG, null);
|
||||
addOwnProperty("engine", NOT_ENUMERABLE_NOT_CONFIG, engine);
|
||||
// default file name
|
||||
addOwnProperty(ScriptEngine.FILENAME, Attribute.NOT_ENUMERABLE, null);
|
||||
// __noSuchProperty__ hook for ScriptContext search of missing variables
|
||||
|
@ -54,6 +54,7 @@ import static jdk.nashorn.internal.parser.TokenType.SEMICOLON;
|
||||
import static jdk.nashorn.internal.parser.TokenType.TERNARY;
|
||||
import static jdk.nashorn.internal.parser.TokenType.WHILE;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -2977,11 +2978,13 @@ loop:
|
||||
* Encapsulates part of the state of the parser, enough to reconstruct the state of both parser and lexer
|
||||
* for resuming parsing after skipping a function body.
|
||||
*/
|
||||
private static class ParserState {
|
||||
private static class ParserState implements Serializable {
|
||||
private final int position;
|
||||
private final int line;
|
||||
private final int linePosition;
|
||||
|
||||
private static final long serialVersionUID = -2382565130754093694L;
|
||||
|
||||
ParserState(final int position, final int line, final int linePosition) {
|
||||
this.position = position;
|
||||
this.line = line;
|
||||
|
@ -119,7 +119,7 @@ public class AccessorProperty extends Property {
|
||||
* produce different boun method handles wrapping the same access mechanism
|
||||
* depending on callsite
|
||||
*/
|
||||
private MethodHandle[] GETTER_CACHE = new MethodHandle[NOOF_TYPES];
|
||||
private transient MethodHandle[] GETTER_CACHE = new MethodHandle[NOOF_TYPES];
|
||||
|
||||
/**
|
||||
* Create a new accessor property. Factory method used by nasgen generated code.
|
||||
|
@ -101,7 +101,7 @@ public abstract class Property implements Serializable {
|
||||
private final int slot;
|
||||
|
||||
/** SwitchPoint that is invalidated when property is changed, optional */
|
||||
protected SwitchPoint changeCallback;
|
||||
protected transient SwitchPoint changeCallback;
|
||||
|
||||
private static final long serialVersionUID = 2099814273074501176L;
|
||||
|
||||
|
@ -568,9 +568,7 @@ public final class PropertyMap implements Iterable<Object>, Serializable {
|
||||
for (final Property property : otherProperties) {
|
||||
// This method is only safe to use with non-slotted, native getter/setter properties
|
||||
assert property.getSlot() == -1;
|
||||
if (isValidArrayIndex(getArrayIndex(property.getKey()))) {
|
||||
newMap.setContainsArrayKeys();
|
||||
}
|
||||
assert !(isValidArrayIndex(getArrayIndex(property.getKey())));
|
||||
}
|
||||
|
||||
return newMap;
|
||||
|
@ -125,6 +125,15 @@ public class NashornBeansLinker implements GuardingDynamicLinker {
|
||||
|
||||
@Override
|
||||
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
|
||||
if (sourceType == ConsString.class) {
|
||||
if (String.class == targetType1 || CharSequence.class == targetType1) {
|
||||
return Comparison.TYPE_1_BETTER;
|
||||
}
|
||||
|
||||
if (String.class == targetType2 || CharSequence.class == targetType2) {
|
||||
return Comparison.TYPE_2_BETTER;
|
||||
}
|
||||
}
|
||||
return linkerServices.compareConversion(sourceType, targetType1, targetType2);
|
||||
}
|
||||
}
|
||||
|
@ -131,11 +131,16 @@ final class NashornBottomLinker implements GuardingDynamicLinker, GuardingTypeCo
|
||||
}
|
||||
return getInvocation(EMPTY_ELEM_GETTER, self, linkerServices, desc);
|
||||
case "setProp":
|
||||
case "setElem":
|
||||
case "setElem": {
|
||||
final boolean strict = NashornCallSiteDescriptor.isStrict(desc);
|
||||
if (strict) {
|
||||
throw typeError("cant.set.property", getArgument(linkRequest), ScriptRuntime.safeToString(self));
|
||||
}
|
||||
if (desc.getOperand() != null) {
|
||||
return getInvocation(EMPTY_PROP_SETTER, self, linkerServices, desc);
|
||||
}
|
||||
return getInvocation(EMPTY_ELEM_SETTER, self, linkerServices, desc);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ type.error.cant.delete.property.of.undefined=Cannot delete property "{0}" of und
|
||||
|
||||
# other wrong usages of property
|
||||
type.error.property.has.no.setter=Cannot set property "{0}" of {1} that has only a getter
|
||||
type.error.cant.set.proto.to.non.object=Cannot set Object {0}'s __proto__ to be a non-object like {1}
|
||||
type.error.cant.set.proto.to.non.object=Cannot set Object {0}''s __proto__ to be a non-object like {1}
|
||||
type.error.no.such.function={1} has no such function "{0}"
|
||||
type.error.no.such.java.class=No such Java class: {0}
|
||||
type.error.no.such.java.constructor=No such Java constructor: {0}
|
||||
@ -125,10 +125,10 @@ type.error.prototype.not.an.object="prototype" of {0} is not an Object, it is {1
|
||||
type.error.cant.load.script=Cannot load script from {0}
|
||||
type.error.JSON.stringify.cyclic=JSON.stringify got a cyclic data structure
|
||||
type.error.cant.convert.string.to.char=Cannot convert string to character; its length must be exactly 1
|
||||
type.error.cant.convert.number.to.char=Cannot convert number to character; it's out of 0-65535 range
|
||||
type.error.cant.convert.number.to.char=Cannot convert number to character; it is out of 0-65535 range
|
||||
type.error.cant.convert.to.java.string=Cannot convert object of type {0} to a Java argument of string type
|
||||
type.error.cant.convert.to.java.number=Cannot convert object of type {0} to a Java argument of number type
|
||||
type.error.cant.convert.to.javascript.array=Can only convert Java arrays and lists to JavaScript arrays. Can't convert object of type {0}.
|
||||
type.error.cant.convert.to.javascript.array=Can only convert Java arrays and lists to JavaScript arrays. Cannot convert object of type {0}.
|
||||
type.error.extend.expects.at.least.one.argument=Java.extend needs at least one argument.
|
||||
type.error.extend.expects.at.least.one.type.argument=Java.extend needs at least one type argument.
|
||||
type.error.extend.expects.java.types=Java.extend needs Java types as its arguments.
|
||||
@ -141,10 +141,10 @@ type.error.extend.ERROR_NO_COMMON_LOADER=Can not find a common class loader for
|
||||
type.error.extend.ERROR_FINAL_FINALIZER=Can not extend class because {0} has a final finalize method.
|
||||
type.error.no.constructor.matches.args=Can not construct {0} with the passed arguments; they do not match any of its constructor signatures.
|
||||
type.error.no.method.matches.args=Can not invoke method {0} with the passed arguments; they do not match any of its method signatures.
|
||||
type.error.method.not.constructor=Java method {0} can't be used as a constructor.
|
||||
type.error.method.not.constructor=Java method {0} cannot be used as a constructor.
|
||||
type.error.env.not.object=$ENV must be an Object.
|
||||
type.error.unsupported.java.to.type=Unsupported Java.to target type {0}.
|
||||
type.error.constructor.requires.new=Constructor {0} requires 'new'.
|
||||
type.error.constructor.requires.new=Constructor {0} requires "new".
|
||||
type.error.new.on.nonpublic.javatype=new cannot be used with non-public java type {0}.
|
||||
|
||||
range.error.dataview.constructor.offset=Wrong offset or length in DataView constructor
|
||||
|
@ -29,14 +29,14 @@
|
||||
*/
|
||||
|
||||
// call explicit constructor
|
||||
print(new (java.awt["Color(int,int,int)"])(255,0,255));
|
||||
print(new (java.lang["String(char[],int,int)"])(['a','b', 'c', 'd'], 1, 3));
|
||||
// print the constructor itself
|
||||
print(java.awt["Color(int,int,int)"]);
|
||||
print(java.lang["String(char[],int,int)"]);
|
||||
|
||||
// store constructor to call later
|
||||
var Color = java.awt["Color(int,int,int)"];
|
||||
var Color = java.lang["String(char[],int,int)"];
|
||||
// call stored constructor
|
||||
print(new Color(33, 233, 2))
|
||||
print(new Color(['r','r', 'e', 'd'], 1, 3))
|
||||
|
||||
// check if default constructor works
|
||||
var obj = new (java.lang["Object()"])();
|
||||
|
@ -1,14 +1,14 @@
|
||||
java.awt.Color[r=255,g=0,b=255]
|
||||
[jdk.internal.dynalink.beans.SimpleDynamicMethod Color java.awt.Color.java.awt.Color(int,int,int)]
|
||||
java.awt.Color[r=33,g=233,b=2]
|
||||
bcd
|
||||
[jdk.internal.dynalink.beans.SimpleDynamicMethod String java.lang.String.java.lang.String(char[],int,int)]
|
||||
red
|
||||
TypeError: No such Java class: java.lang.NonExistent
|
||||
TypeError: No such Java constructor: Object(String)
|
||||
TypeError: Java constructor signature invalid: Object()xxxxx
|
||||
TypeError: Java constructor signature invalid: Object(
|
||||
TypeError: Java constructor signature invalid: Object)
|
||||
TypeError: Java method [jdk.internal.dynalink.beans.OverloadedDynamicMethod java.lang.System.getProperty] cant be used as a constructor.
|
||||
TypeError: Java method [jdk.internal.dynalink.beans.OverloadedDynamicMethod java.io.PrintStream.println] cant be used as a constructor.
|
||||
TypeError: Constructor [jdk.internal.dynalink.beans.SimpleDynamicMethod Color java.awt.Color.java.awt.Color(int,int,int)] requires new.
|
||||
TypeError: Java method [jdk.internal.dynalink.beans.OverloadedDynamicMethod java.lang.System.getProperty] cannot be used as a constructor.
|
||||
TypeError: Java method [jdk.internal.dynalink.beans.OverloadedDynamicMethod java.io.PrintStream.println] cannot be used as a constructor.
|
||||
TypeError: Constructor [jdk.internal.dynalink.beans.SimpleDynamicMethod String java.lang.String.java.lang.String(char[],int,int)] requires "new".
|
||||
TypeError: No such Java constructor: Runnable()
|
||||
TypeError: No such Java constructor: Runnable(int)
|
||||
java.lang.InstantiationException: java.io.InputStream
|
||||
|
@ -58,7 +58,7 @@ print("/foo/ is script object? " + Java.isScriptObject(/foo/));
|
||||
// (a) Java methods (b) Java classes (as these respond to new)
|
||||
// (c) FunctionalInterface objects (d) JSObjects that are 'functions'
|
||||
|
||||
print("java.awt.Color is java function? " + Java.isJavaFunction(java.awt.Color));
|
||||
print("java.lang.String is java function? " + Java.isJavaFunction(java.lang.String));
|
||||
print("java.lang.Runnable instance is java function? "
|
||||
+ Java.isJavaFunction(new java.lang.Runnable(function() {})));
|
||||
print("eval is java function? " + Java.isJavaFunction(eval));
|
||||
|
@ -13,7 +13,7 @@ System is script object? false
|
||||
Object is script object? true
|
||||
{} is script object? true
|
||||
/foo/ is script object? true
|
||||
java.awt.Color is java function? true
|
||||
java.lang.String is java function? true
|
||||
java.lang.Runnable instance is java function? true
|
||||
eval is java function? false
|
||||
println is java function? true
|
||||
|
@ -29,14 +29,14 @@
|
||||
*/
|
||||
|
||||
// call explicit constructor
|
||||
print(new (Java.type("java.awt.Color")["(int,int,int)"])(255,0,255));
|
||||
print(new (Java.type("java.lang.String")["(char[],int,int)"])(['a', 'b', 'c'],0, 3));
|
||||
// print the constructor itself
|
||||
print(Java.type("java.awt.Color")["(int,int,int)"]);
|
||||
print(Java.type("java.lang.String")["(char[],int,int)"]);
|
||||
|
||||
// store constructor to call later
|
||||
var Color = Java.type("java.awt.Color")["(int,int,int)"];
|
||||
var Color = Java.type("java.lang.String")["(char[],int,int)"];
|
||||
// call stored constructor
|
||||
print(new Color(33, 233, 2))
|
||||
print(new Color(['j', 'a', 'v', 'a'], 1, 3))
|
||||
|
||||
// check if default constructor works
|
||||
var obj = new (Java.type("java.lang.Object")["()"])();
|
||||
|
@ -1,10 +1,10 @@
|
||||
java.awt.Color[r=255,g=0,b=255]
|
||||
[jdk.internal.dynalink.beans.SimpleDynamicMethod Color java.awt.Color.java.awt.Color(int,int,int)]
|
||||
java.awt.Color[r=33,g=233,b=2]
|
||||
abc
|
||||
[jdk.internal.dynalink.beans.SimpleDynamicMethod String java.lang.String.java.lang.String(char[],int,int)]
|
||||
ava
|
||||
TypeError: null is not a function
|
||||
TypeError: null is not a function
|
||||
TypeError: null is not a function
|
||||
TypeError: Constructor [jdk.internal.dynalink.beans.SimpleDynamicMethod Color java.awt.Color.java.awt.Color(int,int,int)] requires new.
|
||||
TypeError: Constructor [jdk.internal.dynalink.beans.SimpleDynamicMethod String java.lang.String.java.lang.String(char[],int,int)] requires "new".
|
||||
TypeError: null is not a function
|
||||
TypeError: null is not a function
|
||||
java.lang.InstantiationException: java.io.InputStream
|
||||
|
46
nashorn/test/script/basic/JDK-8056978.js
Normal file
46
nashorn/test/script/basic/JDK-8056978.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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* JDK-8056978: ClassCastException: cannot cast jdk.nashorn.internal.scripts.JO*
|
||||
*
|
||||
* @test
|
||||
* @run
|
||||
*/
|
||||
|
||||
var obj1 = {
|
||||
'name': 'test name',
|
||||
'1': '1',
|
||||
'2': '2',
|
||||
'3': '3',
|
||||
'4': '4',
|
||||
'5': '5'
|
||||
};
|
||||
|
||||
var obj2 = {
|
||||
'name': 'hello'
|
||||
};
|
||||
|
||||
print(obj2['name']);
|
||||
print(obj2.name);
|
||||
|
2
nashorn/test/script/basic/JDK-8056978.js.EXPECTED
Normal file
2
nashorn/test/script/basic/JDK-8056978.js.EXPECTED
Normal file
@ -0,0 +1,2 @@
|
||||
hello
|
||||
hello
|
55
nashorn/test/script/basic/JDK-8058422.js
Normal file
55
nashorn/test/script/basic/JDK-8058422.js
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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-8058422: Users should be able to overwrite "context" and "engine" variables
|
||||
*
|
||||
* @test
|
||||
* @run
|
||||
*/
|
||||
|
||||
var m = new javax.script.ScriptEngineManager();
|
||||
var e = m.getEngineByName("nashorn");
|
||||
e.put("foo", "hello");
|
||||
var obj = e.eval("context.getAttribute('foo')");
|
||||
if (obj != "hello") {
|
||||
fail("Expected 'obj' to be 'hello'");
|
||||
}
|
||||
|
||||
e.put("context", "bar");
|
||||
if (e.eval("context") != "bar") {
|
||||
fail("Expected 'context' to be 'bar'");
|
||||
}
|
||||
|
||||
if (e.eval("foo") != "hello") {
|
||||
fail("Expected 'foo' to be 'hello'");
|
||||
}
|
||||
|
||||
if (e.eval("engine") != e) {
|
||||
fail("'engine' is not evaluaed to current engine");
|
||||
}
|
||||
|
||||
e.put("engine", "foobar");
|
||||
if (e.eval("engine") != "foobar") {
|
||||
fail("'engine' is not evalued to 'foobar'");
|
||||
}
|
41
nashorn/test/script/basic/JDK-8058545.js
Normal file
41
nashorn/test/script/basic/JDK-8058545.js
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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-8058545: With strict mode, bean property assignment of a non-existent property should result in TypeError
|
||||
*
|
||||
* @test
|
||||
* @run
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
var File = Java.type("java.io.File");
|
||||
var f = new File(".");
|
||||
try {
|
||||
f.foo = 33;
|
||||
fail("Should have thrown TypeError");
|
||||
} catch (e) {
|
||||
if (! (e instanceof TypeError)) {
|
||||
fail("Expected TypeError, got " + e);
|
||||
}
|
||||
}
|
36
nashorn/test/script/basic/JDK-8058615.js
Normal file
36
nashorn/test/script/basic/JDK-8058615.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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* JDK-8058615: Overload resolution ambiguity involving ConsString
|
||||
*
|
||||
* @test
|
||||
* @run
|
||||
*/
|
||||
|
||||
var strw = new java.io.StringWriter();
|
||||
var bufw = new java.io.BufferedWriter(strw);
|
||||
var s = "hello ";
|
||||
bufw.write(s + "world");
|
||||
bufw.close();
|
||||
print(strw.toString());
|
1
nashorn/test/script/basic/JDK-8058615.js.EXPECTED
Normal file
1
nashorn/test/script/basic/JDK-8058615.js.EXPECTED
Normal file
@ -0,0 +1 @@
|
||||
hello world
|
@ -582,6 +582,60 @@ public class ScopeTest {
|
||||
assertEquals(e.eval("x", newCtxt), 2);
|
||||
}
|
||||
|
||||
// @bug 8058422: Users should be able to overwrite "context" and "engine" variables
|
||||
@Test
|
||||
public static void contextOverwriteTest() throws ScriptException {
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
final Bindings b = new SimpleBindings();
|
||||
b.put("context", "hello");
|
||||
b.put("foo", 32);
|
||||
final ScriptContext newCtxt = new SimpleScriptContext();
|
||||
newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE);
|
||||
e.setContext(newCtxt);
|
||||
assertEquals(e.eval("context"), "hello");
|
||||
assertEquals(((Number)e.eval("foo")).intValue(), 32);
|
||||
}
|
||||
|
||||
// @bug 8058422: Users should be able to overwrite "context" and "engine" variables
|
||||
@Test
|
||||
public static void contextOverwriteInScriptTest() throws ScriptException {
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
e.put("foo", 32);
|
||||
|
||||
assertEquals(((Number)e.eval("foo")).intValue(), 32);
|
||||
assertEquals(e.eval("context = 'bar'"), "bar");
|
||||
assertEquals(((Number)e.eval("foo")).intValue(), 32);
|
||||
}
|
||||
|
||||
// @bug 8058422: Users should be able to overwrite "context" and "engine" variables
|
||||
@Test
|
||||
public static void engineOverwriteTest() throws ScriptException {
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
final Bindings b = new SimpleBindings();
|
||||
b.put("engine", "hello");
|
||||
b.put("foo", 32);
|
||||
final ScriptContext newCtxt = new SimpleScriptContext();
|
||||
newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE);
|
||||
e.setContext(newCtxt);
|
||||
assertEquals(e.eval("engine"), "hello");
|
||||
assertEquals(((Number)e.eval("foo")).intValue(), 32);
|
||||
}
|
||||
|
||||
// @bug 8058422: Users should be able to overwrite "context" and "engine" variables
|
||||
@Test
|
||||
public static void engineOverwriteInScriptTest() throws ScriptException {
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
e.put("foo", 32);
|
||||
|
||||
assertEquals(((Number)e.eval("foo")).intValue(), 32);
|
||||
assertEquals(e.eval("engine = 'bar'"), "bar");
|
||||
assertEquals(((Number)e.eval("foo")).intValue(), 32);
|
||||
}
|
||||
|
||||
// @bug 8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
|
||||
@Test
|
||||
public static void testMegamorphicGetInGlobal() throws Exception {
|
||||
|
Loading…
Reference in New Issue
Block a user