From b8d1878071ef44c84e4280d1e337b2c6d6e82424 Mon Sep 17 00:00:00 2001 From: Cody Date: Wed, 1 Dec 2021 15:40:11 -0700 Subject: [PATCH] reordered if statement. Added test --- src/backend/kernel.js | 4 +-- test/internal/functions-as-strings.js | 45 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/internal/functions-as-strings.js diff --git a/src/backend/kernel.js b/src/backend/kernel.js index dd68ca10..5fcd63e6 100644 --- a/src/backend/kernel.js +++ b/src/backend/kernel.js @@ -320,10 +320,10 @@ class Kernel { addFunction(source, settings = {}) { if (source.name && source.source && source.argumentTypes && 'returnType' in source) { this.functions.push(source); - } else if ('settings' in source && 'source' in source) { - this.functions.push(this.functionToIGPUFunction(source.source, source.settings)); } else if (typeof source === 'string' || typeof source === 'function') { this.functions.push(this.functionToIGPUFunction(source, settings)); + } else if ('settings' in source && 'source' in source) { + this.functions.push(this.functionToIGPUFunction(source.source, source.settings)); } else { throw new Error(`function not properly defined`); } diff --git a/test/internal/functions-as-strings.js b/test/internal/functions-as-strings.js new file mode 100644 index 00000000..9b9058f9 --- /dev/null +++ b/test/internal/functions-as-strings.js @@ -0,0 +1,45 @@ +const { assert, skip, test, module: describe, only } = require('qunit'); +const { GPU } = require('../../src'); + +describe('internal: functions-as-atrings'); + +function functionsAsStrings(mode) { + const gpu = new GPU({ mode }); + const kernel = gpu.createKernel(`function() { + let x = frodo(0) + return x; + }`, { + output: [1], + }); + kernel.addFunction(`function frodo(a){ + return a + 1 + }`) + const result = kernel(); + console.log('result',result) + assert.equal(result[0],1); + gpu.destroy(); +} + +test('boolean expression false auto', () => { + functionsAsStrings(); +}); + +test('boolean expression false gpu', () => { + functionsAsStrings('gpu'); +}); + +(GPU.isWebGLSupported ? test : skip)('boolean expression false webgl', () => { + functionsAsStrings('webgl'); +}); + +(GPU.isWebGL2Supported ? test : skip)('boolean expression false webgl2', () => { + functionsAsStrings('webgl2'); +}); + +(GPU.isHeadlessGLSupported ? test : skip)('boolean expression false headlessgl', () => { + functionsAsStrings('headlessgl'); +}); + +test('boolean expression false cpu', () => { + functionsAsStrings('cpu'); +});