Skip to content

HTML integration for "Error Stack Accessor" TC39 Proposal#12239

Open
ljharb wants to merge 1 commit intowhatwg:mainfrom
ljharb:error-stack-accessor-integration
Open

HTML integration for "Error Stack Accessor" TC39 Proposal#12239
ljharb wants to merge 1 commit intowhatwg:mainfrom
ljharb:error-stack-accessor-integration

Conversation

@ljharb
Copy link
Contributor

@ljharb ljharb commented Mar 10, 2026

Replace the non-normative "should" language about serializing "interesting accompanying data" with normative steps that explicitly serialize and deserialize the stack trace of Error objects during structured cloning.

In StructuredSerializeInternal, the stack trace is obtained as an implementation-defined string and included in the serialized record as [[Stack]].

In StructuredDeserialize, the Error object is created with a [[Stack]] internal slot, which is set to an implementation-defined value representing the stack trace from the serialized record. This ensures the Error.prototype.stack accessor continues to work properly on deserialized errors.

The bibliography is updated to reference both the Error Stack Accessor and Error Stacks proposals.

This is the HTML integration PR for tc39/proposal-error-stack-accessor.

See tc39/proposal-error-stack-accessor#9 and tc39/proposal-error-stack-accessor#8, as well as whatwg/webidl#1578

(See WHATWG Working Mode: Changes for more details.)


/references.html ( diff )
/structured-data.html ( diff )

Copy link
Collaborator

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

There is other "interesting data" that should still be copied over, such as https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/lineNumber.

@annevk annevk added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: serialize and transfer labels Mar 10, 2026
@ljharb
Copy link
Contributor Author

ljharb commented Mar 11, 2026

@nicolo-ribaudo should that be called out, or left implementation-defined?

Replace the non-normative "should" language about serializing "interesting accompanying data" with normative steps that explicitly serialize and deserialize the stack trace of Error objects during structured cloning.

In StructuredSerializeInternal, the stack trace is obtained as an implementation-defined string and included in the serialized record as [[Stack]].

In StructuredDeserialize, the Error object is created with a [[Stack]] internal slot, which is set to an implementation-defined value representing the stack trace from the serialized record.
This ensures the Error.prototype.stack accessor continues to work properly on deserialized errors.

The bibliography is updated to reference both the Error Stack Accessor and Error Stacks proposals.

This is the HTML integration PR for tc39/proposal-error-stack-accessor.

See tc39/proposal-error-stack-accessor#9 and tc39/proposal-error-stack-accessor#8
@ljharb ljharb force-pushed the error-stack-accessor-integration branch from a426672 to 9f15d18 Compare March 11, 2026 15:33
@nicolo-ribaudo
Copy link
Collaborator

nicolo-ribaudo commented Mar 11, 2026

The old spec text was:

User agents should attach a serialized representation of any interesting accompanying data which are not yet specified, notably the stack property, to serialized.

You replaced it with explicit steps to copy stack, but I think you should also keep including

User agents should attach a serialized representation of any interesting accompanying data which are not yet specified to serialized.

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

And yeah, let's preserve the "interesting accompanying data" step as well. Hopefully one day that won't be needed anymore.

Comment on lines +10389 to +10390
<li><p>Let <var>stack</var> be an <span>implementation-defined</span> string that represents the stack
trace of <var>value</var>. <ref>JSERRORSTACKACCESSOR</ref> <ref>JSERRORSTACKS</ref></p></li>
Copy link
Member

Choose a reason for hiding this comment

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

This needs rewrapping.


<li><p>Any interesting accompanying data attached to <var>serialized</var> should be
deserialized and attached to <var>value</var>.</p></li>
<li><p>Set <var>value</var>.[[Stack]] to an implementation-defined value that represents
Copy link
Member

Choose a reason for hiding this comment

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

xref implementation-defined. Although, can it literally be anything? We already serialized it to a string. Can it stay a string or do some implementations deserialize to an Array or Object? It would be nice if only one side had to be implementation-defined and we could at least agree on the value type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The user-visible value is always a string, but implementations can store any data structure they like there, and they will want to if https://github.com/tc39/proposal-error-stacks advances.

Copy link
Member

Choose a reason for hiding this comment

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

But then let’s just serialize as an implementation-defined string and return that as-is here? Alternatively I suppose we could have implementation-defined on both sides but then we don’t have to require a string when serializing, but do need to require that here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: serialize and transfer

Development

Successfully merging this pull request may close these issues.

3 participants