Move encapsulated environment out of ScriptFnDef.

This commit is contained in:
Stephen Chung
2022-12-12 16:06:24 +08:00
parent 397b5eb39d
commit 67a7ab4069
14 changed files with 116 additions and 79 deletions

View File

@@ -4,6 +4,7 @@
use super::call::FnCallArgs;
use crate::ast::ScriptFnDef;
use crate::eval::{Caches, GlobalRuntimeState};
use crate::func::EncapsulatedEnviron;
use crate::{Dynamic, Engine, Position, RhaiResult, Scope, ERR};
use std::mem;
#[cfg(feature = "no_std")]
@@ -28,6 +29,7 @@ impl Engine {
caches: &mut Caches,
scope: &mut Scope,
this_ptr: &mut Dynamic,
_environ: Option<&EncapsulatedEnviron>,
fn_def: &ScriptFnDef,
args: &mut FnCallArgs,
rewind_scope: bool,
@@ -84,12 +86,12 @@ impl Engine {
let orig_fn_resolution_caches_len = caches.fn_resolution_caches_len();
#[cfg(not(feature = "no_module"))]
let orig_constants = if let Some(ref environ) = fn_def.environ {
let crate::ast::EncapsulatedEnviron {
ref lib,
ref imports,
ref constants,
} = **environ;
let orig_constants = if let Some(environ) = _environ {
let EncapsulatedEnviron {
lib,
imports,
constants,
} = environ;
imports
.iter()
@@ -124,8 +126,7 @@ impl Engine {
_ => Err(ERR::ErrorInFunctionCall(
fn_def.name.to_string(),
#[cfg(not(feature = "no_module"))]
fn_def
.environ
_environ
.as_deref()
.and_then(|environ| environ.lib.id())
.unwrap_or_else(|| global.source().unwrap_or(""))