98762d6ee0
Co-authored-by: Akhil Arora <akhil.arora@oracle.com> Co-authored-by: Andreas Woess <andreas.woess@jku.at> Co-authored-by: Attila Szegedi <attila.szegedi@oracle.com> Co-authored-by: Hannes Wallnoefer <hannes.wallnoefer@oracle.com> Co-authored-by: Henry Jen <henry.jen@oracle.com> Co-authored-by: Marcus Lagergren <marcus.lagergren@oracle.com> Co-authored-by: Pavel Semenov <pavel.semenov@oracle.com> Co-authored-by: Pavel Stepanov <pavel.stepanov@oracle.com> Co-authored-by: Petr Hejl <petr.hejl@oracle.com> Co-authored-by: Petr Pisl <petr.pisl@oracle.com> Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com> Reviewed-by: attila, hannesw, lagergren, sundar
35 lines
1.8 KiB
Plaintext
35 lines
1.8 KiB
Plaintext
Nasgen is a tool for processing Java classes that implement native
|
|
JavaScript objects. It does so by looking for the
|
|
com.oracle.nashorn.objects.annotations.ScriptClass annotation and other
|
|
annotations in that package.
|
|
|
|
For each class "C", nasgen instruments the original class and generates
|
|
two additional classes: a "C$Prototype" class for the JavaScript
|
|
prototype object, and a "C$Constructor" class for the JavaScript
|
|
constructor function.
|
|
|
|
Each class instrumented or generated by nasgen contains a private static
|
|
"$nasgenmap$" field of type com.oracle.nashorn.runtime.PropertyMap and
|
|
static initializer block to initialize the field to the object's
|
|
JavaScript properties.
|
|
|
|
Members annotated with @Function, @Property, @Getter, and @Setter are
|
|
mapped to the $Constructor, $Prototype, or main class, depending on the
|
|
value of the annotation's 'where' field. By default, @Property, @Getter,
|
|
and @Setter belong to the main class while @Function methods without
|
|
explicit 'where' field belong to the $Prototype class. The @Constructor
|
|
annotation marks a method to be invoked as JavaScript constructor.
|
|
|
|
Nasgen enforces all @Function/@Getter/@Setter/@Constructor annotated
|
|
methods to be declared as static. Static final @Property fields remain
|
|
in the main class while other @Property fields are moved to respective
|
|
classes depending on the annotation's 'where' value. For functions
|
|
mapped to the $Prototype or $Constructor class, nasgen also generates
|
|
getters and setters prefixed by G$ and S$, respectively.
|
|
|
|
Nasgen-generated classes are hidden from normal ClassLoaders by giving
|
|
them a ".clazz" file name extension instead of the standard ".class"
|
|
extension. This allows script classes to be loaded independently by each
|
|
Nashorn context through the com.oracle.nashorn.runtime.StructureLoader
|
|
class loader.
|