tc39 / proposal-error-stacks

ECMAScript Proposal, specs, and reference implementation for Error.prototype.stack / System.getStack
https://tc39.github.io/proposal-error-stacks/
MIT License
170 stars 13 forks source link

name of function #24

Closed zoobot closed 5 years ago

zoobot commented 5 years ago

Hi I am looking for a replacement for arguments.callee.name and they referred me here.

Was wondering if you can add stack.name to Object.getOwnPropertyDescriptor(new Error(), 'stack') { value, writable, enumerable, configurable, name }

util = require('util');
function testNAME() {
  console.log(`arguments.callee.name: ${arguments.callee.name} \n`);

  console.log(`Object.getOwnPropertyDescriptor(new Error(), 'stack'): ${Object.getOwnPropertyDescriptor(new Error(), 'stack')}  \n`);

  console.log(`Object.getOwnPropertyDescriptor(new Error(), 'stack'): ${util.inspect(Object.getOwnPropertyDescriptor(new Error(), 'stack'), false, 10, true)} \n`);

  console.log(`Object.getOwnPropertyDescriptor(new Error(), 'stack'): ${util.inspect(Object.getOwnPropertyDescriptor(new Error(), 'stack'), false, 10, true)} \n`);

}

testNAME()

arguments.callee.name: testNAME

Object.getOwnPropertyDescriptor(new Error(), 'stack'): [object Object]

Object.getOwnPropertyDescriptor(new Error(), 'stack'): { value: 'Error\n at testNAME (/mnt/tb/TB-warehouse-automation/test5.js:7:118)\n at Object. (/mnt/tb/TB-warehouse-automation/test5.js:14:1)\n at Module._compile (internal/modules/cjs/loader.js:689:30)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)\n at Module.load (internal/modules/cjs/loader.js:599:32)\n at tryModuleLoad (internal/modules/cjs/loader.js:538:12)\n at Function.Module._load (internal/modules/cjs/loader.js:530:3)\n at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)\n at startup (internal/bootstrap/node.js:266:19)\n at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)', writable: true, enumerable: false, configurable: true }

Object.getOwnPropertyDescriptor(new Error(), 'stack'): 'testNAME (/mnt/tb/TB-warehouse-automation/test5.js:9:118)\n at Object. (/mnt/tb/TB-warehouse-automation/test5.js:14:1)\n at Module._compile (internal/modules/cjs/loader.js:689:30)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)\n at Module.load (internal/modules/cjs/loader.js:599:32)\n at tryModuleLoad (internal/modules/cjs/loader.js:538:12)\n at Function.Module._load (internal/modules/cjs/loader.js:530:3)\n at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)\n at startup (internal/bootstrap/node.js:266:19)\n at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)'

ljharb commented 5 years ago

Can you elaborate on why you need to dynamically reference the name of a function, inside itself? You wrote the name “testNAME”, so you could write it in the code too?

ljharb commented 5 years ago

In this case you could even use testNAME.name

ljharb commented 5 years ago

Closing; happy to reopen with some more information.