Finalize property call fix

This commit is contained in:
Guillaume Ballet 2019-12-02 18:37:24 +01:00
parent f857b8076b
commit 2c78ae55f5

View file

@ -397,16 +397,12 @@ type jsonrpcCall struct {
// Send implements the web3 provider "send" method. // Send implements the web3 provider "send" method.
func (b *bridge) Send(call goja.FunctionCall) (response goja.Value) { func (b *bridge) Send(call goja.FunctionCall) (response goja.Value) {
// Remarshal the request into a Go value. // Remarshal the request into a Go value.
stringify, isFunc := goja.AssertFunction(b.runtime.Get("JSON.stringify")) reqVal, err := call.Argument(0).ToObject(b.runtime).MarshalJSON()
if !isFunc {
throwJSException(b.runtime, "JSON.stringify isn't a function")
}
reqVal, err := stringify(call.Argument(0))
if err != nil { if err != nil {
throwJSException(b.runtime, err.Error()) throwJSException(b.runtime, err.Error())
} }
var ( var (
rawReq = reqVal.String() rawReq = string(reqVal)
dec = json.NewDecoder(strings.NewReader(rawReq)) dec = json.NewDecoder(strings.NewReader(rawReq))
reqs []jsonrpcCall reqs []jsonrpcCall
batch bool batch bool
@ -436,11 +432,7 @@ func (b *bridge) Send(call goja.FunctionCall) (response goja.Value) {
// raw message for some reason. // raw message for some reason.
resp.Set("result", goja.Null()) resp.Set("result", goja.Null())
} else { } else {
parse, isFunc := goja.AssertFunction(b.runtime.Get("JSON.parse")) resultVal, err := b.runtime.RunString(string(result))
if !isFunc {
throwJSException(b.runtime, "JSON.parse isn't a function")
}
resultVal, err := parse(b.runtime.ToValue(string(result)))
if err != nil { if err != nil {
setError(resp, -32603, err.Error()) setError(resp, -32603, err.Error())
} else { } else {