mod

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 12 Imported by: 0

README

Module Execution

First the risk score is computed, if it's too high a prompt is shown to the user to confirm the execution.

If the bytecode interpretration is chosen the module is compiled & executed in the bytecode interpreter (VM). Otherwise the tree walk interpreter executes the module. If debugging is enabled the debugger is attached to the global state just before the execution starts.

Documentation

Index

Constants

View Source
const (
	DEFAULT_MAX_ALLOWED_WARNINGS = 10
)

Variables

View Source
var (
	ErrExecutionAbortedTooManyWarnings = errors.New("execution was aborted because there are too many warnings")
	ErrUserRefusedExecution            = errors.New("user refused execution")
	ErrNoProvidedConfirmExecPrompt     = errors.New("risk score too high and no provided way to show confirm prompt")
)

Functions

func RunLocalModule

func RunLocalModule(args RunLocalModuleArgs) (
	scriptResult core.Value, scriptState *core.GlobalState, scriptModule *core.Module,
	preparationSuccess bool, _err error,
)

RunLocalModule runs a module located in the filesystem.

func RunPreparedModule

func RunPreparedModule(args RunPreparedModuleArgs) (
	moduleResult core.Value, moduleState *core.GlobalState, module *core.Module,
	preparationSuccess bool, _err error,
)

RunPreparedModule runs a prepared module with the configuration specified in RunPreparedModuleArgs (e.g. .UseBytecode).

Types

type RunLocalModuleArgs

type RunLocalModuleArgs struct {
	Fpath                     string
	PassedCLIArgs             []string
	PassedArgs                *core.ModuleArgs
	ParsingCompilationContext *core.Context

	ParentContext         *core.Context
	ParentContextRequired bool              //make .ParentContext required
	StdlibCtx             context.Context   //should not be set if ParentContext is set
	AdditionalPermissions []core.Permission //should not be set if ParentContext is set

	//used during the preinit
	PreinitFilesystem afs.Filesystem

	//If nil the parent context's filesystem is used.
	//If there is no parent context the OS filesystem is used.
	ScriptContextFileSystem afs.Filesystem

	FullAccessToDatabases bool
	Project               *project.Project

	UseBytecode      bool
	OptimizeBytecode bool
	ShowBytecode     bool

	AllowMissingEnvVars bool
	IgnoreHighRiskScore bool

	EnableTesting bool
	TestFilters   core.TestFilters

	//if not nil AND UseBytecode is false the script is executed in debug mode with this debugger.
	//Debugger.AttachAndStart is called before starting the evaluation.
	//if nil the parent state's debugger is used if present.
	Debugger *core.Debugger

	//output for execution, if nil os.Stdout is used
	Out io.Writer

	//ignored if .Logger is set
	LogOut    io.Writer
	Logger    zerolog.Logger
	LogLevels *core.LogLevels

	//PreparedChan signals when the script is prepared (nil error) or failed to be prepared (non-nil error),
	//the channel should be buffered.
	PreparedChan chan error

	OnPrepared func(state *core.GlobalState) error
}

type RunPreparedModuleArgs

type RunPreparedModuleArgs struct {
	State                     *core.GlobalState
	ParsingCompilationContext *core.Context
	ParentContext             *core.Context

	//do not show the confirmation prompt to the user if the risk score is high.
	IgnoreHighRiskScore bool

	UseBytecode             bool
	OptimizeBytecode        bool
	ShowBytecode            bool
	DoNotCancelWhenFinished bool

	Debugger *core.Debugger
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL