Skip to content

Commit c81787f

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 c81787f

2 files changed

Lines changed: 29 additions & 11 deletions

File tree

src/core/friendly_errors/param_validator.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,14 +573,32 @@ 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+
fn._internal = function(callback) {
579+
const wasInternalCall = this._isUserCall;
580+
this._isUserCall = true;
581+
try {
582+
return callback();
583+
} finally {
584+
this._isUserCall = wasInternalCall;
585+
}
586+
};
587+
576588
p5.decorateHelper(
577589
/^(?!_).+$/,
578590
function(target, { name }){
579591
return function(...args){
580-
if (!p5.disableFriendlyErrors && !p5.disableParameterValidator) {
581-
validate(name, args);
592+
const wasInternalCall = this._isUserCall;
593+
this._isUserCall = true;
594+
try {
595+
if (!wasInternalCall && !p5.disableFriendlyErrors && !p5.disableParameterValidator) {
596+
validate(name, args);
597+
}
598+
return target.apply(this, args);
599+
} finally {
600+
this._isUserCall = wasInternalCall;
582601
}
583-
return target.apply(this, args);
584602
};
585603
}
586604
);

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)