Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func (ac *JsArrayToGoConverter[T]) convertToInterface(jsArray *Array, jsLen int6
for i := range jsLen {
jsElem := jsArray.Get(i)

goElem, convErr := jsValueToGo[any](ac.tracker, jsElem)
goElem, convErr := toGoValue[any](ac.tracker, jsElem)

if !jsElem.IsFunction() {
jsElem.Free()
Expand Down Expand Up @@ -398,7 +398,7 @@ func (ac *JsArrayToGoConverter[T]) convertToSlice(jsArray *Array, jsLen int64) (
for i := range jsLen {
jsElem := jsArray.Get(i)
elemSample := reflect.New(elemType).Elem().Interface()
goElem, convErr := jsValueToGo(ac.tracker, jsElem, elemSample)
goElem, convErr := toGoValue(ac.tracker, jsElem, elemSample)

if !jsElem.IsFunction() {
jsElem.Free()
Expand Down Expand Up @@ -433,7 +433,7 @@ func (ac *JsArrayToGoConverter[T]) convertToArray(jsArray *Array, jsLen int64) (
for i := range jsLen {
jsElem := jsArray.Get(i)
elemSample := reflect.New(elemType).Elem().Interface()
goElem, convErr := jsValueToGo(ac.tracker, jsElem, elemSample)
goElem, convErr := toGoValue(ac.tracker, jsElem, elemSample)

if !jsElem.IsFunction() {
jsElem.Free()
Expand Down Expand Up @@ -593,7 +593,7 @@ func processTempValue[T any](prefix string, temp any, err error, samples ...T) (
return tempT, nil
}

return v, newInvalidGoTargetErr(GetGoTypeName(sample), temp)
return v, newInvalidGoTypeErr(GetGoTypeName(sample), temp)
}

valueT, _ := temp.(T)
Expand Down Expand Up @@ -769,7 +769,7 @@ func isGoStruct(goType reflect.Type) bool {
// VerifyGoFunc validates that a function signature is compatible with JS conversion.
func VerifyGoFunc(fnType reflect.Type, sample any) error {
if fnType == nil || fnType.Kind() != reflect.Func {
return newInvalidGoTargetErr("function", sample)
return newInvalidGoTypeErr("function", sample)
}

// Validate that all return values are convertible to JS
Expand Down
4 changes: 2 additions & 2 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,14 +536,14 @@ func TestCreateGoBindFuncType(t *testing.T) {
t.Run("non_function", func(t *testing.T) {
_, err := qjs.CreateGoBindFuncType("not a function")
assert.Error(t, err)
assert.Contains(t, err.Error(), "expected GO target")
assert.Contains(t, err.Error(), "expected GO type")
assert.Contains(t, err.Error(), "function")
})

t.Run("integer", func(t *testing.T) {
_, err := qjs.CreateGoBindFuncType(42)
assert.Error(t, err)
assert.Contains(t, err.Error(), "expected GO target")
assert.Contains(t, err.Error(), "expected GO type")
assert.Contains(t, err.Error(), "function")
})
})
Expand Down
2 changes: 1 addition & 1 deletion context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestContextValueCreation(t *testing.T) {
fmt.Printf("context check: is nil=%t, value=%v\n", ctx == nil, ctx)
return num * 2
}
jsFuncWithContext := must(qjs.ToJSValue(ctx, goFuncWithContext))
jsFuncWithContext := must(qjs.ToJsValue(ctx, goFuncWithContext))
defer jsFuncWithContext.Free()
ctx.Global().SetPropertyStr("funcWithContext", jsFuncWithContext)

Expand Down
4 changes: 2 additions & 2 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ func newArgConversionErr(index int, err error) error {
return fmt.Errorf("cannot convert JS function argument at index %d: %w", index, err)
}

func newInvalidGoTargetErr(expect string, got any) error {
return fmt.Errorf("expected GO target %s, got %T", expect, got)
func newInvalidGoTypeErr(expect string, got any) error {
return fmt.Errorf("expected GO type %s, got %T", expect, got)
}

func newInvalidJsInputErr(kind string, input *Value) (err error) {
Expand Down
14 changes: 7 additions & 7 deletions functojs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func FuncToJS(c *Context, v any) (_ *Value, err error) {
}

if rtype.Kind() != reflect.Func {
return nil, newInvalidGoTargetErr("function", v)
return nil, newInvalidGoTypeErr("function", v)
}

if rval.IsNil() {
Expand Down Expand Up @@ -114,7 +114,7 @@ func handlePointerArgument(jsArg *Value, argType reflect.Type) (reflect.Value, e
underlyingType := argType.Elem()
zeroVal := reflect.New(underlyingType).Elem()

goVal, err := JsValueToGo(jsArg, zeroVal.Interface())
goVal, err := ToGoValue(jsArg, zeroVal.Interface())
if err != nil {
return reflect.Value{}, newJsToGoErr(jsArg, err, "function param pointer to "+jsArg.Type())
}
Expand Down Expand Up @@ -184,7 +184,7 @@ func JsArgToGo(jsArg *Value, argType reflect.Type) (reflect.Value, error) {

goZeroVal := CreateNonNilSample(argType)

goVal, err := JsValueToGo(jsArg, goZeroVal)
goVal, err := ToGoValue(jsArg, goZeroVal)
if err != nil {
return reflect.Value{}, newJsToGoErr(jsArg, err, "function param "+jsArg.Type())
}
Expand Down Expand Up @@ -241,7 +241,7 @@ func GoFuncResultToJs(c *Context, results []reflect.Value) (*Value, error) {

// Single remaining value -> return that value
if len(remaining) == 1 {
return ToJSValue(c, remaining[0].Interface())
return ToJsValue(c, remaining[0].Interface())
}

// Multiple remaining values -> return as JS array
Expand All @@ -250,12 +250,12 @@ func GoFuncResultToJs(c *Context, results []reflect.Value) (*Value, error) {
jsValues[i] = result.Interface()
}

return ToJSValue(c, jsValues)
return ToJsValue(c, jsValues)
}

// Single return value -> return that value
if len(results) == 1 {
return ToJSValue(c, results[0].Interface())
return ToJsValue(c, results[0].Interface())
}

// Multiple return values -> return as JS array
Expand All @@ -264,5 +264,5 @@ func GoFuncResultToJs(c *Context, results []reflect.Value) (*Value, error) {
jsValues[i] = result.Interface()
}

return ToJSValue(c, jsValues)
return ToJsValue(c, jsValues)
}
2 changes: 1 addition & 1 deletion functojs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestBasicConversion(t *testing.T) {
t.Run("InvalidTypes", func(t *testing.T) {
_, err := qjs.FuncToJS(ctx, "not a function")
require.Error(t, err)
assert.Contains(t, err.Error(), "expected GO target function")
assert.Contains(t, err.Error(), "expected GO type function")
})

t.Run("FunctionTypes", func(t *testing.T) {
Expand Down
Loading
Loading