diff --git a/runtime/scripts/jme-variables.js b/runtime/scripts/jme-variables.js index 30662a3a6..0991016d5 100644 --- a/runtime/scripts/jme-variables.js +++ b/runtime/scripts/jme-variables.js @@ -167,15 +167,22 @@ jme.variables = /** @lends Numbas.jme.variables */ { */ makeFunctions: function(tmpFunctions,scope,withEnv) { + var tmpscope = new jme.Scope(scope); + scope = new jme.Scope(scope); - var functions = scope.functions; - var tmpFunctions2 = []; - for(var i=0;i tags which have an event listener for when the content loads, so they must be considered interactive. + element.setAttribute('data-interactive', element.tagName.toLowerCase() == 'object'); + return new THTML(element); } }); @@ -20089,15 +20092,22 @@ jme.variables = /** @lends Numbas.jme.variables */ { */ makeFunctions: function(tmpFunctions,scope,withEnv) { + var tmpscope = new jme.Scope(scope); + scope = new jme.Scope(scope); - var functions = scope.functions; - var tmpFunctions2 = []; - for(var i=0;i tags which have an event listener for when the content loads, so they must be considered interactive. + element.setAttribute('data-interactive', element.tagName.toLowerCase() == 'object'); + return new THTML(element); } }); @@ -19425,15 +19428,22 @@ jme.variables = /** @lends Numbas.jme.variables */ { */ makeFunctions: function(tmpFunctions,scope,withEnv) { + var tmpscope = new jme.Scope(scope); + scope = new jme.Scope(scope); - var functions = scope.functions; - var tmpFunctions2 = []; - for(var i=0;i { } ); + QUnit.module('Variables'); + question_test( + 'Custom functions know about other custom functions when finding free variables', + { + functions: { + "f1": { + parameters: [], + type: 'number', + language: 'jme', + definition: 'f2(3)+y', + }, + "f2": { + parameters: [ + ['x', 'number'] + ], + type: 'number', + language: 'jme', + definition: '1+x+z' + } + } + }, + async function(assert,q) { + const f1_vars = Numbas.jme.findvars(Numbas.jme.compile('f1()'), {}, q.getScope()); + assert.deepEqual(f1_vars, ['y','z'], 'f1() has free variables y, from the definition of f1, and z, from the definition of f2. f2 is not a free variable.'); + } + ); + /** * Capture signals and events from Numbas.schedule.EventBox/SignalBox objects. * If `owner` is not given, then the prototype trigger method is replaced, catching signals/events on all objects.