dougwilson / nodejs-depd

Deprecate all the things
MIT License
325 stars 87 forks source link

Stack trace api differences when in strict mode causing TypeErrors #17

Closed jasisk closed 9 years ago

jasisk commented 9 years ago

Can be realized by setting strict mode in test/fixtures/my-lib.

From the API docs:

To maintain restrictions imposed on strict mode functions, frames that have a strict mode function and all frames below (its caller etc.) are not allow to access their receiver and function objects.

Failing test:

  1) deprecate(message) when message omitted should generate message for function call on named function:
     TypeError: Cannot read property 'constructor' of undefined
      at CallSiteGetTypeName (native)
      at defaultMessage (/Users/jsisk/src/node/nodejs-depd/index.js:283:27)
      at Function.log (/Users/jsisk/src/node/nodejs-depd/index.js:234:9)
      at deprecate (/Users/jsisk/src/node/nodejs-depd/index.js:125:9)
      at automsgnamed (/Users/jsisk/src/node/nodejs-depd/test/fixtures/my-lib.js:59:3)
      at callold (/Users/jsisk/src/node/nodejs-depd/test/test.js:116:9)
      at captureStderr (/Users/jsisk/src/node/nodejs-depd/test/test.js:664:5)
      at Context.<anonymous> (/Users/jsisk/src/node/nodejs-depd/test/test.js:118:20)
      at callFn (/Users/jsisk/src/node/nodejs-depd/node_modules/mocha/lib/runnable.js:250:21)
      at Test.Runnable.run (/Users/jsisk/src/node/nodejs-depd/node_modules/mocha/lib/runnable.js:243:7)
      at Runner.runTest (/Users/jsisk/src/node/nodejs-depd/node_modules/mocha/lib/runner.js:373:10)
      at /Users/jsisk/src/node/nodejs-depd/node_modules/mocha/lib/runner.js:451:12
      at next (/Users/jsisk/src/node/nodejs-depd/node_modules/mocha/lib/runner.js:298:14)
      at /Users/jsisk/src/node/nodejs-depd/node_modules/mocha/lib/runner.js:308:7
      at next (/Users/jsisk/src/node/nodejs-depd/node_modules/mocha/lib/runner.js:246:23)
      at Immediate._onImmediate (/Users/jsisk/src/node/nodejs-depd/node_modules/mocha/lib/runner.js:275:5)
      at processImmediate [as _immediateCallback] (timers.js:358:17)
dougwilson commented 9 years ago

I'll take a look into this. Any suggestions are welcome :)

dougwilson commented 9 years ago

Actually, I assume this just make a TypeError from our getThis() call?

jasisk commented 9 years ago

Not super familiar with the call stack api or your normalization stuff, figured I'd capture the issue before diving in to your caller resolution stuff.

getThis fails but so does getTypeName because TypeError: Cannot read property 'constructor' of undefined.

dougwilson commented 9 years ago

That's fine. Really, I just need a definition of what "causing problems" from your title means. Are there Errors being thrown? If so what are they? If not, what's happening?

jasisk commented 9 years ago

Hah. Sorry. Those are the only two TypeErrors I've come across so far.

dougwilson commented 9 years ago

Cool. This is officially a bug at this point :)

jasisk commented 9 years ago

I'll write a test case for realizing a getThis() failure. The getTypeName() can be seen in the existing test by adding 'use strict'; to the my-lib fixture.

jasisk commented 9 years ago
'use strict';
var dep = require('depd')('dep');
var inc = dep.function(function deprecated() {});
inc.apply(inc);
/Users/jsisk/tmp/depd/node_modules/depd/index.js:292
    typeName = callSite.getThis().name || typeName
                                 ^
TypeError: Cannot read property 'name' of undefined
    at defaultMessage (/Users/jsisk/tmp/depd/node_modules/depd/index.js:292:34)
    at Function.log (/Users/jsisk/tmp/depd/node_modules/depd/index.js:235:9)
    at Function.eval (eval at wrapfunction (/Users/jsisk/tmp/depd/node_modules/depd/index.js:414:5), <anonymous>:3:5)
    at Object.<anonymous> (/Users/jsisk/tmp/depd/index.js:4:5)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
dougwilson commented 9 years ago

Nice. I've found a bunch of issues playing with it already :) Hopefully I want to get a new patch version out tonight for this issue :D

jasisk commented 9 years ago

Awesome! Thanks for your attention to this, Doug. :grinning:

dougwilson commented 9 years ago

No problem at all! The TypeError: Cannot read property 'constructor' of undefined is the most odd-ball error of the bunch :) I'm looking through the native V8 code to determine the best way without adding a slow try, haha

jasisk commented 9 years ago

:+1: looking forward to seeing what you come up with.

dougwilson commented 9 years ago

haha. and lol, this isn't super fun; seems V8 didn't completely think of all the different methods in their error API when they implemented use strict, haha. Seems I have to replicate some of those in my code instead of calling the error API methods.

dougwilson commented 9 years ago

I think I have it mostly working so far :)

dougwilson commented 9 years ago

The worse part is that from those API docs:

For those frames, getFunction() and getThis() will return undefined.

This is true... but not for Node.js < 0.12, which throw on getTypeName() from a bug, but Node.js 0.12+ correctly gets the type name.

jasisk commented 9 years ago

Hah. Sorry for opening up this can of worms. :wink:

dougwilson commented 9 years ago

lol. It's no problem. We'll get this fixed :D!

dougwilson commented 9 years ago

Basically it seems like this part of V8 that is in Node.js 0.10 is buggy, lol

dougwilson commented 9 years ago

Ok, so hopefully it's all fixed on master. If you'd be so kind to test using what you saw the issues with, that would be awesome :)

jasisk commented 9 years ago

Tried in my application and in my test cases. Everything works! Thanks, Doug!

dougwilson commented 9 years ago

Sweet :D I plan to publish tonight (US Eastern time) as version 1.0.1

jasisk commented 9 years ago

Sounds good! Thanks again!

jasisk commented 9 years ago

I see it was released. Thanks again, Doug!

dougwilson commented 9 years ago

No problem! Sorry, I got too busy last night to make the release :(

jasisk commented 9 years ago

Haha. Not a problem at all. I appreciate it!