Skip to content

Commit 21a3d0e

Browse files
committed
address the changes requested by reviewers
1 parent 419bb41 commit 21a3d0e

5 files changed

Lines changed: 18 additions & 28 deletions

File tree

‎src/friendly_errors/param_validator.js‎

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -635,27 +635,14 @@ function validateParams(p5, fn, lifecycles) {
635635
// (buildMaterialShader, buildComputeShader, etc.). They are called
636636
// BEFORE the strands context activates and handle their own validation
637637
// and error reporting internally (e.g. "only available with WebGPU").
638-
if (/^build\w+Shader$/.test(func)) {
638+
if (/^build\w+Shader$/.test(func) && p5._isStrandsContextActive) {
639639
funcSchemas = z.any();
640640
}
641641
// Check _strandsSignatures for explicit bypass entries (value === true)
642642
// regardless of strands context, or array-based overload schemas that
643643
// only apply inside an active strands context.
644-
else if (p5._strandsSignatures?.has(func)) {
645-
const sig = p5._strandsSignatures.get(func);
646-
if (sig === true) {
647-
funcSchemas = z.any();
648-
} else if (p5._isStrandsContextActive && Array.isArray(sig)) {
649-
// Array-based overload schemas only apply inside an active strands
650-
// context; outside of it the normal JSDoc schema is correct.
651-
const nodeSchema = z.union([
652-
z.number(),
653-
z.boolean(),
654-
z.custom(val => val && val.isStrandsNode, { message: 'Expected StrandsNode or primitive' })
655-
]);
656-
const overloads = sig.map(overload => z.tuple(overload.params.map(() => nodeSchema)));
657-
funcSchemas = z.union(overloads);
658-
}
644+
else if (p5._isStrandsContextActive && p5._strandsSignatures?.has(func)) {
645+
funcSchemas = z.any();
659646
}
660647

661648
if (!funcSchemas) {

‎src/strands/p5.strands.js‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ function strands(p5, fn) {
121121
ctx.active = active;
122122
ctx.renderer = renderer;
123123
ctx.baseShader = baseShader;
124-
ctx.previousFES = p5.disableFriendlyErrors;
125124
ctx.windowOverrides = {};
126125
ctx.fnOverrides = {};
127126
ctx.graphicsOverrides = {};
@@ -160,7 +159,6 @@ function strands(p5, fn) {
160159
ctx.active = false;
161160
ctx.renderer = null;
162161
ctx.baseShader = null;
163-
ctx.previousFES = p5.disableFriendlyErrors;
164162
ctx.windowOverrides = {};
165163
ctx.fnOverrides = {};
166164
ctx.graphicsOverrides = {};

‎src/strands/strands_api.js‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,10 @@ export function initGlobalStrandsAPI(p5, fn, strandsContext) {
478478
};
479479
//////////////////////////////////////////////
480480
// Builtins, uniforms, variable constructors
481-
//////////////////////////////////////////////
482-
p5._strandsSignatures = p5._strandsSignatures || new Map();
483-
484481
for (const [functionName, overrides] of Object.entries(
485482
strandsBuiltinFunctions
486483
)) {
487-
p5._strandsSignatures.set(functionName, overrides);
484+
p5._strandsSignatures.set(functionName, true);
488485
const isp5Function = overrides[0].isp5Function;
489486
if (isp5Function) {
490487
const originalFn = fn[functionName];

‎test/unit/core/param_errors.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,4 +462,12 @@ suite('Validate Params', function () {
462462
assert.isFalse(result.success);
463463
});
464464
});
465+
466+
suite('validateParams: math functions without strands context', function () {
467+
test('map(): fails with string parameters outside strands', function () {
468+
const result = mockP5Prototype._validate('p5.map', ['a', 'b']);
469+
assert.isFalse(result.success);
470+
assert.isTrue(result.error.toString().includes('Expected at least 5 arguments'));
471+
});
472+
});
465473
});

‎test/unit/webgl/p5.RendererGL.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,21 @@ suite('p5.RendererGL', function () {
102102
});
103103

104104
test('shader creation logs a warning', function() {
105-
const shader = myp5.buildMaterialShader(() => {});
105+
myp5.buildMaterialShader(() => {});
106106
expect(logSpy).toHaveBeenCalled();
107107
expect(logSpy.mock.calls.length).toEqual(1);
108108
});
109109

110110
test('warning logs only once with multiple shaders', function() {
111-
const shader = myp5.buildMaterialShader(() => {});
112-
const shader2 = myp5.buildMaterialShader(() => {});
111+
myp5.buildMaterialShader(() => {});
112+
myp5.buildMaterialShader(() => {});
113113
expect(logSpy).toHaveBeenCalled();
114114
expect(logSpy.mock.calls.length).toEqual(1);
115115
});
116116

117117
test('warning logs only once with multiple strands calls', function() {
118-
const shader = myp5.buildMaterialShader(() => {});
119-
const shader2 = myp5.buildFilterShader(() => {});
118+
myp5.buildMaterialShader(() => {});
119+
myp5.buildFilterShader(() => {});
120120
expect(logSpy).toHaveBeenCalled();
121121
expect(logSpy.mock.calls.length).toEqual(1);
122122
});
@@ -134,7 +134,7 @@ suite('p5.RendererGL', function () {
134134
});
135135

136136
test('no warnings are logged', function() {
137-
const shader = myp5.buildMaterialShader(() => {});
137+
myp5.buildMaterialShader(() => {});
138138
expect(logSpy).not.toHaveBeenCalled();
139139
});
140140
});

0 commit comments

Comments
 (0)