Merge branch 'main' of github.com:Mathieu-Lala/rhai into fix/lint

This commit is contained in:
Mathieu Lala
2023-02-05 17:18:45 +01:00
23 changed files with 281 additions and 118 deletions

View File

@@ -389,6 +389,11 @@ impl Engine {
)?,
}
#[cfg(feature = "debugging")]
let scope2 = &mut Scope::new();
#[cfg(not(feature = "debugging"))]
let scope2 = ();
match lhs {
// id.??? or id[???]
Expr::Variable(.., var_pos) => {
@@ -399,7 +404,7 @@ impl Engine {
let target = &mut self.search_namespace(global, caches, scope, this_ptr, lhs)?;
self.eval_dot_index_chain_raw(
global, caches, None, lhs, expr, target, rhs, idx_values, new_val,
global, caches, scope2, None, lhs, expr, target, rhs, idx_values, new_val,
)
}
// {expr}.??? = ??? or {expr}[???] = ???
@@ -412,7 +417,8 @@ impl Engine {
let obj_ptr = &mut value.into();
self.eval_dot_index_chain_raw(
global, caches, this_ptr, lhs_expr, expr, obj_ptr, rhs, idx_values, new_val,
global, caches, scope2, this_ptr, lhs_expr, expr, obj_ptr, rhs, idx_values,
new_val,
)
}
}
@@ -523,6 +529,8 @@ impl Engine {
&self,
global: &mut GlobalRuntimeState,
caches: &mut Caches,
#[cfg(feature = "debugging")] scope: &mut Scope,
#[cfg(not(feature = "debugging"))] scope: (),
this_ptr: Option<&mut Dynamic>,
root: &Expr,
parent: &Expr,
@@ -537,9 +545,6 @@ impl Engine {
#[cfg(feature = "debugging")]
let mut this_ptr = this_ptr;
#[cfg(feature = "debugging")]
let scope = &mut Scope::new();
match ChainType::from(parent) {
#[cfg(not(feature = "no_index"))]
ChainType::Indexing => {
@@ -570,8 +575,8 @@ impl Engine {
let obj_ptr = &mut obj;
match self.eval_dot_index_chain_raw(
global, caches, this_ptr, root, rhs, obj_ptr, &x.rhs, idx_values,
new_val,
global, caches, scope, this_ptr, root, rhs, obj_ptr, &x.rhs,
idx_values, new_val,
) {
Ok((result, true)) if is_obj_temp_val => {
(Some(obj.take_or_clone()), (result, true))
@@ -880,8 +885,8 @@ impl Engine {
};
self.eval_dot_index_chain_raw(
global, caches, _this_ptr, root, rhs, val_target, &x.rhs, idx_values,
new_val,
global, caches, scope, _this_ptr, root, rhs, val_target, &x.rhs,
idx_values, new_val,
)
}
// xxx.sub_lhs[expr] | xxx.sub_lhs.expr
@@ -926,8 +931,8 @@ impl Engine {
let val = &mut (&mut val).into();
let (result, may_be_changed) = self.eval_dot_index_chain_raw(
global, caches, _this_ptr, root, rhs, val, &x.rhs, idx_values,
new_val,
global, caches, scope, _this_ptr, root, rhs, val, &x.rhs,
idx_values, new_val,
)?;
// Feed the value back via a setter just in case it has been updated
@@ -994,8 +999,8 @@ impl Engine {
let val = &mut val.into();
self.eval_dot_index_chain_raw(
global, caches, _this_ptr, root, rhs, val, &x.rhs, idx_values,
new_val,
global, caches, scope, _this_ptr, root, rhs, val, &x.rhs,
idx_values, new_val,
)
}
// xxx.module::fn_name(...) - syntax error

View File

@@ -505,14 +505,21 @@ impl Engine {
event: DebuggerEvent,
) -> Result<Option<DebuggerStatus>, Box<crate::EvalAltResult>> {
if let Some(ref x) = self.debugger_interface {
let orig_scope_len = scope.len();
let src = global.source_raw().cloned();
let src = src.as_ref().map(|s| s.as_str());
let context = EvalContext::new(self, global, caches, scope, this_ptr);
let (.., ref on_debugger) = **x;
let command = on_debugger(context, event, node, src, node.position())?;
let command = on_debugger(context, event, node, src, node.position());
match command {
if orig_scope_len != scope.len() {
// The scope is changed, always search from now on
global.always_search_scope = true;
}
match command? {
DebuggerCommand::Continue => {
global.debugger_mut().status = DebuggerStatus::CONTINUE;
Ok(None)

View File

@@ -174,9 +174,18 @@ impl Engine {
// Check the variable resolver, if any
if let Some(ref resolve_var) = self.resolve_var {
let orig_scope_len = scope.len();
let context = EvalContext::new(self, global, caches, scope, this_ptr);
let var_name = expr.get_variable_name(true).expect("`Expr::Variable`");
match resolve_var(var_name, index, context) {
let resolved_var = resolve_var(var_name, index, context);
if orig_scope_len != scope.len() {
// The scope is changed, always search from now on
global.always_search_scope = true;
}
match resolved_var {
Ok(Some(mut result)) => {
result.set_access_mode(AccessMode::ReadOnly);
return Ok(result.into());
@@ -298,7 +307,7 @@ impl Engine {
let source = global.source();
let context = &(self, FUNC_TO_STRING, source, &*global, pos).into();
let display = print_with_func(FUNC_TO_STRING, context, item);
write!(concat, "{}", display).unwrap();
write!(concat, "{display}").unwrap();
}
#[cfg(not(feature = "unchecked"))]

View File

@@ -728,10 +728,17 @@ impl Engine {
nesting_level: global.scope_level,
will_shadow,
};
let orig_scope_len = scope.len();
let context =
EvalContext::new(self, global, caches, scope, this_ptr.as_deref_mut());
let filter_result = filter(true, info, context);
if !filter(true, info, context)? {
if orig_scope_len != scope.len() {
// The scope is changed, always search from now on
global.always_search_scope = true;
}
if !filter_result? {
return Err(ERR::ErrorForbiddenVariable(var_name.to_string(), *pos).into());
}
}