-
Notifications
You must be signed in to change notification settings - Fork 587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compile throws error #443
Labels
Comments
This seems to work just fine for me, here's my code: package otto
import (
"testing"
"github.com/stretchr/testify/require"
)
var jsIssue443 = `
function swap(a) {
var c = a['name'].split(' ');
a['name'] = c[1] + ' ' + c[0];
}
swap(args);
result = args['name'];
`
func TestIssue443(t *testing.T) {
vm := New()
vm.Set("args", map[string]string{"name": "first second"})
val, err := vm.Run(jsIssue443)
require.NoError(t, err)
require.Equal(t, "second first", val.String())
} |
Could you please try doing
This throws the following error, however, if I do a
|
func Test_issue443(t *testing.T) {
fn := `
function fact(n) {
if (n === 0 || n === 1) {
return 1
} else {
return n * fact(n - 1)
}
}
function factorial(m) {
var n = m['num']
m['num'] = fact(n)
}
factorial(args)
`
vm := New()
p := map[string]interface{}{"num": "17"}
vm.Set("args", p)
pg, err := vm.Compile("", fn)
require.NoError(t, err)
fmt.Printf("pg: %#v\n", pg)
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Consider the following function
args is a map passed during runtime before Run(), using Set(), this code executes perfectly well, however, the same when passed to Compile() throws the following error.
I'm using the latest version of otto
github.com/robertkrimen/otto v0.0.0-20221025135307-511d75fba9f8
from go.mod. Any help is really appreciated.The text was updated successfully, but these errors were encountered: