Skip to content

Commit

Permalink
Remove panics on module compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Mar 23, 2023
1 parent e465743 commit ad6095f
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions boa_engine/src/bytecompiler/module.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,64 @@
use super::ByteCompiler;
use crate::{js_string, vm::Opcode};

use super::{ByteCompiler, Literal};
use boa_ast::{ModuleItem, ModuleItemList};

impl ByteCompiler<'_, '_> {
/// Compiles a [`ModuleItemList`].
#[inline]
#[allow(unreachable_code, unused_variables)]
pub fn compile_module_item_list(&mut self, list: &ModuleItemList, configurable_globals: bool) {
// TODO: Remove after implementing modules.
{
let msg = self
.get_or_insert_literal(Literal::String(js_string!("modules are unimplemented")));
self.emit(Opcode::ThrowNewTypeError, &[msg]);
return;
}
for node in list.items() {
self.compile_module_item(node, configurable_globals);
}
}

/// Compiles a [`ModuleItem`].
#[inline]
#[allow(unused_variables, clippy::missing_panics_doc)] // Unimplemented
#[allow(clippy::missing_panics_doc)] // Unimplemented
pub fn compile_module_item(&mut self, item: &ModuleItem, configurable_globals: bool) {
match item {
ModuleItem::ImportDeclaration(import) => todo!("import declaration compilation"),
ModuleItem::ExportDeclaration(export) => todo!("export declaration compilation"),
ModuleItem::ImportDeclaration(_import) => todo!("import declaration compilation"),
ModuleItem::ExportDeclaration(_export) => todo!("export declaration compilation"),
ModuleItem::StatementListItem(stmt) => {
self.compile_stmt_list_item(stmt, false, configurable_globals);
}
}
}

/// Creates the declarations for a module.
#[allow(unreachable_code, unused_variables)]
pub(crate) fn create_module_decls(
&mut self,
stmt_list: &ModuleItemList,
configurable_globals: bool,
) {
// TODO: Remove after implementing modules.
{
return;
}
for node in stmt_list.items() {
self.create_decls_from_module_item(node, configurable_globals);
}
}

/// Creates the declarations from a [`ModuleItem`].
#[inline]
#[allow(unused_variables)] // Unimplemented
pub(crate) fn create_decls_from_module_item(
&mut self,
item: &ModuleItem,
configurable_globals: bool,
) -> bool {
match item {
ModuleItem::ImportDeclaration(import) => todo!("import declaration generation"),
ModuleItem::ExportDeclaration(export) => todo!("export declaration generation"),
ModuleItem::ImportDeclaration(_import) => todo!("import declaration generation"),
ModuleItem::ExportDeclaration(_export) => todo!("export declaration generation"),
ModuleItem::StatementListItem(stmt) => {
self.create_decls_from_stmt_list_item(stmt, configurable_globals)
}
Expand Down

0 comments on commit ad6095f

Please sign in to comment.