gowebapi / webapi

Go Lang Web Assembly bindings for DOM, HTML etc
BSD 3-Clause "New" or "Revised" License
174 stars 12 forks source link

Pointers to scalar values (*string, *int, *bool) fail ValueOf #6

Closed thegrumpylion closed 4 years ago

thegrumpylion commented 4 years ago

Functions that get a pointer to a string/int/bool should dereference the pointers before passing them to any js functions

For example

// SetTextContent setting attribute 'textContent' with
// type string (idl: DOMString).
func (_this *Node) SetTextContent(value *string) {
    input := value
    _this.Value_JS.Set("textContent", input)
}

could be

// SetTextContent setting attribute 'textContent' with
// type string (idl: DOMString).
func (_this *Node) SetTextContent(value *string) {
    if value != nil {
        input := *value
        _this.Value_JS.Set("textContent", input)
    }
}

otherwise it panics panic: ValueOf: invalid value

Similar,

func (_this *Node) CloneNode(deep *bool) (_result *Node) {
    var (
        _args [1]interface{}
        _end  int
    )
    if deep != nil {
        _p0 := deep
        _args[0] = _p0
        _end++
    }
    _returned := _this.Value_JS.Call("cloneNode", _args[0:_end]...)
    var (
        _converted *Node // javascript: Node _what_return_name
    )
    _converted = NodeFromJS(_returned)
    _result = _converted
    return
}

could be

func (_this *Node) CloneNode(deep *bool) (_result *Node) {
    var (
        _args [1]interface{}
        _end  int
    )
    if deep != nil {
        _p0 := *deep
        _args[0] = _p0
        _end++
    }
    _returned := _this.Value_JS.Call("cloneNode", _args[0:_end]...)
    var (
        _converted *Node // javascript: Node _what_return_name
    )
    _converted = NodeFromJS(_returned)
    _result = _converted
    return
}
martin-juhlin commented 4 years ago

I think this issue is now fixed. Thank for the feedback!