Skip to content

Commit e257d89

Browse files
naugturerights
authored andcommitted
feat(ses): prepareStackTrace CallSite toString fallback for Hermes
1 parent ee16985 commit e257d89

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
@@ -200,6 +200,7 @@ export const tameV8ErrorConstructor = (
200200
InitialError,
201201
errorTaming,
202202
stackFiltering,
203+
callSiteToStringFallback,
203204
) => {
204205
if (errorTaming === 'unsafe-debug') {
205206
throw TypeError(
@@ -232,6 +233,10 @@ export const tameV8ErrorConstructor = (
232233

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

0 commit comments

Comments
 (0)