github.com/primecitizens/pcz/std@v0.2.1/ffi/js/export_test.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  
     4  package js_test
     5  
     6  import (
     7  	"github.com/primecitizens/pcz/std/ffi/js"
     8  )
     9  
    10  type JSValue interface {
    11  	Ref() js.Ref
    12  	Free()
    13  }
    14  
    15  var (
    16  	_ JSValue = js.String{}
    17  	_ JSValue = js.Array[js.Any]{}.Ref().Any().AsArray()
    18  	_ JSValue = js.Func[js.Any]{}.Ref().Any().AsFunc()
    19  )
    20  
    21  var _ int = js.String{}.Read([]byte{})
    22  var _ int = js.String{}.Len()
    23  var _ bool = js.String{}.Equals("other string")
    24  
    25  var (
    26  	_ bool = js.Object{}.DefineProp(
    27  		"foo", js.PropDesc_configurable,
    28  		js.Func[func() js.Any]{}.FromRef(js.Undefined),
    29  		js.Func[func(js.Any) bool]{}.FromRef(js.Undefined),
    30  	)
    31  	_ bool = js.Object{}.DeleteProp("foo")
    32  	_ bool = js.Object{}.SetProp("foo", true, js.NewString("woo").Ref())
    33  	_ bool = js.Object{}.SetPropByString(js.NewString("prop"), true, 0)
    34  
    35  	_ bool = js.Object{}.SetNumProp("num", 10)
    36  	_ bool = js.Object{}.SetNumPropByString(js.NewString("num"), 10)
    37  	_ bool = js.Object{}.SetBoolProp("bool", true)
    38  	_ bool = js.Object{}.SetBoolPropByString(js.NewString("bool"), true)
    39  	_ bool = js.Object{}.SetStringProp("string", "a")
    40  	_ bool = js.Object{}.SetStringPropByString(
    41  		js.NewString("string"), true, js.NewString("a"),
    42  	)
    43  	_ js.Object = js.Object{}.Prop("prop").AsObject()
    44  	_ js.Object = js.Object{}.PropByString(js.NewString("prop")).AsObject()
    45  	_ js.Object = js.Object{}.StringProp("foo").Ref().Any().AsObject()
    46  	_ js.Object = js.Object{}.StringPropByString(js.NewString("str")).Ref().Any().AsObject()
    47  
    48  	_ bool    = js.Object{}.BoolProp("bool")
    49  	_ float64 = js.Object{}.NumProp("num")
    50  )