The base class for Function objects. That is one of two purposes. It is also the prototype for every "function" defined except those that are used as GeneratorFunctions via the ES6 "function " syntax. See ECMA 15.3. @author Norris Boyd
| 24 | * @author Norris Boyd |
| 25 | */ |
| 26 | public class BaseFunction extends ScriptableObject implements Function { |
| 27 | @Serial private static final long serialVersionUID = 5311394446546053859L; |
| 28 | |
| 29 | private static final Object FUNCTION_TAG = "Function"; |
| 30 | private static final String FUNCTION_CLASS = "Function"; |
| 31 | static final SymbolKey GENERATOR_FUNCTION_CLASS = |
| 32 | new SymbolKey("GeneratorFunctionPrototype", REGULAR); |
| 33 | |
| 34 | private static final String APPLY_TAG = "APPLY_TAG"; |
| 35 | private static final String CALL_TAG = "CALL_TAG"; |
| 36 | private static final String PROTOTYPE_PROPERTY_NAME = "prototype"; |
| 37 | |
| 38 | private static final ClassDescriptor DESCRIPTOR; |
| 39 | private static final ClassDescriptor ES6_DESCRIPTOR; |
| 40 | private static final ClassDescriptor GENERATOR_DESCRIPTOR; |
| 41 | private static final JSDescriptor<JSFunction> APPLY_DESCRIPTOR; |
| 42 | private static final JSDescriptor<JSFunction> CALL_DESCRIPTOR; |
| 43 | |
| 44 | static { |
| 45 | var builder = |
| 46 | new ClassDescriptor.Builder( |
| 47 | FUNCTION_CLASS, |
| 48 | 1, |
| 49 | BaseFunction::js_constructor, |
| 50 | BaseFunction::js_constructor) |
| 51 | .withMethod(PROTO, "call", 1, BaseFunction::js_call) |
| 52 | .withMethod(PROTO, "apply", 2, BaseFunction::js_apply) |
| 53 | .withMethod(PROTO, "bind", 1, BaseFunction::js_bind) |
| 54 | .withMethod(PROTO, "toSource", 1, BaseFunction::js_toSource) |
| 55 | .withMethod(PROTO, "toString", 0, BaseFunction::js_toString) |
| 56 | .withMethod( |
| 57 | PROTO, |
| 58 | SymbolKey.HAS_INSTANCE, |
| 59 | 1, |
| 60 | BaseFunction::js_hasInstance, |
| 61 | DONTENUM | READONLY | PERMANENT, |
| 62 | DONTENUM | READONLY); |
| 63 | |
| 64 | DESCRIPTOR = builder.build(); |
| 65 | ES6_DESCRIPTOR = |
| 66 | builder.withProp( |
| 67 | PROTO, |
| 68 | "arguments", |
| 69 | BaseFunction::js_protoArgumentsGetter, |
| 70 | BaseFunction::js_protoArgumentsSetter, |
| 71 | DONTENUM | READONLY) |
| 72 | .build(); |
| 73 | |
| 74 | APPLY_DESCRIPTOR = DESCRIPTOR.findProtoDesc("apply"); |
| 75 | CALL_DESCRIPTOR = DESCRIPTOR.findProtoDesc("call"); |
| 76 | |
| 77 | GENERATOR_DESCRIPTOR = |
| 78 | new ClassDescriptor.Builder( |
| 79 | GENERATOR_FUNCTION_CLASS, |
| 80 | "GeneratorFunction", |
| 81 | 1, |
| 82 | BaseFunction::js_gen_constructor, |
| 83 | BaseFunction::js_gen_constructor) |
nothing calls this directly
no test coverage detected