Skip to content

Commit 025dc4e

Browse files
committed
Pass traces instead of full context to bind
1 parent 72e9a04 commit 025dc4e

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

src/bind.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Sass {
1212

13-
void bind(std::string type, std::string name, Parameters_Obj ps, Arguments_Obj as, Env* env, Eval* eval)
13+
void bind(std::string type, std::string name, Parameters_Obj ps, Arguments_Obj as, Env* env, Eval* eval, Backtraces& traces)
1414
{
1515
std::string callee(type + " " + name);
1616

@@ -54,7 +54,7 @@ namespace Sass {
5454
std::stringstream msg;
5555
msg << "wrong number of arguments (" << LA << " for " << LP << ")";
5656
msg << " for `" << name << "'";
57-
return error(msg.str(), as->pstate(), eval->exp.traces);
57+
return error(msg.str(), as->pstate(), traces);
5858
}
5959
Parameter_Obj p = ps->at(ip);
6060

@@ -107,8 +107,8 @@ namespace Sass {
107107
false,
108108
false));
109109
} else {
110-
eval->exp.traces.push_back(Backtrace(key->pstate()));
111-
throw Exception::InvalidVarKwdType(key->pstate(), eval->exp.traces, key->inspect(), a);
110+
traces.push_back(Backtrace(key->pstate()));
111+
throw Exception::InvalidVarKwdType(key->pstate(), traces, key->inspect(), a);
112112
}
113113
}
114114

@@ -222,15 +222,15 @@ namespace Sass {
222222
for (auto key : argmap->keys()) {
223223
String_Constant_Ptr val = Cast<String_Constant>(key);
224224
if (val == NULL) {
225-
eval->exp.traces.push_back(Backtrace(key->pstate()));
226-
throw Exception::InvalidVarKwdType(key->pstate(), eval->exp.traces, key->inspect(), a);
225+
traces.push_back(Backtrace(key->pstate()));
226+
throw Exception::InvalidVarKwdType(key->pstate(), traces, key->inspect(), a);
227227
}
228228
std::string param = "$" + unquote(val->value());
229229

230230
if (!param_map.count(param)) {
231231
std::stringstream msg;
232232
msg << callee << " has no parameter named " << param;
233-
error(msg.str(), a->pstate(), eval->exp.traces);
233+
error(msg.str(), a->pstate(), traces);
234234
}
235235
env->local_frame()[param] = argmap->at(key);
236236
}
@@ -245,7 +245,7 @@ namespace Sass {
245245
std::stringstream msg;
246246
msg << "parameter " << p->name()
247247
<< " provided more than once in call to " << callee;
248-
error(msg.str(), a->pstate(), eval->exp.traces);
248+
error(msg.str(), a->pstate(), traces);
249249
}
250250
// ordinal arg -- bind it to the next param
251251
env->local_frame()[p->name()] = a->value();
@@ -259,22 +259,22 @@ namespace Sass {
259259
} else {
260260
std::stringstream msg;
261261
msg << callee << " has no parameter named " << a->name();
262-
error(msg.str(), a->pstate(), eval->exp.traces);
262+
error(msg.str(), a->pstate(), traces);
263263
}
264264
}
265265
if (param_map[a->name()]) {
266266
if (param_map[a->name()]->is_rest_parameter()) {
267267
std::stringstream msg;
268268
msg << "argument " << a->name() << " of " << callee
269269
<< "cannot be used as named argument";
270-
error(msg.str(), a->pstate(), eval->exp.traces);
270+
error(msg.str(), a->pstate(), traces);
271271
}
272272
}
273273
if (env->has_local(a->name())) {
274274
std::stringstream msg;
275275
msg << "parameter " << p->name()
276276
<< "provided more than once in call to " << callee;
277-
error(msg.str(), a->pstate(), eval->exp.traces);
277+
error(msg.str(), a->pstate(), traces);
278278
}
279279
env->local_frame()[a->name()] = a->value();
280280
}
@@ -299,7 +299,7 @@ namespace Sass {
299299
}
300300
else {
301301
// param is unbound and has no default value -- error
302-
throw Exception::MissingArgument(as->pstate(), eval->exp.traces, name, leftover->name(), type);
302+
throw Exception::MissingArgument(as->pstate(), traces, name, leftover->name(), type);
303303
}
304304
}
305305
}

src/bind.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
#define SASS_BIND_H
33

44
#include <string>
5+
#include "backtrace.hpp"
56
#include "environment.hpp"
67
#include "ast_fwd_decl.hpp"
78

89
namespace Sass {
910

10-
void bind(std::string type, std::string name, Parameters_Obj, Arguments_Obj, Env*, Eval*);
11+
void bind(std::string type, std::string name, Parameters_Obj, Arguments_Obj, Env*, Eval*, Backtraces traces);
1112
}
1213

1314
#endif

src/eval.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ namespace Sass {
10051005
exp.env_stack.push_back(&fn_env);
10061006

10071007
if (func || body) {
1008-
bind(std::string("Function"), c->name(), params, args, &fn_env, this);
1008+
bind(std::string("Function"), c->name(), params, args, &fn_env, this, traces);
10091009
std::string msg(", in function `" + c->name() + "`");
10101010
traces.push_back(Backtrace(c->pstate(), msg));
10111011
ctx.callee_stack.push_back({
@@ -1045,7 +1045,7 @@ namespace Sass {
10451045

10461046
// populates env with default values for params
10471047
std::string ff(c->name());
1048-
bind(std::string("Function"), c->name(), params, args, &fn_env, this);
1048+
bind(std::string("Function"), c->name(), params, args, &fn_env, this, traces);
10491049
std::string msg(", in function `" + c->name() + "`");
10501050
traces.push_back(Backtrace(c->pstate(), msg));
10511051
ctx.callee_stack.push_back({

src/expand.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ namespace Sass {
740740
new_env.local_frame()["@content[m]"] = thunk;
741741
}
742742

743-
bind(std::string("Mixin"), c->name(), params, args, &new_env, &eval);
743+
bind(std::string("Mixin"), c->name(), params, args, &new_env, &eval, traces);
744744

745745
Block_Obj trace_block = SASS_MEMORY_NEW(Block, c->pstate());
746746
Trace_Obj trace = SASS_MEMORY_NEW(Trace, c->pstate(), c->name(), trace_block);

0 commit comments

Comments
 (0)