Skip to content

Commit 7ed3470

Browse files
committed
Improve trusted-suppress-native-method scriptlet
Add support for the `stack` parameter.
1 parent f14257d commit 7ed3470

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/js/resources/scriptlets.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ function objectPruneFn(
431431
? safe.String_split.call(rawNeedlePaths, / +/)
432432
: [];
433433
if ( stackNeedleDetails.matchAll !== true ) {
434-
if ( matchesStackTrace(stackNeedleDetails, extraArgs.logstack) === false ) {
434+
if ( matchesStackTraceFn(stackNeedleDetails, extraArgs.logstack) === false ) {
435435
return;
436436
}
437437
}
@@ -531,13 +531,13 @@ function objectFindOwnerFn(
531531

532532
builtinScriptlets.push({
533533
name: 'matches-stack-trace.fn',
534-
fn: matchesStackTrace,
534+
fn: matchesStackTraceFn,
535535
dependencies: [
536536
'get-exception-token.fn',
537537
'safe-self.fn',
538538
],
539539
});
540-
function matchesStackTrace(
540+
function matchesStackTraceFn(
541541
needleDetails,
542542
logLevel = ''
543543
) {
@@ -1169,13 +1169,13 @@ function abortOnStackTrace(
11691169
let v = owner[chain];
11701170
Object.defineProperty(owner, chain, {
11711171
get: function() {
1172-
if ( matchesStackTrace(needleDetails, extraArgs.log) ) {
1172+
if ( matchesStackTraceFn(needleDetails, extraArgs.log) ) {
11731173
throw new ReferenceError(getExceptionToken());
11741174
}
11751175
return v;
11761176
},
11771177
set: function(a) {
1178-
if ( matchesStackTrace(needleDetails, extraArgs.log) ) {
1178+
if ( matchesStackTraceFn(needleDetails, extraArgs.log) ) {
11791179
throw new ReferenceError(getExceptionToken());
11801180
}
11811181
v = a;
@@ -3447,6 +3447,7 @@ builtinScriptlets.push({
34473447
requiresTrust: true,
34483448
fn: trustedSuppressNativeMethod,
34493449
dependencies: [
3450+
'matches-stack-trace.fn',
34503451
'proxy-apply.fn',
34513452
'safe-self.fn',
34523453
],
@@ -3458,9 +3459,8 @@ function trustedSuppressNativeMethod(
34583459
stack = ''
34593460
) {
34603461
if ( methodPath === '' ) { return; }
3461-
if ( stack !== '' ) { return; }
34623462
const safe = safeSelf();
3463-
const logPrefix = safe.makeLogPrefix('trusted-suppress-native-method', methodPath, signature, how);
3463+
const logPrefix = safe.makeLogPrefix('trusted-suppress-native-method', methodPath, signature, how, stack);
34643464
const signatureArgs = safe.String_split.call(signature, /\s*\|\s*/).map(v => {
34653465
if ( /^".*"$/.test(v) ) {
34663466
return { type: 'pattern', re: safe.patternToRegex(v.slice(1, -1)) };
@@ -3478,6 +3478,7 @@ function trustedSuppressNativeMethod(
34783478
return { type: 'exact', value: undefined };
34793479
}
34803480
});
3481+
const stackNeedle = safe.initPattern(stack, { canNegate: true });
34813482
proxyApplyFn(methodPath, function(context) {
34823483
const { callArgs } = context;
34833484
if ( signature === '' ) {
@@ -3499,6 +3500,11 @@ function trustedSuppressNativeMethod(
34993500
}
35003501
}
35013502
}
3503+
if ( stackNeedle.matchAll !== true ) {
3504+
if ( matchesStackTraceFn(stackNeedle) === false ) {
3505+
return context.reflect();
3506+
}
3507+
}
35023508
if ( how === 'debug' ) {
35033509
debugger; // eslint-disable-line no-debugger
35043510
return context.reflect();

0 commit comments

Comments
 (0)