author | sundar |
Sat, 09 Mar 2013 21:49:32 +0530 | |
changeset 16277 | fd698c5ee684 |
parent 16256 | f2d9a0c49914 |
child 17770 | 3c8602ec5565 |
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 |
||
28 |
import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; |
|
29 |
import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; |
|
30 |
import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.getArrayIndexNoThrow; |
|
16277 | 31 |
import static jdk.nashorn.internal.lookup.Lookup.MH; |
16147 | 32 |
|
33 |
import java.lang.invoke.MethodHandle; |
|
34 |
import java.lang.invoke.MethodHandles; |
|
35 |
import java.util.Arrays; |
|
36 |
import java.util.BitSet; |
|
37 |
import jdk.nashorn.internal.runtime.Property; |
|
38 |
import jdk.nashorn.internal.runtime.PropertyDescriptor; |
|
39 |
import jdk.nashorn.internal.runtime.PropertyMap; |
|
40 |
import jdk.nashorn.internal.runtime.ScriptFunction; |
|
41 |
import jdk.nashorn.internal.runtime.ScriptObject; |
|
42 |
import jdk.nashorn.internal.runtime.ScriptRuntime; |
|
43 |
import jdk.nashorn.internal.runtime.arrays.ArrayData; |
|
44 |
import jdk.nashorn.internal.runtime.arrays.ArrayIndex; |
|
16277 | 45 |
import jdk.nashorn.internal.lookup.Lookup; |
16147 | 46 |
|
47 |
/** |
|
48 |
* ECMA 10.6 Arguments Object. |
|
49 |
* |
|
50 |
* Arguments object used for non-strict mode functions. For strict mode, we use |
|
51 |
* a different implementation (@see NativeStrictArguments). In non-strict mode, |
|
52 |
* named argument access and index argument access (arguments[i]) are linked. |
|
53 |
* Modifications reflect on each other access -- till arguments indexed element |
|
54 |
* is deleted. After delete, there is no link between named access and indexed |
|
55 |
* access for that deleted index alone. |
|
56 |
*/ |
|
57 |
public final class NativeArguments extends ScriptObject { |
|
58 |
||
59 |
private static final MethodHandle G$LENGTH = findOwnMH("G$length", Object.class, Object.class); |
|
60 |
private static final MethodHandle S$LENGTH = findOwnMH("S$length", void.class, Object.class, Object.class); |
|
61 |
private static final MethodHandle G$CALLEE = findOwnMH("G$callee", Object.class, Object.class); |
|
62 |
private static final MethodHandle S$CALLEE = findOwnMH("S$callee", void.class, Object.class, Object.class); |
|
63 |
||
64 |
private static final PropertyMap nasgenmap$; |
|
65 |
||
66 |
static { |
|
67 |
PropertyMap map = PropertyMap.newMap(NativeArguments.class); |
|
68 |
map = Lookup.newProperty(map, "length", Property.NOT_ENUMERABLE, G$LENGTH, S$LENGTH); |
|
69 |
map = Lookup.newProperty(map, "callee", Property.NOT_ENUMERABLE, G$CALLEE, S$CALLEE); |
|
70 |
nasgenmap$ = map; |
|
71 |
} |
|
72 |
||
73 |
private Object length; |
|
74 |
private Object callee; |
|
75 |
private ArrayData namedArgs; |
|
76 |
// This is lazily initialized - only when delete is invoked at all |
|
77 |
private BitSet deleted; |
|
78 |
||
79 |
NativeArguments(final Object[] arguments, final Object callee, final int numParams) { |
|
80 |
super(nasgenmap$); |
|
81 |
setIsArguments(); |
|
82 |
||
83 |
setArray(ArrayData.allocate(arguments)); |
|
84 |
this.length = arguments.length; |
|
85 |
this.callee = callee; |
|
86 |
||
87 |
/** |
|
88 |
* Declared number of parameters may be more or less than the actual passed |
|
89 |
* runtime arguments count. We need to truncate or extend with undefined values. |
|
90 |
* |
|
91 |
* Example: |
|
92 |
* |
|
93 |
* // less declared params |
|
94 |
* (function (x) { print(arguments); })(20, 44); |
|
95 |
* |
|
96 |
* // more declared params |
|
97 |
* (function (x, y) { print(arguments); })(3); |
|
98 |
*/ |
|
99 |
final Object[] newValues = new Object[numParams]; |
|
100 |
if (numParams > arguments.length) { |
|
101 |
Arrays.fill(newValues, UNDEFINED); |
|
102 |
} |
|
103 |
System.arraycopy(arguments, 0, newValues, 0, Math.min(newValues.length, arguments.length)); |
|
104 |
this.namedArgs = ArrayData.allocate(newValues); |
|
105 |
||
106 |
// set Object.prototype as __proto__ |
|
107 |
this.setProto(Global.objectPrototype()); |
|
108 |
} |
|
109 |
||
110 |
@Override |
|
111 |
public String getClassName() { |
|
112 |
return "Arguments"; |
|
113 |
} |
|
114 |
||
115 |
/** |
|
116 |
* getArgument is used for named argument access. |
|
117 |
*/ |
|
118 |
@Override |
|
119 |
public Object getArgument(final int key) { |
|
120 |
return namedArgs.has(key) ? namedArgs.getObject(key) : UNDEFINED; |
|
121 |
} |
|
122 |
||
123 |
/** |
|
124 |
* setArgument is used for named argument set. |
|
125 |
*/ |
|
126 |
@Override |
|
127 |
public void setArgument(final int key, final Object value) { |
|
128 |
if (namedArgs.has(key)) { |
|
129 |
namedArgs.set(key, value, false); |
|
130 |
} |
|
131 |
} |
|
132 |
||
133 |
@Override |
|
134 |
public int getInt(final Object key) { |
|
135 |
final int index = getArrayIndexNoThrow(key); |
|
136 |
return isMapped(index) ? namedArgs.getInt(index) : super.getInt(key); |
|
137 |
} |
|
138 |
||
139 |
@Override |
|
140 |
public int getInt(final double key) { |
|
141 |
final int index = getArrayIndexNoThrow(key); |
|
142 |
return isMapped(index) ? namedArgs.getInt(index) : super.getInt(key); |
|
143 |
} |
|
144 |
||
145 |
@Override |
|
146 |
public int getInt(final long key) { |
|
147 |
final int index = getArrayIndexNoThrow(key); |
|
148 |
return isMapped(index) ? namedArgs.getInt(index) : super.getInt(key); |
|
149 |
} |
|
150 |
||
151 |
@Override |
|
152 |
public int getInt(final int key) { |
|
153 |
final int index = getArrayIndexNoThrow(key); |
|
154 |
return isMapped(index) ? namedArgs.getInt(index) : super.getInt(key); |
|
155 |
} |
|
156 |
||
157 |
@Override |
|
158 |
public long getLong(final Object key) { |
|
159 |
final int index = getArrayIndexNoThrow(key); |
|
160 |
return isMapped(index) ? namedArgs.getLong(index) : super.getLong(key); |
|
161 |
} |
|
162 |
||
163 |
@Override |
|
164 |
public long getLong(final double key) { |
|
165 |
final int index = getArrayIndexNoThrow(key); |
|
166 |
return isMapped(index) ? namedArgs.getLong(index) : super.getLong(key); |
|
167 |
} |
|
168 |
||
169 |
@Override |
|
170 |
public long getLong(final long key) { |
|
171 |
final int index = getArrayIndexNoThrow(key); |
|
172 |
return isMapped(index) ? namedArgs.getLong(index) : super.getLong(key); |
|
173 |
} |
|
174 |
||
175 |
@Override |
|
176 |
public long getLong(final int key) { |
|
177 |
final int index = getArrayIndexNoThrow(key); |
|
178 |
return isMapped(index) ? namedArgs.getLong(index) : super.getLong(key); |
|
179 |
} |
|
180 |
||
181 |
@Override |
|
182 |
public double getDouble(final Object key) { |
|
183 |
final int index = getArrayIndexNoThrow(key); |
|
184 |
return isMapped(index) ? namedArgs.getDouble(index) : super.getDouble(key); |
|
185 |
} |
|
186 |
||
187 |
@Override |
|
188 |
public double getDouble(final double key) { |
|
189 |
final int index = getArrayIndexNoThrow(key); |
|
190 |
return isMapped(index) ? namedArgs.getDouble(index) : super.getDouble(key); |
|
191 |
} |
|
192 |
||
193 |
@Override |
|
194 |
public double getDouble(final long key) { |
|
195 |
final int index = getArrayIndexNoThrow(key); |
|
196 |
return isMapped(index) ? namedArgs.getDouble(index) : super.getDouble(key); |
|
197 |
} |
|
198 |
||
199 |
@Override |
|
200 |
public double getDouble(final int key) { |
|
201 |
final int index = getArrayIndexNoThrow(key); |
|
202 |
return isMapped(index) ? namedArgs.getDouble(index) : super.getDouble(key); |
|
203 |
} |
|
204 |
||
205 |
@Override |
|
206 |
public Object get(final Object key) { |
|
207 |
final int index = getArrayIndexNoThrow(key); |
|
208 |
return isMapped(index) ? namedArgs.getObject(index) : super.get(key); |
|
209 |
} |
|
210 |
||
211 |
@Override |
|
212 |
public Object get(final double key) { |
|
213 |
final int index = getArrayIndexNoThrow(key); |
|
214 |
return isMapped(index) ? namedArgs.getObject(index) : super.get(key); |
|
215 |
} |
|
216 |
||
217 |
@Override |
|
218 |
public Object get(final long key) { |
|
219 |
final int index = getArrayIndexNoThrow(key); |
|
220 |
return isMapped(index) ? namedArgs.getObject(index) : super.get(key); |
|
221 |
} |
|
222 |
||
223 |
@Override |
|
224 |
public Object get(final int key) { |
|
225 |
final int index = getArrayIndexNoThrow(key); |
|
226 |
return isMapped(index) ? namedArgs.getObject(index) : super.get(key); |
|
227 |
} |
|
228 |
||
229 |
@Override |
|
230 |
public void set(final Object key, final int value, final boolean strict) { |
|
231 |
final int index = getArrayIndexNoThrow(key); |
|
232 |
if (isMapped(index)) { |
|
233 |
namedArgs = namedArgs.set(index, value, strict); |
|
234 |
} else { |
|
235 |
super.set(key, value, strict); |
|
236 |
} |
|
237 |
} |
|
238 |
||
239 |
@Override |
|
240 |
public void set(final Object key, final long value, final boolean strict) { |
|
241 |
final int index = getArrayIndexNoThrow(key); |
|
242 |
if (isMapped(index)) { |
|
243 |
namedArgs = namedArgs.set(index, value, strict); |
|
244 |
} else { |
|
245 |
super.set(key, value, strict); |
|
246 |
} |
|
247 |
} |
|
248 |
||
249 |
@Override |
|
250 |
public void set(final Object key, final double value, final boolean strict) { |
|
251 |
final int index = getArrayIndexNoThrow(key); |
|
252 |
if (isMapped(index)) { |
|
253 |
namedArgs = namedArgs.set(index, value, strict); |
|
254 |
} else { |
|
255 |
super.set(key, value, strict); |
|
256 |
} |
|
257 |
} |
|
258 |
||
259 |
@Override |
|
260 |
public void set(final Object key, final Object value, final boolean strict) { |
|
261 |
final int index = getArrayIndexNoThrow(key); |
|
262 |
if (isMapped(index)) { |
|
263 |
namedArgs = namedArgs.set(index, value, strict); |
|
264 |
} else { |
|
265 |
super.set(key, value, strict); |
|
266 |
} |
|
267 |
} |
|
268 |
||
269 |
@Override |
|
270 |
public void set(final double key, final int value, final boolean strict) { |
|
271 |
final int index = getArrayIndexNoThrow(key); |
|
272 |
if (isMapped(index)) { |
|
273 |
namedArgs = namedArgs.set(index, value, strict); |
|
274 |
} else { |
|
275 |
super.set(key, value, strict); |
|
276 |
} |
|
277 |
} |
|
278 |
||
279 |
@Override |
|
280 |
public void set(final double key, final long value, final boolean strict) { |
|
281 |
final int index = getArrayIndexNoThrow(key); |
|
282 |
if (isMapped(index)) { |
|
283 |
namedArgs = namedArgs.set(index, value, strict); |
|
284 |
} else { |
|
285 |
super.set(key, value, strict); |
|
286 |
} |
|
287 |
} |
|
288 |
||
289 |
@Override |
|
290 |
public void set(final double key, final double value, final boolean strict) { |
|
291 |
final int index = getArrayIndexNoThrow(key); |
|
292 |
if (isMapped(index)) { |
|
293 |
namedArgs = namedArgs.set(index, value, strict); |
|
294 |
} else { |
|
295 |
super.set(key, value, strict); |
|
296 |
} |
|
297 |
} |
|
298 |
||
299 |
@Override |
|
300 |
public void set(final double key, final Object value, final boolean strict) { |
|
301 |
final int index = getArrayIndexNoThrow(key); |
|
302 |
if (isMapped(index)) { |
|
303 |
namedArgs = namedArgs.set(index, value, strict); |
|
304 |
} else { |
|
305 |
super.set(key, value, strict); |
|
306 |
} |
|
307 |
} |
|
308 |
||
309 |
@Override |
|
310 |
public void set(final long key, final int value, final boolean strict) { |
|
311 |
final int index = getArrayIndexNoThrow(key); |
|
312 |
if (isMapped(index)) { |
|
313 |
namedArgs = namedArgs.set(index, value, strict); |
|
314 |
} else { |
|
315 |
super.set(key, value, strict); |
|
316 |
} |
|
317 |
} |
|
318 |
||
319 |
@Override |
|
320 |
public void set(final long key, final long value, final boolean strict) { |
|
321 |
final int index = getArrayIndexNoThrow(key); |
|
322 |
if (isMapped(index)) { |
|
323 |
namedArgs = namedArgs.set(index, value, strict); |
|
324 |
} else { |
|
325 |
super.set(key, value, strict); |
|
326 |
} |
|
327 |
} |
|
328 |
||
329 |
@Override |
|
330 |
public void set(final long key, final double value, final boolean strict) { |
|
331 |
final int index = getArrayIndexNoThrow(key); |
|
332 |
if (isMapped(index)) { |
|
333 |
namedArgs = namedArgs.set(index, value, strict); |
|
334 |
} else { |
|
335 |
super.set(key, value, strict); |
|
336 |
} |
|
337 |
} |
|
338 |
||
339 |
@Override |
|
340 |
public void set(final long key, final Object value, final boolean strict) { |
|
341 |
final int index = getArrayIndexNoThrow(key); |
|
342 |
if (isMapped(index)) { |
|
343 |
namedArgs = namedArgs.set(index, value, strict); |
|
344 |
} else { |
|
345 |
super.set(key, value, strict); |
|
346 |
} |
|
347 |
} |
|
348 |
||
349 |
@Override |
|
350 |
public void set(final int key, final int value, final boolean strict) { |
|
351 |
final int index = getArrayIndexNoThrow(key); |
|
352 |
if (isMapped(index)) { |
|
353 |
namedArgs = namedArgs.set(index, value, strict); |
|
354 |
} else { |
|
355 |
super.set(key, value, strict); |
|
356 |
} |
|
357 |
} |
|
358 |
||
359 |
@Override |
|
360 |
public void set(final int key, final long value, final boolean strict) { |
|
361 |
final int index = getArrayIndexNoThrow(key); |
|
362 |
if (isMapped(index)) { |
|
363 |
namedArgs = namedArgs.set(index, value, strict); |
|
364 |
} else { |
|
365 |
super.set(key, value, strict); |
|
366 |
} |
|
367 |
} |
|
368 |
||
369 |
@Override |
|
370 |
public void set(final int key, final double value, final boolean strict) { |
|
371 |
final int index = getArrayIndexNoThrow(key); |
|
372 |
if (isMapped(index)) { |
|
373 |
namedArgs = namedArgs.set(index, value, strict); |
|
374 |
} else { |
|
375 |
super.set(key, value, strict); |
|
376 |
} |
|
377 |
} |
|
378 |
||
379 |
@Override |
|
380 |
public void set(final int key, final Object value, final boolean strict) { |
|
381 |
final int index = getArrayIndexNoThrow(key); |
|
382 |
if (isMapped(index)) { |
|
383 |
namedArgs = namedArgs.set(index, value, strict); |
|
384 |
} else { |
|
385 |
super.set(key, value, strict); |
|
386 |
} |
|
387 |
} |
|
388 |
||
389 |
@Override |
|
390 |
public boolean has(final Object key) { |
|
391 |
final int index = getArrayIndexNoThrow(key); |
|
392 |
return isMapped(index) || super.has(key); |
|
393 |
} |
|
394 |
||
395 |
@Override |
|
396 |
public boolean has(final double key) { |
|
397 |
final int index = getArrayIndexNoThrow(key); |
|
398 |
return isMapped(index) || super.has(key); |
|
399 |
} |
|
400 |
||
401 |
@Override |
|
402 |
public boolean has(final long key) { |
|
403 |
final int index = getArrayIndexNoThrow(key); |
|
404 |
return isMapped(index) || super.has(key); |
|
405 |
} |
|
406 |
||
407 |
@Override |
|
408 |
public boolean has(final int key) { |
|
409 |
final int index = getArrayIndexNoThrow(key); |
|
410 |
return isMapped(index) || super.has(key); |
|
411 |
} |
|
412 |
||
413 |
@Override |
|
414 |
public boolean hasOwnProperty(final Object key) { |
|
415 |
final int index = getArrayIndexNoThrow(key); |
|
416 |
return isMapped(index) || super.hasOwnProperty(key); |
|
417 |
} |
|
418 |
||
419 |
@Override |
|
420 |
public boolean hasOwnProperty(final int key) { |
|
421 |
final int index = getArrayIndexNoThrow(key); |
|
422 |
return isMapped(index) || super.hasOwnProperty(key); |
|
423 |
} |
|
424 |
||
425 |
@Override |
|
426 |
public boolean hasOwnProperty(final long key) { |
|
427 |
final int index = getArrayIndexNoThrow(key); |
|
428 |
return isMapped(index) || super.hasOwnProperty(key); |
|
429 |
} |
|
430 |
||
431 |
@Override |
|
432 |
public boolean hasOwnProperty(final double key) { |
|
433 |
final int index = getArrayIndexNoThrow(key); |
|
434 |
return isMapped(index) || super.hasOwnProperty(key); |
|
435 |
} |
|
436 |
||
437 |
@Override |
|
438 |
public boolean delete(final int key, final boolean strict) { |
|
439 |
final int index = getArrayIndexNoThrow(key); |
|
440 |
final boolean success = super.delete(key, strict); |
|
441 |
if (success && namedArgs.has(index)) { |
|
442 |
setDeleted(index); |
|
443 |
} |
|
444 |
return success; |
|
445 |
} |
|
446 |
||
447 |
@Override |
|
448 |
public boolean delete(final long key, final boolean strict) { |
|
449 |
final int index = getArrayIndexNoThrow(key); |
|
450 |
final boolean success = super.delete(key, strict); |
|
451 |
if (success && namedArgs.has(index)) { |
|
452 |
setDeleted(index); |
|
453 |
} |
|
454 |
return success; |
|
455 |
} |
|
456 |
||
457 |
@Override |
|
458 |
public boolean delete(final double key, final boolean strict) { |
|
459 |
final int index = getArrayIndexNoThrow(key); |
|
460 |
final boolean success = super.delete(key, strict); |
|
461 |
if (success && namedArgs.has(index)) { |
|
462 |
setDeleted(index); |
|
463 |
} |
|
464 |
return success; |
|
465 |
} |
|
466 |
||
467 |
@Override |
|
468 |
public boolean delete(final Object key, final boolean strict) { |
|
469 |
final int index = getArrayIndexNoThrow(key); |
|
470 |
final boolean success = super.delete(key, strict); |
|
471 |
if (success && namedArgs.has(index)) { |
|
472 |
setDeleted(index); |
|
473 |
} |
|
474 |
return success; |
|
475 |
} |
|
476 |
||
477 |
/** |
|
478 |
* ECMA 15.4.5.1 [[DefineOwnProperty]] ( P, Desc, Throw ) as specialized in |
|
479 |
* ECMA 10.6 for Arguments object. |
|
480 |
*/ |
|
481 |
@Override |
|
482 |
public boolean defineOwnProperty(final String key, final Object propertyDesc, final boolean reject) { |
|
483 |
final int index = ArrayIndex.getArrayIndexNoThrow(key); |
|
484 |
if (index >= 0) { |
|
485 |
final boolean allowed = super.defineOwnProperty(key, propertyDesc, false); |
|
486 |
if (!allowed) { |
|
487 |
if (reject) { |
|
16256
f2d9a0c49914
8007002: Replace implicit exception throwing methods with explicit throws - simplify control flow and remove useless code
lagergren
parents:
16206
diff
changeset
|
488 |
throw typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this)); |
16147 | 489 |
} |
490 |
return false; |
|
491 |
} |
|
492 |
||
493 |
if (isMapped(index)) { |
|
494 |
// When mapped argument is redefined, if new descriptor is accessor property |
|
495 |
// or data-non-writable property, we have to "unmap" (unlink). |
|
496 |
final PropertyDescriptor desc = toPropertyDescriptor(Global.instance(), propertyDesc); |
|
497 |
if (desc.type() == PropertyDescriptor.ACCESSOR) { |
|
498 |
setDeleted(index); |
|
499 |
} else { |
|
500 |
// set "value" from new descriptor to named args |
|
501 |
if (desc.has(PropertyDescriptor.VALUE)) { |
|
502 |
namedArgs = namedArgs.set(index, desc.getValue(), false); |
|
503 |
} |
|
504 |
||
505 |
if (desc.has(PropertyDescriptor.WRITABLE) && !desc.isWritable()) { |
|
506 |
setDeleted(index); |
|
507 |
} |
|
508 |
} |
|
509 |
} |
|
510 |
||
511 |
return true; |
|
512 |
} |
|
513 |
||
514 |
return super.defineOwnProperty(key, propertyDesc, reject); |
|
515 |
} |
|
516 |
||
517 |
// Internals below this point |
|
518 |
||
519 |
// We track deletions using a bit set (delete arguments[index]) |
|
520 |
private boolean isDeleted(final int index) { |
|
521 |
return (deleted != null) ? deleted.get(index) : false; |
|
522 |
} |
|
523 |
||
524 |
private void setDeleted(final int index) { |
|
525 |
if (deleted == null) { |
|
526 |
deleted = new BitSet((int)namedArgs.length()); |
|
527 |
} |
|
528 |
deleted.set(index, true); |
|
529 |
} |
|
530 |
||
531 |
/** |
|
532 |
* Are arguments[index] and corresponding named parameter linked? |
|
533 |
* |
|
534 |
* In non-strict mode, arguments[index] and corresponding named param |
|
535 |
* are "linked" or "mapped". Modifications are tacked b/w each other - till |
|
536 |
* (delete arguments[index]) is used. Once deleted, the corresponding arg |
|
537 |
* is no longer 'mapped'. Please note that delete can happen only through |
|
538 |
* the arguments array - named param can not be deleted. (delete is one-way). |
|
539 |
*/ |
|
540 |
private boolean isMapped(final int index) { |
|
541 |
// in named args and not marked as "deleted" |
|
542 |
return namedArgs.has(index) && !isDeleted(index); |
|
543 |
} |
|
544 |
||
545 |
/** |
|
546 |
* Factory to create correct Arguments object based on strict mode. |
|
547 |
* |
|
548 |
* @param arguments the actual arguments array passed |
|
549 |
* @param callee the callee function that uses arguments object |
|
550 |
* @param numParams the number of declared (named) function parameters |
|
551 |
* @return Arguments Object |
|
552 |
*/ |
|
553 |
public static ScriptObject allocate(final Object[] arguments, final ScriptFunction callee, final int numParams) { |
|
16206
83069fa0935b
8006529: Methods always get callee - it should be conditional
attila
parents:
16188
diff
changeset
|
554 |
// Strict functions won't always have a callee for arguments, and will pass null instead. |
83069fa0935b
8006529: Methods always get callee - it should be conditional
attila
parents:
16188
diff
changeset
|
555 |
final boolean isStrict = callee == null || callee.isStrict(); |
16147 | 556 |
return isStrict ? new NativeStrictArguments(arguments, numParams) : new NativeArguments(arguments, callee, numParams); |
557 |
} |
|
558 |
||
559 |
/** |
|
560 |
* Length getter |
|
561 |
* @param self self reference |
|
562 |
* @return length property value |
|
563 |
*/ |
|
564 |
public static Object G$length(final Object self) { |
|
565 |
if (self instanceof NativeArguments) { |
|
566 |
return ((NativeArguments)self).getArgumentsLength(); |
|
567 |
} |
|
568 |
||
569 |
return 0; |
|
570 |
} |
|
571 |
||
572 |
/** |
|
573 |
* Length setter |
|
574 |
* @param self self reference |
|
575 |
* @param value value for length property |
|
576 |
*/ |
|
577 |
public static void S$length(final Object self, final Object value) { |
|
578 |
if (self instanceof NativeArguments) { |
|
579 |
((NativeArguments)self).setArgumentsLength(value); |
|
580 |
} |
|
581 |
} |
|
582 |
||
583 |
/** |
|
584 |
* Callee getter |
|
585 |
* @param self self reference |
|
586 |
* @return value for callee property |
|
587 |
*/ |
|
588 |
public static Object G$callee(final Object self) { |
|
589 |
if (self instanceof NativeArguments) { |
|
590 |
return ((NativeArguments)self).getCallee(); |
|
591 |
} |
|
592 |
return UNDEFINED; |
|
593 |
} |
|
594 |
||
595 |
/** |
|
596 |
* Callee setter |
|
597 |
* @param self self reference |
|
598 |
* @param value value for callee property |
|
599 |
*/ |
|
600 |
public static void S$callee(final Object self, final Object value) { |
|
601 |
if (self instanceof NativeArguments) { |
|
602 |
((NativeArguments)self).setCallee(value); |
|
603 |
} |
|
604 |
} |
|
605 |
||
606 |
private Object getArgumentsLength() { |
|
607 |
return length; |
|
608 |
} |
|
609 |
||
610 |
private void setArgumentsLength(final Object length) { |
|
611 |
this.length = length; |
|
612 |
} |
|
613 |
||
614 |
private Object getCallee() { |
|
615 |
return callee; |
|
616 |
} |
|
617 |
||
618 |
private void setCallee(final Object callee) { |
|
619 |
this.callee = callee; |
|
620 |
} |
|
621 |
||
622 |
private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) { |
|
16181
f6a125580f62
8006562: findOwnMH in nashorn "objects" package should be cleaned up
sundar
parents:
16151
diff
changeset
|
623 |
return MH.findStatic(MethodHandles.publicLookup(), NativeArguments.class, name, MH.type(rtype, types)); |
16147 | 624 |
} |
625 |
||
626 |
} |