Skip to main content

just_engine/runner/ds/
execution_context.rs

1use crate::runner::ds::lex_env::JsLexEnvironmentType;
2use crate::runner::ds::object::JsObjectType;
3use crate::runner::ds::realm::JsCodeRealmType;
4
5pub struct ExecutionContext {
6    pub function: Option<JsObjectType>,
7    pub realm: JsCodeRealmType,
8    pub lex_env: JsLexEnvironmentType,
9    pub var_env: JsLexEnvironmentType,
10}
11
12pub struct ExecutionContextStack {
13    stack: Vec<ExecutionContext>,
14}
15impl ExecutionContextStack {
16    pub fn new() -> Self {
17        ExecutionContextStack { stack: Vec::new() }
18    }
19
20    pub fn get_running_execution_ctx(&self) -> Option<&ExecutionContext> {
21        self.stack.get(self.stack.len() - 1)
22    }
23
24    pub fn get_running_execution_ctx_mut(&mut self) -> Option<&mut ExecutionContext> {
25        let stack = &mut self.stack;
26        let stack_len = stack.len();
27        stack.get_mut(stack_len - 1)
28    }
29
30    pub fn pop_running_execution_ctx(&mut self) -> Option<ExecutionContext> {
31        self.stack.pop()
32    }
33
34    pub fn push_execution_ctx(&mut self, ctx: ExecutionContext) {
35        self.stack.push(ctx)
36    }
37}