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.runtime;
27
28 import static jdk.nashorn.internal.codegen.CompilerConstants.virtualCallNoLookup;
29 import static jdk.nashorn.internal.lookup.Lookup.MH;
30 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
31 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
32
33 import java.lang.invoke.MethodHandle;
34 import java.lang.invoke.MethodHandles;
35 import java.lang.invoke.MethodType;
36 import jdk.internal.dynalink.CallSiteDescriptor;
37 import jdk.internal.dynalink.linker.GuardedInvocation;
38 import jdk.internal.dynalink.linker.LinkRequest;
39 import jdk.nashorn.internal.codegen.CompilerConstants.Call;
40 import jdk.nashorn.internal.lookup.MethodHandleFactory;
41 import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
42 import jdk.nashorn.internal.runtime.linker.NashornGuards;
43
44 /**
45 * Runtime representation of a JavaScript function.
46 */
47 public abstract class ScriptFunction extends ScriptObject {
48
49 /** Method handle for prototype getter for this ScriptFunction */
50 public static final MethodHandle G$PROTOTYPE = findOwnMH("G$prototype", Object.class, Object.class);
51
52 /** Method handle for prototype setter for this ScriptFunction */
53 public static final MethodHandle S$PROTOTYPE = findOwnMH("S$prototype", void.class, Object.class, Object.class);
54
55 /** Method handle for length getter for this ScriptFunction */
56 public static final MethodHandle G$LENGTH = findOwnMH("G$length", int.class, Object.class);
57
58 /** Method handle for name getter for this ScriptFunction */
59 public static final MethodHandle G$NAME = findOwnMH("G$name", Object.class, Object.class);
60
458 }
459
460 /**
461 * @return the allocations
462 */
463 public static int getAllocations() {
464 return allocations;
465 }
466
467 @Override
468 protected GuardedInvocation findNewMethod(final CallSiteDescriptor desc) {
469 final MethodType type = desc.getMethodType();
470 return new GuardedInvocation(pairArguments(data.getBestConstructor(type.changeParameterType(0, ScriptFunction.class), null), type), null, getFunctionGuard(this));
471 }
472
473 @SuppressWarnings("unused")
474 private static Object wrapFilter(final Object obj) {
475 if (obj instanceof ScriptObject || !ScriptFunctionData.isPrimitiveThis(obj)) {
476 return obj;
477 }
478 return ((GlobalObject)Context.getGlobalTrusted()).wrapAsObject(obj);
479 }
480
481
482 @SuppressWarnings("unused")
483 private static Object globalFilter(final Object object) {
484 // replace whatever we get with the current global object
485 return Context.getGlobalTrusted();
486 }
487
488 /**
489 * dyn:call call site signature: (callee, thiz, [args...])
490 * generated method signature: (callee, thiz, [args...])
491 *
492 * cases:
493 * (a) method has callee parameter
494 * (1) for local/scope calls, we just bind thiz and drop the second argument.
495 * (2) for normal this-calls, we have to swap thiz and callee to get matching signatures.
496 * (b) method doesn't have callee parameter (builtin functions)
497 * (3) for local/scope calls, bind thiz and drop both callee and thiz.
498 * (4) for normal this-calls, drop callee.
499 */
500 @Override
501 protected GuardedInvocation findCallMethod(final CallSiteDescriptor desc, final LinkRequest request) {
502 final MethodType type = desc.getMethodType();
503 final boolean scopeCall = NashornCallSiteDescriptor.isScope(desc);
504
505 if (request.isCallSiteUnstable()) {
|
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.runtime;
27
28 import static jdk.nashorn.internal.codegen.CompilerConstants.virtualCallNoLookup;
29 import static jdk.nashorn.internal.lookup.Lookup.MH;
30 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
31 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
32
33 import java.lang.invoke.MethodHandle;
34 import java.lang.invoke.MethodHandles;
35 import java.lang.invoke.MethodType;
36 import jdk.internal.dynalink.CallSiteDescriptor;
37 import jdk.internal.dynalink.linker.GuardedInvocation;
38 import jdk.internal.dynalink.linker.LinkRequest;
39 import jdk.nashorn.internal.codegen.CompilerConstants.Call;
40 import jdk.nashorn.internal.lookup.MethodHandleFactory;
41 import jdk.nashorn.internal.objects.Global;
42 import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
43 import jdk.nashorn.internal.runtime.linker.NashornGuards;
44
45 /**
46 * Runtime representation of a JavaScript function.
47 */
48 public abstract class ScriptFunction extends ScriptObject {
49
50 /** Method handle for prototype getter for this ScriptFunction */
51 public static final MethodHandle G$PROTOTYPE = findOwnMH("G$prototype", Object.class, Object.class);
52
53 /** Method handle for prototype setter for this ScriptFunction */
54 public static final MethodHandle S$PROTOTYPE = findOwnMH("S$prototype", void.class, Object.class, Object.class);
55
56 /** Method handle for length getter for this ScriptFunction */
57 public static final MethodHandle G$LENGTH = findOwnMH("G$length", int.class, Object.class);
58
59 /** Method handle for name getter for this ScriptFunction */
60 public static final MethodHandle G$NAME = findOwnMH("G$name", Object.class, Object.class);
61
459 }
460
461 /**
462 * @return the allocations
463 */
464 public static int getAllocations() {
465 return allocations;
466 }
467
468 @Override
469 protected GuardedInvocation findNewMethod(final CallSiteDescriptor desc) {
470 final MethodType type = desc.getMethodType();
471 return new GuardedInvocation(pairArguments(data.getBestConstructor(type.changeParameterType(0, ScriptFunction.class), null), type), null, getFunctionGuard(this));
472 }
473
474 @SuppressWarnings("unused")
475 private static Object wrapFilter(final Object obj) {
476 if (obj instanceof ScriptObject || !ScriptFunctionData.isPrimitiveThis(obj)) {
477 return obj;
478 }
479 return Context.getGlobal().wrapAsObject(obj);
480 }
481
482
483 @SuppressWarnings("unused")
484 private static Object globalFilter(final Object object) {
485 // replace whatever we get with the current global object
486 return Context.getGlobal();
487 }
488
489 /**
490 * dyn:call call site signature: (callee, thiz, [args...])
491 * generated method signature: (callee, thiz, [args...])
492 *
493 * cases:
494 * (a) method has callee parameter
495 * (1) for local/scope calls, we just bind thiz and drop the second argument.
496 * (2) for normal this-calls, we have to swap thiz and callee to get matching signatures.
497 * (b) method doesn't have callee parameter (builtin functions)
498 * (3) for local/scope calls, bind thiz and drop both callee and thiz.
499 * (4) for normal this-calls, drop callee.
500 */
501 @Override
502 protected GuardedInvocation findCallMethod(final CallSiteDescriptor desc, final LinkRequest request) {
503 final MethodType type = desc.getMethodType();
504 final boolean scopeCall = NashornCallSiteDescriptor.isScope(desc);
505
506 if (request.isCallSiteUnstable()) {
|