Object.seal, read references, and code reliability
Alex Kodat
alexkodat at gmail.com
Tue Aug 15 17:35:05 UTC 2017
Sorry, that was a stupid comment on my part. I was thinking that if you typed foo.bah instead of foo.bar() (making two mistakes) we’d catch it. Pretty thin gruel. I guess, at least with the current incarnation of V8 you would get a slightly nicer error message if you typed foo.bah() instead of foo.bar() assuming foo were guarded. Right now foo.bah() indicates that foo.bah is not a function. But that’s just an implementation detail.
So I’d go back to Object.guard being mostly useful for validating references to non-function properties which was my original motivation.
From: T.J. Crowder [mailto:tj.crowder at farsightsoftware.com]
Sent: Tuesday, August 15, 2017 10:39 AM
To: Alex Kodat <alexkodat at gmail.com>
Cc: Jordan Harband <ljharb at gmail.com>; es-discuss at mozilla.org
Subject: Re: Object.seal, read references, and code reliability
On Tue, Aug 15, 2017 at 4:10 PM, Alex Kodat <mailto:alexkodat at gmail.com> wrote:
>
> But, now that I think about it, we might Object.guard them as it
> would catch the occasional boo-boo where one forgets to put the
> () on a function call
How would `Object.guard` catch that? My understanding of your suggestion was that reading a property from a "guarded" object that it didn't have (`"propname" in obj` would be false) would throw. If you do `foo.bar` where you meant `foo.bar()`, the `bar` property still exists on `foo`.
-- T.J. Crowder
More information about the es-discuss
mailing list