Skip to content

Commit 492c59d

Browse files
committed
skip FES checks on internal calls
track call depth with _isUserCall flag, add _internal() for post-await sections fixes #7817
1 parent ad26404 commit 492c59d

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

src/core/friendly_errors/param_validator.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,14 +573,35 @@ function validateParams(p5, fn, lifecycles) {
573573

574574
fn._validate = validate; // TEMP: For unit tests
575575

576+
// Suppress FES param checking for the duration of a callback.
577+
// Use this to wrap internal p5 calls that happen after an await.
578+
// NOTE: shares the same _isUserCall flag logic as the decorator below.
579+
fn._internal = function(callback) {
580+
const wasInternalCall = this._isUserCall;
581+
this._isUserCall = true;
582+
try {
583+
return callback();
584+
} finally {
585+
this._isUserCall = wasInternalCall;
586+
}
587+
};
588+
589+
// Skip FES validation for nested (internal) calls.
590+
// NOTE: shares the same _isUserCall flag logic as _internal() above.
576591
p5.decorateHelper(
577592
/^(?!_).+$/,
578593
function(target, { name }){
579594
return function(...args){
580-
if (!p5.disableFriendlyErrors && !p5.disableParameterValidator) {
581-
validate(name, args);
595+
const wasInternalCall = this._isUserCall;
596+
this._isUserCall = true;
597+
try {
598+
if (!wasInternalCall && !p5.disableFriendlyErrors && !p5.disableParameterValidator) {
599+
validate(name, args);
600+
}
601+
return target.apply(this, args);
602+
} finally {
603+
this._isUserCall = wasInternalCall;
582604
}
583-
return target.apply(this, args);
584605
};
585606
}
586607
);

src/webgl/material.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,11 @@ function material(p5, fn) {
524524
// Test if we've loaded GLSL or not by checking for the existence of `void main`
525525
let loadedShader;
526526
if (/void\s+main/.exec(fragString)) {
527-
loadedShader = this.createFilterShader(fragString, true);
527+
loadedShader = this._internal(() => this.createFilterShader(fragString, true));
528528
} else {
529-
loadedShader = withGlobalStrands(this, () =>
529+
loadedShader = this._internal(() => withGlobalStrands(this, () =>
530530
this.baseFilterShader().modify(new Function(fragString)),
531-
);
531+
));
532532
}
533533

534534
if (successCallback) {
@@ -1597,7 +1597,7 @@ function material(p5, fn) {
15971597
fn.loadMaterialShader = async function (url, onSuccess, onFail) {
15981598
try {
15991599
const cb = await urlToStrandsCallback(url);
1600-
let shader = withGlobalStrands(this, () => this.buildMaterialShader(cb));
1600+
let shader = this._internal(() => withGlobalStrands(this, () => this.buildMaterialShader(cb)));
16011601
if (onSuccess) {
16021602
shader = onSuccess(shader) || shader;
16031603
}
@@ -1814,9 +1814,9 @@ function material(p5, fn) {
18141814
fn.loadNormalShader = async function (url, onSuccess, onFail) {
18151815
try {
18161816
const cb = await urlToStrandsCallback(url);
1817-
let shader = this.withGlobalStrands(this, () =>
1817+
let shader = this._internal(() => this.withGlobalStrands(this, () =>
18181818
this.buildNormalShader(cb),
1819-
);
1819+
));
18201820
if (onSuccess) {
18211821
shader = onSuccess(shader) || shader;
18221822
}
@@ -1978,7 +1978,7 @@ function material(p5, fn) {
19781978
fn.loadColorShader = async function (url, onSuccess, onFail) {
19791979
try {
19801980
const cb = await urlToStrandsCallback(url);
1981-
let shader = withGlobalStrands(this, () => this.buildColorShader(cb));
1981+
let shader = this._internal(() => withGlobalStrands(this, () => this.buildColorShader(cb)));
19821982
if (onSuccess) {
19831983
shader = onSuccess(shader) || shader;
19841984
}
@@ -2237,7 +2237,7 @@ function material(p5, fn) {
22372237
fn.loadStrokeShader = async function (url, onSuccess, onFail) {
22382238
try {
22392239
const cb = await urlToStrandsCallback(url);
2240-
let shader = withGlobalStrands(this, () => this.buildStrokeShader(cb));
2240+
let shader = this._internal(() => withGlobalStrands(this, () => this.buildStrokeShader(cb)));
22412241
if (onSuccess) {
22422242
shader = onSuccess(shader) || shader;
22432243
}

0 commit comments

Comments
 (0)