Skip to content

syscall/js: expected panic on String method on null and undefined values #29536

Closed
@sternix

Description

@sternix

What version of Go are you using (go version)?

$ go version
go version go1.12beta1 freebsd/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/sternix/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="freebsd"
GOOS="freebsd"
GOPATH="/home/sternix/go"
GOPROXY=""
GORACE=""
GOROOT="/opt/go/1_12_b1/go"
GOTMPDIR=""
GOTOOLDIR="/opt/go/1_12_b1/go/pkg/tool/freebsd_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build182700344=/tmp/go-build -gno-record-gcc-switches

What did you do?

// +build js,wasm
  
package main

import (
        "fmt"
        "syscall/js"
)

func main() {
        null := js.Null()

        //panic: syscall/js: call of Value.Int on null
        //fmt.Printf("Int: %d\n",null.Int())

        //panic: syscall/js: call of Value.Float on null
        //fmt.Printf("Float: %f\n",null.Float())

        //panic: syscall/js: call of Value.Bool on null
        //fmt.Printf("Bool: %t\n",null.Bool())

        //String: null
        fmt.Printf("String: %s\n", null.String())

        undefined := js.Undefined()

        //panic: syscall/js: call of Value.Int on undefined
        //fmt.Printf("Int: %d\n",undefined.Int())

        //panic: syscall/js: call of Value.Float on undefined
        //fmt.Printf("Float: %f\n",undefined.Float())

        //panic: syscall/js: call of Value.Bool on undefined
        //fmt.Printf("Bool: %t\n",undefined.Bool())

        //String: undefined
        fmt.Printf("String: %s\n", undefined.String())
}

What did you expect to see?

a panic or string's zero value ""

What did you see instead?

"null" on null values
"undefined" on undefined values

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.arch-wasmWebAssembly issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions