Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

306
Views
Go failed to call JavaScript function because buffer was introduced into JavaScript code

Go failed to call JavaScript function because the buffer was introduced into JavaScript code

secret.js

import Buffer from 'buffer'

var Q = function(e) {
    return new Buffer("asdfl")
};

main.go

func main() {
    jsFile := "./secret.js"
    bytes, err := ioutil.ReadFile(jsFile)
    if err != nil {
        panic(err)
    }

    vm := otto.New()
    _, err = vm.Run(string(bytes))
    if err != nil {
        panic(err)
    }
    enc, err := vm.Call("Q", nil, "123456")
    if err != nil {
        panic(err)
    }
    fmt.Println(enc.String())
}

error tips

(anonymous): Line 1:1 Unexpected reserved word

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

otto only implemented Javascript ES5 while import is a feautre of ES6, so you couldn't use import in your JS code.

update: You can follow this post to implement your own require method

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!