Ejemplo n.º 1
0
func release_jsstringref_array(refs []C.JSStringRef) {
	for i := 0; i < len(refs); i++ {
		if refs[i] != nil {
			C.JSStringRelease(refs[i])
		}
	}
}
Ejemplo n.º 2
0
func (ctx *Context) NewStringValue(value string) *Value {
	cvalue := C.CString(value)
	defer C.free(unsafe.Pointer(cvalue))
	jsstr := C.JSStringCreateWithUTF8CString(cvalue)
	defer C.JSStringRelease(jsstr)
	ref := C.JSValueMakeString(ctx.ref, jsstr)
	return ctx.newValue(ref)
}
Ejemplo n.º 3
0
// JSON returns the JSON representation of the JavaScript value.
func (v *Value) ToJSON() ([]byte, error) {
	errVal := v.ctx.newErrorValue()
	jsstr := C.JSValueCreateJSONString(v.ctx.ref, v.ref, 0, &errVal.ref)
	if errVal.ref != nil {
		return nil, errVal
	}
	defer C.JSStringRelease(jsstr)
	return (*String)(unsafe.Pointer(jsstr)).Bytes(), nil
}
Ejemplo n.º 4
0
func (v *Value) ToString() (str string, err error) {
	errVal := v.ctx.newErrorValue()
	ret := C.JSValueToStringCopy(v.ctx.ref, v.ref, &errVal.ref)
	if errVal.ref != nil {
		return "", errVal
	}
	defer C.JSStringRelease(ret)
	return newStringFromRef(ret).String(), nil
}
Ejemplo n.º 5
0
func (ref *String) Release() {
	C.JSStringRelease((C.JSStringRef)(unsafe.Pointer(ref)))
}
Ejemplo n.º 6
0
func (ref *PropertyNameArray) NameAtIndex(index uint16) string {
	jsstr := C.JSPropertyNameArrayGetNameAtIndex(C.JSPropertyNameArrayRef(unsafe.Pointer(ref)), C.size_t(index))
	defer C.JSStringRelease(jsstr)
	return (*String)(unsafe.Pointer(jsstr)).String()
}