mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2026-02-02 00:33:10 +08:00
* fuzz: rename 'filters' -> 'pre-condition'
* code proto: pre-condition + integration test
* feat: dsl document generator
* update dsl page header
* fix lint error
* add js defined helper funcs in docs
* remove panic recovery unless its for third party(go-rod,goja)
* handle dynamic values flattening edgecase in flow+multiprotocol
* fix order of kv in form-data (failing test)
* fix template loading counters
* Revert "handle dynamic values flattening edgecase in flow+multiprotocol"
This reverts commit 58fdd4faf7.
* fix flow iteration using 'iterate'
35 lines
934 B
Go
35 lines
934 B
Go
package gojs
|
|
|
|
import (
|
|
"github.com/dop251/goja"
|
|
errorutil "github.com/projectdiscovery/utils/errors"
|
|
)
|
|
|
|
var (
|
|
ErrInvalidFuncOpts = errorutil.NewWithFmt("invalid function options: %v")
|
|
ErrNilRuntime = errorutil.New("runtime is nil")
|
|
)
|
|
|
|
type FuncOpts struct {
|
|
Name string
|
|
Signatures []string
|
|
Description string
|
|
FuncDecl interface{}
|
|
}
|
|
|
|
// valid checks if the function options are valid
|
|
func (f *FuncOpts) valid() bool {
|
|
return f.Name != "" && f.FuncDecl != nil && len(f.Signatures) > 0 && f.Description != ""
|
|
}
|
|
|
|
// RegisterFunc registers a function with given name, signatures and description
|
|
func RegisterFuncWithSignature(runtime *goja.Runtime, opts FuncOpts) error {
|
|
if runtime == nil {
|
|
return ErrNilRuntime
|
|
}
|
|
if !opts.valid() {
|
|
return ErrInvalidFuncOpts.Msgf("name: %s, signatures: %v, description: %s", opts.Name, opts.Signatures, opts.Description)
|
|
}
|
|
return runtime.Set(opts.Name, opts.FuncDecl)
|
|
}
|