diff --git a/Source/JavaScriptCore/runtime/Error.cpp b/Source/JavaScriptCore/runtime/Error.cpp index b5514f770a28..1cc8c72a85ad 100644 --- a/Source/JavaScriptCore/runtime/Error.cpp +++ b/Source/JavaScriptCore/runtime/Error.cpp @@ -262,6 +262,9 @@ JSObject* addErrorInfo(VM& vm, JSObject* error, int line, const SourceCode& sour if (!sourceURL.isEmpty()) { errorInstance->setSourceURL(sourceURL); } + + // materializeErrorInfoIfNeeded() formats the stack through the host, which reads this. + errorInstance->setHasParseLocation(); #endif errorInstance->materializeErrorInfoIfNeeded(vm); diff --git a/Source/JavaScriptCore/runtime/ErrorInstance.cpp b/Source/JavaScriptCore/runtime/ErrorInstance.cpp index 8cb916db573d..6f4afd6ef084 100644 --- a/Source/JavaScriptCore/runtime/ErrorInstance.cpp +++ b/Source/JavaScriptCore/runtime/ErrorInstance.cpp @@ -48,6 +48,9 @@ ErrorInstance::ErrorInstance(VM& vm, Structure* structure, ErrorType errorType) #if ENABLE(WEBASSEMBLY) , m_catchableFromWasm(true) #endif // ENABLE(WEBASSEMBLY) +#if USE(BUN_JSC_ADDITIONS) + , m_hasParseLocation(false) +#endif { } diff --git a/Source/JavaScriptCore/runtime/ErrorInstance.h b/Source/JavaScriptCore/runtime/ErrorInstance.h index c28ce88fd791..05d1bc01ac86 100644 --- a/Source/JavaScriptCore/runtime/ErrorInstance.h +++ b/Source/JavaScriptCore/runtime/ErrorInstance.h @@ -116,6 +116,12 @@ class ErrorInstance : public JSNonFinalObject { void setStackFrames(VM& vm, WTF::Vector&& stackFrames); bool hasMaterializedErrorInfo() const { return m_errorInfoMaterialized; } + // Whether line()/sourceURL() were recorded by addErrorInfo() for a source the parser rejected, as + // opposed to copied from another error (structured clone) or derived from the stack frames. Unlike + // isParseError(), this is not set for parse errors that record no location (eval code), and it is + // set before the stack is materialized, so the host's stack formatter can rely on it. + bool hasParseLocation() const { return m_hasParseLocation; } + void setHasParseLocation() { m_hasParseLocation = true; } #endif JS_EXPORT_PRIVATE String sanitizedToString(JSGlobalObject*); @@ -172,6 +178,9 @@ class ErrorInstance : public JSNonFinalObject { #if ENABLE(WEBASSEMBLY) bool m_catchableFromWasm : 1; #endif +#if USE(BUN_JSC_ADDITIONS) + bool m_hasParseLocation : 1; +#endif }; String appendSourceToErrorMessage(CodeBlock*, BytecodeIndex, const String&, RuntimeType, ErrorInstance::SourceAppender);