Skip to content

Commit

Permalink
Fix __ENV polution
Browse files Browse the repository at this point in the history
  • Loading branch information
na-- authored and imiric committed May 18, 2020
1 parent a44509d commit e1a5c0a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions js/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ type BundleInstance struct {
Runtime *goja.Runtime
Context *context.Context

//TODO: maybe just have a reference to the Bundle? or save and pass rtOpts?
env map[string]string

exports map[string]goja.Callable
}

Expand Down Expand Up @@ -235,6 +238,7 @@ func (b *Bundle) Instantiate() (bi *BundleInstance, instErr error) {
Runtime: rt,
Context: ctxPtr,
exports: make(map[string]goja.Callable),
env: b.Env,
}

// Grab any exported functions that could be executed. These were
Expand Down
13 changes: 7 additions & 6 deletions js/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,14 @@ func (u *VU) Activate(params *lib.VUActivationParams) lib.ActiveVU {
}

// Override the preset global env with any custom env vars
if len(params.Env) > 0 {
env := u.Runtime.Get("__ENV").Export().(map[string]string)
for key, value := range params.Env {
env[key] = value
}
u.Runtime.Set("__ENV", env)
env := make(map[string]string, len(u.env)+len(params.Env))
for key, value := range u.env {
env[key] = value
}
for key, value := range params.Env {
env[key] = value
}
u.Runtime.Set("__ENV", env)

avu := &ActiveVU{
VU: u,
Expand Down

0 comments on commit e1a5c0a

Please sign in to comment.