< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunctionData.java

Print this page

        

@@ -68,10 +68,13 @@
     // Parameter arity of the function, corresponding to "f.length". E.g. "function f(a, b, c) { ... }" arity is 3, and
     // some built-in ECMAScript functions have their arity declared by the specification. Note that regardless of this
     // value, the function might still be capable of receiving variable number of arguments, see isVariableArity.
     private int arity;
 
+    // this may be null, if not available
+    private String documentation;
+
     /**
      * A pair of method handles used for generic invoker and constructor. Field is volatile as it can be initialized by
      * multiple threads concurrently, but we still tolerate a race condition in it as all values stored into it are
      * idempotent.
      */

@@ -116,10 +119,14 @@
 
     final int getArity() {
         return arity;
     }
 
+    final String getDocumentation() {
+        return documentation != null? documentation : toSource();
+    }
+
     final boolean isVariableArity() {
         return (flags & IS_VARIABLE_ARITY) != 0;
     }
 
     final boolean isPropertyAccessor() {

@@ -135,10 +142,19 @@
             throw new IllegalArgumentException(String.valueOf(arity));
         }
         this.arity = arity;
     }
 
+    /**
+     * Used from nasgen generated code.
+     *
+     * @param doc documentation for this function
+     */
+    void setDocumentation(final String doc) {
+        this.documentation = doc;
+    }
+
     CompiledFunction bind(final CompiledFunction originalInv, final ScriptFunction fn, final Object self, final Object[] args) {
         final MethodHandle boundInvoker = bindInvokeHandle(originalInv.createComposableInvoker(), fn, self, args);
 
         if (isConstructor()) {
             return new CompiledFunction(boundInvoker, bindConstructHandle(originalInv.createComposableConstructor(), fn, args), null);
< prev index next >