Uh oh!
There was an error while loading. Please reload this page.
forked from rogchap/v8go
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.go
More file actions
Latest commit
50 lines (44 loc) · 1.34 KB
/
Copy pathfunction.go
File metadata and controls
50 lines (44 loc) · 1.34 KB
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
// Copyright 2021 Roger Chapman and the v8go contributors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package v8go
// #include "v8go.h"
import"C"
import (
"unsafe"
)
// Function is a JavaScript function.
typeFunctionstruct {
*Value
}
// Call this JavaScript function with the given arguments.
func (fn*Function) Call(recvValuer, args...Valuer) (*Value, error) {
varargptr*C.ValuePtr
iflen(args) >0 {
varcArgs=make([]C.ValuePtr, len(args))
fori, arg:=rangeargs {
cArgs[i] =arg.value().ptr
}
argptr= (*C.ValuePtr)(unsafe.Pointer(&cArgs[0]))
}
rtn:=C.FunctionCall(fn.ptr, recv.value().ptr, C.int(len(args)), argptr)
returnvalueResult(fn.ctx, rtn)
}
// Invoke a constructor function to create an object instance.
func (fn*Function) NewInstance(args...Valuer) (*Object, error) {
varargptr*C.ValuePtr
iflen(args) >0 {
varcArgs=make([]C.ValuePtr, len(args))
fori, arg:=rangeargs {
cArgs[i] =arg.value().ptr
}
argptr= (*C.ValuePtr)(unsafe.Pointer(&cArgs[0]))
}
rtn:=C.FunctionNewInstance(fn.ptr, C.int(len(args)), argptr)
returnobjectResult(fn.ctx, rtn)
}
// Return the source map url for a function.
func (fn*Function) SourceMapUrl() *Value {
ptr:=C.FunctionSourceMapUrl(fn.ptr)
return&Value{ptr, fn.ctx}
}