-
Notifications
You must be signed in to change notification settings - Fork 1
/
v8.go
56 lines (47 loc) · 1.4 KB
/
v8.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
46
47
48
49
50
51
52
53
54
55
56
package isolates
//#include "v8_c_bridge.h"
//#cgo CXXFLAGS: -I/usr/local/include/v8 -std=c++17
import "C"
import (
"fmt"
"sync"
)
// Version exposes the compiled-in version of the linked V8 library. This can
// be used to test for specific javascript functionality support (e.g. ES6
// destructuring isn't supported before major version 5.).
var Version = struct{ Major, Minor, Build, Patch int }{
Major: int(C.version.major),
Minor: int(C.version.minor),
Build: int(C.version.build),
Patch: int(C.version.patch),
}
// PromiseState defines the state of a promise: either pending, resolved, or
// rejected. Promises that are pending have no result value yet. A promise that
// is resolved has a result value, and a promise that is rejected has a result
// value that is usually the error.
type PromiseState uint8
const (
PromiseStatePending PromiseState = iota
PromiseStateResolved
PromiseStateRejected
kNumPromiseStates
)
var promiseStateStrings = [kNumPromiseStates]string{"Pending", "Resolved", "Rejected"}
func (s PromiseState) String() string {
if s < 0 || s >= kNumPromiseStates {
return fmt.Sprintf("InvalidPromiseState:%d", int(s))
}
return promiseStateStrings[s]
}
var initOnce sync.Once
func Initialize() {
initOnce.Do(func() {
C.v8_Initialize()
go func() {
for {
v8IsolateInitializer := <-v8IsolateInitializers
v8IsolateInitializer.result <- v8IsolateInitializer.fn()
}
}()
})
}