Skip to main content

Interp

Struct Interp 

Source
pub struct Interp<'a> {
    pub heap: &'a Heap,
    pub realm: Realm,
    pub output: String,
    pub max_frames: usize,
    pub modules: BTreeMap<String, Gc<ModuleRecord>>,
    pub module_loader: Option<Box<dyn ModuleLoader>>,
    pub main_module_name: Option<String>,
    pub module_stack: Vec<String>,
    /* private fields */
}
Expand description

The interpreter: a realm plus a frame stack.

Fields§

§heap: &'a Heap

The heap everything is allocated on.

§realm: Realm

The realm.

§output: String

Text written by print and friends, in order.

Buffered rather than streamed so a test can inspect it; the CLI flushes it once at the end, which is also when upstream’s line buffering becomes visible for the cases compared here.

§max_frames: usize

The most frames that may be live at once.

§modules: BTreeMap<String, Gc<ModuleRecord>>

The module registry, keyed by canonical name.

§module_loader: Option<Box<dyn ModuleLoader>>

How the host turns a specifier into bytes.

§main_module_name: Option<String>

The module the host was asked to run, for import.meta.main.

§module_stack: Vec<String>

Module bodies currently running, innermost last.

A dynamic import() resolves its specifier relative to the module that ran it, and this is the only place that knows which module that is.

Implementations§

Source§

impl<'a> Interp<'a>

Source

