Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix event emitter default export #136

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use rquickjs::{
class::{JsClass, OwnedBorrow, Trace, Tracer},
module::{Declarations, Exports, ModuleDef},
prelude::{Func, Rest, This},
CatchResultExt, Class, Ctx, Function, Result, String as JsString, Symbol, Value,
CatchResultExt, Class, Ctx, Function, Object, Result, String as JsString, Symbol, Value,
};

use tracing::trace;

use crate::{module::export_default, utils::result::ResultExt, vm::ErrorExtensions};
use crate::{utils::result::ResultExt, vm::ErrorExtensions};

#[derive(Clone, Debug)]
pub enum EventKey<'js> {
Expand Down Expand Up @@ -104,7 +104,7 @@ where
Ok(())
}

fn add_event_emitter_prototype(ctx: &Ctx<'js>) -> Result<()> {
fn add_event_emitter_prototype(ctx: &Ctx<'js>) -> Result<Object<'js>> {
let proto = Class::<Self>::prototype(ctx.clone())
.or_throw_msg(ctx, "Prototype for EventEmitter not found")?;

Expand Down Expand Up @@ -132,7 +132,7 @@ where

proto.set("removeListener", off)?;

Ok(())
Ok(proto)
}

fn trace_event_emitter<'a>(&self, tracer: Tracer<'a, 'js>) {
Expand Down Expand Up @@ -409,10 +409,11 @@ impl ModuleDef for EventsModule {
}

fn evaluate<'js>(ctx: &Ctx<'js>, exports: &mut Exports<'js>) -> Result<()> {
export_default(ctx, exports, |default| {
Class::<EventEmitter>::define(default)?;
Ok(())
})?;
let ctor = Class::<EventEmitter>::create_constructor(ctx)?
.expect("Can't create EventEmitter constructor");
ctor.set(stringify!(EventEmitter), ctor.clone())?;
exports.export(stringify!(EventEmitter), ctor.clone())?;
exports.export("default", ctor)?;

EventEmitter::add_event_emitter_prototype(ctx)?;

Expand Down