Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normative: remove the [[ErrorData]] internal slot #438

Closed
wants to merge 1 commit into from

Conversation

domenic
Copy link
Member

@domenic domenic commented Feb 29, 2016

This replaces the [[ErrorData]] internal slot, which is only used for
brand-checking in Object.prototype.toString, with @@toStringTag. This
lets errors be simple objects with no extra private data, just as if
they were implemented in JavaScript code.

This observably changes the behavior of Error instances with
@@toStringTag modified or shadowed.


Presumably this needs consensus. We can bring it up at the next meeting.

This replaces the [[ErrorData]] internal slot, which is only used for
brand-checking in Object.prototype.toString, with @@toStringTag. This
lets errors be simple objects with no extra private data, just as if
they were implemented in JavaScript code.

This observably changes the behavior of Error instances with
@@toStringTag modified or shadowed.
@domenic domenic added normative change Affects behavior required to correctly evaluate some ECMAScript source text needs consensus This needs committee consensus before it can be eligible to be merged. labels Feb 29, 2016
@domenic
Copy link
Member Author

domenic commented Feb 29, 2016

Hmm. I just realized this might be a bad idea after all.

We have a feature request in HTML to make error objects structured-cloneable: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28389. But after this change, there would be no way for HTML to detect an error object (no brand for it to check), and thus it would try to serialize it as an ordinary object. The structured clone algorithm ignores non-enumerable properties, which error.name and error.message are (not to mention error.stack). So after this change errors would just structured clone as an empty object.

I guess the alternative for HTML would be to do what we advise authors to do, and avoid the nominal brand checking in favor of something like InstanceofOperator(object, %Error%). That does seem reasonable to me.

@ljharb
Copy link
Member

ljharb commented Feb 29, 2016

One great way to detect an error object is Error.isError :-p I've found more concrete use cases for it (tc39/proposal-is-error#2) so I'll be revisiting this in March - and the internal slot will be needed for that if isError gets consensus.

@domenic
Copy link
Member Author

domenic commented Feb 29, 2016

As you know, I oppose that proposal. So I guess we will indeed discuss this all in March.

@@ -23638,7 +23637,7 @@
<!-- es6num="19.5.3" -->
<emu-clause id="sec-properties-of-the-error-prototype-object">
<h1>Properties of the Error Prototype Object</h1>
<p>The Error prototype object is the intrinsic object <dfn>%ErrorPrototype%</dfn>. The Error prototype object is an ordinary object. It is not an Error instance and does not have an [[ErrorData]] internal slot.</p>
<p>The Error prototype object is the intrinsic object <dfn>%ErrorPrototype%</dfn>. The Error prototype object is an ordinary object. It is not an Error instance.</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it still make sense to say "It is not an Error instance", now that everything is an ordinary object?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes as much sense as any of the other "Is not an X instance" statements. Presumably they are all combating the same misconception from ES3 days that the prototype is some kind of exemplar of the type. I don't see why this change would impact things.

@erights
Copy link

erights commented Mar 2, 2016

https://esdiscuss.org/topic/error-stack-strawman is a thread about introducing api for obtaining stacks from errors. This would need to add new internal state to error objects anyway, making them detectably different. So any simplicity gain we make from making errors really just be plain objects is likely short lived.

@annevk
Copy link
Member

annevk commented Mar 2, 2016

Yeah, and implementations likely have internal slots anyway to store data that can be exposed to consoles but not the web.

@domenic
Copy link
Member Author

domenic commented Mar 29, 2016

Per March TC39 discussion, I still think this is a good idea, but it won't make errors non-exotic because of the [[StackData]] internal slots that @erights will be proposing. It might be best to wait until after that lands to continue to propose this, since otherwise errors will appear non-exotic in the spec even though they aren't in reality.

@bterlson
Copy link
Member

Going to close this for now. @eright's proposal supercedes here I think, and I'm not too eager to make changes in advance of that lest we make things harder on ourselves. Status quo, for now.

@bterlson bterlson closed this May 11, 2016
@erights
Copy link

erights commented May 11, 2016

@erights ' and @ljharb 's proposal that is. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs consensus This needs committee consensus before it can be eligible to be merged. normative change Affects behavior required to correctly evaluate some ECMAScript source text
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants