24 */ 25 26 package jdk.nashorn.internal.runtime; 27 28 import static jdk.nashorn.internal.lookup.Lookup.MH; 29 30 import java.lang.invoke.MethodHandle; 31 32 /** 33 * This is a subclass that represents a script function that may not be regenerated. 34 * This is used for example for bound functions and builtins. 35 */ 36 final class FinalScriptFunctionData extends ScriptFunctionData { 37 38 /** 39 * Constructor - used for bind 40 * 41 * @param name name 42 * @param arity arity 43 * @param functions precompiled code 44 * @param isStrict strict 45 * @param isBuiltin builtin 46 * @param isConstructor constructor 47 */ 48 FinalScriptFunctionData(final String name, int arity, CompiledFunctions functions, final boolean isStrict, final boolean isBuiltin, final boolean isConstructor) { 49 super(name, arity, isStrict, isBuiltin, isConstructor); 50 code.addAll(functions); 51 } 52 53 /** 54 * Constructor - used from ScriptFunction. This assumes that we have code alraedy for the 55 * method (typically a native method) and possibly specializations. 56 * 57 * @param name name 58 * @param mh method handle for generic version of method 59 * @param specs specializations 60 * @param isStrict strict 61 * @param isBuiltin builtin 62 * @param isConstructor constructor 63 */ 64 FinalScriptFunctionData(final String name, final MethodHandle mh, final MethodHandle[] specs, final boolean isStrict, final boolean isBuiltin, final boolean isConstructor) { 65 super(name, arity(mh), isStrict, isBuiltin, isConstructor); 66 67 addInvoker(mh); 68 if (specs != null) { 69 for (final MethodHandle spec : specs) { 70 addInvoker(spec); 71 } 72 } 73 } 74 75 private void addInvoker(final MethodHandle mh) { 76 if (isConstructor(mh)) { 77 // only nasgen constructors: (boolean, self, args) are subject to binding a boolean newObj. isConstructor 78 // is too conservative a check. However, isConstructor(mh) always implies isConstructor param 79 assert isConstructor(); 80 final MethodHandle invoker = MH.insertArguments(mh, 0, false); 81 final MethodHandle constructor = composeConstructor(MH.insertArguments(mh, 0, true)); 82 code.add(new CompiledFunction(mh.type(), invoker, constructor)); 83 } else { 84 code.add(new CompiledFunction(mh.type(), mh)); 85 } | 24 */ 25 26 package jdk.nashorn.internal.runtime; 27 28 import static jdk.nashorn.internal.lookup.Lookup.MH; 29 30 import java.lang.invoke.MethodHandle; 31 32 /** 33 * This is a subclass that represents a script function that may not be regenerated. 34 * This is used for example for bound functions and builtins. 35 */ 36 final class FinalScriptFunctionData extends ScriptFunctionData { 37 38 /** 39 * Constructor - used for bind 40 * 41 * @param name name 42 * @param arity arity 43 * @param functions precompiled code 44 * @param flags {@link ScriptFunctionData} flags 45 */ 46 FinalScriptFunctionData(final String name, final int arity, final CompiledFunctions functions, final int flags) { 47 super(name, arity, flags); 48 code.addAll(functions); 49 } 50 51 /** 52 * Constructor - used from ScriptFunction. This assumes that we have code already for the 53 * method (typically a native method) and possibly specializations. 54 * 55 * @param name name 56 * @param mh method handle for generic version of method 57 * @param specs specializations 58 * @param flags {@link ScriptFunctionData} flags 59 */ 60 FinalScriptFunctionData(final String name, final MethodHandle mh, final MethodHandle[] specs, final int flags) { 61 super(name, arity(mh), flags); 62 63 addInvoker(mh); 64 if (specs != null) { 65 for (final MethodHandle spec : specs) { 66 addInvoker(spec); 67 } 68 } 69 } 70 71 private void addInvoker(final MethodHandle mh) { 72 if (isConstructor(mh)) { 73 // only nasgen constructors: (boolean, self, args) are subject to binding a boolean newObj. isConstructor 74 // is too conservative a check. However, isConstructor(mh) always implies isConstructor param 75 assert isConstructor(); 76 final MethodHandle invoker = MH.insertArguments(mh, 0, false); 77 final MethodHandle constructor = composeConstructor(MH.insertArguments(mh, 0, true)); 78 code.add(new CompiledFunction(mh.type(), invoker, constructor)); 79 } else { 80 code.add(new CompiledFunction(mh.type(), mh)); 81 } |