davidmarkclements / cute-stack

Cute up your stack traces in Node
82 stars 6 forks source link

TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them #8

Closed GerHobbelt closed 8 years ago

GerHobbelt commented 9 years ago

The use of cute-stack causes a fatal abort when using as a library in an npm/gulp plugin, e.g. in gulp-lint-everything, where it is used like this:

// TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
var cute = require('cute-stack');
cute.ui.badLine = require('bad-line');
cute('badLine');

Some debugging showed this bit of code to be the culprit: the commented line below is the edit required to make gulp-lint-everything run (Node v0.10.26 on MSys/Win8/64)

  function details(frame) {
    var fn = frame.getFunction();

    return {
      fn: fn,
      file: frame.getFileName()
        .replace(process.cwd(), '.')
        .replace(/\/node_modules\//g, '♦'),
      line: frame.getLineNumber(),
      args: '', // fn ? fn.arguments : '',   <-- NodeJS runs standard in ES5 strict mode and b0rks fatally with a TypeError here, or so it seems
      name: frame.getFunctionName(),
      meth: frame.getMethodName(),
      sig: fn ? ((fn+'').split('{')[0].trim() + ' { [body] }') : '',
      id: function () {
        return this.name || this.meth || this.sig;
      }
    }
davidmarkclements commented 9 years ago

Hey @GerHobbelt thanks for flagging this - I noticed this a while ago and have a fix for it - just haven't pushed it. Basically as you point out, any function with 'use strict' in it will cause this error when we try to access the arguments property. Cute stack doesn't even currently use the arguments, it's just in there for future use.

As for the fix, I figured out a way to do it without try catch (which I'm not even sure will/can work as expected within prepareStackTrace) and without losing potential to grab args for non stric funcs.

I'll take a look at my fix and get it in, cheers