News for hackers. Stuff that matters.
Re:Goodbye “undefined is not a function” by paulirish on Sunday February 22, 2015 @04:59PM (#9091337)
This change required adding a pretty-printer into V8 to massage that AST back to something recognizable: https://codereview.chromium.org/861623002

Still, there are decent improvements we could make. Star, or better yet, comment on https://code.google.com/p/chromium/issues/detail?id=259443 with how you get caught out by weak error messages. We want the debugging cycle to be a lot more direct from error to fix.

Re:Goodbye “undefined is not a function” by evilpie on Sunday February 22, 2015 @06:05PM (#9091640)
SpiderMonkey has something that we call ExpressionDecompiler [1]. Basically it allows us to decompile some subset of the JS bytecode. Fun fact: At some point in time SpiderMonkey could actually decompile all bytecode and this is how we used to generate the result of Function#toString. [2]

[1] https://dxr.mozilla.org/mozilla-central/search?q=ExpressionD... [2] https://bugzilla.mozilla.org/show_bug.cgi?id=718969

Re:Goodbye “undefined is not a function” by notatoad on Sunday February 22, 2015 @11:40PM (#9092583)
It doesn't seem relevant to the bug you posted, but as long as you're here... I'm always annoyed by the vagueness of JSON.parse syntax errors. Instead of showing the source file and line number of the call to json.parse (or even better the location of the syntax error in the json string it failed to parse) I get "uncaught syntax error in index.html:1". I know now that that usually means i've forgotten to wrap a json.parse in a try..catch, but it's caught me out a few times.
Re:Goodbye “undefined is not a function” by po on Sunday February 22, 2015 @07:18PM (#9091871)
Thank you. This will save so much development time globally.

Please also look into the "Script error" message. I know it is intentionally non-descript to prevent leaking information about cross domain requests but there has to be something that is safe to report that will help developers narrow down what is causing it.

Re:Goodbye “undefined is not a function” by jon-wood on Monday February 23, 2015 @04:36AM (#9093387)
Given developers can usually narrow it down after a bit of trial and error I see no reason to obfuscate this. By its nature all the source is available to anyone asking, so let's just stop making CORS debugging such a pain.
Re:Goodbye “undefined is not a function” by inglor on Sunday February 22, 2015 @07:31PM (#9091905)
Hey Paul great work! Any idea on when the promises support in the dev tools is landing?
Re:Goodbye “undefined is not a function” by tootie on Sunday February 22, 2015 @05:38PM (#9091534)
Can it throw an exception when we're using a js library that isn't cool anymore?
Re:Goodbye “undefined is not a function” by FLUX-YOU on Sunday February 22, 2015 @05:47PM (#9091572)
Exceptions as a service.js
Re:Goodbye “undefined is not a function” by drcode on Sunday February 22, 2015 @05:36PM (#9091527)
First, I get a roomba, and now this...

For those of you who argue that the US standard of living hasn't improved since the 70s: How do you defend your position in the face of this overwhelming counter-evidence?

Re:Goodbye “undefined is not a function” by UnoriginalGuy on Sunday February 22, 2015 @05:46PM (#9091566)
I'd just point to C++'s error output: http://www.codeproject.com/KB/cpp/791461/errors_temp.PNG
Re:Goodbye “undefined is not a function” by shultays on Monday February 23, 2015 @03:48AM (#9093264)
All I see is blonde, brunette and redhead
Re:Goodbye “undefined is not a function” by rgawdzik on Monday February 23, 2015 @04:28AM (#9093361)
Reference for those confused: https://www.youtube.com/watch?v=3vAnuBtyEYE
Re:Goodbye “undefined is not a function” by iopq on Sunday February 22, 2015 @07:54PM (#9091983)
I can't leave my socks on the floor anymore because Roomba will eat them.
Re:Goodbye “undefined is not a function” by babby on Monday February 23, 2015 @01:36AM (#9092939)
Bug or feature?
Re:Goodbye “undefined is not a function” by iopq on Monday February 23, 2015 @02:05AM (#9093024)
That just means I lock my room's door and it never gets cleaned. I wish it would just make me not put my socks on the floor.
Re:Goodbye “undefined is not a function” by Zarel on Sunday February 22, 2015 @04:03PM (#9091075)
I think "foo.bar is undefined, not a function" might be clearer.
Re:Goodbye “undefined is not a function” by kevan on Sunday February 22, 2015 @06:50PM (#9091793)
This would help a lot in case where you have multiple calls chained together.

    foo.bar().fiz().buz()
What's undefined, bar, fiz, or buz? Then you have to set a breakpoint to find out. Most people I know try to avoid writing code like this, but Knockout ViewModels are a common place where this bites me.
Re:Goodbye “undefined is not a function” by eyko on Sunday February 22, 2015 @08:14PM (#9092034)
If bar() or fiz() return undefined (i.e. don't return at all), then you will still get the same error as usual undefined is not an object, I reckon.
Re:Goodbye “undefined is not a function” by saraid216 on Sunday February 22, 2015 @10:11PM (#9092342)
The issue isn't that the functions are returning undefined. It's...

  foo = {}
  foo.bar()
Or, more commonly,

  foo = {};
  bar = 'bar';
  foo[bar]();
Re:Goodbye “undefined is not a function” by schrijver on Sunday February 22, 2015 @04:36PM (#9091226)
Not just clearer, transmits more information!
Re:Goodbye “undefined is not a function” by CmonDev on Monday February 23, 2015 @04:19AM (#9093327)
Even better: "Error, you are using JavaScript."
Re:Goodbye “undefined is not a function” by rtfeldman on Sunday February 22, 2015 @05:41PM (#9091547)
This is cool, although the title reminded me of one of my favorite parts of Elm[0]...I've effectively said goodbye to “undefined is not a function” because I've said goodbye to runtime exceptions in general.

More specifically, I have yet to write Elm code that compiles and throws a runtime exception. I sure don't miss seeing "undefined is not a function!"

A top-shelf compiler is a hell of a drug. :)

[0] http://elm-lang.org

Re:Goodbye “undefined is not a function” by millstone on Sunday February 22, 2015 @06:25PM (#9091710)
How does Elm handle browser differences? For example, window.clipboardData.setData is only defined in IE, so what happens if I call it unconditionally from Elm, and am using Firefox?
Re:Goodbye “undefined is not a function” by rtfeldman on Sunday February 22, 2015 @07:08PM (#9091837)
Depends on what you're doing. In some cases Elm.Native will take care of browser differences.

In general, Elm's replacement for the concept of undefined is Maybe, and the compiler will tell you if you forgot to handle something properly:

http://elm-lang.org/edit/examples/Functional/Maybe.elm

Re:Goodbye “undefined is not a function” by millstone on Sunday February 22, 2015 @07:50PM (#9091975)
After some research, it looks like my answer is that I can't call it unconditionally from Elm. Elm doesn't provide an easy way to access arbitrary JavaScript properties, and doesn't attempt to expose all of the functionality of the browser, but instead provides its own API.
Re:Goodbye “undefined is not a function” by DigitalSea on Sunday February 22, 2015 @05:26PM (#9091481)
This has been one of the biggest annoyances of debugging Javascript I can think of. Maybe it is rather small to many, but this is a big deal for me and I cannot wait for it to land in the stable version of Chrome (even though I am a Firefox user), I still test in Chrome.
Re:Goodbye “undefined is not a function” by jordanthoms on Sunday February 22, 2015 @04:57PM (#9091327)
This is one of my pet peeves with most languages' error messages - e.g in Ruby: 2.2.0 :001 > a = nil; b = " "; c = "a"; 2.2.0 :002 > a + b + c NoMethodError: undefined method `+' for nil:NilClass from (irb):2

It would be trivial to tell me what the name of the nil variable was - in this case it's obvious, but it's often not.

Re:Goodbye “undefined is not a function” by adrusi on Sunday February 22, 2015 @05:13PM (#9091412)
Except in Ruby, that error is raised by `NilClass#method_missing`. `method_missing` gets to know the name of the method being called, and the arguments passed to it, but it deals with the value, not the variable. It wouldn't be "trivial" to report the name of the variable, it would probably involve intercepting all NoMethodErrors raised by NilClass and then dropping into the debugger to know where exactly execution stopped. I'm not sure this is even possible with the current architecture of the Ruby interpreter.
Re:Goodbye “undefined is not a function” by nilved on Sunday February 22, 2015 @05:31PM (#9091503)
Re:Goodbye “undefined is not a function” by jfaucett on Sunday February 22, 2015 @05:33PM (#9091515)
This is awesome! If there's one area that still needs a lot of work in the js world I think its exception messages. Its hard to believe its 2015 and its still so hard get clean stack traces for your minified js in production since you can't source map it there.

I wonder how large js apps handle production debugging and error reporting on all browsers? The last time I tried window.onerror it had decent support but not comprehensive support across browsers. Maybe its just me but this seems like a problem really needing to be solved, especially as js apps get bigger and bigger.

Re:Goodbye “undefined is not a function” by TheAceOfHearts on Sunday February 22, 2015 @05:42PM (#9091551)
Why can't you use source maps in production?
Re:Goodbye “undefined is not a function” by pimlottc on Monday February 23, 2015 @03:00AM (#9093163)
OP may be referring to jQuery's removal of the sourcemap comment last year, starting from 1.11/2.1 [0]. Basically, many sites deploy the minified library without the sourcemap, leading to tons of 404 errors which confuse users.

0: http://bugs.jquery.com/ticket/14415

Re:Goodbye “undefined is not a function” by woah on Sunday February 22, 2015 @07:24PM (#9091887)
You usually step through the code you were last working on and it's in there.
Re:Goodbye “undefined is not a function” by breck on Sunday February 22, 2015 @05:37PM (#9091531)
Use a query string to run an unminified version in prod.
Re:Goodbye “undefined is not a function” by piotrkaminski on Sunday February 22, 2015 @05:42PM (#9091550)
I just use https://getsentry.com/. Seems to work pretty well, both across browsers and with my minified code.
Re:Goodbye “undefined is not a function” by codewithcheese on Sunday February 22, 2015 @04:16PM (#9091135)
Happy to see someone is working on improving js error messages. This is a good example of why people hate Javascript.
Re:Goodbye “undefined is not a function” by Fiahil on Sunday February 22, 2015 @05:01PM (#9091345)
I would like to add fuel on this javascript-hate fire: https://www.destroyallsoftware.com/talks/wat
Re:Goodbye “undefined is not a function” by saraid216 on Sunday February 22, 2015 @10:13PM (#9092348)
You should watch his other videos.
Re:Goodbye “undefined is not a function” by evincarofautumn on Sunday February 22, 2015 @10:01PM (#9092319)
I am certain that someone somewhere is relying on the old exception message, and that this change broke their code.
Re:Goodbye “undefined is not a function” by acjohnson55 on Sunday February 22, 2015 @10:51PM (#9092423)
They'll either be ready or they'll learn a valuable lesson.
Re:Goodbye “undefined is not a function” by viggity on Sunday February 22, 2015 @09:36PM (#9092261)
If you want something similar for .net, please consider upvoting this issue now that it is open source https://github.com/dotnet/coreclr/issues/25
Re:Goodbye “undefined is not a function” by sandstrom on Sunday February 22, 2015 @03:57PM (#9091050)
This is a great adjustment.

Another one (which IE may have stopped doing in recent versions) is the annoying translation of exceptions.

    O servidor Automation não consegue criar o objeto -- anyone? :)
Re:Goodbye “undefined is not a function” by ygra on Monday February 23, 2015 @01:03PM (#9095770)
If you hate other languages so much, why not use English as your UI language, then?
Re:Goodbye “undefined is not a function” by tosh on Sunday February 22, 2015 @01:44PM (#9090434)
It's available in Chrome Canary.
Re:Goodbye “undefined is not a function” by inglor on Sunday February 22, 2015 @07:25PM (#9091889)
Not going to hijack the thread or anything - I'm just wondering why when I posted it yesterday it went relatively unnoticed?

As someone who might have to do some startup marketting - what did I do wrong from a copyrighting point of view?

Here is the post https://news.ycombinator.com/item?id=9087763

Re:Goodbye “undefined is not a function” by chrisheller on Monday February 23, 2015 @10:33AM (#9094799)
I saw the original link on my phone yesterday. The screenshots in the post were unreadable since pinch and zoom was disabled, so I didn't fully understand until pulling up HN on a larger screen today.

I have no idea how many other people might have read your submission on their phone and had the same issue though.

Re:Goodbye “undefined is not a function” by zo1 on Monday February 23, 2015 @04:08AM (#9093306)
Well, for one, the person that posted this link has 9-10 times more karma than you: karma: 4659

I'm a bit cynical, but I definitely think that had something to do with it if it wasn't just for the timing.

Re:Goodbye “undefined is not a function” by DanBC on Monday February 23, 2015 @10:35AM (#9094812)
I never visit links to Twitter.
Re:Goodbye “undefined is not a function” by akennberg on Monday February 23, 2015 @03:39PM (#9096856)
Can we get a properly working window.onerror? Currently we either get a very generic Script Error (0 information for debugging) or have to wrap every native method in one with a try/catch. This is more for error log collection and aggregation to understand what's breaking in production.
Re:Goodbye “undefined is not a function” by dkersten on Sunday February 22, 2015 @04:38PM (#9091239)
Will this work with source maps?
Re:Goodbye “undefined is not a function” by skybrian on Sunday February 22, 2015 @05:36PM (#9091526)
Someone should try it, but it seems unlikely if V8 is generating the error message. Dev Tools loads the source maps and as far as I know, V8 doesn't know about them.
[deleted]
Re:Goodbye “undefined is not a function” by azeirah on Sunday February 22, 2015 @04:41PM (#9091258)
TypeError: (intermediate value)(...) is not a function

(in firefox :^)

Re:Goodbye “undefined is not a function” by saidajigumi on Sunday February 22, 2015 @05:00PM (#9091343)
What version of FF are you on? I'm seeing this in FF 35.0.1:

    TypeError: foo.bar is not a function
Re:Goodbye “undefined is not a function” by robterrell on Sunday February 22, 2015 @04:55PM (#9091319)
TypeError: undefined is not a function (evaluating 'foo.bar()')

(for completeness, in Safari)

Re:Goodbye “undefined is not a function” by Aldo_MX on Monday February 23, 2015 @05:21AM (#9093492)

  Internet Explorer has stopped working

  Windows is checking for a solution to the problem...

  [||||||||||||||||||||||||||||||||||||||||||||||||||]

                                            [ Cancel ]
Re:Goodbye “undefined is not a function” by PublicEnemy111 on Sunday February 22, 2015 @04:45PM (#9091274)
Uncaught TypeError: (intermediate value)(intermediate value)(...) is not a function

chrome canary

Re:Goodbye “undefined is not a function” by bsimpson on Sunday February 22, 2015 @05:17PM (#9091433)
Certainly a great improvement, but it's sad that the WebKit Dev Tools are well over a decade old, and this change is just coming now. It shows how much room there is for improvement in developer ergonomics.
Re:Goodbye “undefined is not a function” by bpg_92 on Monday February 23, 2015 @08:18AM (#9094074)
This is awesome! "undefined is not a function" was one big problem for me when I started cleaning up code, and didn't know what caused the issue, I spend a lot of time debugging.
Re:Goodbye “undefined is not a function” by criloz2 on Sunday February 22, 2015 @05:26PM (#9091480)
Wow! thanks.. my hate towards JavaScript has been reduced dramatically with this update.
Re:Goodbye “undefined is not a function” by bzbarsky on Sunday February 22, 2015 @08:54PM (#9092146)
Javascript, or V8 and Chrome's devtools? Firefox has had sane error reporting in this situation for quite a long while....
Re:Goodbye “undefined is not a function” by riffraff on Monday February 23, 2015 @01:39AM (#9092949)
while this is awesome, doesn't it affect compatibility? i.e. if a library was checking the error message
Re:Goodbye “undefined is not a function” by Gurkenmaster on Tuesday February 24, 2015 @05:19AM (#9099715)
Re:Goodbye “undefined is not a function” by martinko on Monday February 23, 2015 @01:38AM (#9092946)
If we're lucky, this might make it into node by 2020!
Re:Goodbye “undefined is not a function” by CmonDev on Monday February 23, 2015 @04:16AM (#9093319)
2015.
Re:Goodbye “undefined is not a function” by aerovistae on Sunday February 22, 2015 @11:41PM (#9092587)
YESSSSŚŠSSSSSS