Node: Unmatched destructuring of object into array param rises "undefined is not a function" error

Created on 27 Sep 2017  路  3Comments  路  Source: nodejs/node

  • Version: 6.11.3 & 8.6.0
  • Platform: darwin - MacOS 10.12.6

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"
V8 Engine

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.

> 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

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danialkhansari picture danialkhansari  路  3Comments

fanjunzhi picture fanjunzhi  路  3Comments

sandeepks1 picture sandeepks1  路  3Comments

willnwhite picture willnwhite  路  3Comments

stevenvachon picture stevenvachon  路  3Comments