-
Notifications
You must be signed in to change notification settings - Fork 87
/
v8_engine.go
54 lines (45 loc) · 1 KB
/
v8_engine.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
package v8
/*
#include "v8_wrap.h"
#include <stdlib.h>
*/
import "C"
import "unsafe"
import "runtime"
var traceDispose = false
// Represents an isolated instance of the V8 engine.
// Objects from one engine must not be used in other engine.
type Engine struct {
embedable
self unsafe.Pointer
_undefined *Value
_null *Value
_true *Value
_false *Value
funcTemplateId int
funcTemplates map[int]*FunctionTemplate
objectTemplateId int
objectTemplates map[int]*ObjectTemplate
}
func NewEngine() *Engine {
self := C.V8_NewEngine()
if self == nil {
return nil
}
result := &Engine{
self: self,
funcTemplates: make(map[int]*FunctionTemplate),
objectTemplates: make(map[int]*ObjectTemplate),
}
runtime.SetFinalizer(result, func(e *Engine) {
if traceDispose {
println("v8.Engine.Dispose()", e.self)
}
C.V8_DisposeEngine(e.self)
})
return result
}
//export v8_panic
func v8_panic(message *C.char) {
panic(C.GoString(message))
}