Make inline maps const. Add test for malformed inline map that causes crash
This commit is contained in:
parent
fa2a7045a7
commit
3ab91356e5
@ -396,6 +396,7 @@ namespace detail {
|
||||
m->add(user_type<MapType>(), type);
|
||||
|
||||
typedef typename MapType::mapped_type &(MapType::*elemaccess)(const typename MapType::key_type &);
|
||||
|
||||
m->add(fun(static_cast<elemaccess>(&MapType::operator[])), "[]");
|
||||
|
||||
container_type<MapType>(type, m);
|
||||
|
@ -411,22 +411,18 @@ namespace chaiscript
|
||||
*/
|
||||
Boxed_Value Inline_Map_AST_Node::eval(Dispatch_Engine &ss) {
|
||||
try {
|
||||
Boxed_Value retval = ss.call_function("Map");
|
||||
std::map<std::string, Boxed_Value> retval;
|
||||
for (size_t i = 0; i < this->children[0]->children.size(); ++i) {
|
||||
try {
|
||||
Boxed_Value slot
|
||||
= ss.call_function("[]", retval, this->children[0]->children[i]->children[0]->eval(ss));
|
||||
ss.call_function("=", slot, this->children[0]->children[i]->children[1]->eval(ss));
|
||||
}
|
||||
catch (const dispatch_error &) {
|
||||
throw Eval_Error("Can not find appropriate '=' for map init");
|
||||
retval[boxed_cast<std::string>(this->children[0]->children[i]->children[0]->eval(ss))]
|
||||
= ss.call_function("clone", this->children[0]->children[i]->children[1]->eval(ss));
|
||||
}
|
||||
catch(Eval_Error &ee) {
|
||||
ee.call_stack.push_back(this->children[0]->children[i]);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
return const_var(retval);
|
||||
}
|
||||
catch (const dispatch_error &) {
|
||||
throw Eval_Error("Can not find appropriate 'Map()'");
|
||||
|
2
unittests/malformed_inline_map.chai
Normal file
2
unittests/malformed_inline_map.chai
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
assert_throws("Parse failure", fun() { eval("[\"hello\":5,\"j\",\"k\"]") } );
|
Loading…
x
Reference in New Issue
Block a user