pub fn new(heap: &'a Heap) -> Interp<'a>

Build an interpreter over heap, with a fresh realm.

Source

pub fn bigint(&self, value: BigInt) -> Value

A new string value. A BigInt value from a computed big integer.

Source

pub fn string_wtf8(&self, text: Wtf8) -> Value

A string value from bytes that are already WTF-8, which is how a string with an unpaired surrogate reaches a Value.

Source

pub fn string(&self, text: impl Into<String>) -> Value

A new string value, from text that is valid UTF-8.

Source

pub fn new_object(&self, proto: Option<Gc<JsObject>>) -> Gc<JsObject>

A new ordinary object with the given prototype.

Source

pub fn new_iterator_prototype( &mut self, tag: &str, next: NativeFn, ) -> Gc<JsObject>

A prototype for a built-in iterator, inheriting from Iterator.prototype.

Every built-in iterator has one — %ArrayIteratorPrototype%, %StringIteratorPrototype% and so on — and the whole point of the chain is that such an iterator is an Iterator: [1,2].values().map(f) resolves map by walking up to Iterator.prototype. These used to be plain objects hanging off Object.prototype, so .map was undefined and Object.prototype.toString said [object Object] instead of [object Array Iterator].

The prototype carries next, [Symbol.iterator] answering this, and the @@toStringTag that names it. next is passed in because each iterator kind has its own.

Source

pub fn object_own_property_keys( &mut self, object: &Gc<JsObject>, ) -> JsResult<Vec<PropertyKey>>

[[OwnPropertyKeys]], with the ownKeys trap when there is one.

A trap’s list is used as returned: unlike an ordinary object, whose integer keys the engine sorts, a proxy is specified to hand back exactly what the handler produced. That is why the two branches are not merged.

Source

pub fn promise_state(&self, object: &Gc<JsObject>) -> Option<PromiseRef>

The state behind a promise object, or None when object is not one.

Source

pub fn new_promise(&mut self) -> Gc<JsObject>

A new pending promise.

Source

pub fn fulfill_promise(&mut self, promise: &Gc<JsObject>, value: Value)

Fulfil promise, unless it has already settled.

Settling is one-shot, and a script can see that: resolve called twice, or called after reject, changes nothing.

Source

pub fn reject_promise(&mut self, promise: &Gc<JsObject>, reason: Value)

Reject promise, unless it has already settled.

Source

pub fn new_promise_capability(&mut self) -> (Gc<JsObject>, Value, Value)

NewPromiseCapability as the executor receives it: the promise plus its resolve/reject pair.

The pair are callable objects rather than Rust closures, because the script gets them and may stash them for later.

Source

pub fn promise_resolve_value(&mut self, value: Value) -> JsResult<Value>

PromiseResolve(value): the value itself when it is already a promise, otherwise a new promise resolved with it.

Source

pub fn resolve_promise_with( &mut self, promise: &Gc<JsObject>, value: Value, ) -> JsResult<()>

ResolvePromise: fulfil, unless the value is a thenable — then follow it.

Source

pub fn perform_then( &mut self, promise: &Gc<JsObject>, on_fulfilled: Option<Value>, on_rejected: Option<Value>, ) -> JsResult<Value>

Promise.prototype.then: register a reaction and answer the derived promise.

Source

pub fn take_unhandled_rejections(&mut self) -> Vec<String>

The rejections nobody listened to, formatted the way the reference reports them.

Each line is Possibly unhandled promise rejection: <value> followed by the stack when there is one. The adjective is the reference’s: a rejection is only possibly unhandled at the point the queue drains, because a then may still be attached before the host acts on it.

Source

pub fn drain_jobs(&mut self) -> JsResult<()>

Run the microtask queue to exhaustion.

Jobs queued while draining run in the same drain, FIFO, which is what makes Promise.resolve().then(f).then(g) call f before g.

Source

pub fn new_async_function( &mut self, function: Value, this: Value, args: Vec<Value>, ) -> JsResult<Value>

Build an async function’s result: a promise whose body runs as a coroutine.

Source

pub fn run_async_body( &mut self, code: Gc<CompiledCode>, env: Gc<ClosureEnv>, ) -> JsResult<Value>

The coroutine an async body runs in.

Generator-shaped and never exposed to the script: what makes await work is the same frame-detach-and-resume the generator protocol uses, so this reuses it rather than growing a second state machine. The difference is only in the ending — a return fulfils the caller’s promise here instead of producing {value, done}. Run code as an async function body, answering the promise it settles.

Used for a module with top-level await: its body is an async function whose caller is the host, so there is no function object to pass through Interp::new_async_function.

Source

pub fn object_get_own_property( &mut self, object: &Gc<JsObject>, key: &PropertyKey, ) -> JsResult<Option<Property>>

[[GetOwnProperty]], with the getOwnPropertyDescriptor trap when there is one.

Source

pub fn object_define_own_property( &mut self, object: &Gc<JsObject>, key: &PropertyKey, property: Property, ) -> JsResult<bool>

[[DefineOwnProperty]], with the defineProperty trap when there is one.

Source

pub fn new_proxy(&self, target: Gc<JsObject>, handler: Value) -> Gc<JsObject>

Build a proxy object over target, with its traps read from handler.

Source

pub fn new_revoker(&self, slots: ProxyRef) -> Gc<JsObject>

The revoke function for a proxy’s slots.

Source

pub fn new_array(&self, elements: Vec<Value>) -> Gc<JsObject>

A new array.

Source

pub fn new_native_ctor( &self, name: impl Into<String>, length: u32, func: NativeFn, ) -> Gc<JsObject>

A new native function object.

The observable name and length are installed as properties here, which is what Function.prototype.name and .length read; nothing else stores them, so f.name = "x" behaves like the writable property it is. A native constructor that builds its own instance after validating its arguments.

new hands it this = undefined rather than a pre-made object, so any argument check runs before new.target.prototype is read.

Source

pub fn new_native_constructor( &self, name: impl Into<String>, length: u32, func: NativeFn, ) -> Gc<JsObject>

A native constructor that lets new build the instance first.

The ordinary case for a built-in constructor: new Array(3) has no argument validation that must precede reading new.target.prototype, so the object can be created before the implementation runs. Distinct from Interp::new_native, which makes a method and therefore not a constructor at all.

Source

pub fn new_native( &self, name: impl Into<String>, length: u32, func: NativeFn, ) -> Gc<JsObject>

A new native function object.

Source

pub fn new_bound( &self, target: Value, this: Value, args: Vec<Value>, ) -> Gc<JsObject>

A new bound function.

Source

pub fn new_cell(&self, value: Value) -> Gc<Cell>

A new reference cell.

Source

pub fn eval_builtin_source(&mut self, source: &str) -> JsResult<Value>

Evaluate code as a script body and return its completion value. Compile and run source for the engine’s own use, returning its completion value.

This is how a builtin can be written in JavaScript: [crate::builtins::from_async] needs to be a real async function, and the engine already runs those as coroutines, so compiling the algorithm is cheaper than rebuilding a coroutine by hand.

Differences from Self::eval_in_global, both deliberate:

  • It does not drain the microtask queue. Install runs while the realm is still being built, and the source is an IIFE that only constructs a closure, so there is nothing to drain — and draining here would run script-queued jobs in the middle of install.
  • It reports a syntax error as an InternalError throw rather than as the usual SyntaxError with a position: a malformed builtin source is this crate’s bug, and it should not look like the user wrote something wrong.
Source

pub fn run_script(&mut self, code: CompiledFunction) -> JsResult<Value>

Run an already-parsed script and drain the microtasks it queued.

The drain is what lets an async function’s body advance past its first await before the host sees the result: nothing else pumps the job queue.

Source

pub fn eval_in_global(&mut self, source: &str) -> JsResult<Value>

Compile and run source in global scope, returning its completion value.

This is what eval and new Function use. Running it as a script means it sees the global object and nothing else, which is right for eval("1+1") and for a Function body; a direct eval that reads a local variable would need the compiler to hand its variable environment over, which is not implemented.

Source

pub fn run_function_source(&mut self, code: CompiledFunction) -> JsResult<Value>

Run a compiled script whose completion value is a function, returning it.

new Function(...) compiles (function(params) { body }) and this runs it to get the closure out, which keeps the constant-pool plumbing in one place.

Source

pub fn current_strict(&self) -> bool

Whether the code currently running is strict.

Read off the frame’s function, which is where the parser’s answer ended up; a native function never runs strict-only checks, and there is no frame at all before the first script.

Source

pub fn get_property( &mut self, object: &Gc<JsObject>, key: &str, ) -> JsResult<Option<Value>>

Read object[key], following the prototype chain.

An inherited accessor runs with the receiver as this, which is why the lookup returns the owner rather than just the value.

Source

pub fn get_property_key( &mut self, object: &Gc<JsObject>, key: &PropertyKey, ) -> JsResult<Option<Value>>

Interp::get_property with a key that may be a symbol.

Source

pub fn get_property_key_for( &mut self, object: &Gc<JsObject>, receiver: Option<&Value>, key: &PropertyKey, ) -> JsResult<Option<Value>>

Interp::get_property_key, with an explicit this for an inherited accessor.

The receiver matters when the property is found on a prototype: a getter has to see the object the read started from. For a primitive that is the primitive itself — Symbol("x").description runs the getter with the symbol as this, not with Symbol.prototype — which is why the receiver cannot be inferred from the owner.

Source

pub fn set_property( &mut self, object: &Gc<JsObject>, key: &str, value: Value, ) -> JsResult<()>

Store object[key] = value, honouring setters and inherited properties.

Source

pub fn set_property_with( &mut self, object: &Gc<JsObject>, key: &str, value: Value, on_failure: DeleteFailure, ) -> JsResult<()>

Store a property, choosing what to do when the object refuses.

A rejected store is a TypeError in strict mode and a silent no-op in sloppy mode, which is the one place assignment differs by mode. Native code (the array methods, JSON) always asks for the throw.

Source

pub fn set_property_with_key( &mut self, object: &Gc<JsObject>, key: &PropertyKey, value: Value, on_failure: DeleteFailure, ) -> JsResult<()>

Interp::set_property_with with a key that may be a symbol.

Source

pub fn delete_property( &mut self, object: &Gc<JsObject>, key: &str, ) -> JsResult<bool>

Delete object[key].

Source

pub fn delete_property_key( &mut self, object: &Gc<JsObject>, key: &PropertyKey, ) -> JsResult<bool>

Interp::delete_property with a key that may be a symbol.

Source

pub fn call_value( &mut self, callee: Value, this: Value, args: Vec<Value>, ) -> JsResult<Value>

Call callee with this and args.

Source

pub fn using_method_for( &mut self, value: &Value, await_form: bool, ) -> JsResult<Value>

The dispose method a using declaration should snapshot, or an error.

await-using prefers Symbol.asyncDispose and falls back to Symbol.dispose, which is what makes a resource that only knows the synchronous protocol usable in both forms.

Source

pub fn merge_dispose_error( &mut self, new_error: Value, error_state: Value, ) -> Value

Combine a disposal failure with whatever was already going wrong.

Source

pub fn new_suppressed_error(&mut self, error: Value, suppressed: Value) -> Value

A SuppressedError instance built straight from its prototype.

Not through the constructor: a script that rewrites SuppressedError.prototype.constructor must not be able to divert the engine’s own error wrapping.

Source

pub fn array_like_to_args(&mut self, value: &Value) -> JsResult<Vec<Value>>

Call callee, or push its frame and let the main loop run it.

This is what keeps deep JavaScript recursion off the Rust stack: a bytecode callee becomes a frame on Interp::frames and the instruction loop simply continues, so function f(){ return f() } costs heap and stops at Interp::max_frames instead of aborting the process. Only a native callee is entered directly, and natives do not re-enter JavaScript in this milestone.

Ok(None) means a frame was pushed: the caller must not push a result, because the returning frame will. The elements of an array-like value, as a call argument list.

apply accepts any array-like, not only a real array: the reference reads length and then each index, so {length: 2, 0: "a", 1: "b"} works too.

Source

pub fn new_generator( &mut self, function: Value, this: Value, args: Vec<Value>, ) -> JsResult<Value>

Turn a call to a generator function into a generator object.

The frame is built exactly as an ordinary call would build it, then detached and stored in the generator before any body instruction runs — which is what makes function* g(){ sideEffect() } inert until next(). The one thing that does run is initial_yield, the first instruction of every suspending body.

Source

pub fn resume_generator( &mut self, generator: &Gc<JsObject>, kind: ResumeKind, value: Value, ) -> JsResult<Value>

Advance a generator object, as %GeneratorPrototype%.next and friends do.

Returns the {value, done} object itself rather than the pair, because a yield* suspension already has one — the inner iterator’s own result — and the protocol says to hand that straight through rather than nest it.

Source

pub fn resume_async_generator( &mut self, generator: &Gc<JsObject>, kind: ResumeKind, value: Value, ) -> JsResult<Value>

next/return/throw on an async generator, which answer a promise.

The body is the same coroutine a sync generator runs; what changes is that an await inside it has to settle before the method can answer, so the step is driven off the job queue rather than returning inline.

Source

pub fn dispose_async_all( &mut self, resources: Vec<(Value, Value)>, ) -> JsResult<Value>

Dispose a list of (resource, disposeMethod) pairs, awaiting each disposer.

Returns the promise AsyncDisposableStack.disposeAsync hands back. The first disposer runs synchronously — the reference starts it before returning, which a test can observe by logging after the call — and the rest follow once their predecessor settles.

Source

pub fn iterator_result(&mut self, value: Value, done: bool) -> JsResult<Value>

The {value, done} object an iterator method answers with.

Source

pub fn construct( &mut self, callee: Value, new_target: Value, args: Vec<Value>, ) -> JsResult<Value>

new callee(args).

A constructor differs from a plain call in three ways: it gets a fresh object as this whose prototype is the constructor’s prototype property, its return value is replaced by that object unless it returns an object itself, and a native constructor is expected to initialise the object it is given rather than build one.

Source

pub fn make_error(&self, name: &str, message: &str) -> Value

A TypeError/ReferenceError/RangeError object, as the value to throw.

The error classes themselves arrive with the builtins milestone; what matters here is that the thrown value stringifies the way a script printing the caught value expects.

Source

pub fn add_stack(&self, object: &Gc<JsObject>)

Give an error object its stack property, from the current frame stack.

Only objects get one — throw 42 has no stack anywhere — and an object that already has a stack keeps it, so an error caught and rethrown, or one whose stack a script set, is not rewritten.

Source

pub fn add_stack_skipping(&self, object: &Gc<JsObject>, skip: usize)

Interp::add_stack, omitting the skip innermost frames.

An Error constructor passes 1: the reference builds those traces with JS_BACKTRACE_FLAG_SKIP_FIRST_LEVEL, so new Error() does not report the constructor itself, while a RangeError raised inside toISOString does report at toISOString (native).

Source

pub fn current_callee(&self) -> Option<Gc<JsObject>>

The function object currently being called, if any.

A native function is a bare fn pointer, so it cannot capture which class it belongs to; it reads that from the callee instead. This is also what a stack trace would use.

Source

pub fn prototype_of(&self, constructor: &Gc<JsObject>) -> Gc<JsObject>

The prototype property of a constructor, falling back to Object.prototype for anything that is not shaped like one.

Source

pub fn type_error(&self, message: impl AsRef<str>) -> Signal

Throw a TypeError carrying message.

Source

pub fn range_error(&self, message: impl AsRef<str>) -> Signal

Throw a RangeError carrying message.

Source

pub fn to_primitive(&mut self, value: Value, hint: Hint) -> JsResult<Value>

ToPrimitive, which is what makes "" + obj produce obj.toString().

The order depends on the hint: the “number” order tries valueOf first and toString second, the “string” order the other way round, and the default hint uses the number order. A result that is still an object is a TypeError, because no built-in valueOf/toString returns one.

Source

pub fn to_js_string(&mut self, value: &Value) -> JsResult<String>

ToString with the object case going through ToPrimitive.

Source

pub fn checked_to_wtf8(&mut self, value: &Value) -> JsResult<Wtf8>

ToString that keeps the string’s code units instead of flattening them.

This is what + needs: String.fromCharCode(0xD800) + "a" must keep the unpaired surrogate, and a lossy String in between would turn it into U+FFFD.

Source

pub fn to_js_number(&mut self, value: &Value) -> JsResult<f64>

ToNumber with the object case going through ToPrimitive.

Source

pub fn read_field(&mut self, object: &Value, key: &str) -> JsResult<Value>

Read object[key], returning undefined when the property is missing.

Unlike Interp::get_property this takes a runtime Value, so it works on a primitive (looking through its prototype) as well as an object — which is what get_field/get_array_el need and what a builtin reading a property off an argument needs too.

Source

pub fn read_field_key( &mut self, object: &Value, key: &PropertyKey, ) -> JsResult<Value>

Interp::read_field with a key that may be a symbol.

A symbol key never reaches the string shortcuts: a string’s length and its indices are string properties, and a symbol named length is a different property that a string primitive cannot have.

Source

pub fn checked_to_string(&mut self, value: &Value) -> JsResult<String>

ToString, as the spec defines it: a symbol is a TypeError.

Value::to_js_string cannot fail, so it answers the descriptive form for a symbol. That is right for String(sym) and for error messages, and wrong for everything the spec routes through ToString — "" + sym, ${sym}, Number.parseInt(sym) — so those callers use this instead.

Source

pub fn property_key(&mut self, value: &Value) -> PropertyKey

ToPropertyKey for a builtin that takes a key argument.

Distinct from Interp::propkey, which is fn-private to the instruction loop; the builtins reach this one.

Source

pub fn array_length_of(&mut self, value: &Value) -> JsResult<u32>

ToUint32 with ArraySetLength’s refusal, for an array’s length.

ToUint32 is ToNumber then the modulo, but an object that yields a fraction or NaN falls through to ToString and is parsed as decimal digits. That is why {toString: () => "2"} is a legal length while {valueOf: () => 2.5} is a RangeError — and why this cannot be a plain ToNumber.

Source

pub fn property_key_checked(&mut self, value: &Value) -> JsResult<PropertyKey>

ToPropertyKey that can fail.

Interp::property_key swallows a throwing ToPrimitive and answers "[object Object]", which is fine for a bytecode operand that has already been coerced but wrong for Reflect.get, where a key whose toString throws has to propagate that error (return-abrupt-from-property-key).

Source

pub fn key_value(&self, key: &PropertyKey) -> Value

A PropertyKey as the Value a script sees — what Reflect.ownKeys and Object.getOwnPropertySymbols put in their result array.

Source

pub fn object_prototype_of( &mut self, object: &Gc<JsObject>, ) -> JsResult<Option<Gc<JsObject>>>

[[GetPrototypeOf]], with the proxy trap when there is one.

Source

pub fn object_set_prototype_of( &mut self, object: &Gc<JsObject>, proto: Option<Gc<JsObject>>, ) -> JsResult<bool>

[[SetPrototypeOf]], with the proxy trap when there is one.

Source

pub fn object_is_extensible(&mut self, object: &Gc<JsObject>) -> JsResult<bool>

[[IsExtensible]], with the proxy trap when there is one.

Source

pub fn object_prevent_extensions( &mut self, object: &Gc<JsObject>, ) -> JsResult<bool>

[[PreventExtensions]], with the proxy trap when there is one.

Source

pub fn has_iterator(&mut self, value: &Value) -> JsResult<bool>

The iterator for for-of: the object and its next method.

An object that already carries a next method is used as it is — that is what arr.values() returns — and only arrays and strings get the built-in sequence iterator. Whether value has a callable Symbol.iterator, i.e. GetMethod succeeds.

Callers that must choose between the iterable and the array-like protocol — the typed-array constructor is the main one — need to ask before committing to one.

Source

pub fn collect_iterable(&mut self, value: &Value) -> JsResult<Vec<Value>>

Collect everything an iterable yields, closing it if the walk is abandoned.

The cap is a guard against a generator that never ends: an unbounded collect would be an out-of-memory abort rather than a catchable error.

Source

pub fn new_ctor_instance( &mut self, default_proto: Gc<JsObject>, ) -> JsResult<Gc<JsObject>>

OrdinaryCreateFromConstructor(new.target, default_proto).

A native constructor calls this once it has validated its arguments, which is the order the spec uses for Promise, the typed arrays and DataView: a bad argument is a TypeError before new.target.prototype is read, so a throwing getter there is never reached. The prototype comes from new.target when it is an object, and from default_proto otherwise.

Source

pub fn current_native(&self) -> Option<Gc<JsObject>>

Whether this call is a construction, i.e. new.target is defined.

A native constructor receives this = undefined (it builds its own instance), so it cannot use “this is not an object” to tell Ctor() from new Ctor() — this can. The native function currently executing, if any.

Source

pub fn is_constructing(&self) -> bool

Whether this call is a construction, i.e. new.target is defined.

Source

pub fn new_target_is_custom(&mut self, callee: &Gc<JsObject>) -> bool

Whether the pending new.target needs its own prototype honoured by the constructor.

True whenever new.target is not the callee itself, or when it has no usable prototype — the cases where reading the property is observable at all.

Source

pub fn internal_slot(&mut self, name: &'static str) -> PropertyKey

The symbol key for one of the engine’s own hidden slots.

Cached on the realm, so every object of a kind shares one key and a slot can be read back by name.

Source

pub fn internal_get( &self, object: &Gc<JsObject>, name: &'static str, ) -> Option<Value>

Read a hidden slot, or None when the object has none of that name.

Source

pub fn internal_set( &mut self, object: &Gc<JsObject>, name: &'static str, value: Value, )

Define a hidden slot.

Source

pub fn iterable_values(&mut self, value: &Value) -> JsResult<Option<Vec<Value>>>

Drain anything with a Symbol.iterator method, or answer None when the value is not iterable.

Shared so that Array.from, the Promise combinators and for…of all agree on what “iterable” means. A Map and a Set have no length, so an array-like-only reader silently produced an empty array for both — Array.from(new Set([1,2])) was [].

Source

pub fn describe_exception(&mut self, value: &Value) -> String

How an uncaught exception is reported.

The reference reports a pending exception through JS_PrintValue, which ends up calling the thrown value’s toString, so throw new TypeError("x") prints TypeError: x. Reading name/message off the object directly got this wrong two ways: name usually lives on the prototype rather than on the instance, and a thrown non-error object was not consulted at all, coming out as [object Object]. Routing through ToString keeps every case on one path and honours a user-defined toString, as the reference does.

A toString that throws must not take the reporter down with it, so that case falls back to the type-level rendering. The reference’s printer also walks into plain objects (throw 1, {a:1} prints { a: 1 }); that formatting is a gap shared with console.log.

Source

pub fn stack_trace(&self) -> String

The current call stack, formatted the way qjs prints error.stack.

One at name (file:line:col) line per active frame, innermost first. The position is the one recorded for the instruction each frame is stopped on, which is why the compiler builds a pc-to-position table per function: without it a trace could only name the function, not the line inside it.

A frame whose code has no positions prints just (file), matching the reference’s output for stripped bytecode.

Source

pub fn declare_var_global(&mut self, name: &str)

Declare a global binding, creating its reference cell. Declare a var or function global, whose home is the global object.

Writable and enumerable but not configurable: globalThis.v reads it, for-in lists it, delete refuses. A name that is already there — a built-in such as print, or a redeclaration — is left alone.

Source

pub fn declare_global(&mut self, name: &str, is_const: bool)

Declare a lexical global binding, which starts in its dead zone.

Only let/const/class need this: a var global is a property of the global object and is created when its initialiser runs.

Source§

impl<'a> Interp<'a>

Source

pub fn module_registry(&self) -> &BTreeMap<String, Gc<ModuleRecord>>

The module registry: one entry per canonical name, so each file is compiled once.

Source

pub fn run_main_module(&mut self, specifier: &str) -> JsResult<Value>

Evaluate specifier as the entry module, the way qjs -m file.js does.

Source

pub fn load_module( &mut self, specifier: &str, attributes: &[(String, String)], referrer: &str, ) -> JsResult<Gc<ModuleRecord>>

Load and compile one module.

Resolve every import of module and validate its exports, depth-first.

Source

pub fn resolve_export( &mut self, module: &Gc<ModuleRecord>, name: &str, ) -> JsResult<Gc<Cell>>

The cell behind name in module, following re-exports.

Source

pub fn module_export_names( &mut self, module: &Gc<ModuleRecord>, ) -> JsResult<Vec<String>>

The names module exports, sorted the way §16.2.1.6 requires.

Source

pub fn module_namespace(&mut self, module: &Gc<ModuleRecord>) -> JsResult<Value>

The namespace object of module, built on first use.

An ordinary object with one read-only getter per export, inserted in sorted order. The getter reads the cell, which is what makes the binding live: export let x followed by x = 1 in the exporting module is visible here without copying.

Source

pub fn evaluate_module_body( &mut self, module: &Gc<ModuleRecord>, ) -> JsResult<()>

Run module’s body, evaluating its dependencies first.

Post-order, once each: a module already evaluated is skipped, which is what §16.2.1.5.2.2’s “evaluated or evaluating” guard amounts to, and what makes a cycle terminate instead of recursing.

Source

pub fn dynamic_import(&mut self, specifier: Value) -> JsResult<Value>

import(specifier): load, link, evaluate — asynchronously.

The work happens in a job, because §13.3.10.1 makes dynamic import settle through the promise machinery: import("x").then(f) must call f after the current script finishes, never inside the import expression.

Source

pub fn run_dynamic_import( &mut self, specifier: &str, referrer: &str, promise: &Gc<JsObject>, )

Evaluate a pending dynamic import and settle its promise.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Interp<'a>

§

impl<'a> !Send for Interp<'a>

§

impl<'a> !Sync for Interp<'a>

§

impl<'a> !UnwindSafe for Interp<'a>

§

impl<'a> Forget for Interp<'a>

§

impl<'a> Freeze for Interp<'a>

§

impl<'a> Move for Interp<'a>

§

impl<'a> Unpin for Interp<'a>

§

impl<'a> UnsafeUnpin for Interp<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.