Fix imports in eval.

This commit is contained in:
Stephen Chung 2022-10-14 11:57:36 +08:00
parent e2699aa058
commit 31d045279f
2 changed files with 9 additions and 6 deletions

View File

@ -4,6 +4,12 @@ Rhai Release Notes
Version 1.11.0 Version 1.11.0
============== ==============
Bug fixes
---------
* `Engine::parse_json` now returns an error on unquoted keys to be consistent with JSON specifications.
* `import` statements inside `eval` no longer cause errors in subsequent code.
New features New features
------------ ------------
@ -12,11 +18,6 @@ New features
* It is now possible to specify a fixed _seed_ for use with the `ahash` hasher, via an environment variable, in order to force stable (i.e. deterministic) hashes for function signatures. This is necessary when using Rhai across shared-library boundaries. * It is now possible to specify a fixed _seed_ for use with the `ahash` hasher, via an environment variable, in order to force stable (i.e. deterministic) hashes for function signatures. This is necessary when using Rhai across shared-library boundaries.
* A build script is now used to extract the environment variable (`RHAI_AHASH_SEED`) and splice it into the source code before compilation. * A build script is now used to extract the environment variable (`RHAI_AHASH_SEED`) and splice it into the source code before compilation.
Bug fixes
---------
* `Engine::parse_json` now returns an error on unquoted keys to be consistent with JSON specifications.
Enhancements Enhancements
------------ ------------

View File

@ -1137,6 +1137,7 @@ impl Engine {
KEYWORD_EVAL if total_args == 1 => { KEYWORD_EVAL if total_args == 1 => {
// eval - only in function call style // eval - only in function call style
let orig_scope_len = scope.len(); let orig_scope_len = scope.len();
let orig_imports_len = global.num_imports();
let arg = first_arg.unwrap(); let arg = first_arg.unwrap();
let (arg_value, pos) = let (arg_value, pos) =
self.get_arg_value(scope, global, caches, lib, this_ptr, arg, level)?; self.get_arg_value(scope, global, caches, lib, this_ptr, arg, level)?;
@ -1155,7 +1156,8 @@ impl Engine {
// IMPORTANT! If the eval defines new variables in the current scope, // IMPORTANT! If the eval defines new variables in the current scope,
// all variable offsets from this point on will be mis-aligned. // all variable offsets from this point on will be mis-aligned.
if scope.len() != orig_scope_len { // The same is true for imports.
if scope.len() != orig_scope_len || global.num_imports() != orig_imports_len {
global.always_search_scope = true; global.always_search_scope = true;
} }