author | attila |
Mon, 02 Mar 2015 14:33:55 +0100 | |
changeset 29282 | a8523237b66c |
parent 29280 | 8a79b4040d2a |
child 29624 | 4fd94b55ead4 |
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; |
29282 | 31 |
import static jdk.nashorn.internal.runtime.JSType.isString; |
16147 | 32 |
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
|
33 |
|
16147 | 34 |
import java.io.IOException; |
35 |
import java.io.PrintWriter; |
|
36 |
import java.lang.invoke.MethodHandle; |
|
37 |
import java.lang.invoke.MethodHandles; |
|
27814
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
38 |
import java.lang.invoke.MethodType; |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
39 |
import java.lang.invoke.SwitchPoint; |
16522 | 40 |
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
|
41 |
import java.util.ArrayList; |
18326
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
42 |
import java.util.Arrays; |
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
43 |
import java.util.List; |
16147 | 44 |
import java.util.Map; |
28785
a503c972d4bd
8072595: nashorn should not use obj.getClass() for null checks
sundar
parents:
27814
diff
changeset
|
45 |
import java.util.Objects; |
19456
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
46 |
import java.util.concurrent.Callable; |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
47 |
import java.util.concurrent.ConcurrentHashMap; |
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
48 |
import javax.script.ScriptContext; |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
49 |
import javax.script.ScriptEngine; |
27814
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
50 |
import jdk.internal.dynalink.CallSiteDescriptor; |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
16233
diff
changeset
|
51 |
import jdk.internal.dynalink.linker.GuardedInvocation; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
16233
diff
changeset
|
52 |
import jdk.internal.dynalink.linker.LinkRequest; |
26071 | 53 |
import jdk.nashorn.api.scripting.ClassFilter; |
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
54 |
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
|
55 |
import jdk.nashorn.internal.lookup.Lookup; |
16147 | 56 |
import jdk.nashorn.internal.objects.annotations.Attribute; |
57 |
import jdk.nashorn.internal.objects.annotations.Property; |
|
58 |
import jdk.nashorn.internal.objects.annotations.ScriptClass; |
|
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); |
29282 | 580 |
} else if (isString(obj)) { |
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) { |
29282 | 607 |
if (isString(self)) { |
16195
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) { |
29282 | 624 |
if (isString(self)) { |
26508
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 |
* |
|
927 |
* @param self eval scope |
|
928 |
* @param str eval string |
|
929 |
* |
|
930 |
* @return the result of eval |
|
931 |
*/ |
|
932 |
public static Object eval(final Object self, final Object str) { |
|
25423
ca63828cf996
8047067: all eval arguments need to be copied in Lower
attila
parents:
25422
diff
changeset
|
933 |
return directEval(self, str, UNDEFINED, UNDEFINED, false); |
16147 | 934 |
} |
935 |
||
936 |
/** |
|
937 |
* Direct eval |
|
938 |
* |
|
939 |
* @param self The scope of eval passed as 'self' |
|
940 |
* @param str Evaluated code |
|
941 |
* @param callThis "this" to be passed to the evaluated code |
|
942 |
* @param location location of the eval call |
|
943 |
* @param strict is eval called a strict mode code? |
|
944 |
* |
|
945 |
* @return the return value of the eval |
|
946 |
* |
|
947 |
* This is directly invoked from generated when eval(code) is called in user code |
|
948 |
*/ |
|
25423
ca63828cf996
8047067: all eval arguments need to be copied in Lower
attila
parents:
25422
diff
changeset
|
949 |
public static Object directEval(final Object self, final Object str, final Object callThis, final Object location, final boolean strict) { |
29282 | 950 |
if (!isString(str)) { |
16147 | 951 |
return str; |
952 |
} |
|
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
953 |
final Global global = Global.instanceFrom(self); |
29280
8a79b4040d2a
8074021: Indirect eval fails when used as an element of an array or as a property of an object
sundar
parents:
28786
diff
changeset
|
954 |
final ScriptObject scope = self instanceof ScriptObject && ((ScriptObject)self).isScope() ? (ScriptObject)self : global; |
16147 | 955 |
|
25423
ca63828cf996
8047067: all eval arguments need to be copied in Lower
attila
parents:
25422
diff
changeset
|
956 |
return global.getContext().eval(scope, str.toString(), callThis, location, strict, true); |
16147 | 957 |
} |
958 |
||
959 |
/** |
|
960 |
* Global print implementation - Nashorn extension |
|
961 |
* |
|
962 |
* @param self scope |
|
963 |
* @param objects arguments to print |
|
964 |
* |
|
965 |
* @return result of print (undefined) |
|
966 |
*/ |
|
967 |
public static Object print(final Object self, final Object... objects) { |
|
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
968 |
return Global.instanceFrom(self).printImpl(false, objects); |
16147 | 969 |
} |
970 |
||
971 |
/** |
|
972 |
* Global println implementation - Nashorn extension |
|
973 |
* |
|
974 |
* @param self scope |
|
975 |
* @param objects arguments to print |
|
976 |
* |
|
977 |
* @return result of println (undefined) |
|
978 |
*/ |
|
979 |
public static Object println(final Object self, final Object... objects) { |
|
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
980 |
return Global.instanceFrom(self).printImpl(true, objects); |
16147 | 981 |
} |
982 |
||
983 |
/** |
|
984 |
* Global load implementation - Nashorn extension |
|
985 |
* |
|
986 |
* @param self scope |
|
987 |
* @param source source to load |
|
988 |
* |
|
989 |
* @return result of load (undefined) |
|
990 |
* |
|
991 |
* @throws IOException if source could not be read |
|
992 |
*/ |
|
993 |
public static Object load(final Object self, final Object source) throws IOException { |
|
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
994 |
final Global global = Global.instanceFrom(self); |
24720 | 995 |
final ScriptObject scope = self instanceof ScriptObject ? (ScriptObject)self : global; |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
996 |
return global.getContext().load(scope, source); |
16147 | 997 |
} |
998 |
||
16219 | 999 |
/** |
17974
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
1000 |
* Global loadWithNewGlobal implementation - Nashorn extension |
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
1001 |
* |
18326
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
1002 |
* @param self scope |
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
1003 |
* @param args from plus (optional) arguments to be passed to the loaded script |
17974
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
1004 |
* |
18326
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
1005 |
* @return result of load (may be undefined) |
17974
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
1006 |
* |
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
1007 |
* @throws IOException if source could not be read |
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
1008 |
*/ |
18326
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
1009 |
public static Object loadWithNewGlobal(final Object self, final Object...args) throws IOException { |
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
1010 |
final Global global = Global.instanceFrom(self); |
18326
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
1011 |
final int length = args.length; |
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
1012 |
final boolean hasArgs = 0 < length; |
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
1013 |
final Object from = hasArgs ? args[0] : UNDEFINED; |
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
1014 |
final Object[] arguments = hasArgs ? Arrays.copyOfRange(args, 1, length) : args; |
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
1015 |
|
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
1016 |
return global.getContext().loadWithNewGlobal(from, arguments); |
17974
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
1017 |
} |
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
1018 |
|
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
1019 |
/** |
16219 | 1020 |
* Global exit and quit implementation - Nashorn extension: perform a {@code System.exit} call from the script |
1021 |
* |
|
1022 |
* @param self self reference |
|
1023 |
* @param code exit code |
|
1024 |
* |
|
24733
1e825be55fd1
8027043: Turn global accesses into MethodHandle.constant, with one chance of reassignment, e.g. x = value occuring once in the global scope is ok, twice is not.
lagergren
parents:
24731
diff
changeset
|
1025 |
* @return undefined (will never be reached) |
16219 | 1026 |
*/ |
1027 |
public static Object exit(final Object self, final Object code) { |
|
1028 |
System.exit(JSType.toInt32(code)); |
|
1029 |
return UNDEFINED; |
|
1030 |
} |
|
1031 |
||
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
1032 |
// builtin prototype accessors |
28786 | 1033 |
|
1034 |
/** |
|
1035 |
* Get the builtin Object prototype. |
|
1036 |
* @return the object prototype. |
|
1037 |
*/ |
|
1038 |
public ScriptObject getObjectPrototype() { |
|
1039 |
return ScriptFunction.getPrototype(builtinObject); |
|
1040 |
} |
|
1041 |
||
16147 | 1042 |
ScriptObject getFunctionPrototype() { |
1043 |
return ScriptFunction.getPrototype(builtinFunction); |
|
1044 |
} |
|
1045 |
||
1046 |
ScriptObject getArrayPrototype() { |
|
1047 |
return ScriptFunction.getPrototype(builtinArray); |
|
1048 |
} |
|
1049 |
||
1050 |
ScriptObject getBooleanPrototype() { |
|
1051 |
return ScriptFunction.getPrototype(builtinBoolean); |
|
1052 |
} |
|
1053 |
||
1054 |
ScriptObject getNumberPrototype() { |
|
1055 |
return ScriptFunction.getPrototype(builtinNumber); |
|
1056 |
} |
|
1057 |
||
1058 |
ScriptObject getDatePrototype() { |
|
1059 |
return ScriptFunction.getPrototype(builtinDate); |
|
1060 |
} |
|
1061 |
||
1062 |
ScriptObject getRegExpPrototype() { |
|
1063 |
return ScriptFunction.getPrototype(builtinRegExp); |
|
1064 |
} |
|
1065 |
||
1066 |
ScriptObject getStringPrototype() { |
|
1067 |
return ScriptFunction.getPrototype(builtinString); |
|
1068 |
} |
|
1069 |
||
1070 |
ScriptObject getErrorPrototype() { |
|
1071 |
return ScriptFunction.getPrototype(builtinError); |
|
1072 |
} |
|
1073 |
||
1074 |
ScriptObject getEvalErrorPrototype() { |
|
1075 |
return ScriptFunction.getPrototype(builtinEvalError); |
|
1076 |
} |
|
1077 |
||
1078 |
ScriptObject getRangeErrorPrototype() { |
|
1079 |
return ScriptFunction.getPrototype(builtinRangeError); |
|
1080 |
} |
|
1081 |
||
1082 |
ScriptObject getReferenceErrorPrototype() { |
|
1083 |
return ScriptFunction.getPrototype(builtinReferenceError); |
|
1084 |
} |
|
1085 |
||
1086 |
ScriptObject getSyntaxErrorPrototype() { |
|
1087 |
return ScriptFunction.getPrototype(builtinSyntaxError); |
|
1088 |
} |
|
1089 |
||
1090 |
ScriptObject getTypeErrorPrototype() { |
|
1091 |
return ScriptFunction.getPrototype(builtinTypeError); |
|
1092 |
} |
|
1093 |
||
1094 |
ScriptObject getURIErrorPrototype() { |
|
1095 |
return ScriptFunction.getPrototype(builtinURIError); |
|
1096 |
} |
|
1097 |
||
1098 |
ScriptObject getJavaImporterPrototype() { |
|
1099 |
return ScriptFunction.getPrototype(builtinJavaImporter); |
|
1100 |
} |
|
1101 |
||
1102 |
ScriptObject getJSAdapterPrototype() { |
|
1103 |
return ScriptFunction.getPrototype(builtinJSAdapter); |
|
1104 |
} |
|
1105 |
||
1106 |
ScriptObject getArrayBufferPrototype() { |
|
1107 |
return ScriptFunction.getPrototype(builtinArrayBuffer); |
|
1108 |
} |
|
1109 |
||
23374 | 1110 |
ScriptObject getDataViewPrototype() { |
1111 |
return ScriptFunction.getPrototype(builtinDataView); |
|
1112 |
} |
|
1113 |
||
16147 | 1114 |
ScriptObject getInt8ArrayPrototype() { |
1115 |
return ScriptFunction.getPrototype(builtinInt8Array); |
|
1116 |
} |
|
1117 |
||
1118 |
ScriptObject getUint8ArrayPrototype() { |
|
1119 |
return ScriptFunction.getPrototype(builtinUint8Array); |
|
1120 |
} |
|
1121 |
||
1122 |
ScriptObject getUint8ClampedArrayPrototype() { |
|
1123 |
return ScriptFunction.getPrototype(builtinUint8ClampedArray); |
|
1124 |
} |
|
1125 |
||
1126 |
ScriptObject getInt16ArrayPrototype() { |
|
1127 |
return ScriptFunction.getPrototype(builtinInt16Array); |
|
1128 |
} |
|
1129 |
||
1130 |
ScriptObject getUint16ArrayPrototype() { |
|
1131 |
return ScriptFunction.getPrototype(builtinUint16Array); |
|
1132 |
} |
|
1133 |
||
1134 |
ScriptObject getInt32ArrayPrototype() { |
|
1135 |
return ScriptFunction.getPrototype(builtinInt32Array); |
|
1136 |
} |
|
1137 |
||
1138 |
ScriptObject getUint32ArrayPrototype() { |
|
1139 |
return ScriptFunction.getPrototype(builtinUint32Array); |
|
1140 |
} |
|
1141 |
||
1142 |
ScriptObject getFloat32ArrayPrototype() { |
|
1143 |
return ScriptFunction.getPrototype(builtinFloat32Array); |
|
1144 |
} |
|
1145 |
||
1146 |
ScriptObject getFloat64ArrayPrototype() { |
|
1147 |
return ScriptFunction.getPrototype(builtinFloat64Array); |
|
1148 |
} |
|
1149 |
||
1150 |
private ScriptFunction getBuiltinArray() { |
|
1151 |
return builtinArray; |
|
1152 |
} |
|
1153 |
||
22382
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
1154 |
ScriptFunction getTypeErrorThrower() { |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
1155 |
return typeErrorThrower; |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
1156 |
} |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
1157 |
|
16147 | 1158 |
/** |
1159 |
* Called from compiled script code to test if builtin has been overridden |
|
1160 |
* |
|
1161 |
* @return true if builtin array has not been overridden |
|
1162 |
*/ |
|
1163 |
public static boolean isBuiltinArray() { |
|
1164 |
final Global instance = Global.instance(); |
|
1165 |
return instance.array == instance.getBuiltinArray(); |
|
1166 |
} |
|
1167 |
||
1168 |
private ScriptFunction getBuiltinBoolean() { |
|
1169 |
return builtinBoolean; |
|
1170 |
} |
|
1171 |
||
1172 |
/** |
|
1173 |
* Called from compiled script code to test if builtin has been overridden |
|
1174 |
* |
|
1175 |
* @return true if builtin boolean has not been overridden |
|
1176 |
*/ |
|
1177 |
public static boolean isBuiltinBoolean() { |
|
1178 |
final Global instance = Global.instance(); |
|
1179 |
return instance._boolean == instance.getBuiltinBoolean(); |
|
1180 |
} |
|
1181 |
||
1182 |
private ScriptFunction getBuiltinDate() { |
|
1183 |
return builtinDate; |
|
1184 |
} |
|
1185 |
||
1186 |
/** |
|
1187 |
* Called from compiled script code to test if builtin has been overridden |
|
1188 |
* |
|
1189 |
* @return true if builtin date has not been overridden |
|
1190 |
*/ |
|
1191 |
public static boolean isBuiltinDate() { |
|
1192 |
final Global instance = Global.instance(); |
|
1193 |
return instance.date == instance.getBuiltinDate(); |
|
1194 |
} |
|
1195 |
||
1196 |
private ScriptFunction getBuiltinError() { |
|
1197 |
return builtinError; |
|
1198 |
} |
|
1199 |
||
1200 |
/** |
|
1201 |
* Called from compiled script code to test if builtin has been overridden |
|
1202 |
* |
|
1203 |
* @return true if builtin error has not been overridden |
|
1204 |
*/ |
|
1205 |
public static boolean isBuiltinError() { |
|
1206 |
final Global instance = Global.instance(); |
|
1207 |
return instance.error == instance.getBuiltinError(); |
|
1208 |
} |
|
1209 |
||
1210 |
private ScriptFunction getBuiltinEvalError() { |
|
1211 |
return builtinEvalError; |
|
1212 |
} |
|
1213 |
||
1214 |
/** |
|
1215 |
* Called from compiled script code to test if builtin has been overridden |
|
1216 |
* |
|
1217 |
* @return true if builtin eval error has not been overridden |
|
1218 |
*/ |
|
1219 |
public static boolean isBuiltinEvalError() { |
|
1220 |
final Global instance = Global.instance(); |
|
1221 |
return instance.evalError == instance.getBuiltinEvalError(); |
|
1222 |
} |
|
1223 |
||
1224 |
private ScriptFunction getBuiltinFunction() { |
|
1225 |
return builtinFunction; |
|
1226 |
} |
|
1227 |
||
1228 |
/** |
|
1229 |
* Called from compiled script code to test if builtin has been overridden |
|
1230 |
* |
|
1231 |
* @return true if builtin function has not been overridden |
|
1232 |
*/ |
|
1233 |
public static boolean isBuiltinFunction() { |
|
1234 |
final Global instance = Global.instance(); |
|
1235 |
return instance.function == instance.getBuiltinFunction(); |
|
1236 |
} |
|
1237 |
||
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1238 |
/** |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1239 |
* Get the switchpoint used to check property changes for Function.prototype.apply |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1240 |
* @return the switchpoint guarding apply (same as guarding call, and everything else in function) |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1241 |
*/ |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1242 |
public static SwitchPoint getBuiltinFunctionApplySwitchPoint() { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1243 |
return ScriptFunction.getPrototype(Global.instance().getBuiltinFunction()).getProperty("apply").getBuiltinSwitchPoint(); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1244 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1245 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1246 |
private static boolean isBuiltinFunctionProperty(final String name) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1247 |
final Global instance = Global.instance(); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1248 |
final ScriptFunction builtinFunction = instance.getBuiltinFunction(); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1249 |
if (builtinFunction == null) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1250 |
return false; //conservative for compile-only mode |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1251 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1252 |
final boolean isBuiltinFunction = instance.function == builtinFunction; |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1253 |
return isBuiltinFunction && ScriptFunction.getPrototype(builtinFunction).getProperty(name).isBuiltin(); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1254 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1255 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1256 |
/** |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1257 |
* Check if the Function.prototype.apply has not been replaced |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1258 |
* @return true if Function.prototype.apply has been replaced |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1259 |
*/ |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1260 |
public static boolean isBuiltinFunctionPrototypeApply() { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1261 |
return isBuiltinFunctionProperty("apply"); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1262 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1263 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1264 |
/** |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1265 |
* Check if the Function.prototype.apply has not been replaced |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1266 |
* @return true if Function.prototype.call has been replaced |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1267 |
*/ |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1268 |
public static boolean isBuiltinFunctionPrototypeCall() { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1269 |
return isBuiltinFunctionProperty("call"); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1270 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1271 |
|
16147 | 1272 |
private ScriptFunction getBuiltinJSAdapter() { |
1273 |
return builtinJSAdapter; |
|
1274 |
} |
|
1275 |
||
1276 |
/** |
|
1277 |
* Called from compiled script code to test if builtin has been overridden |
|
1278 |
* |
|
1279 |
* @return true if builtin JSAdapter has not been overridden |
|
1280 |
*/ |
|
1281 |
public static boolean isBuiltinJSAdapter() { |
|
1282 |
final Global instance = Global.instance(); |
|
1283 |
return instance.jsadapter == instance.getBuiltinJSAdapter(); |
|
1284 |
} |
|
1285 |
||
1286 |
private ScriptObject getBuiltinJSON() { |
|
1287 |
return builtinJSON; |
|
1288 |
} |
|
1289 |
||
1290 |
/** |
|
1291 |
* Called from compiled script code to test if builtin has been overridden |
|
1292 |
* |
|
1293 |
* @return true if builtin JSON has has not been overridden |
|
1294 |
*/ |
|
1295 |
public static boolean isBuiltinJSON() { |
|
1296 |
final Global instance = Global.instance(); |
|
1297 |
return instance.json == instance.getBuiltinJSON(); |
|
1298 |
} |
|
1299 |
||
1300 |
private ScriptObject getBuiltinJava() { |
|
1301 |
return builtinJava; |
|
1302 |
} |
|
1303 |
||
1304 |
/** |
|
1305 |
* Called from compiled script code to test if builtin has been overridden |
|
1306 |
* |
|
1307 |
* @return true if builtin Java has not been overridden |
|
1308 |
*/ |
|
1309 |
public static boolean isBuiltinJava() { |
|
1310 |
final Global instance = Global.instance(); |
|
1311 |
return instance.java == instance.getBuiltinJava(); |
|
1312 |
} |
|
1313 |
||
1314 |
private ScriptObject getBuiltinJavax() { |
|
1315 |
return builtinJavax; |
|
1316 |
} |
|
1317 |
||
1318 |
/** |
|
1319 |
* Called from compiled script code to test if builtin has been overridden |
|
1320 |
* |
|
1321 |
* @return true if builtin Javax has not been overridden |
|
1322 |
*/ |
|
1323 |
public static boolean isBuiltinJavax() { |
|
1324 |
final Global instance = Global.instance(); |
|
1325 |
return instance.javax == instance.getBuiltinJavax(); |
|
1326 |
} |
|
1327 |
||
1328 |
private ScriptObject getBuiltinJavaImporter() { |
|
1329 |
return builtinJavaImporter; |
|
1330 |
} |
|
1331 |
||
1332 |
/** |
|
1333 |
* Called from compiled script code to test if builtin has been overridden |
|
1334 |
* |
|
1335 |
* @return true if builtin Java importer has not been overridden |
|
1336 |
*/ |
|
1337 |
public static boolean isBuiltinJavaImporter() { |
|
1338 |
final Global instance = Global.instance(); |
|
1339 |
return instance.javaImporter == instance.getBuiltinJavaImporter(); |
|
1340 |
} |
|
1341 |
||
1342 |
private ScriptObject getBuiltinMath() { |
|
1343 |
return builtinMath; |
|
1344 |
} |
|
1345 |
||
1346 |
/** |
|
1347 |
* Called from compiled script code to test if builtin has been overridden |
|
1348 |
* |
|
1349 |
* @return true if builtin math has not been overridden |
|
1350 |
*/ |
|
1351 |
public static boolean isBuiltinMath() { |
|
1352 |
final Global instance = Global.instance(); |
|
1353 |
return instance.math == instance.getBuiltinMath(); |
|
1354 |
} |
|
1355 |
||
1356 |
private ScriptFunction getBuiltinNumber() { |
|
1357 |
return builtinNumber; |
|
1358 |
} |
|
1359 |
||
1360 |
/** |
|
1361 |
* Called from compiled script code to test if builtin has been overridden |
|
1362 |
* |
|
1363 |
* @return true if builtin number has not been overridden |
|
1364 |
*/ |
|
1365 |
public static boolean isBuiltinNumber() { |
|
1366 |
final Global instance = Global.instance(); |
|
1367 |
return instance.number == instance.getBuiltinNumber(); |
|
1368 |
} |
|
1369 |
||
1370 |
private ScriptFunction getBuiltinObject() { |
|
1371 |
return builtinObject; |
|
1372 |
} |
|
1373 |
||
1374 |
/** |
|
1375 |
* Called from compiled script code to test if builtin has been overridden |
|
1376 |
* |
|
1377 |
* @return true if builtin object has not been overridden |
|
1378 |
*/ |
|
1379 |
public static boolean isBuiltinObject() { |
|
1380 |
final Global instance = Global.instance(); |
|
1381 |
return instance.object == instance.getBuiltinObject(); |
|
1382 |
} |
|
1383 |
||
1384 |
private ScriptObject getBuiltinPackages() { |
|
1385 |
return builtinPackages; |
|
1386 |
} |
|
1387 |
||
1388 |
/** |
|
1389 |
* Called from compiled script code to test if builtin has been overridden |
|
1390 |
* |
|
1391 |
* @return true if builtin package has not been overridden |
|
1392 |
*/ |
|
1393 |
public static boolean isBuiltinPackages() { |
|
1394 |
final Global instance = Global.instance(); |
|
1395 |
return instance.packages == instance.getBuiltinPackages(); |
|
1396 |
} |
|
1397 |
||
1398 |
private ScriptFunction getBuiltinRangeError() { |
|
1399 |
return builtinRangeError; |
|
1400 |
} |
|
1401 |
||
1402 |
/** |
|
1403 |
* Called from compiled script code to test if builtin has been overridden |
|
1404 |
* |
|
1405 |
* @return true if builtin range error has not been overridden |
|
1406 |
*/ |
|
1407 |
public static boolean isBuiltinRangeError() { |
|
1408 |
final Global instance = Global.instance(); |
|
1409 |
return instance.rangeError == instance.getBuiltinRangeError(); |
|
1410 |
} |
|
1411 |
||
1412 |
private ScriptFunction getBuiltinReferenceError() { |
|
1413 |
return builtinReferenceError; |
|
1414 |
} |
|
1415 |
||
1416 |
/** |
|
1417 |
* Called from compiled script code to test if builtin has been overridden |
|
1418 |
* |
|
1419 |
* @return true if builtin reference error has not been overridden |
|
1420 |
*/ |
|
1421 |
public static boolean isBuiltinReferenceError() { |
|
1422 |
final Global instance = Global.instance(); |
|
1423 |
return instance.referenceError == instance.getBuiltinReferenceError(); |
|
1424 |
} |
|
1425 |
||
1426 |
private ScriptFunction getBuiltinRegExp() { |
|
1427 |
return builtinRegExp; |
|
1428 |
} |
|
1429 |
||
1430 |
/** |
|
1431 |
* Called from compiled script code to test if builtin has been overridden |
|
1432 |
* |
|
1433 |
* @return true if builtin regexp has not been overridden |
|
1434 |
*/ |
|
1435 |
public static boolean isBuiltinRegExp() { |
|
1436 |
final Global instance = Global.instance(); |
|
1437 |
return instance.regexp == instance.getBuiltinRegExp(); |
|
1438 |
} |
|
1439 |
||
1440 |
private ScriptFunction getBuiltinString() { |
|
1441 |
return builtinString; |
|
1442 |
} |
|
1443 |
||
1444 |
/** |
|
1445 |
* Called from compiled script code to test if builtin has been overridden |
|
1446 |
* |
|
1447 |
* @return true if builtin Java has not been overridden |
|
1448 |
*/ |
|
1449 |
public static boolean isBuiltinString() { |
|
1450 |
final Global instance = Global.instance(); |
|
1451 |
return instance.string == instance.getBuiltinString(); |
|
1452 |
} |
|
1453 |
||
1454 |
private ScriptFunction getBuiltinSyntaxError() { |
|
1455 |
return builtinSyntaxError; |
|
1456 |
} |
|
1457 |
||
1458 |
/** |
|
1459 |
* Called from compiled script code to test if builtin has been overridden |
|
1460 |
* |
|
1461 |
* @return true if builtin syntax error has not been overridden |
|
1462 |
*/ |
|
1463 |
public static boolean isBuiltinSyntaxError() { |
|
1464 |
final Global instance = Global.instance(); |
|
1465 |
return instance.syntaxError == instance.getBuiltinSyntaxError(); |
|
1466 |
} |
|
1467 |
||
1468 |
private ScriptFunction getBuiltinTypeError() { |
|
1469 |
return builtinTypeError; |
|
1470 |
} |
|
1471 |
||
1472 |
/** |
|
1473 |
* Called from compiled script code to test if builtin has been overridden |
|
1474 |
* |
|
1475 |
* @return true if builtin type error has not been overridden |
|
1476 |
*/ |
|
1477 |
public static boolean isBuiltinTypeError() { |
|
1478 |
final Global instance = Global.instance(); |
|
1479 |
return instance.typeError == instance.getBuiltinTypeError(); |
|
1480 |
} |
|
1481 |
||
1482 |
private ScriptFunction getBuiltinURIError() { |
|
1483 |
return builtinURIError; |
|
1484 |
} |
|
1485 |
||
1486 |
/** |
|
1487 |
* Called from compiled script code to test if builtin has been overridden |
|
1488 |
* |
|
1489 |
* @return true if builtin URI error has not been overridden |
|
1490 |
*/ |
|
1491 |
public static boolean isBuiltinURIError() { |
|
1492 |
final Global instance = Global.instance(); |
|
1493 |
return instance.uriError == instance.getBuiltinURIError(); |
|
1494 |
} |
|
1495 |
||
1496 |
@Override |
|
1497 |
public String getClassName() { |
|
1498 |
return "global"; |
|
1499 |
} |
|
1500 |
||
1501 |
/** |
|
1502 |
* Copy function used to clone NativeRegExp objects. |
|
1503 |
* |
|
1504 |
* @param regexp a NativeRegExp to clone |
|
1505 |
* |
|
1506 |
* @return copy of the given regexp object |
|
1507 |
*/ |
|
1508 |
public static Object regExpCopy(final Object regexp) { |
|
1509 |
return new NativeRegExp((NativeRegExp)regexp); |
|
1510 |
} |
|
1511 |
||
1512 |
/** |
|
1513 |
* Convert given object to NativeRegExp type. |
|
1514 |
* |
|
1515 |
* @param obj object to be converted |
|
1516 |
* @return NativeRegExp instance |
|
1517 |
*/ |
|
1518 |
public static NativeRegExp toRegExp(final Object obj) { |
|
1519 |
if (obj instanceof NativeRegExp) { |
|
1520 |
return (NativeRegExp)obj; |
|
1521 |
} |
|
1522 |
return new NativeRegExp(JSType.toString(obj)); |
|
1523 |
} |
|
1524 |
||
1525 |
/** |
|
1526 |
* ECMA 9.9 ToObject implementation |
|
1527 |
* |
|
1528 |
* @param obj an item for which to run ToObject |
|
1529 |
* @return ToObject version of given item |
|
1530 |
*/ |
|
1531 |
public static Object toObject(final Object obj) { |
|
1532 |
if (obj == null || obj == UNDEFINED) { |
|
16256
f2d9a0c49914
8007002: Replace implicit exception throwing methods with explicit throws - simplify control flow and remove useless code
lagergren
parents:
16234
diff
changeset
|
1533 |
throw typeError("not.an.object", ScriptRuntime.safeToString(obj)); |
16147 | 1534 |
} |
1535 |
||
1536 |
if (obj instanceof ScriptObject) { |
|
1537 |
return obj; |
|
1538 |
} |
|
1539 |
||
1540 |
return instance().wrapAsObject(obj); |
|
1541 |
} |
|
1542 |
||
1543 |
/** |
|
1544 |
* Allocate a new object array. |
|
1545 |
* |
|
1546 |
* @param initial object values. |
|
1547 |
* @return the new array |
|
1548 |
*/ |
|
16210
8ad1381b69d0
8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents:
16207
diff
changeset
|
1549 |
public static NativeArray allocate(final Object[] initial) { |
18618
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1550 |
ArrayData arrayData = ArrayData.allocate(initial); |
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1551 |
|
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1552 |
for (int index = 0; index < initial.length; index++) { |
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1553 |
final Object value = initial[index]; |
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1554 |
|
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1555 |
if (value == ScriptRuntime.EMPTY) { |
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1556 |
arrayData = arrayData.delete(index); |
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1557 |
} |
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1558 |
} |
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1559 |
|
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1560 |
return new NativeArray(arrayData); |
16147 | 1561 |
} |
1562 |
||
1563 |
/** |
|
1564 |
* Allocate a new number array. |
|
1565 |
* |
|
1566 |
* @param initial number values. |
|
1567 |
* @return the new array |
|
1568 |
*/ |
|
16210
8ad1381b69d0
8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents:
16207
diff
changeset
|
1569 |
public static NativeArray allocate(final double[] initial) { |
18618
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1570 |
return new NativeArray(ArrayData.allocate(initial)); |
16147 | 1571 |
} |
1572 |
||
1573 |
/** |
|
1574 |
* Allocate a new long array. |
|
1575 |
* |
|
1576 |
* @param initial number values. |
|
1577 |
* @return the new array |
|
1578 |
*/ |
|
16210
8ad1381b69d0
8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents:
16207
diff
changeset
|
1579 |
public static NativeArray allocate(final long[] initial) { |
18618
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1580 |
return new NativeArray(ArrayData.allocate(initial)); |
16147 | 1581 |
} |
1582 |
||
1583 |
/** |
|
1584 |
* Allocate a new integer array. |
|
1585 |
* |
|
1586 |
* @param initial number values. |
|
1587 |
* @return the new array |
|
1588 |
*/ |
|
16210
8ad1381b69d0
8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents:
16207
diff
changeset
|
1589 |
public static NativeArray allocate(final int[] initial) { |
18618
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1590 |
return new NativeArray(ArrayData.allocate(initial)); |
16147 | 1591 |
} |
1592 |
||
1593 |
/** |
|
1594 |
* Allocate a new object array for arguments. |
|
1595 |
* |
|
1596 |
* @param arguments initial arguments passed. |
|
1597 |
* @param callee reference to the function that uses arguments object |
|
1598 |
* @param numParams actual number of declared parameters |
|
1599 |
* |
|
1600 |
* @return the new array |
|
1601 |
*/ |
|
16206
83069fa0935b
8006529: Methods always get callee - it should be conditional
attila
parents:
16196
diff
changeset
|
1602 |
public static ScriptObject allocateArguments(final Object[] arguments, final Object callee, final int numParams) { |
16147 | 1603 |
return NativeArguments.allocate(arguments, (ScriptFunction)callee, numParams); |
1604 |
} |
|
1605 |
||
1606 |
/** |
|
1607 |
* Called from generated to check if given function is the builtin 'eval'. If |
|
1608 |
* eval is used in a script, a lot of optimizations and assumptions cannot be done. |
|
1609 |
* |
|
1610 |
* @param fn function object that is checked |
|
1611 |
* @return true if fn is the builtin eval |
|
1612 |
*/ |
|
1613 |
public static boolean isEval(final Object fn) { |
|
1614 |
return fn == Global.instance().builtinEval; |
|
1615 |
} |
|
1616 |
||
1617 |
/** |
|
24719 | 1618 |
* Called from generated to replace a location property placeholder with the actual location property value. |
1619 |
* |
|
1620 |
* @param placeholder the value tested for being a placeholder for a location property |
|
1621 |
* @param locationProperty the actual value for the location property |
|
1622 |
* @return locationProperty if placeholder is indeed a placeholder for a location property, the placeholder otherwise |
|
1623 |
*/ |
|
1624 |
public static Object replaceLocationPropertyPlaceholder(final Object placeholder, final Object locationProperty) { |
|
1625 |
return isLocationPropertyPlaceholder(placeholder) ? locationProperty : placeholder; |
|
1626 |
} |
|
1627 |
||
1628 |
/** |
|
1629 |
* Called from runtime internals to check if the passed value is a location property placeholder. |
|
1630 |
* @param placeholder the value tested for being a placeholder for a location property |
|
1631 |
* @return true if the value is a placeholder, false otherwise. |
|
1632 |
*/ |
|
1633 |
public static boolean isLocationPropertyPlaceholder(final Object placeholder) { |
|
1634 |
return placeholder == LOCATION_PROPERTY_PLACEHOLDER; |
|
1635 |
} |
|
1636 |
||
1637 |
/** |
|
16147 | 1638 |
* Create a new RegExp object. |
1639 |
* |
|
1640 |
* @param expression Regular expression. |
|
1641 |
* @param options Search options. |
|
1642 |
* |
|
1643 |
* @return New RegExp object. |
|
1644 |
*/ |
|
1645 |
public static Object newRegExp(final String expression, final String options) { |
|
1646 |
if (options == null) { |
|
1647 |
return new NativeRegExp(expression); |
|
1648 |
} |
|
1649 |
return new NativeRegExp(expression, options); |
|
1650 |
} |
|
1651 |
||
1652 |
/** |
|
1653 |
* Get the object prototype |
|
1654 |
* |
|
1655 |
* @return the object prototype |
|
1656 |
*/ |
|
1657 |
public static ScriptObject objectPrototype() { |
|
1658 |
return Global.instance().getObjectPrototype(); |
|
1659 |
} |
|
1660 |
||
1661 |
/** |
|
1662 |
* Create a new empty object instance. |
|
1663 |
* |
|
1664 |
* @return New empty object. |
|
1665 |
*/ |
|
1666 |
public static ScriptObject newEmptyInstance() { |
|
18618
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1667 |
return Global.instance().newObject(); |
16147 | 1668 |
} |
1669 |
||
1670 |
/** |
|
1671 |
* Check if a given object is a ScriptObject, raises an exception if this is |
|
1672 |
* not the case |
|
1673 |
* |
|
1674 |
* @param obj and object to check |
|
24720 | 1675 |
* @return the script object |
16147 | 1676 |
*/ |
24720 | 1677 |
public static ScriptObject checkObject(final Object obj) { |
16147 | 1678 |
if (!(obj instanceof ScriptObject)) { |
16256
f2d9a0c49914
8007002: Replace implicit exception throwing methods with explicit throws - simplify control flow and remove useless code
lagergren
parents:
16234
diff
changeset
|
1679 |
throw typeError("not.an.object", ScriptRuntime.safeToString(obj)); |
16147 | 1680 |
} |
24720 | 1681 |
return (ScriptObject)obj; |
16147 | 1682 |
} |
1683 |
||
1684 |
/** |
|
1685 |
* ECMA 9.10 - implementation of CheckObjectCoercible, i.e. raise an exception |
|
1686 |
* if this object is null or undefined. |
|
1687 |
* |
|
1688 |
* @param obj an object to check |
|
1689 |
*/ |
|
1690 |
public static void checkObjectCoercible(final Object obj) { |
|
1691 |
if (obj == null || obj == UNDEFINED) { |
|
16256
f2d9a0c49914
8007002: Replace implicit exception throwing methods with explicit throws - simplify control flow and remove useless code
lagergren
parents:
16234
diff
changeset
|
1692 |
throw typeError("not.an.object", ScriptRuntime.safeToString(obj)); |
16147 | 1693 |
} |
1694 |
} |
|
1695 |
||
1696 |
/** |
|
1697 |
* Get the current split state. |
|
1698 |
* |
|
1699 |
* @return current split state |
|
1700 |
*/ |
|
1701 |
@Override |
|
1702 |
public int getSplitState() { |
|
1703 |
return splitState; |
|
1704 |
} |
|
1705 |
||
1706 |
/** |
|
1707 |
* Set the current split state. |
|
1708 |
* |
|
1709 |
* @param state current split state |
|
1710 |
*/ |
|
1711 |
@Override |
|
1712 |
public void setSplitState(final int state) { |
|
1713 |
splitState = state; |
|
1714 |
} |
|
1715 |
||
27814
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1716 |
/** |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1717 |
* Return the ES6 global scope for lexically declared bindings. |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1718 |
* @return the ES6 lexical global scope. |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1719 |
*/ |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1720 |
public final ScriptObject getLexicalScope() { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1721 |
assert context.getEnv()._es6; |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1722 |
return lexicalScope; |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1723 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1724 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1725 |
@Override |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1726 |
public void addBoundProperties(final ScriptObject source, final jdk.nashorn.internal.runtime.Property[] properties) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1727 |
PropertyMap ownMap = getMap(); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1728 |
LexicalScope lexicalScope = null; |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1729 |
PropertyMap lexicalMap = null; |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1730 |
boolean hasLexicalDefinitions = false; |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1731 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1732 |
if (context.getEnv()._es6) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1733 |
lexicalScope = (LexicalScope) getLexicalScope(); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1734 |
lexicalMap = lexicalScope.getMap(); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1735 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1736 |
for (final jdk.nashorn.internal.runtime.Property property : properties) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1737 |
if (property.isLexicalBinding()) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1738 |
hasLexicalDefinitions = true; |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1739 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1740 |
// ES6 15.1.8 steps 6. and 7. |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1741 |
final jdk.nashorn.internal.runtime.Property globalProperty = ownMap.findProperty(property.getKey()); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1742 |
if (globalProperty != null && !globalProperty.isConfigurable() && property.isLexicalBinding()) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1743 |
throw ECMAErrors.syntaxError("redeclare.variable", property.getKey()); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1744 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1745 |
final jdk.nashorn.internal.runtime.Property lexicalProperty = lexicalMap.findProperty(property.getKey()); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1746 |
if (lexicalProperty != null && !property.isConfigurable()) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1747 |
throw ECMAErrors.syntaxError("redeclare.variable", property.getKey()); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1748 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1749 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1750 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1751 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1752 |
for (final jdk.nashorn.internal.runtime.Property property : properties) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1753 |
if (property.isLexicalBinding()) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1754 |
assert lexicalScope != null; |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1755 |
lexicalMap = lexicalScope.addBoundProperty(lexicalMap, source, property); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1756 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1757 |
if (ownMap.findProperty(property.getKey()) != null) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1758 |
// If property exists in the global object invalidate any global constant call sites. |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1759 |
invalidateGlobalConstant(property.getKey()); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1760 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1761 |
} else { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1762 |
ownMap = addBoundProperty(ownMap, source, property); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1763 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1764 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1765 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1766 |
setMap(ownMap); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1767 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1768 |
if (hasLexicalDefinitions) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1769 |
lexicalScope.setMap(lexicalMap); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1770 |
invalidateLexicalSwitchPoint(); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1771 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1772 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1773 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1774 |
@Override |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1775 |
public GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request, final String operator) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1776 |
final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1777 |
final boolean isScope = NashornCallSiteDescriptor.isScope(desc); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1778 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1779 |
if (lexicalScope != null && isScope && !NashornCallSiteDescriptor.isApplyToCall(desc)) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1780 |
if (lexicalScope.hasOwnProperty(name)) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1781 |
return lexicalScope.findGetMethod(desc, request, operator); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1782 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1783 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1784 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1785 |
final GuardedInvocation invocation = super.findGetMethod(desc, request, operator); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1786 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1787 |
// We want to avoid adding our generic lexical scope switchpoint to global constant invocations, |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1788 |
// because those are invalidated per-key in the addBoundProperties method above. |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1789 |
// We therefor check if the invocation does already have a switchpoint and the property is non-inherited, |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1790 |
// assuming this only applies to global constants. If other non-inherited properties will |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1791 |
// start using switchpoints some time in the future we'll have to revisit this. |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1792 |
if (isScope && context.getEnv()._es6 && (invocation.getSwitchPoints() == null || !hasOwnProperty(name))) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1793 |
return invocation.addSwitchPoint(getLexicalScopeSwitchPoint()); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1794 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1795 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1796 |
return invocation; |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1797 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1798 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1799 |
@Override |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1800 |
public GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1801 |
final boolean isScope = NashornCallSiteDescriptor.isScope(desc); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1802 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1803 |
if (lexicalScope != null && isScope) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1804 |
final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1805 |
if (lexicalScope.hasOwnProperty(name)) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1806 |
return lexicalScope.findSetMethod(desc, request); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1807 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1808 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1809 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1810 |
final GuardedInvocation invocation = super.findSetMethod(desc, request); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1811 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1812 |
if (isScope && context.getEnv()._es6) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1813 |
return invocation.addSwitchPoint(getLexicalScopeSwitchPoint()); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1814 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1815 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1816 |
return invocation; |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1817 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1818 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1819 |
private synchronized SwitchPoint getLexicalScopeSwitchPoint() { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1820 |
SwitchPoint switchPoint = lexicalScopeSwitchPoint; |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1821 |
if (switchPoint == null || switchPoint.hasBeenInvalidated()) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1822 |
switchPoint = lexicalScopeSwitchPoint = new SwitchPoint(); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1823 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1824 |
return switchPoint; |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1825 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1826 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1827 |
private synchronized void invalidateLexicalSwitchPoint() { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1828 |
if (lexicalScopeSwitchPoint != null) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1829 |
context.getLogger(GlobalConstants.class).info("Invalidating non-constant globals on lexical scope update"); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1830 |
SwitchPoint.invalidateAll(new SwitchPoint[]{ lexicalScopeSwitchPoint }); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1831 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1832 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1833 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1834 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1835 |
@SuppressWarnings("unused") |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1836 |
private static Object lexicalScopeFilter(final Object self) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1837 |
if (self instanceof Global) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1838 |
return ((Global) self).getLexicalScope(); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1839 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1840 |
return self; |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1841 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1842 |
|
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1843 |
private <T extends ScriptObject> T initConstructorAndSwitchPoint(final String name, final Class<T> clazz) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1844 |
final T func = initConstructor(name, clazz); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1845 |
tagBuiltinProperties(name, func); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1846 |
return func; |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1847 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1848 |
|
27361 | 1849 |
private void init(final ScriptEngine eng) { |
16185 | 1850 |
assert Context.getGlobal() == this : "this global is not set as current"; |
1851 |
||
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
1852 |
final ScriptEnvironment env = getContext().getEnv(); |
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
1853 |
|
16147 | 1854 |
// initialize Function and Object constructor |
1855 |
initFunctionAndObject(); |
|
1856 |
||
1857 |
// Now fix Global's own proto. |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
1858 |
this.setInitialProto(getObjectPrototype()); |
16147 | 1859 |
|
1860 |
// initialize global function properties |
|
1861 |
this.eval = this.builtinEval = ScriptFunctionImpl.makeFunction("eval", EVAL); |
|
1862 |
||
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1863 |
this.parseInt = ScriptFunctionImpl.makeFunction("parseInt", GlobalFunctions.PARSEINT, |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1864 |
new Specialization[] { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1865 |
new Specialization(GlobalFunctions.PARSEINT_Z), |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1866 |
new Specialization(GlobalFunctions.PARSEINT_I), |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1867 |
new Specialization(GlobalFunctions.PARSEINT_J), |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1868 |
new Specialization(GlobalFunctions.PARSEINT_OI), |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1869 |
new Specialization(GlobalFunctions.PARSEINT_O) }); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1870 |
this.parseFloat = ScriptFunctionImpl.makeFunction("parseFloat", GlobalFunctions.PARSEFLOAT); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1871 |
this.isNaN = ScriptFunctionImpl.makeFunction("isNaN", GlobalFunctions.IS_NAN, |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1872 |
new Specialization[] { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1873 |
new Specialization(GlobalFunctions.IS_NAN_I), |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1874 |
new Specialization(GlobalFunctions.IS_NAN_J), |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1875 |
new Specialization(GlobalFunctions.IS_NAN_D) }); |
16147 | 1876 |
this.parseFloat = ScriptFunctionImpl.makeFunction("parseFloat", GlobalFunctions.PARSEFLOAT); |
1877 |
this.isNaN = ScriptFunctionImpl.makeFunction("isNaN", GlobalFunctions.IS_NAN); |
|
1878 |
this.isFinite = ScriptFunctionImpl.makeFunction("isFinite", GlobalFunctions.IS_FINITE); |
|
1879 |
this.encodeURI = ScriptFunctionImpl.makeFunction("encodeURI", GlobalFunctions.ENCODE_URI); |
|
1880 |
this.encodeURIComponent = ScriptFunctionImpl.makeFunction("encodeURIComponent", GlobalFunctions.ENCODE_URICOMPONENT); |
|
1881 |
this.decodeURI = ScriptFunctionImpl.makeFunction("decodeURI", GlobalFunctions.DECODE_URI); |
|
1882 |
this.decodeURIComponent = ScriptFunctionImpl.makeFunction("decodeURIComponent", GlobalFunctions.DECODE_URICOMPONENT); |
|
1883 |
this.escape = ScriptFunctionImpl.makeFunction("escape", GlobalFunctions.ESCAPE); |
|
1884 |
this.unescape = ScriptFunctionImpl.makeFunction("unescape", GlobalFunctions.UNESCAPE); |
|
16262
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
1885 |
this.print = ScriptFunctionImpl.makeFunction("print", env._print_no_newline ? PRINT : PRINTLN); |
16147 | 1886 |
this.load = ScriptFunctionImpl.makeFunction("load", LOAD); |
27814
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
1887 |
this.loadWithNewGlobal = ScriptFunctionImpl.makeFunction("loadWithNewGlobal", LOAD_WITH_NEW_GLOBAL); |
16219 | 1888 |
this.exit = ScriptFunctionImpl.makeFunction("exit", EXIT); |
1889 |
this.quit = ScriptFunctionImpl.makeFunction("quit", EXIT); |
|
16147 | 1890 |
|
1891 |
// built-in constructors |
|
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1892 |
this.builtinArray = initConstructorAndSwitchPoint("Array", ScriptFunction.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1893 |
this.builtinBoolean = initConstructorAndSwitchPoint("Boolean", ScriptFunction.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1894 |
this.builtinDate = initConstructorAndSwitchPoint("Date", ScriptFunction.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1895 |
this.builtinJSON = initConstructorAndSwitchPoint("JSON", ScriptObject.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1896 |
this.builtinJSAdapter = initConstructorAndSwitchPoint("JSAdapter", ScriptFunction.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1897 |
this.builtinMath = initConstructorAndSwitchPoint("Math", ScriptObject.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1898 |
this.builtinNumber = initConstructorAndSwitchPoint("Number", ScriptFunction.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1899 |
this.builtinRegExp = initConstructorAndSwitchPoint("RegExp", ScriptFunction.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
1900 |
this.builtinString = initConstructorAndSwitchPoint("String", ScriptFunction.class); |
16147 | 1901 |
|
1902 |
// initialize String.prototype.length to 0 |
|
1903 |
// add String.prototype.length |
|
1904 |
final ScriptObject stringPrototype = getStringPrototype(); |
|
1905 |
stringPrototype.addOwnProperty("length", Attribute.NON_ENUMERABLE_CONSTANT, 0.0); |
|
1906 |
||
21439
31c57355a4a7
8026805: Array.prototype.length doesn't work as expected
hannesw
parents:
20933
diff
changeset
|
1907 |
// set isArray flag on Array.prototype |
16147 | 1908 |
final ScriptObject arrayPrototype = getArrayPrototype(); |
21439
31c57355a4a7
8026805: Array.prototype.length doesn't work as expected
hannesw
parents:
20933
diff
changeset
|
1909 |
arrayPrototype.setIsArray(); |
16147 | 1910 |
|
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
1911 |
this.DEFAULT_DATE = new NativeDate(Double.NaN, this); |
16147 | 1912 |
|
1913 |
// initialize default regexp object |
|
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
1914 |
this.DEFAULT_REGEXP = new NativeRegExp("(?:)", this); |
16147 | 1915 |
|
1916 |
// RegExp.prototype should behave like a RegExp object. So copy the |
|
1917 |
// properties. |
|
1918 |
final ScriptObject regExpProto = getRegExpPrototype(); |
|
1919 |
regExpProto.addBoundProperties(DEFAULT_REGEXP); |
|
1920 |
||
1921 |
// Error stuff |
|
1922 |
initErrorObjects(); |
|
1923 |
||
1924 |
// java access |
|
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18851
diff
changeset
|
1925 |
if (! env._no_java) { |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18851
diff
changeset
|
1926 |
initJavaAccess(); |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18851
diff
changeset
|
1927 |
} |
16147 | 1928 |
|
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18851
diff
changeset
|
1929 |
if (! env._no_typed_arrays) { |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18851
diff
changeset
|
1930 |
initTypedArray(); |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18851
diff
changeset
|
1931 |
} |
16147 | 1932 |
|
16262
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
1933 |
if (env._scripting) { |
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18851
diff
changeset
|
1934 |
initScripting(env); |
16147 | 1935 |
} |
1936 |
||
22389
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1937 |
if (Context.DEBUG) { |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1938 |
boolean debugOkay; |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1939 |
final SecurityManager sm = System.getSecurityManager(); |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1940 |
if (sm != null) { |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1941 |
try { |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1942 |
sm.checkPermission(new RuntimePermission(Context.NASHORN_DEBUG_MODE)); |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1943 |
debugOkay = true; |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1944 |
} catch (final SecurityException ignored) { |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1945 |
// if no permission, don't initialize Debug object |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1946 |
debugOkay = false; |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1947 |
} |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1948 |
|
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1949 |
} else { |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1950 |
debugOkay = true; |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1951 |
} |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1952 |
|
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1953 |
if (debugOkay) { |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1954 |
initDebug(); |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1955 |
} |
16147 | 1956 |
} |
1957 |
||
1958 |
copyBuiltins(); |
|
1959 |
||
1960 |
// expose script (command line) arguments as "arguments" property of global |
|
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
1961 |
arguments = wrapAsObject(env.getArguments().toArray()); |
16262
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
1962 |
if (env._scripting) { |
16147 | 1963 |
// synonym for "arguments" in scripting mode |
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
1964 |
addOwnProperty("$ARG", Attribute.NOT_ENUMERABLE, arguments); |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
1965 |
} |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
1966 |
|
27361 | 1967 |
if (eng != null) { |
25585
0968d8ab046a
8050432: javax.script.filename variable should not be enumerable with nashorn engine's ENGINE_SCOPE bindings
sundar
parents:
25423
diff
changeset
|
1968 |
// default file name |
0968d8ab046a
8050432: javax.script.filename variable should not be enumerable with nashorn engine's ENGINE_SCOPE bindings
sundar
parents:
25423
diff
changeset
|
1969 |
addOwnProperty(ScriptEngine.FILENAME, Attribute.NOT_ENUMERABLE, null); |
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
1970 |
// __noSuchProperty__ hook for ScriptContext search of missing variables |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
1971 |
final ScriptFunction noSuchProp = ScriptFunctionImpl.makeStrictFunction(NO_SUCH_PROPERTY_NAME, NO_SUCH_PROPERTY); |
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
1972 |
addOwnProperty(NO_SUCH_PROPERTY_NAME, Attribute.NOT_ENUMERABLE, noSuchProp); |
16147 | 1973 |
} |
1974 |
} |
|
1975 |
||
1976 |
private void initErrorObjects() { |
|
1977 |
// Error objects |
|
26056
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
1978 |
this.builtinError = initConstructor("Error", ScriptFunction.class); |
16147 | 1979 |
final ScriptObject errorProto = getErrorPrototype(); |
1980 |
||
1981 |
// Nashorn specific accessors on Error.prototype - stack, lineNumber, columnNumber and fileName |
|
1982 |
final ScriptFunction getStack = ScriptFunctionImpl.makeFunction("getStack", NativeError.GET_STACK); |
|
1983 |
final ScriptFunction setStack = ScriptFunctionImpl.makeFunction("setStack", NativeError.SET_STACK); |
|
1984 |
errorProto.addOwnProperty("stack", Attribute.NOT_ENUMERABLE, getStack, setStack); |
|
1985 |
final ScriptFunction getLineNumber = ScriptFunctionImpl.makeFunction("getLineNumber", NativeError.GET_LINENUMBER); |
|
1986 |
final ScriptFunction setLineNumber = ScriptFunctionImpl.makeFunction("setLineNumber", NativeError.SET_LINENUMBER); |
|
1987 |
errorProto.addOwnProperty("lineNumber", Attribute.NOT_ENUMERABLE, getLineNumber, setLineNumber); |
|
1988 |
final ScriptFunction getColumnNumber = ScriptFunctionImpl.makeFunction("getColumnNumber", NativeError.GET_COLUMNNUMBER); |
|
1989 |
final ScriptFunction setColumnNumber = ScriptFunctionImpl.makeFunction("setColumnNumber", NativeError.SET_COLUMNNUMBER); |
|
1990 |
errorProto.addOwnProperty("columnNumber", Attribute.NOT_ENUMERABLE, getColumnNumber, setColumnNumber); |
|
1991 |
final ScriptFunction getFileName = ScriptFunctionImpl.makeFunction("getFileName", NativeError.GET_FILENAME); |
|
1992 |
final ScriptFunction setFileName = ScriptFunctionImpl.makeFunction("setFileName", NativeError.SET_FILENAME); |
|
1993 |
errorProto.addOwnProperty("fileName", Attribute.NOT_ENUMERABLE, getFileName, setFileName); |
|
1994 |
||
1995 |
// ECMA 15.11.4.2 Error.prototype.name |
|
1996 |
// Error.prototype.name = "Error"; |
|
26765
97501edd2979
8047764: Indexed or polymorphic set on global affects Object.prototype
hannesw
parents:
26647
diff
changeset
|
1997 |
errorProto.set(NativeError.NAME, "Error", 0); |
16147 | 1998 |
// ECMA 15.11.4.3 Error.prototype.message |
1999 |
// Error.prototype.message = ""; |
|
26765
97501edd2979
8047764: Indexed or polymorphic set on global affects Object.prototype
hannesw
parents:
26647
diff
changeset
|
2000 |
errorProto.set(NativeError.MESSAGE, "", 0); |
16147 | 2001 |
|
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2002 |
tagBuiltinProperties("Error", builtinError); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2003 |
|
16147 | 2004 |
this.builtinEvalError = initErrorSubtype("EvalError", errorProto); |
2005 |
this.builtinRangeError = initErrorSubtype("RangeError", errorProto); |
|
2006 |
this.builtinReferenceError = initErrorSubtype("ReferenceError", errorProto); |
|
2007 |
this.builtinSyntaxError = initErrorSubtype("SyntaxError", errorProto); |
|
2008 |
this.builtinTypeError = initErrorSubtype("TypeError", errorProto); |
|
2009 |
this.builtinURIError = initErrorSubtype("URIError", errorProto); |
|
2010 |
} |
|
2011 |
||
2012 |
private ScriptFunction initErrorSubtype(final String name, final ScriptObject errorProto) { |
|
26056
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
2013 |
final ScriptFunction cons = initConstructor(name, ScriptFunction.class); |
16147 | 2014 |
final ScriptObject prototype = ScriptFunction.getPrototype(cons); |
26765
97501edd2979
8047764: Indexed or polymorphic set on global affects Object.prototype
hannesw
parents:
26647
diff
changeset
|
2015 |
prototype.set(NativeError.NAME, name, 0); |
97501edd2979
8047764: Indexed or polymorphic set on global affects Object.prototype
hannesw
parents:
26647
diff
changeset
|
2016 |
prototype.set(NativeError.MESSAGE, "", 0); |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
2017 |
prototype.setInitialProto(errorProto); |
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2018 |
tagBuiltinProperties(name, cons); |
26056
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
2019 |
return cons; |
16147 | 2020 |
} |
2021 |
||
2022 |
private void initJavaAccess() { |
|
2023 |
final ScriptObject objectProto = getObjectPrototype(); |
|
2024 |
this.builtinPackages = new NativeJavaPackage("", objectProto); |
|
16532 | 2025 |
this.builtinCom = new NativeJavaPackage("com", objectProto); |
2026 |
this.builtinEdu = new NativeJavaPackage("edu", objectProto); |
|
16147 | 2027 |
this.builtinJava = new NativeJavaPackage("java", objectProto); |
16532 | 2028 |
this.builtinJavafx = new NativeJavaPackage("javafx", objectProto); |
16147 | 2029 |
this.builtinJavax = new NativeJavaPackage("javax", objectProto); |
16532 | 2030 |
this.builtinOrg = new NativeJavaPackage("org", objectProto); |
26056
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
2031 |
this.builtinJavaImporter = initConstructor("JavaImporter", ScriptFunction.class); |
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
2032 |
this.builtinJavaApi = initConstructor("Java", ScriptObject.class); |
16147 | 2033 |
} |
2034 |
||
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18851
diff
changeset
|
2035 |
private void initScripting(final ScriptEnvironment scriptEnv) { |
16147 | 2036 |
Object value; |
2037 |
value = ScriptFunctionImpl.makeFunction("readLine", ScriptingFunctions.READLINE); |
|
2038 |
addOwnProperty("readLine", Attribute.NOT_ENUMERABLE, value); |
|
2039 |
||
16196
58f6f046bb5e
8006983: Introduce a command line option to switch off syntactic extensions of nashorn
sundar
parents:
16195
diff
changeset
|
2040 |
value = ScriptFunctionImpl.makeFunction("readFully", ScriptingFunctions.READFULLY); |
58f6f046bb5e
8006983: Introduce a command line option to switch off syntactic extensions of nashorn
sundar
parents:
16195
diff
changeset
|
2041 |
addOwnProperty("readFully", Attribute.NOT_ENUMERABLE, value); |
16147 | 2042 |
|
16211 | 2043 |
final String execName = ScriptingFunctions.EXEC_NAME; |
2044 |
value = ScriptFunctionImpl.makeFunction(execName, ScriptingFunctions.EXEC); |
|
2045 |
addOwnProperty(execName, Attribute.NOT_ENUMERABLE, value); |
|
2046 |
||
16147 | 2047 |
// Nashorn extension: global.echo (scripting-mode-only) |
2048 |
// alias for "print" |
|
2049 |
value = get("print"); |
|
2050 |
addOwnProperty("echo", Attribute.NOT_ENUMERABLE, value); |
|
2051 |
||
2052 |
// Nashorn extension: global.$OPTIONS (scripting-mode-only) |
|
18618
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
2053 |
final ScriptObject options = newObject(); |
16522 | 2054 |
copyOptions(options, scriptEnv); |
2055 |
addOwnProperty("$OPTIONS", Attribute.NOT_ENUMERABLE, options); |
|
16211 | 2056 |
|
2057 |
// Nashorn extension: global.$ENV (scripting-mode-only) |
|
16213
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
2058 |
if (System.getSecurityManager() == null) { |
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
2059 |
// do not fill $ENV if we have a security manager around |
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
2060 |
// Retrieve current state of ENV variables. |
18618
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
2061 |
final ScriptObject env = newObject(); |
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
2062 |
env.putAll(System.getenv(), scriptEnv._strict); |
16213
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
2063 |
addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, env); |
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
2064 |
} else { |
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
2065 |
addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED); |
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
2066 |
} |
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
2067 |
|
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
2068 |
// add other special properties for exec support |
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
2069 |
addOwnProperty(ScriptingFunctions.OUT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED); |
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
2070 |
addOwnProperty(ScriptingFunctions.ERR_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED); |
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
2071 |
addOwnProperty(ScriptingFunctions.EXIT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED); |
16147 | 2072 |
} |
2073 |
||
16525
1409942e618e
8009982: Lazy execution bugfix. Added lazy sunspider unit test. Added mandreel to compile-octane test. Fixed warnings
lagergren
parents:
16522
diff
changeset
|
2074 |
private static void copyOptions(final ScriptObject options, final ScriptEnvironment scriptEnv) { |
24720 | 2075 |
for (final Field f : scriptEnv.getClass().getFields()) { |
19459 | 2076 |
try { |
26765
97501edd2979
8047764: Indexed or polymorphic set on global affects Object.prototype
hannesw
parents:
26647
diff
changeset
|
2077 |
options.set(f.getName(), f.get(scriptEnv), 0); |
19459 | 2078 |
} catch (final IllegalArgumentException | IllegalAccessException exp) { |
2079 |
throw new RuntimeException(exp); |
|
16522 | 2080 |
} |
19459 | 2081 |
} |
16522 | 2082 |
} |
2083 |
||
16147 | 2084 |
private void initTypedArray() { |
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2085 |
this.builtinArrayBuffer = initConstructorAndSwitchPoint("ArrayBuffer", ScriptFunction.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2086 |
this.builtinDataView = initConstructorAndSwitchPoint("DataView", ScriptFunction.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2087 |
this.builtinInt8Array = initConstructorAndSwitchPoint("Int8Array", ScriptFunction.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2088 |
this.builtinUint8Array = initConstructorAndSwitchPoint("Uint8Array", ScriptFunction.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2089 |
this.builtinUint8ClampedArray = initConstructorAndSwitchPoint("Uint8ClampedArray", ScriptFunction.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2090 |
this.builtinInt16Array = initConstructorAndSwitchPoint("Int16Array", ScriptFunction.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2091 |
this.builtinUint16Array = initConstructorAndSwitchPoint("Uint16Array", ScriptFunction.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2092 |
this.builtinInt32Array = initConstructorAndSwitchPoint("Int32Array", ScriptFunction.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2093 |
this.builtinUint32Array = initConstructorAndSwitchPoint("Uint32Array", ScriptFunction.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2094 |
this.builtinFloat32Array = initConstructorAndSwitchPoint("Float32Array", ScriptFunction.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2095 |
this.builtinFloat64Array = initConstructorAndSwitchPoint("Float64Array", ScriptFunction.class); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2096 |
|
16147 | 2097 |
} |
2098 |
||
2099 |
private void copyBuiltins() { |
|
2100 |
this.array = this.builtinArray; |
|
2101 |
this._boolean = this.builtinBoolean; |
|
2102 |
this.date = this.builtinDate; |
|
2103 |
this.error = this.builtinError; |
|
2104 |
this.evalError = this.builtinEvalError; |
|
2105 |
this.function = this.builtinFunction; |
|
2106 |
this.jsadapter = this.builtinJSAdapter; |
|
2107 |
this.json = this.builtinJSON; |
|
16532 | 2108 |
this.com = this.builtinCom; |
2109 |
this.edu = this.builtinEdu; |
|
16147 | 2110 |
this.java = this.builtinJava; |
16532 | 2111 |
this.javafx = this.builtinJavafx; |
16147 | 2112 |
this.javax = this.builtinJavax; |
16532 | 2113 |
this.org = this.builtinOrg; |
16147 | 2114 |
this.javaImporter = this.builtinJavaImporter; |
2115 |
this.javaApi = this.builtinJavaApi; |
|
2116 |
this.math = this.builtinMath; |
|
2117 |
this.number = this.builtinNumber; |
|
2118 |
this.object = this.builtinObject; |
|
2119 |
this.packages = this.builtinPackages; |
|
2120 |
this.rangeError = this.builtinRangeError; |
|
2121 |
this.referenceError = this.builtinReferenceError; |
|
2122 |
this.regexp = this.builtinRegExp; |
|
2123 |
this.string = this.builtinString; |
|
2124 |
this.syntaxError = this.builtinSyntaxError; |
|
2125 |
this.typeError = this.builtinTypeError; |
|
2126 |
this.uriError = this.builtinURIError; |
|
2127 |
this.arrayBuffer = this.builtinArrayBuffer; |
|
23374 | 2128 |
this.dataView = this.builtinDataView; |
16147 | 2129 |
this.int8Array = this.builtinInt8Array; |
2130 |
this.uint8Array = this.builtinUint8Array; |
|
2131 |
this.uint8ClampedArray = this.builtinUint8ClampedArray; |
|
2132 |
this.int16Array = this.builtinInt16Array; |
|
2133 |
this.uint16Array = this.builtinUint16Array; |
|
2134 |
this.int32Array = this.builtinInt32Array; |
|
2135 |
this.uint32Array = this.builtinUint32Array; |
|
2136 |
this.float32Array = this.builtinFloat32Array; |
|
2137 |
this.float64Array = this.builtinFloat64Array; |
|
2138 |
} |
|
2139 |
||
2140 |
private void initDebug() { |
|
26056
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
2141 |
this.addOwnProperty("Debug", Attribute.NOT_ENUMERABLE, initConstructor("Debug", ScriptObject.class)); |
16147 | 2142 |
} |
2143 |
||
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
2144 |
private Object printImpl(final boolean newLine, final Object... objects) { |
25821
fbb51e67d2a7
8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents:
25585
diff
changeset
|
2145 |
@SuppressWarnings("resource") |
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
2146 |
final PrintWriter out = scontext != null? new PrintWriter(scontext.getWriter()) : getContext().getEnv().getOut(); |
17972 | 2147 |
final StringBuilder sb = new StringBuilder(); |
16147 | 2148 |
|
25821
fbb51e67d2a7
8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents:
25585
diff
changeset
|
2149 |
for (final Object obj : objects) { |
17972 | 2150 |
if (sb.length() != 0) { |
2151 |
sb.append(' '); |
|
16147 | 2152 |
} |
2153 |
||
25821
fbb51e67d2a7
8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents:
25585
diff
changeset
|
2154 |
sb.append(JSType.toString(obj)); |
16147 | 2155 |
} |
2156 |
||
17972 | 2157 |
// Print all at once to ensure thread friendly result. |
16147 | 2158 |
if (newLine) { |
17972 | 2159 |
out.println(sb.toString()); |
2160 |
} else { |
|
2161 |
out.print(sb.toString()); |
|
16147 | 2162 |
} |
2163 |
||
2164 |
out.flush(); |
|
2165 |
||
2166 |
return UNDEFINED; |
|
2167 |
} |
|
2168 |
||
26056
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
2169 |
private <T extends ScriptObject> T initConstructor(final String name, final Class<T> clazz) { |
16147 | 2170 |
try { |
2171 |
// Assuming class name pattern for built-in JS constructors. |
|
2172 |
final StringBuilder sb = new StringBuilder("jdk.nashorn.internal.objects."); |
|
2173 |
||
2174 |
sb.append("Native"); |
|
2175 |
sb.append(name); |
|
2176 |
sb.append("$Constructor"); |
|
2177 |
||
26056
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
2178 |
final Class<?> funcClass = Class.forName(sb.toString()); |
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
2179 |
final T res = clazz.cast(funcClass.newInstance()); |
16147 | 2180 |
|
2181 |
if (res instanceof ScriptFunction) { |
|
2182 |
// All global constructor prototypes are not-writable, |
|
2183 |
// not-enumerable and not-configurable. |
|
2184 |
final ScriptFunction func = (ScriptFunction)res; |
|
2185 |
func.modifyOwnProperty(func.getProperty("prototype"), Attribute.NON_ENUMERABLE_CONSTANT); |
|
2186 |
} |
|
2187 |
||
2188 |
if (res.getProto() == null) { |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
2189 |
res.setInitialProto(getObjectPrototype()); |
16147 | 2190 |
} |
2191 |
||
24733
1e825be55fd1
8027043: Turn global accesses into MethodHandle.constant, with one chance of reassignment, e.g. x = value occuring once in the global scope is ok, twice is not.
lagergren
parents:
24731
diff
changeset
|
2192 |
res.setIsBuiltin(); |
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2193 |
|
16147 | 2194 |
return res; |
2195 |
} catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) { |
|
2196 |
throw new RuntimeException(e); |
|
2197 |
} |
|
2198 |
} |
|
2199 |
||
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2200 |
private List<jdk.nashorn.internal.runtime.Property> extractBuiltinProperties(final String name, final ScriptObject func) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2201 |
final List<jdk.nashorn.internal.runtime.Property> list = new ArrayList<>(); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2202 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2203 |
list.addAll(Arrays.asList(func.getMap().getProperties())); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2204 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2205 |
if (func instanceof ScriptFunction) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2206 |
final ScriptObject proto = ScriptFunction.getPrototype((ScriptFunction)func); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2207 |
if (proto != null) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2208 |
list.addAll(Arrays.asList(proto.getMap().getProperties())); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2209 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2210 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2211 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2212 |
final jdk.nashorn.internal.runtime.Property prop = getProperty(name); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2213 |
if (prop != null) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2214 |
list.add(prop); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2215 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2216 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2217 |
return list; |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2218 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2219 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2220 |
/** |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2221 |
* Given a builtin object, traverse its properties recursively and associate them with a name that |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2222 |
* will be a key to their invalidation switchpoint. |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2223 |
* @param name name for key |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2224 |
* @param func builtin script object |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2225 |
*/ |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2226 |
private void tagBuiltinProperties(final String name, final ScriptObject func) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2227 |
SwitchPoint sp = context.getBuiltinSwitchPoint(name); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2228 |
if (sp == null) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2229 |
sp = context.newBuiltinSwitchPoint(name); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2230 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2231 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2232 |
//get all builtin properties in this builtin object and register switchpoints keyed on the propery name, |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2233 |
//one overwrite destroys all for now, e.g. Function.prototype.apply = 17; also destroys Function.prototype.call etc |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2234 |
for (final jdk.nashorn.internal.runtime.Property prop : extractBuiltinProperties(name, func)) { |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2235 |
prop.setBuiltinSwitchPoint(sp); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2236 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2237 |
} |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2238 |
|
16147 | 2239 |
// Function and Object constructors are inter-dependent. Also, |
2240 |
// Function.prototype |
|
2241 |
// functions are not properly initialized. We fix the references here. |
|
2242 |
// NOTE: be careful if you want to re-order the operations here. You may |
|
2243 |
// have |
|
2244 |
// to play with object references carefully!! |
|
2245 |
private void initFunctionAndObject() { |
|
2246 |
// First-n-foremost is Function |
|
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2247 |
|
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2248 |
this.builtinFunction = initConstructor("Function", ScriptFunction.class); |
16147 | 2249 |
|
2250 |
// create global anonymous function |
|
24751 | 2251 |
final ScriptFunction anon = ScriptFunctionImpl.newAnonymousFunction(); |
16147 | 2252 |
// need to copy over members of Function.prototype to anon function |
2253 |
anon.addBoundProperties(getFunctionPrototype()); |
|
2254 |
||
2255 |
// Function.prototype === Object.getPrototypeOf(Function) === |
|
2256 |
// <anon-function> |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
2257 |
builtinFunction.setInitialProto(anon); |
16147 | 2258 |
builtinFunction.setPrototype(anon); |
26765
97501edd2979
8047764: Indexed or polymorphic set on global affects Object.prototype
hannesw
parents:
26647
diff
changeset
|
2259 |
anon.set("constructor", builtinFunction, 0); |
16147 | 2260 |
anon.deleteOwnProperty(anon.getMap().findProperty("prototype")); |
2261 |
||
22382
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
2262 |
// use "getter" so that [[ThrowTypeError]] function's arity is 0 - as specified in step 10 of section 13.2.3 |
23372
09707b3e5fb0
8021350: Share script classes between threads/globals within context
hannesw
parents:
23084
diff
changeset
|
2263 |
this.typeErrorThrower = new ScriptFunctionImpl("TypeErrorThrower", Lookup.TYPE_ERROR_THROWER_GETTER, null, null, 0); |
22382
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
2264 |
typeErrorThrower.setPrototype(UNDEFINED); |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
2265 |
// Non-constructor built-in functions do not have "prototype" property |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
2266 |
typeErrorThrower.deleteOwnProperty(typeErrorThrower.getMap().findProperty("prototype")); |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
2267 |
typeErrorThrower.preventExtensions(); |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
2268 |
|
16147 | 2269 |
// now initialize Object |
26056
a64f0cd60e66
8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types
sundar
parents:
25821
diff
changeset
|
2270 |
this.builtinObject = initConstructor("Object", ScriptFunction.class); |
16147 | 2271 |
final ScriptObject ObjectPrototype = getObjectPrototype(); |
2272 |
// Object.getPrototypeOf(Function.prototype) === Object.prototype |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
2273 |
anon.setInitialProto(ObjectPrototype); |
16147 | 2274 |
|
24281 | 2275 |
// ES6 draft compliant __proto__ property of Object.prototype |
2276 |
// accessors on Object.prototype for "__proto__" |
|
24772
0fc1013a1785
8044520: Nashorn cannot execute node.js's express module
sundar
parents:
24769
diff
changeset
|
2277 |
final ScriptFunction getProto = ScriptFunctionImpl.makeFunction("getProto", NativeObject.GET__PROTO__); |
0fc1013a1785
8044520: Nashorn cannot execute node.js's express module
sundar
parents:
24769
diff
changeset
|
2278 |
final ScriptFunction setProto = ScriptFunctionImpl.makeFunction("setProto", NativeObject.SET__PROTO__); |
24281 | 2279 |
ObjectPrototype.addOwnProperty("__proto__", Attribute.NOT_ENUMERABLE, getProto, setProto); |
2280 |
||
16147 | 2281 |
// Function valued properties of Function.prototype were not properly |
2282 |
// initialized. Because, these were created before global.function and |
|
2283 |
// global.object were not initialized. |
|
2284 |
jdk.nashorn.internal.runtime.Property[] properties = getFunctionPrototype().getMap().getProperties(); |
|
2285 |
for (final jdk.nashorn.internal.runtime.Property property : properties) { |
|
2286 |
final Object key = property.getKey(); |
|
2287 |
final Object value = builtinFunction.get(key); |
|
2288 |
||
2289 |
if (value instanceof ScriptFunction && value != anon) { |
|
2290 |
final ScriptFunction func = (ScriptFunction)value; |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
2291 |
func.setInitialProto(getFunctionPrototype()); |
16147 | 2292 |
final ScriptObject prototype = ScriptFunction.getPrototype(func); |
2293 |
if (prototype != null) { |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
2294 |
prototype.setInitialProto(ObjectPrototype); |
16147 | 2295 |
} |
2296 |
} |
|
2297 |
} |
|
2298 |
||
2299 |
// For function valued properties of Object and Object.prototype, make |
|
2300 |
// sure prototype's proto chain ends with Object.prototype |
|
2301 |
for (final jdk.nashorn.internal.runtime.Property property : builtinObject.getMap().getProperties()) { |
|
2302 |
final Object key = property.getKey(); |
|
2303 |
final Object value = builtinObject.get(key); |
|
2304 |
||
2305 |
if (value instanceof ScriptFunction) { |
|
2306 |
final ScriptFunction func = (ScriptFunction)value; |
|
2307 |
final ScriptObject prototype = ScriptFunction.getPrototype(func); |
|
2308 |
if (prototype != null) { |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
2309 |
prototype.setInitialProto(ObjectPrototype); |
16147 | 2310 |
} |
2311 |
} |
|
2312 |
} |
|
2313 |
||
2314 |
properties = getObjectPrototype().getMap().getProperties(); |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2315 |
|
16147 | 2316 |
for (final jdk.nashorn.internal.runtime.Property property : properties) { |
2317 |
final Object key = property.getKey(); |
|
2318 |
if (key.equals("constructor")) { |
|
2319 |
continue; |
|
2320 |
} |
|
2321 |
||
25422
199a23bee487
8049524: Global object initialization via javax.script API should be minimal
sundar
parents:
25421
diff
changeset
|
2322 |
final Object value = ObjectPrototype.get(key); |
16147 | 2323 |
if (value instanceof ScriptFunction) { |
2324 |
final ScriptFunction func = (ScriptFunction)value; |
|
2325 |
final ScriptObject prototype = ScriptFunction.getPrototype(func); |
|
2326 |
if (prototype != null) { |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
2327 |
prototype.setInitialProto(ObjectPrototype); |
16147 | 2328 |
} |
2329 |
} |
|
2330 |
} |
|
2331 |
||
26768
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2332 |
tagBuiltinProperties("Object", builtinObject); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2333 |
tagBuiltinProperties("Function", builtinFunction); |
751b0f427090
8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents:
26765
diff
changeset
|
2334 |
tagBuiltinProperties("Function", anon); |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2335 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2336 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2337 |
private static MethodHandle findOwnMH_S(final String name, final Class<?> rtype, final Class<?>... types) { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
2338 |
return MH.findStatic(MethodHandles.lookup(), Global.class, name, MH.type(rtype, types)); |
16147 | 2339 |
} |
16223
dff592a332a4
8007718: Make static RegExp properties fully compatible to other engines
hannesw
parents:
16219
diff
changeset
|
2340 |
|
16258 | 2341 |
RegExpResult getLastRegExpResult() { |
2342 |
return lastRegExpResult; |
|
16223
dff592a332a4
8007718: Make static RegExp properties fully compatible to other engines
hannesw
parents:
16219
diff
changeset
|
2343 |
} |
dff592a332a4
8007718: Make static RegExp properties fully compatible to other engines
hannesw
parents:
16219
diff
changeset
|
2344 |
|
16258 | 2345 |
void setLastRegExpResult(final RegExpResult regExpResult) { |
2346 |
this.lastRegExpResult = regExpResult; |
|
16223
dff592a332a4
8007718: Make static RegExp properties fully compatible to other engines
hannesw
parents:
16219
diff
changeset
|
2347 |
} |
dff592a332a4
8007718: Make static RegExp properties fully compatible to other engines
hannesw
parents:
16219
diff
changeset
|
2348 |
|
24733
1e825be55fd1
8027043: Turn global accesses into MethodHandle.constant, with one chance of reassignment, e.g. x = value occuring once in the global scope is ok, twice is not.
lagergren
parents:
24731
diff
changeset
|
2349 |
@Override |
1e825be55fd1
8027043: Turn global accesses into MethodHandle.constant, with one chance of reassignment, e.g. x = value occuring once in the global scope is ok, twice is not.
lagergren
parents:
24731
diff
changeset
|
2350 |
protected boolean isGlobal() { |
1e825be55fd1
8027043: Turn global accesses into MethodHandle.constant, with one chance of reassignment, e.g. x = value occuring once in the global scope is ok, twice is not.
lagergren
parents:
24731
diff
changeset
|
2351 |
return true; |
1e825be55fd1
8027043: Turn global accesses into MethodHandle.constant, with one chance of reassignment, e.g. x = value occuring once in the global scope is ok, twice is not.
lagergren
parents:
24731
diff
changeset
|
2352 |
} |
27814
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2353 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2354 |
/** |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2355 |
* A class representing the ES6 global lexical scope. |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2356 |
*/ |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2357 |
private static class LexicalScope extends ScriptObject { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2358 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2359 |
LexicalScope(final ScriptObject proto) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2360 |
super(proto, PropertyMap.newMap()); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2361 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2362 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2363 |
@Override |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2364 |
protected GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request, final String operator) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2365 |
return filterInvocation(super.findGetMethod(desc, request, operator)); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2366 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2367 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2368 |
@Override |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2369 |
protected GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final LinkRequest request) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2370 |
return filterInvocation(super.findSetMethod(desc, request)); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2371 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2372 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2373 |
@Override |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2374 |
protected PropertyMap addBoundProperty(final PropertyMap propMap, final ScriptObject source, final jdk.nashorn.internal.runtime.Property property) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2375 |
// We override this method just to make it callable by Global |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2376 |
return super.addBoundProperty(propMap, source, property); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2377 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2378 |
|
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2379 |
private static GuardedInvocation filterInvocation(final GuardedInvocation invocation) { |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2380 |
final MethodType type = invocation.getInvocation().type(); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2381 |
return invocation.asType(type.changeParameterType(0, Object.class)).filterArguments(0, LEXICAL_SCOPE_FILTER); |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2382 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2383 |
} |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
27369
diff
changeset
|
2384 |
|
16147 | 2385 |
} |