diff --git a/src/lib.rs b/src/lib.rs index 9dbd62af..e436e23e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,7 @@ mod handle_scope; mod isolate; mod local; mod locker; +mod module; mod number; mod object; mod primitives; @@ -42,6 +43,7 @@ pub use isolate::Isolate; pub use isolate::OwnedIsolate; pub use local::Local; pub use locker::Locker; +pub use module::Module; pub use number::{Integer, Number}; pub use object::Object; pub use primitives::*; diff --git a/src/module.rs b/src/module.rs new file mode 100644 index 00000000..b119766f --- /dev/null +++ b/src/module.rs @@ -0,0 +1,83 @@ +use crate::support::int; +use crate::support::Opaque; +use crate::Context; +use crate::Local; +use crate::Value; + +extern "C" {} + +/// The different states a module can be in. +/// +/// This corresponds to the states used in ECMAScript except that "evaluated" +/// is split into kEvaluated and kErrored, indicating success and failure, +/// respectively. +#[derive(Debug, PartialEq)] +#[repr(C)] +pub enum Status { + Uninstantiated, + Instantiating, + Instantiated, + Evaluating, + Evaluated, + Errored, +} + +#[repr(C)] +pub struct Module(Opaque); + +/// A compiled JavaScript module. +impl Module { + /// Returns the module's current status. + pub fn get_status(&self) -> Status { + unimplemented!(); + } + + /// For a module in kErrored status, this returns the corresponding exception. + pub fn get_exception(&self) -> Local { + unimplemented!(); + } + + /// Returns the number of modules requested by this module. + pub fn get_module_requests_length(&self) -> int { + unimplemented!(); + } + + /// Returns the ith module specifier in this module. + /// i must be < self.get_module_requests_length() and >= 0. + pub fn get_module_request(&self, _i: usize) -> Local { + unimplemented!(); + } + + /// Returns the identity hash for this object. + pub fn get_identity_hash(&self) -> int { + unimplemented!(); + } + + /// Instantiates the module and its dependencies. + /// + /// Returns an empty Maybe if an exception occurred during + /// instantiation. (In the case where the callback throws an exception, that + /// exception is propagated.) + #[must_use] + pub fn instantiate_module( + &self, + _context: Local, + _callback: Box, + ) -> Option { + unimplemented!(); + } + + /// Evaluates the module and its dependencies. + /// + /// If status is kInstantiated, run the module's code. On success, set status + /// to kEvaluated and return the completion value; on failure, set status to + /// kErrored and propagate the thrown exception (which is then also available + /// via |GetException|). + #[must_use] + pub fn evaluate(&self, _context: Local) -> Option> { + unimplemented!(); + } +} + +type ResolveCallback = + dyn Fn(Local, Local, Local) -> Option>;