203 /** ECMA 15.1.4.2 Function constructor. */
204 @Property(name = "Function", attributes = Attribute.NOT_ENUMERABLE)
205 public volatile Object function;
206
207 /** ECMA 15.1.4.3 Array constructor. */
208 @Property(name = "Array", attributes = Attribute.NOT_ENUMERABLE)
209 public volatile Object array;
210
211 /** ECMA 15.1.4.4 String constructor */
212 @Property(name = "String", attributes = Attribute.NOT_ENUMERABLE)
213 public volatile Object string;
214
215 /** ECMA 15.1.4.5 Boolean constructor */
216 @Property(name = "Boolean", attributes = Attribute.NOT_ENUMERABLE)
217 public volatile Object _boolean;
218
219 /** ECMA 15.1.4.6 - Number constructor */
220 @Property(name = "Number", attributes = Attribute.NOT_ENUMERABLE)
221 public volatile Object number;
222
223 /** ECMA 15.1.4.7 Date constructor */
224 @Getter(name = "Date", attributes = Attribute.NOT_ENUMERABLE)
225 public static Object getDate(final Object self) {
226 final Global global = Global.instanceFrom(self);
227 if (global.date == LAZY_SENTINEL) {
228 global.date = global.getBuiltinDate();
229 }
230 return global.date;
231 }
232
233 @Setter(name = "Date", attributes = Attribute.NOT_ENUMERABLE)
234 public static void setDate(final Object self, final Object value) {
235 final Global global = Global.instanceFrom(self);
236 global.date = value;
237 }
238
239 private volatile Object date = LAZY_SENTINEL;
240
241 /** ECMA 15.1.4.8 RegExp constructor */
242 @Getter(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE)
243 public static Object getRegExp(final Object self) {
244 final Global global = Global.instanceFrom(self);
245 if (global.regexp == LAZY_SENTINEL) {
246 global.regexp = global.getBuiltinRegExp();
247 }
248 return global.regexp;
249 }
250
251 @Setter(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE)
252 public static void setRegExp(final Object self, final Object value) {
253 final Global global = Global.instanceFrom(self);
254 global.regexp = value;
255 }
256
257 private volatile Object regexp = LAZY_SENTINEL;
258
259 /** ECMA 15.12 - The JSON object */
260 @Getter(name = "JSON", attributes = Attribute.NOT_ENUMERABLE)
261 public static Object getJSON(final Object self) {
262 final Global global = Global.instanceFrom(self);
263 if (global.json == LAZY_SENTINEL) {
264 global.json = global.getBuiltinJSON();
265 }
266 return global.json;
267 }
268
269 @Setter(name = "JSON", attributes = Attribute.NOT_ENUMERABLE)
270 public static void setJSON(final Object self, final Object value) {
271 final Global global = Global.instanceFrom(self);
272 global.json = value;
273 }
274
275 private volatile Object json = LAZY_SENTINEL;
276
277 /** Nashorn extension: global.JSAdapter */
278 @Getter(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE)
279 public static Object getJSAdapter(final Object self) {
280 final Global global = Global.instanceFrom(self);
281 if (global.jsadapter == LAZY_SENTINEL) {
282 global.jsadapter = global.getBuiltinJSAdapter();
283 }
284 return global.jsadapter;
285 }
286
287 @Setter(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE)
288 public static void setJSAdapter(final Object self, final Object value) {
289 final Global global = Global.instanceFrom(self);
290 global.jsadapter = value;
291 }
292
293 private volatile Object jsadapter = LAZY_SENTINEL;
294
295 /** ECMA 15.8 - The Math object */
296 @Property(name = "Math", attributes = Attribute.NOT_ENUMERABLE)
297 public volatile Object math;
298
299 /** Error object */
300 @Property(name = "Error", attributes = Attribute.NOT_ENUMERABLE)
301 public volatile Object error;
302
303 /** EvalError object */
304 @Getter(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE)
305 public static Object getEvalError(final Object self) {
306 final Global global = Global.instanceFrom(self);
307 if (global.evalError == LAZY_SENTINEL) {
308 global.evalError = global.getBuiltinEvalError();
309 }
310 return global.evalError;
311 }
312
313 @Setter(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE)
314 public static void setEvalError(final Object self, final Object value) {
315 final Global global = Global.instanceFrom(self);
316 global.evalError = value;
317 }
318
319 private volatile Object evalError = LAZY_SENTINEL;
320
321 /** RangeError object */
322 @Getter(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE)
323 public static Object getRangeError(final Object self) {
324 final Global global = Global.instanceFrom(self);
325 if (global.rangeError == LAZY_SENTINEL) {
326 global.rangeError = global.getBuiltinRangeError();
327 }
328 return global.rangeError;
329 }
330
331 @Setter(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE)
332 public static void setRangeError(final Object self, final Object value) {
333 final Global global = Global.instanceFrom(self);
334 global.rangeError = value;
335 }
336
337 private volatile Object rangeError = LAZY_SENTINEL;
338
339 /** ReferenceError object */
340 @Property(name = "ReferenceError", attributes = Attribute.NOT_ENUMERABLE)
341 public volatile Object referenceError;
342
343 /** SyntaxError object */
344 @Property(name = "SyntaxError", attributes = Attribute.NOT_ENUMERABLE)
345 public volatile Object syntaxError;
346
347 /** TypeError object */
348 @Property(name = "TypeError", attributes = Attribute.NOT_ENUMERABLE)
349 public volatile Object typeError;
350
351 /** URIError object */
352 @Getter(name = "URIError", attributes = Attribute.NOT_ENUMERABLE)
353 public static Object getURIError(final Object self) {
354 final Global global = Global.instanceFrom(self);
355 if (global.uriError == LAZY_SENTINEL) {
356 global.uriError = global.getBuiltinURIError();
357 }
358 return global.uriError;
359 }
360
361 @Setter(name = "URIError", attributes = Attribute.NOT_ENUMERABLE)
362 public static void setURIError(final Object self, final Object value) {
363 final Global global = Global.instanceFrom(self);
364 global.uriError = value;
365 }
366
367 private volatile Object uriError = LAZY_SENTINEL;
368
369 /** ArrayBuffer object */
370 @Getter(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE)
371 public static Object getArrayBuffer(final Object self) {
372 final Global global = Global.instanceFrom(self);
373 if (global.arrayBuffer == LAZY_SENTINEL) {
374 global.arrayBuffer = global.getBuiltinArrayBuffer();
375 }
376 return global.arrayBuffer;
377 }
378
379 @Setter(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE)
380 public static void setArrayBuffer(final Object self, final Object value) {
381 final Global global = Global.instanceFrom(self);
382 global.arrayBuffer = value;
383 }
384
385 private volatile Object arrayBuffer;
386
387 /** DataView object */
388 @Getter(name = "DataView", attributes = Attribute.NOT_ENUMERABLE)
389 public static Object getDataView(final Object self) {
390 final Global global = Global.instanceFrom(self);
391 if (global.dataView == LAZY_SENTINEL) {
392 global.dataView = global.getBuiltinDataView();
393 }
394 return global.dataView;
395 }
396
397 @Setter(name = "DataView", attributes = Attribute.NOT_ENUMERABLE)
398 public static void setDataView(final Object self, final Object value) {
399 final Global global = Global.instanceFrom(self);
400 global.dataView = value;
401 }
402
403 private volatile Object dataView;
404
405 /** TypedArray (int8) */
406 @Getter(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE)
407 public static Object getInt8Array(final Object self) {
408 final Global global = Global.instanceFrom(self);
409 if (global.int8Array == LAZY_SENTINEL) {
410 global.int8Array = global.getBuiltinInt8Array();
411 }
412 return global.int8Array;
413 }
414
415 @Setter(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE)
416 public static void setInt8Array(final Object self, final Object value) {
417 final Global global = Global.instanceFrom(self);
418 global.int8Array = value;
419 }
420
421 private volatile Object int8Array;
422
423 /** TypedArray (uint8) */
424 @Getter(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE)
425 public static Object getUint8Array(final Object self) {
426 final Global global = Global.instanceFrom(self);
427 if (global.uint8Array == LAZY_SENTINEL) {
428 global.uint8Array = global.getBuiltinUint8Array();
429 }
430 return global.uint8Array;
431 }
432
433 @Setter(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE)
434 public static void setUint8Array(final Object self, final Object value) {
435 final Global global = Global.instanceFrom(self);
436 global.uint8Array = value;
437 }
438
439 private volatile Object uint8Array;
440
441 /** TypedArray (uint8) - Clamped */
442 @Getter(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE)
443 public static Object getUint8ClampedArray(final Object self) {
444 final Global global = Global.instanceFrom(self);
445 if (global.uint8ClampedArray == LAZY_SENTINEL) {
446 global.uint8ClampedArray = global.getBuiltinUint8ClampedArray();
447 }
448 return global.uint8ClampedArray;
449 }
450
451 @Setter(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE)
452 public static void setUint8ClampedArray(final Object self, final Object value) {
453 final Global global = Global.instanceFrom(self);
454 global.uint8ClampedArray = value;
455 }
456
457 private volatile Object uint8ClampedArray;
458
459 /** TypedArray (int16) */
460 @Getter(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE)
461 public static Object getInt16Array(final Object self) {
462 final Global global = Global.instanceFrom(self);
463 if (global.int16Array == LAZY_SENTINEL) {
464 global.int16Array = global.getBuiltinInt16Array();
465 }
466 return global.int16Array;
467 }
468
469 @Setter(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE)
470 public static void setInt16Array(final Object self, final Object value) {
471 final Global global = Global.instanceFrom(self);
472 global.int16Array = value;
473 }
474
475 private volatile Object int16Array;
476
477 /** TypedArray (uint16) */
478 @Getter(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE)
479 public static Object getUint16Array(final Object self) {
480 final Global global = Global.instanceFrom(self);
481 if (global.uint16Array == LAZY_SENTINEL) {
482 global.uint16Array = global.getBuiltinUint16Array();
483 }
484 return global.uint16Array;
485 }
486
487 @Setter(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE)
488 public static void setUint16Array(final Object self, final Object value) {
489 final Global global = Global.instanceFrom(self);
490 global.uint16Array = value;
491 }
492
493 private volatile Object uint16Array;
494
495 /** TypedArray (int32) */
496 @Getter(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE)
497 public static Object getInt32Array(final Object self) {
498 final Global global = Global.instanceFrom(self);
499 if (global.int32Array == LAZY_SENTINEL) {
500 global.int32Array = global.getBuiltinInt32Array();
501 }
502 return global.int32Array;
503 }
504
505 @Setter(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE)
506 public static void setInt32Array(final Object self, final Object value) {
507 final Global global = Global.instanceFrom(self);
508 global.int32Array = value;
509 }
510
511 private volatile Object int32Array;
512
513 /** TypedArray (uint32) */
514 @Getter(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE)
515 public static Object getUint32Array(final Object self) {
516 final Global global = Global.instanceFrom(self);
517 if (global.uint32Array == LAZY_SENTINEL) {
518 global.uint32Array = global.getBuiltinUint32Array();
519 }
520 return global.uint32Array;
521 }
522
523 @Setter(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE)
524 public static void setUint32Array(final Object self, final Object value) {
525 final Global global = Global.instanceFrom(self);
526 global.uint32Array = value;
527 }
528
529 private volatile Object uint32Array;
530
531 /** TypedArray (float32) */
532 @Getter(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE)
533 public static Object getFloat32Array(final Object self) {
534 final Global global = Global.instanceFrom(self);
535 if (global.float32Array == LAZY_SENTINEL) {
536 global.float32Array = global.getBuiltinFloat32Array();
537 }
538 return global.float32Array;
539 }
540
541 @Setter(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE)
542 public static void setFloat32Array(final Object self, final Object value) {
543 final Global global = Global.instanceFrom(self);
544 global.float32Array = value;
545 }
546
547 private volatile Object float32Array;
548
549 /** TypedArray (float64) */
550 @Getter(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE)
551 public static Object getFloat64Array(final Object self) {
552 final Global global = Global.instanceFrom(self);
553 if (global.float64Array == LAZY_SENTINEL) {
554 global.float64Array = global.getBuiltinFloat64Array();
555 }
556 return global.float64Array;
557 }
558
559 @Setter(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE)
560 public static void setFloat64Array(final Object self, final Object value) {
561 final Global global = Global.instanceFrom(self);
562 global.float64Array = value;
563 }
564
565 private volatile Object float64Array;
566
567 /** Nashorn extension: Java access - global.Packages */
568 @Property(name = "Packages", attributes = Attribute.NOT_ENUMERABLE)
569 public volatile Object packages;
570
571 /** Nashorn extension: Java access - global.com */
572 @Property(attributes = Attribute.NOT_ENUMERABLE)
573 public volatile Object com;
574
575 /** Nashorn extension: Java access - global.edu */
576 @Property(attributes = Attribute.NOT_ENUMERABLE)
577 public volatile Object edu;
578
579 /** Nashorn extension: Java access - global.java */
580 @Property(attributes = Attribute.NOT_ENUMERABLE)
581 public volatile Object java;
582
583 /** Nashorn extension: Java access - global.javafx */
584 @Property(attributes = Attribute.NOT_ENUMERABLE)
585 public volatile Object javafx;
586
587 /** Nashorn extension: Java access - global.javax */
588 @Property(attributes = Attribute.NOT_ENUMERABLE)
589 public volatile Object javax;
590
591 /** Nashorn extension: Java access - global.org */
592 @Property(attributes = Attribute.NOT_ENUMERABLE)
593 public volatile Object org;
594
595 /** Nashorn extension: Java access - global.javaImporter */
596 @Getter(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE)
597 public static Object getJavaImporter(final Object self) {
598 final Global global = Global.instanceFrom(self);
599 if (global.javaImporter == LAZY_SENTINEL) {
600 global.javaImporter = global.getBuiltinJavaImporter();
601 }
602 return global.javaImporter;
603 }
604
605 @Setter(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE)
606 public static void setJavaImporter(final Object self, final Object value) {
607 final Global global = Global.instanceFrom(self);
608 global.javaImporter = value;
609 }
610
611 private volatile Object javaImporter;
612
613 /** Nashorn extension: global.Java Object constructor. */
614 @Getter(name = "Java", attributes = Attribute.NOT_ENUMERABLE)
615 public static Object getJavaApi(final Object self) {
616 final Global global = Global.instanceFrom(self);
617 if (global.javaApi == LAZY_SENTINEL) {
618 global.javaApi = global.getBuiltinJavaApi();
619 }
620 return global.javaApi;
621 }
622
623 @Setter(name = "Java", attributes = Attribute.NOT_ENUMERABLE)
624 public static void setJavaApi(final Object self, final Object value) {
625 final Global global = Global.instanceFrom(self);
626 global.javaApi = value;
627 }
628
629 private volatile Object javaApi;
630
631 /** Nashorn extension: current script's file name */
632 @Property(name = "__FILE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
633 public final Object __FILE__ = LOCATION_PROPERTY_PLACEHOLDER;
634
635 /** Nashorn extension: current script's directory */
636 @Property(name = "__DIR__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
637 public final Object __DIR__ = LOCATION_PROPERTY_PLACEHOLDER;
638
639 /** Nashorn extension: current source line number being executed */
640 @Property(name = "__LINE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
641 public final Object __LINE__ = LOCATION_PROPERTY_PLACEHOLDER;
642
2123 *
2124 * @param state current split state
2125 */
2126 @Override
2127 public void setSplitState(final int state) {
2128 splitState = state;
2129 }
2130
2131 /**
2132 * Return the ES6 global scope for lexically declared bindings.
2133 * @return the ES6 lexical global scope.
2134 */
2135 public final ScriptObject getLexicalScope() {
2136 assert context.getEnv()._es6;
2137 return lexicalScope;
2138 }
2139
2140 @Override
2141 public void addBoundProperties(final ScriptObject source, final jdk.nashorn.internal.runtime.Property[] properties) {
2142 PropertyMap ownMap = getMap();
2143 LexicalScope lexicalScope = null;
2144 PropertyMap lexicalMap = null;
2145 boolean hasLexicalDefinitions = false;
2146
2147 if (context.getEnv()._es6) {
2148 lexicalScope = (LexicalScope) getLexicalScope();
2149 lexicalMap = lexicalScope.getMap();
2150
2151 for (final jdk.nashorn.internal.runtime.Property property : properties) {
2152 if (property.isLexicalBinding()) {
2153 hasLexicalDefinitions = true;
2154 }
2155 // ES6 15.1.8 steps 6. and 7.
2156 final jdk.nashorn.internal.runtime.Property globalProperty = ownMap.findProperty(property.getKey());
2157 if (globalProperty != null && !globalProperty.isConfigurable() && property.isLexicalBinding()) {
2158 throw ECMAErrors.syntaxError("redeclare.variable", property.getKey());
2159 }
2160 final jdk.nashorn.internal.runtime.Property lexicalProperty = lexicalMap.findProperty(property.getKey());
2161 if (lexicalProperty != null && !property.isConfigurable()) {
2162 throw ECMAErrors.syntaxError("redeclare.variable", property.getKey());
2163 }
2164 }
2165 }
2166
2167 for (final jdk.nashorn.internal.runtime.Property property : properties) {
2168 if (property.isLexicalBinding()) {
2169 assert lexicalScope != null;
2170 lexicalMap = lexicalScope.addBoundProperty(lexicalMap, source, property);
2171
2172 if (ownMap.findProperty(property.getKey()) != null) {
2173 // If property exists in the global object invalidate any global constant call sites.
2174 invalidateGlobalConstant(property.getKey());
2175 }
2176 } else {
2177 ownMap = addBoundProperty(ownMap, source, property);
2178 }
2179 }
2180
2181 setMap(ownMap);
2182
2183 if (hasLexicalDefinitions) {
2184 lexicalScope.setMap(lexicalMap);
2185 invalidateLexicalSwitchPoint();
2186 }
2187 }
2188
2189 @Override
2190 public GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request, final String operator) {
2191 final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
2192 final boolean isScope = NashornCallSiteDescriptor.isScope(desc);
2193
2194 if (lexicalScope != null && isScope && !NashornCallSiteDescriptor.isApplyToCall(desc)) {
2195 if (lexicalScope.hasOwnProperty(name)) {
2196 return lexicalScope.findGetMethod(desc, request, operator);
2197 }
2198 }
2199
2200 final GuardedInvocation invocation = super.findGetMethod(desc, request, operator);
2201
2202 // We want to avoid adding our generic lexical scope switchpoint to global constant invocations,
2203 // because those are invalidated per-key in the addBoundProperties method above.
2204 // We therefor check if the invocation does already have a switchpoint and the property is non-inherited,
|
203 /** ECMA 15.1.4.2 Function constructor. */
204 @Property(name = "Function", attributes = Attribute.NOT_ENUMERABLE)
205 public volatile Object function;
206
207 /** ECMA 15.1.4.3 Array constructor. */
208 @Property(name = "Array", attributes = Attribute.NOT_ENUMERABLE)
209 public volatile Object array;
210
211 /** ECMA 15.1.4.4 String constructor */
212 @Property(name = "String", attributes = Attribute.NOT_ENUMERABLE)
213 public volatile Object string;
214
215 /** ECMA 15.1.4.5 Boolean constructor */
216 @Property(name = "Boolean", attributes = Attribute.NOT_ENUMERABLE)
217 public volatile Object _boolean;
218
219 /** ECMA 15.1.4.6 - Number constructor */
220 @Property(name = "Number", attributes = Attribute.NOT_ENUMERABLE)
221 public volatile Object number;
222
223 /**
224 * Getter for ECMA 15.1.4.7 Date property
225 *
226 * @param self self reference
227 * @return Date property value
228 */
229 @Getter(name = "Date", attributes = Attribute.NOT_ENUMERABLE)
230 public static Object getDate(final Object self) {
231 final Global global = Global.instanceFrom(self);
232 if (global.date == LAZY_SENTINEL) {
233 global.date = global.getBuiltinDate();
234 }
235 return global.date;
236 }
237
238 /**
239 * Setter for ECMA 15.1.4.7 Date property
240 *
241 * @param self self reference
242 * @param value value for the Date property
243 */
244 @Setter(name = "Date", attributes = Attribute.NOT_ENUMERABLE)
245 public static void setDate(final Object self, final Object value) {
246 final Global global = Global.instanceFrom(self);
247 global.date = value;
248 }
249
250 private volatile Object date = LAZY_SENTINEL;
251
252 /**
253 * Getter for ECMA 15.1.4.8 RegExp property
254 *
255 * @param self self reference
256 * @return RegExp property value
257 */
258 @Getter(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE)
259 public static Object getRegExp(final Object self) {
260 final Global global = Global.instanceFrom(self);
261 if (global.regexp == LAZY_SENTINEL) {
262 global.regexp = global.getBuiltinRegExp();
263 }
264 return global.regexp;
265 }
266
267 /**
268 * Setter for ECMA 15.1.4.8 RegExp property
269 *
270 * @param self self reference
271 * @param value value for the RegExp property
272 */
273 @Setter(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE)
274 public static void setRegExp(final Object self, final Object value) {
275 final Global global = Global.instanceFrom(self);
276 global.regexp = value;
277 }
278
279 private volatile Object regexp = LAZY_SENTINEL;
280
281 /**
282 * Getter for ECMA 15.12 - The JSON property
283 * @param self self reference
284 * @return the value of JSON property
285 */
286 @Getter(name = "JSON", attributes = Attribute.NOT_ENUMERABLE)
287 public static Object getJSON(final Object self) {
288 final Global global = Global.instanceFrom(self);
289 if (global.json == LAZY_SENTINEL) {
290 global.json = global.getBuiltinJSON();
291 }
292 return global.json;
293 }
294
295 /**
296 * Setter for ECMA 15.12 - The JSON property
297 * @param self self reference
298 * @param value value for the JSON property
299 */
300 @Setter(name = "JSON", attributes = Attribute.NOT_ENUMERABLE)
301 public static void setJSON(final Object self, final Object value) {
302 final Global global = Global.instanceFrom(self);
303 global.json = value;
304 }
305
306 private volatile Object json = LAZY_SENTINEL;
307
308 /**
309 * Getter for Nashorn extension: global.JSAdapter
310 * @param self self reference
311 * @return value of the JSAdapter property
312 */
313 @Getter(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE)
314 public static Object getJSAdapter(final Object self) {
315 final Global global = Global.instanceFrom(self);
316 if (global.jsadapter == LAZY_SENTINEL) {
317 global.jsadapter = global.getBuiltinJSAdapter();
318 }
319 return global.jsadapter;
320 }
321
322 /**
323 * Setter for Nashorn extension: global.JSAdapter
324 * @param self self reference
325 * @param value value for the JSAdapter property
326 */
327 @Setter(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE)
328 public static void setJSAdapter(final Object self, final Object value) {
329 final Global global = Global.instanceFrom(self);
330 global.jsadapter = value;
331 }
332
333 private volatile Object jsadapter = LAZY_SENTINEL;
334
335 /** ECMA 15.8 - The Math object */
336 @Property(name = "Math", attributes = Attribute.NOT_ENUMERABLE)
337 public volatile Object math;
338
339 /** Error object */
340 @Property(name = "Error", attributes = Attribute.NOT_ENUMERABLE)
341 public volatile Object error;
342
343 /**
344 * Getter for the EvalError property
345 * @param self self reference
346 * @return the value of EvalError property
347 */
348 @Getter(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE)
349 public static Object getEvalError(final Object self) {
350 final Global global = Global.instanceFrom(self);
351 if (global.evalError == LAZY_SENTINEL) {
352 global.evalError = global.getBuiltinEvalError();
353 }
354 return global.evalError;
355 }
356
357 /**
358 * Setter for the EvalError property
359 * @param self self reference
360 * @param value value of the EvalError property
361 */
362 @Setter(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE)
363 public static void setEvalError(final Object self, final Object value) {
364 final Global global = Global.instanceFrom(self);
365 global.evalError = value;
366 }
367
368 private volatile Object evalError = LAZY_SENTINEL;
369
370 /**
371 * Getter for the RangeError property.
372 * @param self self reference
373 * @return the value of RangeError property
374 */
375 @Getter(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE)
376 public static Object getRangeError(final Object self) {
377 final Global global = Global.instanceFrom(self);
378 if (global.rangeError == LAZY_SENTINEL) {
379 global.rangeError = global.getBuiltinRangeError();
380 }
381 return global.rangeError;
382 }
383
384
385 /**
386 * Setter for the RangeError property.
387 * @param self self reference
388 * @param value value for the RangeError property
389 */
390 @Setter(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE)
391 public static void setRangeError(final Object self, final Object value) {
392 final Global global = Global.instanceFrom(self);
393 global.rangeError = value;
394 }
395
396 private volatile Object rangeError = LAZY_SENTINEL;
397
398 /** ReferenceError object */
399 @Property(name = "ReferenceError", attributes = Attribute.NOT_ENUMERABLE)
400 public volatile Object referenceError;
401
402 /** SyntaxError object */
403 @Property(name = "SyntaxError", attributes = Attribute.NOT_ENUMERABLE)
404 public volatile Object syntaxError;
405
406 /** TypeError object */
407 @Property(name = "TypeError", attributes = Attribute.NOT_ENUMERABLE)
408 public volatile Object typeError;
409
410 /**
411 * Getter for the URIError property.
412 * @param self self reference
413 * @return the value of URIError property
414 */
415 @Getter(name = "URIError", attributes = Attribute.NOT_ENUMERABLE)
416 public static Object getURIError(final Object self) {
417 final Global global = Global.instanceFrom(self);
418 if (global.uriError == LAZY_SENTINEL) {
419 global.uriError = global.getBuiltinURIError();
420 }
421 return global.uriError;
422 }
423
424 /**
425 * Setter for the URIError property.
426 * @param self self reference
427 * @param value value for the URIError property
428 */
429 @Setter(name = "URIError", attributes = Attribute.NOT_ENUMERABLE)
430 public static void setURIError(final Object self, final Object value) {
431 final Global global = Global.instanceFrom(self);
432 global.uriError = value;
433 }
434
435 private volatile Object uriError = LAZY_SENTINEL;
436
437 /**
438 * Getter for the ArrayBuffer property.
439 * @param self self reference
440 * @return the value of the ArrayBuffer property
441 */
442 @Getter(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE)
443 public static Object getArrayBuffer(final Object self) {
444 final Global global = Global.instanceFrom(self);
445 if (global.arrayBuffer == LAZY_SENTINEL) {
446 global.arrayBuffer = global.getBuiltinArrayBuffer();
447 }
448 return global.arrayBuffer;
449 }
450
451 /**
452 * Setter for the ArrayBuffer property.
453 * @param self self reference
454 * @param value value of the ArrayBuffer property
455 */
456 @Setter(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE)
457 public static void setArrayBuffer(final Object self, final Object value) {
458 final Global global = Global.instanceFrom(self);
459 global.arrayBuffer = value;
460 }
461
462 private volatile Object arrayBuffer;
463
464 /**
465 * Getter for the DataView property.
466 * @param self self reference
467 * @return the value of the DataView property
468 */
469 @Getter(name = "DataView", attributes = Attribute.NOT_ENUMERABLE)
470 public static Object getDataView(final Object self) {
471 final Global global = Global.instanceFrom(self);
472 if (global.dataView == LAZY_SENTINEL) {
473 global.dataView = global.getBuiltinDataView();
474 }
475 return global.dataView;
476 }
477
478
479 /**
480 * Setter for the DataView property.
481 * @param self self reference
482 * @param value value of the DataView property
483 */
484 @Setter(name = "DataView", attributes = Attribute.NOT_ENUMERABLE)
485 public static void setDataView(final Object self, final Object value) {
486 final Global global = Global.instanceFrom(self);
487 global.dataView = value;
488 }
489
490 private volatile Object dataView;
491
492 /**
493 * Getter for the Int8Array property.
494 * @param self self reference
495 * @return the value of the Int8Array property.
496 */
497 @Getter(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE)
498 public static Object getInt8Array(final Object self) {
499 final Global global = Global.instanceFrom(self);
500 if (global.int8Array == LAZY_SENTINEL) {
501 global.int8Array = global.getBuiltinInt8Array();
502 }
503 return global.int8Array;
504 }
505
506 /**
507 * Setter for the Int8Array property.
508 * @param self self reference
509 * @param value value of the Int8Array property
510 */
511 @Setter(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE)
512 public static void setInt8Array(final Object self, final Object value) {
513 final Global global = Global.instanceFrom(self);
514 global.int8Array = value;
515 }
516
517 private volatile Object int8Array;
518
519 /**
520 * Getter for the Uin8Array property.
521 * @param self self reference
522 * @return the value of the Uint8Array property
523 */
524 @Getter(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE)
525 public static Object getUint8Array(final Object self) {
526 final Global global = Global.instanceFrom(self);
527 if (global.uint8Array == LAZY_SENTINEL) {
528 global.uint8Array = global.getBuiltinUint8Array();
529 }
530 return global.uint8Array;
531 }
532
533 /**
534 * Setter for the Uin8Array property.
535 * @param self self reference
536 * @param value value of the Uin8Array property
537 */
538 @Setter(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE)
539 public static void setUint8Array(final Object self, final Object value) {
540 final Global global = Global.instanceFrom(self);
541 global.uint8Array = value;
542 }
543
544 private volatile Object uint8Array;
545
546 /**
547 * Getter for the Uint8ClampedArray property.
548 * @param self self reference
549 * @return the value of the Uint8ClampedArray property
550 */
551 @Getter(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE)
552 public static Object getUint8ClampedArray(final Object self) {
553 final Global global = Global.instanceFrom(self);
554 if (global.uint8ClampedArray == LAZY_SENTINEL) {
555 global.uint8ClampedArray = global.getBuiltinUint8ClampedArray();
556 }
557 return global.uint8ClampedArray;
558 }
559
560 /**
561 * Setter for the Uint8ClampedArray property.
562 * @param self self reference
563 * @param value value of the Uint8ClampedArray property
564 */
565 @Setter(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE)
566 public static void setUint8ClampedArray(final Object self, final Object value) {
567 final Global global = Global.instanceFrom(self);
568 global.uint8ClampedArray = value;
569 }
570
571 private volatile Object uint8ClampedArray;
572
573 /**
574 * Getter for the Int16Array property.
575 * @param self self reference
576 * @return the value of the Int16Array property
577 */
578 @Getter(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE)
579 public static Object getInt16Array(final Object self) {
580 final Global global = Global.instanceFrom(self);
581 if (global.int16Array == LAZY_SENTINEL) {
582 global.int16Array = global.getBuiltinInt16Array();
583 }
584 return global.int16Array;
585 }
586
587 /**
588 * Setter for the Int16Array property.
589 * @param self self reference
590 * @param value value of the Int16Array property
591 */
592 @Setter(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE)
593 public static void setInt16Array(final Object self, final Object value) {
594 final Global global = Global.instanceFrom(self);
595 global.int16Array = value;
596 }
597
598 private volatile Object int16Array;
599
600 /**
601 * Getter for the Uint16Array property.
602 * @param self self reference
603 * @return the value of the Uint16Array property
604 */
605 @Getter(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE)
606 public static Object getUint16Array(final Object self) {
607 final Global global = Global.instanceFrom(self);
608 if (global.uint16Array == LAZY_SENTINEL) {
609 global.uint16Array = global.getBuiltinUint16Array();
610 }
611 return global.uint16Array;
612 }
613
614 /**
615 * Setter for the Uint16Array property.
616 * @param self self reference
617 * @param value value of the Uint16Array property
618 */
619 @Setter(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE)
620 public static void setUint16Array(final Object self, final Object value) {
621 final Global global = Global.instanceFrom(self);
622 global.uint16Array = value;
623 }
624
625 private volatile Object uint16Array;
626
627 /**
628 * Getter for the Int32Array property.
629 *
630 * @param self self reference
631 * @return the value of the Int32Array property
632 */
633 @Getter(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE)
634 public static Object getInt32Array(final Object self) {
635 final Global global = Global.instanceFrom(self);
636 if (global.int32Array == LAZY_SENTINEL) {
637 global.int32Array = global.getBuiltinInt32Array();
638 }
639 return global.int32Array;
640 }
641
642
643 /**
644 * Setter for the Int32Array property.
645 *
646 * @param self self reference
647 * @param value value of the Int32Array property
648 */
649 @Setter(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE)
650 public static void setInt32Array(final Object self, final Object value) {
651 final Global global = Global.instanceFrom(self);
652 global.int32Array = value;
653 }
654
655 private volatile Object int32Array;
656
657 /**
658 * Getter of the Uint32Array property.
659 *
660 * @param self self reference
661 * @return the value of the Uint32Array property
662 */
663 @Getter(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE)
664 public static Object getUint32Array(final Object self) {
665 final Global global = Global.instanceFrom(self);
666 if (global.uint32Array == LAZY_SENTINEL) {
667 global.uint32Array = global.getBuiltinUint32Array();
668 }
669 return global.uint32Array;
670 }
671
672
673 /**
674 * Setter of the Uint32Array property.
675 *
676 * @param self self reference
677 * @param value value of the Uint32Array property
678 */
679 @Setter(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE)
680 public static void setUint32Array(final Object self, final Object value) {
681 final Global global = Global.instanceFrom(self);
682 global.uint32Array = value;
683 }
684
685 private volatile Object uint32Array;
686
687 /**
688 * Getter for the Float32Array property.
689 *
690 * @param self self reference
691 * @return the value of the Float32Array property
692 */
693 @Getter(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE)
694 public static Object getFloat32Array(final Object self) {
695 final Global global = Global.instanceFrom(self);
696 if (global.float32Array == LAZY_SENTINEL) {
697 global.float32Array = global.getBuiltinFloat32Array();
698 }
699 return global.float32Array;
700 }
701
702 /**
703 * Setter for the Float32Array property.
704 *
705 * @param self self reference
706 * @param value value of the Float32Array property
707 */
708 @Setter(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE)
709 public static void setFloat32Array(final Object self, final Object value) {
710 final Global global = Global.instanceFrom(self);
711 global.float32Array = value;
712 }
713
714 private volatile Object float32Array;
715
716 /**
717 * Getter for the Float64Array property.
718 *
719 * @param self self reference
720 * @return the value of the Float64Array property
721 */
722 @Getter(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE)
723 public static Object getFloat64Array(final Object self) {
724 final Global global = Global.instanceFrom(self);
725 if (global.float64Array == LAZY_SENTINEL) {
726 global.float64Array = global.getBuiltinFloat64Array();
727 }
728 return global.float64Array;
729 }
730
731 /**
732 * Setter for the Float64Array property.
733 *
734 * @param self self reference
735 * @param value value of the Float64Array property
736 */
737 @Setter(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE)
738 public static void setFloat64Array(final Object self, final Object value) {
739 final Global global = Global.instanceFrom(self);
740 global.float64Array = value;
741 }
742
743 private volatile Object float64Array;
744
745 /** Nashorn extension: Java access - global.Packages */
746 @Property(name = "Packages", attributes = Attribute.NOT_ENUMERABLE)
747 public volatile Object packages;
748
749 /** Nashorn extension: Java access - global.com */
750 @Property(attributes = Attribute.NOT_ENUMERABLE)
751 public volatile Object com;
752
753 /** Nashorn extension: Java access - global.edu */
754 @Property(attributes = Attribute.NOT_ENUMERABLE)
755 public volatile Object edu;
756
757 /** Nashorn extension: Java access - global.java */
758 @Property(attributes = Attribute.NOT_ENUMERABLE)
759 public volatile Object java;
760
761 /** Nashorn extension: Java access - global.javafx */
762 @Property(attributes = Attribute.NOT_ENUMERABLE)
763 public volatile Object javafx;
764
765 /** Nashorn extension: Java access - global.javax */
766 @Property(attributes = Attribute.NOT_ENUMERABLE)
767 public volatile Object javax;
768
769 /** Nashorn extension: Java access - global.org */
770 @Property(attributes = Attribute.NOT_ENUMERABLE)
771 public volatile Object org;
772
773 /**
774 * Getter for the Nashorn extension: Java access - global.javaImporter.
775 *
776 * @param self self reference
777 * @return the value of the JavaImporter property
778 */
779 @Getter(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE)
780 public static Object getJavaImporter(final Object self) {
781 final Global global = Global.instanceFrom(self);
782 if (global.javaImporter == LAZY_SENTINEL) {
783 global.javaImporter = global.getBuiltinJavaImporter();
784 }
785 return global.javaImporter;
786 }
787
788 /**
789 * Setter for the Nashorn extension: Java access - global.javaImporter.
790 *
791 * @param self self reference
792 * @param value value of the JavaImporter property
793 */
794 @Setter(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE)
795 public static void setJavaImporter(final Object self, final Object value) {
796 final Global global = Global.instanceFrom(self);
797 global.javaImporter = value;
798 }
799
800 private volatile Object javaImporter;
801
802 /**
803 * Getter for the Nashorn extension: global.Java property.
804 *
805 * @param self self reference
806 * @return the value of the Java property
807 */
808 @Getter(name = "Java", attributes = Attribute.NOT_ENUMERABLE)
809 public static Object getJavaApi(final Object self) {
810 final Global global = Global.instanceFrom(self);
811 if (global.javaApi == LAZY_SENTINEL) {
812 global.javaApi = global.getBuiltinJavaApi();
813 }
814 return global.javaApi;
815 }
816
817 /**
818 * Setter for the Nashorn extension: global.Java property.
819 *
820 * @param self self reference
821 * @param value value of the Java property
822 */
823 @Setter(name = "Java", attributes = Attribute.NOT_ENUMERABLE)
824 public static void setJavaApi(final Object self, final Object value) {
825 final Global global = Global.instanceFrom(self);
826 global.javaApi = value;
827 }
828
829 private volatile Object javaApi;
830
831 /** Nashorn extension: current script's file name */
832 @Property(name = "__FILE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
833 public final Object __FILE__ = LOCATION_PROPERTY_PLACEHOLDER;
834
835 /** Nashorn extension: current script's directory */
836 @Property(name = "__DIR__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
837 public final Object __DIR__ = LOCATION_PROPERTY_PLACEHOLDER;
838
839 /** Nashorn extension: current source line number being executed */
840 @Property(name = "__LINE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
841 public final Object __LINE__ = LOCATION_PROPERTY_PLACEHOLDER;
842
2323 *
2324 * @param state current split state
2325 */
2326 @Override
2327 public void setSplitState(final int state) {
2328 splitState = state;
2329 }
2330
2331 /**
2332 * Return the ES6 global scope for lexically declared bindings.
2333 * @return the ES6 lexical global scope.
2334 */
2335 public final ScriptObject getLexicalScope() {
2336 assert context.getEnv()._es6;
2337 return lexicalScope;
2338 }
2339
2340 @Override
2341 public void addBoundProperties(final ScriptObject source, final jdk.nashorn.internal.runtime.Property[] properties) {
2342 PropertyMap ownMap = getMap();
2343 LexicalScope lexScope = null;
2344 PropertyMap lexicalMap = null;
2345 boolean hasLexicalDefinitions = false;
2346
2347 if (context.getEnv()._es6) {
2348 lexScope = (LexicalScope) getLexicalScope();
2349 lexicalMap = lexScope.getMap();
2350
2351 for (final jdk.nashorn.internal.runtime.Property property : properties) {
2352 if (property.isLexicalBinding()) {
2353 hasLexicalDefinitions = true;
2354 }
2355 // ES6 15.1.8 steps 6. and 7.
2356 final jdk.nashorn.internal.runtime.Property globalProperty = ownMap.findProperty(property.getKey());
2357 if (globalProperty != null && !globalProperty.isConfigurable() && property.isLexicalBinding()) {
2358 throw ECMAErrors.syntaxError("redeclare.variable", property.getKey());
2359 }
2360 final jdk.nashorn.internal.runtime.Property lexicalProperty = lexicalMap.findProperty(property.getKey());
2361 if (lexicalProperty != null && !property.isConfigurable()) {
2362 throw ECMAErrors.syntaxError("redeclare.variable", property.getKey());
2363 }
2364 }
2365 }
2366
2367 for (final jdk.nashorn.internal.runtime.Property property : properties) {
2368 if (property.isLexicalBinding()) {
2369 assert lexScope != null;
2370 lexicalMap = lexScope.addBoundProperty(lexicalMap, source, property);
2371
2372 if (ownMap.findProperty(property.getKey()) != null) {
2373 // If property exists in the global object invalidate any global constant call sites.
2374 invalidateGlobalConstant(property.getKey());
2375 }
2376 } else {
2377 ownMap = addBoundProperty(ownMap, source, property);
2378 }
2379 }
2380
2381 setMap(ownMap);
2382
2383 if (hasLexicalDefinitions) {
2384 assert lexScope != null;
2385 lexScope.setMap(lexicalMap);
2386 invalidateLexicalSwitchPoint();
2387 }
2388 }
2389
2390 @Override
2391 public GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request, final String operator) {
2392 final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
2393 final boolean isScope = NashornCallSiteDescriptor.isScope(desc);
2394
2395 if (lexicalScope != null && isScope && !NashornCallSiteDescriptor.isApplyToCall(desc)) {
2396 if (lexicalScope.hasOwnProperty(name)) {
2397 return lexicalScope.findGetMethod(desc, request, operator);
2398 }
2399 }
2400
2401 final GuardedInvocation invocation = super.findGetMethod(desc, request, operator);
2402
2403 // We want to avoid adding our generic lexical scope switchpoint to global constant invocations,
2404 // because those are invalidated per-key in the addBoundProperties method above.
2405 // We therefor check if the invocation does already have a switchpoint and the property is non-inherited,
|