Skip to content

Support for APIs that expose the internal state of the VM #667

@sixletters

Description

@sixletters

Currently, we are building a wrapper around Goja and building a script debugger. However, we would like to show state of the code (local variables, the environment stack etc). However as of today, Goja does not provide user APIs to get the local variables/lexical environment at a point in time.

An example of how it could be used would be as following.

vm := goja.New()
// run some JS that enters multiple function scopes

stack := vm.DumpEnvironmentStack()
for i, env := range stack {
    fmt.Printf("Frame %d:\n", i)
    for k, v := range env {
        fmt.Printf("  %s = %v\n", k, v)
    }
}

I understand one way we can do this is by injecting the locals into the globals object at every function call but it would be good if this could be done natively. Was wondering if there was plans for support? Or if contributions on this part would be accepted?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions