Object.seal, read references, and code reliability
Alex Kodat
akodat at rocketsoftware.com
Tue Aug 15 13:43:44 UTC 2017
-- Jordan Harband wrote ---
- Every non-null/undefined value is checked for "then" when it's passed to a Promise's resolver, not just promises.
----------------------------------------------------------------
OK, fair enough. I didn't realize Promise does this (haven't really used it much). This can be dealt with easily enough by the same technique used for toJSON, simply adding it to guarded object prototypes. All of these issues could also be dealt with by, if Object.guard were to ever make it into the spec, adding magic functions like toJson and then to the base object prototype in the same spec (set to undefined). This would present no backward incompatibilities (well, unless some code is doing something truly odd, IMO) and provides some visibility to these magic functions.
-- Jordan Harband wrote ---
- Every non-null/undefined value, including `Object.create(null)` or `new (class extends null {})`, has valueOf and/or toString checked when attempting to convert it to a primitive.
----------------------------------------------------------------
Sure but these all exist on Object.prototype so these would never throw for guarded objects. Maybe I'm missing something here?
-- Jordan Harband wrote ---
- toJSON was added in 2009/2011; Symbols were added in 2015.
----------------------------------------------------------------
OK, that explains it. And Promise probably didn't use Symbol.then (or whatever) because of the slight extra hassle of having to do object[Symbol.then] = ... instead of just adding a function using object literals, I'd guess.
------
Alex Kodat
Senior Product Architect
Rocket Software
t: +1 781 684 2294 • m: +1 315 527 4764 • w: http://www.rocketsoftware.com/
================================
Rocket Software, Inc. and subsidiaries ■ 77 Fourth Avenue, Waltham MA 02451 ■ Main Office Toll Free Number: +1 877.328.2932
Contact Customer Support: https://my.rocketsoftware.com/RocketCommunity/RCEmailSupport
Unsubscribe from Marketing Messages/Manage Your Subscription Preferences - http://www.rocketsoftware.com/manage-your-email-preferences
Privacy Policy - http://www.rocketsoftware.com/company/legal/privacy-policy
================================
This communication and any attachments may contain confidential information of Rocket Software, Inc. All unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please notify Rocket Software immediately and destroy all copies of this communication. Thank you.
More information about the es-discuss
mailing list