author | sundar |
Tue, 24 Jun 2014 19:43:44 +0530 | |
changeset 25240 | f92c14b1ca11 |
parent 24772 | 0fc1013a1785 |
child 25421 | a1df2de833a2 |
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 |
||
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
28 |
import static jdk.nashorn.internal.codegen.CompilerConstants.staticCall; |
18610 | 29 |
import static jdk.nashorn.internal.lookup.Lookup.MH; |
16147 | 30 |
import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; |
31 |
import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; |
|
32 |
||
33 |
import java.io.IOException; |
|
34 |
import java.io.PrintWriter; |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
35 |
import java.lang.invoke.CallSite; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
36 |
import java.lang.invoke.ConstantCallSite; |
16147 | 37 |
import java.lang.invoke.MethodHandle; |
38 |
import java.lang.invoke.MethodHandles; |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
39 |
import java.lang.invoke.MethodType; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
40 |
import java.lang.invoke.SwitchPoint; |
16522 | 41 |
import java.lang.reflect.Field; |
18326
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
42 |
import java.util.Arrays; |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
43 |
import java.util.HashMap; |
16147 | 44 |
import java.util.Map; |
19456
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
45 |
import java.util.concurrent.Callable; |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
46 |
import java.util.concurrent.ConcurrentHashMap; |
24745
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
47 |
import java.util.concurrent.atomic.AtomicReference; |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
16233
diff
changeset
|
48 |
import jdk.internal.dynalink.linker.GuardedInvocation; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
16233
diff
changeset
|
49 |
import jdk.internal.dynalink.linker.LinkRequest; |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
50 |
import jdk.nashorn.internal.codegen.ApplySpecialization; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
51 |
import jdk.nashorn.internal.codegen.CompilerConstants.Call; |
22382
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
52 |
import jdk.nashorn.internal.lookup.Lookup; |
16147 | 53 |
import jdk.nashorn.internal.objects.annotations.Attribute; |
54 |
import jdk.nashorn.internal.objects.annotations.Property; |
|
55 |
import jdk.nashorn.internal.objects.annotations.ScriptClass; |
|
56 |
import jdk.nashorn.internal.runtime.ConsString; |
|
57 |
import jdk.nashorn.internal.runtime.Context; |
|
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
|
58 |
import jdk.nashorn.internal.runtime.GlobalConstants; |
16147 | 59 |
import jdk.nashorn.internal.runtime.GlobalFunctions; |
60 |
import jdk.nashorn.internal.runtime.JSType; |
|
61 |
import jdk.nashorn.internal.runtime.NativeJavaPackage; |
|
21686
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21439
diff
changeset
|
62 |
import jdk.nashorn.internal.runtime.PropertyDescriptor; |
18618
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
63 |
import jdk.nashorn.internal.runtime.PropertyMap; |
21686
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21439
diff
changeset
|
64 |
import jdk.nashorn.internal.runtime.Scope; |
16262
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
65 |
import jdk.nashorn.internal.runtime.ScriptEnvironment; |
16147 | 66 |
import jdk.nashorn.internal.runtime.ScriptFunction; |
67 |
import jdk.nashorn.internal.runtime.ScriptObject; |
|
68 |
import jdk.nashorn.internal.runtime.ScriptRuntime; |
|
69 |
import jdk.nashorn.internal.runtime.ScriptingFunctions; |
|
21686
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21439
diff
changeset
|
70 |
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
|
71 |
import jdk.nashorn.internal.runtime.linker.Bootstrap; |
16147 | 72 |
import jdk.nashorn.internal.runtime.linker.InvokeByName; |
21686
5c6946f97d6f
8027236: Ensure ScriptObject and ConsString aren't visible to Java
attila
parents:
21439
diff
changeset
|
73 |
import jdk.nashorn.internal.runtime.regexp.RegExpResult; |
16275 | 74 |
import jdk.nashorn.internal.scripts.JO; |
16147 | 75 |
|
76 |
/** |
|
77 |
* Representation of global scope. |
|
78 |
*/ |
|
79 |
@ScriptClass("Global") |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
80 |
public final class Global extends ScriptObject implements Scope { |
24719 | 81 |
// Placeholder value used in place of a location property (__FILE__, __DIR__, __LINE__) |
82 |
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
|
83 |
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
|
84 |
private final InvokeByName VALUE_OF = new InvokeByName("valueOf", ScriptObject.class); |
16147 | 85 |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
86 |
/** |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
87 |
* Optimistic builtin names that require switchpoint invalidation |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
88 |
* 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
|
89 |
* 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
|
90 |
* like |
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 |
* <pre> |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
93 |
* public boolean setterGuard(final Object receiver) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
94 |
* final Global global = Global.instance(); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
95 |
* final ScriptObject sobj = global.getFunctionPrototype(); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
96 |
* final Object apply = sobj.get("apply"); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
97 |
* return apply == receiver; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
98 |
* } |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
99 |
* </pre> |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
100 |
* |
24751 | 101 |
* 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
|
102 |
* 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
|
103 |
* problems with guard speed. |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
104 |
*/ |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
105 |
public final Map<String, SwitchPoint> optimisticFunctionMap; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
106 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
107 |
/** Name invalidator for things like call/apply */ |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
108 |
public static final Call BOOTSTRAP = staticCall(MethodHandles.lookup(), Global.class, "invalidateNameBootstrap", CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
109 |
|
16147 | 110 |
/** ECMA 15.1.2.2 parseInt (string , radix) */ |
111 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
112 |
public Object parseInt; |
|
113 |
||
114 |
/** ECMA 15.1.2.3 parseFloat (string) */ |
|
115 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
116 |
public Object parseFloat; |
|
117 |
||
118 |
/** ECMA 15.1.2.4 isNaN (number) */ |
|
119 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
120 |
public Object isNaN; |
|
121 |
||
122 |
/** ECMA 15.1.2.5 isFinite (number) */ |
|
123 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
124 |
public Object isFinite; |
|
125 |
||
126 |
/** ECMA 15.1.3.3 encodeURI */ |
|
127 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
128 |
public Object encodeURI; |
|
129 |
||
130 |
/** ECMA 15.1.3.4 encodeURIComponent */ |
|
131 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
132 |
public Object encodeURIComponent; |
|
133 |
||
134 |
/** ECMA 15.1.3.1 decodeURI */ |
|
135 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
136 |
public Object decodeURI; |
|
137 |
||
138 |
/** ECMA 15.1.3.2 decodeURIComponent */ |
|
139 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
140 |
public Object decodeURIComponent; |
|
141 |
||
142 |
/** ECMA B.2.1 escape (string) */ |
|
143 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
144 |
public Object escape; |
|
145 |
||
146 |
/** ECMA B.2.2 unescape (string) */ |
|
147 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
148 |
public Object unescape; |
|
149 |
||
150 |
/** Nashorn extension: global.print */ |
|
151 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
152 |
public Object print; |
|
153 |
||
154 |
/** Nashorn extension: global.load */ |
|
155 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
156 |
public Object load; |
|
157 |
||
17974
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
158 |
/** Nashorn extension: global.loadWithNewGlobal */ |
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
159 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
160 |
public Object loadWithNewGlobal; |
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
161 |
|
16219 | 162 |
/** Nashorn extension: global.exit */ |
163 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
164 |
public Object exit; |
|
165 |
||
166 |
/** Nashorn extension: global.quit */ |
|
167 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
168 |
public Object quit; |
|
169 |
||
16147 | 170 |
/** Value property NaN of the Global Object - ECMA 15.1.1.1 NaN */ |
171 |
@Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT) |
|
24719 | 172 |
public final double NaN = Double.NaN; |
16147 | 173 |
|
174 |
/** Value property Infinity of the Global Object - ECMA 15.1.1.2 Infinity */ |
|
175 |
@Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT) |
|
24719 | 176 |
public final double Infinity = Double.POSITIVE_INFINITY; |
16147 | 177 |
|
178 |
/** Value property Undefined of the Global Object - ECMA 15.1.1.3 Undefined */ |
|
179 |
@Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT) |
|
180 |
public final Object undefined = UNDEFINED; |
|
181 |
||
182 |
/** ECMA 15.1.2.1 eval(x) */ |
|
183 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
184 |
public Object eval; |
|
185 |
||
186 |
/** ECMA 15.1.4.1 Object constructor. */ |
|
187 |
@Property(name = "Object", attributes = Attribute.NOT_ENUMERABLE) |
|
188 |
public volatile Object object; |
|
189 |
||
190 |
/** ECMA 15.1.4.2 Function constructor. */ |
|
191 |
@Property(name = "Function", attributes = Attribute.NOT_ENUMERABLE) |
|
192 |
public volatile Object function; |
|
193 |
||
194 |
/** ECMA 15.1.4.3 Array constructor. */ |
|
195 |
@Property(name = "Array", attributes = Attribute.NOT_ENUMERABLE) |
|
196 |
public volatile Object array; |
|
197 |
||
198 |
/** ECMA 15.1.4.4 String constructor */ |
|
199 |
@Property(name = "String", attributes = Attribute.NOT_ENUMERABLE) |
|
200 |
public volatile Object string; |
|
201 |
||
202 |
/** ECMA 15.1.4.5 Boolean constructor */ |
|
203 |
@Property(name = "Boolean", attributes = Attribute.NOT_ENUMERABLE) |
|
204 |
public volatile Object _boolean; |
|
205 |
||
206 |
/** ECMA 15.1.4.6 - Number constructor */ |
|
207 |
@Property(name = "Number", attributes = Attribute.NOT_ENUMERABLE) |
|
208 |
public volatile Object number; |
|
209 |
||
210 |
/** ECMA 15.1.4.7 Date constructor */ |
|
211 |
@Property(name = "Date", attributes = Attribute.NOT_ENUMERABLE) |
|
212 |
public volatile Object date; |
|
213 |
||
214 |
/** ECMA 15.1.4.8 RegExp constructor */ |
|
215 |
@Property(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE) |
|
216 |
public volatile Object regexp; |
|
217 |
||
218 |
/** ECMA 15.12 - The JSON object */ |
|
219 |
@Property(name = "JSON", attributes = Attribute.NOT_ENUMERABLE) |
|
220 |
public volatile Object json; |
|
221 |
||
222 |
/** Nashorn extension: global.JSAdapter */ |
|
223 |
@Property(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE) |
|
224 |
public volatile Object jsadapter; |
|
225 |
||
226 |
/** ECMA 15.8 - The Math object */ |
|
227 |
@Property(name = "Math", attributes = Attribute.NOT_ENUMERABLE) |
|
228 |
public volatile Object math; |
|
229 |
||
230 |
/** Error object */ |
|
231 |
@Property(name = "Error", attributes = Attribute.NOT_ENUMERABLE) |
|
232 |
public volatile Object error; |
|
233 |
||
234 |
/** EvalError object */ |
|
235 |
@Property(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE) |
|
236 |
public volatile Object evalError; |
|
237 |
||
238 |
/** RangeError object */ |
|
239 |
@Property(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE) |
|
240 |
public volatile Object rangeError; |
|
241 |
||
242 |
/** ReferenceError object */ |
|
243 |
@Property(name = "ReferenceError", attributes = Attribute.NOT_ENUMERABLE) |
|
244 |
public volatile Object referenceError; |
|
245 |
||
246 |
/** SyntaxError object */ |
|
247 |
@Property(name = "SyntaxError", attributes = Attribute.NOT_ENUMERABLE) |
|
248 |
public volatile Object syntaxError; |
|
249 |
||
250 |
/** TypeError object */ |
|
251 |
@Property(name = "TypeError", attributes = Attribute.NOT_ENUMERABLE) |
|
252 |
public volatile Object typeError; |
|
253 |
||
254 |
/** URIError object */ |
|
255 |
@Property(name = "URIError", attributes = Attribute.NOT_ENUMERABLE) |
|
256 |
public volatile Object uriError; |
|
257 |
||
258 |
/** ArrayBuffer object */ |
|
259 |
@Property(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE) |
|
260 |
public volatile Object arrayBuffer; |
|
261 |
||
23374 | 262 |
/** DataView object */ |
263 |
@Property(name = "DataView", attributes = Attribute.NOT_ENUMERABLE) |
|
264 |
public volatile Object dataView; |
|
265 |
||
16147 | 266 |
/** TypedArray (int8) */ |
267 |
@Property(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE) |
|
268 |
public volatile Object int8Array; |
|
269 |
||
270 |
/** TypedArray (uint8) */ |
|
271 |
@Property(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE) |
|
272 |
public volatile Object uint8Array; |
|
273 |
||
274 |
/** TypedArray (uint8) - Clamped */ |
|
275 |
@Property(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE) |
|
276 |
public volatile Object uint8ClampedArray; |
|
277 |
||
278 |
/** TypedArray (int16) */ |
|
279 |
@Property(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE) |
|
280 |
public volatile Object int16Array; |
|
281 |
||
282 |
/** TypedArray (uint16) */ |
|
283 |
@Property(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE) |
|
284 |
public volatile Object uint16Array; |
|
285 |
||
286 |
/** TypedArray (int32) */ |
|
287 |
@Property(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE) |
|
288 |
public volatile Object int32Array; |
|
289 |
||
290 |
/** TypedArray (uint32) */ |
|
291 |
@Property(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE) |
|
292 |
public volatile Object uint32Array; |
|
293 |
||
294 |
/** TypedArray (float32) */ |
|
295 |
@Property(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE) |
|
296 |
public volatile Object float32Array; |
|
297 |
||
298 |
/** TypedArray (float64) */ |
|
299 |
@Property(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE) |
|
300 |
public volatile Object float64Array; |
|
301 |
||
302 |
/** Nashorn extension: Java access - global.Packages */ |
|
303 |
@Property(name = "Packages", attributes = Attribute.NOT_ENUMERABLE) |
|
304 |
public volatile Object packages; |
|
305 |
||
16532 | 306 |
/** Nashorn extension: Java access - global.com */ |
307 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
308 |
public volatile Object com; |
|
309 |
||
310 |
/** Nashorn extension: Java access - global.edu */ |
|
311 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
312 |
public volatile Object edu; |
|
313 |
||
16147 | 314 |
/** Nashorn extension: Java access - global.java */ |
315 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
316 |
public volatile Object java; |
|
317 |
||
16532 | 318 |
/** Nashorn extension: Java access - global.javafx */ |
319 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
320 |
public volatile Object javafx; |
|
321 |
||
16147 | 322 |
/** Nashorn extension: Java access - global.javax */ |
323 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
16532 | 324 |
public volatile Object javax; |
325 |
||
326 |
/** Nashorn extension: Java access - global.org */ |
|
327 |
@Property(attributes = Attribute.NOT_ENUMERABLE) |
|
328 |
public volatile Object org; |
|
16147 | 329 |
|
330 |
/** Nashorn extension: Java access - global.javaImporter */ |
|
331 |
@Property(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE) |
|
332 |
public volatile Object javaImporter; |
|
333 |
||
334 |
/** Nashorn extension: global.Java Object constructor. */ |
|
335 |
@Property(name = "Java", attributes = Attribute.NOT_ENUMERABLE) |
|
336 |
public volatile Object javaApi; |
|
337 |
||
338 |
/** Nashorn extension: current script's file name */ |
|
339 |
@Property(name = "__FILE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT) |
|
24719 | 340 |
public final Object __FILE__ = LOCATION_PROPERTY_PLACEHOLDER; |
16147 | 341 |
|
342 |
/** Nashorn extension: current script's directory */ |
|
343 |
@Property(name = "__DIR__", attributes = Attribute.NON_ENUMERABLE_CONSTANT) |
|
24719 | 344 |
public final Object __DIR__ = LOCATION_PROPERTY_PLACEHOLDER; |
16147 | 345 |
|
346 |
/** Nashorn extension: current source line number being executed */ |
|
347 |
@Property(name = "__LINE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT) |
|
24719 | 348 |
public final Object __LINE__ = LOCATION_PROPERTY_PLACEHOLDER; |
16147 | 349 |
|
350 |
/** Used as Date.prototype's default value */ |
|
351 |
public NativeDate DEFAULT_DATE; |
|
352 |
||
353 |
/** Used as RegExp.prototype's default value */ |
|
354 |
public NativeRegExp DEFAULT_REGEXP; |
|
355 |
||
356 |
/* |
|
357 |
* Built-in constructor objects: Even if user changes dynamic values of |
|
358 |
* "Object", "Array" etc., we still want to keep original values of these |
|
359 |
* constructors here. For example, we need to be able to create array, |
|
360 |
* regexp literals even after user overwrites global "Array" or "RegExp" |
|
361 |
* constructor - see also ECMA 262 spec. Annex D. |
|
362 |
*/ |
|
363 |
private ScriptFunction builtinFunction; |
|
364 |
private ScriptFunction builtinObject; |
|
365 |
private ScriptFunction builtinArray; |
|
366 |
private ScriptFunction builtinBoolean; |
|
367 |
private ScriptFunction builtinDate; |
|
368 |
private ScriptObject builtinJSON; |
|
369 |
private ScriptFunction builtinJSAdapter; |
|
370 |
private ScriptObject builtinMath; |
|
371 |
private ScriptFunction builtinNumber; |
|
372 |
private ScriptFunction builtinRegExp; |
|
373 |
private ScriptFunction builtinString; |
|
374 |
private ScriptFunction builtinError; |
|
375 |
private ScriptFunction builtinEval; |
|
376 |
private ScriptFunction builtinEvalError; |
|
377 |
private ScriptFunction builtinRangeError; |
|
378 |
private ScriptFunction builtinReferenceError; |
|
379 |
private ScriptFunction builtinSyntaxError; |
|
380 |
private ScriptFunction builtinTypeError; |
|
381 |
private ScriptFunction builtinURIError; |
|
382 |
private ScriptObject builtinPackages; |
|
16532 | 383 |
private ScriptObject builtinCom; |
384 |
private ScriptObject builtinEdu; |
|
16147 | 385 |
private ScriptObject builtinJava; |
16532 | 386 |
private ScriptObject builtinJavafx; |
16147 | 387 |
private ScriptObject builtinJavax; |
16532 | 388 |
private ScriptObject builtinOrg; |
16147 | 389 |
private ScriptObject builtinJavaImporter; |
390 |
private ScriptObject builtinJavaApi; |
|
391 |
private ScriptObject builtinArrayBuffer; |
|
23374 | 392 |
private ScriptObject builtinDataView; |
16147 | 393 |
private ScriptObject builtinInt8Array; |
394 |
private ScriptObject builtinUint8Array; |
|
395 |
private ScriptObject builtinUint8ClampedArray; |
|
396 |
private ScriptObject builtinInt16Array; |
|
397 |
private ScriptObject builtinUint16Array; |
|
398 |
private ScriptObject builtinInt32Array; |
|
399 |
private ScriptObject builtinUint32Array; |
|
400 |
private ScriptObject builtinFloat32Array; |
|
401 |
private ScriptObject builtinFloat64Array; |
|
402 |
||
22382
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
403 |
/* |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
404 |
* 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
|
405 |
*/ |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
406 |
private ScriptFunction typeErrorThrower; |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
407 |
|
16147 | 408 |
// Flag to indicate that a split method issued a return statement |
409 |
private int splitState = -1; |
|
410 |
||
16223
dff592a332a4
8007718: Make static RegExp properties fully compatible to other engines
hannesw
parents:
16219
diff
changeset
|
411 |
// Used to store the last RegExp result to support deprecated RegExp constructor properties |
16258 | 412 |
private RegExpResult lastRegExpResult; |
16223
dff592a332a4
8007718: Make static RegExp properties fully compatible to other engines
hannesw
parents:
16219
diff
changeset
|
413 |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
414 |
private static final MethodHandle EVAL = findOwnMH_S("eval", Object.class, Object.class, Object.class); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
415 |
private static final MethodHandle PRINT = findOwnMH_S("print", Object.class, Object.class, Object[].class); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
416 |
private static final MethodHandle PRINTLN = findOwnMH_S("println", Object.class, Object.class, Object[].class); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
417 |
private static final MethodHandle LOAD = findOwnMH_S("load", Object.class, Object.class, Object.class); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
418 |
private static final MethodHandle LOADWITHNEWGLOBAL = findOwnMH_S("loadWithNewGlobal", Object.class, Object.class, Object[].class); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
419 |
private static final MethodHandle EXIT = findOwnMH_S("exit", Object.class, Object.class, Object.class); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
420 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
421 |
/** Invalidate a reserved name, such as "apply" or "call" if assigned */ |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
422 |
public MethodHandle INVALIDATE_RESERVED_NAME = MH.bindTo(findOwnMH_V("invalidateReservedName", void.class, String.class), this); |
16147 | 423 |
|
18618
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
424 |
// initialized by nasgen |
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
425 |
private static PropertyMap $nasgenmap$; |
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
426 |
|
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
427 |
// context to which this global belongs to |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
428 |
private final Context context; |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
429 |
|
24745
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
430 |
// global constants for this global - they can be replaced with MethodHandle.constant until invalidated |
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
431 |
private static AtomicReference<GlobalConstants> gcsInstance = new AtomicReference<>(); |
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24738
diff
changeset
|
432 |
|
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
433 |
@Override |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
434 |
protected Context getContext() { |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
435 |
return context; |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
436 |
} |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
437 |
|
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
438 |
// performs initialization checks for Global constructor and returns the |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
439 |
// PropertyMap, if everything is fine. |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
440 |
private static PropertyMap checkAndGetMap(final Context context) { |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
441 |
// security check first |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
442 |
final SecurityManager sm = System.getSecurityManager(); |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
443 |
if (sm != null) { |
19459 | 444 |
sm.checkPermission(new RuntimePermission(Context.NASHORN_CREATE_GLOBAL)); |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
445 |
} |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
446 |
|
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
447 |
// null check on context |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
448 |
context.getClass(); |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
449 |
|
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
450 |
/* |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
451 |
* Duplicate global's map and use it. This way the initial Map filled |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
452 |
* by nasgen (referenced from static field in this class) is retained |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
453 |
* 'as is' (as that one is process wide singleton. |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
454 |
*/ |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
455 |
return $nasgenmap$.duplicate(); |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
456 |
} |
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
457 |
|
16147 | 458 |
/** |
459 |
* Constructor |
|
16233
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16228
diff
changeset
|
460 |
* |
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16228
diff
changeset
|
461 |
* @param context the context |
16147 | 462 |
*/ |
16226
0e4f37e6cc40
8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents:
16223
diff
changeset
|
463 |
public Global(final Context context) { |
19085
066c9e5afd79
8020731: Revisit checkPermission calls in Context class
sundar
parents:
18855
diff
changeset
|
464 |
super(checkAndGetMap(context)); |
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
465 |
this.context = context; |
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18851
diff
changeset
|
466 |
this.setIsScope(); |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
467 |
this.optimisticFunctionMap = new HashMap<>(); |
24745
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
468 |
//we can only share one instance of Global constants between globals, or we consume way too much |
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
469 |
//memory - this is good enough for most programs |
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
470 |
while (gcsInstance.get() == null) { |
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
471 |
gcsInstance.compareAndSet(null, new GlobalConstants(context.getLogger(GlobalConstants.class))); |
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
472 |
} |
16147 | 473 |
} |
474 |
||
475 |
/** |
|
16226
0e4f37e6cc40
8007915: Nashorn IR, codegen, parser packages and Context instance should be inaccessible to user code
sundar
parents:
16223
diff
changeset
|
476 |
* Script access to "current" Global instance |
16147 | 477 |
* |
478 |
* @return the global singleton |
|
479 |
*/ |
|
480 |
public static Global instance() { |
|
24727 | 481 |
final Global global = Context.getGlobal(); |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
482 |
global.getClass(); // null check |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
483 |
return global; |
16147 | 484 |
} |
485 |
||
486 |
/** |
|
24745
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
487 |
* Return the global constants map for fields that |
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
488 |
* can be accessed as MethodHandle.constant |
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
489 |
* @return constant map |
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
490 |
*/ |
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
491 |
public static GlobalConstants getConstants() { |
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
492 |
return gcsInstance.get(); |
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
493 |
} |
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
494 |
|
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
495 |
/** |
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24738
diff
changeset
|
496 |
* Check if we have a Global instance |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24738
diff
changeset
|
497 |
* @return true if one exists |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24738
diff
changeset
|
498 |
*/ |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24738
diff
changeset
|
499 |
public static boolean hasInstance() { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24738
diff
changeset
|
500 |
return Context.getGlobal() != null; |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24738
diff
changeset
|
501 |
} |
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 |
/** |
16262
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
504 |
* Script access to {@link ScriptEnvironment} |
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
505 |
* |
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
506 |
* @return the script environment |
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
507 |
*/ |
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
508 |
static ScriptEnvironment getEnv() { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
509 |
return instance().getContext().getEnv(); |
16262
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
510 |
} |
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 |
/** |
16147 | 513 |
* Script access to {@link Context} |
514 |
* |
|
515 |
* @return the context |
|
516 |
*/ |
|
16185 | 517 |
static Context getThisContext() { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
518 |
return instance().getContext(); |
16147 | 519 |
} |
520 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
521 |
// Runtime interface to Global |
16147 | 522 |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
523 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
524 |
* Is this global of the given Context? |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
525 |
* @param ctxt the context |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
526 |
* @return true if this global belongs to the given Context |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
527 |
*/ |
20933
89748612fd1d
8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents:
20216
diff
changeset
|
528 |
public boolean isOfContext(final Context ctxt) { |
89748612fd1d
8026250: Logging nullpointer bugfix and javadoc warnings
lagergren
parents:
20216
diff
changeset
|
529 |
return this.context == ctxt; |
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
530 |
} |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
531 |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
532 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
533 |
* Does this global belong to a strict Context? |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
534 |
* @return true if this global belongs to a strict Context |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
535 |
*/ |
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
536 |
public boolean isStrictContext() { |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
537 |
return context.getEnv()._strict; |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
538 |
} |
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
539 |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
540 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
541 |
* Initialize standard builtin objects like "Object", "Array", "Function" etc. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
542 |
* 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
|
543 |
* of the global scope object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
544 |
*/ |
16147 | 545 |
public void initBuiltinObjects() { |
546 |
if (this.builtinObject != null) { |
|
547 |
// already initialized, just return |
|
548 |
return; |
|
549 |
} |
|
550 |
||
16185 | 551 |
init(); |
16147 | 552 |
} |
553 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
554 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
555 |
* Wrap a Java object as corresponding script object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
556 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
557 |
* @param obj object to wrap |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
558 |
* @return wrapped object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
559 |
*/ |
16147 | 560 |
public Object wrapAsObject(final Object obj) { |
561 |
if (obj instanceof Boolean) { |
|
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
562 |
return new NativeBoolean((Boolean)obj, this); |
16147 | 563 |
} 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
|
564 |
return new NativeNumber(((Number)obj).doubleValue(), this); |
16147 | 565 |
} else if (obj instanceof String || obj instanceof ConsString) { |
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
566 |
return new NativeString((CharSequence)obj, this); |
16147 | 567 |
} else if (obj instanceof Object[]) { // extension |
568 |
return new NativeArray((Object[])obj); |
|
569 |
} else if (obj instanceof double[]) { // extension |
|
570 |
return new NativeArray((double[])obj); |
|
571 |
} else if (obj instanceof long[]) { |
|
572 |
return new NativeArray((long[])obj); |
|
573 |
} else if (obj instanceof int[]) { |
|
574 |
return new NativeArray((int[])obj); |
|
575 |
} else { |
|
576 |
// FIXME: more special cases? Map? List? |
|
577 |
return obj; |
|
578 |
} |
|
579 |
} |
|
580 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
581 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
582 |
* Lookup helper for JS primitive types |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
583 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
584 |
* @param request the link request for the dynamic call site. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
585 |
* @param self self reference |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
586 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
587 |
* @return guarded invocation |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
588 |
*/ |
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
|
589 |
public static GuardedInvocation primitiveLookup(final LinkRequest request, final Object self) { |
16195
3f6c0ab2597a
8006766: Array-like access to characters of a string is slow
hannesw
parents:
16188
diff
changeset
|
590 |
if (self instanceof String || self instanceof ConsString) { |
3f6c0ab2597a
8006766: Array-like access to characters of a string is slow
hannesw
parents:
16188
diff
changeset
|
591 |
return NativeString.lookupPrimitive(request, self); |
3f6c0ab2597a
8006766: Array-like access to characters of a string is slow
hannesw
parents:
16188
diff
changeset
|
592 |
} else if (self instanceof Number) { |
3f6c0ab2597a
8006766: Array-like access to characters of a string is slow
hannesw
parents:
16188
diff
changeset
|
593 |
return NativeNumber.lookupPrimitive(request, self); |
3f6c0ab2597a
8006766: Array-like access to characters of a string is slow
hannesw
parents:
16188
diff
changeset
|
594 |
} else if (self instanceof Boolean) { |
3f6c0ab2597a
8006766: Array-like access to characters of a string is slow
hannesw
parents:
16188
diff
changeset
|
595 |
return NativeBoolean.lookupPrimitive(request, self); |
3f6c0ab2597a
8006766: Array-like access to characters of a string is slow
hannesw
parents:
16188
diff
changeset
|
596 |
} |
3f6c0ab2597a
8006766: Array-like access to characters of a string is slow
hannesw
parents:
16188
diff
changeset
|
597 |
throw new IllegalArgumentException("Unsupported primitive: " + self); |
16147 | 598 |
} |
599 |
||
23375
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 |
* Create a new empty script object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
602 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
603 |
* @return the new ScriptObject |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
604 |
*/ |
16147 | 605 |
public ScriptObject newObject() { |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
606 |
return new JO(getObjectPrototype(), JO.getInitialMap()); |
16147 | 607 |
} |
608 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
609 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
610 |
* Default value of given type |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
611 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
612 |
* @param sobj script object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
613 |
* @param typeHint type hint |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
614 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
615 |
* @return default value |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
616 |
*/ |
16147 | 617 |
public Object getDefaultValue(final ScriptObject sobj, final Class<?> typeHint) { |
618 |
// When the [[DefaultValue]] internal method of O is called with no hint, |
|
619 |
// then it behaves as if the hint were Number, unless O is a Date object |
|
620 |
// in which case it behaves as if the hint were String. |
|
621 |
Class<?> hint = typeHint; |
|
622 |
if (hint == null) { |
|
623 |
hint = Number.class; |
|
624 |
} |
|
625 |
||
626 |
try { |
|
627 |
if (hint == String.class) { |
|
628 |
||
629 |
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
|
630 |
|
153f268bfa72
8021122: Not all callables are handled for toString and other function valued properties
sundar
parents:
19085
diff
changeset
|
631 |
if (Bootstrap.isCallable(toString)) { |
16147 | 632 |
final Object value = TO_STRING.getInvoker().invokeExact(toString, sobj); |
633 |
if (JSType.isPrimitive(value)) { |
|
634 |
return value; |
|
635 |
} |
|
636 |
} |
|
637 |
||
638 |
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
|
639 |
if (Bootstrap.isCallable(valueOf)) { |
16147 | 640 |
final Object value = VALUE_OF.getInvoker().invokeExact(valueOf, sobj); |
641 |
if (JSType.isPrimitive(value)) { |
|
642 |
return value; |
|
643 |
} |
|
644 |
} |
|
16256
f2d9a0c49914
8007002: Replace implicit exception throwing methods with explicit throws - simplify control flow and remove useless code
lagergren
parents:
16234
diff
changeset
|
645 |
throw typeError(this, "cannot.get.default.string"); |
16147 | 646 |
} |
647 |
||
648 |
if (hint == Number.class) { |
|
649 |
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
|
650 |
if (Bootstrap.isCallable(valueOf)) { |
16147 | 651 |
final Object value = VALUE_OF.getInvoker().invokeExact(valueOf, sobj); |
652 |
if (JSType.isPrimitive(value)) { |
|
653 |
return value; |
|
654 |
} |
|
655 |
} |
|
656 |
||
657 |
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
|
658 |
if (Bootstrap.isCallable(toString)) { |
16147 | 659 |
final Object value = TO_STRING.getInvoker().invokeExact(toString, sobj); |
660 |
if (JSType.isPrimitive(value)) { |
|
661 |
return value; |
|
662 |
} |
|
663 |
} |
|
664 |
||
16256
f2d9a0c49914
8007002: Replace implicit exception throwing methods with explicit throws - simplify control flow and remove useless code
lagergren
parents:
16234
diff
changeset
|
665 |
throw typeError(this, "cannot.get.default.number"); |
16147 | 666 |
} |
667 |
} catch (final RuntimeException | Error e) { |
|
668 |
throw e; |
|
669 |
} catch (final Throwable t) { |
|
670 |
throw new RuntimeException(t); |
|
671 |
} |
|
672 |
||
673 |
return UNDEFINED; |
|
674 |
} |
|
675 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
676 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
677 |
* Is the given ScriptObject an ECMAScript Error object? |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
678 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
679 |
* @param sobj the object being checked |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
680 |
* @return true if sobj is an Error object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
681 |
*/ |
16147 | 682 |
public boolean isError(final ScriptObject sobj) { |
683 |
final ScriptObject errorProto = getErrorPrototype(); |
|
684 |
ScriptObject proto = sobj.getProto(); |
|
685 |
while (proto != null) { |
|
686 |
if (proto == errorProto) { |
|
687 |
return true; |
|
688 |
} |
|
689 |
proto = proto.getProto(); |
|
690 |
} |
|
691 |
return false; |
|
692 |
} |
|
693 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
694 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
695 |
* Create a new ECMAScript Error object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
696 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
697 |
* @param msg error message |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
698 |
* @return newly created Error object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
699 |
*/ |
16147 | 700 |
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
|
701 |
return new NativeError(msg, this); |
16147 | 702 |
} |
703 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
704 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
705 |
* Create a new ECMAScript EvalError object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
706 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
707 |
* @param msg error message |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
708 |
* @return newly created EvalError object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
709 |
*/ |
16147 | 710 |
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
|
711 |
return new NativeEvalError(msg, this); |
16147 | 712 |
} |
713 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
714 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
715 |
* Create a new ECMAScript RangeError object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
716 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
717 |
* @param msg error message |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
718 |
* @return newly created RangeError object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
719 |
*/ |
16147 | 720 |
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
|
721 |
return new NativeRangeError(msg, this); |
16147 | 722 |
} |
723 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
724 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
725 |
* Create a new ECMAScript ReferenceError object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
726 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
727 |
* @param msg error message |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
728 |
* @return newly created ReferenceError object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
729 |
*/ |
16147 | 730 |
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
|
731 |
return new NativeReferenceError(msg, this); |
16147 | 732 |
} |
733 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
734 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
735 |
* Create a new ECMAScript SyntaxError object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
736 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
737 |
* @param msg error message |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
738 |
* @return newly created SyntaxError object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
739 |
*/ |
16147 | 740 |
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
|
741 |
return new NativeSyntaxError(msg, this); |
16147 | 742 |
} |
743 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
744 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
745 |
* Create a new ECMAScript TypeError object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
746 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
747 |
* @param msg error message |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
748 |
* @return newly created TypeError object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
749 |
*/ |
16147 | 750 |
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
|
751 |
return new NativeTypeError(msg, this); |
16147 | 752 |
} |
753 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
754 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
755 |
* Create a new ECMAScript URIError object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
756 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
757 |
* @param msg error message |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
758 |
* @return newly created URIError object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
759 |
*/ |
16147 | 760 |
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
|
761 |
return new NativeURIError(msg, this); |
16147 | 762 |
} |
763 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
764 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
765 |
* Create a new ECMAScript GenericDescriptor object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
766 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
767 |
* @param configurable is the property configurable? |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
768 |
* @param enumerable is the property enumerable? |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
769 |
* @return newly created GenericDescriptor object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
770 |
*/ |
16147 | 771 |
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
|
772 |
return new GenericPropertyDescriptor(configurable, enumerable, this); |
16147 | 773 |
} |
774 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
775 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
776 |
* Create a new ECMAScript DatePropertyDescriptor object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
777 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
778 |
* @param value of the data property |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
779 |
* @param configurable is the property configurable? |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
780 |
* @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
|
781 |
* @param writable is the property writable? |
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
782 |
* @return newly created DataPropertyDescriptor object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
783 |
*/ |
16147 | 784 |
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
|
785 |
return new DataPropertyDescriptor(configurable, enumerable, writable, value, this); |
16147 | 786 |
} |
787 |
||
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
788 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
789 |
* Create a new ECMAScript AccessorPropertyDescriptor object. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
790 |
* |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
791 |
* @param get getter function of the user accessor property |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
792 |
* @param set setter function of the user accessor property |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
793 |
* @param configurable is the property configurable? |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
794 |
* @param enumerable is the property enumerable? |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
795 |
* @return newly created AccessorPropertyDescriptor object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
796 |
*/ |
16147 | 797 |
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
|
798 |
final AccessorPropertyDescriptor desc = new AccessorPropertyDescriptor(configurable, enumerable, get == null ? UNDEFINED : get, set == null ? UNDEFINED : set, this); |
16147 | 799 |
|
800 |
if (get == null) { |
|
18328
ebd24057f163
8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
18326
diff
changeset
|
801 |
desc.delete(PropertyDescriptor.GET, false); |
16147 | 802 |
} |
803 |
||
804 |
if (set == null) { |
|
18328
ebd24057f163
8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
18326
diff
changeset
|
805 |
desc.delete(PropertyDescriptor.SET, false); |
16147 | 806 |
} |
807 |
||
808 |
return desc; |
|
809 |
} |
|
810 |
||
19456
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
811 |
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
|
812 |
final T obj = map.get(key); |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
813 |
if (obj != null) { |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
814 |
return obj; |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
815 |
} |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
816 |
|
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
817 |
try { |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
818 |
final T newObj = creator.call(); |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
819 |
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
|
820 |
return existingObj != null ? existingObj : newObj; |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
821 |
} catch (final Exception exp) { |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
822 |
throw new RuntimeException(exp); |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
823 |
} |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
824 |
} |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
825 |
|
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
826 |
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
|
827 |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
828 |
|
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
829 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
830 |
* Get cached InvokeByName object for the given key |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
831 |
* @param key key to be associated with InvokeByName object |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
832 |
* @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
|
833 |
* @return InvokeByName object associated with the key. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
834 |
*/ |
19456
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
835 |
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
|
836 |
return getLazilyCreatedValue(key, creator, namedInvokers); |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
837 |
} |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
838 |
|
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
839 |
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
|
840 |
|
23375
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
841 |
/** |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
842 |
* Get cached dynamic method handle for the given key |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
843 |
* @param key key to be associated with dynamic method handle |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
844 |
* @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
|
845 |
* @return dynamic method handle associated with the key. |
a1110f2cbe75
8037400: Remove getInitialMap getters and GlobalObject interface
sundar
parents:
23374
diff
changeset
|
846 |
*/ |
19456
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
847 |
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
|
848 |
return getLazilyCreatedValue(key, creator, dynamicInvokers); |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
849 |
} |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
19088
diff
changeset
|
850 |
|
16147 | 851 |
/** |
852 |
* This is the eval used when 'indirect' eval call is made. |
|
853 |
* |
|
854 |
* var global = this; |
|
855 |
* global.eval("print('hello')"); |
|
856 |
* |
|
857 |
* @param self eval scope |
|
858 |
* @param str eval string |
|
859 |
* |
|
860 |
* @return the result of eval |
|
861 |
*/ |
|
862 |
public static Object eval(final Object self, final Object str) { |
|
863 |
return directEval(self, str, UNDEFINED, UNDEFINED, UNDEFINED); |
|
864 |
} |
|
865 |
||
866 |
/** |
|
867 |
* Direct eval |
|
868 |
* |
|
869 |
* @param self The scope of eval passed as 'self' |
|
870 |
* @param str Evaluated code |
|
871 |
* @param callThis "this" to be passed to the evaluated code |
|
872 |
* @param location location of the eval call |
|
873 |
* @param strict is eval called a strict mode code? |
|
874 |
* |
|
875 |
* @return the return value of the eval |
|
876 |
* |
|
877 |
* This is directly invoked from generated when eval(code) is called in user code |
|
878 |
*/ |
|
879 |
public static Object directEval(final Object self, final Object str, final Object callThis, final Object location, final Object strict) { |
|
880 |
if (!(str instanceof String || str instanceof ConsString)) { |
|
881 |
return str; |
|
882 |
} |
|
16185 | 883 |
final Global global = Global.instance(); |
24720 | 884 |
final ScriptObject scope = self instanceof ScriptObject ? (ScriptObject)self : global; |
16147 | 885 |
|
25240
f92c14b1ca11
8047959: bindings created for declarations in eval code are not mutable
sundar
parents:
24772
diff
changeset
|
886 |
return global.getContext().eval(scope, str.toString(), callThis, location, Boolean.TRUE.equals(strict), true); |
16147 | 887 |
} |
888 |
||
889 |
/** |
|
890 |
* Global print implementation - Nashorn extension |
|
891 |
* |
|
892 |
* @param self scope |
|
893 |
* @param objects arguments to print |
|
894 |
* |
|
895 |
* @return result of print (undefined) |
|
896 |
*/ |
|
897 |
public static Object print(final Object self, final Object... objects) { |
|
898 |
return printImpl(false, objects); |
|
899 |
} |
|
900 |
||
901 |
/** |
|
902 |
* Global println implementation - Nashorn extension |
|
903 |
* |
|
904 |
* @param self scope |
|
905 |
* @param objects arguments to print |
|
906 |
* |
|
907 |
* @return result of println (undefined) |
|
908 |
*/ |
|
909 |
public static Object println(final Object self, final Object... objects) { |
|
910 |
return printImpl(true, objects); |
|
911 |
} |
|
912 |
||
913 |
/** |
|
914 |
* Global load implementation - Nashorn extension |
|
915 |
* |
|
916 |
* @param self scope |
|
917 |
* @param source source to load |
|
918 |
* |
|
919 |
* @return result of load (undefined) |
|
920 |
* |
|
921 |
* @throws IOException if source could not be read |
|
922 |
*/ |
|
923 |
public static Object load(final Object self, final Object source) throws IOException { |
|
16185 | 924 |
final Global global = Global.instance(); |
24720 | 925 |
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
|
926 |
return global.getContext().load(scope, source); |
16147 | 927 |
} |
928 |
||
16219 | 929 |
/** |
17974
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
930 |
* Global loadWithNewGlobal implementation - Nashorn extension |
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
931 |
* |
18326
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
932 |
* @param self scope |
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
933 |
* @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
|
934 |
* |
18326
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
935 |
* @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
|
936 |
* |
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
937 |
* @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
|
938 |
*/ |
18326
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
939 |
public static Object loadWithNewGlobal(final Object self, final Object...args) throws IOException { |
17974
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
940 |
final Global global = Global.instance(); |
18326
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
941 |
final int length = args.length; |
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
942 |
final boolean hasArgs = 0 < length; |
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
943 |
final Object from = hasArgs ? args[0] : UNDEFINED; |
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
944 |
final Object[] arguments = hasArgs ? Arrays.copyOfRange(args, 1, length) : args; |
512bdf9535a6
8016453: loadWithNewGlobal does not allow apply operation
jlaskey
parents:
18321
diff
changeset
|
945 |
|
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
946 |
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
|
947 |
} |
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
948 |
|
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
949 |
/** |
16219 | 950 |
* Global exit and quit implementation - Nashorn extension: perform a {@code System.exit} call from the script |
951 |
* |
|
952 |
* @param self self reference |
|
953 |
* @param code exit code |
|
954 |
* |
|
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
|
955 |
* @return undefined (will never be reached) |
16219 | 956 |
*/ |
957 |
public static Object exit(final Object self, final Object code) { |
|
958 |
System.exit(JSType.toInt32(code)); |
|
959 |
return UNDEFINED; |
|
960 |
} |
|
961 |
||
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
962 |
// builtin prototype accessors |
16147 | 963 |
ScriptObject getFunctionPrototype() { |
964 |
return ScriptFunction.getPrototype(builtinFunction); |
|
965 |
} |
|
966 |
||
967 |
ScriptObject getObjectPrototype() { |
|
968 |
return ScriptFunction.getPrototype(builtinObject); |
|
969 |
} |
|
970 |
||
971 |
ScriptObject getArrayPrototype() { |
|
972 |
return ScriptFunction.getPrototype(builtinArray); |
|
973 |
} |
|
974 |
||
975 |
ScriptObject getBooleanPrototype() { |
|
976 |
return ScriptFunction.getPrototype(builtinBoolean); |
|
977 |
} |
|
978 |
||
979 |
ScriptObject getNumberPrototype() { |
|
980 |
return ScriptFunction.getPrototype(builtinNumber); |
|
981 |
} |
|
982 |
||
983 |
ScriptObject getDatePrototype() { |
|
984 |
return ScriptFunction.getPrototype(builtinDate); |
|
985 |
} |
|
986 |
||
987 |
ScriptObject getRegExpPrototype() { |
|
988 |
return ScriptFunction.getPrototype(builtinRegExp); |
|
989 |
} |
|
990 |
||
991 |
ScriptObject getStringPrototype() { |
|
992 |
return ScriptFunction.getPrototype(builtinString); |
|
993 |
} |
|
994 |
||
995 |
ScriptObject getErrorPrototype() { |
|
996 |
return ScriptFunction.getPrototype(builtinError); |
|
997 |
} |
|
998 |
||
999 |
ScriptObject getEvalErrorPrototype() { |
|
1000 |
return ScriptFunction.getPrototype(builtinEvalError); |
|
1001 |
} |
|
1002 |
||
1003 |
ScriptObject getRangeErrorPrototype() { |
|
1004 |
return ScriptFunction.getPrototype(builtinRangeError); |
|
1005 |
} |
|
1006 |
||
1007 |
ScriptObject getReferenceErrorPrototype() { |
|
1008 |
return ScriptFunction.getPrototype(builtinReferenceError); |
|
1009 |
} |
|
1010 |
||
1011 |
ScriptObject getSyntaxErrorPrototype() { |
|
1012 |
return ScriptFunction.getPrototype(builtinSyntaxError); |
|
1013 |
} |
|
1014 |
||
1015 |
ScriptObject getTypeErrorPrototype() { |
|
1016 |
return ScriptFunction.getPrototype(builtinTypeError); |
|
1017 |
} |
|
1018 |
||
1019 |
ScriptObject getURIErrorPrototype() { |
|
1020 |
return ScriptFunction.getPrototype(builtinURIError); |
|
1021 |
} |
|
1022 |
||
1023 |
ScriptObject getJavaImporterPrototype() { |
|
1024 |
return ScriptFunction.getPrototype(builtinJavaImporter); |
|
1025 |
} |
|
1026 |
||
1027 |
ScriptObject getJSAdapterPrototype() { |
|
1028 |
return ScriptFunction.getPrototype(builtinJSAdapter); |
|
1029 |
} |
|
1030 |
||
1031 |
ScriptObject getArrayBufferPrototype() { |
|
1032 |
return ScriptFunction.getPrototype(builtinArrayBuffer); |
|
1033 |
} |
|
1034 |
||
23374 | 1035 |
ScriptObject getDataViewPrototype() { |
1036 |
return ScriptFunction.getPrototype(builtinDataView); |
|
1037 |
} |
|
1038 |
||
16147 | 1039 |
ScriptObject getInt8ArrayPrototype() { |
1040 |
return ScriptFunction.getPrototype(builtinInt8Array); |
|
1041 |
} |
|
1042 |
||
1043 |
ScriptObject getUint8ArrayPrototype() { |
|
1044 |
return ScriptFunction.getPrototype(builtinUint8Array); |
|
1045 |
} |
|
1046 |
||
1047 |
ScriptObject getUint8ClampedArrayPrototype() { |
|
1048 |
return ScriptFunction.getPrototype(builtinUint8ClampedArray); |
|
1049 |
} |
|
1050 |
||
1051 |
ScriptObject getInt16ArrayPrototype() { |
|
1052 |
return ScriptFunction.getPrototype(builtinInt16Array); |
|
1053 |
} |
|
1054 |
||
1055 |
ScriptObject getUint16ArrayPrototype() { |
|
1056 |
return ScriptFunction.getPrototype(builtinUint16Array); |
|
1057 |
} |
|
1058 |
||
1059 |
ScriptObject getInt32ArrayPrototype() { |
|
1060 |
return ScriptFunction.getPrototype(builtinInt32Array); |
|
1061 |
} |
|
1062 |
||
1063 |
ScriptObject getUint32ArrayPrototype() { |
|
1064 |
return ScriptFunction.getPrototype(builtinUint32Array); |
|
1065 |
} |
|
1066 |
||
1067 |
ScriptObject getFloat32ArrayPrototype() { |
|
1068 |
return ScriptFunction.getPrototype(builtinFloat32Array); |
|
1069 |
} |
|
1070 |
||
1071 |
ScriptObject getFloat64ArrayPrototype() { |
|
1072 |
return ScriptFunction.getPrototype(builtinFloat64Array); |
|
1073 |
} |
|
1074 |
||
1075 |
private ScriptFunction getBuiltinArray() { |
|
1076 |
return builtinArray; |
|
1077 |
} |
|
1078 |
||
22382
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
1079 |
ScriptFunction getTypeErrorThrower() { |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
1080 |
return typeErrorThrower; |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
1081 |
} |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
1082 |
|
16147 | 1083 |
/** |
1084 |
* Called from compiled script code to test if builtin has been overridden |
|
1085 |
* |
|
1086 |
* @return true if builtin array has not been overridden |
|
1087 |
*/ |
|
1088 |
public static boolean isBuiltinArray() { |
|
1089 |
final Global instance = Global.instance(); |
|
1090 |
return instance.array == instance.getBuiltinArray(); |
|
1091 |
} |
|
1092 |
||
1093 |
private ScriptFunction getBuiltinBoolean() { |
|
1094 |
return builtinBoolean; |
|
1095 |
} |
|
1096 |
||
1097 |
/** |
|
1098 |
* Called from compiled script code to test if builtin has been overridden |
|
1099 |
* |
|
1100 |
* @return true if builtin boolean has not been overridden |
|
1101 |
*/ |
|
1102 |
public static boolean isBuiltinBoolean() { |
|
1103 |
final Global instance = Global.instance(); |
|
1104 |
return instance._boolean == instance.getBuiltinBoolean(); |
|
1105 |
} |
|
1106 |
||
1107 |
private ScriptFunction getBuiltinDate() { |
|
1108 |
return builtinDate; |
|
1109 |
} |
|
1110 |
||
1111 |
/** |
|
1112 |
* Called from compiled script code to test if builtin has been overridden |
|
1113 |
* |
|
1114 |
* @return true if builtin date has not been overridden |
|
1115 |
*/ |
|
1116 |
public static boolean isBuiltinDate() { |
|
1117 |
final Global instance = Global.instance(); |
|
1118 |
return instance.date == instance.getBuiltinDate(); |
|
1119 |
} |
|
1120 |
||
1121 |
private ScriptFunction getBuiltinError() { |
|
1122 |
return builtinError; |
|
1123 |
} |
|
1124 |
||
1125 |
/** |
|
1126 |
* Called from compiled script code to test if builtin has been overridden |
|
1127 |
* |
|
1128 |
* @return true if builtin error has not been overridden |
|
1129 |
*/ |
|
1130 |
public static boolean isBuiltinError() { |
|
1131 |
final Global instance = Global.instance(); |
|
1132 |
return instance.error == instance.getBuiltinError(); |
|
1133 |
} |
|
1134 |
||
1135 |
private ScriptFunction getBuiltinEvalError() { |
|
1136 |
return builtinEvalError; |
|
1137 |
} |
|
1138 |
||
1139 |
/** |
|
1140 |
* Called from compiled script code to test if builtin has been overridden |
|
1141 |
* |
|
1142 |
* @return true if builtin eval error has not been overridden |
|
1143 |
*/ |
|
1144 |
public static boolean isBuiltinEvalError() { |
|
1145 |
final Global instance = Global.instance(); |
|
1146 |
return instance.evalError == instance.getBuiltinEvalError(); |
|
1147 |
} |
|
1148 |
||
1149 |
private ScriptFunction getBuiltinFunction() { |
|
1150 |
return builtinFunction; |
|
1151 |
} |
|
1152 |
||
1153 |
/** |
|
1154 |
* Called from compiled script code to test if builtin has been overridden |
|
1155 |
* |
|
1156 |
* @return true if builtin function has not been overridden |
|
1157 |
*/ |
|
1158 |
public static boolean isBuiltinFunction() { |
|
1159 |
final Global instance = Global.instance(); |
|
1160 |
return instance.function == instance.getBuiltinFunction(); |
|
1161 |
} |
|
1162 |
||
1163 |
private ScriptFunction getBuiltinJSAdapter() { |
|
1164 |
return builtinJSAdapter; |
|
1165 |
} |
|
1166 |
||
1167 |
/** |
|
1168 |
* Called from compiled script code to test if builtin has been overridden |
|
1169 |
* |
|
1170 |
* @return true if builtin JSAdapter has not been overridden |
|
1171 |
*/ |
|
1172 |
public static boolean isBuiltinJSAdapter() { |
|
1173 |
final Global instance = Global.instance(); |
|
1174 |
return instance.jsadapter == instance.getBuiltinJSAdapter(); |
|
1175 |
} |
|
1176 |
||
1177 |
private ScriptObject getBuiltinJSON() { |
|
1178 |
return builtinJSON; |
|
1179 |
} |
|
1180 |
||
1181 |
/** |
|
1182 |
* Called from compiled script code to test if builtin has been overridden |
|
1183 |
* |
|
1184 |
* @return true if builtin JSON has has not been overridden |
|
1185 |
*/ |
|
1186 |
public static boolean isBuiltinJSON() { |
|
1187 |
final Global instance = Global.instance(); |
|
1188 |
return instance.json == instance.getBuiltinJSON(); |
|
1189 |
} |
|
1190 |
||
1191 |
private ScriptObject getBuiltinJava() { |
|
1192 |
return builtinJava; |
|
1193 |
} |
|
1194 |
||
1195 |
/** |
|
1196 |
* Called from compiled script code to test if builtin has been overridden |
|
1197 |
* |
|
1198 |
* @return true if builtin Java has not been overridden |
|
1199 |
*/ |
|
1200 |
public static boolean isBuiltinJava() { |
|
1201 |
final Global instance = Global.instance(); |
|
1202 |
return instance.java == instance.getBuiltinJava(); |
|
1203 |
} |
|
1204 |
||
1205 |
private ScriptObject getBuiltinJavax() { |
|
1206 |
return builtinJavax; |
|
1207 |
} |
|
1208 |
||
1209 |
/** |
|
1210 |
* Called from compiled script code to test if builtin has been overridden |
|
1211 |
* |
|
1212 |
* @return true if builtin Javax has not been overridden |
|
1213 |
*/ |
|
1214 |
public static boolean isBuiltinJavax() { |
|
1215 |
final Global instance = Global.instance(); |
|
1216 |
return instance.javax == instance.getBuiltinJavax(); |
|
1217 |
} |
|
1218 |
||
1219 |
private ScriptObject getBuiltinJavaImporter() { |
|
1220 |
return builtinJavaImporter; |
|
1221 |
} |
|
1222 |
||
1223 |
/** |
|
1224 |
* Called from compiled script code to test if builtin has been overridden |
|
1225 |
* |
|
1226 |
* @return true if builtin Java importer has not been overridden |
|
1227 |
*/ |
|
1228 |
public static boolean isBuiltinJavaImporter() { |
|
1229 |
final Global instance = Global.instance(); |
|
1230 |
return instance.javaImporter == instance.getBuiltinJavaImporter(); |
|
1231 |
} |
|
1232 |
||
1233 |
private ScriptObject getBuiltinMath() { |
|
1234 |
return builtinMath; |
|
1235 |
} |
|
1236 |
||
1237 |
/** |
|
1238 |
* Called from compiled script code to test if builtin has been overridden |
|
1239 |
* |
|
1240 |
* @return true if builtin math has not been overridden |
|
1241 |
*/ |
|
1242 |
public static boolean isBuiltinMath() { |
|
1243 |
final Global instance = Global.instance(); |
|
1244 |
return instance.math == instance.getBuiltinMath(); |
|
1245 |
} |
|
1246 |
||
1247 |
private ScriptFunction getBuiltinNumber() { |
|
1248 |
return builtinNumber; |
|
1249 |
} |
|
1250 |
||
1251 |
/** |
|
1252 |
* Called from compiled script code to test if builtin has been overridden |
|
1253 |
* |
|
1254 |
* @return true if builtin number has not been overridden |
|
1255 |
*/ |
|
1256 |
public static boolean isBuiltinNumber() { |
|
1257 |
final Global instance = Global.instance(); |
|
1258 |
return instance.number == instance.getBuiltinNumber(); |
|
1259 |
} |
|
1260 |
||
1261 |
private ScriptFunction getBuiltinObject() { |
|
1262 |
return builtinObject; |
|
1263 |
} |
|
1264 |
||
1265 |
/** |
|
1266 |
* Called from compiled script code to test if builtin has been overridden |
|
1267 |
* |
|
1268 |
* @return true if builtin object has not been overridden |
|
1269 |
*/ |
|
1270 |
public static boolean isBuiltinObject() { |
|
1271 |
final Global instance = Global.instance(); |
|
1272 |
return instance.object == instance.getBuiltinObject(); |
|
1273 |
} |
|
1274 |
||
1275 |
private ScriptObject getBuiltinPackages() { |
|
1276 |
return builtinPackages; |
|
1277 |
} |
|
1278 |
||
1279 |
/** |
|
1280 |
* Called from compiled script code to test if builtin has been overridden |
|
1281 |
* |
|
1282 |
* @return true if builtin package has not been overridden |
|
1283 |
*/ |
|
1284 |
public static boolean isBuiltinPackages() { |
|
1285 |
final Global instance = Global.instance(); |
|
1286 |
return instance.packages == instance.getBuiltinPackages(); |
|
1287 |
} |
|
1288 |
||
1289 |
private ScriptFunction getBuiltinRangeError() { |
|
1290 |
return builtinRangeError; |
|
1291 |
} |
|
1292 |
||
1293 |
/** |
|
1294 |
* Called from compiled script code to test if builtin has been overridden |
|
1295 |
* |
|
1296 |
* @return true if builtin range error has not been overridden |
|
1297 |
*/ |
|
1298 |
public static boolean isBuiltinRangeError() { |
|
1299 |
final Global instance = Global.instance(); |
|
1300 |
return instance.rangeError == instance.getBuiltinRangeError(); |
|
1301 |
} |
|
1302 |
||
1303 |
private ScriptFunction getBuiltinReferenceError() { |
|
1304 |
return builtinReferenceError; |
|
1305 |
} |
|
1306 |
||
1307 |
/** |
|
1308 |
* Called from compiled script code to test if builtin has been overridden |
|
1309 |
* |
|
1310 |
* @return true if builtin reference error has not been overridden |
|
1311 |
*/ |
|
1312 |
public static boolean isBuiltinReferenceError() { |
|
1313 |
final Global instance = Global.instance(); |
|
1314 |
return instance.referenceError == instance.getBuiltinReferenceError(); |
|
1315 |
} |
|
1316 |
||
1317 |
private ScriptFunction getBuiltinRegExp() { |
|
1318 |
return builtinRegExp; |
|
1319 |
} |
|
1320 |
||
1321 |
/** |
|
1322 |
* Called from compiled script code to test if builtin has been overridden |
|
1323 |
* |
|
1324 |
* @return true if builtin regexp has not been overridden |
|
1325 |
*/ |
|
1326 |
public static boolean isBuiltinRegExp() { |
|
1327 |
final Global instance = Global.instance(); |
|
1328 |
return instance.regexp == instance.getBuiltinRegExp(); |
|
1329 |
} |
|
1330 |
||
1331 |
private ScriptFunction getBuiltinString() { |
|
1332 |
return builtinString; |
|
1333 |
} |
|
1334 |
||
1335 |
/** |
|
1336 |
* Called from compiled script code to test if builtin has been overridden |
|
1337 |
* |
|
1338 |
* @return true if builtin Java has not been overridden |
|
1339 |
*/ |
|
1340 |
public static boolean isBuiltinString() { |
|
1341 |
final Global instance = Global.instance(); |
|
1342 |
return instance.string == instance.getBuiltinString(); |
|
1343 |
} |
|
1344 |
||
1345 |
private ScriptFunction getBuiltinSyntaxError() { |
|
1346 |
return builtinSyntaxError; |
|
1347 |
} |
|
1348 |
||
1349 |
/** |
|
1350 |
* Called from compiled script code to test if builtin has been overridden |
|
1351 |
* |
|
1352 |
* @return true if builtin syntax error has not been overridden |
|
1353 |
*/ |
|
1354 |
public static boolean isBuiltinSyntaxError() { |
|
1355 |
final Global instance = Global.instance(); |
|
1356 |
return instance.syntaxError == instance.getBuiltinSyntaxError(); |
|
1357 |
} |
|
1358 |
||
1359 |
private ScriptFunction getBuiltinTypeError() { |
|
1360 |
return builtinTypeError; |
|
1361 |
} |
|
1362 |
||
1363 |
/** |
|
1364 |
* Called from compiled script code to test if builtin has been overridden |
|
1365 |
* |
|
1366 |
* @return true if builtin type error has not been overridden |
|
1367 |
*/ |
|
1368 |
public static boolean isBuiltinTypeError() { |
|
1369 |
final Global instance = Global.instance(); |
|
1370 |
return instance.typeError == instance.getBuiltinTypeError(); |
|
1371 |
} |
|
1372 |
||
1373 |
private ScriptFunction getBuiltinURIError() { |
|
1374 |
return builtinURIError; |
|
1375 |
} |
|
1376 |
||
1377 |
/** |
|
1378 |
* Called from compiled script code to test if builtin has been overridden |
|
1379 |
* |
|
1380 |
* @return true if builtin URI error has not been overridden |
|
1381 |
*/ |
|
1382 |
public static boolean isBuiltinURIError() { |
|
1383 |
final Global instance = Global.instance(); |
|
1384 |
return instance.uriError == instance.getBuiltinURIError(); |
|
1385 |
} |
|
1386 |
||
1387 |
@Override |
|
1388 |
public String getClassName() { |
|
1389 |
return "global"; |
|
1390 |
} |
|
1391 |
||
1392 |
/** |
|
1393 |
* Copy function used to clone NativeRegExp objects. |
|
1394 |
* |
|
1395 |
* @param regexp a NativeRegExp to clone |
|
1396 |
* |
|
1397 |
* @return copy of the given regexp object |
|
1398 |
*/ |
|
1399 |
public static Object regExpCopy(final Object regexp) { |
|
1400 |
return new NativeRegExp((NativeRegExp)regexp); |
|
1401 |
} |
|
1402 |
||
1403 |
/** |
|
1404 |
* Convert given object to NativeRegExp type. |
|
1405 |
* |
|
1406 |
* @param obj object to be converted |
|
1407 |
* @return NativeRegExp instance |
|
1408 |
*/ |
|
1409 |
public static NativeRegExp toRegExp(final Object obj) { |
|
1410 |
if (obj instanceof NativeRegExp) { |
|
1411 |
return (NativeRegExp)obj; |
|
1412 |
} |
|
1413 |
return new NativeRegExp(JSType.toString(obj)); |
|
1414 |
} |
|
1415 |
||
1416 |
/** |
|
1417 |
* ECMA 9.9 ToObject implementation |
|
1418 |
* |
|
1419 |
* @param obj an item for which to run ToObject |
|
1420 |
* @return ToObject version of given item |
|
1421 |
*/ |
|
1422 |
public static Object toObject(final Object obj) { |
|
1423 |
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
|
1424 |
throw typeError("not.an.object", ScriptRuntime.safeToString(obj)); |
16147 | 1425 |
} |
1426 |
||
1427 |
if (obj instanceof ScriptObject) { |
|
1428 |
return obj; |
|
1429 |
} |
|
1430 |
||
1431 |
return instance().wrapAsObject(obj); |
|
1432 |
} |
|
1433 |
||
1434 |
/** |
|
1435 |
* Allocate a new object array. |
|
1436 |
* |
|
1437 |
* @param initial object values. |
|
1438 |
* @return the new array |
|
1439 |
*/ |
|
16210
8ad1381b69d0
8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents:
16207
diff
changeset
|
1440 |
public static NativeArray allocate(final Object[] initial) { |
18618
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1441 |
ArrayData arrayData = ArrayData.allocate(initial); |
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1442 |
|
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1443 |
for (int index = 0; index < initial.length; index++) { |
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1444 |
final Object value = initial[index]; |
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1445 |
|
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1446 |
if (value == ScriptRuntime.EMPTY) { |
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1447 |
arrayData = arrayData.delete(index); |
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1448 |
} |
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1449 |
} |
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1450 |
|
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1451 |
return new NativeArray(arrayData); |
16147 | 1452 |
} |
1453 |
||
1454 |
/** |
|
1455 |
* Allocate a new number array. |
|
1456 |
* |
|
1457 |
* @param initial number values. |
|
1458 |
* @return the new array |
|
1459 |
*/ |
|
16210
8ad1381b69d0
8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents:
16207
diff
changeset
|
1460 |
public static NativeArray allocate(final double[] initial) { |
18618
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1461 |
return new NativeArray(ArrayData.allocate(initial)); |
16147 | 1462 |
} |
1463 |
||
1464 |
/** |
|
1465 |
* Allocate a new long array. |
|
1466 |
* |
|
1467 |
* @param initial number values. |
|
1468 |
* @return the new array |
|
1469 |
*/ |
|
16210
8ad1381b69d0
8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents:
16207
diff
changeset
|
1470 |
public static NativeArray allocate(final long[] initial) { |
18618
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1471 |
return new NativeArray(ArrayData.allocate(initial)); |
16147 | 1472 |
} |
1473 |
||
1474 |
/** |
|
1475 |
* Allocate a new integer array. |
|
1476 |
* |
|
1477 |
* @param initial number values. |
|
1478 |
* @return the new array |
|
1479 |
*/ |
|
16210
8ad1381b69d0
8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents:
16207
diff
changeset
|
1480 |
public static NativeArray allocate(final int[] initial) { |
18618
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1481 |
return new NativeArray(ArrayData.allocate(initial)); |
16147 | 1482 |
} |
1483 |
||
1484 |
/** |
|
1485 |
* Allocate a new object array for arguments. |
|
1486 |
* |
|
1487 |
* @param arguments initial arguments passed. |
|
1488 |
* @param callee reference to the function that uses arguments object |
|
1489 |
* @param numParams actual number of declared parameters |
|
1490 |
* |
|
1491 |
* @return the new array |
|
1492 |
*/ |
|
16206
83069fa0935b
8006529: Methods always get callee - it should be conditional
attila
parents:
16196
diff
changeset
|
1493 |
public static ScriptObject allocateArguments(final Object[] arguments, final Object callee, final int numParams) { |
16147 | 1494 |
return NativeArguments.allocate(arguments, (ScriptFunction)callee, numParams); |
1495 |
} |
|
1496 |
||
1497 |
/** |
|
1498 |
* Called from generated to check if given function is the builtin 'eval'. If |
|
1499 |
* eval is used in a script, a lot of optimizations and assumptions cannot be done. |
|
1500 |
* |
|
1501 |
* @param fn function object that is checked |
|
1502 |
* @return true if fn is the builtin eval |
|
1503 |
*/ |
|
1504 |
public static boolean isEval(final Object fn) { |
|
1505 |
return fn == Global.instance().builtinEval; |
|
1506 |
} |
|
1507 |
||
1508 |
/** |
|
24719 | 1509 |
* Called from generated to replace a location property placeholder with the actual location property value. |
1510 |
* |
|
1511 |
* @param placeholder the value tested for being a placeholder for a location property |
|
1512 |
* @param locationProperty the actual value for the location property |
|
1513 |
* @return locationProperty if placeholder is indeed a placeholder for a location property, the placeholder otherwise |
|
1514 |
*/ |
|
1515 |
public static Object replaceLocationPropertyPlaceholder(final Object placeholder, final Object locationProperty) { |
|
1516 |
return isLocationPropertyPlaceholder(placeholder) ? locationProperty : placeholder; |
|
1517 |
} |
|
1518 |
||
1519 |
/** |
|
1520 |
* Called from runtime internals to check if the passed value is a location property placeholder. |
|
1521 |
* @param placeholder the value tested for being a placeholder for a location property |
|
1522 |
* @return true if the value is a placeholder, false otherwise. |
|
1523 |
*/ |
|
1524 |
public static boolean isLocationPropertyPlaceholder(final Object placeholder) { |
|
1525 |
return placeholder == LOCATION_PROPERTY_PLACEHOLDER; |
|
1526 |
} |
|
1527 |
||
1528 |
/** |
|
16147 | 1529 |
* Create a new RegExp object. |
1530 |
* |
|
1531 |
* @param expression Regular expression. |
|
1532 |
* @param options Search options. |
|
1533 |
* |
|
1534 |
* @return New RegExp object. |
|
1535 |
*/ |
|
1536 |
public static Object newRegExp(final String expression, final String options) { |
|
1537 |
if (options == null) { |
|
1538 |
return new NativeRegExp(expression); |
|
1539 |
} |
|
1540 |
return new NativeRegExp(expression, options); |
|
1541 |
} |
|
1542 |
||
1543 |
/** |
|
1544 |
* Get the object prototype |
|
1545 |
* |
|
1546 |
* @return the object prototype |
|
1547 |
*/ |
|
1548 |
public static ScriptObject objectPrototype() { |
|
1549 |
return Global.instance().getObjectPrototype(); |
|
1550 |
} |
|
1551 |
||
1552 |
/** |
|
1553 |
* Create a new empty object instance. |
|
1554 |
* |
|
1555 |
* @return New empty object. |
|
1556 |
*/ |
|
1557 |
public static ScriptObject newEmptyInstance() { |
|
18618
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1558 |
return Global.instance().newObject(); |
16147 | 1559 |
} |
1560 |
||
1561 |
/** |
|
1562 |
* Check if a given object is a ScriptObject, raises an exception if this is |
|
1563 |
* not the case |
|
1564 |
* |
|
1565 |
* @param obj and object to check |
|
24720 | 1566 |
* @return the script object |
16147 | 1567 |
*/ |
24720 | 1568 |
public static ScriptObject checkObject(final Object obj) { |
16147 | 1569 |
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
|
1570 |
throw typeError("not.an.object", ScriptRuntime.safeToString(obj)); |
16147 | 1571 |
} |
24720 | 1572 |
return (ScriptObject)obj; |
16147 | 1573 |
} |
1574 |
||
1575 |
/** |
|
1576 |
* ECMA 9.10 - implementation of CheckObjectCoercible, i.e. raise an exception |
|
1577 |
* if this object is null or undefined. |
|
1578 |
* |
|
1579 |
* @param obj an object to check |
|
1580 |
*/ |
|
1581 |
public static void checkObjectCoercible(final Object obj) { |
|
1582 |
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
|
1583 |
throw typeError("not.an.object", ScriptRuntime.safeToString(obj)); |
16147 | 1584 |
} |
1585 |
} |
|
1586 |
||
1587 |
/** |
|
1588 |
* Get the current split state. |
|
1589 |
* |
|
1590 |
* @return current split state |
|
1591 |
*/ |
|
1592 |
@Override |
|
1593 |
public int getSplitState() { |
|
1594 |
return splitState; |
|
1595 |
} |
|
1596 |
||
1597 |
/** |
|
1598 |
* Set the current split state. |
|
1599 |
* |
|
1600 |
* @param state current split state |
|
1601 |
*/ |
|
1602 |
@Override |
|
1603 |
public void setSplitState(final int state) { |
|
1604 |
splitState = state; |
|
1605 |
} |
|
1606 |
||
1607 |
private void init() { |
|
16185 | 1608 |
assert Context.getGlobal() == this : "this global is not set as current"; |
1609 |
||
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
1610 |
final ScriptEnvironment env = getContext().getEnv(); |
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
1611 |
|
16147 | 1612 |
// initialize Function and Object constructor |
1613 |
initFunctionAndObject(); |
|
1614 |
||
1615 |
// Now fix Global's own proto. |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
1616 |
this.setInitialProto(getObjectPrototype()); |
16147 | 1617 |
|
1618 |
// initialize global function properties |
|
1619 |
this.eval = this.builtinEval = ScriptFunctionImpl.makeFunction("eval", EVAL); |
|
1620 |
||
24720 | 1621 |
this.parseInt = ScriptFunctionImpl.makeFunction("parseInt", GlobalFunctions.PARSEINT, |
1622 |
new MethodHandle[] { GlobalFunctions.PARSEINT_OI, GlobalFunctions.PARSEINT_O }); |
|
16147 | 1623 |
this.parseFloat = ScriptFunctionImpl.makeFunction("parseFloat", GlobalFunctions.PARSEFLOAT); |
1624 |
this.isNaN = ScriptFunctionImpl.makeFunction("isNaN", GlobalFunctions.IS_NAN); |
|
1625 |
this.isFinite = ScriptFunctionImpl.makeFunction("isFinite", GlobalFunctions.IS_FINITE); |
|
1626 |
this.encodeURI = ScriptFunctionImpl.makeFunction("encodeURI", GlobalFunctions.ENCODE_URI); |
|
1627 |
this.encodeURIComponent = ScriptFunctionImpl.makeFunction("encodeURIComponent", GlobalFunctions.ENCODE_URICOMPONENT); |
|
1628 |
this.decodeURI = ScriptFunctionImpl.makeFunction("decodeURI", GlobalFunctions.DECODE_URI); |
|
1629 |
this.decodeURIComponent = ScriptFunctionImpl.makeFunction("decodeURIComponent", GlobalFunctions.DECODE_URICOMPONENT); |
|
1630 |
this.escape = ScriptFunctionImpl.makeFunction("escape", GlobalFunctions.ESCAPE); |
|
1631 |
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
|
1632 |
this.print = ScriptFunctionImpl.makeFunction("print", env._print_no_newline ? PRINT : PRINTLN); |
16147 | 1633 |
this.load = ScriptFunctionImpl.makeFunction("load", LOAD); |
17974
a2818f17324e
8015741: Need a global.load function that starts with a new global scope.
jlaskey
parents:
17972
diff
changeset
|
1634 |
this.loadWithNewGlobal = ScriptFunctionImpl.makeFunction("loadWithNewGlobal", LOADWITHNEWGLOBAL); |
16219 | 1635 |
this.exit = ScriptFunctionImpl.makeFunction("exit", EXIT); |
1636 |
this.quit = ScriptFunctionImpl.makeFunction("quit", EXIT); |
|
16147 | 1637 |
|
1638 |
// built-in constructors |
|
1639 |
this.builtinArray = (ScriptFunction)initConstructor("Array"); |
|
1640 |
this.builtinBoolean = (ScriptFunction)initConstructor("Boolean"); |
|
1641 |
this.builtinDate = (ScriptFunction)initConstructor("Date"); |
|
1642 |
this.builtinJSON = initConstructor("JSON"); |
|
1643 |
this.builtinJSAdapter = (ScriptFunction)initConstructor("JSAdapter"); |
|
1644 |
this.builtinMath = initConstructor("Math"); |
|
1645 |
this.builtinNumber = (ScriptFunction)initConstructor("Number"); |
|
1646 |
this.builtinRegExp = (ScriptFunction)initConstructor("RegExp"); |
|
1647 |
this.builtinString = (ScriptFunction)initConstructor("String"); |
|
1648 |
||
1649 |
// initialize String.prototype.length to 0 |
|
1650 |
// add String.prototype.length |
|
1651 |
final ScriptObject stringPrototype = getStringPrototype(); |
|
1652 |
stringPrototype.addOwnProperty("length", Attribute.NON_ENUMERABLE_CONSTANT, 0.0); |
|
1653 |
||
21439
31c57355a4a7
8026805: Array.prototype.length doesn't work as expected
hannesw
parents:
20933
diff
changeset
|
1654 |
// set isArray flag on Array.prototype |
16147 | 1655 |
final ScriptObject arrayPrototype = getArrayPrototype(); |
21439
31c57355a4a7
8026805: Array.prototype.length doesn't work as expected
hannesw
parents:
20933
diff
changeset
|
1656 |
arrayPrototype.setIsArray(); |
16147 | 1657 |
|
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
1658 |
this.DEFAULT_DATE = new NativeDate(Double.NaN, this); |
16147 | 1659 |
|
1660 |
// initialize default regexp object |
|
18851
bdb92c95f886
8019947: inherited property invalidation does not work with two globals in same context
sundar
parents:
18842
diff
changeset
|
1661 |
this.DEFAULT_REGEXP = new NativeRegExp("(?:)", this); |
16147 | 1662 |
|
1663 |
// RegExp.prototype should behave like a RegExp object. So copy the |
|
1664 |
// properties. |
|
1665 |
final ScriptObject regExpProto = getRegExpPrototype(); |
|
1666 |
regExpProto.addBoundProperties(DEFAULT_REGEXP); |
|
1667 |
||
1668 |
// Error stuff |
|
1669 |
initErrorObjects(); |
|
1670 |
||
1671 |
// java access |
|
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18851
diff
changeset
|
1672 |
if (! env._no_java) { |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18851
diff
changeset
|
1673 |
initJavaAccess(); |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18851
diff
changeset
|
1674 |
} |
16147 | 1675 |
|
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18851
diff
changeset
|
1676 |
if (! env._no_typed_arrays) { |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18851
diff
changeset
|
1677 |
initTypedArray(); |
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18851
diff
changeset
|
1678 |
} |
16147 | 1679 |
|
16262
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
1680 |
if (env._scripting) { |
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18851
diff
changeset
|
1681 |
initScripting(env); |
16147 | 1682 |
} |
1683 |
||
22389
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1684 |
if (Context.DEBUG) { |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1685 |
boolean debugOkay; |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1686 |
final SecurityManager sm = System.getSecurityManager(); |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1687 |
if (sm != null) { |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1688 |
try { |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1689 |
sm.checkPermission(new RuntimePermission(Context.NASHORN_DEBUG_MODE)); |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1690 |
debugOkay = true; |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1691 |
} catch (final SecurityException ignored) { |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1692 |
// if no permission, don't initialize Debug object |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1693 |
debugOkay = false; |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1694 |
} |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1695 |
|
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1696 |
} else { |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1697 |
debugOkay = true; |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1698 |
} |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1699 |
|
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1700 |
if (debugOkay) { |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1701 |
initDebug(); |
ea3dda90768c
8032060: PropertyMap of Error objects is not stable
sundar
parents:
22382
diff
changeset
|
1702 |
} |
16147 | 1703 |
} |
1704 |
||
1705 |
copyBuiltins(); |
|
1706 |
||
1707 |
// expose script (command line) arguments as "arguments" property of global |
|
24720 | 1708 |
final Object argumentsObject = wrapAsObject(env.getArguments().toArray()); |
1709 |
final int argumentsFlags = Attribute.NOT_ENUMERABLE; |
|
1710 |
addOwnProperty("arguments", argumentsFlags, argumentsObject); |
|
16262
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
1711 |
if (env._scripting) { |
16147 | 1712 |
// synonym for "arguments" in scripting mode |
24720 | 1713 |
addOwnProperty("$ARG", argumentsFlags, argumentsObject); |
16147 | 1714 |
} |
1715 |
} |
|
1716 |
||
1717 |
private void initErrorObjects() { |
|
1718 |
// Error objects |
|
1719 |
this.builtinError = (ScriptFunction)initConstructor("Error"); |
|
1720 |
final ScriptObject errorProto = getErrorPrototype(); |
|
1721 |
||
1722 |
// Nashorn specific accessors on Error.prototype - stack, lineNumber, columnNumber and fileName |
|
1723 |
final ScriptFunction getStack = ScriptFunctionImpl.makeFunction("getStack", NativeError.GET_STACK); |
|
1724 |
final ScriptFunction setStack = ScriptFunctionImpl.makeFunction("setStack", NativeError.SET_STACK); |
|
1725 |
errorProto.addOwnProperty("stack", Attribute.NOT_ENUMERABLE, getStack, setStack); |
|
1726 |
final ScriptFunction getLineNumber = ScriptFunctionImpl.makeFunction("getLineNumber", NativeError.GET_LINENUMBER); |
|
1727 |
final ScriptFunction setLineNumber = ScriptFunctionImpl.makeFunction("setLineNumber", NativeError.SET_LINENUMBER); |
|
1728 |
errorProto.addOwnProperty("lineNumber", Attribute.NOT_ENUMERABLE, getLineNumber, setLineNumber); |
|
1729 |
final ScriptFunction getColumnNumber = ScriptFunctionImpl.makeFunction("getColumnNumber", NativeError.GET_COLUMNNUMBER); |
|
1730 |
final ScriptFunction setColumnNumber = ScriptFunctionImpl.makeFunction("setColumnNumber", NativeError.SET_COLUMNNUMBER); |
|
1731 |
errorProto.addOwnProperty("columnNumber", Attribute.NOT_ENUMERABLE, getColumnNumber, setColumnNumber); |
|
1732 |
final ScriptFunction getFileName = ScriptFunctionImpl.makeFunction("getFileName", NativeError.GET_FILENAME); |
|
1733 |
final ScriptFunction setFileName = ScriptFunctionImpl.makeFunction("setFileName", NativeError.SET_FILENAME); |
|
1734 |
errorProto.addOwnProperty("fileName", Attribute.NOT_ENUMERABLE, getFileName, setFileName); |
|
1735 |
||
1736 |
// ECMA 15.11.4.2 Error.prototype.name |
|
1737 |
// Error.prototype.name = "Error"; |
|
18328
ebd24057f163
8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
18326
diff
changeset
|
1738 |
errorProto.set(NativeError.NAME, "Error", false); |
16147 | 1739 |
// ECMA 15.11.4.3 Error.prototype.message |
1740 |
// Error.prototype.message = ""; |
|
18328
ebd24057f163
8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
18326
diff
changeset
|
1741 |
errorProto.set(NativeError.MESSAGE, "", false); |
16147 | 1742 |
|
1743 |
this.builtinEvalError = initErrorSubtype("EvalError", errorProto); |
|
1744 |
this.builtinRangeError = initErrorSubtype("RangeError", errorProto); |
|
1745 |
this.builtinReferenceError = initErrorSubtype("ReferenceError", errorProto); |
|
1746 |
this.builtinSyntaxError = initErrorSubtype("SyntaxError", errorProto); |
|
1747 |
this.builtinTypeError = initErrorSubtype("TypeError", errorProto); |
|
1748 |
this.builtinURIError = initErrorSubtype("URIError", errorProto); |
|
1749 |
} |
|
1750 |
||
1751 |
private ScriptFunction initErrorSubtype(final String name, final ScriptObject errorProto) { |
|
1752 |
final ScriptObject cons = initConstructor(name); |
|
1753 |
final ScriptObject prototype = ScriptFunction.getPrototype(cons); |
|
18328
ebd24057f163
8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
18326
diff
changeset
|
1754 |
prototype.set(NativeError.NAME, name, false); |
ebd24057f163
8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
18326
diff
changeset
|
1755 |
prototype.set(NativeError.MESSAGE, "", false); |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
1756 |
prototype.setInitialProto(errorProto); |
16147 | 1757 |
return (ScriptFunction)cons; |
1758 |
} |
|
1759 |
||
1760 |
private void initJavaAccess() { |
|
1761 |
final ScriptObject objectProto = getObjectPrototype(); |
|
1762 |
this.builtinPackages = new NativeJavaPackage("", objectProto); |
|
16532 | 1763 |
this.builtinCom = new NativeJavaPackage("com", objectProto); |
1764 |
this.builtinEdu = new NativeJavaPackage("edu", objectProto); |
|
16147 | 1765 |
this.builtinJava = new NativeJavaPackage("java", objectProto); |
16532 | 1766 |
this.builtinJavafx = new NativeJavaPackage("javafx", objectProto); |
16147 | 1767 |
this.builtinJavax = new NativeJavaPackage("javax", objectProto); |
16532 | 1768 |
this.builtinOrg = new NativeJavaPackage("org", objectProto); |
16147 | 1769 |
this.builtinJavaImporter = initConstructor("JavaImporter"); |
1770 |
this.builtinJavaApi = initConstructor("Java"); |
|
1771 |
} |
|
1772 |
||
18855
408663ef8f66
8020015: shared PropertyMaps should not be used without duplication
sundar
parents:
18851
diff
changeset
|
1773 |
private void initScripting(final ScriptEnvironment scriptEnv) { |
16147 | 1774 |
Object value; |
1775 |
value = ScriptFunctionImpl.makeFunction("readLine", ScriptingFunctions.READLINE); |
|
1776 |
addOwnProperty("readLine", Attribute.NOT_ENUMERABLE, value); |
|
1777 |
||
16196
58f6f046bb5e
8006983: Introduce a command line option to switch off syntactic extensions of nashorn
sundar
parents:
16195
diff
changeset
|
1778 |
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
|
1779 |
addOwnProperty("readFully", Attribute.NOT_ENUMERABLE, value); |
16147 | 1780 |
|
16211 | 1781 |
final String execName = ScriptingFunctions.EXEC_NAME; |
1782 |
value = ScriptFunctionImpl.makeFunction(execName, ScriptingFunctions.EXEC); |
|
1783 |
addOwnProperty(execName, Attribute.NOT_ENUMERABLE, value); |
|
1784 |
||
16147 | 1785 |
// Nashorn extension: global.echo (scripting-mode-only) |
1786 |
// alias for "print" |
|
1787 |
value = get("print"); |
|
1788 |
addOwnProperty("echo", Attribute.NOT_ENUMERABLE, value); |
|
1789 |
||
1790 |
// Nashorn extension: global.$OPTIONS (scripting-mode-only) |
|
18618
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1791 |
final ScriptObject options = newObject(); |
16522 | 1792 |
copyOptions(options, scriptEnv); |
1793 |
addOwnProperty("$OPTIONS", Attribute.NOT_ENUMERABLE, options); |
|
16211 | 1794 |
|
1795 |
// Nashorn extension: global.$ENV (scripting-mode-only) |
|
16213
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
1796 |
if (System.getSecurityManager() == null) { |
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
1797 |
// 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
|
1798 |
// Retrieve current state of ENV variables. |
18618
136279c4cbe6
8019157: Avoid calling ScriptObject.setProto() if possible
hannesw
parents:
18610
diff
changeset
|
1799 |
final ScriptObject env = newObject(); |
19884
1bacbaa1bfc7
8024180: Incorrect handling of expression and parent scope in 'with' statements
sundar
parents:
19459
diff
changeset
|
1800 |
env.putAll(System.getenv(), scriptEnv._strict); |
16213
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
1801 |
addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, env); |
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
1802 |
} else { |
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
1803 |
addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED); |
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
1804 |
} |
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
1805 |
|
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
1806 |
// add other special properties for exec support |
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
1807 |
addOwnProperty(ScriptingFunctions.OUT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED); |
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
1808 |
addOwnProperty(ScriptingFunctions.ERR_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED); |
66cb726a76d5
8007521: $ENV should be undefined when security manager is present
sundar
parents:
16211
diff
changeset
|
1809 |
addOwnProperty(ScriptingFunctions.EXIT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED); |
16147 | 1810 |
} |
1811 |
||
16525
1409942e618e
8009982: Lazy execution bugfix. Added lazy sunspider unit test. Added mandreel to compile-octane test. Fixed warnings
lagergren
parents:
16522
diff
changeset
|
1812 |
private static void copyOptions(final ScriptObject options, final ScriptEnvironment scriptEnv) { |
24720 | 1813 |
for (final Field f : scriptEnv.getClass().getFields()) { |
19459 | 1814 |
try { |
1815 |
options.set(f.getName(), f.get(scriptEnv), false); |
|
1816 |
} catch (final IllegalArgumentException | IllegalAccessException exp) { |
|
1817 |
throw new RuntimeException(exp); |
|
16522 | 1818 |
} |
19459 | 1819 |
} |
16522 | 1820 |
} |
1821 |
||
16147 | 1822 |
private void initTypedArray() { |
1823 |
this.builtinArrayBuffer = initConstructor("ArrayBuffer"); |
|
23374 | 1824 |
this.builtinDataView = initConstructor("DataView"); |
16147 | 1825 |
this.builtinInt8Array = initConstructor("Int8Array"); |
1826 |
this.builtinUint8Array = initConstructor("Uint8Array"); |
|
1827 |
this.builtinUint8ClampedArray = initConstructor("Uint8ClampedArray"); |
|
1828 |
this.builtinInt16Array = initConstructor("Int16Array"); |
|
1829 |
this.builtinUint16Array = initConstructor("Uint16Array"); |
|
1830 |
this.builtinInt32Array = initConstructor("Int32Array"); |
|
1831 |
this.builtinUint32Array = initConstructor("Uint32Array"); |
|
1832 |
this.builtinFloat32Array = initConstructor("Float32Array"); |
|
1833 |
this.builtinFloat64Array = initConstructor("Float64Array"); |
|
1834 |
} |
|
1835 |
||
1836 |
private void copyBuiltins() { |
|
1837 |
this.array = this.builtinArray; |
|
1838 |
this._boolean = this.builtinBoolean; |
|
1839 |
this.date = this.builtinDate; |
|
1840 |
this.error = this.builtinError; |
|
1841 |
this.evalError = this.builtinEvalError; |
|
1842 |
this.function = this.builtinFunction; |
|
1843 |
this.jsadapter = this.builtinJSAdapter; |
|
1844 |
this.json = this.builtinJSON; |
|
16532 | 1845 |
this.com = this.builtinCom; |
1846 |
this.edu = this.builtinEdu; |
|
16147 | 1847 |
this.java = this.builtinJava; |
16532 | 1848 |
this.javafx = this.builtinJavafx; |
16147 | 1849 |
this.javax = this.builtinJavax; |
16532 | 1850 |
this.org = this.builtinOrg; |
16147 | 1851 |
this.javaImporter = this.builtinJavaImporter; |
1852 |
this.javaApi = this.builtinJavaApi; |
|
1853 |
this.math = this.builtinMath; |
|
1854 |
this.number = this.builtinNumber; |
|
1855 |
this.object = this.builtinObject; |
|
1856 |
this.packages = this.builtinPackages; |
|
1857 |
this.rangeError = this.builtinRangeError; |
|
1858 |
this.referenceError = this.builtinReferenceError; |
|
1859 |
this.regexp = this.builtinRegExp; |
|
1860 |
this.string = this.builtinString; |
|
1861 |
this.syntaxError = this.builtinSyntaxError; |
|
1862 |
this.typeError = this.builtinTypeError; |
|
1863 |
this.uriError = this.builtinURIError; |
|
1864 |
this.arrayBuffer = this.builtinArrayBuffer; |
|
23374 | 1865 |
this.dataView = this.builtinDataView; |
16147 | 1866 |
this.int8Array = this.builtinInt8Array; |
1867 |
this.uint8Array = this.builtinUint8Array; |
|
1868 |
this.uint8ClampedArray = this.builtinUint8ClampedArray; |
|
1869 |
this.int16Array = this.builtinInt16Array; |
|
1870 |
this.uint16Array = this.builtinUint16Array; |
|
1871 |
this.int32Array = this.builtinInt32Array; |
|
1872 |
this.uint32Array = this.builtinUint32Array; |
|
1873 |
this.float32Array = this.builtinFloat32Array; |
|
1874 |
this.float64Array = this.builtinFloat64Array; |
|
1875 |
} |
|
1876 |
||
1877 |
private void initDebug() { |
|
1878 |
this.addOwnProperty("Debug", Attribute.NOT_ENUMERABLE, initConstructor("Debug")); |
|
1879 |
} |
|
1880 |
||
1881 |
private static Object printImpl(final boolean newLine, final Object... objects) { |
|
16262
75513555e603
8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents:
16258
diff
changeset
|
1882 |
final PrintWriter out = Global.getEnv().getOut(); |
17972 | 1883 |
final StringBuilder sb = new StringBuilder(); |
16147 | 1884 |
|
1885 |
for (final Object object : objects) { |
|
17972 | 1886 |
if (sb.length() != 0) { |
1887 |
sb.append(' '); |
|
16147 | 1888 |
} |
1889 |
||
17972 | 1890 |
sb.append(JSType.toString(object)); |
16147 | 1891 |
} |
1892 |
||
17972 | 1893 |
// Print all at once to ensure thread friendly result. |
16147 | 1894 |
if (newLine) { |
17972 | 1895 |
out.println(sb.toString()); |
1896 |
} else { |
|
1897 |
out.print(sb.toString()); |
|
16147 | 1898 |
} |
1899 |
||
1900 |
out.flush(); |
|
1901 |
||
1902 |
return UNDEFINED; |
|
1903 |
} |
|
1904 |
||
1905 |
/** |
|
1906 |
* These classes are generated by nasgen tool and so we have to use |
|
1907 |
* reflection to load and create new instance of these classes. |
|
1908 |
*/ |
|
1909 |
private ScriptObject initConstructor(final String name) { |
|
1910 |
try { |
|
1911 |
// Assuming class name pattern for built-in JS constructors. |
|
1912 |
final StringBuilder sb = new StringBuilder("jdk.nashorn.internal.objects."); |
|
1913 |
||
1914 |
sb.append("Native"); |
|
1915 |
sb.append(name); |
|
1916 |
sb.append("$Constructor"); |
|
1917 |
||
1918 |
final Class<?> funcClass = Class.forName(sb.toString()); |
|
1919 |
final ScriptObject res = (ScriptObject)funcClass.newInstance(); |
|
1920 |
||
1921 |
if (res instanceof ScriptFunction) { |
|
1922 |
// All global constructor prototypes are not-writable, |
|
1923 |
// not-enumerable and not-configurable. |
|
1924 |
final ScriptFunction func = (ScriptFunction)res; |
|
1925 |
func.modifyOwnProperty(func.getProperty("prototype"), Attribute.NON_ENUMERABLE_CONSTANT); |
|
1926 |
} |
|
1927 |
||
1928 |
if (res.getProto() == null) { |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
1929 |
res.setInitialProto(getObjectPrototype()); |
16147 | 1930 |
} |
1931 |
||
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
|
1932 |
res.setIsBuiltin(); |
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
|
1933 |
|
16147 | 1934 |
return res; |
1935 |
||
1936 |
} catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) { |
|
1937 |
throw new RuntimeException(e); |
|
1938 |
} |
|
1939 |
} |
|
1940 |
||
1941 |
// Function and Object constructors are inter-dependent. Also, |
|
1942 |
// Function.prototype |
|
1943 |
// functions are not properly initialized. We fix the references here. |
|
1944 |
// NOTE: be careful if you want to re-order the operations here. You may |
|
1945 |
// have |
|
1946 |
// to play with object references carefully!! |
|
1947 |
private void initFunctionAndObject() { |
|
1948 |
// First-n-foremost is Function |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
1949 |
this.builtinFunction = (ScriptFunction)initConstructor("Function"); |
16147 | 1950 |
|
1951 |
// create global anonymous function |
|
24751 | 1952 |
final ScriptFunction anon = ScriptFunctionImpl.newAnonymousFunction(); |
16147 | 1953 |
// need to copy over members of Function.prototype to anon function |
1954 |
anon.addBoundProperties(getFunctionPrototype()); |
|
1955 |
||
1956 |
// Function.prototype === Object.getPrototypeOf(Function) === |
|
1957 |
// <anon-function> |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
1958 |
builtinFunction.setInitialProto(anon); |
16147 | 1959 |
builtinFunction.setPrototype(anon); |
18328
ebd24057f163
8015355: Array.prototype functions don't honour non-writable length and / or index properties
sundar
parents:
18326
diff
changeset
|
1960 |
anon.set("constructor", builtinFunction, false); |
16147 | 1961 |
anon.deleteOwnProperty(anon.getMap().findProperty("prototype")); |
1962 |
||
22382
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
1963 |
// 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
|
1964 |
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
|
1965 |
typeErrorThrower.setPrototype(UNDEFINED); |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
1966 |
// 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
|
1967 |
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
|
1968 |
typeErrorThrower.preventExtensions(); |
2abc7240ef59
8029612: the typeErrorThrower field in ScriptFunctionImpl cannot be static and common to all Globals
sundar
parents:
21686
diff
changeset
|
1969 |
|
16147 | 1970 |
// now initialize Object |
1971 |
this.builtinObject = (ScriptFunction)initConstructor("Object"); |
|
1972 |
final ScriptObject ObjectPrototype = getObjectPrototype(); |
|
1973 |
// Object.getPrototypeOf(Function.prototype) === Object.prototype |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
1974 |
anon.setInitialProto(ObjectPrototype); |
16147 | 1975 |
|
24281 | 1976 |
// ES6 draft compliant __proto__ property of Object.prototype |
1977 |
// accessors on Object.prototype for "__proto__" |
|
24772
0fc1013a1785
8044520: Nashorn cannot execute node.js's express module
sundar
parents:
24769
diff
changeset
|
1978 |
final ScriptFunction getProto = ScriptFunctionImpl.makeFunction("getProto", NativeObject.GET__PROTO__); |
0fc1013a1785
8044520: Nashorn cannot execute node.js's express module
sundar
parents:
24769
diff
changeset
|
1979 |
final ScriptFunction setProto = ScriptFunctionImpl.makeFunction("setProto", NativeObject.SET__PROTO__); |
24281 | 1980 |
ObjectPrototype.addOwnProperty("__proto__", Attribute.NOT_ENUMERABLE, getProto, setProto); |
1981 |
||
16147 | 1982 |
// Function valued properties of Function.prototype were not properly |
1983 |
// initialized. Because, these were created before global.function and |
|
1984 |
// global.object were not initialized. |
|
1985 |
jdk.nashorn.internal.runtime.Property[] properties = getFunctionPrototype().getMap().getProperties(); |
|
1986 |
for (final jdk.nashorn.internal.runtime.Property property : properties) { |
|
1987 |
final Object key = property.getKey(); |
|
1988 |
final Object value = builtinFunction.get(key); |
|
1989 |
||
1990 |
if (value instanceof ScriptFunction && value != anon) { |
|
1991 |
final ScriptFunction func = (ScriptFunction)value; |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
1992 |
func.setInitialProto(getFunctionPrototype()); |
16147 | 1993 |
final ScriptObject prototype = ScriptFunction.getPrototype(func); |
1994 |
if (prototype != null) { |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
1995 |
prototype.setInitialProto(ObjectPrototype); |
16147 | 1996 |
} |
1997 |
} |
|
1998 |
} |
|
1999 |
||
2000 |
// For function valued properties of Object and Object.prototype, make |
|
2001 |
// sure prototype's proto chain ends with Object.prototype |
|
2002 |
for (final jdk.nashorn.internal.runtime.Property property : builtinObject.getMap().getProperties()) { |
|
2003 |
final Object key = property.getKey(); |
|
2004 |
final Object value = builtinObject.get(key); |
|
2005 |
||
2006 |
if (value instanceof ScriptFunction) { |
|
2007 |
final ScriptFunction func = (ScriptFunction)value; |
|
2008 |
final ScriptObject prototype = ScriptFunction.getPrototype(func); |
|
2009 |
if (prototype != null) { |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
2010 |
prototype.setInitialProto(ObjectPrototype); |
16147 | 2011 |
} |
2012 |
} |
|
2013 |
} |
|
2014 |
||
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2015 |
//make sure apply and call have the same invalidation switchpoint |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2016 |
final SwitchPoint sp = new SwitchPoint(); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2017 |
optimisticFunctionMap.put("apply", sp); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2018 |
optimisticFunctionMap.put("call", sp); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2019 |
getFunctionPrototype().getProperty("apply").setChangeCallback(sp); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2020 |
getFunctionPrototype().getProperty("call").setChangeCallback(sp); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2021 |
|
16147 | 2022 |
properties = getObjectPrototype().getMap().getProperties(); |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2023 |
|
16147 | 2024 |
for (final jdk.nashorn.internal.runtime.Property property : properties) { |
2025 |
final Object key = property.getKey(); |
|
2026 |
final Object value = ObjectPrototype.get(key); |
|
2027 |
||
2028 |
if (key.equals("constructor")) { |
|
2029 |
continue; |
|
2030 |
} |
|
2031 |
||
2032 |
if (value instanceof ScriptFunction) { |
|
2033 |
final ScriptFunction func = (ScriptFunction)value; |
|
2034 |
final ScriptObject prototype = ScriptFunction.getPrototype(func); |
|
2035 |
if (prototype != null) { |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
22389
diff
changeset
|
2036 |
prototype.setInitialProto(ObjectPrototype); |
16147 | 2037 |
} |
2038 |
} |
|
2039 |
} |
|
2040 |
} |
|
2041 |
||
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2042 |
private static MethodHandle findOwnMH_V(final String name, final Class<?> rtype, final Class<?>... types) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2043 |
return MH.findVirtual(MethodHandles.lookup(), Global.class, name, MH.type(rtype, types)); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2044 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2045 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2046 |
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
|
2047 |
return MH.findStatic(MethodHandles.lookup(), Global.class, name, MH.type(rtype, types)); |
16147 | 2048 |
} |
16223
dff592a332a4
8007718: Make static RegExp properties fully compatible to other engines
hannesw
parents:
16219
diff
changeset
|
2049 |
|
16258 | 2050 |
RegExpResult getLastRegExpResult() { |
2051 |
return lastRegExpResult; |
|
16223
dff592a332a4
8007718: Make static RegExp properties fully compatible to other engines
hannesw
parents:
16219
diff
changeset
|
2052 |
} |
dff592a332a4
8007718: Make static RegExp properties fully compatible to other engines
hannesw
parents:
16219
diff
changeset
|
2053 |
|
16258 | 2054 |
void setLastRegExpResult(final RegExpResult regExpResult) { |
2055 |
this.lastRegExpResult = regExpResult; |
|
16223
dff592a332a4
8007718: Make static RegExp properties fully compatible to other engines
hannesw
parents:
16219
diff
changeset
|
2056 |
} |
dff592a332a4
8007718: Make static RegExp properties fully compatible to other engines
hannesw
parents:
16219
diff
changeset
|
2057 |
|
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
|
2058 |
@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
|
2059 |
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
|
2060 |
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
|
2061 |
} |
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
|
2062 |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2063 |
/** |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2064 |
* Check if there is a switchpoint for a reserved name. If there |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2065 |
* is, it must be invalidated upon properties with this name |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2066 |
* @param name property name |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2067 |
* @return switchpoint for invalidating this property, or null if not registered |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2068 |
*/ |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2069 |
public SwitchPoint getChangeCallback(final String name) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2070 |
return optimisticFunctionMap.get(name); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2071 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2072 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2073 |
/** |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2074 |
* Is this a special name, that might be subject to invalidation |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2075 |
* on write, such as "apply" or "call" |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2076 |
* @param name name to check |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2077 |
* @return true if special name |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2078 |
*/ |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2079 |
public boolean isSpecialName(final String name) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2080 |
return getChangeCallback(name) != null; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2081 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2082 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2083 |
/** |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2084 |
* Check if a reserved property name is invalidated |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2085 |
* @param name property name |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2086 |
* @return true if someone has written to it since Global was instantiated |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2087 |
*/ |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2088 |
public boolean isSpecialNameValid(final String name) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2089 |
final SwitchPoint sp = getChangeCallback(name); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2090 |
return sp != null && !sp.hasBeenInvalidated(); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2091 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2092 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2093 |
/** |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2094 |
* Tag a reserved name as invalidated - used when someone writes |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2095 |
* to a property with this name - overly conservative, but link time |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2096 |
* is too late to apply e.g. apply->call specialization |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2097 |
* @param name property name |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2098 |
*/ |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2099 |
public void invalidateReservedName(final String name) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2100 |
final SwitchPoint sp = getChangeCallback(name); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2101 |
if (sp != null) { |
24745
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
2102 |
getContext().getLogger(ApplySpecialization.class).info("Overwrote special name '" + name +"' - invalidating switchpoint"); |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2103 |
SwitchPoint.invalidateAll(new SwitchPoint[] { sp }); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2104 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2105 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2106 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2107 |
/** |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2108 |
* Bootstrapper for invalidating a builtin name |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2109 |
* @param lookup lookup |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2110 |
* @param name name to invalidate |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2111 |
* @param type methodhandle type |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2112 |
* @return callsite for invalidator |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2113 |
*/ |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2114 |
public static CallSite invalidateNameBootstrap(final MethodHandles.Lookup lookup, final String name, final MethodType type) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2115 |
final MethodHandle target = MH.insertArguments(Global.instance().INVALIDATE_RESERVED_NAME, 0, name); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2116 |
return new ConstantCallSite(target); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24733
diff
changeset
|
2117 |
} |
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24738
diff
changeset
|
2118 |
|
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24738
diff
changeset
|
2119 |
|
16147 | 2120 |
} |