Object.getOwnPropertyDescriptor: argument is not an Object
Safari
Requested property descriptor of a value that is not an object.
Opera
Object.getOwnPropertyDescriptor: first argument not an Object
Android
Object.getOwnPropertyDescriptor called on non-object
Which practically boils down to the same thing.
Reason
According to ES 5.1 standard if first argument to Object.getOwnPropertyDescriptor is not an Object it throws a TypeError exception. That's what we get in failing platforms.
According to ES 2015 standard the first argument is always coerced to object.
All failing platforms seem to behave according to ES 5 standard. In our case the function causing the errors is asDeepMutable, which just passes whatever it gets to Object.getOwnPropertyDescriptor. It is being called by two other functions asMutableArray and asMutableObject. Both iterate indiscriminately over elements / keys and pass them to asDeepMutable. So when the value is not an object (e.g. a number, null, etc.) the ES 5 platforms are throwing errors.
Solution
Test if type of value passed to asDeepMutable is object and only recur if it is. Otherwise return unchanged value. This shall prevent calling asMutable with deep option on leaf properties of immutable object.
Also the if statement is now split into multiple lines for readability - there are four alternative conditions there and it was looking really messy on a single line IMO.
Fix two tests that are failing on some platforms.
Tests
Platforms
Errors
Which practically boils down to the same thing.
Reason
According to ES 5.1 standard if first argument to
Object.getOwnPropertyDescriptor
is not anObject
it throws aTypeError
exception. That's what we get in failing platforms.According to ES 2015 standard the first argument is always coerced to object.
All failing platforms seem to behave according to ES 5 standard. In our case the function causing the errors is asDeepMutable, which just passes whatever it gets to
Object.getOwnPropertyDescriptor
. It is being called by two other functions asMutableArray and asMutableObject. Both iterate indiscriminately over elements / keys and pass them toasDeepMutable
. So when the value is not an object (e.g. anumber
,null
, etc.) the ES 5 platforms are throwing errors.Solution
Test if type of value passed to
asDeepMutable
is object and only recur if it is. Otherwise return unchanged value. This shall prevent calling asMutable with deep option on leaf properties of immutable object.Also the if statement is now split into multiple lines for readability - there are four alternative conditions there and it was looking really messy on a single line IMO.