javascript: pooling and reuse with export functions + misc updates #4709
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed Changes
anonymous functions
and should not modify global values to avoid collisions with other scripts/code when reusing a javascript runtimeWarning
Issue with implementing IIFE pattern is that values need to be returned explicitly instead of implicitly using last value as output but existing templates do not use
return
keyword and are based on implicit value usage pattern. but to effectively scale js templates reuse is a must, hence with this PR the existing pattern of last expression implicit logging will be soft deprecated and completely removed after some Minor releases [ but will continue to work for some time ]Current Last Value Implicit Output Pattern
^ This is example javascript code of how to log/store response ( just write / use it at end of execution )
New Style of log/store response for IIFE pattern
^ Only change is that to store / log response
Export()
helper function should be used . and this comes with feature additionsTip
Export(value any)
can be used multiple times (will append data) and anywhere in the program not necessarily on last lineto_json(resp)
anymore exporting withExport(resp)
will automatically return json if it is a struct/objectExportAs(key string,Value any)
helper functionExample Nuclei Runs
Current Last Value Implicit Output Pattern
New Export Function Output Pattern