v8go
v8go copied to clipboard
uint8 array support
This PR adds code to v8go to convert []uint8 array from javascript to golang and back, and also an Isolate method to allow throwing javascript exceptions from golang callbacks. Test case resides in file array_test.go.
Codecov Report
Patch coverage: 100.00
% and project coverage change: +1.79
:tada:
Comparison is base (
1f00b50
) 95.23% compared to head (92acee2
) 97.03%.
:exclamation: Current head 92acee2 differs from pull request most recent head b75eec2. Consider uploading reports for the commit b75eec2 to get more accurate results
Additional details and impacted files
@@ Coverage Diff @@
## master #143 +/- ##
==========================================
+ Coverage 95.23% 97.03% +1.79%
==========================================
Files 17 13 -4
Lines 588 472 -116
==========================================
- Hits 560 458 -102
+ Misses 19 9 -10
+ Partials 9 5 -4
Impacted Files | Coverage Δ | |
---|---|---|
arraybuffer.go | 100.00% <100.00%> (ø) |
|
isolate.go | 100.00% <100.00%> (ø) |
|
object.go | 100.00% <100.00%> (ø) |
|
value.go | 97.63% <100.00%> (+2.80%) |
:arrow_up: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
There is some great code here; but I'm unsure about this API as it's not following the V8 API (in hindsight I think this is also true for BigInt and maybe some of the other simple types)
I would like to see the API reflect the inheritance structure that exits in the V8 API eg: https://v8.github.io/api/head/classv8_1_1Uint8Array.html
Similar to how we deal with Object and Function, Array and ArrayBuffers should follow suit.
Once that API is in place we can add convenance methods between the Go world and the V8 world.
Although there is an overhead, I would avoid shared memory for the slices as it can be hard for callers to free allocated memory; we want the public API to be as Go friendly as possible.
This is just wonderful PR! Cant wait to have this merged. 👍
@teuget btw I did messed around with changes. Seems to me that v8go.NewObject
doesnt work elsewhere except in the context of NewFunctionTemplate
.
try this:
ctx, err := v8go.NewContext()
require.NoError(t, err)
v8go.NewObject(ctx)
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0xffffffffffffffff pc=0x41a93c9]
runtime stack:
runtime.throw(0x4d2ae0c, 0x2a)
/usr/local/go/src/runtime/panic.go:1117 +0x72
runtime.sigpanic()
/usr/local/go/src/runtime/signal_unix.go:718 +0x2ef
goroutine 19 [syscall]:
runtime.cgocall(0x4157330, 0xc00003e6b0, 0x4128f05)
/usr/local/go/src/runtime/cgocall.go:154 +0x5b fp=0xc00003e680 sp=0xc00003e648 pc=0x4007d1b
rogchap.com/v8go._Cfunc_NewObject(0x357300000000, 0x0)
_cgo_gotypes.go:431 +0x45 fp=0xc00003e6b0 sp=0xc00003e680 pc=0x4125105
rogchap.com/v8go.NewObject.func1(0xc00012c048, 0xc0001188b0)
/v8go/object.go:25 +0x59 fp=0xc00003e6e8 sp=0xc00003e6b0 pc=0x41318f9
rogchap.com/v8go.NewObject(0xc00012c048, 0x1)
/v8go/object.go:25 +0x39 fp=0xc00003e718 sp=0xc00003e6e8 pc=0x412b3d9
rogchap.com/v8go_test.TestNewObject(0xc000102900)
/v8go/object_test.go:214 +0x7f fp=0xc00003e780 sp=0xc00003e718 pc=0x414d1df
testing.tRunner(0xc000102900, 0x4d2ddb0)
/usr/local/go/src/testing/testing.go:1193 +0xef fp=0xc00003e7d0 sp=0xc00003e780 pc=0x40d680f
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1371 +0x1 fp=0xc00003e7d8 sp=0xc00003e7d0 pc=0x4071781
created by testing.(*T).Run
/usr/local/go/src/testing/testing.go:1238 +0x2b3
goroutine 1 [chan receive]:
testing.tRunner.func1(0xc000102780)
/usr/local/go/src/testing/testing.go:1159 +0x2bc
testing.tRunner(0xc000102780, 0xc000139da8)
/usr/local/go/src/testing/testing.go:1197 +0x125
testing.runTests(0xc00012c030, 0x4f4b7c0, 0x37, 0x37, 0xc0312d4103ceea20, 0x1bf094dc93, 0x4f5af20, 0x4d22a1a)
/usr/local/go/src/testing/testing.go:1509 +0x2fe
testing.(*M).Run(0xc000172000, 0x0)
/usr/local/go/src/testing/testing.go:1417 +0x1eb
main.main()
_testmain.go:249 +0x1c5
goroutine 20 [chan receive]:
testing.runTests.func1.1(0xc000102780)
/usr/local/go/src/testing/testing.go:1516 +0x3b
created by testing.runTests.func1
/usr/local/go/src/testing/testing.go:1516 +0xac
FAIL rogchap.com/v8go 0.445s
FAIL
func TestNewObject(t *testing.T) {
t.Parallel()
iso, _ := v8go.NewIsolate()
ctx, _ := v8go.NewContext(iso)
obj := v8go.NewObject(ctx)
err := obj.Set("test", "ok")
if err != nil {
t.Errorf("Got error from setting object property: %v", err)
}
}
but seems that c->Enter();
and c->Exit();
does the job for NewObject
as well.
Richard,
Great to hear that Enter/Exit fixes the issue. That was also the first thing I was going to try when I got the chance.
Thanks,
Tom
On Tue, 6 Jul 2021 at 14:06, Richard Hutta @.***> wrote:
but seems that c->Enter(); and c->Exit(); does the job for NewObject as well.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rogchap/v8go/pull/143#issuecomment-874702852, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACFKA4726JWGAU5P74J2NCTTWLWVXANCNFSM46JJSGVA .
@sharmaashish13 @teuget are you still on this? I think this is a great addition and would make this library so much better. I actually need workarounds for this as of now and this being finished would be a charm! ❤️
@sharmaashish13 @teuget I agree with @boindil . I'd also dig String arrays.
+1 in wanting to see this get merged
+1 here 😅