proposal-error-stacks

ECMAScript Proposal, specs, and reference implementation for Error.prototype.stack / System.getStack

  • 所有者: tc39/proposal-error-stacks
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Error Stacks

ECMAScript Proposal, specs, and reference implementation for Error.prototype.stack/System.getStack/System.getStackString

Spec drafted by @ljharb along with @erights.

This proposal is currently stage 1 of the process.

Rationale

Errors have never had a stack trace attached in the language spec — however, implementations have very consistently provided one on a property named “stack” on instantiated Error objects. There has long been concern about standardizing stack traces improperly - such that implementations could not claim to be fully compliant while also providing security guarantees. This proposal is an attempt to standardize the intersection of existing browser behavior, in a way that addresses these security concerns.

Compatibility

Object.getOwnPropertyDescriptor(new Error(), 'stack');
Object.getOwnPropertyDescriptor(Error.prototype, 'stack');

V8 in Node 7+ and Chrome 54+: stack is an own property on Error instances which claims to be a value property ({"value":"(stack here)","writable":true,"enumerable":false,"configurable":true), but V8's Error has exotic behavior for that acts like a getter the first time (if there's been no set first) by triggering prepareStackTrace and setting stack, as discussed in this thread. After that, it behaves like a standard value property.

V8 in Node <= 6 and Chrome <= 53: stack is an own property on Error instances with a getter/setter: { configurable: true, enumerable: false }

  • The getter returns undefined with a non-Error receiver, and returns the stack property (whatever its current value may be) otherwise.
  • The setter is a no-op with a non-Error object receiver, and sets the return of the stack getter otherwise.

Safari: stack is an own string data property on Error instances: { configurable: true, enumerable: false, writable: true }

Firefox: stack is an own property on Error.prototype: { configurable: true, enumerable: false }

  • The getter throws on a non-Error receiver, and returns the original stack trace otherwise.
  • The setter sets the stack property on a non-Error receiver, and is a no-op on an Error receiver.

Naming

Error.prototype.stack is set in stone - this is a defacto reality, and will be implemented in Annex B.

Spec

You can view the spec in markdown format or rendered as HTML.

主要指标

概览
名称与所有者tc39/proposal-error-stacks
主编程语言HTML
编程语言HTML (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2016-10-24 22:23:20
推送于2024-02-08 17:25:54
最后一次提交
发布数0
用户参与
星数180
关注者数34
派生数12
提交数37
已启用问题?
问题数44
打开的问题数13
拉请求数4
打开的拉请求数5
关闭的拉请求数1
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?