Skip to content

Commit

Permalink
BAAS-24694: Ensure Object.fromEntries calls are nil-safe (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
UnicodeSnowman authored Oct 4, 2023
1 parent 2bb76f0 commit dabd75f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion builtin_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ func (r *Runtime) object_fromEntries(call FunctionCall) Value {
itemObj := r.toObject(nextValue)
k := itemObj.self.getIdx(i0, nil)
v := itemObj.self.getIdx(i1, nil)
key := toPropertyKey(k)
key := toPropertyKey(nilSafe(k))

createDataPropertyOrThrow(result, key, v)
})
Expand Down
6 changes: 6 additions & 0 deletions builtin_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ func TestObject_fromEntries(t *testing.T) {
[ o.a, o.b, o.c ]
`, "1,true,sea",
},
{
`
var o = Object.fromEntries([['a', 1], [, 'empty'], ['b', true]]);
[ o.a, o[undefined], o.b ]
`, "1,empty,true",
},
} {
actual, err := vm.RunString(tt.js)
if err != nil {
Expand Down

0 comments on commit dabd75f

Please sign in to comment.