getOwnPropertyDescriptor side effects

Jordan Harband ljharb at gmail.com
Thu Jan 12 05:39:53 UTC 2017


Per https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptor
, `Object.getOwnPropertyDescriptor` will throw if you pass it `null` or
`undefined` as the first argument, if you pass it something as the second
argument that can't be coerced to a primitive (ie, a valueOf or toString
throws, or both are missing), or if the object you pass is a Proxy (or
other exotic object) whose `[[GetOwnProperty]]` trap throws or returns
anything other than an Object or `undefined`.

On Wed, Jan 11, 2017 at 5:55 PM, Isiah Meadows <isiahmeadows at gmail.com>
wrote:

> I was expecting the error to throw on invoking the getter. Calling `Object.getOwnPropertyDescriptor`
> should *never* do that (spec invariant).
>
> On Wed, Jan 11, 2017, 15:30 Boris Zbarsky <bzbarsky at mit.edu> wrote:
>
>> On 1/11/17 3:12 PM, Isiah Meadows wrote:
>> > Okay. The error stack being constructed that early is odd, though.
>>
>> I'm not sure I follow.  The error stack in SpiderMonkey and V8 (and
>> JavaScriptCore too, afaict) is captured at the point when the Error
>> object is created.  The captured thing is information that can be used
>> to construct a stack string later.
>>
>> Then getting .stack constructs the stack string.  This operation is
>> somewhat expensive, so is deferred until someone asks.
>>
>> In V8, the stringification process includes an explicit
>> script-modifiable hook: the "prepareStackTrace" property of the Error
>> constructor.
>>
>> Is the odd part the stack capture during Error object construction?
>> Were you expecting it to only be captured at the throw point?
>>
>> -Boris
>>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170111/b22b195e/attachment-0001.html>


More information about the es-discuss mailing list