Commit d5b2e7d7 authored by twanvl's avatar twanvl

correct scope handling for closures, this was broken after the change to not...

correct scope handling for closures, this was broken after the change to not make calls open a scope.
parent f3a78007
...@@ -144,7 +144,8 @@ ScriptValueP Context::eval(const Script& script, bool useScope) { ...@@ -144,7 +144,8 @@ ScriptValueP Context::eval(const Script& script, bool useScope) {
: (Variable)-1; : (Variable)-1;
Profiler prof(timer, function); Profiler prof(timer, function);
#endif #endif
// get function and call // get function and call.
// there is no need to open a new scope for this function, since we already did so for the arguments
stack.back() = stack.back()->eval(*this, false); stack.back() = stack.back()->eval(*this, false);
// finish profiling // finish profiling
#if USE_SCRIPT_PROFILING #if USE_SCRIPT_PROFILING
...@@ -387,7 +388,7 @@ class ScriptCompose : public ScriptValue { ...@@ -387,7 +388,7 @@ class ScriptCompose : public ScriptValue {
// execute b // execute b
Variable fun = ctx.lookupVariableValue(b); Variable fun = ctx.lookupVariableValue(b);
Profiler prof(timer,fun); Profiler prof(timer,fun);
return b->eval(ctx); return b->eval(ctx, openScope);
} }
#else #else
// Always open a scope for a; variables it makes need to be // Always open a scope for a; variables it makes need to be
......
...@@ -527,7 +527,8 @@ ScriptValueP ScriptClosure::dependencies(Context& ctx, const Dependency& dep) co ...@@ -527,7 +527,8 @@ ScriptValueP ScriptClosure::dependencies(Context& ctx, const Dependency& dep) co
} }
void ScriptClosure::applyBindings(Context& ctx) const { void ScriptClosure::applyBindings(Context& ctx) const {
FOR_EACH_CONST(b, bindings) { FOR_EACH_CONST(b, bindings) {
if (ctx.getVariableScope(b.first) != 1) { if (ctx.getVariableScope(b.first) != 0) {
// variables passed as arguments (i.e. in scope 0) override these default bindings
ctx.setVariable(b.first, b.second); ctx.setVariable(b.first, b.second);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment