Skip to content

[WIP] feat(ecmascript): Begin SourceTextModuleRecord and module loading implementation #178

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
30 changes: 30 additions & 0 deletions nova_vm/src/ecmascript/builtins/builtin_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
ecmascript::{
execution::{agent::ExceptionType, Agent, ExecutionContext, JsResult, RealmIdentifier},
types::{
AbstractClosure, AbstractClosureBehaviour, AbstractClosureHeapData,
BuiltinFunctionHeapData, Function, InternalMethods, IntoFunction, IntoObject,
IntoValue, Object, OrdinaryObject, OrdinaryObjectInternalSlots, PropertyDescriptor,
PropertyKey, String, Value, BUILTIN_STRING_MEMORY,
Expand Down Expand Up @@ -698,6 +699,35 @@ pub fn create_builtin_function(
})
}

pub fn create_abstract_closure_function(
agent: &mut Agent,
behaviour: Box<dyn AbstractClosureBehaviour>,
args: BuiltinFunctionArgs,
) -> AbstractClosure {
// 1. If realm is not present, set realm to the current Realm Record.
let realm = args.realm.unwrap_or(agent.current_realm_id());

// 9. Set func.[[InitialName]] to null.
// Note: SetFunctionName inlined here: We know name is a string
let initial_name = if let Some(prefix) = args.prefix {
// 12. Else,
// a. Perform SetFunctionName(func, name, prefix).
String::from_string(agent, format!("{} {}", args.name, prefix))
} else {
// 11. If prefix is not present, then
// a. Perform SetFunctionName(func, name).
String::from_str(agent, args.name)
};

agent.heap.create(AbstractClosureHeapData {
object_index: None,
length: args.length as u8,
realm,
initial_name: Some(initial_name),
behaviour,
})
}

pub fn define_builtin_function(
agent: &mut Agent,
_object: Object,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub(crate) mod promise_abstract_operations;
pub(crate) mod promise_constructor;
pub(crate) mod promise_prototype;
Loading