Skip to content

Commit

Permalink
Add null resolver safeguard
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Oct 25, 2023
1 parent 4ecc397 commit 20fdb4d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions languageserver/cmd/languageserver/main_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,25 @@ func start(id int) {
)

addressImportResolver := func(location common.AddressLocation) (code string, err error) {
res := global.Call(globalFunctionName(id, "getAddressCode"), location.String())
getAddressCodeFunc := global.Get(globalFunctionName(id, "getAddressCode"))
if getAddressCodeFunc.IsNull() || getAddressCodeFunc.IsUndefined() {
return "", fmt.Errorf("CLS %d: getAddressCode not defined", id)
}

res := getAddressCodeFunc.Invoke(location.Address().String())
if res.IsNull() || res.IsUndefined() {
return "", fmt.Errorf("CLS %d: getAddressCode failed: %s", id, res)
}
return res.String(), nil
}

stringImportResolver := func(location common.StringLocation) (code string, err error) {
res := global.Call(globalFunctionName(id, "getStringCode"), location.String())
getStringCodeFunc = global.Get(globalFunctionName(id, "getStringCode"))
if getStringCodeFunc.IsNull() || getStringCodeFunc.IsUndefined() {
return "", fmt.Errorf("CLS %d: getStringCode not defined", id)
}

res := getStringCodeFunc.Invoke(location.String())
if res.IsNull() || res.IsUndefined() {
return "", fmt.Errorf("CLS %d: getStringCode failed: %s", id, res)
}
Expand Down

0 comments on commit 20fdb4d

Please sign in to comment.