forked from YaoApp/v8go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexternal_test.go
45 lines (35 loc) · 895 Bytes
/
external_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package v8go_test
import (
"testing"
v8 "rogchap.com/v8go"
)
func TestExternal(t *testing.T) {
t.Parallel()
ctx := v8.NewContext()
defer ctx.Isolate().Dispose()
defer ctx.Close()
goValue := map[string]interface{}{"foo": "bar"}
val, err := v8.NewExternal(ctx.Isolate(), goValue)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !val.IsYaoExternal() {
t.Errorf("expected value to be of type External")
}
resValue, err := val.External()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
v, ok := resValue.(map[string]interface{})
if !ok {
t.Errorf("expected value to be of type map[string]interface{}")
}
if v["foo"] != "bar" {
t.Errorf("expected value to be 'bar', got %v", v["foo"])
}
// Release the external value
val.Release()
if v8.ExternalCount() != 0 {
t.Errorf("expected external count to be 0, got %v", v8.ExternalCount())
}
}