When destructuring function call parameters as an array but the function is given an object, node throws "TypeError: undefined is not a function", which is unexpected.
const objectFn = ({ key }) => key
const arrayFn = ([{ key }]) => key
const object = { key: 'value' }
objectFn(object) // all ok
arrayFn([object]) // all ok
arrayFn(object) // throws "TypeError: undefined is not a function"
See https://bugs.chromium.org/p/v8/issues/detail?id=5532
But your case with argument destructuring still gives the same error even in the V8 6.3. The simple destructuring seems OK in V8 6.1 already.
> node.9.0.0.v8-6.1.20170924.nightly.exe
> const [foo] = {}
TypeError: {} is not iterable
> node.9.0.0.v8-6.3.20170924.v8-canary.exe
> const arrayFn = ([{ key }]) => key
> const object = { key: 'value' }
> arrayFn(object)
TypeError: undefined is not a function
> const [{ key }] = { key: 'value' }
TypeError: {(intermediate value)} is not iterable
Maybe it is worth to post your case in the https://bugs.chromium.org/p/v8/issues/detail?id=5532
@vsemozhetbyt thanks for taking a look at this!
Chrome had another related issue: https://bugs.chromium.org/p/v8/issues/detail?id=6522&desc=2
I'll close this out as it's a V8 bug and is being tracked over there. The fix will eventually make its way into node.js.
Most helpful comment
See https://bugs.chromium.org/p/v8/issues/detail?id=5532
But your case with argument destructuring still gives the same error even in the V8 6.3. The simple destructuring seems OK in V8 6.1 already.
Maybe it is worth to post your case in the https://bugs.chromium.org/p/v8/issues/detail?id=5532