Added GopherJS support

This commit is contained in:
tidwall 2019-01-14 08:40:04 -07:00
parent 081192fa2e
commit 5a96cfda70
3 changed files with 35 additions and 39 deletions

View File

@ -1,4 +1,4 @@
//+build appengine
//+build appengine js
package gjson

View File

@ -1,4 +1,5 @@
//+build !appengine
//+build !js
package gjson
@ -15,12 +16,6 @@ func getBytes(json []byte, path string) Result {
if json != nil {
// unsafe cast to string
result = Get(*(*string)(unsafe.Pointer(&json)), path)
result = fromBytesGet(result)
}
return result
}
func fromBytesGet(result Result) Result {
// safely get the string headers
rawhi := *(*reflect.StringHeader)(unsafe.Pointer(&result.Raw))
strhi := *(*reflect.StringHeader)(unsafe.Pointer(&result.Str))
@ -55,6 +50,7 @@ func fromBytesGet(result Result) Result {
result.Raw = string(*(*[]byte)(unsafe.Pointer(&rawh)))
result.Str = string(*(*[]byte)(unsafe.Pointer(&strh)))
}
}
return result
}

View File

@ -1361,7 +1361,7 @@ null
}
func TestNumUint64String(t *testing.T) {
i := 9007199254740993 //2^53 + 1
var i int64 = 9007199254740993 //2^53 + 1
j := fmt.Sprintf(`{"data": [ %d, "hello" ] }`, i)
res := Get(j, "data.0")
if res.String() != "9007199254740993" {
@ -1370,7 +1370,7 @@ func TestNumUint64String(t *testing.T) {
}
func TestNumInt64String(t *testing.T) {
i := -9007199254740993
var i int64 = -9007199254740993
j := fmt.Sprintf(`{"data":[ "hello", %d ]}`, i)
res := Get(j, "data.1")
if res.String() != "-9007199254740993" {
@ -1388,7 +1388,7 @@ func TestNumBigString(t *testing.T) {
}
func TestNumFloatString(t *testing.T) {
i := -9007199254740993
var i int64 = -9007199254740993
j := fmt.Sprintf(`{"data":[ "hello", %d ]}`, i) //No quotes around value!!
res := Get(j, "data.1")
if res.String() != "-9007199254740993" {