Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destructuring array assignment to function which returns a non-iterable produces a confusing error #12098

Closed
aneilbaboo opened this issue Mar 28, 2017 · 2 comments · May be fixed by baby636/node#59
Labels
v8 engine Issues and PRs related to the V8 dependency.

Comments

@aneilbaboo
Copy link

aneilbaboo commented Mar 28, 2017

Version: 7.6.0
Platform: Darwin 16.5.0 Darwin Kernel Version 16.5.0: Fri Mar 3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64

function foo() { return {}; }
var [x,y] = foo();  // error claims that foo is not a function

Here is the error:

TypeError: foo is not a function
at repl:1:13
at ContextifyScript.Script.runInThisContext (vm.js:23:33)
at REPLServer.defaultEval (repl.js:334:29)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.onLine (repl.js:531:10)
at emitOne (events.js:101:20)
at REPLServer.emit (events.js:189:7)
at REPLServer.Interface._onLine (readline.js:238:10)
at REPLServer.Interface._line (readline.js:582:8)

This is a rather confusing output. In this example it's trivial to spot the problem, but I stumbled upon it in a more complex situation using argument destructuring and async functions inside a class. I was getting an error that read TypeError: undefined is not a function (because ES6 class methods are %s printed as undefined). A nicer error message would be helpful.

@addaleax addaleax added the v8 engine Issues and PRs related to the V8 dependency. label Mar 28, 2017
@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Mar 28, 2017

@aneilbaboo Unfortunately, Node.js can't fix this as this is a v8 issue. However, there is a report upstream: https://bugs.chromium.org/p/v8/issues/detail?id=5532 You can star it there to draw more attention.

@vsemozhetbyt
Copy link
Contributor

@aneilbaboo I see you've reached out to the v8 issue tracker, so I will go ahead and close this issue for now, but fill free to ask any questions here if you need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants