Skip to content

Commit 1497816

Browse files
authored
Merge pull request gopherjs#1118 from samhocevar-forks/fix/jsfs-callback-arg-count
Fix jsFS callback-related crashes
2 parents d7a9da2 + aad4eda commit 1497816

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

compiler/natives/src/syscall/fs_js.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ func fsCall(name string, args ...interface{}) (js.Value, error) {
2222
f := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
2323
var res callResult
2424

25-
if jsErr := args[0]; !jsErr.IsNull() {
26-
res.err = mapJSError(jsErr)
25+
// Check that args has at least one element, then check both IsUndefined() and IsNull() on
26+
// that element. In some situations, BrowserFS calls the callback without arguments or with
27+
// an undefined argument: https://github.com/gopherjs/gopherjs/pull/1118
28+
if len(args) >= 1 {
29+
if jsErr := args[0]; !jsErr.IsUndefined() && !jsErr.IsNull() {
30+
res.err = mapJSError(jsErr)
31+
}
2732
}
2833

2934
res.val = js.Undefined()

0 commit comments

Comments
 (0)