olebedev on master
Update CI box (compare)
olebedev on master
Update build badge at readme.md Add gitter badger Add command line tool to execut… and 7 more (compare)
olebedev on v2
Fix build on FreeBSD Merge pull request #31 from cry… (compare)
olebedev on v2
Add benchmarks (compare)
C.duk_debugger_attach
, it's my first time going a bit deeper into CGO, therefore any help appreciated :D noctarius/go-duktape@b7007c4
package main
import (
"fmt"
"gopkg.in/olebedev/go-duktape.v3"
)
const theFunc = `
setTimeout(function() {
print('in timeout callback');
second();
}, 2000);
print('first step');
while(true) {
}
`
func main() {
ctx := duktape.New()
// Let's inject `setTimeout`, `setInterval`, `clearTimeout`,
// `clearInterval` into global scope.
ctx.PushTimers()
ch := make(chan string)
ctx.PushGlobalGoFunction("second", func(_ *duktape.Context) int {
ch <- "second step"
return 0
})
ctx.PevalString(theFunc)
fmt.Println(<-ch)
}
first step
in timeout callback
fatal error: unexpected signal during runtime execution
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x40ba73d]
goroutine 19 [running]:
gopkg.in/olebedev/go-duktape%2ev3.(*Context).transmute(...)
/Users/clarkbynum/Developer/golang/src/gopkg.in/olebedev/go-duktape.v3/duktape.go:38
gopkg.in/olebedev/go-duktape%2ev3.goFunctionCall(0x4304a50, 0xc00003c5f8)
/Users/clarkbynum/Developer/golang/src/gopkg.in/olebedev/go-duktape.v3/duktape.go:152 +0x7d
gopkg.in/olebedev/go-duktape%2ev3._cgoexpwrap_9803a0f8a99f_goFunctionCall(0x4304a50, 0x2)
_cgo_gotypes.go:3433 +0x2b
gopkg.in/olebedev/go-duktape%2ev3._Cfunc_duk_pcall(0x4304a50, 0x0, 0x0)
_cgo_gotypes.go:2204 +0x4d
gopkg.in/olebedev/go-duktape%2ev3.(*Context).Pcall.func1(0x4304a50, 0x0, 0xc000000006)
/Users/clarkbynum/Developer/golang/src/gopkg.in/olebedev/go-duktape.v3/api.go:773 +0x5e
gopkg.in/olebedev/go-duktape%2ev3.(*Context).Pcall(0xc00009a030, 0x0, 0x6)
/Users/clarkbynum/Developer/golang/src/gopkg.in/olebedev/go-duktape.v3/api.go:773 +0x3d
gopkg.in/olebedev/go-duktape%2ev3.setTimeout.func1(0x409f400000000000, 0xc00009a030, 0x3ff0000000000000)
/Users/clarkbynum/Developer/golang/src/gopkg.in/olebedev/go-duktape.v3/timers.go:55 +0x11b
created by gopkg.in/olebedev/go-duktape%2ev3.setTimeout
/Users/clarkbynum/Developer/golang/src/gopkg.in/olebedev/go-duktape.v3/timers.go:43 +0xab
[signal SIGSEGV: segmentation violation code=0x1 addr=0x131ceb6b0 pc=0x40f0f4b]
runtime stack:
runtime.throw(0x4136990, 0x2a)
/usr/local/Cellar/go/1.11.1/libexec/src/runtime/panic.go:608 +0x72
runtime.sigpanic()
/usr/local/Cellar/go/1.11.1/libexec/src/runtime/signal_unix.go:374 +0x2f2
goroutine 1 [syscall]:
runtime.cgocall(0x40bd546, 0xc0000b9ea8, 0xc0000b9eb0)
/usr/local/Cellar/go/1.11.1/libexec/src/runtime/cgocall.go:128 +0x5e fp=0xc0000b9e78 sp=0xc0000b9e40 pc=0x4004afe
gopkg.in/olebedev/go-duktape%2ev3._Cfunc__duk_peval_string(0x4304a50, 0x4318fb0, 0x0)
_cgo_gotypes.go:644 +0x4d fp=0xc0000b9ea8 sp=0xc0000b9e78 pc=0x40b763d
gopkg.in/olebedev/go-duktape%2ev3.(*Context).PevalString.func1(0x4304a50, 0x4318fb0, 0x4318fb0)
/Users/clarkbynum/Developer/golang/src/gopkg.in/olebedev/go-duktape.v3/api.go:880 +0x60 fp=0xc0000b9ee0 sp=0xc0000b9ea8 pc=0x40bbd30
gopkg.in/olebedev/go-duktape%2ev3.(*Context).PevalString(0xc00009a020, 0x4137a08, 0x7a, 0xc00008a210, 0x1)
/Users/clarkbynum/Developer/golang/src/gopkg.in/olebedev/go-duktape.v3/api.go:880 +0x5f fp=0xc0000b9f20 sp=0xc0000b9ee0 pc=0x40b961f
main.main()
/Users/clarkbynum/Developer/golang/src/test-go-duktape/main.go:32 +0xd7 fp=0xc0000b9f98 sp=0xc0000b9f20 pc=0x40bce77
runtime.main()
/usr/local/Cellar/go/1.11.1/libexec/src/runtime/proc.go:201 +0x207 fp=0xc0000b9fe0 sp=0xc0000b9f98 pc=0x402b8f7
runtime.goexit()
/usr/local/Cellar/go/1.11.1/libexec/src/runtime/asm_amd64.s:1333 +0x1 fp=0xc0000b9fe8 sp=0xc0000b9fe0 pc=0x40543f1
goroutine 19 [running]:
goroutine running on other thread; stack unavailable
created by gopkg.in/olebedev/go-duktape%2ev3.setTimeout
/Users/clarkbynum/Developer/golang/src/gopkg.in/olebedev/go-duktape.v3/timers.go:43 +0xab
first step
in timeout callback
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4141690]
runtime stack:
runtime.throw(0x4193500, 0x2a)
/usr/local/Cellar/go/1.11.1/libexec/src/runtime/panic.go:608 +0x72
runtime.sigpanic()
/usr/local/Cellar/go/1.11.1/libexec/src/runtime/signal_unix.go:374 +0x2f2
goroutine 1 [syscall]:
runtime.cgocall(0x40bd0b0, 0xc0000bfea8, 0xc0000bfeb0)
/usr/local/Cellar/go/1.11.1/libexec/src/runtime/cgocall.go:128 +0x5e fp=0xc0000bfe78 sp=0xc0000bfe40 pc=0x400450e
test-go-duktape/vendor/gopkg.in/olebedev/go-duktape%2ev3._Cfunc__duk_peval_string(0x44049f0, 0x44194a0, 0x0)
_cgo_gotypes.go:706 +0x4d fp=0xc0000bfea8 sp=0xc0000bfe78 pc=0x40b704d
test-go-duktape/vendor/gopkg.in/olebedev/go-duktape%2ev3.(*Context).PevalString.func1(0x44049f0, 0x44194a0, 0x44194a0)
/Users/clarkbynum/Developer/golang/src/test-go-duktape/vendor/gopkg.in/olebedev/go-duktape.v3/api.go:882 +0x60 fp=0xc0000bfee0 sp=0xc0000bfea8 pc=0x40bb740
test-go-duktape/vendor/gopkg.in/olebedev/go-duktape%2ev3.(*Context).PevalString(0xc0000a0020, 0x4194578, 0x7a, 0xc000090210, 0x1)
/Users/clarkbynum/Developer/golang/src/test-go-duktape/vendor/gopkg.in/olebedev/go-duktape.v3/api.go:882 +0x5f fp=0xc0000bff20 sp=0xc0000bfee0 pc=0x40b902f
main.main()
/Users/clarkbynum/Developer/golang/src/test-go-duktape/main.go:35 +0xd7 fp=0xc0000bff98 sp=0xc0000bff20 pc=0x40bc887
runtime.main()
/usr/local/Cellar/go/1.11.1/libexec/src/runtime/proc.go:201 +0x207 fp=0xc0000bffe0 sp=0xc0000bff98 pc=0x402b307
runtime.goexit()
/usr/local/Cellar/go/1.11.1/libexec/src/runtime/asm_amd64.s:1333 +0x1 fp=0xc0000bffe8 sp=0xc0000bffe0 pc=0x4053e01
goroutine 19 [chan send, locked to thread]:
main.main.func1(0xc0000a0038, 0x4419100)
/Users/clarkbynum/Developer/golang/src/test-go-duktape/main.go:32 +0x36
test-go-duktape/vendor/gopkg.in/olebedev/go-duktape%2ev3.goFunctionCall(0x44049f0, 0xc00003c5f8)
/Users/clarkbynum/Developer/golang/src/test-go-duktape/vendor/gopkg.in/olebedev/go-duktape.v3/duktape.go:156 +0xb6
test-go-duktape/vendor/gopkg.in/olebedev/go-duktape%2ev3._cgoexpwrap_25d7a6c4a830_goFunctionCall(0x44049f0, 0x0)
_cgo_gotypes.go:3511 +0x2b
test-go-duktape/vendor/gopkg.in/olebedev/go-duktape%2ev3._Cfunc_duk_pcall(0x44049f0, 0x0, 0x0)
_cgo_gotypes.go:2282 +0x4d
test-go-duktape/vendor/gopkg.in/olebedev/go-duktape%2ev3.(*Context).Pcall.func1(0x44049f0, 0x0, 0xc000000006)
/Users/clarkbynum/Developer/golang/src/test-go-duktape/vendor/gopkg.in/olebedev/go-duktape.v3/api.go:776 +0x5e
test-go-duktape/vendor/gopkg.in/olebedev/go-duktape%2ev3.(*Context).Pcall(0xc0000a0030, 0x0, 0x6)
/Users/clarkbynum/Developer/golang/src/test-go-duktape/vendor/gopkg.in/olebedev/go-duktape.v3/api.go:776 +0x3d
test-go-duktape/vendor/gopkg.in/olebedev/go-duktape%2ev3.setTimeout.func1(0x409f400000000000, 0xc0000a0030, 0x3ff0000000000000)
/Users/clarkbynum/Developer/golang/src/test-go-duktape/vendor/gopkg.in/olebedev/go-duktape.v3/timers.go:55 +0x11b
created by test-go-duktape/vendor/gopkg.in/olebedev/go-duktape%2ev3.setTimeout
/Users/clarkbynum/Developer/golang/src/test-go-duktape/vendor/gopkg.in/olebedev/go-duktape.v3/timers.go:43 +0xab
v2
branch and got this -
first step
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x412e303]
runtime stack:
runtime.throw(0x4170190, 0x2a)
/usr/local/Cellar/go/1.11.1/libexec/src/runtime/panic.go:608 +0x72
runtime.sigpanic()
/usr/local/Cellar/go/1.11.1/libexec/src/runtime/signal_unix.go:374 +0x2f2
goroutine 5 [syscall]:
runtime.cgocall(0x40be960, 0xc000041f18, 0x29)
/usr/local/Cellar/go/1.11.1/libexec/src/runtime/cgocall.go:128 +0x5e fp=0xc000041ee0 sp=0xc000041ea8 pc=0x40046ae
test-go-duktape/vendor/gopkg.in/olebedev/go-duktape%2ev2._Cfunc_duk_pcall(0x4704fd0, 0x0, 0x0)
_cgo_gotypes.go:2175 +0x4d fp=0xc000041f18 sp=0xc000041ee0 pc=0x40b7cad
test-go-duktape/vendor/gopkg.in/olebedev/go-duktape%2ev2.(*Context).Pcall.func1(0x4704fd0, 0x0, 0xc000000006)
/Users/clarkbynum/Developer/golang/src/test-go-duktape/vendor/gopkg.in/olebedev/go-duktape.v2/api.go:766 +0x5e fp=0xc000041f50 sp=0xc000041f18 pc=0x40bb5ee
test-go-duktape/vendor/gopkg.in/olebedev/go-duktape%2ev2.(*Context).Pcall(0xc00000e040, 0x0, 0x6)
/Users/clarkbynum/Developer/golang/src/test-go-duktape/vendor/gopkg.in/olebedev/go-duktape.v2/api.go:766 +0x3d fp=0xc000041f78 sp=0xc000041f50 pc=0x40b8eed
test-go-duktape/vendor/gopkg.in/olebedev/go-duktape%2ev2.setTimeout.func1(0x409f400000000000, 0xc00000e040, 0x3ff0000000000000)
/Users/clarkbynum/Developer/golang/src/test-go-duktape/vendor/gopkg.in/olebedev/go-duktape.v2/timers.go:55 +0x11b fp=0xc000041fc8 sp=0xc000041f78 pc=0x40bac8b
runtime.goexit()
/usr/local/Cellar/go/1.11.1/libexec/src/runtime/asm_amd64.s:1333 +0x1 fp=0xc000041fd0 sp=0xc000041fc8 pc=0x4053fa1
created by test-go-duktape/vendor/gopkg.in/olebedev/go-duktape%2ev2.setTimeout
/Users/clarkbynum/Developer/golang/src/test-go-duktape/vendor/gopkg.in/olebedev/go-duktape.v2/timers.go:43 +0xab
goroutine 1 [syscall]:
test-go-duktape/vendor/gopkg.in/olebedev/go-duktape%2ev2._Cfunc__duk_peval_string(0x4704fd0, 0x470d680, 0x0)
_cgo_gotypes.go:642 +0x4d
test-go-duktape/vendor/gopkg.in/olebedev/go-duktape%2ev2.(*Context).PevalString.func2(0x4704fd0, 0x470d680, 0x470d680)
/Users/clarkbynum/Developer/golang/src/test-go-duktape/vendor/gopkg.in/olebedev/go-duktape.v2/api.go:879 +0x60
test-go-duktape/vendor/gopkg.in/olebedev/go-duktape%2ev2.(*Context).PevalString(0xc00000e030, 0x4171208, 0x7a, 0x0, 0x0)
/Users/clarkbynum/Developer/golang/src/test-go-duktape/vendor/gopkg.in/olebedev/go-duktape.v2/api.go:879 +0x88
main.main()
/Users/clarkbynum/Developer/golang/src/test-go-duktape/main.go:35 +0xd7
Build started
git clone -q --depth=5 https://github.com/olebedev/go-duktape.git C:\gopath\src\gopkg.in\olebedev\go-duktape.v3
git fetch -q origin +refs/pull/65/merge:
git checkout -qf FETCH_HEAD
Running Install scripts
rmdir C:\go /s /q
appveyor DownloadFile https://storage.googleapis.com/golang/go1.9.2.windows-%DUKTAPE_ARCH%.zip
Error downloading remote file: One or more errors occurred.
Inner Exception: Unable to connect to the remote server
Command exited with code 2
Hey @jeongkyun-oh I don't think there's a way to copy a context. The duktape issue tracker has multiple questions on cloning or copying a context (e.g. here svaarala/duktape#770). I think as long as duktape doesn't have support for it, there's nothing the wrapper could do.
One thing you may want to look into though is creating the appropriate JavaScript code, parse it into bytecode, dump and reload it. You still need to make sure you're able to supply your native functions though