author | hannesw |
Thu, 05 Feb 2015 14:42:14 +0100 | |
changeset 28786 | 679fd2d26470 |
parent 28785 | a503c972d4bd |
child 29280 | 8a79b4040d2a |
permissions | -rw-r--r-- |
16147 | 1 |
/* |
16151 | 2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
16147 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.nashorn.internal.objects; |
|
27 |
||
18610 | 28 |
import static jdk.nashorn.internal.lookup.Lookup.MH; |
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
29 |
import static jdk.nashorn.internal.runtime.ECMAErrors.referenceError; |
16147 | 30 |
import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; |
31 |
import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; |
|
27369
5a251d0063d1
8062308: Incorrect constant linkage with multiple Globals in a Context
attila
parents:
27361
diff
changeset
|
32 |
|
16147 | 33 |
import java.io.IOException; |
34 |
import java.io.PrintWriter; |
|
35 |
import java.lang.invoke.MethodHandle; |
|
36 |
import java.lang.invoke.MethodHandles; |
|
27814
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
37 |
import java.lang.invoke.MethodType; |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
38 |
import java.lang.invoke.SwitchPoint; |
16522 | 39 |
import java.lang.reflect.Field; |
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
40 |
import java.util.ArrayList; |
18326
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
41 |
import java.util.Arrays; |
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
42 |
import java.util.List; |
16147 | 43 |
import java.util.Map; |
28785
a503c972d4bd
8072595: nashorn should not use obj.getClass() for null checks
sundar
parents:
27814
diff
changeset
|
44 |
import java.util.Objects; |
19456
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
45 |
import java.util.concurrent.Callable; |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
46 |
import java.util.concurrent.ConcurrentHashMap; |
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
47 |
import javax.script.ScriptContext; |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
48 |
import javax.script.ScriptEngine; |
27814
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
49 |
import jdk.internal.dynalink.CallSiteDescriptor; |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
16233
diff
changeset
|
50 |
import jdk.internal.dynalink.linker.GuardedInvocation; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
16233
diff
changeset
|
51 |
import jdk.internal.dynalink.linker.LinkRequest; |
26071 | 52 |
import jdk.nashorn.api.scripting.ClassFilter; |
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
53 |
import jdk.nashorn.api.scripting.ScriptObjectMirror; |
22382
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
54 |
import jdk.nashorn.internal.lookup.Lookup; |
16147 | 55 |
import jdk.nashorn.internal.objects.annotations.Attribute; |
56 |
import jdk.nashorn.internal.objects.annotations.Property; |
|
57 |
import jdk.nashorn.internal.objects.annotations.ScriptClass; |
|
58 |
import jdk.nashorn.internal.runtime.ConsString; |
|
59 |
import jdk.nashorn.internal.runtime.Context; |
|
27814
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
60 |
import jdk.nashorn.internal.runtime.ECMAErrors; |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
61 |
import jdk.nashorn.internal.runtime.GlobalConstants; |
16147 | 62 |
import jdk.nashorn.internal.runtime.GlobalFunctions; |
63 |
import jdk.nashorn.internal.runtime.JSType; |
|
64 |
import jdk.nashorn.internal.runtime.NativeJavaPackage; |
|
21686
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21439
diff
changeset
|
65 |
import jdk.nashorn.internal.runtime.PropertyDescriptor; |
18618
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
66 |
import jdk.nashorn.internal.runtime.PropertyMap; |
21686
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21439
diff
changeset
|
67 |
import jdk.nashorn.internal.runtime.Scope; |
16262
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
68 |
import jdk.nashorn.internal.runtime.ScriptEnvironment; |
16147 | 69 |
import jdk.nashorn.internal.runtime.ScriptFunction; |
70 |
import jdk.nashorn.internal.runtime.ScriptObject; |
|
71 |
import jdk.nashorn.internal.runtime.ScriptRuntime; |
|
72 |
import jdk.nashorn.internal.runtime.ScriptingFunctions; |
|
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
73 |
import jdk.nashorn.internal.runtime.Specialization; |
21686
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21439
diff
changeset
|
74 |
import jdk.nashorn.internal.runtime.arrays.ArrayData; |
19088
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
19085
diff
changeset
|
75 |
import jdk.nashorn.internal.runtime.linker.Bootstrap; |
16147 | 76 |
import jdk.nashorn.internal.runtime.linker.InvokeByName; |
27814
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
77 |
import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; |
21686
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21439
diff
changeset
|
78 |
import jdk.nashorn.internal.runtime.regexp.RegExpResult; |
16275 | 79 |
import jdk.nashorn.internal.scripts.JO; |
16147 | 80 |
|
81 |
/** |
|
82 |
* Representation of global scope. |
|
83 |
*/ |
|
84 |
@ScriptClass("Global") |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
85 |
public final class Global extends ScriptObject implements Scope { |
24719 | 86 |
// Placeholder value used in place of a location property (__FILE__, __DIR__, __LINE__) |
87 |
private static final Object LOCATION_PROPERTY_PLACEHOLDER = new Object(); |
|
19456
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
88 |
private final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class); |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
89 |
private final InvokeByName VALUE_OF = new InvokeByName("valueOf", ScriptObject.class); |
16147 | 90 |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
91 |
/** |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
92 |
* Optimistic builtin names that require switchpoint invalidation |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
93 |
* upon assignment. Overly conservative, but works for now, to avoid |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
94 |
* any complicated scope checks and especially heavy weight guards |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
95 |
* like |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
96 |
* |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
97 |
* <pre> |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
98 |
* public boolean setterGuard(final Object receiver) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
99 |
* final Global global = Global.instance(); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
100 |
* final ScriptObject sobj = global.getFunctionPrototype(); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
101 |
* final Object apply = sobj.get("apply"); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
102 |
* return apply == receiver; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
103 |
* } |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
104 |
* </pre> |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
105 |
* |
24751 | 106 |
* Naturally, checking for builtin classes like NativeFunction is cheaper, |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
107 |
* it's when you start adding property checks for said builtins you have |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
108 |
* problems with guard speed. |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
109 |
*/ |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
110 |
|
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
111 |
/** Nashorn extension: arguments array */ |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
112 |
@Property(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE) |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
113 |
public Object arguments; |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
114 |
|
16147 | 115 |
/** ECMA 15.1.2.2 parseInt (string , radix) */ |
116 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
117 |
public Object parseInt; |
|
118 |
||
119 |
/** ECMA 15.1.2.3 parseFloat (string) */ |
|
120 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
121 |
public Object parseFloat; |
|
122 |
||
123 |
/** ECMA 15.1.2.4 isNaN (number) */ |
|
124 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
125 |
public Object isNaN; |
|
126 |
||
127 |
/** ECMA 15.1.2.5 isFinite (number) */ |
|
128 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
129 |
public Object isFinite; |
|
130 |
||
131 |
/** ECMA 15.1.3.3 encodeURI */ |
|
132 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
133 |
public Object encodeURI; |
|
134 |
||
135 |
/** ECMA 15.1.3.4 encodeURIComponent */ |
|
136 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
137 |
public Object encodeURIComponent; |
|
138 |
||
139 |
/** ECMA 15.1.3.1 decodeURI */ |
|
140 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
141 |
public Object decodeURI; |
|
142 |
||
143 |
/** ECMA 15.1.3.2 decodeURIComponent */ |
|
144 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
145 |
public Object decodeURIComponent; |
|
146 |
||
147 |
/** ECMA B.2.1 escape (string) */ |
|
148 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
149 |
public Object escape; |
|
150 |
||
151 |
/** ECMA B.2.2 unescape (string) */ |
|
152 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
153 |
public Object unescape; |
|
154 |
||
155 |
/** Nashorn extension: global.print */ |
|
156 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
157 |
public Object print; |
|
158 |
||
159 |
/** Nashorn extension: global.load */ |
|
160 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
161 |
public Object load; |
|
162 |
||
17974
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
163 |
/** Nashorn extension: global.loadWithNewGlobal */ |
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
164 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
165 |
public Object loadWithNewGlobal; |
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
166 |
|
16219 | 167 |
/** Nashorn extension: global.exit */ |
168 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
169 |
public Object exit; |
|
170 |
||
171 |
/** Nashorn extension: global.quit */ |
|
172 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
173 |
public Object quit; |
|
174 |
||
16147 | 175 |
/** Value property NaN of the Global Object - ECMA 15.1.1.1 NaN */ |
176 |
@Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT) |
|
24719 | 177 |
public final double NaN = Double.NaN; |
16147 | 178 |
|
179 |
/** Value property Infinity of the Global Object - ECMA 15.1.1.2 Infinity */ |
|
180 |
@Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT) |
|
24719 | 181 |
public final double Infinity = Double.POSITIVE_INFINITY; |
16147 | 182 |
|
183 |
/** Value property Undefined of the Global Object - ECMA 15.1.1.3 Undefined */ |
|
184 |
@Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT) |
|
185 |
public final Object undefined = UNDEFINED; |
|
186 |
||
187 |
/** ECMA 15.1.2.1 eval(x) */ |
|
188 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
189 |
public Object eval; |
|
190 |
||
191 |
/** ECMA 15.1.4.1 Object constructor. */ |
|
192 |
@Property(name = "Object", attributes = Attribute.NOT_ENUMERABLE) |
|
193 |
public volatile Object object; |
|
194 |
||
195 |
/** ECMA 15.1.4.2 Function constructor. */ |
|
196 |
@Property(name = "Function", attributes = Attribute.NOT_ENUMERABLE) |
|
197 |
public volatile Object function; |
|
198 |
||
199 |
/** ECMA 15.1.4.3 Array constructor. */ |
|
200 |
@Property(name = "Array", attributes = Attribute.NOT_ENUMERABLE) |
|
201 |
public volatile Object array; |
|
202 |
||
203 |
/** ECMA 15.1.4.4 String constructor */ |
|
204 |
@Property(name = "String", attributes = Attribute.NOT_ENUMERABLE) |
|
205 |
public volatile Object string; |
|
206 |
||
207 |
/** ECMA 15.1.4.5 Boolean constructor */ |
|
208 |
@Property(name = "Boolean", attributes = Attribute.NOT_ENUMERABLE) |
|
209 |
public volatile Object _boolean; |
|
210 |
||
211 |
/** ECMA 15.1.4.6 - Number constructor */ |
|
212 |
@Property(name = "Number", attributes = Attribute.NOT_ENUMERABLE) |
|
213 |
public volatile Object number; |
|
214 |
||
215 |
/** ECMA 15.1.4.7 Date constructor */ |
|
216 |
@Property(name = "Date", attributes = Attribute.NOT_ENUMERABLE) |
|
217 |
public volatile Object date; |
|
218 |
||
219 |
/** ECMA 15.1.4.8 RegExp constructor */ |
|
220 |
@Property(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE) |
|
221 |
public volatile Object regexp; |
|
222 |
||
223 |
/** ECMA 15.12 - The JSON object */ |
|
224 |
@Property(name = "JSON", attributes = Attribute.NOT_ENUMERABLE) |
|
225 |
public volatile Object json; |
|
226 |
||
227 |
/** Nashorn extension: global.JSAdapter */ |
|
228 |
@Property(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE) |
|
229 |
public volatile Object jsadapter; |
|
230 |
||
231 |
/** ECMA 15.8 - The Math object */ |
|
232 |
@Property(name = "Math", attributes = Attribute.NOT_ENUMERABLE) |
|
233 |
public volatile Object math; |
|
234 |
||
235 |
/** Error object */ |
|
236 |
@Property(name = "Error", attributes = Attribute.NOT_ENUMERABLE) |
|
237 |
public volatile Object error; |
|
238 |
||
239 |
/** EvalError object */ |
|
240 |
@Property(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE) |
|
241 |
public volatile Object evalError; |
|
242 |
||
243 |
/** RangeError object */ |
|
244 |
@Property(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE) |
|
245 |
public volatile Object rangeError; |
|
246 |
||
247 |
/** ReferenceError object */ |
|
248 |
@Property(name = "ReferenceError", attributes = Attribute.NOT_ENUMERABLE) |
|
249 |
public volatile Object referenceError; |
|
250 |
||
251 |
/** SyntaxError object */ |
|
252 |
@Property(name = "SyntaxError", attributes = Attribute.NOT_ENUMERABLE) |
|
253 |
public volatile Object syntaxError; |
|
254 |
||
255 |
/** TypeError object */ |
|
256 |
@Property(name = "TypeError", attributes = Attribute.NOT_ENUMERABLE) |
|
257 |
public volatile Object typeError; |
|
258 |
||
259 |
/** URIError object */ |
|
260 |
@Property(name = "URIError", attributes = Attribute.NOT_ENUMERABLE) |
|
261 |
public volatile Object uriError; |
|
262 |
||
263 |
/** ArrayBuffer object */ |
|
264 |
@Property(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE) |
|
265 |
public volatile Object arrayBuffer; |
|
266 |
||
23374 | 267 |
/** DataView object */ |
268 |
@Property(name = "DataView", attributes = Attribute.NOT_ENUMERABLE) |
|
269 |
public volatile Object dataView; |
|
270 |
||
16147 | 271 |
/** TypedArray (int8) */ |
272 |
@Property(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE) |
|
273 |
public volatile Object int8Array; |
|
274 |
||
275 |
/** TypedArray (uint8) */ |
|
276 |
@Property(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE) |
|
277 |
public volatile Object uint8Array; |
|
278 |
||
279 |
/** TypedArray (uint8) - Clamped */ |
|
280 |
@Property(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE) |
|
281 |
public volatile Object uint8ClampedArray; |
|
282 |
||
283 |
/** TypedArray (int16) */ |
|
284 |
@Property(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE) |
|
285 |
public volatile Object int16Array; |
|
286 |
||
287 |
/** TypedArray (uint16) */ |
|
288 |
@Property(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE) |
|
289 |
public volatile Object uint16Array; |
|
290 |
||
291 |
/** TypedArray (int32) */ |
|
292 |
@Property(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE) |
|
293 |
public volatile Object int32Array; |
|
294 |
||
295 |
/** TypedArray (uint32) */ |
|
296 |
@Property(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE) |
|
297 |
public volatile Object uint32Array; |
|
298 |
||
299 |
/** TypedArray (float32) */ |
|
300 |
@Property(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE) |
|
301 |
public volatile Object float32Array; |
|
302 |
||
303 |
/** TypedArray (float64) */ |
|
304 |
@Property(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE) |
|
305 |
public volatile Object float64Array; |
|
306 |
||
307 |
/** Nashorn extension: Java access - global.Packages */ |
|
308 |
@Property(name = "Packages", attributes = Attribute.NOT_ENUMERABLE) |
|
309 |
public volatile Object packages; |
|
310 |
||
16532 | 311 |
/** Nashorn extension: Java access - global.com */ |
312 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
313 |
public volatile Object com; |
|
314 |
||
315 |
/** Nashorn extension: Java access - global.edu */ |
|
316 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
317 |
public volatile Object edu; |
|
318 |
||
16147 | 319 |
/** Nashorn extension: Java access - global.java */ |
320 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
321 |
public volatile Object java; |
|
322 |
||
16532 | 323 |
/** Nashorn extension: Java access - global.javafx */ |
324 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
325 |
public volatile Object javafx; |
|
326 |
||
16147 | 327 |
/** Nashorn extension: Java access - global.javax */ |
328 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
16532 | 329 |
public volatile Object javax; |
330 |
||
331 |
/** Nashorn extension: Java access - global.org */ |
|
332 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
333 |
public volatile Object org; |
|
16147 | 334 |
|
335 |
/** Nashorn extension: Java access - global.javaImporter */ |
|
336 |
@Property(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE) |
|
337 |
public volatile Object javaImporter; |
|
338 |
||
339 |
/** Nashorn extension: global.Java Object constructor. */ |
|
340 |
@Property(name = "Java", attributes = Attribute.NOT_ENUMERABLE) |
|
341 |
public volatile Object javaApi; |
|
342 |
||
343 |
/** Nashorn extension: current script's file name */ |
|
344 |
@Property(name = "__FILE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT) |
|
24719 | 345 |
public final Object __FILE__ = LOCATION_PROPERTY_PLACEHOLDER; |
16147 | 346 |
|
347 |
/** Nashorn extension: current script's directory */ |
|
348 |
@Property(name = "__DIR__", attributes = Attribute.NON_ENUMERABLE_CONSTANT) |
|
24719 | 349 |
public final Object __DIR__ = LOCATION_PROPERTY_PLACEHOLDER; |
16147 | 350 |
|
351 |
/** Nashorn extension: current source line number being executed */ |
|
352 |
@Property(name = "__LINE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT) |
|
24719 | 353 |
public final Object __LINE__ = LOCATION_PROPERTY_PLACEHOLDER; |
16147 | 354 |
|
355 |
/** Used as Date.prototype's default value */ |
|
356 |
public NativeDate DEFAULT_DATE; |
|
357 |
||
358 |
/** Used as RegExp.prototype's default value */ |
|
359 |
public NativeRegExp DEFAULT_REGEXP; |
|
360 |
||
361 |
/* |
|
362 |
* Built-in constructor objects: Even if user changes dynamic values of |
|
363 |
* "Object", "Array" etc., we still want to keep original values of these |
|
364 |
* constructors here. For example, we need to be able to create array, |
|
365 |
* regexp literals even after user overwrites global "Array" or "RegExp" |
|
366 |
* constructor - see also ECMA 262 spec. Annex D. |
|
367 |
*/ |
|
368 |
private ScriptFunction builtinFunction; |
|
369 |
private ScriptFunction builtinObject; |
|
370 |
private ScriptFunction builtinArray; |
|
371 |
private ScriptFunction builtinBoolean; |
|
372 |
private ScriptFunction builtinDate; |
|
373 |
private ScriptObject builtinJSON; |
|
374 |
private ScriptFunction builtinJSAdapter; |
|
375 |
private ScriptObject builtinMath; |
|
376 |
private ScriptFunction builtinNumber; |
|
377 |
private ScriptFunction builtinRegExp; |
|
378 |
private ScriptFunction builtinString; |
|
379 |
private ScriptFunction builtinError; |
|
380 |
private ScriptFunction builtinEval; |
|
381 |
private ScriptFunction builtinEvalError; |
|
382 |
private ScriptFunction builtinRangeError; |
|
383 |
private ScriptFunction builtinReferenceError; |
|
384 |
private ScriptFunction builtinSyntaxError; |
|
385 |
private ScriptFunction builtinTypeError; |
|
386 |
private ScriptFunction builtinURIError; |
|
387 |
private ScriptObject builtinPackages; |
|
16532 | 388 |
private ScriptObject builtinCom; |
389 |
private ScriptObject builtinEdu; |
|
16147 | 390 |
private ScriptObject builtinJava; |
16532 | 391 |
private ScriptObject builtinJavafx; |
16147 | 392 |
private ScriptObject builtinJavax; |
16532 | 393 |
private ScriptObject builtinOrg; |
26056
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
394 |
private ScriptFunction builtinJavaImporter; |
16147 | 395 |
private ScriptObject builtinJavaApi; |
26056
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
396 |
private ScriptFunction builtinArrayBuffer; |
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
397 |
private ScriptFunction builtinDataView; |
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
398 |
private ScriptFunction builtinInt8Array; |
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
399 |
private ScriptFunction builtinUint8Array; |
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
400 |
private ScriptFunction builtinUint8ClampedArray; |
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
401 |
private ScriptFunction builtinInt16Array; |
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
402 |
private ScriptFunction builtinUint16Array; |
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
403 |
private ScriptFunction builtinInt32Array; |
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
404 |
private ScriptFunction builtinUint32Array; |
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
405 |
private ScriptFunction builtinFloat32Array; |
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
406 |
private ScriptFunction builtinFloat64Array; |
16147 | 407 |
|
22382
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
408 |
/* |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
409 |
* ECMA section 13.2.3 The [[ThrowTypeError]] Function Object |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
410 |
*/ |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
411 |
private ScriptFunction typeErrorThrower; |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
412 |
|
16147 | 413 |
// Flag to indicate that a split method issued a return statement |
414 |
private int splitState = -1; |
|
415 |
||
16223
dff592a332a4
8007718: Make static RegExp properties fully compatible to other engines
hannesw
parents:
16219
diff
changeset
|
416 |
// Used to store the last RegExp result to support deprecated RegExp constructor properties |
16258 | 417 |
private RegExpResult lastRegExpResult; |
16223
dff592a332a4
8007718: Make static RegExp properties fully compatible to other engines
hannesw
parents:
16219
diff
changeset
|
418 |
|
27814
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
419 |
private static final MethodHandle EVAL = findOwnMH_S("eval", Object.class, Object.class, Object.class); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
420 |
private static final MethodHandle NO_SUCH_PROPERTY = findOwnMH_S(NO_SUCH_PROPERTY_NAME, Object.class, Object.class, Object.class); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
421 |
private static final MethodHandle PRINT = findOwnMH_S("print", Object.class, Object.class, Object[].class); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
422 |
private static final MethodHandle PRINTLN = findOwnMH_S("println", Object.class, Object.class, Object[].class); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
423 |
private static final MethodHandle LOAD = findOwnMH_S("load", Object.class, Object.class, Object.class); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
424 |
private static final MethodHandle LOAD_WITH_NEW_GLOBAL = findOwnMH_S("loadWithNewGlobal", Object.class, Object.class, Object[].class); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
425 |
private static final MethodHandle EXIT = findOwnMH_S("exit", Object.class, Object.class, Object.class); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
426 |
private static final MethodHandle LEXICAL_SCOPE_FILTER = findOwnMH_S("lexicalScopeFilter", Object.class, Object.class); |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
427 |
|
18618
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
428 |
// initialized by nasgen |
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
429 |
private static PropertyMap $nasgenmap$; |
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
430 |
|
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
431 |
// context to which this global belongs to |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
432 |
private final Context context; |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
433 |
|
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
434 |
// current ScriptContext to use - can be null. |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
435 |
private ScriptContext scontext; |
26647
a6acc63c2a31
8058422: Users should be able to overwrite "context" and "engine" variables
sundar
parents:
26508
diff
changeset
|
436 |
// current ScriptEngine associated - can be null. |
a6acc63c2a31
8058422: Users should be able to overwrite "context" and "engine" variables
sundar
parents:
26508
diff
changeset
|
437 |
private ScriptEngine engine; |
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
438 |
|
27814
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
439 |
// ES6 global lexical scope. |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
440 |
private final LexicalScope lexicalScope; |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
441 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
442 |
// Switchpoint for non-constant global callsites in the presence of ES6 lexical scope. |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
443 |
private SwitchPoint lexicalScopeSwitchPoint; |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
444 |
|
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
445 |
/** |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
446 |
* Set the current script context |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
447 |
* @param scontext script context |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
448 |
*/ |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
449 |
public void setScriptContext(final ScriptContext scontext) { |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
450 |
this.scontext = scontext; |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
451 |
} |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
452 |
|
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
453 |
@Override |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
454 |
protected Context getContext() { |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
455 |
return context; |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
456 |
} |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
457 |
|
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
458 |
// performs initialization checks for Global constructor and returns the |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
459 |
// PropertyMap, if everything is fine. |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
460 |
private static PropertyMap checkAndGetMap(final Context context) { |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
461 |
// security check first |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
462 |
final SecurityManager sm = System.getSecurityManager(); |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
463 |
if (sm != null) { |
19459 | 464 |
sm.checkPermission(new RuntimePermission(Context.NASHORN_CREATE_GLOBAL)); |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
465 |
} |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
466 |
|
28785
a503c972d4bd
8072595: nashorn should not use obj.getClass() for null checks
sundar
parents:
27814
diff
changeset
|
467 |
Objects.requireNonNull(context); |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
468 |
|
25421
a1df2de833a2
8044760: Avoid PropertyMap duplicate for global instances
sundar
parents:
25240
diff
changeset
|
469 |
return $nasgenmap$; |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
470 |
} |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
471 |
|
16147 | 472 |
/** |
473 |
* Constructor |
|
16233
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16228
diff
changeset
|
474 |
* |
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16228
diff
changeset
|
475 |
* @param context the context |
16147 | 476 |
*/ |
16226
0e4f37e6cc40
8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents:
16223
diff
changeset
|
477 |
public Global(final Context context) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
478 |
super(checkAndGetMap(context)); |
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
479 |
this.context = context; |
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18851
diff
changeset
|
480 |
this.setIsScope(); |
27814
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
481 |
this.lexicalScope = context.getEnv()._es6 ? new LexicalScope(this) : null; |
16147 | 482 |
} |
483 |
||
484 |
/** |
|
16226
0e4f37e6cc40
8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents:
16223
diff
changeset
|
485 |
* Script access to "current" Global instance |
16147 | 486 |
* |
487 |
* @return the global singleton |
|
488 |
*/ |
|
489 |
public static Global instance() { |
|
24727 | 490 |
final Global global = Context.getGlobal(); |
28785
a503c972d4bd
8072595: nashorn should not use obj.getClass() for null checks
sundar
parents:
27814
diff
changeset
|
491 |
Objects.requireNonNull(global); |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
492 |
return global; |
16147 | 493 |
} |
494 |
||
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
495 |
private static Global instanceFrom(final Object self) { |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
496 |
return self instanceof Global? (Global)self : instance(); |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
497 |
} |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
498 |
|
16147 | 499 |
/** |
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24738
diff
changeset
|
500 |
* Check if we have a Global instance |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24738
diff
changeset
|
501 |
* @return true if one exists |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24738
diff
changeset
|
502 |
*/ |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24738
diff
changeset
|
503 |
public static boolean hasInstance() { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24738
diff
changeset
|
504 |
return Context.getGlobal() != null; |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24738
diff
changeset
|
505 |
} |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24738
diff
changeset
|
506 |
|
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24738
diff
changeset
|
507 |
/** |
16262
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
508 |
* Script access to {@link ScriptEnvironment} |
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
509 |
* |
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
510 |
* @return the script environment |
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
511 |
*/ |
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
512 |
static ScriptEnvironment getEnv() { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
513 |
return instance().getContext().getEnv(); |
16262
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
514 |
} |
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
515 |
|
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
516 |
/** |
16147 | 517 |
* Script access to {@link Context} |
518 |
* |
|
519 |
* @return the context |
|
520 |
*/ |
|
16185 | 521 |
static Context getThisContext() { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
522 |
return instance().getContext(); |
16147 | 523 |
} |
524 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
525 |
// Runtime interface to Global |
16147 | 526 |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
527 |
/** |
26071 | 528 |
* Is there a class filter in the current Context? |
529 |
* @return class filter |
|
530 |
*/ |
|
531 |
public ClassFilter getClassFilter() { |
|
532 |
return context.getClassFilter(); |
|
533 |
} |
|
534 |
||
535 |
/** |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
536 |
* Is this global of the given Context? |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
537 |
* @param ctxt the context |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
538 |
* @return true if this global belongs to the given Context |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
539 |
*/ |
20933
89748612fd1d
8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents:
20216
diff
changeset
|
540 |
public boolean isOfContext(final Context ctxt) { |
89748612fd1d
8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents:
20216
diff
changeset
|
541 |
return this.context == ctxt; |
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
542 |
} |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
543 |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
544 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
545 |
* Does this global belong to a strict Context? |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
546 |
* @return true if this global belongs to a strict Context |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
547 |
*/ |
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
548 |
public boolean isStrictContext() { |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
549 |
return context.getEnv()._strict; |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
550 |
} |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
551 |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
552 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
553 |
* Initialize standard builtin objects like "Object", "Array", "Function" etc. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
554 |
* as well as our extension builtin objects like "Java", "JSAdapter" as properties |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
555 |
* of the global scope object. |
25821
fbb51e67d2a7
8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents:
25585
diff
changeset
|
556 |
* |
27361 | 557 |
* @param eng ScriptEngine to initialize |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
558 |
*/ |
27361 | 559 |
public void initBuiltinObjects(final ScriptEngine eng) { |
16147 | 560 |
if (this.builtinObject != null) { |
561 |
// already initialized, just return |
|
562 |
return; |
|
563 |
} |
|
564 |
||
27361 | 565 |
this.engine = eng; |
566 |
init(eng); |
|
16147 | 567 |
} |
568 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
569 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
570 |
* Wrap a Java object as corresponding script object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
571 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
572 |
* @param obj object to wrap |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
573 |
* @return wrapped object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
574 |
*/ |
16147 | 575 |
public Object wrapAsObject(final Object obj) { |
576 |
if (obj instanceof Boolean) { |
|
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
577 |
return new NativeBoolean((Boolean)obj, this); |
16147 | 578 |
} else if (obj instanceof Number) { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
579 |
return new NativeNumber(((Number)obj).doubleValue(), this); |
16147 | 580 |
} else if (obj instanceof String || obj instanceof ConsString) { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
581 |
return new NativeString((CharSequence)obj, this); |
16147 | 582 |
} else if (obj instanceof Object[]) { // extension |
28786 | 583 |
return new NativeArray(ArrayData.allocate((Object[])obj), this); |
16147 | 584 |
} else if (obj instanceof double[]) { // extension |
28786 | 585 |
return new NativeArray(ArrayData.allocate((double[])obj), this); |
16147 | 586 |
} else if (obj instanceof long[]) { |
28786 | 587 |
return new NativeArray(ArrayData.allocate((long[])obj), this); |
16147 | 588 |
} else if (obj instanceof int[]) { |
28786 | 589 |
return new NativeArray(ArrayData.allocate((int[]) obj), this); |
590 |
} else if (obj instanceof ArrayData) { |
|
591 |
return new NativeArray((ArrayData) obj, this); |
|
16147 | 592 |
} else { |
593 |
// FIXME: more special cases? Map? List? |
|
594 |
return obj; |
|
595 |
} |
|
596 |
} |
|
597 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
598 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
599 |
* Lookup helper for JS primitive types |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
600 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
601 |
* @param request the link request for the dynamic call site. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
602 |
* @param self self reference |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
603 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
604 |
* @return guarded invocation |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
605 |
*/ |
24731
ab0c8fc915ae
8038406: Testability: as a first step of moving loggers away from the process global space, the Debug object now supports logging POJOs from log entries as an event queue, which can be introspected from test scripts. This is way better than screen scraping brittle and subject-to-change log output.
lagergren
parents:
24727
diff
changeset
|
606 |
public static GuardedInvocation primitiveLookup(final LinkRequest request, final Object self) { |
16195
3f6c0ab2597a
8006766: Array-like access to characters of a string is slow
hannesw
parents:
16188
diff
changeset
|
607 |
if (self instanceof String || self instanceof ConsString) { |
3f6c0ab2597a
8006766: Array-like access to characters of a string is slow
hannesw
parents:
16188
diff
changeset
|
608 |
return NativeString.lookupPrimitive(request, self); |
3f6c0ab2597a
8006766: Array-like access to characters of a string is slow
hannesw
parents:
16188
diff
changeset
|
609 |
} else if (self instanceof Number) { |
3f6c0ab2597a
8006766: Array-like access to characters of a string is slow
hannesw
parents:
16188
diff
changeset
|
610 |
return NativeNumber.lookupPrimitive(request, self); |
3f6c0ab2597a
8006766: Array-like access to characters of a string is slow
hannesw
parents:
16188
diff
changeset
|
611 |
} else if (self instanceof Boolean) { |
3f6c0ab2597a
8006766: Array-like access to characters of a string is slow
hannesw
parents:
16188
diff
changeset
|
612 |
return NativeBoolean.lookupPrimitive(request, self); |
3f6c0ab2597a
8006766: Array-like access to characters of a string is slow
hannesw
parents:
16188
diff
changeset
|
613 |
} |
3f6c0ab2597a
8006766: Array-like access to characters of a string is slow
hannesw
parents:
16188
diff
changeset
|
614 |
throw new IllegalArgumentException("Unsupported primitive: " + self); |
16147 | 615 |
} |
616 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
617 |
/** |
26508
b40ef4386b01
8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents:
26071
diff
changeset
|
618 |
* Returns a method handle that creates a wrapper object for a JS primitive value. |
b40ef4386b01
8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents:
26071
diff
changeset
|
619 |
* |
b40ef4386b01
8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents:
26071
diff
changeset
|
620 |
* @param self receiver object |
b40ef4386b01
8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents:
26071
diff
changeset
|
621 |
* @return method handle to create wrapper objects for primitive receiver |
b40ef4386b01
8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents:
26071
diff
changeset
|
622 |
*/ |
b40ef4386b01
8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents:
26071
diff
changeset
|
623 |
public static MethodHandle getPrimitiveWrapFilter(final Object self) { |
b40ef4386b01
8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents:
26071
diff
changeset
|
624 |
if (self instanceof String || self instanceof ConsString) { |
b40ef4386b01
8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents:
26071
diff
changeset
|
625 |
return NativeString.WRAPFILTER; |
b40ef4386b01
8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents:
26071
diff
changeset
|
626 |
} else if (self instanceof Number) { |
b40ef4386b01
8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents:
26071
diff
changeset
|
627 |
return NativeNumber.WRAPFILTER; |
b40ef4386b01
8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents:
26071
diff
changeset
|
628 |
} else if (self instanceof Boolean) { |
b40ef4386b01
8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents:
26071
diff
changeset
|
629 |
return NativeBoolean.WRAPFILTER; |
b40ef4386b01
8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents:
26071
diff
changeset
|
630 |
} |
b40ef4386b01
8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents:
26071
diff
changeset
|
631 |
throw new IllegalArgumentException("Unsupported primitive: " + self); |
b40ef4386b01
8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents:
26071
diff
changeset
|
632 |
} |
b40ef4386b01
8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents:
26071
diff
changeset
|
633 |
|
b40ef4386b01
8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents:
26071
diff
changeset
|
634 |
|
b40ef4386b01
8057021: UserAccessorProperty guards fail with multiple globals
hannesw
parents:
26071
diff
changeset
|
635 |
/** |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
636 |
* Create a new empty script object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
637 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
638 |
* @return the new ScriptObject |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
639 |
*/ |
16147 | 640 |
public ScriptObject newObject() { |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
641 |
return new JO(getObjectPrototype(), JO.getInitialMap()); |
16147 | 642 |
} |
643 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
644 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
645 |
* Default value of given type |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
646 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
647 |
* @param sobj script object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
648 |
* @param typeHint type hint |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
649 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
650 |
* @return default value |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
651 |
*/ |
16147 | 652 |
public Object getDefaultValue(final ScriptObject sobj, final Class<?> typeHint) { |
653 |
// When the [[DefaultValue]] internal method of O is called with no hint, |
|
654 |
// then it behaves as if the hint were Number, unless O is a Date object |
|
655 |
// in which case it behaves as if the hint were String. |
|
656 |
Class<?> hint = typeHint; |
|
657 |
if (hint == null) { |
|
658 |
hint = Number.class; |
|
659 |
} |
|
660 |
||
661 |
try { |
|
662 |
if (hint == String.class) { |
|
663 |
||
664 |
final Object toString = TO_STRING.getGetter().invokeExact(sobj); |
|
19088
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
19085
diff
changeset
|
665 |
|
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
19085
diff
changeset
|
666 |
if (Bootstrap.isCallable(toString)) { |
16147 | 667 |
final Object value = TO_STRING.getInvoker().invokeExact(toString, sobj); |
668 |
if (JSType.isPrimitive(value)) { |
|
669 |
return value; |
|
670 |
} |
|
671 |
} |
|
672 |
||
673 |
final Object valueOf = VALUE_OF.getGetter().invokeExact(sobj); |
|
19088
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
19085
diff
changeset
|
674 |
if (Bootstrap.isCallable(valueOf)) { |
16147 | 675 |
final Object value = VALUE_OF.getInvoker().invokeExact(valueOf, sobj); |
676 |
if (JSType.isPrimitive(value)) { |
|
677 |
return value; |
|
678 |
} |
|
679 |
} |
|
16256
f2d9a0c49914
8007002: Replace implicit exception throwing methods with explicit throws - simplify control flow and remove useless code
lagergren
parents:
16234
diff
changeset
|
680 |
throw typeError(this, "cannot.get.default.string"); |
16147 | 681 |
} |
682 |
||
683 |
if (hint == Number.class) { |
|
684 |
final Object valueOf = VALUE_OF.getGetter().invokeExact(sobj); |
|
19088
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
19085
diff
changeset
|
685 |
if (Bootstrap.isCallable(valueOf)) { |
16147 | 686 |
final Object value = VALUE_OF.getInvoker().invokeExact(valueOf, sobj); |
687 |
if (JSType.isPrimitive(value)) { |
|
688 |
return value; |
|
689 |
} |
|
690 |
} |
|
691 |
||
692 |
final Object toString = TO_STRING.getGetter().invokeExact(sobj); |
|
19088
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
19085
diff
changeset
|
693 |
if (Bootstrap.isCallable(toString)) { |
16147 | 694 |
final Object value = TO_STRING.getInvoker().invokeExact(toString, sobj); |
695 |
if (JSType.isPrimitive(value)) { |
|
696 |
return value; |
|
697 |
} |
|
698 |
} |
|
699 |
||
16256
f2d9a0c49914
8007002: Replace implicit exception throwing methods with explicit throws - simplify control flow and remove useless code
lagergren
parents:
16234
diff
changeset
|
700 |
throw typeError(this, "cannot.get.default.number"); |
16147 | 701 |
} |
702 |
} catch (final RuntimeException | Error e) { |
|
703 |
throw e; |
|
704 |
} catch (final Throwable t) { |
|
705 |
throw new RuntimeException(t); |
|
706 |
} |
|
707 |
||
708 |
return UNDEFINED; |
|
709 |
} |
|
710 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
711 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
712 |
* Is the given ScriptObject an ECMAScript Error object? |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
713 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
714 |
* @param sobj the object being checked |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
715 |
* @return true if sobj is an Error object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
716 |
*/ |
16147 | 717 |
public boolean isError(final ScriptObject sobj) { |
718 |
final ScriptObject errorProto = getErrorPrototype(); |
|
719 |
ScriptObject proto = sobj.getProto(); |
|
720 |
while (proto != null) { |
|
721 |
if (proto == errorProto) { |
|
722 |
return true; |
|
723 |
} |
|
724 |
proto = proto.getProto(); |
|
725 |
} |
|
726 |
return false; |
|
727 |
} |
|
728 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
729 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
730 |
* Create a new ECMAScript Error object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
731 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
732 |
* @param msg error message |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
733 |
* @return newly created Error object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
734 |
*/ |
16147 | 735 |
public ScriptObject newError(final String msg) { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
736 |
return new NativeError(msg, this); |
16147 | 737 |
} |
738 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
739 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
740 |
* Create a new ECMAScript EvalError object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
741 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
742 |
* @param msg error message |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
743 |
* @return newly created EvalError object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
744 |
*/ |
16147 | 745 |
public ScriptObject newEvalError(final String msg) { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
746 |
return new NativeEvalError(msg, this); |
16147 | 747 |
} |
748 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
749 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
750 |
* Create a new ECMAScript RangeError object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
751 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
752 |
* @param msg error message |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
753 |
* @return newly created RangeError object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
754 |
*/ |
16147 | 755 |
public ScriptObject newRangeError(final String msg) { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
756 |
return new NativeRangeError(msg, this); |
16147 | 757 |
} |
758 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
759 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
760 |
* Create a new ECMAScript ReferenceError object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
761 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
762 |
* @param msg error message |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
763 |
* @return newly created ReferenceError object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
764 |
*/ |
16147 | 765 |
public ScriptObject newReferenceError(final String msg) { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
766 |
return new NativeReferenceError(msg, this); |
16147 | 767 |
} |
768 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
769 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
770 |
* Create a new ECMAScript SyntaxError object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
771 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
772 |
* @param msg error message |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
773 |
* @return newly created SyntaxError object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
774 |
*/ |
16147 | 775 |
public ScriptObject newSyntaxError(final String msg) { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
776 |
return new NativeSyntaxError(msg, this); |
16147 | 777 |
} |
778 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
779 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
780 |
* Create a new ECMAScript TypeError object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
781 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
782 |
* @param msg error message |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
783 |
* @return newly created TypeError object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
784 |
*/ |
16147 | 785 |
public ScriptObject newTypeError(final String msg) { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
786 |
return new NativeTypeError(msg, this); |
16147 | 787 |
} |
788 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
789 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
790 |
* Create a new ECMAScript URIError object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
791 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
792 |
* @param msg error message |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
793 |
* @return newly created URIError object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
794 |
*/ |
16147 | 795 |
public ScriptObject newURIError(final String msg) { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
796 |
return new NativeURIError(msg, this); |
16147 | 797 |
} |
798 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
799 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
800 |
* Create a new ECMAScript GenericDescriptor object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
801 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
802 |
* @param configurable is the property configurable? |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
803 |
* @param enumerable is the property enumerable? |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
804 |
* @return newly created GenericDescriptor object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
805 |
*/ |
16147 | 806 |
public PropertyDescriptor newGenericDescriptor(final boolean configurable, final boolean enumerable) { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
807 |
return new GenericPropertyDescriptor(configurable, enumerable, this); |
16147 | 808 |
} |
809 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
810 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
811 |
* Create a new ECMAScript DatePropertyDescriptor object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
812 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
813 |
* @param value of the data property |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
814 |
* @param configurable is the property configurable? |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
815 |
* @param enumerable is the property enumerable? |
24731
ab0c8fc915ae
8038406: Testability: as a first step of moving loggers away from the process global space, the Debug object now supports logging POJOs from log entries as an event queue, which can be introspected from test scripts. This is way better than screen scraping brittle and subject-to-change log output.
lagergren
parents:
24727
diff
changeset
|
816 |
* @param writable is the property writable? |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
817 |
* @return newly created DataPropertyDescriptor object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
818 |
*/ |
16147 | 819 |
public PropertyDescriptor newDataDescriptor(final Object value, final boolean configurable, final boolean enumerable, final boolean writable) { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
820 |
return new DataPropertyDescriptor(configurable, enumerable, writable, value, this); |
16147 | 821 |
} |
822 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
823 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
824 |
* Create a new ECMAScript AccessorPropertyDescriptor object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
825 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
826 |
* @param get getter function of the user accessor property |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
827 |
* @param set setter function of the user accessor property |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
828 |
* @param configurable is the property configurable? |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
829 |
* @param enumerable is the property enumerable? |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
830 |
* @return newly created AccessorPropertyDescriptor object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
831 |
*/ |
16147 | 832 |
public PropertyDescriptor newAccessorDescriptor(final Object get, final Object set, final boolean configurable, final boolean enumerable) { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
833 |
final AccessorPropertyDescriptor desc = new AccessorPropertyDescriptor(configurable, enumerable, get == null ? UNDEFINED : get, set == null ? UNDEFINED : set, this); |
16147 | 834 |
|
835 |
if (get == null) { |
|
18328
ebd24057f163
8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
18326
diff
changeset
|
836 |
desc.delete(PropertyDescriptor.GET, false); |
16147 | 837 |
} |
838 |
||
839 |
if (set == null) { |
|
18328
ebd24057f163
8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
18326
diff
changeset
|
840 |
desc.delete(PropertyDescriptor.SET, false); |
16147 | 841 |
} |
842 |
||
843 |
return desc; |
|
844 |
} |
|
845 |
||
19456
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
846 |
private static <T> T getLazilyCreatedValue(final Object key, final Callable<T> creator, final Map<Object, T> map) { |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
847 |
final T obj = map.get(key); |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
848 |
if (obj != null) { |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
849 |
return obj; |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
850 |
} |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
851 |
|
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
852 |
try { |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
853 |
final T newObj = creator.call(); |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
854 |
final T existingObj = map.putIfAbsent(key, newObj); |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
855 |
return existingObj != null ? existingObj : newObj; |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
856 |
} catch (final Exception exp) { |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
857 |
throw new RuntimeException(exp); |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
858 |
} |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
859 |
} |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
860 |
|
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
861 |
private final Map<Object, InvokeByName> namedInvokers = new ConcurrentHashMap<>(); |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
862 |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
863 |
|
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
864 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
865 |
* Get cached InvokeByName object for the given key |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
866 |
* @param key key to be associated with InvokeByName object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
867 |
* @param creator if InvokeByName is absent 'creator' is called to make one (lazy init) |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
868 |
* @return InvokeByName object associated with the key. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
869 |
*/ |
19456
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
870 |
public InvokeByName getInvokeByName(final Object key, final Callable<InvokeByName> creator) { |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
871 |
return getLazilyCreatedValue(key, creator, namedInvokers); |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
872 |
} |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
873 |
|
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
874 |
private final Map<Object, MethodHandle> dynamicInvokers = new ConcurrentHashMap<>(); |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
875 |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
876 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
877 |
* Get cached dynamic method handle for the given key |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
878 |
* @param key key to be associated with dynamic method handle |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
879 |
* @param creator if method handle is absent 'creator' is called to make one (lazy init) |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
880 |
* @return dynamic method handle associated with the key. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
881 |
*/ |
19456
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
882 |
public MethodHandle getDynamicInvoker(final Object key, final Callable<MethodHandle> creator) { |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
883 |
return getLazilyCreatedValue(key, creator, dynamicInvokers); |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
884 |
} |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
885 |
|
16147 | 886 |
/** |
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
887 |
* Hook to search missing variables in ScriptContext if available |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
888 |
* @param self used to detect if scope call or not (this function is 'strict') |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
889 |
* @param name name of the variable missing |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
890 |
* @return value of the missing variable or undefined (or TypeError for scope search) |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
891 |
*/ |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
892 |
public static Object __noSuchProperty__(final Object self, final Object name) { |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
893 |
final Global global = Global.instance(); |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
894 |
final ScriptContext sctxt = global.scontext; |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
895 |
final String nameStr = name.toString(); |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
896 |
|
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
897 |
if (sctxt != null) { |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
898 |
final int scope = sctxt.getAttributesScope(nameStr); |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
899 |
if (scope != -1) { |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
900 |
return ScriptObjectMirror.unwrap(sctxt.getAttribute(nameStr, scope), global); |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
901 |
} |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
902 |
} |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
903 |
|
26647
a6acc63c2a31
8058422: Users should be able to overwrite "context" and "engine" variables
sundar
parents:
26508
diff
changeset
|
904 |
switch (nameStr) { |
26886
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
905 |
case "context": |
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
906 |
return sctxt; |
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
907 |
case "engine": |
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
908 |
return global.engine; |
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
909 |
default: |
18c744ab4df2
8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents:
26768
diff
changeset
|
910 |
break; |
26647
a6acc63c2a31
8058422: Users should be able to overwrite "context" and "engine" variables
sundar
parents:
26508
diff
changeset
|
911 |
} |
a6acc63c2a31
8058422: Users should be able to overwrite "context" and "engine" variables
sundar
parents:
26508
diff
changeset
|
912 |
|
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
913 |
if (self == UNDEFINED) { |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
914 |
// scope access and so throw ReferenceError |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
915 |
throw referenceError(global, "not.defined", nameStr); |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
916 |
} |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
917 |
|
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
918 |
return UNDEFINED; |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
919 |
} |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
920 |
|
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
921 |
/** |
16147 | 922 |
* This is the eval used when 'indirect' eval call is made. |
923 |
* |
|
924 |
* var global = this; |
|
925 |
* global.eval("print('hello')"); |
|
926 |
* |
|