Thu, 09 Apr 2015 22:59:28 -0700
Merge
.hgtags | file | annotate | diff | comparison | revisions | |
src/jdk/nashorn/tools/resources/shell.js | file | annotate | diff | comparison | revisions |
1.1 --- a/.hgtags Wed Apr 01 11:35:19 2015 -0700 1.2 +++ b/.hgtags Thu Apr 09 22:59:28 2015 -0700 1.3 @@ -392,3 +392,4 @@ 1.4 80966e5cc384fb8c67938c0e05e2b990116d3f4c jdk8u60-b07 1.5 e024db176497a3655f7c9d1d86571df74707ba62 jdk8u60-b08 1.6 1f73439a45bf9cdb73ece75b2c935980657b10d4 jdk8u60-b09 1.7 +7aaa64363e1a632ab113b459c46a8ce0c32e4738 jdk8u60-b10
2.1 --- a/src/jdk/nashorn/internal/objects/Global.java Wed Apr 01 11:35:19 2015 -0700 2.2 +++ b/src/jdk/nashorn/internal/objects/Global.java Thu Apr 09 22:59:28 2015 -0700 2.3 @@ -54,10 +54,13 @@ 2.4 import jdk.nashorn.api.scripting.ScriptObjectMirror; 2.5 import jdk.nashorn.internal.lookup.Lookup; 2.6 import jdk.nashorn.internal.objects.annotations.Attribute; 2.7 +import jdk.nashorn.internal.objects.annotations.Getter; 2.8 import jdk.nashorn.internal.objects.annotations.Property; 2.9 import jdk.nashorn.internal.objects.annotations.ScriptClass; 2.10 +import jdk.nashorn.internal.objects.annotations.Setter; 2.11 import jdk.nashorn.internal.runtime.Context; 2.12 import jdk.nashorn.internal.runtime.ECMAErrors; 2.13 +import jdk.nashorn.internal.runtime.FindProperty; 2.14 import jdk.nashorn.internal.runtime.GlobalConstants; 2.15 import jdk.nashorn.internal.runtime.GlobalFunctions; 2.16 import jdk.nashorn.internal.runtime.JSType; 2.17 @@ -77,6 +80,7 @@ 2.18 import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; 2.19 import jdk.nashorn.internal.runtime.regexp.RegExpResult; 2.20 import jdk.nashorn.internal.scripts.JO; 2.21 +import jdk.nashorn.tools.ShellFunctions; 2.22 2.23 /** 2.24 * Representation of global scope. 2.25 @@ -88,6 +92,9 @@ 2.26 private final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class); 2.27 private final InvokeByName VALUE_OF = new InvokeByName("valueOf", ScriptObject.class); 2.28 2.29 + // placeholder value for lazily initialized global objects 2.30 + private static final Object LAZY_SENTINEL = new Object(); 2.31 + 2.32 /** 2.33 * Optimistic builtin names that require switchpoint invalidation 2.34 * upon assignment. Overly conservative, but works for now, to avoid 2.35 @@ -213,20 +220,76 @@ 2.36 public volatile Object number; 2.37 2.38 /** ECMA 15.1.4.7 Date constructor */ 2.39 - @Property(name = "Date", attributes = Attribute.NOT_ENUMERABLE) 2.40 - public volatile Object date; 2.41 + @Getter(name = "Date", attributes = Attribute.NOT_ENUMERABLE) 2.42 + public static Object getDate(final Object self) { 2.43 + final Global global = Global.instanceFrom(self); 2.44 + if (global.date == LAZY_SENTINEL) { 2.45 + global.date = global.getBuiltinDate(); 2.46 + } 2.47 + return global.date; 2.48 + } 2.49 + 2.50 + @Setter(name = "Date", attributes = Attribute.NOT_ENUMERABLE) 2.51 + public static void setDate(final Object self, final Object value) { 2.52 + final Global global = Global.instanceFrom(self); 2.53 + global.date = value; 2.54 + } 2.55 + 2.56 + private volatile Object date = LAZY_SENTINEL; 2.57 2.58 /** ECMA 15.1.4.8 RegExp constructor */ 2.59 - @Property(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE) 2.60 - public volatile Object regexp; 2.61 + @Getter(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE) 2.62 + public static Object getRegExp(final Object self) { 2.63 + final Global global = Global.instanceFrom(self); 2.64 + if (global.regexp == LAZY_SENTINEL) { 2.65 + global.regexp = global.getBuiltinRegExp(); 2.66 + } 2.67 + return global.regexp; 2.68 + } 2.69 + 2.70 + @Setter(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE) 2.71 + public static void setRegExp(final Object self, final Object value) { 2.72 + final Global global = Global.instanceFrom(self); 2.73 + global.regexp = value; 2.74 + } 2.75 + 2.76 + private volatile Object regexp = LAZY_SENTINEL; 2.77 2.78 /** ECMA 15.12 - The JSON object */ 2.79 - @Property(name = "JSON", attributes = Attribute.NOT_ENUMERABLE) 2.80 - public volatile Object json; 2.81 + @Getter(name = "JSON", attributes = Attribute.NOT_ENUMERABLE) 2.82 + public static Object getJSON(final Object self) { 2.83 + final Global global = Global.instanceFrom(self); 2.84 + if (global.json == LAZY_SENTINEL) { 2.85 + global.json = global.getBuiltinJSON(); 2.86 + } 2.87 + return global.json; 2.88 + } 2.89 + 2.90 + @Setter(name = "JSON", attributes = Attribute.NOT_ENUMERABLE) 2.91 + public static void setJSON(final Object self, final Object value) { 2.92 + final Global global = Global.instanceFrom(self); 2.93 + global.json = value; 2.94 + } 2.95 + 2.96 + private volatile Object json = LAZY_SENTINEL; 2.97 2.98 /** Nashorn extension: global.JSAdapter */ 2.99 - @Property(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE) 2.100 - public volatile Object jsadapter; 2.101 + @Getter(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE) 2.102 + public static Object getJSAdapter(final Object self) { 2.103 + final Global global = Global.instanceFrom(self); 2.104 + if (global.jsadapter == LAZY_SENTINEL) { 2.105 + global.jsadapter = global.getBuiltinJSAdapter(); 2.106 + } 2.107 + return global.jsadapter; 2.108 + } 2.109 + 2.110 + @Setter(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE) 2.111 + public static void setJSAdapter(final Object self, final Object value) { 2.112 + final Global global = Global.instanceFrom(self); 2.113 + global.jsadapter = value; 2.114 + } 2.115 + 2.116 + private volatile Object jsadapter = LAZY_SENTINEL; 2.117 2.118 /** ECMA 15.8 - The Math object */ 2.119 @Property(name = "Math", attributes = Attribute.NOT_ENUMERABLE) 2.120 @@ -237,12 +300,40 @@ 2.121 public volatile Object error; 2.122 2.123 /** EvalError object */ 2.124 - @Property(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE) 2.125 - public volatile Object evalError; 2.126 + @Getter(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE) 2.127 + public static Object getEvalError(final Object self) { 2.128 + final Global global = Global.instanceFrom(self); 2.129 + if (global.evalError == LAZY_SENTINEL) { 2.130 + global.evalError = global.getBuiltinEvalError(); 2.131 + } 2.132 + return global.evalError; 2.133 + } 2.134 + 2.135 + @Setter(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE) 2.136 + public static void setEvalError(final Object self, final Object value) { 2.137 + final Global global = Global.instanceFrom(self); 2.138 + global.evalError = value; 2.139 + } 2.140 + 2.141 + private volatile Object evalError = LAZY_SENTINEL; 2.142 2.143 /** RangeError object */ 2.144 - @Property(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE) 2.145 - public volatile Object rangeError; 2.146 + @Getter(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE) 2.147 + public static Object getRangeError(final Object self) { 2.148 + final Global global = Global.instanceFrom(self); 2.149 + if (global.rangeError == LAZY_SENTINEL) { 2.150 + global.rangeError = global.getBuiltinRangeError(); 2.151 + } 2.152 + return global.rangeError; 2.153 + } 2.154 + 2.155 + @Setter(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE) 2.156 + public static void setRangeError(final Object self, final Object value) { 2.157 + final Global global = Global.instanceFrom(self); 2.158 + global.rangeError = value; 2.159 + } 2.160 + 2.161 + private volatile Object rangeError = LAZY_SENTINEL; 2.162 2.163 /** ReferenceError object */ 2.164 @Property(name = "ReferenceError", attributes = Attribute.NOT_ENUMERABLE) 2.165 @@ -257,52 +348,220 @@ 2.166 public volatile Object typeError; 2.167 2.168 /** URIError object */ 2.169 - @Property(name = "URIError", attributes = Attribute.NOT_ENUMERABLE) 2.170 - public volatile Object uriError; 2.171 + @Getter(name = "URIError", attributes = Attribute.NOT_ENUMERABLE) 2.172 + public static Object getURIError(final Object self) { 2.173 + final Global global = Global.instanceFrom(self); 2.174 + if (global.uriError == LAZY_SENTINEL) { 2.175 + global.uriError = global.getBuiltinURIError(); 2.176 + } 2.177 + return global.uriError; 2.178 + } 2.179 + 2.180 + @Setter(name = "URIError", attributes = Attribute.NOT_ENUMERABLE) 2.181 + public static void setURIError(final Object self, final Object value) { 2.182 + final Global global = Global.instanceFrom(self); 2.183 + global.uriError = value; 2.184 + } 2.185 + 2.186 + private volatile Object uriError = LAZY_SENTINEL; 2.187 2.188 /** ArrayBuffer object */ 2.189 - @Property(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE) 2.190 - public volatile Object arrayBuffer; 2.191 + @Getter(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE) 2.192 + public static Object getArrayBuffer(final Object self) { 2.193 + final Global global = Global.instanceFrom(self); 2.194 + if (global.arrayBuffer == LAZY_SENTINEL) { 2.195 + global.arrayBuffer = global.getBuiltinArrayBuffer(); 2.196 + } 2.197 + return global.arrayBuffer; 2.198 + } 2.199 + 2.200 + @Setter(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE) 2.201 + public static void setArrayBuffer(final Object self, final Object value) { 2.202 + final Global global = Global.instanceFrom(self); 2.203 + global.arrayBuffer = value; 2.204 + } 2.205 + 2.206 + private volatile Object arrayBuffer; 2.207 2.208 /** DataView object */ 2.209 - @Property(name = "DataView", attributes = Attribute.NOT_ENUMERABLE) 2.210 - public volatile Object dataView; 2.211 + @Getter(name = "DataView", attributes = Attribute.NOT_ENUMERABLE) 2.212 + public static Object getDataView(final Object self) { 2.213 + final Global global = Global.instanceFrom(self); 2.214 + if (global.dataView == LAZY_SENTINEL) { 2.215 + global.dataView = global.getBuiltinDataView(); 2.216 + } 2.217 + return global.dataView; 2.218 + } 2.219 + 2.220 + @Setter(name = "DataView", attributes = Attribute.NOT_ENUMERABLE) 2.221 + public static void setDataView(final Object self, final Object value) { 2.222 + final Global global = Global.instanceFrom(self); 2.223 + global.dataView = value; 2.224 + } 2.225 + 2.226 + private volatile Object dataView; 2.227 2.228 /** TypedArray (int8) */ 2.229 - @Property(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE) 2.230 - public volatile Object int8Array; 2.231 + @Getter(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE) 2.232 + public static Object getInt8Array(final Object self) { 2.233 + final Global global = Global.instanceFrom(self); 2.234 + if (global.int8Array == LAZY_SENTINEL) { 2.235 + global.int8Array = global.getBuiltinInt8Array(); 2.236 + } 2.237 + return global.int8Array; 2.238 + } 2.239 + 2.240 + @Setter(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE) 2.241 + public static void setInt8Array(final Object self, final Object value) { 2.242 + final Global global = Global.instanceFrom(self); 2.243 + global.int8Array = value; 2.244 + } 2.245 + 2.246 + private volatile Object int8Array; 2.247 2.248 /** TypedArray (uint8) */ 2.249 - @Property(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE) 2.250 - public volatile Object uint8Array; 2.251 + @Getter(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE) 2.252 + public static Object getUint8Array(final Object self) { 2.253 + final Global global = Global.instanceFrom(self); 2.254 + if (global.uint8Array == LAZY_SENTINEL) { 2.255 + global.uint8Array = global.getBuiltinUint8Array(); 2.256 + } 2.257 + return global.uint8Array; 2.258 + } 2.259 + 2.260 + @Setter(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE) 2.261 + public static void setUint8Array(final Object self, final Object value) { 2.262 + final Global global = Global.instanceFrom(self); 2.263 + global.uint8Array = value; 2.264 + } 2.265 + 2.266 + private volatile Object uint8Array; 2.267 2.268 /** TypedArray (uint8) - Clamped */ 2.269 - @Property(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE) 2.270 - public volatile Object uint8ClampedArray; 2.271 + @Getter(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE) 2.272 + public static Object getUint8ClampedArray(final Object self) { 2.273 + final Global global = Global.instanceFrom(self); 2.274 + if (global.uint8ClampedArray == LAZY_SENTINEL) { 2.275 + global.uint8ClampedArray = global.getBuiltinUint8ClampedArray(); 2.276 + } 2.277 + return global.uint8ClampedArray; 2.278 + } 2.279 + 2.280 + @Setter(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE) 2.281 + public static void setUint8ClampedArray(final Object self, final Object value) { 2.282 + final Global global = Global.instanceFrom(self); 2.283 + global.uint8ClampedArray = value; 2.284 + } 2.285 + 2.286 + private volatile Object uint8ClampedArray; 2.287 2.288 /** TypedArray (int16) */ 2.289 - @Property(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE) 2.290 - public volatile Object int16Array; 2.291 + @Getter(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE) 2.292 + public static Object getInt16Array(final Object self) { 2.293 + final Global global = Global.instanceFrom(self); 2.294 + if (global.int16Array == LAZY_SENTINEL) { 2.295 + global.int16Array = global.getBuiltinInt16Array(); 2.296 + } 2.297 + return global.int16Array; 2.298 + } 2.299 + 2.300 + @Setter(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE) 2.301 + public static void setInt16Array(final Object self, final Object value) { 2.302 + final Global global = Global.instanceFrom(self); 2.303 + global.int16Array = value; 2.304 + } 2.305 + 2.306 + private volatile Object int16Array; 2.307 2.308 /** TypedArray (uint16) */ 2.309 - @Property(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE) 2.310 - public volatile Object uint16Array; 2.311 + @Getter(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE) 2.312 + public static Object getUint16Array(final Object self) { 2.313 + final Global global = Global.instanceFrom(self); 2.314 + if (global.uint16Array == LAZY_SENTINEL) { 2.315 + global.uint16Array = global.getBuiltinUint16Array(); 2.316 + } 2.317 + return global.uint16Array; 2.318 + } 2.319 + 2.320 + @Setter(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE) 2.321 + public static void setUint16Array(final Object self, final Object value) { 2.322 + final Global global = Global.instanceFrom(self); 2.323 + global.uint16Array = value; 2.324 + } 2.325 + 2.326 + private volatile Object uint16Array; 2.327 2.328 /** TypedArray (int32) */ 2.329 - @Property(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE) 2.330 - public volatile Object int32Array; 2.331 + @Getter(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE) 2.332 + public static Object getInt32Array(final Object self) { 2.333 + final Global global = Global.instanceFrom(self); 2.334 + if (global.int32Array == LAZY_SENTINEL) { 2.335 + global.int32Array = global.getBuiltinInt32Array(); 2.336 + } 2.337 + return global.int32Array; 2.338 + } 2.339 + 2.340 + @Setter(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE) 2.341 + public static void setInt32Array(final Object self, final Object value) { 2.342 + final Global global = Global.instanceFrom(self); 2.343 + global.int32Array = value; 2.344 + } 2.345 + 2.346 + private volatile Object int32Array; 2.347 2.348 /** TypedArray (uint32) */ 2.349 - @Property(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE) 2.350 - public volatile Object uint32Array; 2.351 + @Getter(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE) 2.352 + public static Object getUint32Array(final Object self) { 2.353 + final Global global = Global.instanceFrom(self); 2.354 + if (global.uint32Array == LAZY_SENTINEL) { 2.355 + global.uint32Array = global.getBuiltinUint32Array(); 2.356 + } 2.357 + return global.uint32Array; 2.358 + } 2.359 + 2.360 + @Setter(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE) 2.361 + public static void setUint32Array(final Object self, final Object value) { 2.362 + final Global global = Global.instanceFrom(self); 2.363 + global.uint32Array = value; 2.364 + } 2.365 + 2.366 + private volatile Object uint32Array; 2.367 2.368 /** TypedArray (float32) */ 2.369 - @Property(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE) 2.370 - public volatile Object float32Array; 2.371 + @Getter(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE) 2.372 + public static Object getFloat32Array(final Object self) { 2.373 + final Global global = Global.instanceFrom(self); 2.374 + if (global.float32Array == LAZY_SENTINEL) { 2.375 + global.float32Array = global.getBuiltinFloat32Array(); 2.376 + } 2.377 + return global.float32Array; 2.378 + } 2.379 + 2.380 + @Setter(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE) 2.381 + public static void setFloat32Array(final Object self, final Object value) { 2.382 + final Global global = Global.instanceFrom(self); 2.383 + global.float32Array = value; 2.384 + } 2.385 + 2.386 + private volatile Object float32Array; 2.387 2.388 /** TypedArray (float64) */ 2.389 - @Property(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE) 2.390 - public volatile Object float64Array; 2.391 + @Getter(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE) 2.392 + public static Object getFloat64Array(final Object self) { 2.393 + final Global global = Global.instanceFrom(self); 2.394 + if (global.float64Array == LAZY_SENTINEL) { 2.395 + global.float64Array = global.getBuiltinFloat64Array(); 2.396 + } 2.397 + return global.float64Array; 2.398 + } 2.399 + 2.400 + @Setter(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE) 2.401 + public static void setFloat64Array(final Object self, final Object value) { 2.402 + final Global global = Global.instanceFrom(self); 2.403 + global.float64Array = value; 2.404 + } 2.405 + 2.406 + private volatile Object float64Array; 2.407 2.408 /** Nashorn extension: Java access - global.Packages */ 2.409 @Property(name = "Packages", attributes = Attribute.NOT_ENUMERABLE) 2.410 @@ -333,12 +592,40 @@ 2.411 public volatile Object org; 2.412 2.413 /** Nashorn extension: Java access - global.javaImporter */ 2.414 - @Property(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE) 2.415 - public volatile Object javaImporter; 2.416 + @Getter(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE) 2.417 + public static Object getJavaImporter(final Object self) { 2.418 + final Global global = Global.instanceFrom(self); 2.419 + if (global.javaImporter == LAZY_SENTINEL) { 2.420 + global.javaImporter = global.getBuiltinJavaImporter(); 2.421 + } 2.422 + return global.javaImporter; 2.423 + } 2.424 + 2.425 + @Setter(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE) 2.426 + public static void setJavaImporter(final Object self, final Object value) { 2.427 + final Global global = Global.instanceFrom(self); 2.428 + global.javaImporter = value; 2.429 + } 2.430 + 2.431 + private volatile Object javaImporter; 2.432 2.433 /** Nashorn extension: global.Java Object constructor. */ 2.434 - @Property(name = "Java", attributes = Attribute.NOT_ENUMERABLE) 2.435 - public volatile Object javaApi; 2.436 + @Getter(name = "Java", attributes = Attribute.NOT_ENUMERABLE) 2.437 + public static Object getJavaApi(final Object self) { 2.438 + final Global global = Global.instanceFrom(self); 2.439 + if (global.javaApi == LAZY_SENTINEL) { 2.440 + global.javaApi = global.getBuiltinJavaApi(); 2.441 + } 2.442 + return global.javaApi; 2.443 + } 2.444 + 2.445 + @Setter(name = "Java", attributes = Attribute.NOT_ENUMERABLE) 2.446 + public static void setJavaApi(final Object self, final Object value) { 2.447 + final Global global = Global.instanceFrom(self); 2.448 + global.javaApi = value; 2.449 + } 2.450 + 2.451 + private volatile Object javaApi; 2.452 2.453 /** Nashorn extension: current script's file name */ 2.454 @Property(name = "__FILE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT) 2.455 @@ -352,11 +639,19 @@ 2.456 @Property(name = "__LINE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT) 2.457 public final Object __LINE__ = LOCATION_PROPERTY_PLACEHOLDER; 2.458 2.459 + private volatile NativeDate DEFAULT_DATE; 2.460 + 2.461 /** Used as Date.prototype's default value */ 2.462 - public NativeDate DEFAULT_DATE; 2.463 + NativeDate getDefaultDate() { 2.464 + return DEFAULT_DATE; 2.465 + } 2.466 + 2.467 + private volatile NativeRegExp DEFAULT_REGEXP; 2.468 2.469 /** Used as RegExp.prototype's default value */ 2.470 - public NativeRegExp DEFAULT_REGEXP; 2.471 + NativeRegExp getDefaultRegExp() { 2.472 + return DEFAULT_REGEXP; 2.473 + } 2.474 2.475 /* 2.476 * Built-in constructor objects: Even if user changes dynamic values of 2.477 @@ -1034,7 +1329,7 @@ 2.478 2.479 /** 2.480 * Get the builtin Object prototype. 2.481 - * @return the object prototype. 2.482 + * @return the object prototype. 2.483 */ 2.484 public ScriptObject getObjectPrototype() { 2.485 return ScriptFunction.getPrototype(builtinObject); 2.486 @@ -1057,11 +1352,11 @@ 2.487 } 2.488 2.489 ScriptObject getDatePrototype() { 2.490 - return ScriptFunction.getPrototype(builtinDate); 2.491 + return ScriptFunction.getPrototype(getBuiltinDate()); 2.492 } 2.493 2.494 ScriptObject getRegExpPrototype() { 2.495 - return ScriptFunction.getPrototype(builtinRegExp); 2.496 + return ScriptFunction.getPrototype(getBuiltinRegExp()); 2.497 } 2.498 2.499 ScriptObject getStringPrototype() { 2.500 @@ -1073,11 +1368,11 @@ 2.501 } 2.502 2.503 ScriptObject getEvalErrorPrototype() { 2.504 - return ScriptFunction.getPrototype(builtinEvalError); 2.505 + return ScriptFunction.getPrototype(getBuiltinEvalError()); 2.506 } 2.507 2.508 ScriptObject getRangeErrorPrototype() { 2.509 - return ScriptFunction.getPrototype(builtinRangeError); 2.510 + return ScriptFunction.getPrototype(getBuiltinRangeError()); 2.511 } 2.512 2.513 ScriptObject getReferenceErrorPrototype() { 2.514 @@ -1093,59 +1388,136 @@ 2.515 } 2.516 2.517 ScriptObject getURIErrorPrototype() { 2.518 - return ScriptFunction.getPrototype(builtinURIError); 2.519 + return ScriptFunction.getPrototype(getBuiltinURIError()); 2.520 } 2.521 2.522 ScriptObject getJavaImporterPrototype() { 2.523 - return ScriptFunction.getPrototype(builtinJavaImporter); 2.524 + return ScriptFunction.getPrototype(getBuiltinJavaImporter()); 2.525 } 2.526 2.527 ScriptObject getJSAdapterPrototype() { 2.528 - return ScriptFunction.getPrototype(builtinJSAdapter); 2.529 + return ScriptFunction.getPrototype(getBuiltinJSAdapter()); 2.530 } 2.531 2.532 + private synchronized ScriptFunction getBuiltinArrayBuffer() { 2.533 + if (this.builtinArrayBuffer == null) { 2.534 + this.builtinArrayBuffer = initConstructorAndSwitchPoint("ArrayBuffer", ScriptFunction.class); 2.535 + } 2.536 + return this.builtinArrayBuffer; 2.537 + } 2.538 + 2.539 ScriptObject getArrayBufferPrototype() { 2.540 - return ScriptFunction.getPrototype(builtinArrayBuffer); 2.541 + return ScriptFunction.getPrototype(getBuiltinArrayBuffer()); 2.542 } 2.543 2.544 + private synchronized ScriptFunction getBuiltinDataView() { 2.545 + if (this.builtinDataView == null) { 2.546 + this.builtinDataView = initConstructorAndSwitchPoint("DataView", ScriptFunction.class); 2.547 + } 2.548 + return this.builtinDataView; 2.549 + } 2.550 + 2.551 ScriptObject getDataViewPrototype() { 2.552 - return ScriptFunction.getPrototype(builtinDataView); 2.553 + return ScriptFunction.getPrototype(getBuiltinDataView()); 2.554 } 2.555 2.556 + private synchronized ScriptFunction getBuiltinInt8Array() { 2.557 + if (this.builtinInt8Array == null) { 2.558 + this.builtinInt8Array = initConstructorAndSwitchPoint("Int8Array", ScriptFunction.class); 2.559 + } 2.560 + return this.builtinInt8Array; 2.561 + } 2.562 + 2.563 ScriptObject getInt8ArrayPrototype() { 2.564 - return ScriptFunction.getPrototype(builtinInt8Array); 2.565 + return ScriptFunction.getPrototype(getBuiltinInt8Array()); 2.566 } 2.567 2.568 + private synchronized ScriptFunction getBuiltinUint8Array() { 2.569 + if (this.builtinUint8Array == null) { 2.570 + this.builtinUint8Array = initConstructorAndSwitchPoint("Uint8Array", ScriptFunction.class); 2.571 + } 2.572 + return this.builtinUint8Array; 2.573 + } 2.574 + 2.575 ScriptObject getUint8ArrayPrototype() { 2.576 - return ScriptFunction.getPrototype(builtinUint8Array); 2.577 + return ScriptFunction.getPrototype(getBuiltinUint8Array()); 2.578 } 2.579 2.580 + private synchronized ScriptFunction getBuiltinUint8ClampedArray() { 2.581 + if (this.builtinUint8ClampedArray == null) { 2.582 + this.builtinUint8ClampedArray = initConstructorAndSwitchPoint("Uint8ClampedArray", ScriptFunction.class); 2.583 + } 2.584 + return this.builtinUint8ClampedArray; 2.585 + } 2.586 + 2.587 ScriptObject getUint8ClampedArrayPrototype() { 2.588 - return ScriptFunction.getPrototype(builtinUint8ClampedArray); 2.589 + return ScriptFunction.getPrototype(getBuiltinUint8ClampedArray()); 2.590 } 2.591 2.592 + private synchronized ScriptFunction getBuiltinInt16Array() { 2.593 + if (this.builtinInt16Array == null) { 2.594 + this.builtinInt16Array = initConstructorAndSwitchPoint("Int16Array", ScriptFunction.class); 2.595 + } 2.596 + return this.builtinInt16Array; 2.597 + } 2.598 + 2.599 ScriptObject getInt16ArrayPrototype() { 2.600 - return ScriptFunction.getPrototype(builtinInt16Array); 2.601 + return ScriptFunction.getPrototype(getBuiltinInt16Array()); 2.602 } 2.603 2.604 + private synchronized ScriptFunction getBuiltinUint16Array() { 2.605 + if (this.builtinUint16Array == null) { 2.606 + this.builtinUint16Array = initConstructorAndSwitchPoint("Uint16Array", ScriptFunction.class); 2.607 + } 2.608 + return this.builtinUint16Array; 2.609 + } 2.610 + 2.611 ScriptObject getUint16ArrayPrototype() { 2.612 - return ScriptFunction.getPrototype(builtinUint16Array); 2.613 + return ScriptFunction.getPrototype(getBuiltinUint16Array()); 2.614 } 2.615 2.616 + private synchronized ScriptFunction getBuiltinInt32Array() { 2.617 + if (this.builtinInt32Array == null) { 2.618 + this.builtinInt32Array = initConstructorAndSwitchPoint("Int32Array", ScriptFunction.class); 2.619 + } 2.620 + return this.builtinInt32Array; 2.621 + } 2.622 + 2.623 ScriptObject getInt32ArrayPrototype() { 2.624 - return ScriptFunction.getPrototype(builtinInt32Array); 2.625 + return ScriptFunction.getPrototype(getBuiltinInt32Array()); 2.626 } 2.627 2.628 + private synchronized ScriptFunction getBuiltinUint32Array() { 2.629 + if (this.builtinUint32Array == null) { 2.630 + this.builtinUint32Array = initConstructorAndSwitchPoint("Uint32Array", ScriptFunction.class); 2.631 + } 2.632 + return this.builtinUint32Array; 2.633 + } 2.634 + 2.635 ScriptObject getUint32ArrayPrototype() { 2.636 - return ScriptFunction.getPrototype(builtinUint32Array); 2.637 + return ScriptFunction.getPrototype(getBuiltinUint32Array()); 2.638 } 2.639 2.640 + private synchronized ScriptFunction getBuiltinFloat32Array() { 2.641 + if (this.builtinFloat32Array == null) { 2.642 + this.builtinFloat32Array = initConstructorAndSwitchPoint("Float32Array", ScriptFunction.class); 2.643 + } 2.644 + return this.builtinFloat32Array; 2.645 + } 2.646 + 2.647 ScriptObject getFloat32ArrayPrototype() { 2.648 - return ScriptFunction.getPrototype(builtinFloat32Array); 2.649 + return ScriptFunction.getPrototype(getBuiltinFloat32Array()); 2.650 } 2.651 2.652 + private synchronized ScriptFunction getBuiltinFloat64Array() { 2.653 + if (this.builtinFloat64Array == null) { 2.654 + this.builtinFloat64Array = initConstructorAndSwitchPoint("Float64Array", ScriptFunction.class); 2.655 + } 2.656 + return this.builtinFloat64Array; 2.657 + } 2.658 + 2.659 ScriptObject getFloat64ArrayPrototype() { 2.660 - return ScriptFunction.getPrototype(builtinFloat64Array); 2.661 + return ScriptFunction.getPrototype(getBuiltinFloat64Array()); 2.662 } 2.663 2.664 private ScriptFunction getBuiltinArray() { 2.665 @@ -1180,8 +1552,14 @@ 2.666 return instance._boolean == instance.getBuiltinBoolean(); 2.667 } 2.668 2.669 - private ScriptFunction getBuiltinDate() { 2.670 - return builtinDate; 2.671 + private synchronized ScriptFunction getBuiltinDate() { 2.672 + if (this.builtinDate == null) { 2.673 + this.builtinDate = initConstructorAndSwitchPoint("Date", ScriptFunction.class); 2.674 + final ScriptObject dateProto = ScriptFunction.getPrototype(builtinDate); 2.675 + // initialize default date 2.676 + this.DEFAULT_DATE = new NativeDate(NaN, dateProto); 2.677 + } 2.678 + return this.builtinDate; 2.679 } 2.680 2.681 /** 2.682 @@ -1191,7 +1569,7 @@ 2.683 */ 2.684 public static boolean isBuiltinDate() { 2.685 final Global instance = Global.instance(); 2.686 - return instance.date == instance.getBuiltinDate(); 2.687 + return instance.date == LAZY_SENTINEL || instance.date == instance.getBuiltinDate(); 2.688 } 2.689 2.690 private ScriptFunction getBuiltinError() { 2.691 @@ -1208,8 +1586,11 @@ 2.692 return instance.error == instance.getBuiltinError(); 2.693 } 2.694 2.695 - private ScriptFunction getBuiltinEvalError() { 2.696 - return builtinEvalError; 2.697 + private synchronized ScriptFunction getBuiltinEvalError() { 2.698 + if (this.builtinEvalError == null) { 2.699 + this.builtinEvalError = initErrorSubtype("EvalError", getErrorPrototype()); 2.700 + } 2.701 + return this.builtinEvalError; 2.702 } 2.703 2.704 /** 2.705 @@ -1219,7 +1600,7 @@ 2.706 */ 2.707 public static boolean isBuiltinEvalError() { 2.708 final Global instance = Global.instance(); 2.709 - return instance.evalError == instance.getBuiltinEvalError(); 2.710 + return instance.evalError == LAZY_SENTINEL || instance.evalError == instance.getBuiltinEvalError(); 2.711 } 2.712 2.713 private ScriptFunction getBuiltinFunction() { 2.714 @@ -1270,7 +1651,10 @@ 2.715 return isBuiltinFunctionProperty("call"); 2.716 } 2.717 2.718 - private ScriptFunction getBuiltinJSAdapter() { 2.719 + private synchronized ScriptFunction getBuiltinJSAdapter() { 2.720 + if (this.builtinJSAdapter == null) { 2.721 + this.builtinJSAdapter = initConstructorAndSwitchPoint("JSAdapter", ScriptFunction.class); 2.722 + } 2.723 return builtinJSAdapter; 2.724 } 2.725 2.726 @@ -1281,11 +1665,14 @@ 2.727 */ 2.728 public static boolean isBuiltinJSAdapter() { 2.729 final Global instance = Global.instance(); 2.730 - return instance.jsadapter == instance.getBuiltinJSAdapter(); 2.731 + return instance.jsadapter == LAZY_SENTINEL || instance.jsadapter == instance.getBuiltinJSAdapter(); 2.732 } 2.733 2.734 - private ScriptObject getBuiltinJSON() { 2.735 - return builtinJSON; 2.736 + private synchronized ScriptObject getBuiltinJSON() { 2.737 + if (this.builtinJSON == null) { 2.738 + this.builtinJSON = initConstructorAndSwitchPoint("JSON", ScriptObject.class); 2.739 + } 2.740 + return this.builtinJSON; 2.741 } 2.742 2.743 /** 2.744 @@ -1295,7 +1682,7 @@ 2.745 */ 2.746 public static boolean isBuiltinJSON() { 2.747 final Global instance = Global.instance(); 2.748 - return instance.json == instance.getBuiltinJSON(); 2.749 + return instance.json == LAZY_SENTINEL || instance.json == instance.getBuiltinJSON(); 2.750 } 2.751 2.752 private ScriptObject getBuiltinJava() { 2.753 @@ -1326,8 +1713,18 @@ 2.754 return instance.javax == instance.getBuiltinJavax(); 2.755 } 2.756 2.757 - private ScriptObject getBuiltinJavaImporter() { 2.758 - return builtinJavaImporter; 2.759 + private synchronized ScriptFunction getBuiltinJavaImporter() { 2.760 + if (this.builtinJavaImporter == null) { 2.761 + this.builtinJavaImporter = initConstructor("JavaImporter", ScriptFunction.class); 2.762 + } 2.763 + return this.builtinJavaImporter; 2.764 + } 2.765 + 2.766 + private synchronized ScriptObject getBuiltinJavaApi() { 2.767 + if (this.builtinJavaApi == null) { 2.768 + this.builtinJavaApi = initConstructor("Java", ScriptObject.class); 2.769 + } 2.770 + return this.builtinJavaApi; 2.771 } 2.772 2.773 /** 2.774 @@ -1337,11 +1734,7 @@ 2.775 */ 2.776 public static boolean isBuiltinJavaImporter() { 2.777 final Global instance = Global.instance(); 2.778 - return instance.javaImporter == instance.getBuiltinJavaImporter(); 2.779 - } 2.780 - 2.781 - private ScriptObject getBuiltinMath() { 2.782 - return builtinMath; 2.783 + return instance.javaImporter == LAZY_SENTINEL || instance.javaImporter == instance.getBuiltinJavaImporter(); 2.784 } 2.785 2.786 /** 2.787 @@ -1351,7 +1744,7 @@ 2.788 */ 2.789 public static boolean isBuiltinMath() { 2.790 final Global instance = Global.instance(); 2.791 - return instance.math == instance.getBuiltinMath(); 2.792 + return instance.math == instance.builtinMath; 2.793 } 2.794 2.795 private ScriptFunction getBuiltinNumber() { 2.796 @@ -1396,7 +1789,10 @@ 2.797 return instance.packages == instance.getBuiltinPackages(); 2.798 } 2.799 2.800 - private ScriptFunction getBuiltinRangeError() { 2.801 + private synchronized ScriptFunction getBuiltinRangeError() { 2.802 + if (this.builtinRangeError == null) { 2.803 + this.builtinRangeError = initErrorSubtype("RangeError", getErrorPrototype()); 2.804 + } 2.805 return builtinRangeError; 2.806 } 2.807 2.808 @@ -1407,10 +1803,10 @@ 2.809 */ 2.810 public static boolean isBuiltinRangeError() { 2.811 final Global instance = Global.instance(); 2.812 - return instance.rangeError == instance.getBuiltinRangeError(); 2.813 + return instance.rangeError == LAZY_SENTINEL || instance.rangeError == instance.getBuiltinRangeError(); 2.814 } 2.815 2.816 - private ScriptFunction getBuiltinReferenceError() { 2.817 + private synchronized ScriptFunction getBuiltinReferenceError() { 2.818 return builtinReferenceError; 2.819 } 2.820 2.821 @@ -1424,7 +1820,16 @@ 2.822 return instance.referenceError == instance.getBuiltinReferenceError(); 2.823 } 2.824 2.825 - private ScriptFunction getBuiltinRegExp() { 2.826 + private synchronized ScriptFunction getBuiltinRegExp() { 2.827 + if (this.builtinRegExp == null) { 2.828 + this.builtinRegExp = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class); 2.829 + final ScriptObject regExpProto = ScriptFunction.getPrototype(builtinRegExp); 2.830 + // initialize default regexp object 2.831 + this.DEFAULT_REGEXP = new NativeRegExp("(?:)", "", this, regExpProto); 2.832 + // RegExp.prototype should behave like a RegExp object. So copy the 2.833 + // properties. 2.834 + regExpProto.addBoundProperties(DEFAULT_REGEXP); 2.835 + } 2.836 return builtinRegExp; 2.837 } 2.838 2.839 @@ -1435,7 +1840,7 @@ 2.840 */ 2.841 public static boolean isBuiltinRegExp() { 2.842 final Global instance = Global.instance(); 2.843 - return instance.regexp == instance.getBuiltinRegExp(); 2.844 + return instance.regexp == LAZY_SENTINEL || instance.regexp == instance.getBuiltinRegExp(); 2.845 } 2.846 2.847 private ScriptFunction getBuiltinString() { 2.848 @@ -1480,8 +1885,11 @@ 2.849 return instance.typeError == instance.getBuiltinTypeError(); 2.850 } 2.851 2.852 - private ScriptFunction getBuiltinURIError() { 2.853 - return builtinURIError; 2.854 + private synchronized ScriptFunction getBuiltinURIError() { 2.855 + if (this.builtinURIError == null) { 2.856 + this.builtinURIError = initErrorSubtype("URIError", getErrorPrototype()); 2.857 + } 2.858 + return this.builtinURIError; 2.859 } 2.860 2.861 /** 2.862 @@ -1491,7 +1899,7 @@ 2.863 */ 2.864 public static boolean isBuiltinURIError() { 2.865 final Global instance = Global.instance(); 2.866 - return instance.uriError == instance.getBuiltinURIError(); 2.867 + return instance.uriError == LAZY_SENTINEL || instance.uriError == instance.getBuiltinURIError(); 2.868 } 2.869 2.870 @Override 2.871 @@ -1798,6 +2206,17 @@ 2.872 } 2.873 2.874 @Override 2.875 + protected FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) { 2.876 + if (lexicalScope != null && start != this && start.isScope()) { 2.877 + final FindProperty find = lexicalScope.findProperty(key, false); 2.878 + if (find != null) { 2.879 + return find; 2.880 + } 2.881 + } 2.882 + return super.findProperty(key, deep, start); 2.883 + } 2.884 + 2.885 + @Override 2.886 public GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) { 2.887 final boolean isScope = NashornCallSiteDescriptor.isScope(desc); 2.888 2.889 @@ -1817,6 +2236,17 @@ 2.890 return invocation; 2.891 } 2.892 2.893 + /** 2.894 + * Adds jjs shell interactive mode builtin functions to global scope. 2.895 + */ 2.896 + public void addShellBuiltins() { 2.897 + Object value = ScriptFunctionImpl.makeFunction("input", ShellFunctions.INPUT); 2.898 + addOwnProperty("input", Attribute.NOT_ENUMERABLE, value); 2.899 + 2.900 + value = ScriptFunctionImpl.makeFunction("evalinput", ShellFunctions.EVALINPUT); 2.901 + addOwnProperty("evalinput", Attribute.NOT_ENUMERABLE, value); 2.902 + } 2.903 + 2.904 private synchronized SwitchPoint getLexicalScopeSwitchPoint() { 2.905 SwitchPoint switchPoint = lexicalScopeSwitchPoint; 2.906 if (switchPoint == null || switchPoint.hasBeenInvalidated()) { 2.907 @@ -1893,13 +2323,9 @@ 2.908 // built-in constructors 2.909 this.builtinArray = initConstructorAndSwitchPoint("Array", ScriptFunction.class); 2.910 this.builtinBoolean = initConstructorAndSwitchPoint("Boolean", ScriptFunction.class); 2.911 - this.builtinDate = initConstructorAndSwitchPoint("Date", ScriptFunction.class); 2.912 - this.builtinJSON = initConstructorAndSwitchPoint("JSON", ScriptObject.class); 2.913 - this.builtinJSAdapter = initConstructorAndSwitchPoint("JSAdapter", ScriptFunction.class); 2.914 + this.builtinNumber = initConstructorAndSwitchPoint("Number", ScriptFunction.class); 2.915 + this.builtinString = initConstructorAndSwitchPoint("String", ScriptFunction.class); 2.916 this.builtinMath = initConstructorAndSwitchPoint("Math", ScriptObject.class); 2.917 - this.builtinNumber = initConstructorAndSwitchPoint("Number", ScriptFunction.class); 2.918 - this.builtinRegExp = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class); 2.919 - this.builtinString = initConstructorAndSwitchPoint("String", ScriptFunction.class); 2.920 2.921 // initialize String.prototype.length to 0 2.922 // add String.prototype.length 2.923 @@ -1910,26 +2336,28 @@ 2.924 final ScriptObject arrayPrototype = getArrayPrototype(); 2.925 arrayPrototype.setIsArray(); 2.926 2.927 - this.DEFAULT_DATE = new NativeDate(Double.NaN, this); 2.928 - 2.929 - // initialize default regexp object 2.930 - this.DEFAULT_REGEXP = new NativeRegExp("(?:)", this); 2.931 - 2.932 - // RegExp.prototype should behave like a RegExp object. So copy the 2.933 - // properties. 2.934 - final ScriptObject regExpProto = getRegExpPrototype(); 2.935 - regExpProto.addBoundProperties(DEFAULT_REGEXP); 2.936 - 2.937 // Error stuff 2.938 initErrorObjects(); 2.939 2.940 // java access 2.941 if (! env._no_java) { 2.942 + this.javaApi = LAZY_SENTINEL; 2.943 + this.javaImporter = LAZY_SENTINEL; 2.944 initJavaAccess(); 2.945 } 2.946 2.947 if (! env._no_typed_arrays) { 2.948 - initTypedArray(); 2.949 + this.arrayBuffer = LAZY_SENTINEL; 2.950 + this.dataView = LAZY_SENTINEL; 2.951 + this.int8Array = LAZY_SENTINEL; 2.952 + this.uint8Array = LAZY_SENTINEL; 2.953 + this.uint8ClampedArray = LAZY_SENTINEL; 2.954 + this.int16Array = LAZY_SENTINEL; 2.955 + this.uint16Array = LAZY_SENTINEL; 2.956 + this.int32Array = LAZY_SENTINEL; 2.957 + this.uint32Array = LAZY_SENTINEL; 2.958 + this.float32Array = LAZY_SENTINEL; 2.959 + this.float64Array = LAZY_SENTINEL; 2.960 } 2.961 2.962 if (env._scripting) { 2.963 @@ -2003,12 +2431,9 @@ 2.964 2.965 tagBuiltinProperties("Error", builtinError); 2.966 2.967 - this.builtinEvalError = initErrorSubtype("EvalError", errorProto); 2.968 - this.builtinRangeError = initErrorSubtype("RangeError", errorProto); 2.969 this.builtinReferenceError = initErrorSubtype("ReferenceError", errorProto); 2.970 this.builtinSyntaxError = initErrorSubtype("SyntaxError", errorProto); 2.971 this.builtinTypeError = initErrorSubtype("TypeError", errorProto); 2.972 - this.builtinURIError = initErrorSubtype("URIError", errorProto); 2.973 } 2.974 2.975 private ScriptFunction initErrorSubtype(final String name, final ScriptObject errorProto) { 2.976 @@ -2030,8 +2455,6 @@ 2.977 this.builtinJavafx = new NativeJavaPackage("javafx", objectProto); 2.978 this.builtinJavax = new NativeJavaPackage("javax", objectProto); 2.979 this.builtinOrg = new NativeJavaPackage("org", objectProto); 2.980 - this.builtinJavaImporter = initConstructor("JavaImporter", ScriptFunction.class); 2.981 - this.builtinJavaApi = initConstructor("Java", ScriptObject.class); 2.982 } 2.983 2.984 private void initScripting(final ScriptEnvironment scriptEnv) { 2.985 @@ -2083,60 +2506,25 @@ 2.986 } 2.987 } 2.988 2.989 - private void initTypedArray() { 2.990 - this.builtinArrayBuffer = initConstructorAndSwitchPoint("ArrayBuffer", ScriptFunction.class); 2.991 - this.builtinDataView = initConstructorAndSwitchPoint("DataView", ScriptFunction.class); 2.992 - this.builtinInt8Array = initConstructorAndSwitchPoint("Int8Array", ScriptFunction.class); 2.993 - this.builtinUint8Array = initConstructorAndSwitchPoint("Uint8Array", ScriptFunction.class); 2.994 - this.builtinUint8ClampedArray = initConstructorAndSwitchPoint("Uint8ClampedArray", ScriptFunction.class); 2.995 - this.builtinInt16Array = initConstructorAndSwitchPoint("Int16Array", ScriptFunction.class); 2.996 - this.builtinUint16Array = initConstructorAndSwitchPoint("Uint16Array", ScriptFunction.class); 2.997 - this.builtinInt32Array = initConstructorAndSwitchPoint("Int32Array", ScriptFunction.class); 2.998 - this.builtinUint32Array = initConstructorAndSwitchPoint("Uint32Array", ScriptFunction.class); 2.999 - this.builtinFloat32Array = initConstructorAndSwitchPoint("Float32Array", ScriptFunction.class); 2.1000 - this.builtinFloat64Array = initConstructorAndSwitchPoint("Float64Array", ScriptFunction.class); 2.1001 - 2.1002 - } 2.1003 - 2.1004 private void copyBuiltins() { 2.1005 this.array = this.builtinArray; 2.1006 this._boolean = this.builtinBoolean; 2.1007 - this.date = this.builtinDate; 2.1008 this.error = this.builtinError; 2.1009 - this.evalError = this.builtinEvalError; 2.1010 this.function = this.builtinFunction; 2.1011 - this.jsadapter = this.builtinJSAdapter; 2.1012 - this.json = this.builtinJSON; 2.1013 this.com = this.builtinCom; 2.1014 this.edu = this.builtinEdu; 2.1015 this.java = this.builtinJava; 2.1016 this.javafx = this.builtinJavafx; 2.1017 this.javax = this.builtinJavax; 2.1018 this.org = this.builtinOrg; 2.1019 - this.javaImporter = this.builtinJavaImporter; 2.1020 - this.javaApi = this.builtinJavaApi; 2.1021 this.math = this.builtinMath; 2.1022 this.number = this.builtinNumber; 2.1023 this.object = this.builtinObject; 2.1024 this.packages = this.builtinPackages; 2.1025 - this.rangeError = this.builtinRangeError; 2.1026 this.referenceError = this.builtinReferenceError; 2.1027 - this.regexp = this.builtinRegExp; 2.1028 this.string = this.builtinString; 2.1029 this.syntaxError = this.builtinSyntaxError; 2.1030 this.typeError = this.builtinTypeError; 2.1031 - this.uriError = this.builtinURIError; 2.1032 - this.arrayBuffer = this.builtinArrayBuffer; 2.1033 - this.dataView = this.builtinDataView; 2.1034 - this.int8Array = this.builtinInt8Array; 2.1035 - this.uint8Array = this.builtinUint8Array; 2.1036 - this.uint8ClampedArray = this.builtinUint8ClampedArray; 2.1037 - this.int16Array = this.builtinInt16Array; 2.1038 - this.uint16Array = this.builtinUint16Array; 2.1039 - this.int32Array = this.builtinInt32Array; 2.1040 - this.uint32Array = this.builtinUint32Array; 2.1041 - this.float32Array = this.builtinFloat32Array; 2.1042 - this.float64Array = this.builtinFloat64Array; 2.1043 } 2.1044 2.1045 private void initDebug() {
3.1 --- a/src/jdk/nashorn/internal/objects/NativeDate.java Wed Apr 01 11:35:19 2015 -0700 3.2 +++ b/src/jdk/nashorn/internal/objects/NativeDate.java Thu Apr 09 22:59:28 2015 -0700 3.3 @@ -121,6 +121,10 @@ 3.4 this.timezone = env._timezone; 3.5 } 3.6 3.7 + NativeDate(final double time, final ScriptObject proto) { 3.8 + this(time, proto, $nasgenmap$); 3.9 + } 3.10 + 3.11 NativeDate(final double time, final Global global) { 3.12 this(time, global.getDatePrototype(), $nasgenmap$); 3.13 } 3.14 @@ -1276,7 +1280,7 @@ 3.15 if (self instanceof NativeDate) { 3.16 return (NativeDate)self; 3.17 } else if (self != null && self == Global.instance().getDatePrototype()) { 3.18 - return Global.instance().DEFAULT_DATE; 3.19 + return Global.instance().getDefaultDate(); 3.20 } else { 3.21 throw typeError("not.a.date", ScriptRuntime.safeToString(self)); 3.22 }
4.1 --- a/src/jdk/nashorn/internal/objects/NativeFloat32Array.java Wed Apr 01 11:35:19 2015 -0700 4.2 +++ b/src/jdk/nashorn/internal/objects/NativeFloat32Array.java Thu Apr 09 22:59:28 2015 -0700 4.3 @@ -114,12 +114,11 @@ 4.4 4.5 private void setElem(final int index, final double elem) { 4.6 try { 4.7 - nb.put(index, (float)elem); 4.8 + if (index < nb.limit()) { 4.9 + nb.put(index, (float) elem); 4.10 + } 4.11 } catch (final IndexOutOfBoundsException e) { 4.12 - //swallow valid array indexes. it's ok. 4.13 - if (index < 0) { 4.14 - throw new ClassCastException(); 4.15 - } 4.16 + throw new ClassCastException(); 4.17 } 4.18 } 4.19
5.1 --- a/src/jdk/nashorn/internal/objects/NativeFloat64Array.java Wed Apr 01 11:35:19 2015 -0700 5.2 +++ b/src/jdk/nashorn/internal/objects/NativeFloat64Array.java Thu Apr 09 22:59:28 2015 -0700 5.3 @@ -114,12 +114,11 @@ 5.4 5.5 private void setElem(final int index, final double elem) { 5.6 try { 5.7 - nb.put(index, elem); 5.8 + if (index < nb.limit()) { 5.9 + nb.put(index, elem); 5.10 + } 5.11 } catch (final IndexOutOfBoundsException e) { 5.12 - //swallow valid array indexes. it's ok. 5.13 - if (index < 0) { 5.14 - throw new ClassCastException(); 5.15 - } 5.16 + throw new ClassCastException(); 5.17 } 5.18 } 5.19
6.1 --- a/src/jdk/nashorn/internal/objects/NativeInt16Array.java Wed Apr 01 11:35:19 2015 -0700 6.2 +++ b/src/jdk/nashorn/internal/objects/NativeInt16Array.java Thu Apr 09 22:59:28 2015 -0700 6.3 @@ -115,12 +115,11 @@ 6.4 6.5 private void setElem(final int index, final int elem) { 6.6 try { 6.7 - nb.put(index, (short)elem); 6.8 + if (index < nb.limit()) { 6.9 + nb.put(index, (short) elem); 6.10 + } 6.11 } catch (final IndexOutOfBoundsException e) { 6.12 - //swallow valid array indexes. it's ok. 6.13 - if (index < 0) { 6.14 - throw new ClassCastException(); 6.15 - } 6.16 + throw new ClassCastException(); 6.17 } 6.18 } 6.19
7.1 --- a/src/jdk/nashorn/internal/objects/NativeInt32Array.java Wed Apr 01 11:35:19 2015 -0700 7.2 +++ b/src/jdk/nashorn/internal/objects/NativeInt32Array.java Thu Apr 09 22:59:28 2015 -0700 7.3 @@ -104,11 +104,11 @@ 7.4 7.5 private void setElem(final int index, final int elem) { 7.6 try { 7.7 - nb.put(index, elem); 7.8 - } catch (final IndexOutOfBoundsException e) { 7.9 - if (index < 0) { 7.10 - throw new ClassCastException(); 7.11 - } 7.12 + if (index < nb.limit()) { 7.13 + nb.put(index, elem); 7.14 + } 7.15 + } catch (final IndexOutOfBoundsException e) { 7.16 + throw new ClassCastException(); 7.17 } 7.18 } 7.19
8.1 --- a/src/jdk/nashorn/internal/objects/NativeInt8Array.java Wed Apr 01 11:35:19 2015 -0700 8.2 +++ b/src/jdk/nashorn/internal/objects/NativeInt8Array.java Thu Apr 09 22:59:28 2015 -0700 8.3 @@ -113,12 +113,11 @@ 8.4 8.5 private void setElem(final int index, final int elem) { 8.6 try { 8.7 - nb.put(index, (byte)elem); 8.8 + if (index < nb.limit()) { 8.9 + nb.put(index, (byte) elem); 8.10 + } 8.11 } catch (final IndexOutOfBoundsException e) { 8.12 - //swallow valid array indexes. it's ok. 8.13 - if (index < 0) { 8.14 - throw new ClassCastException(); 8.15 - } 8.16 + throw new ClassCastException(); 8.17 } 8.18 } 8.19
9.1 --- a/src/jdk/nashorn/internal/objects/NativeRegExp.java Wed Apr 01 11:35:19 2015 -0700 9.2 +++ b/src/jdk/nashorn/internal/objects/NativeRegExp.java Thu Apr 09 22:59:28 2015 -0700 9.3 @@ -78,8 +78,8 @@ 9.4 this.globalObject = global; 9.5 } 9.6 9.7 - NativeRegExp(final String input, final String flagString, final Global global) { 9.8 - this(global); 9.9 + NativeRegExp(final String input, final String flagString, final Global global, final ScriptObject proto) { 9.10 + super(proto, $nasgenmap$); 9.11 try { 9.12 this.regexp = RegExpFactory.create(input, flagString); 9.13 } catch (final ParserException e) { 9.14 @@ -87,8 +87,12 @@ 9.15 e.throwAsEcmaException(); 9.16 throw new AssertionError(); //guard against null warnings below 9.17 } 9.18 + this.globalObject = global; 9.19 + this.setLastIndex(0); 9.20 + } 9.21 9.22 - this.setLastIndex(0); 9.23 + NativeRegExp(final String input, final String flagString, final Global global) { 9.24 + this(input, flagString, global, global.getRegExpPrototype()); 9.25 } 9.26 9.27 NativeRegExp(final String input, final String flagString) { 9.28 @@ -928,7 +932,7 @@ 9.29 if (self instanceof NativeRegExp) { 9.30 return (NativeRegExp)self; 9.31 } else if (self != null && self == Global.instance().getRegExpPrototype()) { 9.32 - return Global.instance().DEFAULT_REGEXP; 9.33 + return Global.instance().getDefaultRegExp(); 9.34 } else { 9.35 throw typeError("not.a.regexp", ScriptRuntime.safeToString(self)); 9.36 }
10.1 --- a/src/jdk/nashorn/internal/objects/NativeUint16Array.java Wed Apr 01 11:35:19 2015 -0700 10.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint16Array.java Thu Apr 09 22:59:28 2015 -0700 10.3 @@ -104,12 +104,11 @@ 10.4 10.5 private void setElem(final int index, final int elem) { 10.6 try { 10.7 - nb.put(index, (char)elem); 10.8 + if (index < nb.limit()) { 10.9 + nb.put(index, (char) elem); 10.10 + } 10.11 } catch (final IndexOutOfBoundsException e) { 10.12 - //swallow valid array indexes. it's ok. 10.13 - if (index < 0) { 10.14 - throw new ClassCastException(); 10.15 - } 10.16 + throw new ClassCastException(); 10.17 } 10.18 } 10.19
11.1 --- a/src/jdk/nashorn/internal/objects/NativeUint32Array.java Wed Apr 01 11:35:19 2015 -0700 11.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint32Array.java Thu Apr 09 22:59:28 2015 -0700 11.3 @@ -113,12 +113,11 @@ 11.4 11.5 private void setElem(final int index, final int elem) { 11.6 try { 11.7 - nb.put(index, elem); 11.8 + if (index < nb.limit()) { 11.9 + nb.put(index, elem); 11.10 + } 11.11 } catch (final IndexOutOfBoundsException e) { 11.12 - //swallow valid array indexes. it's ok. 11.13 - if (index < 0) { 11.14 - throw new ClassCastException(); 11.15 - } 11.16 + throw new ClassCastException(); 11.17 } 11.18 } 11.19
12.1 --- a/src/jdk/nashorn/internal/objects/NativeUint8Array.java Wed Apr 01 11:35:19 2015 -0700 12.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint8Array.java Thu Apr 09 22:59:28 2015 -0700 12.3 @@ -104,12 +104,11 @@ 12.4 12.5 private void setElem(final int index, final int elem) { 12.6 try { 12.7 - nb.put(index, (byte)elem); 12.8 + if (index < nb.limit()) { 12.9 + nb.put(index, (byte) elem); 12.10 + } 12.11 } catch (final IndexOutOfBoundsException e) { 12.12 - //swallow valid array indexes. it's ok. 12.13 - if (index < 0) { 12.14 - throw new ClassCastException(); 12.15 - } 12.16 + throw new ClassCastException(); 12.17 } 12.18 } 12.19
13.1 --- a/src/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java Wed Apr 01 11:35:19 2015 -0700 13.2 +++ b/src/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java Thu Apr 09 22:59:28 2015 -0700 13.3 @@ -133,18 +133,17 @@ 13.4 13.5 private void setElem(final int index, final int elem) { 13.6 try { 13.7 - final byte clamped; 13.8 - if ((elem & 0xffff_ff00) == 0) { 13.9 - clamped = (byte)elem; 13.10 - } else { 13.11 - clamped = elem < 0 ? 0 : (byte)0xff; 13.12 + if (index < nb.limit()) { 13.13 + final byte clamped; 13.14 + if ((elem & 0xffff_ff00) == 0) { 13.15 + clamped = (byte) elem; 13.16 + } else { 13.17 + clamped = elem < 0 ? 0 : (byte) 0xff; 13.18 + } 13.19 + nb.put(index, clamped); 13.20 } 13.21 - nb.put(index, clamped); 13.22 } catch (final IndexOutOfBoundsException e) { 13.23 - //swallow valid array indexes. it's ok. 13.24 - if (index < 0) { 13.25 - throw new ClassCastException(); 13.26 - } 13.27 + throw new ClassCastException(); 13.28 } 13.29 } 13.30
14.1 --- a/src/jdk/nashorn/internal/runtime/JSType.java Wed Apr 01 11:35:19 2015 -0700 14.2 +++ b/src/jdk/nashorn/internal/runtime/JSType.java Thu Apr 09 22:59:28 2015 -0700 14.3 @@ -934,11 +934,15 @@ 14.4 if (start + 1 < end && f == '0' && Character.toLowerCase(str.charAt(start + 1)) == 'x') { 14.5 //decode hex string 14.6 value = parseRadix(str.toCharArray(), start + 2, end, 16); 14.7 + } else if (f == 'I' && end - start == 8 && str.regionMatches(start, "Infinity", 0, 8)) { 14.8 + return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; 14.9 } else { 14.10 - // Fast (no NumberFormatException) path to NaN for non-numeric strings. We allow those starting with "I" or 14.11 - // "N" to allow for parsing "NaN" and "Infinity" correctly. 14.12 - if ((f < '0' || f > '9') && f != '.' && f != 'I' && f != 'N') { 14.13 - return Double.NaN; 14.14 + // Fast (no NumberFormatException) path to NaN for non-numeric strings. 14.15 + for (int i = start; i < end; i++) { 14.16 + f = str.charAt(i); 14.17 + if ((f < '0' || f > '9') && f != '.' && f != 'e' && f != 'E' && f != '+' && f != '-') { 14.18 + return Double.NaN; 14.19 + } 14.20 } 14.21 try { 14.22 value = Double.parseDouble(str.substring(start, end));
15.1 --- a/src/jdk/nashorn/internal/runtime/PropertyMap.java Wed Apr 01 11:35:19 2015 -0700 15.2 +++ b/src/jdk/nashorn/internal/runtime/PropertyMap.java Thu Apr 09 22:59:28 2015 -0700 15.3 @@ -330,12 +330,15 @@ 15.4 * Indicate that proto itself has changed in hierarchy somewhere. 15.5 */ 15.6 synchronized void invalidateAllProtoGetSwitchPoints() { 15.7 - if (protoGetSwitches != null && !protoGetSwitches.isEmpty()) { 15.8 - if (Context.DEBUG) { 15.9 - protoInvalidations += protoGetSwitches.size(); 15.10 + if (protoGetSwitches != null) { 15.11 + final int size = protoGetSwitches.size(); 15.12 + if (size > 0) { 15.13 + if (Context.DEBUG) { 15.14 + protoInvalidations += size; 15.15 + } 15.16 + SwitchPoint.invalidateAll(protoGetSwitches.values().toArray(new SwitchPoint[size])); 15.17 + protoGetSwitches.clear(); 15.18 } 15.19 - SwitchPoint.invalidateAll(protoGetSwitches.values().toArray(new SwitchPoint[protoGetSwitches.values().size()])); 15.20 - protoGetSwitches.clear(); 15.21 } 15.22 } 15.23 15.24 @@ -375,7 +378,8 @@ 15.25 } 15.26 } 15.27 15.28 - // Update the free slots bitmap for a property that has been deleted and/or added. 15.29 + // Update the free slots bitmap for a property that has been deleted and/or added. This method is not synchronized 15.30 + // as it is always invoked on a newly created instance. 15.31 private void updateFreeSlots(final Property oldProperty, final Property newProperty) { 15.32 // Free slots bitset is possibly shared with parent map, so we must clone it before making modifications. 15.33 boolean freeSlotsCloned = false; 15.34 @@ -425,7 +429,7 @@ 15.35 * 15.36 * @return New {@link PropertyMap} with {@link Property} added. 15.37 */ 15.38 - public PropertyMap addProperty(final Property property) { 15.39 + public synchronized PropertyMap addProperty(final Property property) { 15.40 if (listeners != null) { 15.41 listeners.propertyAdded(property); 15.42 } 15.43 @@ -434,9 +438,9 @@ 15.44 if (newMap == null) { 15.45 final PropertyHashMap newProperties = properties.immutableAdd(property); 15.46 newMap = new PropertyMap(this, newProperties); 15.47 - addToHistory(property, newMap); 15.48 newMap.updateFlagsAndBoundaries(property); 15.49 newMap.updateFreeSlots(null, property); 15.50 + addToHistory(property, newMap); 15.51 } 15.52 15.53 return newMap; 15.54 @@ -449,7 +453,7 @@ 15.55 * 15.56 * @return New {@link PropertyMap} with {@link Property} removed or {@code null} if not found. 15.57 */ 15.58 - public PropertyMap deleteProperty(final Property property) { 15.59 + public synchronized PropertyMap deleteProperty(final Property property) { 15.60 if (listeners != null) { 15.61 listeners.propertyDeleted(property); 15.62 } 15.63 @@ -881,8 +885,7 @@ 15.64 * @param newProto New prototype object to replace oldProto. 15.65 * @return New {@link PropertyMap} with prototype changed. 15.66 */ 15.67 - public PropertyMap changeProto(final ScriptObject newProto) { 15.68 - 15.69 + public synchronized PropertyMap changeProto(final ScriptObject newProto) { 15.70 final PropertyMap nextMap = checkProtoHistory(newProto); 15.71 if (nextMap != null) { 15.72 return nextMap;
16.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Wed Apr 01 11:35:19 2015 -0700 16.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Thu Apr 09 22:59:28 2015 -0700 16.3 @@ -812,7 +812,7 @@ 16.4 * 16.5 * @return FindPropertyData or null if not found. 16.6 */ 16.7 - FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) { 16.8 + protected FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) { 16.9 16.10 final PropertyMap selfMap = getMap(); 16.11 final Property property = selfMap.findProperty(key);
17.1 --- a/src/jdk/nashorn/internal/runtime/WithObject.java Wed Apr 01 11:35:19 2015 -0700 17.2 +++ b/src/jdk/nashorn/internal/runtime/WithObject.java Thu Apr 09 22:59:28 2015 -0700 17.3 @@ -198,7 +198,7 @@ 17.4 * @return FindPropertyData or null if not found. 17.5 */ 17.6 @Override 17.7 - FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) { 17.8 + protected FindProperty findProperty(final String key, final boolean deep, final ScriptObject start) { 17.9 // We call findProperty on 'expression' with 'expression' itself as start parameter. 17.10 // This way in ScriptObject.setObject we can tell the property is from a 'with' expression 17.11 // (as opposed from another non-scope object in the proto chain such as Object.prototype).
18.1 --- a/src/jdk/nashorn/internal/runtime/regexp/joni/ArrayCompiler.java Wed Apr 01 11:35:19 2015 -0700 18.2 +++ b/src/jdk/nashorn/internal/runtime/regexp/joni/ArrayCompiler.java Thu Apr 09 22:59:28 2015 -0700 18.3 @@ -145,9 +145,6 @@ 18.4 case TargetInfo.IS_EMPTY_MEM: 18.5 addOpcode(OPCode.NULL_CHECK_END_MEMST); 18.6 break; 18.7 - case TargetInfo.IS_EMPTY_REC: 18.8 - addOpcode(OPCode.NULL_CHECK_END_MEMST_PUSH); 18.9 - break; 18.10 default: 18.11 break; 18.12 } // switch
19.1 --- a/src/jdk/nashorn/internal/runtime/regexp/joni/ByteCodeMachine.java Wed Apr 01 11:35:19 2015 -0700 19.2 +++ b/src/jdk/nashorn/internal/runtime/regexp/joni/ByteCodeMachine.java Thu Apr 09 22:59:28 2015 -0700 19.3 @@ -183,7 +183,6 @@ 19.4 case OPCode.NULL_CHECK_START: opNullCheckStart(); continue; 19.5 case OPCode.NULL_CHECK_END: opNullCheckEnd(); continue; 19.6 case OPCode.NULL_CHECK_END_MEMST: opNullCheckEndMemST(); continue; 19.7 - case OPCode.NULL_CHECK_END_MEMST_PUSH: opNullCheckEndMemSTPush(); continue; 19.8 19.9 case OPCode.JUMP: opJump(); continue; 19.10 case OPCode.PUSH: opPush(); continue; 19.11 @@ -1025,29 +1024,6 @@ 19.12 } 19.13 } 19.14 19.15 - // USE_SUBEXP_CALL 19.16 - private void opNullCheckEndMemSTPush() { 19.17 - final int mem = code[ip++]; /* mem: null check id */ 19.18 - 19.19 - int isNull; 19.20 - if (Config.USE_MONOMANIAC_CHECK_CAPTURES_IN_ENDLESS_REPEAT) { 19.21 - isNull = nullCheckMemStRec(mem, s); 19.22 - } else { 19.23 - isNull = nullCheckRec(mem, s); 19.24 - } 19.25 - 19.26 - if (isNull != 0) { 19.27 - if (Config.DEBUG_MATCH) { 19.28 - Config.log.println("NULL_CHECK_END_MEMST_PUSH: skip id:" + mem + ", s:" + s); 19.29 - } 19.30 - 19.31 - if (isNull == -1) {opFail(); return;} 19.32 - nullCheckFound(); 19.33 - } else { 19.34 - pushNullCheckEnd(mem); 19.35 - } 19.36 - } 19.37 - 19.38 private void opJump() { 19.39 ip += code[ip] + 1; 19.40 }
20.1 --- a/src/jdk/nashorn/internal/runtime/regexp/joni/StackMachine.java Wed Apr 01 11:35:19 2015 -0700 20.2 +++ b/src/jdk/nashorn/internal/runtime/regexp/joni/StackMachine.java Thu Apr 09 22:59:28 2015 -0700 20.3 @@ -19,7 +19,6 @@ 20.4 */ 20.5 package jdk.nashorn.internal.runtime.regexp.joni; 20.6 20.7 -import static jdk.nashorn.internal.runtime.regexp.joni.BitStatus.bsAt; 20.8 import java.lang.ref.WeakReference; 20.9 import jdk.nashorn.internal.runtime.regexp.joni.constants.StackPopLevel; 20.10 import jdk.nashorn.internal.runtime.regexp.joni.constants.StackType; 20.11 @@ -369,118 +368,9 @@ 20.12 } 20.13 } 20.14 20.15 - protected final int nullCheckRec(final int id, final int s) { 20.16 - int level = 0; 20.17 - int k = stk; 20.18 - while (true) { 20.19 - k--; 20.20 - final StackEntry e = stack[k]; 20.21 - 20.22 - if (e.type == NULL_CHECK_START) { 20.23 - if (e.getNullCheckNum() == id) { 20.24 - if (level == 0) { 20.25 - return e.getNullCheckPStr() == s ? 1 : 0; 20.26 - } 20.27 - level--; 20.28 - } 20.29 - } else if (e.type == NULL_CHECK_END) { 20.30 - level++; 20.31 - } 20.32 - } 20.33 - } 20.34 - 20.35 protected final int nullCheckMemSt(final int id, final int s) { 20.36 - int k = stk; 20.37 - int isNull; 20.38 - while (true) { 20.39 - k--; 20.40 - StackEntry e = stack[k]; 20.41 - 20.42 - if (e.type == NULL_CHECK_START) { 20.43 - if (e.getNullCheckNum() == id) { 20.44 - if (e.getNullCheckPStr() != s) { 20.45 - isNull = 0; 20.46 - break; 20.47 - } 20.48 - int endp; 20.49 - isNull = 1; 20.50 - while (k < stk) { 20.51 - if (e.type == MEM_START) { 20.52 - if (e.getMemEnd() == INVALID_INDEX) { 20.53 - isNull = 0; 20.54 - break; 20.55 - } 20.56 - if (bsAt(regex.btMemEnd, e.getMemNum())) { 20.57 - endp = stack[e.getMemEnd()].getMemPStr(); 20.58 - } else { 20.59 - endp = e.getMemEnd(); 20.60 - } 20.61 - if (stack[e.getMemStart()].getMemPStr() != endp) { 20.62 - isNull = 0; 20.63 - break; 20.64 - } else if (endp != s) { 20.65 - isNull = -1; /* empty, but position changed */ 20.66 - } 20.67 - } 20.68 - k++; 20.69 - e = stack[k]; // !! 20.70 - } 20.71 - break; 20.72 - } 20.73 - } 20.74 - } 20.75 - return isNull; 20.76 - } 20.77 - 20.78 - protected final int nullCheckMemStRec(final int id, final int s) { 20.79 - int level = 0; 20.80 - int k = stk; 20.81 - int isNull; 20.82 - while (true) { 20.83 - k--; 20.84 - StackEntry e = stack[k]; 20.85 - 20.86 - if (e.type == NULL_CHECK_START) { 20.87 - if (e.getNullCheckNum() == id) { 20.88 - if (level == 0) { 20.89 - if (e.getNullCheckPStr() != s) { 20.90 - isNull = 0; 20.91 - break; 20.92 - } 20.93 - int endp; 20.94 - isNull = 1; 20.95 - while (k < stk) { 20.96 - if (e.type == MEM_START) { 20.97 - if (e.getMemEnd() == INVALID_INDEX) { 20.98 - isNull = 0; 20.99 - break; 20.100 - } 20.101 - if (bsAt(regex.btMemEnd, e.getMemNum())) { 20.102 - endp = stack[e.getMemEnd()].getMemPStr(); 20.103 - } else { 20.104 - endp = e.getMemEnd(); 20.105 - } 20.106 - if (stack[e.getMemStart()].getMemPStr() != endp) { 20.107 - isNull = 0; 20.108 - break; 20.109 - } else if (endp != s) { 20.110 - isNull = -1; /* empty, but position changed */ 20.111 - } 20.112 - } 20.113 - k++; 20.114 - e = stack[k]; 20.115 - } 20.116 - break; 20.117 - } 20.118 - level--; 20.119 - } 20.120 - } else if (e.type == NULL_CHECK_END) { 20.121 - if (e.getNullCheckNum() == id) { 20.122 - level++; 20.123 - } 20.124 - } 20.125 - } 20.126 - return isNull; 20.127 + // Return -1 here to cause operation to fail 20.128 + return -nullCheck(id, s); 20.129 } 20.130 20.131 protected final int getRepeat(final int id) {
21.1 --- a/src/jdk/nashorn/internal/runtime/regexp/joni/constants/TargetInfo.java Wed Apr 01 11:35:19 2015 -0700 21.2 +++ b/src/jdk/nashorn/internal/runtime/regexp/joni/constants/TargetInfo.java Thu Apr 09 22:59:28 2015 -0700 21.3 @@ -24,5 +24,4 @@ 21.4 final int ISNOT_EMPTY = 0; 21.5 final int IS_EMPTY = 1; 21.6 final int IS_EMPTY_MEM = 2; 21.7 - final int IS_EMPTY_REC = 3; 21.8 }
22.1 --- a/src/jdk/nashorn/tools/Shell.java Wed Apr 01 11:35:19 2015 -0700 22.2 +++ b/src/jdk/nashorn/tools/Shell.java Thu Apr 09 22:59:28 2015 -0700 22.3 @@ -109,7 +109,10 @@ 22.4 */ 22.5 public static void main(final String[] args) { 22.6 try { 22.7 - System.exit(main(System.in, System.out, System.err, args)); 22.8 + final int exitCode = main(System.in, System.out, System.err, args); 22.9 + if (exitCode != SUCCESS) { 22.10 + System.exit(exitCode); 22.11 + } 22.12 } catch (final IOException e) { 22.13 System.err.println(e); //bootstrapping, Context.err may not exist 22.14 System.exit(IO_ERROR); 22.15 @@ -414,18 +417,7 @@ 22.16 Context.setGlobal(global); 22.17 } 22.18 22.19 - // initialize with "shell.js" script 22.20 - try { 22.21 - final Source source = sourceFor("<shell.js>", Shell.class.getResource("resources/shell.js")); 22.22 - context.eval(global, source.getString(), global, "<shell.js>", false); 22.23 - } catch (final Exception e) { 22.24 - err.println(e); 22.25 - if (env._dump_on_error) { 22.26 - e.printStackTrace(err); 22.27 - } 22.28 - 22.29 - return INTERNAL_ERROR; 22.30 - } 22.31 + global.addShellBuiltins(); 22.32 22.33 while (true) { 22.34 err.print(prompt);
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/src/jdk/nashorn/tools/ShellFunctions.java Thu Apr 09 22:59:28 2015 -0700 23.3 @@ -0,0 +1,104 @@ 23.4 +/* 23.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 23.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 23.7 + * 23.8 + * This code is free software; you can redistribute it and/or modify it 23.9 + * under the terms of the GNU General Public License version 2 only, as 23.10 + * published by the Free Software Foundation. Oracle designates this 23.11 + * particular file as subject to the "Classpath" exception as provided 23.12 + * by Oracle in the LICENSE file that accompanied this code. 23.13 + * 23.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 23.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 23.17 + * version 2 for more details (a copy is included in the LICENSE file that 23.18 + * accompanied this code). 23.19 + * 23.20 + * You should have received a copy of the GNU General Public License version 23.21 + * 2 along with this work; if not, write to the Free Software Foundation, 23.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 23.23 + * 23.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 23.25 + * or visit www.oracle.com if you need additional information or have any 23.26 + * questions. 23.27 + */ 23.28 + 23.29 +package jdk.nashorn.tools; 23.30 + 23.31 +import static jdk.nashorn.internal.lookup.Lookup.MH; 23.32 +import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; 23.33 + 23.34 +import java.io.BufferedReader; 23.35 +import java.io.File; 23.36 +import java.io.IOException; 23.37 +import java.io.InputStreamReader; 23.38 +import java.io.OutputStreamWriter; 23.39 +import java.lang.invoke.MethodHandle; 23.40 +import java.lang.invoke.MethodHandles; 23.41 +import jdk.nashorn.internal.runtime.JSType; 23.42 +import jdk.nashorn.internal.objects.Global; 23.43 + 23.44 +/** 23.45 + * Global functions supported only in shell interactive mode. 23.46 + */ 23.47 +public final class ShellFunctions { 23.48 + 23.49 + /** Handle to implementation of {@link ShellFunctions#input} - Nashorn extension */ 23.50 + public static final MethodHandle INPUT = findOwnMH("input", Object.class, Object.class, Object.class, Object.class); 23.51 + 23.52 + /** Handle to implementation of {@link ShellFunctions#evalinput} - Nashorn extension */ 23.53 + public static final MethodHandle EVALINPUT = findOwnMH("evalinput", Object.class, Object.class, Object.class, Object.class); 23.54 + 23.55 + private ShellFunctions() { 23.56 + } 23.57 + 23.58 + /** 23.59 + * Nashorn extension: global.input (shell-interactive-mode-only) 23.60 + * Read one or more lines of input from the standard input till the 23.61 + * given end marker is seen in standard input. 23.62 + * 23.63 + * @param self self reference 23.64 + * @param endMarker String used as end marker for input 23.65 + * @param prompt String used as input prompt 23.66 + * 23.67 + * @return line that was read 23.68 + * 23.69 + * @throws IOException if an exception occurs 23.70 + */ 23.71 + public static Object input(final Object self, final Object endMarker, final Object prompt) throws IOException { 23.72 + final String endMarkerStr = (endMarker != UNDEFINED)? JSType.toString(endMarker) : ""; 23.73 + final String promptStr = (prompt != UNDEFINED)? JSType.toString(prompt) : ">> "; 23.74 + final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 23.75 + final StringBuilder buf = new StringBuilder(); 23.76 + while (true) { 23.77 + System.out.print(promptStr); 23.78 + final String line = reader.readLine(); 23.79 + if (line == null || line.equals(endMarkerStr)) { 23.80 + break; 23.81 + } 23.82 + buf.append(line); 23.83 + buf.append('\n'); 23.84 + } 23.85 + return buf.toString(); 23.86 + } 23.87 + 23.88 + /** 23.89 + * Nashorn extension: Reads zero or more lines from standard input and 23.90 + * evaluates the concatenated string as code 23.91 + * 23.92 + * @param self self reference 23.93 + * @param endMarker String used as end marker for input 23.94 + * @param prompt String used as input prompt 23.95 + * 23.96 + * @return output from evaluating the script 23.97 + * 23.98 + * @throws IOException if an exception occurs 23.99 + */ 23.100 + public static Object evalinput(final Object self, final Object endMarker, final Object prompt) throws IOException { 23.101 + return Global.eval(self, input(self, endMarker, prompt)); 23.102 + } 23.103 + 23.104 + private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) { 23.105 + return MH.findStatic(MethodHandles.lookup(), ShellFunctions.class, name, MH.type(rtype, types)); 23.106 + } 23.107 +}
24.1 --- a/src/jdk/nashorn/tools/resources/shell.js Wed Apr 01 11:35:19 2015 -0700 24.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 24.3 @@ -1,83 +0,0 @@ 24.4 -/* 24.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 24.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 24.7 - * 24.8 - * This code is free software; you can redistribute it and/or modify it 24.9 - * under the terms of the GNU General Public License version 2 only, as 24.10 - * published by the Free Software Foundation. 24.11 - * 24.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 24.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 24.15 - * version 2 for more details (a copy is included in the LICENSE file that 24.16 - * accompanied this code). 24.17 - * 24.18 - * You should have received a copy of the GNU General Public License version 24.19 - * 2 along with this work; if not, write to the Free Software Foundation, 24.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 24.21 - * 24.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 24.23 - * or visit www.oracle.com if you need additional information or have any 24.24 - * questions. 24.25 - */ 24.26 - 24.27 -/* 24.28 - * Initialization script for shell when running in interactive mode. 24.29 - */ 24.30 - 24.31 -/** 24.32 - * Reads zero or more lines from standard input and returns concatenated string 24.33 - * 24.34 - * @param endMarker marker string that signals end of input 24.35 - * @param prompt prompt printed for each line 24.36 - */ 24.37 -Object.defineProperty(this, "input", { 24.38 - value: function input(endMarker, prompt) { 24.39 - if (!endMarker) { 24.40 - endMarker = ""; 24.41 - } 24.42 - 24.43 - if (!prompt) { 24.44 - prompt = " >> "; 24.45 - } 24.46 - 24.47 - var imports = new JavaImporter(java.io, java.lang); 24.48 - var str = ""; 24.49 - with (imports) { 24.50 - var reader = new BufferedReader(new InputStreamReader(System['in'])); 24.51 - var line; 24.52 - while (true) { 24.53 - System.out.print(prompt); 24.54 - line = reader.readLine(); 24.55 - if (line == null || line == endMarker) { 24.56 - break; 24.57 - } 24.58 - str += line + "\n"; 24.59 - } 24.60 - } 24.61 - 24.62 - return str; 24.63 - }, 24.64 - enumerable: false, 24.65 - writable: true, 24.66 - configurable: true 24.67 -}); 24.68 - 24.69 - 24.70 -/** 24.71 - * Reads zero or more lines from standard input and evaluates the concatenated 24.72 - * string as code 24.73 - * 24.74 - * @param endMarker marker string that signals end of input 24.75 - * @param prompt prompt printed for each line 24.76 - */ 24.77 -Object.defineProperty(this, "evalinput", { 24.78 - value: function evalinput(endMarker, prompt) { 24.79 - var code = input(endMarker, prompt); 24.80 - // make sure everything is evaluated in global scope! 24.81 - return this.eval(code); 24.82 - }, 24.83 - enumerable: false, 24.84 - writable: true, 24.85 - configurable: true 24.86 -});
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 25.2 +++ b/test/script/basic/JDK-8073868.js Thu Apr 09 22:59:28 2015 -0700 25.3 @@ -0,0 +1,45 @@ 25.4 +/* 25.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 25.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 25.7 + * 25.8 + * This code is free software; you can redistribute it and/or modify it 25.9 + * under the terms of the GNU General Public License version 2 only, as 25.10 + * published by the Free Software Foundation. 25.11 + * 25.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 25.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 25.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25.15 + * version 2 for more details (a copy is included in the LICENSE file that 25.16 + * accompanied this code). 25.17 + * 25.18 + * You should have received a copy of the GNU General Public License version 25.19 + * 2 along with this work; if not, write to the Free Software Foundation, 25.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 25.21 + * 25.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 25.23 + * or visit www.oracle.com if you need additional information or have any 25.24 + * questions. 25.25 + */ 25.26 + 25.27 +/** 25.28 + * JDK-8073868: Regex matching causes java.lang.ArrayIndexOutOfBoundsException: 64 25.29 + * 25.30 + * @test 25.31 + * @run 25.32 + */ 25.33 + 25.34 +function test(input) { 25.35 + var comma = input.indexOf(","); 25.36 + Assert.assertEquals(/([^\s]+),(.*)+/.exec(input)[0], input.trimLeft()); 25.37 + Assert.assertEquals(/([^\s]+),(.*)+/.exec(input)[1], input.substring(0, comma).trimLeft()); 25.38 + Assert.assertEquals(/([^\s]+),(.*)+/.exec(input)[2], input.substring(comma + 1)); 25.39 + Assert.assertEquals(/(.*)+/.exec(input)[0], input); 25.40 + Assert.assertEquals(/(.*)+/.exec(input)[1], input); 25.41 +} 25.42 + 25.43 +test(" xxxx, xxx xxxxxx xxxxxxxxx xxxxxxx, xxxx xxxxx xxxxx "); 25.44 +test(" xxxx, xxx xxxxxx xxxxxxxxx xxxxxxx, xxxx xxxxx xxxxx "); 25.45 +test("x, xxxxxxxxxx xxxxxxxxx xxxxxxx, xxxx xxxxx xxxxx "); 25.46 + 25.47 +Assert.assertEquals(/(?:\1a|())*/.exec("a")[0], "a"); 25.48 +Assert.assertEquals(/(?:\1a|())*/.exec("a")[1], undefined);
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 26.2 +++ b/test/script/basic/JDK-8075927.js Thu Apr 09 22:59:28 2015 -0700 26.3 @@ -0,0 +1,38 @@ 26.4 +/* 26.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 26.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 26.7 + * 26.8 + * This code is free software; you can redistribute it and/or modify it 26.9 + * under the terms of the GNU General Public License version 2 only, as 26.10 + * published by the Free Software Foundation. 26.11 + * 26.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 26.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 26.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 26.15 + * version 2 for more details (a copy is included in the LICENSE file that 26.16 + * accompanied this code). 26.17 + * 26.18 + * You should have received a copy of the GNU General Public License version 26.19 + * 2 along with this work; if not, write to the Free Software Foundation, 26.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 26.21 + * 26.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 26.23 + * or visit www.oracle.com if you need additional information or have any 26.24 + * questions. 26.25 + */ 26.26 + 26.27 +/** 26.28 + * JDK-8075927: toNumber(String) accepts illegal characters 26.29 + * 26.30 + * @test 26.31 + * @run 26.32 + */ 26.33 + 26.34 +Assert.assertTrue(isNaN(Number("-123d"))); 26.35 +Assert.assertTrue(isNaN(Number("-123f"))); 26.36 +Assert.assertTrue(Number(" 123 ") === 123); 26.37 +Assert.assertTrue(Number(" -123 ") === -123); 26.38 +Assert.assertEquals(Number(" Infinity "), Infinity); 26.39 +Assert.assertEquals(Number(" +Infinity "), Infinity); 26.40 +Assert.assertEquals(Number(" -Infinity "), -Infinity); 26.41 +
27.1 --- a/test/script/basic/es6/let-eval.js Wed Apr 01 11:35:19 2015 -0700 27.2 +++ b/test/script/basic/es6/let-eval.js Thu Apr 09 22:59:28 2015 -0700 27.3 @@ -96,3 +96,9 @@ 27.4 f(); 27.5 27.6 print(typeof a, typeof b, typeof c, typeof x, typeof z); 27.7 + 27.8 +let v = 1; 27.9 +eval("print('v: ' + v); v = 2; print ('v: ' + v);"); 27.10 +print("this.v: " + this.v); 27.11 +print("v: " + v); 27.12 +
28.1 --- a/test/script/basic/es6/let-eval.js.EXPECTED Wed Apr 01 11:35:19 2015 -0700 28.2 +++ b/test/script/basic/es6/let-eval.js.EXPECTED Thu Apr 09 22:59:28 2015 -0700 28.3 @@ -14,3 +14,7 @@ 28.4 2 1 0 28.5 2 1 0 undefined 28.6 undefined undefined undefined undefined undefined 28.7 +v: 1 28.8 +v: 2 28.9 +this.v: undefined 28.10 +v: 2