Mon, 22 Sep 2014 18:34:06 -0700
Merge
1.1 --- a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Wed Sep 17 13:53:36 2014 -0700 1.2 +++ b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Mon Sep 22 18:34:06 2014 -0700 1.3 @@ -50,6 +50,7 @@ 1.4 import jdk.nashorn.internal.runtime.ScriptObject; 1.5 import jdk.nashorn.internal.runtime.ScriptRuntime; 1.6 import jdk.nashorn.internal.runtime.arrays.ArrayData; 1.7 +import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; 1.8 1.9 /** 1.10 * Mirror object that wraps a given Nashorn Script object. 1.11 @@ -261,7 +262,7 @@ 1.12 public void setSlot(final int index, final Object value) { 1.13 inGlobal(new Callable<Void>() { 1.14 @Override public Void call() { 1.15 - sobj.set(index, unwrap(value, global), strict); 1.16 + sobj.set(index, unwrap(value, global), getCallSiteFlags()); 1.17 return null; 1.18 } 1.19 }); 1.20 @@ -425,7 +426,7 @@ 1.21 for (final Map.Entry<? extends String, ? extends Object> entry : map.entrySet()) { 1.22 final Object value = entry.getValue(); 1.23 final Object modValue = globalChanged? wrap(value, oldGlobal) : value; 1.24 - sobj.set(entry.getKey(), unwrap(modValue, global), strict); 1.25 + sobj.set(entry.getKey(), unwrap(modValue, global), getCallSiteFlags()); 1.26 } 1.27 return null; 1.28 } 1.29 @@ -756,6 +757,10 @@ 1.30 return (obj == ScriptRuntime.UNDEFINED)? null : obj; 1.31 } 1.32 1.33 + private int getCallSiteFlags() { 1.34 + return strict ? NashornCallSiteDescriptor.CALLSITE_STRICT : 0; 1.35 + } 1.36 + 1.37 // internals only below this. 1.38 private <V> V inGlobal(final Callable<V> callable) { 1.39 final Global oldGlobal = Context.getGlobal();
2.1 --- a/src/jdk/nashorn/internal/codegen/FieldObjectCreator.java Wed Sep 17 13:53:36 2014 -0700 2.2 +++ b/src/jdk/nashorn/internal/codegen/FieldObjectCreator.java Mon Sep 22 18:34:06 2014 -0700 2.3 @@ -231,7 +231,7 @@ 2.4 if (symbol != null) { 2.5 if (hasArguments() && symbol.isParam()) { 2.6 symbol.setFieldIndex(paramCount++); 2.7 - } else { 2.8 + } else if (!isValidArrayIndex(getArrayIndex(tuple.key))) { 2.9 symbol.setFieldIndex(fieldCount++); 2.10 } 2.11 }
3.1 --- a/src/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java Wed Sep 17 13:53:36 2014 -0700 3.2 +++ b/src/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java Mon Sep 22 18:34:06 2014 -0700 3.3 @@ -558,7 +558,7 @@ 3.4 // of the compilation that the object being iterated over must use strings for property 3.5 // names (e.g., it is a native JS object or array), then we'll not bother trying to treat 3.6 // the property names optimistically. 3.7 - !forNode.isForEach() && compiler.hasStringPropertyIterator(iterable.getExpression())); 3.8 + !compiler.useOptimisticTypes() || (!forNode.isForEach() && compiler.hasStringPropertyIterator(iterable.getExpression()))); 3.9 } else { 3.10 if(init != null) { 3.11 init.accept(this); 3.12 @@ -686,6 +686,10 @@ 3.13 3.14 @Override 3.15 public boolean enterReturnNode(final ReturnNode returnNode) { 3.16 + if(!reachable) { 3.17 + return false; 3.18 + } 3.19 + 3.20 final Expression returnExpr = returnNode.getExpression(); 3.21 final Type returnExprType; 3.22 if(returnExpr != null) { 3.23 @@ -701,6 +705,9 @@ 3.24 3.25 @Override 3.26 public boolean enterSplitNode(final SplitNode splitNode) { 3.27 + if(!reachable) { 3.28 + return false; 3.29 + } 3.30 // Need to visit inside of split nodes. While it's true that they don't have local variables, we need to visit 3.31 // breaks, continues, and returns in them. 3.32 if(topSplit == null) { 3.33 @@ -950,6 +957,9 @@ 3.34 3.35 @Override 3.36 public boolean enterVarNode(final VarNode varNode) { 3.37 + if (!reachable) { 3.38 + return false; 3.39 + } 3.40 final Expression init = varNode.getInit(); 3.41 if(init != null) { 3.42 init.accept(this);
4.1 --- a/src/jdk/nashorn/internal/objects/ArrayBufferView.java Wed Sep 17 13:53:36 2014 -0700 4.2 +++ b/src/jdk/nashorn/internal/objects/ArrayBufferView.java Mon Sep 22 18:34:06 2014 -0700 4.3 @@ -228,11 +228,11 @@ 4.4 private static void copyElements(final ArrayBufferView dest, final int length, final ScriptObject source, final int offset) { 4.5 if (!dest.isFloatArray()) { 4.6 for (int i = 0, j = offset; i < length; i++, j++) { 4.7 - dest.set(j, source.getInt(i, INVALID_PROGRAM_POINT), false); 4.8 + dest.set(j, source.getInt(i, INVALID_PROGRAM_POINT), 0); 4.9 } 4.10 } else { 4.11 for (int i = 0, j = offset; i < length; i++, j++) { 4.12 - dest.set(j, source.getDouble(i, INVALID_PROGRAM_POINT), false); 4.13 + dest.set(j, source.getDouble(i, INVALID_PROGRAM_POINT), 0); 4.14 } 4.15 } 4.16 }
5.1 --- a/src/jdk/nashorn/internal/objects/Global.java Wed Sep 17 13:53:36 2014 -0700 5.2 +++ b/src/jdk/nashorn/internal/objects/Global.java Mon Sep 22 18:34:06 2014 -0700 5.3 @@ -439,8 +439,8 @@ 5.4 5.5 // current ScriptContext to use - can be null. 5.6 private ScriptContext scontext; 5.7 - // associated Property object for "context" property. 5.8 - private jdk.nashorn.internal.runtime.Property scontextProperty; 5.9 + // current ScriptEngine associated - can be null. 5.10 + private ScriptEngine engine; 5.11 5.12 /** 5.13 * Set the current script context 5.14 @@ -448,7 +448,6 @@ 5.15 */ 5.16 public void setScriptContext(final ScriptContext scontext) { 5.17 this.scontext = scontext; 5.18 - scontextProperty.setValue(this, this, scontext, false); 5.19 } 5.20 5.21 // global constants for this global - they can be replaced with MethodHandle.constant until invalidated 5.22 @@ -581,6 +580,7 @@ 5.23 return; 5.24 } 5.25 5.26 + this.engine = engine; 5.27 init(engine); 5.28 } 5.29 5.30 @@ -917,6 +917,13 @@ 5.31 } 5.32 } 5.33 5.34 + switch (nameStr) { 5.35 + case "context": 5.36 + return sctxt; 5.37 + case "engine": 5.38 + return global.engine; 5.39 + } 5.40 + 5.41 if (self == UNDEFINED) { 5.42 // scope access and so throw ReferenceError 5.43 throw referenceError(global, "not.defined", nameStr); 5.44 @@ -1789,9 +1796,6 @@ 5.45 } 5.46 5.47 if (engine != null) { 5.48 - final int NOT_ENUMERABLE_NOT_CONFIG = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE; 5.49 - scontextProperty = addOwnProperty("context", NOT_ENUMERABLE_NOT_CONFIG, null); 5.50 - addOwnProperty("engine", NOT_ENUMERABLE_NOT_CONFIG, engine); 5.51 // default file name 5.52 addOwnProperty(ScriptEngine.FILENAME, Attribute.NOT_ENUMERABLE, null); 5.53 // __noSuchProperty__ hook for ScriptContext search of missing variables 5.54 @@ -1821,10 +1825,10 @@ 5.55 5.56 // ECMA 15.11.4.2 Error.prototype.name 5.57 // Error.prototype.name = "Error"; 5.58 - errorProto.set(NativeError.NAME, "Error", false); 5.59 + errorProto.set(NativeError.NAME, "Error", 0); 5.60 // ECMA 15.11.4.3 Error.prototype.message 5.61 // Error.prototype.message = ""; 5.62 - errorProto.set(NativeError.MESSAGE, "", false); 5.63 + errorProto.set(NativeError.MESSAGE, "", 0); 5.64 5.65 this.builtinEvalError = initErrorSubtype("EvalError", errorProto); 5.66 this.builtinRangeError = initErrorSubtype("RangeError", errorProto); 5.67 @@ -1837,8 +1841,8 @@ 5.68 private ScriptFunction initErrorSubtype(final String name, final ScriptObject errorProto) { 5.69 final ScriptFunction cons = initConstructor(name, ScriptFunction.class); 5.70 final ScriptObject prototype = ScriptFunction.getPrototype(cons); 5.71 - prototype.set(NativeError.NAME, name, false); 5.72 - prototype.set(NativeError.MESSAGE, "", false); 5.73 + prototype.set(NativeError.NAME, name, 0); 5.74 + prototype.set(NativeError.MESSAGE, "", 0); 5.75 prototype.setInitialProto(errorProto); 5.76 return cons; 5.77 } 5.78 @@ -1898,7 +1902,7 @@ 5.79 private static void copyOptions(final ScriptObject options, final ScriptEnvironment scriptEnv) { 5.80 for (final Field f : scriptEnv.getClass().getFields()) { 5.81 try { 5.82 - options.set(f.getName(), f.get(scriptEnv), false); 5.83 + options.set(f.getName(), f.get(scriptEnv), 0); 5.84 } catch (final IllegalArgumentException | IllegalAccessException exp) { 5.85 throw new RuntimeException(exp); 5.86 } 5.87 @@ -2042,7 +2046,7 @@ 5.88 // <anon-function> 5.89 builtinFunction.setInitialProto(anon); 5.90 builtinFunction.setPrototype(anon); 5.91 - anon.set("constructor", builtinFunction, false); 5.92 + anon.set("constructor", builtinFunction, 0); 5.93 anon.deleteOwnProperty(anon.getMap().findProperty("prototype")); 5.94 5.95 // use "getter" so that [[ThrowTypeError]] function's arity is 0 - as specified in step 10 of section 13.2.3
6.1 --- a/src/jdk/nashorn/internal/objects/NativeArray.java Wed Sep 17 13:53:36 2014 -0700 6.2 +++ b/src/jdk/nashorn/internal/objects/NativeArray.java Mon Sep 22 18:34:06 2014 -0700 6.3 @@ -32,6 +32,7 @@ 6.4 import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.isValidArrayIndex; 6.5 import static jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator.arrayLikeIterator; 6.6 import static jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator.reverseArrayLikeIterator; 6.7 +import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_STRICT; 6.8 6.9 import java.lang.invoke.MethodHandle; 6.10 import java.util.ArrayList; 6.11 @@ -69,6 +70,7 @@ 6.12 import jdk.nashorn.internal.runtime.arrays.IteratorAction; 6.13 import jdk.nashorn.internal.runtime.linker.Bootstrap; 6.14 import jdk.nashorn.internal.runtime.linker.InvokeByName; 6.15 +import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; 6.16 6.17 /** 6.18 * Runtime representation of a JavaScript array. NativeArray only holds numeric 6.19 @@ -341,7 +343,7 @@ 6.20 if (!newWritable) { 6.21 // make 'length' property not writable 6.22 final ScriptObject newDesc = Global.newEmptyInstance(); 6.23 - newDesc.set(WRITABLE, false, false); 6.24 + newDesc.set(WRITABLE, false, 0); 6.25 return super.defineOwnProperty("length", newDesc, false); 6.26 } 6.27 6.28 @@ -808,7 +810,7 @@ 6.29 final long len = JSType.toUint32(sobj.getLength()); 6.30 6.31 if (len == 0) { 6.32 - sobj.set("length", 0, true); 6.33 + sobj.set("length", 0, CALLSITE_STRICT); 6.34 return ScriptRuntime.UNDEFINED; 6.35 } 6.36 6.37 @@ -816,7 +818,7 @@ 6.38 final Object element = sobj.get(index); 6.39 6.40 sobj.delete(index, true); 6.41 - sobj.set("length", index, true); 6.42 + sobj.set("length", index, CALLSITE_STRICT); 6.43 6.44 return element; 6.45 } catch (final ClassCastException | NullPointerException e) { 6.46 @@ -844,9 +846,9 @@ 6.47 6.48 long len = JSType.toUint32(sobj.getLength()); 6.49 for (final Object element : args) { 6.50 - sobj.set(len++, element, true); 6.51 + sobj.set(len++, element, CALLSITE_STRICT); 6.52 } 6.53 - sobj.set("length", len, true); 6.54 + sobj.set("length", len, CALLSITE_STRICT); 6.55 6.56 return len; 6.57 } catch (final ClassCastException | NullPointerException e) { 6.58 @@ -928,8 +930,8 @@ 6.59 } 6.60 6.61 long len = JSType.toUint32(sobj.getLength()); 6.62 - sobj.set(len++, arg, true); 6.63 - sobj.set("length", len, true); 6.64 + sobj.set(len++, arg, CALLSITE_STRICT); 6.65 + sobj.set("length", len, CALLSITE_STRICT); 6.66 return len; 6.67 } catch (final ClassCastException | NullPointerException e) { 6.68 throw typeError("not.an.object", ScriptRuntime.safeToString(self)); 6.69 @@ -957,14 +959,14 @@ 6.70 final boolean upperExists = sobj.has(upper); 6.71 6.72 if (lowerExists && upperExists) { 6.73 - sobj.set(lower, upperValue, true); 6.74 - sobj.set(upper, lowerValue, true); 6.75 + sobj.set(lower, upperValue, CALLSITE_STRICT); 6.76 + sobj.set(upper, lowerValue, CALLSITE_STRICT); 6.77 } else if (!lowerExists && upperExists) { 6.78 - sobj.set(lower, upperValue, true); 6.79 + sobj.set(lower, upperValue, CALLSITE_STRICT); 6.80 sobj.delete(upper, true); 6.81 } else if (lowerExists && !upperExists) { 6.82 sobj.delete(lower, true); 6.83 - sobj.set(upper, lowerValue, true); 6.84 + sobj.set(upper, lowerValue, CALLSITE_STRICT); 6.85 } 6.86 } 6.87 return sobj; 6.88 @@ -1003,7 +1005,7 @@ 6.89 for (long k = 1; k < len; k++) { 6.90 final boolean hasCurrent = sobj.has(k); 6.91 if (hasCurrent) { 6.92 - sobj.set(k - 1, sobj.get(k), true); 6.93 + sobj.set(k - 1, sobj.get(k), CALLSITE_STRICT); 6.94 } else if (hasPrevious) { 6.95 sobj.delete(k - 1, true); 6.96 } 6.97 @@ -1015,7 +1017,7 @@ 6.98 len = 0; 6.99 } 6.100 6.101 - sobj.set("length", len, true); 6.102 + sobj.set("length", len, CALLSITE_STRICT); 6.103 6.104 return first; 6.105 } 6.106 @@ -1226,7 +1228,7 @@ 6.107 final long to = k + items.length; 6.108 6.109 if (sobj.has(from)) { 6.110 - sobj.set(to, sobj.get(from), true); 6.111 + sobj.set(to, sobj.get(from), CALLSITE_STRICT); 6.112 } else { 6.113 sobj.delete(to, true); 6.114 } 6.115 @@ -1242,7 +1244,7 @@ 6.116 6.117 if (sobj.has(from)) { 6.118 final Object fromValue = sobj.get(from); 6.119 - sobj.set(to, fromValue, true); 6.120 + sobj.set(to, fromValue, CALLSITE_STRICT); 6.121 } else { 6.122 sobj.delete(to, true); 6.123 } 6.124 @@ -1251,11 +1253,11 @@ 6.125 6.126 long k = start; 6.127 for (int i = 0; i < items.length; i++, k++) { 6.128 - sobj.set(k, items[i], true); 6.129 + sobj.set(k, items[i], CALLSITE_STRICT); 6.130 } 6.131 6.132 final long newLength = len - deleteCount + items.length; 6.133 - sobj.set("length", newLength, true); 6.134 + sobj.set("length", newLength, CALLSITE_STRICT); 6.135 6.136 return array; 6.137 } 6.138 @@ -1295,19 +1297,19 @@ 6.139 6.140 if (sobj.has(from)) { 6.141 final Object fromValue = sobj.get(from); 6.142 - sobj.set(to, fromValue, true); 6.143 + sobj.set(to, fromValue, CALLSITE_STRICT); 6.144 } else { 6.145 sobj.delete(to, true); 6.146 } 6.147 } 6.148 6.149 for (int j = 0; j < items.length; j++) { 6.150 - sobj.set(j, items[j], true); 6.151 + sobj.set(j, items[j], CALLSITE_STRICT); 6.152 } 6.153 } 6.154 6.155 final long newLength = len + items.length; 6.156 - sobj.set("length", newLength, true); 6.157 + sobj.set("length", newLength, CALLSITE_STRICT); 6.158 6.159 return newLength; 6.160 }
7.1 --- a/src/jdk/nashorn/internal/objects/NativeDebug.java Wed Sep 17 13:53:36 2014 -0700 7.2 +++ b/src/jdk/nashorn/internal/objects/NativeDebug.java Mon Sep 22 18:34:06 2014 -0700 7.3 @@ -42,6 +42,7 @@ 7.4 import jdk.nashorn.internal.runtime.ScriptObject; 7.5 import jdk.nashorn.internal.runtime.events.RuntimeEvent; 7.6 import jdk.nashorn.internal.runtime.linker.LinkerCallSite; 7.7 +import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; 7.8 7.9 /** 7.10 * Nashorn specific debug utils. This is meant for Nashorn developers. 7.11 @@ -266,7 +267,7 @@ 7.12 */ 7.13 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 7.14 public static void setEventQueueCapacity(final Object self, final Object newCapacity) { 7.15 - ((ScriptObject)self).set(EVENT_QUEUE_CAPACITY, newCapacity, true); 7.16 + ((ScriptObject)self).set(EVENT_QUEUE_CAPACITY, newCapacity, NashornCallSiteDescriptor.CALLSITE_STRICT); 7.17 } 7.18 7.19 /** 7.20 @@ -355,7 +356,7 @@ 7.21 if (sobj.has(EVENT_QUEUE)) { 7.22 q = (LinkedList<RuntimeEvent<?>>)((ScriptObject)self).get(EVENT_QUEUE); 7.23 } else { 7.24 - ((ScriptObject)self).set(EVENT_QUEUE, q = new LinkedList<>(), true); 7.25 + ((ScriptObject)self).set(EVENT_QUEUE, q = new LinkedList<>(), NashornCallSiteDescriptor.CALLSITE_STRICT); 7.26 } 7.27 return q; 7.28 }
8.1 --- a/src/jdk/nashorn/internal/objects/NativeJSAdapter.java Wed Sep 17 13:53:36 2014 -0700 8.2 +++ b/src/jdk/nashorn/internal/objects/NativeJSAdapter.java Mon Sep 22 18:34:06 2014 -0700 8.3 @@ -250,146 +250,146 @@ 8.4 } 8.5 8.6 @Override 8.7 - public void set(final Object key, final int value, final boolean strict) { 8.8 + public void set(final Object key, final int value, final int flags) { 8.9 if (overrides && super.hasOwnProperty(key)) { 8.10 - super.set(key, value, strict); 8.11 + super.set(key, value, flags); 8.12 } else { 8.13 - callAdaptee(__put__, key, value, strict); 8.14 + callAdaptee(__put__, key, value, flags); 8.15 } 8.16 } 8.17 8.18 @Override 8.19 - public void set(final Object key, final long value, final boolean strict) { 8.20 + public void set(final Object key, final long value, final int flags) { 8.21 if (overrides && super.hasOwnProperty(key)) { 8.22 - super.set(key, value, strict); 8.23 + super.set(key, value, flags); 8.24 } else { 8.25 - callAdaptee(__put__, key, value, strict); 8.26 + callAdaptee(__put__, key, value, flags); 8.27 } 8.28 } 8.29 8.30 @Override 8.31 - public void set(final Object key, final double value, final boolean strict) { 8.32 + public void set(final Object key, final double value, final int flags) { 8.33 if (overrides && super.hasOwnProperty(key)) { 8.34 - super.set(key, value, strict); 8.35 + super.set(key, value, flags); 8.36 } else { 8.37 - callAdaptee(__put__, key, value, strict); 8.38 + callAdaptee(__put__, key, value, flags); 8.39 } 8.40 } 8.41 8.42 @Override 8.43 - public void set(final Object key, final Object value, final boolean strict) { 8.44 + public void set(final Object key, final Object value, final int flags) { 8.45 if (overrides && super.hasOwnProperty(key)) { 8.46 - super.set(key, value, strict); 8.47 + super.set(key, value, flags); 8.48 } else { 8.49 - callAdaptee(__put__, key, value, strict); 8.50 + callAdaptee(__put__, key, value, flags); 8.51 } 8.52 } 8.53 8.54 @Override 8.55 - public void set(final double key, final int value, final boolean strict) { 8.56 + public void set(final double key, final int value, final int flags) { 8.57 if (overrides && super.hasOwnProperty(key)) { 8.58 - super.set(key, value, strict); 8.59 + super.set(key, value, flags); 8.60 } else { 8.61 - callAdaptee(__put__, key, value, strict); 8.62 + callAdaptee(__put__, key, value, flags); 8.63 } 8.64 } 8.65 8.66 @Override 8.67 - public void set(final double key, final long value, final boolean strict) { 8.68 + public void set(final double key, final long value, final int flags) { 8.69 if (overrides && super.hasOwnProperty(key)) { 8.70 - super.set(key, value, strict); 8.71 + super.set(key, value, flags); 8.72 } else { 8.73 - callAdaptee(__put__, key, value, strict); 8.74 + callAdaptee(__put__, key, value, flags); 8.75 } 8.76 } 8.77 8.78 @Override 8.79 - public void set(final double key, final double value, final boolean strict) { 8.80 + public void set(final double key, final double value, final int flags) { 8.81 if (overrides && super.hasOwnProperty(key)) { 8.82 - super.set(key, value, strict); 8.83 + super.set(key, value, flags); 8.84 } else { 8.85 - callAdaptee(__put__, key, value, strict); 8.86 + callAdaptee(__put__, key, value, flags); 8.87 } 8.88 } 8.89 8.90 @Override 8.91 - public void set(final double key, final Object value, final boolean strict) { 8.92 + public void set(final double key, final Object value, final int flags) { 8.93 if (overrides && super.hasOwnProperty(key)) { 8.94 - super.set(key, value, strict); 8.95 + super.set(key, value, flags); 8.96 } else { 8.97 - callAdaptee(__put__, key, value, strict); 8.98 + callAdaptee(__put__, key, value, flags); 8.99 } 8.100 } 8.101 8.102 @Override 8.103 - public void set(final long key, final int value, final boolean strict) { 8.104 + public void set(final long key, final int value, final int flags) { 8.105 if (overrides && super.hasOwnProperty(key)) { 8.106 - super.set(key, value, strict); 8.107 + super.set(key, value, flags); 8.108 } else { 8.109 - callAdaptee(__put__, key, value, strict); 8.110 + callAdaptee(__put__, key, value, flags); 8.111 } 8.112 } 8.113 8.114 @Override 8.115 - public void set(final long key, final long value, final boolean strict) { 8.116 + public void set(final long key, final long value, final int flags) { 8.117 if (overrides && super.hasOwnProperty(key)) { 8.118 - super.set(key, value, strict); 8.119 + super.set(key, value, flags); 8.120 } else { 8.121 - callAdaptee(__put__, key, value, strict); 8.122 + callAdaptee(__put__, key, value, flags); 8.123 } 8.124 } 8.125 8.126 @Override 8.127 - public void set(final long key, final double value, final boolean strict) { 8.128 + public void set(final long key, final double value, final int flags) { 8.129 if (overrides && super.hasOwnProperty(key)) { 8.130 - super.set(key, value, strict); 8.131 + super.set(key, value, flags); 8.132 } else { 8.133 - callAdaptee(__put__, key, value, strict); 8.134 + callAdaptee(__put__, key, value, flags); 8.135 } 8.136 } 8.137 8.138 @Override 8.139 - public void set(final long key, final Object value, final boolean strict) { 8.140 + public void set(final long key, final Object value, final int flags) { 8.141 if (overrides && super.hasOwnProperty(key)) { 8.142 - super.set(key, value, strict); 8.143 + super.set(key, value, flags); 8.144 } else { 8.145 - callAdaptee(__put__, key, value, strict); 8.146 + callAdaptee(__put__, key, value, flags); 8.147 } 8.148 } 8.149 8.150 @Override 8.151 - public void set(final int key, final int value, final boolean strict) { 8.152 + public void set(final int key, final int value, final int flags) { 8.153 if (overrides && super.hasOwnProperty(key)) { 8.154 - super.set(key, value, strict); 8.155 + super.set(key, value, flags); 8.156 } else { 8.157 - callAdaptee(__put__, key, value, strict); 8.158 + callAdaptee(__put__, key, value, flags); 8.159 } 8.160 } 8.161 8.162 @Override 8.163 - public void set(final int key, final long value, final boolean strict) { 8.164 + public void set(final int key, final long value, final int flags) { 8.165 if (overrides && super.hasOwnProperty(key)) { 8.166 - super.set(key, value, strict); 8.167 + super.set(key, value, flags); 8.168 } else { 8.169 - callAdaptee(__put__, key, value, strict); 8.170 + callAdaptee(__put__, key, value, flags); 8.171 } 8.172 } 8.173 8.174 @Override 8.175 - public void set(final int key, final double value, final boolean strict) { 8.176 + public void set(final int key, final double value, final int flags) { 8.177 if (overrides && super.hasOwnProperty(key)) { 8.178 - super.set(key, value, strict); 8.179 + super.set(key, value, flags); 8.180 } else { 8.181 - callAdaptee(__put__, key, value, strict); 8.182 + callAdaptee(__put__, key, value, flags); 8.183 } 8.184 } 8.185 8.186 @Override 8.187 - public void set(final int key, final Object value, final boolean strict) { 8.188 + public void set(final int key, final Object value, final int flags) { 8.189 if (overrides && super.hasOwnProperty(key)) { 8.190 - super.set(key, value, strict); 8.191 + super.set(key, value, flags); 8.192 } else { 8.193 - callAdaptee(__put__, key, value, strict); 8.194 + callAdaptee(__put__, key, value, flags); 8.195 } 8.196 } 8.197
9.1 --- a/src/jdk/nashorn/internal/objects/NativeJSON.java Wed Sep 17 13:53:36 2014 -0700 9.2 +++ b/src/jdk/nashorn/internal/objects/NativeJSON.java Mon Sep 22 18:34:06 2014 -0700 9.3 @@ -191,7 +191,7 @@ 9.4 state.gap = gap; 9.5 9.6 final ScriptObject wrapper = Global.newEmptyInstance(); 9.7 - wrapper.set("", value, false); 9.8 + wrapper.set("", value, 0); 9.9 9.10 return str("", wrapper, state); 9.11 }
10.1 --- a/src/jdk/nashorn/internal/objects/NativeJavaImporter.java Wed Sep 17 13:53:36 2014 -0700 10.2 +++ b/src/jdk/nashorn/internal/objects/NativeJavaImporter.java Mon Sep 22 18:34:06 2014 -0700 10.3 @@ -146,7 +146,7 @@ 10.4 final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND); 10.5 final Object value = createProperty(name); 10.6 if(value != null) { 10.7 - set(name, value, false); 10.8 + set(name, value, 0); 10.9 return true; 10.10 } 10.11 return false;
11.1 --- a/src/jdk/nashorn/internal/parser/Parser.java Wed Sep 17 13:53:36 2014 -0700 11.2 +++ b/src/jdk/nashorn/internal/parser/Parser.java Mon Sep 22 18:34:06 2014 -0700 11.3 @@ -54,6 +54,7 @@ 11.4 import static jdk.nashorn.internal.parser.TokenType.TERNARY; 11.5 import static jdk.nashorn.internal.parser.TokenType.WHILE; 11.6 11.7 +import java.io.Serializable; 11.8 import java.util.ArrayDeque; 11.9 import java.util.ArrayList; 11.10 import java.util.Collections; 11.11 @@ -2977,11 +2978,13 @@ 11.12 * Encapsulates part of the state of the parser, enough to reconstruct the state of both parser and lexer 11.13 * for resuming parsing after skipping a function body. 11.14 */ 11.15 - private static class ParserState { 11.16 + private static class ParserState implements Serializable { 11.17 private final int position; 11.18 private final int line; 11.19 private final int linePosition; 11.20 11.21 + private static final long serialVersionUID = -2382565130754093694L; 11.22 + 11.23 ParserState(final int position, final int line, final int linePosition) { 11.24 this.position = position; 11.25 this.line = line;
12.1 --- a/src/jdk/nashorn/internal/runtime/AccessorProperty.java Wed Sep 17 13:53:36 2014 -0700 12.2 +++ b/src/jdk/nashorn/internal/runtime/AccessorProperty.java Mon Sep 22 18:34:06 2014 -0700 12.3 @@ -119,7 +119,7 @@ 12.4 * produce different boun method handles wrapping the same access mechanism 12.5 * depending on callsite 12.6 */ 12.7 - private MethodHandle[] GETTER_CACHE = new MethodHandle[NOOF_TYPES]; 12.8 + private transient MethodHandle[] GETTER_CACHE = new MethodHandle[NOOF_TYPES]; 12.9 12.10 /** 12.11 * Create a new accessor property. Factory method used by nasgen generated code.
13.1 --- a/src/jdk/nashorn/internal/runtime/CodeStore.java Wed Sep 17 13:53:36 2014 -0700 13.2 +++ b/src/jdk/nashorn/internal/runtime/CodeStore.java Mon Sep 22 18:34:06 2014 -0700 13.3 @@ -34,51 +34,42 @@ 13.4 import java.io.ObjectInputStream; 13.5 import java.io.ObjectOutputStream; 13.6 import java.io.Serializable; 13.7 +import java.security.AccessControlException; 13.8 import java.security.AccessController; 13.9 import java.security.PrivilegedActionException; 13.10 import java.security.PrivilegedExceptionAction; 13.11 +import java.util.Iterator; 13.12 import java.util.Map; 13.13 +import java.util.ServiceLoader; 13.14 import jdk.nashorn.internal.codegen.types.Type; 13.15 import jdk.nashorn.internal.runtime.logging.DebugLogger; 13.16 import jdk.nashorn.internal.runtime.logging.Loggable; 13.17 import jdk.nashorn.internal.runtime.logging.Logger; 13.18 +import jdk.nashorn.internal.runtime.options.Options; 13.19 13.20 /** 13.21 * A code cache for persistent caching of compiled scripts. 13.22 */ 13.23 @Logger(name="codestore") 13.24 -final class CodeStore implements Loggable { 13.25 +public abstract class CodeStore implements Loggable { 13.26 13.27 - private final File dir; 13.28 - private final int minSize; 13.29 - private final DebugLogger log; 13.30 + /** 13.31 + * Permission needed to provide a CodeStore instance via ServiceLoader. 13.32 + */ 13.33 + public final static String NASHORN_PROVIDE_CODE_STORE = "nashorn.provideCodeStore"; 13.34 13.35 - // Default minimum size for storing a compiled script class 13.36 - private final static int DEFAULT_MIN_SIZE = 1000; 13.37 + private DebugLogger log; 13.38 13.39 /** 13.40 * Constructor 13.41 - * @throws IOException 13.42 */ 13.43 - public CodeStore(final Context context, final String path) throws IOException { 13.44 - this(context, path, DEFAULT_MIN_SIZE); 13.45 - } 13.46 - 13.47 - /** 13.48 - * Constructor 13.49 - * @param path directory to store code in 13.50 - * @param minSize minimum file size for caching scripts 13.51 - * @throws IOException 13.52 - */ 13.53 - public CodeStore(final Context context, final String path, final int minSize) throws IOException { 13.54 - this.dir = checkDirectory(path); 13.55 - this.minSize = minSize; 13.56 - this.log = initLogger(context); 13.57 + protected CodeStore() { 13.58 } 13.59 13.60 @Override 13.61 public DebugLogger initLogger(final Context context) { 13.62 - return context.getLogger(getClass()); 13.63 + log = context.getLogger(getClass()); 13.64 + return log; 13.65 } 13.66 13.67 @Override 13.68 @@ -86,29 +77,101 @@ 13.69 return log; 13.70 } 13.71 13.72 - private static File checkDirectory(final String path) throws IOException { 13.73 + /** 13.74 + * Returns a new code store instance. 13.75 + * 13.76 + * @param context the current context 13.77 + * @return The instance 13.78 + * @throws IOException If an error occurs 13.79 + */ 13.80 + public static CodeStore newCodeStore(final Context context) throws IOException { 13.81 + final Class<CodeStore> baseClass = CodeStore.class; 13.82 try { 13.83 - return AccessController.doPrivileged(new PrivilegedExceptionAction<File>() { 13.84 - @Override 13.85 - public File run() throws IOException { 13.86 - final File dir = new File(path).getAbsoluteFile(); 13.87 - if (!dir.exists() && !dir.mkdirs()) { 13.88 - throw new IOException("Could not create directory: " + dir.getPath()); 13.89 - } else if (!dir.isDirectory()) { 13.90 - throw new IOException("Not a directory: " + dir.getPath()); 13.91 - } else if (!dir.canRead() || !dir.canWrite()) { 13.92 - throw new IOException("Directory not readable or writable: " + dir.getPath()); 13.93 - } 13.94 - return dir; 13.95 - } 13.96 - }); 13.97 - } catch (final PrivilegedActionException e) { 13.98 - throw (IOException) e.getException(); 13.99 + // security check first 13.100 + final SecurityManager sm = System.getSecurityManager(); 13.101 + if (sm != null) { 13.102 + sm.checkPermission(new RuntimePermission(NASHORN_PROVIDE_CODE_STORE)); 13.103 + } 13.104 + final ServiceLoader<CodeStore> services = ServiceLoader.load(baseClass); 13.105 + final Iterator<CodeStore> iterator = services.iterator(); 13.106 + if (iterator.hasNext()) { 13.107 + final CodeStore store = iterator.next(); 13.108 + store.initLogger(context).info("using code store provider ", store.getClass().getCanonicalName()); 13.109 + return store; 13.110 + } 13.111 + } catch (final AccessControlException e) { 13.112 + context.getLogger(CodeStore.class).warning("failed to load code store provider ", e); 13.113 } 13.114 + final CodeStore store = new DirectoryCodeStore(); 13.115 + store.initLogger(context); 13.116 + return store; 13.117 } 13.118 13.119 - private File getCacheFile(final Source source, final String functionKey) { 13.120 - return new File(dir, source.getDigest() + '-' + functionKey); 13.121 + 13.122 + /** 13.123 + * Store a compiled script in the cache. 13.124 + * 13.125 + * @param functionKey the function key 13.126 + * @param source the source 13.127 + * @param mainClassName the main class name 13.128 + * @param classBytes a map of class bytes 13.129 + * @param initializers the function initializers 13.130 + * @param constants the constants array 13.131 + * @param compilationId the compilation id 13.132 + */ 13.133 + public StoredScript store(final String functionKey, 13.134 + final Source source, 13.135 + final String mainClassName, 13.136 + final Map<String, byte[]> classBytes, 13.137 + final Map<Integer, FunctionInitializer> initializers, 13.138 + final Object[] constants, 13.139 + final int compilationId) { 13.140 + return store(functionKey, source, storedScriptFor(source, mainClassName, classBytes, initializers, constants, compilationId)); 13.141 + } 13.142 + 13.143 + /** 13.144 + * Stores a compiled script. 13.145 + * 13.146 + * @param functionKey the function key 13.147 + * @param source the source 13.148 + * @param script The compiled script 13.149 + * @return The compiled script or {@code null} if not stored 13.150 + */ 13.151 + public abstract StoredScript store(final String functionKey, 13.152 + final Source source, 13.153 + final StoredScript script); 13.154 + 13.155 + /** 13.156 + * Return a compiled script from the cache, or null if it isn't found. 13.157 + * 13.158 + * @param source the source 13.159 + * @param functionKey the function key 13.160 + * @return the stored script or null 13.161 + */ 13.162 + public abstract StoredScript load(final Source source, final String functionKey); 13.163 + 13.164 + /** 13.165 + * Returns a new StoredScript instance. 13.166 + * 13.167 + * @param mainClassName the main class name 13.168 + * @param classBytes a map of class bytes 13.169 + * @param initializers function initializers 13.170 + * @param constants the constants array 13.171 + * @param compilationId the compilation id 13.172 + * @return The compiled script 13.173 + */ 13.174 + public StoredScript storedScriptFor(final Source source, final String mainClassName, 13.175 + final Map<String, byte[]> classBytes, 13.176 + final Map<Integer, FunctionInitializer> initializers, 13.177 + final Object[] constants, final int compilationId) { 13.178 + for (final Object constant : constants) { 13.179 + // Make sure all constant data is serializable 13.180 + if (!(constant instanceof Serializable)) { 13.181 + getLogger().warning("cannot store ", source, " non serializable constant ", constant); 13.182 + return null; 13.183 + } 13.184 + } 13.185 + return new StoredScript(compilationId, mainClassName, classBytes, initializers, constants); 13.186 } 13.187 13.188 /** 13.189 @@ -129,77 +192,130 @@ 13.190 } 13.191 13.192 /** 13.193 - * Return a compiled script from the cache, or null if it isn't found. 13.194 - * 13.195 - * @param source the source 13.196 - * @param functionKey the function key 13.197 - * @return the stored script or null 13.198 + * A store using a file system directory. 13.199 */ 13.200 - public StoredScript loadScript(final Source source, final String functionKey) { 13.201 - if (source.getLength() < minSize) { 13.202 - return null; 13.203 + public static class DirectoryCodeStore extends CodeStore { 13.204 + 13.205 + // Default minimum size for storing a compiled script class 13.206 + private final static int DEFAULT_MIN_SIZE = 1000; 13.207 + 13.208 + private final File dir; 13.209 + private final boolean readOnly; 13.210 + private final int minSize; 13.211 + 13.212 + /** 13.213 + * Constructor 13.214 + * 13.215 + * @throws IOException 13.216 + */ 13.217 + public DirectoryCodeStore() throws IOException { 13.218 + this(Options.getStringProperty("nashorn.persistent.code.cache", "nashorn_code_cache"), false, DEFAULT_MIN_SIZE); 13.219 } 13.220 13.221 - final File file = getCacheFile(source, functionKey); 13.222 + /** 13.223 + * Constructor 13.224 + * 13.225 + * @param path directory to store code in 13.226 + * @param minSize minimum file size for caching scripts 13.227 + * @throws IOException 13.228 + */ 13.229 + public DirectoryCodeStore(final String path, final boolean readOnly, final int minSize) throws IOException { 13.230 + this.dir = checkDirectory(path, readOnly); 13.231 + this.readOnly = readOnly; 13.232 + this.minSize = minSize; 13.233 + } 13.234 13.235 - try { 13.236 - return AccessController.doPrivileged(new PrivilegedExceptionAction<StoredScript>() { 13.237 - @Override 13.238 - public StoredScript run() throws IOException, ClassNotFoundException { 13.239 - if (!file.exists()) { 13.240 - return null; 13.241 + private static File checkDirectory(final String path, final boolean readOnly) throws IOException { 13.242 + try { 13.243 + return AccessController.doPrivileged(new PrivilegedExceptionAction<File>() { 13.244 + @Override 13.245 + public File run() throws IOException { 13.246 + final File dir = new File(path).getAbsoluteFile(); 13.247 + if (readOnly) { 13.248 + if (!dir.exists() || !dir.isDirectory()) { 13.249 + throw new IOException("Not a directory: " + dir.getPath()); 13.250 + } else if (!dir.canRead()) { 13.251 + throw new IOException("Directory not readable: " + dir.getPath()); 13.252 + } 13.253 + } else if (!dir.exists() && !dir.mkdirs()) { 13.254 + throw new IOException("Could not create directory: " + dir.getPath()); 13.255 + } else if (!dir.isDirectory()) { 13.256 + throw new IOException("Not a directory: " + dir.getPath()); 13.257 + } else if (!dir.canRead() || !dir.canWrite()) { 13.258 + throw new IOException("Directory not readable or writable: " + dir.getPath()); 13.259 + } 13.260 + return dir; 13.261 } 13.262 - try (ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file)))) { 13.263 - final StoredScript storedScript = (StoredScript) in.readObject(); 13.264 - getLogger().info("loaded ", source, "-", functionKey); 13.265 - return storedScript; 13.266 - } 13.267 - } 13.268 - }); 13.269 - } catch (final PrivilegedActionException e) { 13.270 - getLogger().warning("failed to load ", source, "-", functionKey, ": ", e.getException()); 13.271 - return null; 13.272 - } 13.273 - } 13.274 - 13.275 - /** 13.276 - * Store a compiled script in the cache. 13.277 - * 13.278 - * @param functionKey the function key 13.279 - * @param source the source 13.280 - * @param mainClassName the main class name 13.281 - * @param classBytes a map of class bytes 13.282 - * @param constants the constants array 13.283 - */ 13.284 - public void storeScript(final String functionKey, final Source source, final String mainClassName, final Map<String, byte[]> classBytes, 13.285 - final Map<Integer, FunctionInitializer> initializers, final Object[] constants, final int compilationId) { 13.286 - if (source.getLength() < minSize) { 13.287 - return; 13.288 - } 13.289 - for (final Object constant : constants) { 13.290 - // Make sure all constant data is serializable 13.291 - if (! (constant instanceof Serializable)) { 13.292 - getLogger().warning("cannot store ", source, " non serializable constant ", constant); 13.293 - return; 13.294 + }); 13.295 + } catch (final PrivilegedActionException e) { 13.296 + throw (IOException) e.getException(); 13.297 } 13.298 } 13.299 13.300 - final File file = getCacheFile(source, functionKey); 13.301 - final StoredScript script = new StoredScript(compilationId, mainClassName, classBytes, initializers, constants); 13.302 + @Override 13.303 + public StoredScript load(final Source source, final String functionKey) { 13.304 + if (source.getLength() < minSize) { 13.305 + return null; 13.306 + } 13.307 13.308 - try { 13.309 - AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() { 13.310 - @Override 13.311 - public Void run() throws IOException { 13.312 - try (ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)))) { 13.313 - out.writeObject(script); 13.314 + final File file = getCacheFile(source, functionKey); 13.315 + 13.316 + try { 13.317 + return AccessController.doPrivileged(new PrivilegedExceptionAction<StoredScript>() { 13.318 + @Override 13.319 + public StoredScript run() throws IOException, ClassNotFoundException { 13.320 + if (!file.exists()) { 13.321 + return null; 13.322 + } 13.323 + try (ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file)))) { 13.324 + final StoredScript storedScript = (StoredScript) in.readObject(); 13.325 + getLogger().info("loaded ", source, "-", functionKey); 13.326 + return storedScript; 13.327 + } 13.328 } 13.329 - getLogger().info("stored ", source, "-", functionKey); 13.330 - return null; 13.331 - } 13.332 - }); 13.333 - } catch (final PrivilegedActionException e) { 13.334 - getLogger().warning("failed to store ", script, "-", functionKey, ": ", e.getException()); 13.335 + }); 13.336 + } catch (final PrivilegedActionException e) { 13.337 + getLogger().warning("failed to load ", source, "-", functionKey, ": ", e.getException()); 13.338 + return null; 13.339 + } 13.340 + } 13.341 + 13.342 + @Override 13.343 + public StoredScript store(final String functionKey, final Source source, final StoredScript script) { 13.344 + if (readOnly || script == null || belowThreshold(source)) { 13.345 + return null; 13.346 + } 13.347 + 13.348 + final File file = getCacheFile(source, functionKey); 13.349 + 13.350 + try { 13.351 + return AccessController.doPrivileged(new PrivilegedExceptionAction<StoredScript>() { 13.352 + @Override 13.353 + public StoredScript run() throws IOException { 13.354 + try (ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)))) { 13.355 + out.writeObject(script); 13.356 + } 13.357 + getLogger().info("stored ", source, "-", functionKey); 13.358 + return script; 13.359 + } 13.360 + }); 13.361 + } catch (final PrivilegedActionException e) { 13.362 + getLogger().warning("failed to store ", script, "-", functionKey, ": ", e.getException()); 13.363 + return null; 13.364 + } 13.365 + } 13.366 + 13.367 + 13.368 + private File getCacheFile(final Source source, final String functionKey) { 13.369 + return new File(dir, source.getDigest() + '-' + functionKey); 13.370 + } 13.371 + 13.372 + private boolean belowThreshold(final Source source) { 13.373 + if (source.getLength() < minSize) { 13.374 + getLogger().info("below size threshold ", source); 13.375 + return true; 13.376 + } 13.377 + return false; 13.378 } 13.379 } 13.380 }
14.1 --- a/src/jdk/nashorn/internal/runtime/Context.java Wed Sep 17 13:53:36 2014 -0700 14.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java Mon Sep 22 18:34:06 2014 -0700 14.3 @@ -29,6 +29,7 @@ 14.4 import static jdk.nashorn.internal.codegen.CompilerConstants.CREATE_PROGRAM_FUNCTION; 14.5 import static jdk.nashorn.internal.codegen.CompilerConstants.SOURCE; 14.6 import static jdk.nashorn.internal.codegen.CompilerConstants.STRICT_MODE; 14.7 +import static jdk.nashorn.internal.runtime.CodeStore.newCodeStore; 14.8 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; 14.9 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; 14.10 import static jdk.nashorn.internal.runtime.Source.sourceFor; 14.11 @@ -200,14 +201,14 @@ 14.12 final Map<String,byte[]> classBytes, final Map<Integer, FunctionInitializer> initializers, 14.13 final Object[] constants, final int compilationId) { 14.14 if (context.codeStore != null) { 14.15 - context.codeStore.storeScript(cacheKey, source, mainClassName, classBytes, initializers, constants, compilationId); 14.16 + context.codeStore.store(cacheKey, source, mainClassName, classBytes, initializers, constants, compilationId); 14.17 } 14.18 } 14.19 14.20 @Override 14.21 public StoredScript loadScript(final Source source, final String functionKey) { 14.22 if (context.codeStore != null) { 14.23 - return context.codeStore.loadScript(source, functionKey); 14.24 + return context.codeStore.load(source, functionKey); 14.25 } 14.26 return null; 14.27 } 14.28 @@ -463,8 +464,7 @@ 14.29 14.30 if (env._persistent_cache) { 14.31 try { 14.32 - final String cacheDir = Options.getStringProperty("nashorn.persistent.code.cache", "nashorn_code_cache"); 14.33 - codeStore = new CodeStore(this, cacheDir); 14.34 + codeStore = newCodeStore(this); 14.35 } catch (final IOException e) { 14.36 throw new RuntimeException("Error initializing code cache", e); 14.37 } 14.38 @@ -1117,7 +1117,7 @@ 14.39 final String cacheKey = useCodeStore ? CodeStore.getCacheKey(0, null) : null; 14.40 14.41 if (useCodeStore) { 14.42 - storedScript = codeStore.loadScript(source, cacheKey); 14.43 + storedScript = codeStore.load(source, cacheKey); 14.44 } 14.45 14.46 if (storedScript == null) { 14.47 @@ -1194,15 +1194,16 @@ 14.48 private static Class<?> install(final StoredScript storedScript, final Source source, final CodeInstaller<ScriptEnvironment> installer) { 14.49 14.50 final Map<String, Class<?>> installedClasses = new HashMap<>(); 14.51 + final Map<String, byte[]> classBytes = storedScript.getClassBytes(); 14.52 final Object[] constants = storedScript.getConstants(); 14.53 final String mainClassName = storedScript.getMainClassName(); 14.54 - final byte[] mainClassBytes = storedScript.getClassBytes().get(mainClassName); 14.55 + final byte[] mainClassBytes = classBytes.get(mainClassName); 14.56 final Class<?> mainClass = installer.install(mainClassName, mainClassBytes); 14.57 final Map<Integer, FunctionInitializer> initialzers = storedScript.getInitializers(); 14.58 14.59 installedClasses.put(mainClassName, mainClass); 14.60 14.61 - for (final Map.Entry<String, byte[]> entry : storedScript.getClassBytes().entrySet()) { 14.62 + for (final Map.Entry<String, byte[]> entry : classBytes.entrySet()) { 14.63 final String className = entry.getKey(); 14.64 if (className.equals(mainClassName)) { 14.65 continue;
15.1 --- a/src/jdk/nashorn/internal/runtime/DefaultPropertyAccess.java Wed Sep 17 13:53:36 2014 -0700 15.2 +++ b/src/jdk/nashorn/internal/runtime/DefaultPropertyAccess.java Mon Sep 22 18:34:06 2014 -0700 15.3 @@ -112,82 +112,82 @@ 15.4 } 15.5 15.6 @Override 15.7 - public void set(final double key, final int value, final boolean strict) { 15.8 - set(JSType.toObject(key), JSType.toObject(value), strict); 15.9 + public void set(final double key, final int value, final int flags) { 15.10 + set(JSType.toObject(key), JSType.toObject(value), flags); 15.11 } 15.12 15.13 @Override 15.14 - public void set(final double key, final long value, final boolean strict) { 15.15 - set(JSType.toObject(key), JSType.toObject(value), strict); 15.16 + public void set(final double key, final long value, final int flags) { 15.17 + set(JSType.toObject(key), JSType.toObject(value), flags); 15.18 } 15.19 15.20 @Override 15.21 - public void set(final double key, final double value, final boolean strict) { 15.22 - set(JSType.toObject(key), JSType.toObject(value), strict); 15.23 + public void set(final double key, final double value, final int flags) { 15.24 + set(JSType.toObject(key), JSType.toObject(value), flags); 15.25 } 15.26 15.27 @Override 15.28 - public void set(final double key, final Object value, final boolean strict) { 15.29 - set(JSType.toObject(key), JSType.toObject(value), strict); 15.30 + public void set(final double key, final Object value, final int flags) { 15.31 + set(JSType.toObject(key), JSType.toObject(value), flags); 15.32 } 15.33 15.34 @Override 15.35 - public void set(final long key, final int value, final boolean strict) { 15.36 - set(JSType.toObject(key), JSType.toObject(value), strict); 15.37 + public void set(final long key, final int value, final int flags) { 15.38 + set(JSType.toObject(key), JSType.toObject(value), flags); 15.39 } 15.40 15.41 @Override 15.42 - public void set(final long key, final long value, final boolean strict) { 15.43 - set(JSType.toObject(key), JSType.toObject(value), strict); 15.44 + public void set(final long key, final long value, final int flags) { 15.45 + set(JSType.toObject(key), JSType.toObject(value), flags); 15.46 } 15.47 15.48 @Override 15.49 - public void set(final long key, final double value, final boolean strict) { 15.50 - set(JSType.toObject(key), JSType.toObject(value), strict); 15.51 + public void set(final long key, final double value, final int flags) { 15.52 + set(JSType.toObject(key), JSType.toObject(value), flags); 15.53 } 15.54 15.55 @Override 15.56 - public void set(final long key, final Object value, final boolean strict) { 15.57 - set(JSType.toObject(key), value, strict); 15.58 + public void set(final long key, final Object value, final int flags) { 15.59 + set(JSType.toObject(key), value, flags); 15.60 } 15.61 15.62 @Override 15.63 - public void set(final int key, final int value, final boolean strict) { 15.64 - set(JSType.toObject(key), JSType.toObject(value), strict); 15.65 + public void set(final int key, final int value, final int flags) { 15.66 + set(JSType.toObject(key), JSType.toObject(value), flags); 15.67 } 15.68 15.69 @Override 15.70 - public void set(final int key, final long value, final boolean strict) { 15.71 - set(JSType.toObject(key), JSType.toObject(value), strict); 15.72 + public void set(final int key, final long value, final int flags) { 15.73 + set(JSType.toObject(key), JSType.toObject(value), flags); 15.74 } 15.75 15.76 @Override 15.77 - public void set(final int key, final double value, final boolean strict) { 15.78 - set(JSType.toObject(key), JSType.toObject(value), strict); 15.79 + public void set(final int key, final double value, final int flags) { 15.80 + set(JSType.toObject(key), JSType.toObject(value), flags); 15.81 } 15.82 15.83 @Override 15.84 - public void set(final int key, final Object value, final boolean strict) { 15.85 - set(JSType.toObject(key), value, strict); 15.86 + public void set(final int key, final Object value, final int flags) { 15.87 + set(JSType.toObject(key), value, flags); 15.88 } 15.89 15.90 @Override 15.91 - public void set(final Object key, final int value, final boolean strict) { 15.92 - set(key, JSType.toObject(value), strict); 15.93 + public void set(final Object key, final int value, final int flags) { 15.94 + set(key, JSType.toObject(value), flags); 15.95 } 15.96 15.97 @Override 15.98 - public void set(final Object key, final long value, final boolean strict) { 15.99 - set(key, JSType.toObject(value), strict); 15.100 + public void set(final Object key, final long value, final int flags) { 15.101 + set(key, JSType.toObject(value), flags); 15.102 } 15.103 15.104 @Override 15.105 - public void set(final Object key, final double value, final boolean strict) { 15.106 - set(key, JSType.toObject(value), strict); 15.107 + public void set(final Object key, final double value, final int flags) { 15.108 + set(key, JSType.toObject(value), flags); 15.109 } 15.110 15.111 @Override 15.112 - public abstract void set(Object key, Object value, boolean strict); 15.113 + public abstract void set(Object key, Object value, int flags); 15.114 15.115 @Override 15.116 public abstract boolean has(Object key);
16.1 --- a/src/jdk/nashorn/internal/runtime/ECMAException.java Wed Sep 17 13:53:36 2014 -0700 16.2 +++ b/src/jdk/nashorn/internal/runtime/ECMAException.java Mon Sep 22 18:34:06 2014 -0700 16.3 @@ -285,7 +285,7 @@ 16.4 if (!sobj.has(EXCEPTION_PROPERTY)) { 16.5 sobj.addOwnProperty(EXCEPTION_PROPERTY, Property.NOT_ENUMERABLE, this); 16.6 } else { 16.7 - sobj.set(EXCEPTION_PROPERTY, this, false); 16.8 + sobj.set(EXCEPTION_PROPERTY, this, 0); 16.9 } 16.10 } 16.11 }
17.1 --- a/src/jdk/nashorn/internal/runtime/FindProperty.java Wed Sep 17 13:53:36 2014 -0700 17.2 +++ b/src/jdk/nashorn/internal/runtime/FindProperty.java Mon Sep 22 18:34:06 2014 -0700 17.3 @@ -139,6 +139,17 @@ 17.4 } 17.5 17.6 /** 17.7 + * Return the {@code ScriptObject} where the search started. This is usually the ScriptObject the 17.8 + * operation was started on, except for properties found inside a 'with' statement, where it is the 17.9 + * top-level 'with' expression object. 17.10 + * 17.11 + * @return the start object. 17.12 + */ 17.13 + public ScriptObject getSelf() { 17.14 + return self; 17.15 + } 17.16 + 17.17 + /** 17.18 * Return the appropriate receiver for a getter. 17.19 * @return appropriate receiver 17.20 */
18.1 --- a/src/jdk/nashorn/internal/runtime/FunctionInitializer.java Wed Sep 17 13:53:36 2014 -0700 18.2 +++ b/src/jdk/nashorn/internal/runtime/FunctionInitializer.java Mon Sep 22 18:34:06 2014 -0700 18.3 @@ -60,6 +60,17 @@ 18.4 } 18.5 18.6 /** 18.7 + * Copy constructor. 18.8 + * 18.9 + * @param init original initializer 18.10 + */ 18.11 + FunctionInitializer(final FunctionInitializer init) { 18.12 + this.className = init.getClassName(); 18.13 + this.methodType = init.getMethodType(); 18.14 + this.flags = init.getFlags(); 18.15 + } 18.16 + 18.17 + /** 18.18 * Constructor. 18.19 * 18.20 * @param functionNode the function node
19.1 --- a/src/jdk/nashorn/internal/runtime/GlobalConstants.java Wed Sep 17 13:53:36 2014 -0700 19.2 +++ b/src/jdk/nashorn/internal/runtime/GlobalConstants.java Mon Sep 22 18:34:06 2014 -0700 19.3 @@ -309,7 +309,7 @@ 19.4 * 19.5 * @param find property lookup 19.6 * @param inv normal guarded invocation for this setter, as computed by the ScriptObject linker 19.7 - * @param desc callsite descriptr 19.8 + * @param desc callsite descriptor 19.9 * @param request link request 19.10 * 19.11 * @return null if failed to set up constant linkage 19.12 @@ -376,8 +376,12 @@ 19.13 * @return resulting getter, or null if failed to create constant 19.14 */ 19.15 synchronized GuardedInvocation findGetMethod(final FindProperty find, final ScriptObject receiver, final CallSiteDescriptor desc) { 19.16 - // Also return null if property may have side effects 19.17 - if ((GLOBAL_ONLY && !find.getOwner().isGlobal()) || find.getProperty() instanceof UserAccessorProperty) { 19.18 + // Only use constant getter for fast scope access, because the receiver may change between invocations 19.19 + // for slow-scope and non-scope callsites. 19.20 + // Also return null for user accessor properties as they may have side effects. 19.21 + if (!NashornCallSiteDescriptor.isFastScope(desc) 19.22 + || (GLOBAL_ONLY && !find.getOwner().isGlobal()) 19.23 + || find.getProperty() instanceof UserAccessorProperty) { 19.24 return null; 19.25 } 19.26
20.1 --- a/src/jdk/nashorn/internal/runtime/JSONFunctions.java Wed Sep 17 13:53:36 2014 -0700 20.2 +++ b/src/jdk/nashorn/internal/runtime/JSONFunctions.java Mon Sep 22 18:34:06 2014 -0700 20.3 @@ -122,7 +122,7 @@ 20.4 if (newElement == ScriptRuntime.UNDEFINED) { 20.5 valueObj.delete(key, false); 20.6 } else { 20.7 - setPropertyValue(valueObj, key, newElement, false); 20.8 + setPropertyValue(valueObj, key, newElement); 20.9 } 20.10 } 20.11 } 20.12 @@ -179,7 +179,7 @@ 20.13 20.14 final String name = pNode.getKeyName(); 20.15 final Object value = convertNode(global, valueNode); 20.16 - setPropertyValue(object, name, value, false); 20.17 + setPropertyValue(object, name, value); 20.18 } 20.19 20.20 return object; 20.21 @@ -193,14 +193,14 @@ 20.22 } 20.23 20.24 // add a new property if does not exist already, or else set old property 20.25 - private static void setPropertyValue(final ScriptObject sobj, final String name, final Object value, final boolean strict) { 20.26 + private static void setPropertyValue(final ScriptObject sobj, final String name, final Object value) { 20.27 final int index = ArrayIndex.getArrayIndex(name); 20.28 if (ArrayIndex.isValidArrayIndex(index)) { 20.29 // array index key 20.30 sobj.defineOwnProperty(index, value); 20.31 } else if (sobj.getMap().findProperty(name) != null) { 20.32 // pre-existing non-inherited property, call set 20.33 - sobj.set(name, value, strict); 20.34 + sobj.set(name, value, 0); 20.35 } else { 20.36 // add new property 20.37 sobj.addOwnProperty(name, Property.WRITABLE_ENUMERABLE_CONFIGURABLE, value);
21.1 --- a/src/jdk/nashorn/internal/runtime/NativeJavaPackage.java Wed Sep 17 13:53:36 2014 -0700 21.2 +++ b/src/jdk/nashorn/internal/runtime/NativeJavaPackage.java Mon Sep 22 18:34:06 2014 -0700 21.3 @@ -256,7 +256,7 @@ 21.4 final Object constructor = BeansLinker.getConstructorMethod( 21.5 javaClass, propertyName.substring(openBrace + 1, lastChar)); 21.6 if (constructor != null) { 21.7 - set(propertyName, constructor, false); 21.8 + set(propertyName, constructor, 0); 21.9 return constructor; 21.10 } 21.11 // we didn't find a matching constructor! 21.12 @@ -270,7 +270,7 @@ 21.13 propertyValue = StaticClass.forClass(javaClass); 21.14 } 21.15 21.16 - set(propertyName, propertyValue, false); 21.17 + set(propertyName, propertyValue, 0); 21.18 return propertyValue; 21.19 } 21.20 }
22.1 --- a/src/jdk/nashorn/internal/runtime/Property.java Wed Sep 17 13:53:36 2014 -0700 22.2 +++ b/src/jdk/nashorn/internal/runtime/Property.java Mon Sep 22 18:34:06 2014 -0700 22.3 @@ -101,7 +101,7 @@ 22.4 private final int slot; 22.5 22.6 /** SwitchPoint that is invalidated when property is changed, optional */ 22.7 - protected SwitchPoint changeCallback; 22.8 + protected transient SwitchPoint changeCallback; 22.9 22.10 private static final long serialVersionUID = 2099814273074501176L; 22.11
23.1 --- a/src/jdk/nashorn/internal/runtime/PropertyAccess.java Wed Sep 17 13:53:36 2014 -0700 23.2 +++ b/src/jdk/nashorn/internal/runtime/PropertyAccess.java Mon Sep 22 18:34:06 2014 -0700 23.3 @@ -163,129 +163,129 @@ 23.4 * Set the value of a given key 23.5 * @param key the key 23.6 * @param value the value 23.7 - * @param strict are we in strict mode 23.8 + * @param flags call site flags 23.9 */ 23.10 - public void set(Object key, int value, boolean strict); 23.11 + public void set(Object key, int value, int flags); 23.12 23.13 /** 23.14 * Set the value of a given key 23.15 * @param key the key 23.16 * @param value the value 23.17 - * @param strict are we in strict mode 23.18 + * @param flags call site flags 23.19 */ 23.20 - public void set(Object key, long value, boolean strict); 23.21 + public void set(Object key, long value, int flags); 23.22 23.23 /** 23.24 * Set the value of a given key 23.25 * @param key the key 23.26 * @param value the value 23.27 - * @param strict are we in strict mode 23.28 + * @param flags call site flags 23.29 */ 23.30 - public void set(Object key, double value, boolean strict); 23.31 + public void set(Object key, double value, int flags); 23.32 23.33 /** 23.34 * Set the value of a given key 23.35 * @param key the key 23.36 * @param value the value 23.37 - * @param strict are we in strict mode 23.38 + * @param flags call site flags 23.39 */ 23.40 - public void set(Object key, Object value, boolean strict); 23.41 + public void set(Object key, Object value, int flags); 23.42 23.43 /** 23.44 * Set the value of a given key 23.45 * @param key the key 23.46 * @param value the value 23.47 - * @param strict are we in strict mode 23.48 + * @param flags call site flags 23.49 */ 23.50 - public void set(double key, int value, boolean strict); 23.51 + public void set(double key, int value, int flags); 23.52 23.53 /** 23.54 * Set the value of a given key 23.55 * @param key the key 23.56 * @param value the value 23.57 - * @param strict are we in strict mode 23.58 + * @param flags call site flags 23.59 */ 23.60 - public void set(double key, long value, boolean strict); 23.61 + public void set(double key, long value, int flags); 23.62 23.63 /** 23.64 * Set the value of a given key 23.65 * @param key the key 23.66 * @param value the value 23.67 - * @param strict are we in strict mode 23.68 + * @param flags call site flags 23.69 */ 23.70 - public void set(double key, double value, boolean strict); 23.71 + public void set(double key, double value, int flags); 23.72 23.73 /** 23.74 * Set the value of a given key 23.75 * @param key the key 23.76 * @param value the value 23.77 - * @param strict are we in strict mode 23.78 + * @param flags call site flags 23.79 */ 23.80 - public void set(double key, Object value, boolean strict); 23.81 + public void set(double key, Object value, int flags); 23.82 23.83 /** 23.84 * Set the value of a given key 23.85 * @param key the key 23.86 * @param value the value 23.87 - * @param strict are we in strict mode 23.88 + * @param flags call site flags 23.89 */ 23.90 - public void set(long key, int value, boolean strict); 23.91 + public void set(long key, int value, int flags); 23.92 23.93 /** 23.94 * Set the value of a given key 23.95 * @param key the key 23.96 * @param value the value 23.97 - * @param strict are we in strict mode 23.98 + * @param flags call site flags 23.99 */ 23.100 - public void set(long key, long value, boolean strict); 23.101 + public void set(long key, long value, int flags); 23.102 23.103 /** 23.104 * Set the value of a given key 23.105 * @param key the key 23.106 * @param value the value 23.107 - * @param strict are we in strict mode 23.108 + * @param flags call site flags 23.109 */ 23.110 - public void set(long key, double value, boolean strict); 23.111 + public void set(long key, double value, int flags); 23.112 23.113 /** 23.114 * Set the value of a given key 23.115 * @param key the key 23.116 * @param value the value 23.117 - * @param strict are we in strict mode 23.118 + * @param flags call site flags 23.119 */ 23.120 - public void set(long key, Object value, boolean strict); 23.121 + public void set(long key, Object value, int flags); 23.122 23.123 /** 23.124 * Set the value of a given key 23.125 * @param key the key 23.126 * @param value the value 23.127 - * @param strict are we in strict mode 23.128 + * @param flags call site flags 23.129 */ 23.130 - public void set(int key, int value, boolean strict); 23.131 + public void set(int key, int value, int flags); 23.132 23.133 /** 23.134 * Set the value of a given key 23.135 * @param key the key 23.136 * @param value the value 23.137 - * @param strict are we in strict mode 23.138 + * @param flags call site flags 23.139 */ 23.140 - public void set(int key, long value, boolean strict); 23.141 + public void set(int key, long value, int flags); 23.142 23.143 /** 23.144 * Set the value of a given key 23.145 * @param key the key 23.146 * @param value the value 23.147 - * @param strict are we in strict mode 23.148 + * @param flags call site flags 23.149 */ 23.150 - public void set(int key, double value, boolean strict); 23.151 + public void set(int key, double value, int flags); 23.152 23.153 /** 23.154 * Set the value of a given key 23.155 * @param key the key 23.156 * @param value the value 23.157 - * @param strict are we in strict mode 23.158 + * @param flags call site flags 23.159 */ 23.160 - public void set(int key, Object value, boolean strict); 23.161 + public void set(int key, Object value, int flags); 23.162 23.163 /** 23.164 * Check if the given key exists anywhere in the proto chain
24.1 --- a/src/jdk/nashorn/internal/runtime/PropertyMap.java Wed Sep 17 13:53:36 2014 -0700 24.2 +++ b/src/jdk/nashorn/internal/runtime/PropertyMap.java Mon Sep 22 18:34:06 2014 -0700 24.3 @@ -568,9 +568,7 @@ 24.4 for (final Property property : otherProperties) { 24.5 // This method is only safe to use with non-slotted, native getter/setter properties 24.6 assert property.getSlot() == -1; 24.7 - if (isValidArrayIndex(getArrayIndex(property.getKey()))) { 24.8 - newMap.setContainsArrayKeys(); 24.9 - } 24.10 + assert !(isValidArrayIndex(getArrayIndex(property.getKey()))); 24.11 } 24.12 24.13 return newMap;
25.1 --- a/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Wed Sep 17 13:53:36 2014 -0700 25.2 +++ b/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Mon Sep 22 18:34:06 2014 -0700 25.3 @@ -491,14 +491,15 @@ 25.4 private FunctionInitializer install(final StoredScript script) { 25.5 25.6 final Map<String, Class<?>> installedClasses = new HashMap<>(); 25.7 + final Map<String, byte[]> classBytes = script.getClassBytes(); 25.8 final String mainClassName = script.getMainClassName(); 25.9 - final byte[] mainClassBytes = script.getClassBytes().get(mainClassName); 25.10 + final byte[] mainClassBytes = classBytes.get(mainClassName); 25.11 25.12 final Class<?> mainClass = installer.install(mainClassName, mainClassBytes); 25.13 25.14 installedClasses.put(mainClassName, mainClass); 25.15 25.16 - for (final Map.Entry<String, byte[]> entry : script.getClassBytes().entrySet()) { 25.17 + for (final Map.Entry<String, byte[]> entry : classBytes.entrySet()) { 25.18 final String className = entry.getKey(); 25.19 final byte[] code = entry.getValue(); 25.20
26.1 --- a/src/jdk/nashorn/internal/runtime/RewriteException.java Wed Sep 17 13:53:36 2014 -0700 26.2 +++ b/src/jdk/nashorn/internal/runtime/RewriteException.java Mon Sep 22 18:34:06 2014 -0700 26.3 @@ -45,6 +45,7 @@ 26.4 import jdk.nashorn.internal.lookup.MethodHandleFactory; 26.5 import jdk.nashorn.internal.lookup.MethodHandleFunctionality; 26.6 import jdk.nashorn.internal.objects.Global; 26.7 +import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; 26.8 26.9 /** 26.10 * Used to signal to the linker to relink the callee 26.11 @@ -161,7 +162,7 @@ 26.12 assert runtimeScope == null; 26.13 runtimeScope = (ScriptObject)value; 26.14 } else if(name != null) { 26.15 - locals.set(name, value, true); 26.16 + locals.set(name, value, NashornCallSiteDescriptor.CALLSITE_STRICT); 26.17 } 26.18 } 26.19 locals.setProto(runtimeScope);
27.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Wed Sep 17 13:53:36 2014 -0700 27.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Mon Sep 22 18:34:06 2014 -0700 27.3 @@ -198,10 +198,10 @@ 27.4 public static final Call SET_USER_ACCESSORS = virtualCall(MethodHandles.lookup(), ScriptObject.class, "setUserAccessors", void.class, String.class, ScriptFunction.class, ScriptFunction.class); 27.5 27.6 static final MethodHandle[] SET_SLOW = new MethodHandle[] { 27.7 - findOwnMH_V("set", void.class, Object.class, int.class, boolean.class), 27.8 - findOwnMH_V("set", void.class, Object.class, long.class, boolean.class), 27.9 - findOwnMH_V("set", void.class, Object.class, double.class, boolean.class), 27.10 - findOwnMH_V("set", void.class, Object.class, Object.class, boolean.class) 27.11 + findOwnMH_V("set", void.class, Object.class, int.class, int.class), 27.12 + findOwnMH_V("set", void.class, Object.class, long.class, int.class), 27.13 + findOwnMH_V("set", void.class, Object.class, double.class, int.class), 27.14 + findOwnMH_V("set", void.class, Object.class, Object.class, int.class) 27.15 }; 27.16 27.17 /** Method handle to reset the map of this ScriptObject */ 27.18 @@ -593,7 +593,7 @@ 27.19 if (newValue && property != null) { 27.20 // Temporarily clear flags. 27.21 property = modifyOwnProperty(property, 0); 27.22 - set(key, value, false); 27.23 + set(key, value, 0); 27.24 //this might change the map if we change types of the property 27.25 //hence we need to read it again. note that we should probably 27.26 //have the setter return the new property throughout and in 27.27 @@ -758,7 +758,7 @@ 27.28 * @return FindPropertyData or null if not found. 27.29 */ 27.30 public final FindProperty findProperty(final String key, final boolean deep) { 27.31 - return findProperty(key, deep, false, this); 27.32 + return findProperty(key, deep, this); 27.33 } 27.34 27.35 /** 27.36 @@ -775,16 +775,11 @@ 27.37 * 27.38 * @param key Property key. 27.39 * @param deep Whether the search should look up proto chain. 27.40 - * @param stopOnNonScope should a deep search stop on the first non-scope object? 27.41 * @param start the object on which the lookup was originally initiated 27.42 * 27.43 * @return FindPropertyData or null if not found. 27.44 */ 27.45 - FindProperty findProperty(final String key, final boolean deep, final boolean stopOnNonScope, final ScriptObject start) { 27.46 - // if doing deep search, stop search on the first non-scope object if asked to do so 27.47 - if (stopOnNonScope && start != this && !isScope()) { 27.48 - return null; 27.49 - } 27.50 + FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) { 27.51 27.52 final PropertyMap selfMap = getMap(); 27.53 final Property property = selfMap.findProperty(key); 27.54 @@ -796,7 +791,7 @@ 27.55 if (deep) { 27.56 final ScriptObject myProto = getProto(); 27.57 if (myProto != null) { 27.58 - return myProto.findProperty(key, deep, stopOnNonScope, start); 27.59 + return myProto.findProperty(key, deep, start); 27.60 } 27.61 } 27.62 27.63 @@ -1164,7 +1159,7 @@ 27.64 * @param value the value to write at the given index 27.65 */ 27.66 public void setArgument(final int key, final Object value) { 27.67 - set(key, value, false); 27.68 + set(key, value, 0); 27.69 } 27.70 27.71 /** 27.72 @@ -1725,7 +1720,8 @@ 27.73 */ 27.74 public Object put(final Object key, final Object value, final boolean strict) { 27.75 final Object oldValue = get(key); 27.76 - set(key, value, strict); 27.77 + final int flags = strict ? NashornCallSiteDescriptor.CALLSITE_STRICT : 0; 27.78 + set(key, value, flags); 27.79 return oldValue; 27.80 } 27.81 27.82 @@ -1738,8 +1734,9 @@ 27.83 * @param strict strict mode or not 27.84 */ 27.85 public void putAll(final Map<?, ?> otherMap, final boolean strict) { 27.86 + final int flags = strict ? NashornCallSiteDescriptor.CALLSITE_STRICT : 0; 27.87 for (final Map.Entry<?, ?> entry : otherMap.entrySet()) { 27.88 - set(entry.getKey(), entry.getValue(), strict); 27.89 + set(entry.getKey(), entry.getValue(), flags); 27.90 } 27.91 } 27.92 27.93 @@ -2042,7 +2039,7 @@ 27.94 27.95 final PropertyMap newMap = map.replaceProperty(property, property.removeFlags(Property.NEEDS_DECLARATION)); 27.96 setMap(newMap); 27.97 - set(key, value, true); 27.98 + set(key, value, 0); 27.99 } 27.100 27.101 /** 27.102 @@ -2135,7 +2132,6 @@ 27.103 return findMegaMorphicSetMethod(desc, name); 27.104 } 27.105 27.106 - final boolean scope = isScope(); 27.107 final boolean explicitInstanceOfCheck = explicitInstanceOfCheck(desc, request); 27.108 27.109 /* 27.110 @@ -2145,16 +2141,18 @@ 27.111 * 27.112 * toString = function() { print("global toString"); } // don't affect Object.prototype.toString 27.113 */ 27.114 - FindProperty find = findProperty(name, true, scope, this); 27.115 + FindProperty find = findProperty(name, true, this); 27.116 27.117 // If it's not a scope search, then we don't want any inherited properties except those with user defined accessors. 27.118 - if (!scope && find != null && find.isInherited() && !(find.getProperty() instanceof UserAccessorProperty)) { 27.119 + if (find != null && find.isInherited() && !(find.getProperty() instanceof UserAccessorProperty)) { 27.120 // We should still check if inherited data property is not writable 27.121 if (isExtensible() && !find.getProperty().isWritable()) { 27.122 - return createEmptySetMethod(desc, explicitInstanceOfCheck, "property.not.writable", false); 27.123 + return createEmptySetMethod(desc, explicitInstanceOfCheck, "property.not.writable", true); 27.124 } 27.125 - // Otherwise, forget the found property 27.126 - find = null; 27.127 + // Otherwise, forget the found property unless this is a scope callsite and the owner is a scope object as well. 27.128 + if (!NashornCallSiteDescriptor.isScope(desc) || !find.getOwner().isScope()) { 27.129 + find = null; 27.130 + } 27.131 } 27.132 27.133 if (find != null) { 27.134 @@ -2180,8 +2178,8 @@ 27.135 27.136 private GuardedInvocation createEmptySetMethod(final CallSiteDescriptor desc, final boolean explicitInstanceOfCheck, final String strictErrorMessage, final boolean canBeFastScope) { 27.137 final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND); 27.138 - if (NashornCallSiteDescriptor.isStrict(desc)) { 27.139 - throw typeError(strictErrorMessage, name, ScriptRuntime.safeToString(this)); 27.140 + if (NashornCallSiteDescriptor.isStrict(desc)) { 27.141 + throw typeError(strictErrorMessage, name, ScriptRuntime.safeToString(this)); 27.142 } 27.143 assert canBeFastScope || !NashornCallSiteDescriptor.isFastScope(desc); 27.144 return new GuardedInvocation( 27.145 @@ -2207,7 +2205,7 @@ 27.146 private GuardedInvocation findMegaMorphicSetMethod(final CallSiteDescriptor desc, final String name) { 27.147 final MethodType type = desc.getMethodType().insertParameterTypes(1, Object.class); 27.148 //never bother with ClassCastExceptionGuard for megamorphic callsites 27.149 - final GuardedInvocation inv = findSetIndexMethod(getClass(), false, type, NashornCallSiteDescriptor.isStrict(desc)); 27.150 + final GuardedInvocation inv = findSetIndexMethod(getClass(), desc, false, type); 27.151 return inv.replaceMethods(MH.insertArguments(inv.getInvocation(), 1, name), inv.getGuard()); 27.152 } 27.153 27.154 @@ -2230,24 +2228,26 @@ 27.155 * @return GuardedInvocation to be invoked at call site. 27.156 */ 27.157 protected GuardedInvocation findSetIndexMethod(final CallSiteDescriptor desc, final LinkRequest request) { // array, index, value 27.158 - return findSetIndexMethod(getClass(), explicitInstanceOfCheck(desc, request), desc.getMethodType(), NashornCallSiteDescriptor.isStrict(desc)); 27.159 + return findSetIndexMethod(getClass(), desc, explicitInstanceOfCheck(desc, request), desc.getMethodType()); 27.160 } 27.161 27.162 /** 27.163 * Find the appropriate SETINDEX method for an invoke dynamic call. 27.164 * 27.165 + * @param clazz the receiver class 27.166 + * @param desc the call site descriptor 27.167 + * @param explicitInstanceOfCheck add an explicit instanceof check? 27.168 * @param callType the method type at the call site 27.169 - * @param isStrict are we in strict mode? 27.170 * 27.171 * @return GuardedInvocation to be invoked at call site. 27.172 */ 27.173 - private static GuardedInvocation findSetIndexMethod(final Class<? extends ScriptObject> clazz, final boolean explicitInstanceOfCheck, final MethodType callType, final boolean isStrict) { 27.174 + private static GuardedInvocation findSetIndexMethod(final Class<? extends ScriptObject> clazz, final CallSiteDescriptor desc, final boolean explicitInstanceOfCheck, final MethodType callType) { 27.175 assert callType.parameterCount() == 3; 27.176 final Class<?> keyClass = callType.parameterType(1); 27.177 final Class<?> valueClass = callType.parameterType(2); 27.178 27.179 - MethodHandle methodHandle = findOwnMH_V(clazz, "set", void.class, keyClass, valueClass, boolean.class); 27.180 - methodHandle = MH.insertArguments(methodHandle, 3, isStrict); 27.181 + MethodHandle methodHandle = findOwnMH_V(clazz, "set", void.class, keyClass, valueClass, int.class); 27.182 + methodHandle = MH.insertArguments(methodHandle, 3, NashornCallSiteDescriptor.getFlags(desc)); 27.183 27.184 return new GuardedInvocation(methodHandle, getScriptObjectGuard(callType, explicitInstanceOfCheck), (SwitchPoint)null, explicitInstanceOfCheck ? null : ClassCastException.class); 27.185 } 27.186 @@ -2672,7 +2672,7 @@ 27.187 if (isValidArrayIndex(index)) { 27.188 for (ScriptObject object = this; ; ) { 27.189 if (object.getMap().containsArrayKeys()) { 27.190 - final FindProperty find = object.findProperty(key, false, false, this); 27.191 + final FindProperty find = object.findProperty(key, false, this); 27.192 27.193 if (find != null) { 27.194 return getIntValue(find, programPoint); 27.195 @@ -2755,7 +2755,7 @@ 27.196 if (isValidArrayIndex(index)) { 27.197 for (ScriptObject object = this; ; ) { 27.198 if (object.getMap().containsArrayKeys()) { 27.199 - final FindProperty find = object.findProperty(key, false, false, this); 27.200 + final FindProperty find = object.findProperty(key, false, this); 27.201 if (find != null) { 27.202 return getLongValue(find, programPoint); 27.203 } 27.204 @@ -2837,7 +2837,7 @@ 27.205 if (isValidArrayIndex(index)) { 27.206 for (ScriptObject object = this; ; ) { 27.207 if (object.getMap().containsArrayKeys()) { 27.208 - final FindProperty find = object.findProperty(key, false, false, this); 27.209 + final FindProperty find = object.findProperty(key, false, this); 27.210 if (find != null) { 27.211 return getDoubleValue(find, programPoint); 27.212 } 27.213 @@ -2919,7 +2919,7 @@ 27.214 if (isValidArrayIndex(index)) { 27.215 for (ScriptObject object = this; ; ) { 27.216 if (object.getMap().containsArrayKeys()) { 27.217 - final FindProperty find = object.findProperty(key, false, false, this); 27.218 + final FindProperty find = object.findProperty(key, false, this); 27.219 27.220 if (find != null) { 27.221 return find.getObjectValue(); 27.222 @@ -2996,48 +2996,48 @@ 27.223 return get(index, JSType.toString(key)); 27.224 } 27.225 27.226 - private boolean doesNotHaveCheckArrayKeys(final long longIndex, final int value, final boolean strict) { 27.227 + private boolean doesNotHaveCheckArrayKeys(final long longIndex, final int value, final int callSiteFlags) { 27.228 if (getMap().containsArrayKeys()) { 27.229 final String key = JSType.toString(longIndex); 27.230 final FindProperty find = findProperty(key, true); 27.231 if (find != null) { 27.232 - setObject(find, strict, key, value); 27.233 + setObject(find, callSiteFlags, key, value); 27.234 return true; 27.235 } 27.236 } 27.237 return false; 27.238 } 27.239 27.240 - private boolean doesNotHaveCheckArrayKeys(final long longIndex, final long value, final boolean strict) { 27.241 + private boolean doesNotHaveCheckArrayKeys(final long longIndex, final long value, final int callSiteFlags) { 27.242 if (getMap().containsArrayKeys()) { 27.243 final String key = JSType.toString(longIndex); 27.244 final FindProperty find = findProperty(key, true); 27.245 if (find != null) { 27.246 - setObject(find, strict, key, value); 27.247 + setObject(find, callSiteFlags, key, value); 27.248 return true; 27.249 } 27.250 } 27.251 return false; 27.252 } 27.253 27.254 - private boolean doesNotHaveCheckArrayKeys(final long longIndex, final double value, final boolean strict) { 27.255 + private boolean doesNotHaveCheckArrayKeys(final long longIndex, final double value, final int callSiteFlags) { 27.256 if (getMap().containsArrayKeys()) { 27.257 final String key = JSType.toString(longIndex); 27.258 final FindProperty find = findProperty(key, true); 27.259 if (find != null) { 27.260 - setObject(find, strict, key, value); 27.261 + setObject(find, callSiteFlags, key, value); 27.262 return true; 27.263 } 27.264 } 27.265 return false; 27.266 } 27.267 27.268 - private boolean doesNotHaveCheckArrayKeys(final long longIndex, final Object value, final boolean strict) { 27.269 + private boolean doesNotHaveCheckArrayKeys(final long longIndex, final Object value, final int callSiteFlags) { 27.270 if (getMap().containsArrayKeys()) { 27.271 final String key = JSType.toString(longIndex); 27.272 final FindProperty find = findProperty(key, true); 27.273 if (find != null) { 27.274 - setObject(find, strict, key, value); 27.275 + setObject(find, callSiteFlags, key, value); 27.276 return true; 27.277 } 27.278 } 27.279 @@ -3045,10 +3045,10 @@ 27.280 } 27.281 27.282 //value agnostic 27.283 - private boolean doesNotHaveEnsureLength(final long longIndex, final long oldLength, final boolean strict) { 27.284 + private boolean doesNotHaveEnsureLength(final long longIndex, final long oldLength, final int callSiteFlags) { 27.285 if (longIndex >= oldLength) { 27.286 if (!isExtensible()) { 27.287 - if (strict) { 27.288 + if (NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)) { 27.289 throw typeError("object.non.extensible", JSType.toString(longIndex), ScriptRuntime.safeToString(this)); 27.290 } 27.291 return true; 27.292 @@ -3068,37 +3068,41 @@ 27.293 } 27.294 } 27.295 27.296 - private void doesNotHave(final int index, final int value, final boolean strict) { 27.297 + private void doesNotHave(final int index, final int value, final int callSiteFlags) { 27.298 final long oldLength = getArray().length(); 27.299 final long longIndex = ArrayIndex.toLongIndex(index); 27.300 - if (!doesNotHaveCheckArrayKeys(longIndex, value, strict) && !doesNotHaveEnsureLength(longIndex, oldLength, strict)) { 27.301 + if (!doesNotHaveCheckArrayKeys(longIndex, value, callSiteFlags) && !doesNotHaveEnsureLength(longIndex, oldLength, callSiteFlags)) { 27.302 + final boolean strict = NashornCallSiteDescriptor.isStrictFlag(callSiteFlags); 27.303 setArray(getArray().set(index, value, strict)); 27.304 doesNotHaveEnsureDelete(longIndex, oldLength, strict); 27.305 } 27.306 } 27.307 27.308 - private void doesNotHave(final int index, final long value, final boolean strict) { 27.309 + private void doesNotHave(final int index, final long value, final int callSiteFlags) { 27.310 final long oldLength = getArray().length(); 27.311 final long longIndex = ArrayIndex.toLongIndex(index); 27.312 - if (!doesNotHaveCheckArrayKeys(longIndex, value, strict) && !doesNotHaveEnsureLength(longIndex, oldLength, strict)) { 27.313 + if (!doesNotHaveCheckArrayKeys(longIndex, value, callSiteFlags) && !doesNotHaveEnsureLength(longIndex, oldLength, callSiteFlags)) { 27.314 + final boolean strict = NashornCallSiteDescriptor.isStrictFlag(callSiteFlags); 27.315 setArray(getArray().set(index, value, strict)); 27.316 doesNotHaveEnsureDelete(longIndex, oldLength, strict); 27.317 } 27.318 } 27.319 27.320 - private void doesNotHave(final int index, final double value, final boolean strict) { 27.321 + private void doesNotHave(final int index, final double value, final int callSiteFlags) { 27.322 final long oldLength = getArray().length(); 27.323 final long longIndex = ArrayIndex.toLongIndex(index); 27.324 - if (!doesNotHaveCheckArrayKeys(longIndex, value, strict) && !doesNotHaveEnsureLength(longIndex, oldLength, strict)) { 27.325 + if (!doesNotHaveCheckArrayKeys(longIndex, value, callSiteFlags) && !doesNotHaveEnsureLength(longIndex, oldLength, callSiteFlags)) { 27.326 + final boolean strict = NashornCallSiteDescriptor.isStrictFlag(callSiteFlags); 27.327 setArray(getArray().set(index, value, strict)); 27.328 doesNotHaveEnsureDelete(longIndex, oldLength, strict); 27.329 } 27.330 } 27.331 27.332 - private void doesNotHave(final int index, final Object value, final boolean strict) { 27.333 + private void doesNotHave(final int index, final Object value, final int callSiteFlags) { 27.334 final long oldLength = getArray().length(); 27.335 final long longIndex = ArrayIndex.toLongIndex(index); 27.336 - if (!doesNotHaveCheckArrayKeys(longIndex, value, strict) && !doesNotHaveEnsureLength(longIndex, oldLength, strict)) { 27.337 + if (!doesNotHaveCheckArrayKeys(longIndex, value, callSiteFlags) && !doesNotHaveEnsureLength(longIndex, oldLength, callSiteFlags)) { 27.338 + final boolean strict = NashornCallSiteDescriptor.isStrictFlag(callSiteFlags); 27.339 setArray(getArray().set(index, value, strict)); 27.340 doesNotHaveEnsureDelete(longIndex, oldLength, strict); 27.341 } 27.342 @@ -3108,32 +3112,47 @@ 27.343 * This is the most generic of all Object setters. Most of the others use this in some form. 27.344 * TODO: should be further specialized 27.345 * 27.346 - * @param find found property 27.347 - * @param strict are we in strict mode 27.348 - * @param key property key 27.349 - * @param value property value 27.350 + * @param find found property 27.351 + * @param callSiteFlags callsite flags 27.352 + * @param key property key 27.353 + * @param value property value 27.354 */ 27.355 - public final void setObject(final FindProperty find, final boolean strict, final String key, final Object value) { 27.356 + public final void setObject(final FindProperty find, final int callSiteFlags, final String key, final Object value) { 27.357 FindProperty f = find; 27.358 27.359 - if (f != null && f.isInherited() && !(f.getProperty() instanceof UserAccessorProperty) && !isScope()) { 27.360 - // Setting a property should not modify the property in prototype unless this is a scope object. 27.361 - f = null; 27.362 + if (f != null && f.isInherited() && !(f.getProperty() instanceof UserAccessorProperty)) { 27.363 + final boolean isScope = NashornCallSiteDescriptor.isScopeFlag(callSiteFlags); 27.364 + // If the start object of the find is not this object it means the property was found inside a 27.365 + // 'with' statement expression (see WithObject.findProperty()). In this case we forward the 'set' 27.366 + // to the 'with' object. 27.367 + // Note that although a 'set' operation involving a with statement follows scope rules outside 27.368 + // the 'with' expression (the 'set' operation is performed on the owning prototype if it exists), 27.369 + // it follows non-scope rules inside the 'with' expression (set is performed on the top level object). 27.370 + // This is why we clear the callsite flags and FindProperty in the forward call to the 'with' object. 27.371 + if (isScope && f.getSelf() != this) { 27.372 + f.getSelf().setObject(null, 0, key, value); 27.373 + return; 27.374 + } 27.375 + // Setting a property should not modify the property in prototype unless this is a scope callsite 27.376 + // and the owner is a scope object as well (with the exception of 'with' statement handled above). 27.377 + if (!isScope || !f.getOwner().isScope()) { 27.378 + f = null; 27.379 + } 27.380 } 27.381 27.382 if (f != null) { 27.383 if (!f.getProperty().isWritable()) { 27.384 - if (strict) { 27.385 + if (NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)) { 27.386 throw typeError("property.not.writable", key, ScriptRuntime.safeToString(this)); 27.387 } 27.388 27.389 return; 27.390 } 27.391 27.392 - f.setValue(value, strict); 27.393 + f.setValue(value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)); 27.394 27.395 } else if (!isExtensible()) { 27.396 - if (strict) { 27.397 + if (NashornCallSiteDescriptor.isStrictFlag(callSiteFlags)) { 27.398 throw typeError("object.non.extensible", key, ScriptRuntime.safeToString(this)); 27.399 } 27.400 } else { 27.401 @@ -3153,293 +3172,293 @@ 27.402 } 27.403 27.404 @Override 27.405 - public void set(final Object key, final int value, final boolean strict) { 27.406 + public void set(final Object key, final int value, final int callSiteFlags) { 27.407 final Object primitiveKey = JSType.toPrimitive(key, String.class); 27.408 final int index = getArrayIndex(primitiveKey); 27.409 27.410 if (isValidArrayIndex(index)) { 27.411 if (getArray().has(index)) { 27.412 - setArray(getArray().set(index, value, strict)); 27.413 + setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 27.414 } else { 27.415 - doesNotHave(index, value, strict); 27.416 + doesNotHave(index, value, callSiteFlags); 27.417 } 27.418 27.419 return; 27.420 } 27.421 27.422 final String propName = JSType.toString(primitiveKey); 27.423 - setObject(findProperty(propName, true), strict, propName, JSType.toObject(value)); 27.424 + setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value)); 27.425 } 27.426 27.427 @Override 27.428 - public void set(final Object key, final long value, final boolean strict) { 27.429 + public void set(final Object key, final long value, final int callSiteFlags) { 27.430 final Object primitiveKey = JSType.toPrimitive(key, String.class); 27.431 final int index = getArrayIndex(primitiveKey); 27.432 27.433 if (isValidArrayIndex(index)) { 27.434 if (getArray().has(index)) { 27.435 - setArray(getArray().set(index, value, strict)); 27.436 + setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 27.437 } else { 27.438 - doesNotHave(index, value, strict); 27.439 + doesNotHave(index, value, callSiteFlags); 27.440 } 27.441 27.442 return; 27.443 } 27.444 27.445 final String propName = JSType.toString(primitiveKey); 27.446 - setObject(findProperty(propName, true), strict, propName, JSType.toObject(value)); 27.447 + setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value)); 27.448 } 27.449 27.450 @Override 27.451 - public void set(final Object key, final double value, final boolean strict) { 27.452 + public void set(final Object key, final double value, final int callSiteFlags) { 27.453 final Object primitiveKey = JSType.toPrimitive(key, String.class); 27.454 final int index = getArrayIndex(primitiveKey); 27.455 27.456 if (isValidArrayIndex(index)) { 27.457 if (getArray().has(index)) { 27.458 - setArray(getArray().set(index, value, strict)); 27.459 + setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 27.460 } else { 27.461 - doesNotHave(index, value, strict); 27.462 + doesNotHave(index, value, callSiteFlags); 27.463 } 27.464 27.465 return; 27.466 } 27.467 27.468 final String propName = JSType.toString(primitiveKey); 27.469 - setObject(findProperty(propName, true), strict, propName, JSType.toObject(value)); 27.470 + setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value)); 27.471 } 27.472 27.473 @Override 27.474 - public void set(final Object key, final Object value, final boolean strict) { 27.475 + public void set(final Object key, final Object value, final int callSiteFlags) { 27.476 final Object primitiveKey = JSType.toPrimitive(key, String.class); 27.477 final int index = getArrayIndex(primitiveKey); 27.478 27.479 if (isValidArrayIndex(index)) { 27.480 if (getArray().has(index)) { 27.481 - setArray(getArray().set(index, value, strict)); 27.482 + setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 27.483 } else { 27.484 - doesNotHave(index, value, strict); 27.485 + doesNotHave(index, value, callSiteFlags); 27.486 } 27.487 27.488 return; 27.489 } 27.490 27.491 final String propName = JSType.toString(primitiveKey); 27.492 - setObject(findProperty(propName, true), strict, propName, value); 27.493 + setObject(findProperty(propName, true), callSiteFlags, propName, value); 27.494 } 27.495 27.496 @Override 27.497 - public void set(final double key, final int value, final boolean strict) { 27.498 + public void set(final double key, final int value, final int callSiteFlags) { 27.499 final int index = getArrayIndex(key); 27.500 27.501 if (isValidArrayIndex(index)) { 27.502 if (getArray().has(index)) { 27.503 - setArray(getArray().set(index, value, strict)); 27.504 + setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 27.505 } else { 27.506 - doesNotHave(index, value, strict); 27.507 + doesNotHave(index, value, callSiteFlags); 27.508 } 27.509 27.510 return; 27.511 } 27.512 27.513 final String propName = JSType.toString(key); 27.514 - setObject(findProperty(propName, true), strict, propName, JSType.toObject(value)); 27.515 + setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value)); 27.516 } 27.517 27.518 @Override 27.519 - public void set(final double key, final long value, final boolean strict) { 27.520 + public void set(final double key, final long value, final int callSiteFlags) { 27.521 final int index = getArrayIndex(key); 27.522 27.523 if (isValidArrayIndex(index)) { 27.524 if (getArray().has(index)) { 27.525 - setArray(getArray().set(index, value, strict)); 27.526 + setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 27.527 } else { 27.528 - doesNotHave(index, value, strict); 27.529 + doesNotHave(index, value, callSiteFlags); 27.530 } 27.531 27.532 return; 27.533 } 27.534 27.535 final String propName = JSType.toString(key); 27.536 - setObject(findProperty(propName, true), strict, propName, JSType.toObject(value)); 27.537 + setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value)); 27.538 } 27.539 27.540 @Override 27.541 - public void set(final double key, final double value, final boolean strict) { 27.542 + public void set(final double key, final double value, final int callSiteFlags) { 27.543 final int index = getArrayIndex(key); 27.544 27.545 if (isValidArrayIndex(index)) { 27.546 if (getArray().has(index)) { 27.547 - setArray(getArray().set(index, value, strict)); 27.548 + setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 27.549 } else { 27.550 - doesNotHave(index, value, strict); 27.551 + doesNotHave(index, value, callSiteFlags); 27.552 } 27.553 27.554 return; 27.555 } 27.556 27.557 final String propName = JSType.toString(key); 27.558 - setObject(findProperty(propName, true), strict, propName, JSType.toObject(value)); 27.559 + setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value)); 27.560 } 27.561 27.562 @Override 27.563 - public void set(final double key, final Object value, final boolean strict) { 27.564 + public void set(final double key, final Object value, final int callSiteFlags) { 27.565 final int index = getArrayIndex(key); 27.566 27.567 if (isValidArrayIndex(index)) { 27.568 if (getArray().has(index)) { 27.569 - setArray(getArray().set(index, value, strict)); 27.570 + setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 27.571 } else { 27.572 - doesNotHave(index, value, strict); 27.573 + doesNotHave(index, value, callSiteFlags); 27.574 } 27.575 27.576 return; 27.577 } 27.578 27.579 final String propName = JSType.toString(key); 27.580 - setObject(findProperty(propName, true), strict, propName, value); 27.581 + setObject(findProperty(propName, true), callSiteFlags, propName, value); 27.582 } 27.583 27.584 @Override 27.585 - public void set(final long key, final int value, final boolean strict) { 27.586 + public void set(final long key, final int value, final int callSiteFlags) { 27.587 final int index = getArrayIndex(key); 27.588 27.589 if (isValidArrayIndex(index)) { 27.590 if (getArray().has(index)) { 27.591 - setArray(getArray().set(index, value, strict)); 27.592 + setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 27.593 } else { 27.594 - doesNotHave(index, value, strict); 27.595 + doesNotHave(index, value, callSiteFlags); 27.596 } 27.597 27.598 return; 27.599 } 27.600 27.601 final String propName = JSType.toString(key); 27.602 - setObject(findProperty(propName, true), strict, propName, JSType.toObject(value)); 27.603 + setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value)); 27.604 } 27.605 27.606 @Override 27.607 - public void set(final long key, final long value, final boolean strict) { 27.608 + public void set(final long key, final long value, final int callSiteFlags) { 27.609 final int index = getArrayIndex(key); 27.610 27.611 if (isValidArrayIndex(index)) { 27.612 if (getArray().has(index)) { 27.613 - setArray(getArray().set(index, value, strict)); 27.614 + setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 27.615 } else { 27.616 - doesNotHave(index, value, strict); 27.617 + doesNotHave(index, value, callSiteFlags); 27.618 } 27.619 27.620 return; 27.621 } 27.622 27.623 final String propName = JSType.toString(key); 27.624 - setObject(findProperty(propName, true), strict, propName, JSType.toObject(value)); 27.625 + setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value)); 27.626 } 27.627 27.628 @Override 27.629 - public void set(final long key, final double value, final boolean strict) { 27.630 + public void set(final long key, final double value, final int callSiteFlags) { 27.631 final int index = getArrayIndex(key); 27.632 27.633 if (isValidArrayIndex(index)) { 27.634 if (getArray().has(index)) { 27.635 - setArray(getArray().set(index, value, strict)); 27.636 + setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 27.637 } else { 27.638 - doesNotHave(index, value, strict); 27.639 + doesNotHave(index, value, callSiteFlags); 27.640 } 27.641 27.642 return; 27.643 } 27.644 27.645 final String propName = JSType.toString(key); 27.646 - setObject(findProperty(propName, true), strict, propName, JSType.toObject(value)); 27.647 + setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value)); 27.648 } 27.649 27.650 @Override 27.651 - public void set(final long key, final Object value, final boolean strict) { 27.652 + public void set(final long key, final Object value, final int callSiteFlags) { 27.653 final int index = getArrayIndex(key); 27.654 27.655 if (isValidArrayIndex(index)) { 27.656 if (getArray().has(index)) { 27.657 - setArray(getArray().set(index, value, strict)); 27.658 + setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 27.659 } else { 27.660 - doesNotHave(index, value, strict); 27.661 + doesNotHave(index, value, callSiteFlags); 27.662 } 27.663 27.664 return; 27.665 } 27.666 27.667 final String propName = JSType.toString(key); 27.668 - setObject(findProperty(propName, true), strict, propName, value); 27.669 + setObject(findProperty(propName, true), callSiteFlags, propName, value); 27.670 } 27.671 27.672 @Override 27.673 - public void set(final int key, final int value, final boolean strict) { 27.674 + public void set(final int key, final int value, final int callSiteFlags) { 27.675 final int index = getArrayIndex(key); 27.676 if (isValidArrayIndex(index)) { 27.677 if (getArray().has(index)) { 27.678 - setArray(getArray().set(index, value, strict)); 27.679 + setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 27.680 } else { 27.681 - doesNotHave(index, value, strict); 27.682 + doesNotHave(index, value, callSiteFlags); 27.683 } 27.684 return; 27.685 } 27.686 27.687 final String propName = JSType.toString(key); 27.688 - setObject(findProperty(propName, true), strict, propName, JSType.toObject(value)); 27.689 + setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value)); 27.690 } 27.691 27.692 @Override 27.693 - public void set(final int key, final long value, final boolean strict) { 27.694 + public void set(final int key, final long value, final int callSiteFlags) { 27.695 final int index = getArrayIndex(key); 27.696 27.697 if (isValidArrayIndex(index)) { 27.698 if (getArray().has(index)) { 27.699 - setArray(getArray().set(index, value, strict)); 27.700 + setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 27.701 } else { 27.702 - doesNotHave(index, value, strict); 27.703 + doesNotHave(index, value, callSiteFlags); 27.704 } 27.705 27.706 return; 27.707 } 27.708 27.709 final String propName = JSType.toString(key); 27.710 - setObject(findProperty(propName, true), strict, propName, JSType.toObject(value)); 27.711 + setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value)); 27.712 } 27.713 27.714 @Override 27.715 - public void set(final int key, final double value, final boolean strict) { 27.716 + public void set(final int key, final double value, final int callSiteFlags) { 27.717 final int index = getArrayIndex(key); 27.718 27.719 if (isValidArrayIndex(index)) { 27.720 if (getArray().has(index)) { 27.721 - setArray(getArray().set(index, value, strict)); 27.722 + setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 27.723 } else { 27.724 - doesNotHave(index, value, strict); 27.725 + doesNotHave(index, value, callSiteFlags); 27.726 } 27.727 27.728 return; 27.729 } 27.730 27.731 final String propName = JSType.toString(key); 27.732 - setObject(findProperty(propName, true), strict, propName, JSType.toObject(value)); 27.733 + setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value)); 27.734 } 27.735 27.736 @Override 27.737 - public void set(final int key, final Object value, final boolean strict) { 27.738 + public void set(final int key, final Object value, final int callSiteFlags) { 27.739 final int index = getArrayIndex(key); 27.740 27.741 if (isValidArrayIndex(index)) { 27.742 if (getArray().has(index)) { 27.743 - setArray(getArray().set(index, value, strict)); 27.744 + setArray(getArray().set(index, value, NashornCallSiteDescriptor.isStrictFlag(callSiteFlags))); 27.745 } else { 27.746 - doesNotHave(index, value, strict); 27.747 + doesNotHave(index, value, callSiteFlags); 27.748 } 27.749 27.750 return; 27.751 } 27.752 27.753 final String propName = JSType.toString(key); 27.754 - setObject(findProperty(propName, true), strict, propName, value); 27.755 + setObject(findProperty(propName, true), callSiteFlags, propName, value); 27.756 } 27.757 27.758 @Override
28.1 --- a/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java Wed Sep 17 13:53:36 2014 -0700 28.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java Mon Sep 22 18:34:06 2014 -0700 28.3 @@ -221,9 +221,9 @@ 28.4 final String err = errBuffer.toString(); 28.5 28.6 // Set globals for secondary results. 28.7 - global.set(OUT_NAME, out, false); 28.8 - global.set(ERR_NAME, err, false); 28.9 - global.set(EXIT_NAME, exit, false); 28.10 + global.set(OUT_NAME, out, 0); 28.11 + global.set(ERR_NAME, err, 0); 28.12 + global.set(EXIT_NAME, exit, 0); 28.13 28.14 // Propagate exception if present. 28.15 for (final IOException element : exception) {
29.1 --- a/src/jdk/nashorn/internal/runtime/SetMethodCreator.java Wed Sep 17 13:53:36 2014 -0700 29.2 +++ b/src/jdk/nashorn/internal/runtime/SetMethodCreator.java Mon Sep 22 18:34:06 2014 -0700 29.3 @@ -205,7 +205,7 @@ 29.4 29.5 //slow setter, that calls ScriptObject.set with appropraite type and key name 29.6 MethodHandle slowSetter = ScriptObject.SET_SLOW[getAccessorTypeIndex(type)]; 29.7 - slowSetter = MH.insertArguments(slowSetter, 3, NashornCallSiteDescriptor.isStrict(desc)); 29.8 + slowSetter = MH.insertArguments(slowSetter, 3, NashornCallSiteDescriptor.getFlags(desc)); 29.9 slowSetter = MH.insertArguments(slowSetter, 1, name); 29.10 slowSetter = MH.asType(slowSetter, slowSetter.type().changeParameterType(0, Object.class)); 29.11
30.1 --- a/src/jdk/nashorn/internal/runtime/StoredScript.java Wed Sep 17 13:53:36 2014 -0700 30.2 +++ b/src/jdk/nashorn/internal/runtime/StoredScript.java Mon Sep 22 18:34:06 2014 -0700 30.3 @@ -27,6 +27,7 @@ 30.4 30.5 import java.io.Serializable; 30.6 import java.util.Arrays; 30.7 +import java.util.LinkedHashMap; 30.8 import java.util.Map; 30.9 30.10 /** 30.11 @@ -83,7 +84,11 @@ 30.12 * @return map of class bytes 30.13 */ 30.14 public Map<String, byte[]> getClassBytes() { 30.15 - return classBytes; 30.16 + final Map<String, byte[]> clonedMap = new LinkedHashMap<>(); 30.17 + for (final Map.Entry<String, byte[]> entry : classBytes.entrySet()) { 30.18 + clonedMap.put(entry.getKey(), entry.getValue().clone()); 30.19 + } 30.20 + return clonedMap; 30.21 } 30.22 30.23 /** 30.24 @@ -91,11 +96,19 @@ 30.25 * @return constants array 30.26 */ 30.27 public Object[] getConstants() { 30.28 - return constants; 30.29 + return constants.clone(); 30.30 } 30.31 30.32 - Map<Integer, FunctionInitializer> getInitializers() { 30.33 - return initializers; 30.34 + /** 30.35 + * Returns the function initializers map. 30.36 + * @return The initializers map. 30.37 + */ 30.38 + public Map<Integer, FunctionInitializer> getInitializers() { 30.39 + final Map<Integer, FunctionInitializer> clonedMap = new LinkedHashMap<>(); 30.40 + for (final Map.Entry<Integer, FunctionInitializer> entry : initializers.entrySet()) { 30.41 + clonedMap.put(entry.getKey(), new FunctionInitializer(entry.getValue())); 30.42 + } 30.43 + return clonedMap; 30.44 } 30.45 30.46 @Override
31.1 --- a/src/jdk/nashorn/internal/runtime/Undefined.java Wed Sep 17 13:53:36 2014 -0700 31.2 +++ b/src/jdk/nashorn/internal/runtime/Undefined.java Mon Sep 22 18:34:06 2014 -0700 31.3 @@ -34,6 +34,7 @@ 31.4 import jdk.internal.dynalink.linker.GuardedInvocation; 31.5 import jdk.internal.dynalink.support.CallSiteDescriptorFactory; 31.6 import jdk.internal.dynalink.support.Guards; 31.7 +import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; 31.8 31.9 /** 31.10 * Unique instance of this class is used to represent JavaScript undefined. 31.11 @@ -128,7 +129,7 @@ 31.12 } 31.13 31.14 private static final MethodHandle GET_METHOD = findOwnMH("get", Object.class, Object.class); 31.15 - private static final MethodHandle SET_METHOD = MH.insertArguments(findOwnMH("set", void.class, Object.class, Object.class, boolean.class), 3, Boolean.TRUE); 31.16 + private static final MethodHandle SET_METHOD = MH.insertArguments(findOwnMH("set", void.class, Object.class, Object.class, int.class), 3, NashornCallSiteDescriptor.CALLSITE_STRICT); 31.17 31.18 private static GuardedInvocation findGetMethod(final CallSiteDescriptor desc) { 31.19 return new GuardedInvocation(MH.insertArguments(GET_METHOD, 1, desc.getNameToken(2)), UNDEFINED_GUARD).asType(desc); 31.20 @@ -152,7 +153,7 @@ 31.21 } 31.22 31.23 @Override 31.24 - public void set(final Object key, final Object value, final boolean strict) { 31.25 + public void set(final Object key, final Object value, final int flags) { 31.26 throw typeError("cant.set.property.of.undefined", ScriptRuntime.safeToString(key)); 31.27 } 31.28
32.1 --- a/src/jdk/nashorn/internal/runtime/WithObject.java Wed Sep 17 13:53:36 2014 -0700 32.2 +++ b/src/jdk/nashorn/internal/runtime/WithObject.java Mon Sep 22 18:34:06 2014 -0700 32.3 @@ -193,18 +193,20 @@ 32.4 * 32.5 * @param key Property key. 32.6 * @param deep Whether the search should look up proto chain. 32.7 - * @param stopOnNonScope should a deep search stop on the first non-scope object? 32.8 * @param start the object on which the lookup was originally initiated 32.9 * 32.10 * @return FindPropertyData or null if not found. 32.11 */ 32.12 @Override 32.13 - FindProperty findProperty(final String key, final boolean deep, final boolean stopOnNonScope, final ScriptObject start) { 32.14 - final FindProperty exprProperty = expression.findProperty(key, deep, stopOnNonScope, start); 32.15 + FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) { 32.16 + // We call findProperty on 'expression' with 'expression' itself as start parameter. 32.17 + // This way in ScriptObject.setObject we can tell the property is from a 'with' expression 32.18 + // (as opposed from another non-scope object in the proto chain such as Object.prototype). 32.19 + final FindProperty exprProperty = expression.findProperty(key, true, expression); 32.20 if (exprProperty != null) { 32.21 return exprProperty; 32.22 } 32.23 - return super.findProperty(key, deep, stopOnNonScope, start); 32.24 + return super.findProperty(key, deep, start); 32.25 } 32.26 32.27 @Override
33.1 --- a/src/jdk/nashorn/internal/runtime/linker/NashornBeansLinker.java Wed Sep 17 13:53:36 2014 -0700 33.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornBeansLinker.java Mon Sep 22 18:34:06 2014 -0700 33.3 @@ -125,6 +125,15 @@ 33.4 33.5 @Override 33.6 public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) { 33.7 + if (sourceType == ConsString.class) { 33.8 + if (String.class == targetType1 || CharSequence.class == targetType1) { 33.9 + return Comparison.TYPE_1_BETTER; 33.10 + } 33.11 + 33.12 + if (String.class == targetType2 || CharSequence.class == targetType2) { 33.13 + return Comparison.TYPE_2_BETTER; 33.14 + } 33.15 + } 33.16 return linkerServices.compareConversion(sourceType, targetType1, targetType2); 33.17 } 33.18 }
34.1 --- a/src/jdk/nashorn/internal/runtime/linker/NashornBottomLinker.java Wed Sep 17 13:53:36 2014 -0700 34.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornBottomLinker.java Mon Sep 22 18:34:06 2014 -0700 34.3 @@ -131,11 +131,16 @@ 34.4 } 34.5 return getInvocation(EMPTY_ELEM_GETTER, self, linkerServices, desc); 34.6 case "setProp": 34.7 - case "setElem": 34.8 + case "setElem": { 34.9 + final boolean strict = NashornCallSiteDescriptor.isStrict(desc); 34.10 + if (strict) { 34.11 + throw typeError("cant.set.property", getArgument(linkRequest), ScriptRuntime.safeToString(self)); 34.12 + } 34.13 if (desc.getOperand() != null) { 34.14 return getInvocation(EMPTY_PROP_SETTER, self, linkerServices, desc); 34.15 } 34.16 return getInvocation(EMPTY_ELEM_SETTER, self, linkerServices, desc); 34.17 + } 34.18 default: 34.19 break; 34.20 }
35.1 --- a/src/jdk/nashorn/internal/runtime/linker/NashornCallSiteDescriptor.java Wed Sep 17 13:53:36 2014 -0700 35.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornCallSiteDescriptor.java Mon Sep 22 18:34:06 2014 -0700 35.3 @@ -255,7 +255,7 @@ 35.4 * @return the Nashorn-specific flags for the call site, or 0 if the passed descriptor is not a Nashorn call site 35.5 * descriptor. 35.6 */ 35.7 - private static int getFlags(final CallSiteDescriptor desc) { 35.8 + public static int getFlags(final CallSiteDescriptor desc) { 35.9 return desc instanceof NashornCallSiteDescriptor ? ((NashornCallSiteDescriptor)desc).flags : 0; 35.10 } 35.11 35.12 @@ -343,6 +343,24 @@ 35.13 } 35.14 35.15 /** 35.16 + * Returns true if {@code flags} has the {@link #CALLSITE_STRICT} bit set. 35.17 + * @param flags the flags 35.18 + * @return true if the flag is set, false otherwise. 35.19 + */ 35.20 + public static boolean isStrictFlag(final int flags) { 35.21 + return (flags & CALLSITE_STRICT) != 0; 35.22 + } 35.23 + 35.24 + /** 35.25 + * Returns true if {@code flags} has the {@link #CALLSITE_SCOPE} bit set. 35.26 + * @param flags the flags 35.27 + * @return true if the flag is set, false otherwise. 35.28 + */ 35.29 + public static boolean isScopeFlag(final int flags) { 35.30 + return (flags & CALLSITE_SCOPE) != 0; 35.31 + } 35.32 + 35.33 + /** 35.34 * Get a program point from a descriptor (must be optimistic) 35.35 * @param desc descriptor 35.36 * @return program point
36.1 --- a/src/jdk/nashorn/internal/runtime/resources/Messages.properties Wed Sep 17 13:53:36 2014 -0700 36.2 +++ b/src/jdk/nashorn/internal/runtime/resources/Messages.properties Mon Sep 22 18:34:06 2014 -0700 36.3 @@ -92,7 +92,7 @@ 36.4 36.5 # other wrong usages of property 36.6 type.error.property.has.no.setter=Cannot set property "{0}" of {1} that has only a getter 36.7 -type.error.cant.set.proto.to.non.object=Cannot set Object {0}'s __proto__ to be a non-object like {1} 36.8 +type.error.cant.set.proto.to.non.object=Cannot set Object {0}''s __proto__ to be a non-object like {1} 36.9 type.error.no.such.function={1} has no such function "{0}" 36.10 type.error.no.such.java.class=No such Java class: {0} 36.11 type.error.no.such.java.constructor=No such Java constructor: {0} 36.12 @@ -125,10 +125,10 @@ 36.13 type.error.cant.load.script=Cannot load script from {0} 36.14 type.error.JSON.stringify.cyclic=JSON.stringify got a cyclic data structure 36.15 type.error.cant.convert.string.to.char=Cannot convert string to character; its length must be exactly 1 36.16 -type.error.cant.convert.number.to.char=Cannot convert number to character; it's out of 0-65535 range 36.17 +type.error.cant.convert.number.to.char=Cannot convert number to character; it is out of 0-65535 range 36.18 type.error.cant.convert.to.java.string=Cannot convert object of type {0} to a Java argument of string type 36.19 type.error.cant.convert.to.java.number=Cannot convert object of type {0} to a Java argument of number type 36.20 -type.error.cant.convert.to.javascript.array=Can only convert Java arrays and lists to JavaScript arrays. Can't convert object of type {0}. 36.21 +type.error.cant.convert.to.javascript.array=Can only convert Java arrays and lists to JavaScript arrays. Cannot convert object of type {0}. 36.22 type.error.extend.expects.at.least.one.argument=Java.extend needs at least one argument. 36.23 type.error.extend.expects.at.least.one.type.argument=Java.extend needs at least one type argument. 36.24 type.error.extend.expects.java.types=Java.extend needs Java types as its arguments. 36.25 @@ -141,10 +141,10 @@ 36.26 type.error.extend.ERROR_FINAL_FINALIZER=Can not extend class because {0} has a final finalize method. 36.27 type.error.no.constructor.matches.args=Can not construct {0} with the passed arguments; they do not match any of its constructor signatures. 36.28 type.error.no.method.matches.args=Can not invoke method {0} with the passed arguments; they do not match any of its method signatures. 36.29 -type.error.method.not.constructor=Java method {0} can't be used as a constructor. 36.30 +type.error.method.not.constructor=Java method {0} cannot be used as a constructor. 36.31 type.error.env.not.object=$ENV must be an Object. 36.32 type.error.unsupported.java.to.type=Unsupported Java.to target type {0}. 36.33 -type.error.constructor.requires.new=Constructor {0} requires 'new'. 36.34 +type.error.constructor.requires.new=Constructor {0} requires "new". 36.35 type.error.new.on.nonpublic.javatype=new cannot be used with non-public java type {0}. 36.36 36.37 range.error.dataview.constructor.offset=Wrong offset or length in DataView constructor
37.1 --- a/test/script/basic/JDK-8043232.js.EXPECTED Wed Sep 17 13:53:36 2014 -0700 37.2 +++ b/test/script/basic/JDK-8043232.js.EXPECTED Mon Sep 22 18:34:06 2014 -0700 37.3 @@ -6,9 +6,9 @@ 37.4 TypeError: Java constructor signature invalid: Object()xxxxx 37.5 TypeError: Java constructor signature invalid: Object( 37.6 TypeError: Java constructor signature invalid: Object) 37.7 -TypeError: Java method [jdk.internal.dynalink.beans.OverloadedDynamicMethod java.lang.System.getProperty] cant be used as a constructor. 37.8 -TypeError: Java method [jdk.internal.dynalink.beans.OverloadedDynamicMethod java.io.PrintStream.println] cant be used as a constructor. 37.9 -TypeError: Constructor [jdk.internal.dynalink.beans.SimpleDynamicMethod Color java.awt.Color.java.awt.Color(int,int,int)] requires new. 37.10 +TypeError: Java method [jdk.internal.dynalink.beans.OverloadedDynamicMethod java.lang.System.getProperty] cannot be used as a constructor. 37.11 +TypeError: Java method [jdk.internal.dynalink.beans.OverloadedDynamicMethod java.io.PrintStream.println] cannot be used as a constructor. 37.12 +TypeError: Constructor [jdk.internal.dynalink.beans.SimpleDynamicMethod Color java.awt.Color.java.awt.Color(int,int,int)] requires "new". 37.13 TypeError: No such Java constructor: Runnable() 37.14 TypeError: No such Java constructor: Runnable(int) 37.15 java.lang.InstantiationException: java.io.InputStream
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 38.2 +++ b/test/script/basic/JDK-8047764-strict.js Mon Sep 22 18:34:06 2014 -0700 38.3 @@ -0,0 +1,69 @@ 38.4 +/* 38.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 38.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 38.7 + * 38.8 + * This code is free software; you can redistribute it and/or modify it 38.9 + * under the terms of the GNU General Public License version 2 only, as 38.10 + * published by the Free Software Foundation. 38.11 + * 38.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 38.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 38.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 38.15 + * version 2 for more details (a copy is included in the LICENSE file that 38.16 + * accompanied this code). 38.17 + * 38.18 + * You should have received a copy of the GNU General Public License version 38.19 + * 2 along with this work; if not, write to the Free Software Foundation, 38.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 38.21 + * 38.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 38.23 + * or visit www.oracle.com if you need additional information or have any 38.24 + * questions. 38.25 + */ 38.26 + 38.27 +/** 38.28 + * JDK-8047764: Indexed or polymorphic set on global affects Object.prototype 38.29 + * 38.30 + * @test 38.31 + * @run 38.32 + */ 38.33 + 38.34 +// Same as JDK-8047764.js but running in strict mode 38.35 +"use strict"; 38.36 + 38.37 +// Test global set operation on properties defined in Object.prototype 38.38 + 38.39 +Object.defineProperty(Object.prototype, "prop1", { get: function() { return 1; }, set: function(v) { print("setting prop1: " + v); }}); 38.40 +Object.defineProperty(Object.prototype, "prop2", { value: 1, writable: false, configurable: false }); 38.41 + 38.42 +try { 38.43 + prop1 = 1; 38.44 + print("prop 1: " + prop2); 38.45 +} catch (e) { 38.46 + print(e.name); 38.47 +} 38.48 + 38.49 +try { 38.50 + prop2 = 2; 38.51 + print("prop 2: " + prop2); 38.52 +} catch (e) { 38.53 + print(e.name); 38.54 +} 38.55 + 38.56 +// Make sure various ways of setting global toString don't affect Object.prototype.toString 38.57 + 38.58 +function checkToString() { 38.59 + print(global); 38.60 + print(Object.prototype); 38.61 + print(global.toString === Object.prototype.toString); 38.62 + print(objProtoToString === Object.prototype.toString); 38.63 +} 38.64 + 38.65 +var global = this; 38.66 +var objProtoToString = Object.prototype.toString; 38.67 +global["toString"] = function() { return "global toString 1"; }; 38.68 +checkToString(); 38.69 +global.toString = function() { return "global toString 2"; }; 38.70 +checkToString(); 38.71 +toString = function() { return "global toString 3"; }; 38.72 +checkToString();
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/test/script/basic/JDK-8047764-strict.js.EXPECTED Mon Sep 22 18:34:06 2014 -0700 39.3 @@ -0,0 +1,15 @@ 39.4 +setting prop1: 1 39.5 +prop 1: 1 39.6 +TypeError 39.7 +global toString 1 39.8 +[object Object] 39.9 +false 39.10 +true 39.11 +global toString 2 39.12 +[object Object] 39.13 +false 39.14 +true 39.15 +global toString 3 39.16 +[object Object] 39.17 +false 39.18 +true
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 40.2 +++ b/test/script/basic/JDK-8047764.js Mon Sep 22 18:34:06 2014 -0700 40.3 @@ -0,0 +1,94 @@ 40.4 +/* 40.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 40.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 40.7 + * 40.8 + * This code is free software; you can redistribute it and/or modify it 40.9 + * under the terms of the GNU General Public License version 2 only, as 40.10 + * published by the Free Software Foundation. 40.11 + * 40.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 40.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 40.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 40.15 + * version 2 for more details (a copy is included in the LICENSE file that 40.16 + * accompanied this code). 40.17 + * 40.18 + * You should have received a copy of the GNU General Public License version 40.19 + * 2 along with this work; if not, write to the Free Software Foundation, 40.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 40.21 + * 40.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 40.23 + * or visit www.oracle.com if you need additional information or have any 40.24 + * questions. 40.25 + */ 40.26 + 40.27 +/** 40.28 + * JDK-8047764: Indexed or polymorphic set on global affects Object.prototype 40.29 + * 40.30 + * @test 40.31 + * @run 40.32 + */ 40.33 + 40.34 +// Test global set operation on properties defined in Object.prototype 40.35 + 40.36 +Object.defineProperty(Object.prototype, "prop1", { get: function() { return 1; }, set: function(v) { print("setting prop1: " + v); }}); 40.37 +Object.defineProperty(Object.prototype, "prop2", { value: 1, writable: false, configurable: false }); 40.38 + 40.39 +try { 40.40 + prop1 = 1; 40.41 + print("prop 1: " + prop2); 40.42 +} catch (e) { 40.43 + print(e.name); 40.44 +} 40.45 + 40.46 +try { 40.47 + prop2 = 2; 40.48 + print("prop 2: " + prop2); 40.49 +} catch (e) { 40.50 + print(e.name); 40.51 +} 40.52 + 40.53 +// Make sure various ways of setting global toString don't affect Object.prototype.toString 40.54 + 40.55 +function checkToString() { 40.56 + print(global); 40.57 + print(Object.prototype); 40.58 + print(global.toString === Object.prototype.toString); 40.59 + print(objProtoToString === Object.prototype.toString); 40.60 +} 40.61 + 40.62 +var global = this; 40.63 +var objProtoToString = Object.prototype.toString; 40.64 +global["toString"] = function() { return "global toString 1"; }; 40.65 +checkToString(); 40.66 +global.toString = function() { return "global toString 2"; }; 40.67 +checkToString(); 40.68 +toString = function() { return "global toString 3"; }; 40.69 +checkToString(); 40.70 + 40.71 +// Test setters on 'with' object 40.72 + 40.73 +var p = { prop3: 3, toString: function() { return "[object p]"; }}; 40.74 +Object.defineProperty(p, "prop4", { get: function() { print("get", this); return 4; }, set: function(v) { print("set", this, v); }}); 40.75 +var o = Object.create(p); 40.76 +o.toString = function() { return "[object o]"; }; 40.77 + 40.78 +with(o) { 40.79 + (function() { 40.80 + var m = 5; 40.81 + (function() { 40.82 + print(prop3); 40.83 + prop3 = m; 40.84 + print(prop3); 40.85 + print(prop4); 40.86 + prop4 = m; 40.87 + print(prop4); 40.88 + })(); 40.89 + })(); 40.90 +} 40.91 + 40.92 +print(o.hasOwnProperty("prop3")); 40.93 +print(o.prop3); 40.94 +print(p.prop3); 40.95 +print(o.hasOwnProperty("prop4")); 40.96 +print(o.prop4); 40.97 +print(p.prop4);
41.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 41.2 +++ b/test/script/basic/JDK-8047764.js.EXPECTED Mon Sep 22 18:34:06 2014 -0700 41.3 @@ -0,0 +1,30 @@ 41.4 +setting prop1: 1 41.5 +prop 1: 1 41.6 +prop 2: 1 41.7 +global toString 1 41.8 +[object Object] 41.9 +false 41.10 +true 41.11 +global toString 2 41.12 +[object Object] 41.13 +false 41.14 +true 41.15 +global toString 3 41.16 +[object Object] 41.17 +false 41.18 +true 41.19 +3 41.20 +5 41.21 +get [object o] 41.22 +4 41.23 +set [object o] 5 41.24 +get [object o] 41.25 +4 41.26 +true 41.27 +5 41.28 +3 41.29 +false 41.30 +get [object o] 41.31 +4 41.32 +get [object p] 41.33 +4
42.1 --- a/test/script/basic/JDK-8049242.js.EXPECTED Wed Sep 17 13:53:36 2014 -0700 42.2 +++ b/test/script/basic/JDK-8049242.js.EXPECTED Mon Sep 22 18:34:06 2014 -0700 42.3 @@ -4,7 +4,7 @@ 42.4 TypeError: null is not a function 42.5 TypeError: null is not a function 42.6 TypeError: null is not a function 42.7 -TypeError: Constructor [jdk.internal.dynalink.beans.SimpleDynamicMethod Color java.awt.Color.java.awt.Color(int,int,int)] requires new. 42.8 +TypeError: Constructor [jdk.internal.dynalink.beans.SimpleDynamicMethod Color java.awt.Color.java.awt.Color(int,int,int)] requires "new". 42.9 TypeError: null is not a function 42.10 TypeError: null is not a function 42.11 java.lang.InstantiationException: java.io.InputStream
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 43.2 +++ b/test/script/basic/JDK-8056978.js Mon Sep 22 18:34:06 2014 -0700 43.3 @@ -0,0 +1,46 @@ 43.4 +/* 43.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 43.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 43.7 + * 43.8 + * This code is free software; you can redistribute it and/or modify it 43.9 + * under the terms of the GNU General Public License version 2 only, as 43.10 + * published by the Free Software Foundation. 43.11 + * 43.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 43.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 43.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 43.15 + * version 2 for more details (a copy is included in the LICENSE file that 43.16 + * accompanied this code). 43.17 + * 43.18 + * You should have received a copy of the GNU General Public License version 43.19 + * 2 along with this work; if not, write to the Free Software Foundation, 43.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 43.21 + * 43.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 43.23 + * or visit www.oracle.com if you need additional information or have any 43.24 + * questions. 43.25 + */ 43.26 + 43.27 +/** 43.28 + * JDK-8056978: ClassCastException: cannot cast jdk.nashorn.internal.scripts.JO* 43.29 + * 43.30 + * @test 43.31 + * @run 43.32 + */ 43.33 + 43.34 +var obj1 = { 43.35 + 'name': 'test name', 43.36 + '1': '1', 43.37 + '2': '2', 43.38 + '3': '3', 43.39 + '4': '4', 43.40 + '5': '5' 43.41 +}; 43.42 + 43.43 +var obj2 = { 43.44 + 'name': 'hello' 43.45 +}; 43.46 + 43.47 +print(obj2['name']); 43.48 +print(obj2.name); 43.49 +
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 44.2 +++ b/test/script/basic/JDK-8056978.js.EXPECTED Mon Sep 22 18:34:06 2014 -0700 44.3 @@ -0,0 +1,2 @@ 44.4 +hello 44.5 +hello
45.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 45.2 +++ b/test/script/basic/JDK-8058422.js Mon Sep 22 18:34:06 2014 -0700 45.3 @@ -0,0 +1,55 @@ 45.4 +/* 45.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 45.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 45.7 + * 45.8 + * This code is free software; you can redistribute it and/or modify it 45.9 + * under the terms of the GNU General Public License version 2 only, as 45.10 + * published by the Free Software Foundation. 45.11 + * 45.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 45.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 45.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 45.15 + * version 2 for more details (a copy is included in the LICENSE file that 45.16 + * accompanied this code). 45.17 + * 45.18 + * You should have received a copy of the GNU General Public License version 45.19 + * 2 along with this work; if not, write to the Free Software Foundation, 45.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 45.21 + * 45.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 45.23 + * or visit www.oracle.com if you need additional information or have any 45.24 + * questions. 45.25 + */ 45.26 + 45.27 +/** 45.28 + * JDK-8058422: Users should be able to overwrite "context" and "engine" variables 45.29 + * 45.30 + * @test 45.31 + * @run 45.32 + */ 45.33 + 45.34 +var m = new javax.script.ScriptEngineManager(); 45.35 +var e = m.getEngineByName("nashorn"); 45.36 +e.put("foo", "hello"); 45.37 +var obj = e.eval("context.getAttribute('foo')"); 45.38 +if (obj != "hello") { 45.39 + fail("Expected 'obj' to be 'hello'"); 45.40 +} 45.41 + 45.42 +e.put("context", "bar"); 45.43 +if (e.eval("context") != "bar") { 45.44 + fail("Expected 'context' to be 'bar'"); 45.45 +} 45.46 + 45.47 +if (e.eval("foo") != "hello") { 45.48 + fail("Expected 'foo' to be 'hello'"); 45.49 +} 45.50 + 45.51 +if (e.eval("engine") != e) { 45.52 + fail("'engine' is not evaluaed to current engine"); 45.53 +} 45.54 + 45.55 +e.put("engine", "foobar"); 45.56 +if (e.eval("engine") != "foobar") { 45.57 + fail("'engine' is not evalued to 'foobar'"); 45.58 +}
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 46.2 +++ b/test/script/basic/JDK-8058545.js Mon Sep 22 18:34:06 2014 -0700 46.3 @@ -0,0 +1,41 @@ 46.4 +/* 46.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 46.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 46.7 + * 46.8 + * This code is free software; you can redistribute it and/or modify it 46.9 + * under the terms of the GNU General Public License version 2 only, as 46.10 + * published by the Free Software Foundation. 46.11 + * 46.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 46.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 46.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 46.15 + * version 2 for more details (a copy is included in the LICENSE file that 46.16 + * accompanied this code). 46.17 + * 46.18 + * You should have received a copy of the GNU General Public License version 46.19 + * 2 along with this work; if not, write to the Free Software Foundation, 46.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 46.21 + * 46.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 46.23 + * or visit www.oracle.com if you need additional information or have any 46.24 + * questions. 46.25 + */ 46.26 + 46.27 +/** 46.28 + * JDK-8058545: With strict mode, bean property assignment of a non-existent property should result in TypeError 46.29 + * 46.30 + * @test 46.31 + * @run 46.32 + */ 46.33 + 46.34 +'use strict'; 46.35 +var File = Java.type("java.io.File"); 46.36 +var f = new File("."); 46.37 +try { 46.38 + f.foo = 33; 46.39 + fail("Should have thrown TypeError"); 46.40 +} catch (e) { 46.41 + if (! (e instanceof TypeError)) { 46.42 + fail("Expected TypeError, got " + e); 46.43 + } 46.44 +}
47.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 47.2 +++ b/test/script/basic/JDK-8058561.js Mon Sep 22 18:34:06 2014 -0700 47.3 @@ -0,0 +1,42 @@ 47.4 +/* 47.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 47.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 47.7 + * 47.8 + * This code is free software; you can redistribute it and/or modify it 47.9 + * under the terms of the GNU General Public License version 2 only, as 47.10 + * published by the Free Software Foundation. 47.11 + * 47.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 47.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 47.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 47.15 + * version 2 for more details (a copy is included in the LICENSE file that 47.16 + * accompanied this code). 47.17 + * 47.18 + * You should have received a copy of the GNU General Public License version 47.19 + * 2 along with this work; if not, write to the Free Software Foundation, 47.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 47.21 + * 47.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 47.23 + * or visit www.oracle.com if you need additional information or have any 47.24 + * questions. 47.25 + */ 47.26 + 47.27 +/** 47.28 + * JDK-8058561: NPE in LocalVariableTypesCalculator 47.29 + * 47.30 + * @test 47.31 + * @run 47.32 + * @option --lazy-compilation=false 47.33 + */ 47.34 + 47.35 +// Just attempting to compile this caused the NPE 47.36 +function func(x, y) { 47.37 + while(true) { 47.38 + switch (y[0]) { 47.39 + case "bar": 47.40 + x = 'xxx'; 47.41 + break; 47.42 + } 47.43 + } 47.44 + return x; 47.45 +}
48.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 48.2 +++ b/test/script/basic/JDK-8058615.js Mon Sep 22 18:34:06 2014 -0700 48.3 @@ -0,0 +1,36 @@ 48.4 +/* 48.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 48.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 48.7 + * 48.8 + * This code is free software; you can redistribute it and/or modify it 48.9 + * under the terms of the GNU General Public License version 2 only, as 48.10 + * published by the Free Software Foundation. 48.11 + * 48.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 48.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 48.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 48.15 + * version 2 for more details (a copy is included in the LICENSE file that 48.16 + * accompanied this code). 48.17 + * 48.18 + * You should have received a copy of the GNU General Public License version 48.19 + * 2 along with this work; if not, write to the Free Software Foundation, 48.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 48.21 + * 48.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 48.23 + * or visit www.oracle.com if you need additional information or have any 48.24 + * questions. 48.25 + */ 48.26 + 48.27 +/** 48.28 + * JDK-8058615: Overload resolution ambiguity involving ConsString 48.29 + * 48.30 + * @test 48.31 + * @run 48.32 + */ 48.33 + 48.34 +var strw = new java.io.StringWriter(); 48.35 +var bufw = new java.io.BufferedWriter(strw); 48.36 +var s = "hello "; 48.37 +bufw.write(s + "world"); 48.38 +bufw.close(); 48.39 +print(strw.toString());
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 49.2 +++ b/test/script/basic/JDK-8058615.js.EXPECTED Mon Sep 22 18:34:06 2014 -0700 49.3 @@ -0,0 +1,1 @@ 49.4 +hello world
50.1 --- a/test/src/jdk/nashorn/api/scripting/ScopeTest.java Wed Sep 17 13:53:36 2014 -0700 50.2 +++ b/test/src/jdk/nashorn/api/scripting/ScopeTest.java Mon Sep 22 18:34:06 2014 -0700 50.3 @@ -582,6 +582,60 @@ 50.4 assertEquals(e.eval("x", newCtxt), 2); 50.5 } 50.6 50.7 + // @bug 8058422: Users should be able to overwrite "context" and "engine" variables 50.8 + @Test 50.9 + public static void contextOverwriteTest() throws ScriptException { 50.10 + final ScriptEngineManager m = new ScriptEngineManager(); 50.11 + final ScriptEngine e = m.getEngineByName("nashorn"); 50.12 + final Bindings b = new SimpleBindings(); 50.13 + b.put("context", "hello"); 50.14 + b.put("foo", 32); 50.15 + final ScriptContext newCtxt = new SimpleScriptContext(); 50.16 + newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE); 50.17 + e.setContext(newCtxt); 50.18 + assertEquals(e.eval("context"), "hello"); 50.19 + assertEquals(((Number)e.eval("foo")).intValue(), 32); 50.20 + } 50.21 + 50.22 + // @bug 8058422: Users should be able to overwrite "context" and "engine" variables 50.23 + @Test 50.24 + public static void contextOverwriteInScriptTest() throws ScriptException { 50.25 + final ScriptEngineManager m = new ScriptEngineManager(); 50.26 + final ScriptEngine e = m.getEngineByName("nashorn"); 50.27 + e.put("foo", 32); 50.28 + 50.29 + assertEquals(((Number)e.eval("foo")).intValue(), 32); 50.30 + assertEquals(e.eval("context = 'bar'"), "bar"); 50.31 + assertEquals(((Number)e.eval("foo")).intValue(), 32); 50.32 + } 50.33 + 50.34 + // @bug 8058422: Users should be able to overwrite "context" and "engine" variables 50.35 + @Test 50.36 + public static void engineOverwriteTest() throws ScriptException { 50.37 + final ScriptEngineManager m = new ScriptEngineManager(); 50.38 + final ScriptEngine e = m.getEngineByName("nashorn"); 50.39 + final Bindings b = new SimpleBindings(); 50.40 + b.put("engine", "hello"); 50.41 + b.put("foo", 32); 50.42 + final ScriptContext newCtxt = new SimpleScriptContext(); 50.43 + newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE); 50.44 + e.setContext(newCtxt); 50.45 + assertEquals(e.eval("engine"), "hello"); 50.46 + assertEquals(((Number)e.eval("foo")).intValue(), 32); 50.47 + } 50.48 + 50.49 + // @bug 8058422: Users should be able to overwrite "context" and "engine" variables 50.50 + @Test 50.51 + public static void engineOverwriteInScriptTest() throws ScriptException { 50.52 + final ScriptEngineManager m = new ScriptEngineManager(); 50.53 + final ScriptEngine e = m.getEngineByName("nashorn"); 50.54 + e.put("foo", 32); 50.55 + 50.56 + assertEquals(((Number)e.eval("foo")).intValue(), 32); 50.57 + assertEquals(e.eval("engine = 'bar'"), "bar"); 50.58 + assertEquals(((Number)e.eval("foo")).intValue(), 32); 50.59 + } 50.60 + 50.61 // @bug 8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook 50.62 @Test 50.63 public static void testMegamorphicGetInGlobal() throws Exception {