From 1c5213758d7688dc713e3c607b185e5b3d8a0724 Mon Sep 17 00:00:00 2001 From: Iban Eguia Moraza Date: Sun, 27 Nov 2022 12:46:03 +0100 Subject: [PATCH] Fixed compilation --- boa_engine/src/context/mod.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/boa_engine/src/context/mod.rs b/boa_engine/src/context/mod.rs index 8d4b8e10b91..ea261585ff8 100644 --- a/boa_engine/src/context/mod.rs +++ b/boa_engine/src/context/mod.rs @@ -146,14 +146,15 @@ impl Context<'_> { ContextBuilder::default() } - /// Evaluates the given code by compiling down to bytecode, then interpreting the bytecode into a value + /// Evaluates the given script by compiling down to bytecode, then interpreting the bytecode + /// into a value. /// /// # Examples /// ``` /// # use boa_engine::Context; /// let mut context = Context::default(); /// - /// let value = context.eval("1 + 3").unwrap(); + /// let value = context.eval_script("1 + 3").unwrap(); /// /// assert!(value.is_number()); /// assert_eq!(value.as_number().unwrap(), 4.0); @@ -166,9 +167,10 @@ impl Context<'_> { where S: AsRef<[u8]>, { - let main_timer = Profiler::global().start_event("Evaluation", "Main"); + let main_timer = Profiler::global().start_event("Script evaluation", "Main"); + + let statement_list = Parser::new(src.as_ref()).parse_script(&mut self.interner)?; - let statement_list = self.parse_script(src)?; let code_block = self.compile_script(&statement_list)?; let result = self.execute(code_block); @@ -229,10 +231,11 @@ impl Context<'_> { let mut parser = Parser::new(src.as_ref()); parser.parse_module(&mut self.interner) } - - /// Compile the AST into a `CodeBlock` ready to be executed by the VM. + + /// Compile the script AST into a `CodeBlock` ready to be executed by the VM. pub fn compile_script(&mut self, statement_list: &StatementList) -> JsResult> { - let _timer = Profiler::global().start_event("Compilation", "Main"); + let _timer = Profiler::global().start_event("Script compilation", "Main"); + let mut compiler = ByteCompiler::new(Sym::MAIN, statement_list.strict(), false, self); compiler.create_script_decls(statement_list, false); compiler.compile_statement_list(statement_list, true, false)?; @@ -242,6 +245,7 @@ impl Context<'_> { /// Compile the module AST into a `CodeBlock` ready to be executed by the VM. pub fn compile_module(&mut self, statement_list: &ModuleItemList) -> JsResult> { let _timer = Profiler::global().start_event("Module compilation", "Main"); + let mut compiler = ByteCompiler::new(Sym::MAIN, true, false, self); compiler.create_module_decls(statement_list, false); compiler.compile_module_item_list(statement_list, false)?;