Skip to content

Commit

Permalink
vendor goja
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblakeley committed Nov 5, 2018
1 parent 5bf1a09 commit 12c0eb8
Show file tree
Hide file tree
Showing 118 changed files with 18,169 additions and 182,427 deletions.
1 change: 0 additions & 1 deletion jsvm_goja.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/TykTechnologies/tyk/config"
"github.com/TykTechnologies/tyk/user"
"github.com/dop251/goja"
_ "github.com/robertkrimen/otto/underscore"
)

type TykJSVM interface {
Expand Down
12 changes: 5 additions & 7 deletions jsvm_otto.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,27 @@ func (j *OttoJSVM) GetTimeout() time.Duration {
// Init creates the JSVM with the core library and sets up a default
// timeout.
func (j *OttoJSVM) Init(spec *APISpec, logger *logrus.Entry) {
vm := otto.New()
j.VM = otto.New()
logger = logger.WithField("prefix", "jsvm")

// Init TykJS namespace, constructors etc.
if _, err := vm.Run(coreJS); err != nil {
if _, err := j.Run(coreJS); err != nil {
logger.WithError(err).Error("Could not load TykJS")
return
}

// Load user's TykJS on top, if any
if path := config.Global().TykJSPath; path != "" {
f, err := os.Open(path)
f, err := ioutil.ReadFile(path)
if err == nil {
_, err = vm.Run(f)
f.Close()
_, err = j.Run(string(f))

if err != nil {
logger.WithError(err).Error("Could not load user's TykJS")
}
}
}

j.VM = vm
j.Spec = spec

// Add environment API
Expand Down Expand Up @@ -434,7 +432,7 @@ func (j *OttoJSVM) Run(s string) (interface{}, error) {
return j.VM.Run(s)
}

// wraps otto string function to avoid using reflection in tests etc when stringifying results of vm.Run() so it here where its safer
// wraps otto String() function to avoid using reflection in tests etc when stringifying results of vm.Run() so it here where its safer
func (j *OttoJSVM) String(val interface{}) string {
return val.(otto.Value).String()
}
2 changes: 1 addition & 1 deletion utils/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ go get -t
# profile for multiple pkgs
for pkg in $PKGS; do
for opts in "${MATRIX[@]}"; do
show go test -timeout 60s -v -coverprofile=test-$i.cov $opts $pkg \
show go test -timeout 40s -v -coverprofile=test-$i.cov $opts $pkg \
|| fatal "go test errored"
let i++ || true
done
Expand Down
15 changes: 15 additions & 0 deletions vendor/github.com/dop251/goja/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

199 changes: 199 additions & 0 deletions vendor/github.com/dop251/goja/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 12c0eb8

Please sign in to comment.