git.delta.rocks / jrsonnet / refs/commits / 36ab91f4c34c

difftreelog

fix add state wrapping for top level api methods

Лач2020-07-19parent: #beff66c.patch.diff
in: master

1 file changed

modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
376/// Raw methods evaluates passed values, but not performs TLA execution376/// Raw methods evaluates passed values, but not performs TLA execution
377impl EvaluationState {377impl EvaluationState {
378 pub fn evaluate_file_raw(&self, name: &PathBuf) -> Result<Val> {378 pub fn evaluate_file_raw(&self, name: &PathBuf) -> Result<Val> {
379 self.import_file(&std::env::current_dir().expect("cwd"), &name)379 self.run_in_state(|| self.import_file(&std::env::current_dir().expect("cwd"), &name))
380 }380 }
381 pub fn evaluate_file_raw_nocwd(&self, name: &PathBuf) -> Result<Val> {381 pub fn evaluate_file_raw_nocwd(&self, name: &PathBuf) -> Result<Val> {
382 self.import_file(&PathBuf::from("."), &name)382 self.run_in_state(|| self.import_file(&PathBuf::from("."), &name))
383 }383 }
384 /// Parses and evaluates snippet384 /// Parses and evaluates snippet
385 pub fn evaluate_snippet_raw(&self, source: Rc<PathBuf>, code: Rc<str>) -> Result<Val> {385 pub fn evaluate_snippet_raw(&self, source: Rc<PathBuf>, code: Rc<str>) -> Result<Val> {
396 }396 }
397 /// Evaluates parsed expression397 /// Evaluates parsed expression
398 pub fn evaluate_expr_raw(&self, code: LocExpr) -> Result<Val> {398 pub fn evaluate_expr_raw(&self, code: LocExpr) -> Result<Val> {
399 evaluate(self.create_default_context()?, &code)399 self.run_in_state(|| evaluate(self.create_default_context()?, &code))
400 }400 }
401}401}
402402
479 use std::{path::PathBuf, rc::Rc};479 use std::{path::PathBuf, rc::Rc};
480480
481 #[test]481 #[test]
482 #[should_panic]
482 fn eval_state_stacktrace() {483 fn eval_state_stacktrace() {
483 let state = EvaluationState::default();484 let state = EvaluationState::default();
484 state.run_in_state(|| {485 state.run_in_state(|| {