Skip to content

Commit bd4fcbc

Browse files
naugturerights
authored andcommitted
feat(ses): prepareStackTrace CallSite toString fallback for Hermes
1 parent 42128b1 commit bd4fcbc

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

packages/ses/src/error/tame-error-constructor.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {
33
apply,
44
construct,
55
defineProperties,
6+
getPrototypeOf,
7+
uncurryThis,
68
setPrototypeOf,
79
getOwnPropertyDescriptor,
810
defineProperty,
@@ -43,6 +45,7 @@ export default function tameErrorConstructor(
4345
prepareStackTrace: originalPrepareStackTrace,
4446
} = FERAL_ERROR;
4547
let platform = 'unknown';
48+
let callSiteToStringFallback;
4649
if (typeof originalCaptureStackTrace === 'function') {
4750
// we might be on v8
4851
if (typeof originalPrepareStackTrace === 'function') {
@@ -65,6 +68,27 @@ export default function tameErrorConstructor(
6568
// error stack logic is close enough that we can treat it
6669
// like v8.
6770
platform = 'v8';
71+
72+
if (`${sst[0]}` === '[object CallSite]') {
73+
const csProto = getPrototypeOf(sst[0]);
74+
75+
const [
76+
getFunctionName,
77+
getMethodName,
78+
getFileName,
79+
getLineNumber,
80+
getColumnNumber,
81+
] = [
82+
uncurryThis(csProto.getFunctionName),
83+
uncurryThis(csProto.getMethodName),
84+
uncurryThis(csProto.getFileName),
85+
uncurryThis(csProto.getLineNumber),
86+
uncurryThis(csProto.getColumnNumber),
87+
];
88+
89+
callSiteToStringFallback = callSite =>
90+
`${getFunctionName(callSite) || getMethodName(callSite)} (${getFileName(callSite)}:${getLineNumber(callSite)}:${getColumnNumber(callSite)})`;
91+
}
6892
}
6993
};
7094
const sacrificialError = new FERAL_ERROR('just for testing');
@@ -247,6 +271,7 @@ export default function tameErrorConstructor(
247271
InitialError,
248272
errorTaming,
249273
stackFiltering,
274+
callSiteToStringFallback,
250275
);
251276
} else if (errorTaming === 'unsafe' || errorTaming === 'unsafe-debug') {
252277
// v8 has too much magic around their 'stack' own property for it to

packages/ses/src/error/tame-v8-error-constructor.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ export const tameV8ErrorConstructor = (
201201
InitialError,
202202
errorTaming,
203203
stackFiltering,
204+
callSiteToStringFallback,
204205
) => {
205206
if (errorTaming === 'unsafe-debug') {
206207
throw TypeError(
@@ -233,6 +234,10 @@ export const tameV8ErrorConstructor = (
233234

234235
const callSiteStringifier = callSite => {
235236
let callSiteString = `${callSite}`;
237+
if (callSiteToStringFallback) {
238+
callSiteString = callSiteToStringFallback(callSite);
239+
}
240+
236241
if (shortenPaths) {
237242
callSiteString = shortenCallSiteString(callSiteString);
238243
}

0 commit comments

Comments
 (0)