From 18eaf39766e74da362af347a11cce2f6fe6d76e3 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sat, 7 Mar 2026 01:41:07 -0600 Subject: [PATCH] Issue #2304 - Part 5 - Add cause property when a cause is present. I thought this was just to check whether it should be added, but is necessary. --- js/src/vm/ErrorObject.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/js/src/vm/ErrorObject.cpp b/js/src/vm/ErrorObject.cpp index ce7ea2cdbc..46e3777dfb 100644 --- a/js/src/vm/ErrorObject.cpp +++ b/js/src/vm/ErrorObject.cpp @@ -469,6 +469,15 @@ js::ErrorObject::init(JSContext* cx, Handle obj, JSExnType type, MOZ_ASSERT(messageShape->slot() == MESSAGE_SLOT); } + // Similar to the .message property, .cause is present only in some error + // objects -- |new Error("f", {cause: cause})| -- but not in other -- + // |Error.prototype|, |new Error()|, |new Error("f")|. + if (cause.isSome()) { + if (!obj->addDataProperty(cx, cx->names().cause, CAUSE_SLOT, 0)) { + return false; + } + } + MOZ_ASSERT(obj->lookupPure(NameToId(cx->names().fileName))->slot() == FILENAME_SLOT); MOZ_ASSERT(obj->lookupPure(NameToId(cx->names().lineNumber))->slot() == LINENUMBER_SLOT); MOZ_ASSERT(obj->lookupPure(NameToId(cx->names().columnNumber))->slot() ==