Skip to content

Commit 39e42fe

Browse files
committed
SSO function call arguments
1 parent be617d6 commit 39e42fe

File tree

35 files changed

+261
-146
lines changed

35 files changed

+261
-146
lines changed

crates/dash_node_impl/src/events.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use dash_rt::typemap::Key;
99
use dash_vm::frame::This;
1010
use dash_vm::gc::ObjectId;
1111
use dash_vm::localscope::LocalScope;
12-
use dash_vm::value::function::native::{register_native_fn, CallContext};
12+
use dash_vm::value::function::args::CallArgs;
13+
use dash_vm::value::function::native::{CallContext, register_native_fn};
1314
use dash_vm::value::function::{Function, FunctionKind};
1415
use dash_vm::value::object::{NamedObject, Object, PropertyValue};
1516
use dash_vm::value::ops::conversions::ValueConversion;
@@ -65,13 +66,10 @@ pub fn init_module(sc: &mut LocalScope<'_>) -> Result<Value, Value> {
6566
sc.register(event_emitter_ctor)
6667
};
6768

68-
State::from_vm_mut(sc).store.insert(
69-
EventsKey,
70-
EventsState {
71-
event_emitter_constructor: event_emitter_ctor,
72-
event_emitter_prototype,
73-
},
74-
);
69+
State::from_vm_mut(sc).store.insert(EventsKey, EventsState {
70+
event_emitter_constructor: event_emitter_ctor,
71+
event_emitter_prototype,
72+
});
7573

7674
event_emitter_ctor.set_property(
7775
sc,
@@ -159,7 +157,9 @@ fn emit(cx: CallContext) -> Result<Value, Value> {
159157
let mut did_emit = false;
160158
if let Some(handlers) = this.handlers.borrow().get(&name.sym()) {
161159
for handler in handlers {
162-
handler.apply(sc, This::Bound(cx.this), args.to_owned()).root_err(sc)?;
160+
handler
161+
.apply(sc, This::Bound(cx.this), CallArgs::from(args))
162+
.root_err(sc)?;
163163
did_emit = true;
164164
}
165165
}

crates/dash_node_impl/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use dash_vm::frame::This;
1717
use dash_vm::gc::ObjectId;
1818
use dash_vm::localscope::LocalScope;
1919
use dash_vm::value::array::Array;
20+
use dash_vm::value::function::args::CallArgs;
2021
use dash_vm::value::object::{NamedObject, Object, PropertyValue};
2122
use dash_vm::value::{Root, Unpack, Unrooted, Value, ValueKind};
2223
use dash_vm::{Vm, delegate, extract, throw};
@@ -230,8 +231,12 @@ fn execute_node_module(
230231

231232
let dirname = Value::string(scope.intern(dir_path.to_str().expect("invalid utf-8 path")).into());
232233
let filename = Value::string(scope.intern(file_path.to_str().expect("invalid utf-8 path")).into());
233-
fun.apply(scope, This::Default, vec![exports, module, require, dirname, filename])
234-
.map_err(|err| (EvalError::Exception(err), code))?;
234+
fun.apply(
235+
scope,
236+
This::Default,
237+
[exports, module, require, dirname, filename].into(),
238+
)
239+
.map_err(|err| (EvalError::Exception(err), code))?;
235240

236241
Ok(module)
237242
}
@@ -278,7 +283,7 @@ impl Object for RequireFunction {
278283
scope: &mut LocalScope,
279284
_callee: dash_vm::gc::ObjectId,
280285
_this: This,
281-
args: Vec<Value>,
286+
args: CallArgs,
282287
) -> Result<Unrooted, Unrooted> {
283288
let Some(ValueKind::String(raw_arg)) = args.first().unpack() else {
284289
throw!(scope, Error, "require() expects a string argument");

crates/dash_node_impl/src/util.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use dash_middle::interner::sym;
22
use dash_vm::frame::This;
33
use dash_vm::localscope::LocalScope;
44
use dash_vm::throw;
5-
use dash_vm::value::function::native::{register_native_fn, CallContext};
5+
use dash_vm::value::function::args::CallArgs;
6+
use dash_vm::value::function::native::{CallContext, register_native_fn};
67
use dash_vm::value::object::{NamedObject, Object, PropertyDataDescriptor, PropertyValue, PropertyValueKind};
78
use dash_vm::value::{Root, Typeof, Value, ValueContext};
89

@@ -39,17 +40,13 @@ fn inherits(cx: CallContext) -> Result<Value, Value> {
3940
}
4041

4142
let super_inst = super_ctor
42-
.construct(cx.scope, This::Default, Vec::new())
43+
.construct(cx.scope, This::Default, CallArgs::empty())
4344
.root(cx.scope)?;
4445

45-
super_inst.set_property(
46-
cx.scope,
47-
sym::constructor.into(),
48-
PropertyValue {
49-
kind: PropertyValueKind::Static(ctor),
50-
descriptor: PropertyDataDescriptor::WRITABLE | PropertyDataDescriptor::CONFIGURABLE,
51-
},
52-
)?;
46+
super_inst.set_property(cx.scope, sym::constructor.into(), PropertyValue {
47+
kind: PropertyValueKind::Static(ctor),
48+
descriptor: PropertyDataDescriptor::WRITABLE | PropertyDataDescriptor::CONFIGURABLE,
49+
})?;
5350

5451
ctor.set_property(
5552
cx.scope,

crates/dash_rt/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ where
5050
Ok(ok) => (ok, PromiseAction::Resolve),
5151
Err(err) => (err, PromiseAction::Reject),
5252
};
53-
scope.drive_promise(action, promise, vec![arg]);
53+
scope.drive_promise(action, promise, [arg].into());
5454
scope.process_async_tasks();
5555
})));
5656
});

crates/dash_rt_fetch/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn fetch(cx: CallContext) -> Result<Value, Value> {
9292
}
9393
};
9494

95-
sc.drive_promise(action, promise, vec![req]);
95+
sc.drive_promise(action, promise, [req].into());
9696
sc.process_async_tasks();
9797
})));
9898
});
@@ -139,7 +139,7 @@ fn http_response_text(cx: CallContext) -> Result<Value, Value> {
139139
}
140140
};
141141

142-
sc.drive_promise(action, promise, vec![value]);
142+
sc.drive_promise(action, promise, [value].into());
143143
sc.process_async_tasks();
144144
})));
145145
});

crates/dash_rt_http/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub fn listen(cx: CallContext) -> Result<Value, Value> {
100100

101101
let ctx = Value::object(scope.register(ctx));
102102

103-
if let Err(err) = cb.apply(&mut scope, This::Default, vec![ctx]).root_err(&mut scope) {
103+
if let Err(err) = cb.apply(&mut scope, This::Default, [ctx].into()).root_err(&mut scope) {
104104
match err.to_js_string(&mut scope) {
105105
Ok(err) => eprintln!("Unhandled exception in HTTP handler! {}", err.res(&scope)),
106106
Err(..) => eprintln!("Unhandled exception in exception toString method in HTTP handler!"),

crates/dash_rt_net/src/listener/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use dash_vm::gc::trace::{Trace, TraceCtxt};
1010
use dash_vm::js_std::receiver_t;
1111
use dash_vm::localscope::LocalScope;
1212
use dash_vm::value::arraybuffer::ArrayBuffer;
13+
use dash_vm::value::function::args::CallArgs;
1314
use dash_vm::value::function::native::CallContext;
1415
use dash_vm::value::function::{Function, FunctionKind};
1516
use dash_vm::value::object::{NamedObject, Object, PropertyValue};
@@ -70,7 +71,7 @@ impl Object for TcpListenerConstructor {
7071
scope: &mut dash_vm::localscope::LocalScope,
7172
_callee: dash_vm::gc::ObjectId,
7273
_this: This,
73-
_args: Vec<dash_vm::value::Value>,
74+
_args: CallArgs,
7475
) -> Result<dash_vm::value::Unrooted, dash_vm::value::Unrooted> {
7576
throw!(scope, Error, "TcpListener should be called as a constructor")
7677
}
@@ -80,7 +81,7 @@ impl Object for TcpListenerConstructor {
8081
scope: &mut dash_vm::localscope::LocalScope,
8182
_callee: dash_vm::gc::ObjectId,
8283
_this: This,
83-
args: Vec<Value>,
84+
args: CallArgs,
8485
new_target: ObjectId,
8586
) -> Result<Unrooted, Unrooted> {
8687
let Some(value) = args.first() else {
@@ -129,7 +130,7 @@ impl Object for TcpListenerConstructor {
129130
let stream_handle = TcpStreamHandle::new(&mut scope, writer_tx, reader_tx).unwrap();
130131
let stream_handle = scope.register(stream_handle);
131132

132-
scope.drive_promise(PromiseAction::Resolve, promise, vec![Value::object(stream_handle)]);
133+
scope.drive_promise(PromiseAction::Resolve, promise, [Value::object(stream_handle)].into());
133134
scope.process_async_tasks();
134135
})));
135136
}

crates/dash_rt_timers/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use dash_vm::frame::This;
1010
use dash_vm::gc::persistent::Persistent;
1111
use dash_vm::localscope::LocalScope;
1212
use dash_vm::throw;
13-
use dash_vm::value::function::native::{register_native_fn, CallContext};
13+
use dash_vm::value::function::args::CallArgs;
14+
use dash_vm::value::function::native::{CallContext, register_native_fn};
1415
use dash_vm::value::object::{NamedObject, Object, PropertyValue};
1516
use dash_vm::value::ops::conversions::ValueConversion;
1617
use dash_vm::value::string::JsString;
@@ -82,7 +83,7 @@ fn set_timeout(cx: CallContext) -> Result<Value, Value> {
8283
let mut sc = rt.vm_mut().scope();
8384
let callback = callback.get();
8485

85-
if let Err(err) = callback.apply(&mut sc, This::Default, Vec::new()) {
86+
if let Err(err) = callback.apply(&mut sc, This::Default, CallArgs::empty()) {
8687
eprintln!("Unhandled error in timer callback: {err:?}");
8788
}
8889

@@ -109,7 +110,7 @@ fn set_immediate(cx: CallContext) -> Result<Value, Value> {
109110
let callback = callback.get();
110111
let mut sc = rt.vm_mut().scope();
111112

112-
if let Err(err) = callback.apply(&mut sc, This::Default, Vec::new()) {
113+
if let Err(err) = callback.apply(&mut sc, This::Default, CallArgs::empty()) {
113114
eprintln!("Unhandled error in timer callback: {err:?}");
114115
}
115116
})));

crates/dash_vm/src/dispatch.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ mod handlers {
570570
use crate::util::unlikely;
571571
use crate::value::array::table::ArrayTable;
572572
use crate::value::array::{Array, ArrayIterator};
573+
use crate::value::function::args::CallArgs;
573574
use crate::value::function::r#async::AsyncFunction;
574575
use crate::value::function::closure::Closure;
575576
use crate::value::function::generator::GeneratorFunction;
@@ -1129,7 +1130,7 @@ mod handlers {
11291130
call_ip: u16,
11301131
) -> Result<Option<HandleResult>, Unrooted> {
11311132
let args = {
1132-
let mut args = Vec::with_capacity(argc);
1133+
let mut args = SmallVec::with_capacity(argc);
11331134

11341135
let len = cx.fetch_and_inc_ip();
11351136
let spread_indices: SmallVec<[_; 4]> = (0..len).map(|_| cx.fetch_and_inc_ip()).collect();
@@ -1167,12 +1168,12 @@ mod handlers {
11671168
cx.scope.add_many(&args);
11681169

11691170
let ret = match function_call_kind {
1170-
FunctionCallKind::Constructor => callee.construct(&mut cx.scope, this, args)?,
1171+
FunctionCallKind::Constructor => callee.construct(&mut cx.scope, this, args.into())?,
11711172
FunctionCallKind::Super => {
11721173
let new_target = cx.active_frame().new_target().unwrap();
1173-
callee.construct_with_target(&mut cx.scope, this, args, new_target)?
1174+
callee.construct_with_target(&mut cx.scope, this, args.into(), new_target)?
11741175
}
1175-
FunctionCallKind::Function => callee.apply_with_debug(&mut cx.scope, this, args, call_ip)?,
1176+
FunctionCallKind::Function => callee.apply_with_debug(&mut cx.scope, this, args.into(), call_ip)?,
11761177
};
11771178

11781179
// SAFETY: no need to root, we're directly pushing into the value stack which itself is a root
@@ -2034,7 +2035,7 @@ mod handlers {
20342035
let iterable = value
20352036
.get_property(&mut cx, PropertyKey::Symbol(symbol_iterator))?
20362037
.root(&mut cx.scope);
2037-
let iterator = iterable.apply(&mut cx, This::Bound(value), Vec::new())?;
2038+
let iterator = iterable.apply(&mut cx, This::Bound(value), CallArgs::empty())?;
20382039
cx.push_stack(iterator);
20392040
Ok(None)
20402041
}
@@ -2258,7 +2259,7 @@ mod handlers {
22582259
macro_rules! fn_call {
22592260
($fun:ident, $k:expr, $v:expr) => {{
22602261
let argc = cx.fetch_and_inc_ip();
2261-
let args = cx.pop_stack_many(argc.into()).collect::<Vec<_>>();
2262+
let args = cx.pop_stack_many(argc.into()).collect::<CallArgs>();
22622263
let fun = cx.statics.$fun.clone();
22632264

22642265
if unlikely(!cx.builtins_purity()) {

crates/dash_vm/src/gc/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use trace::TraceCtxt;
1313
use crate::Vm;
1414
use crate::frame::This;
1515
use crate::localscope::LocalScope;
16+
use crate::value::function::args::CallArgs;
1617
use crate::value::object::{PropertyKey, PropertyValue};
1718
use crate::value::primitive::InternalSlots;
1819
use crate::value::{Typeof, Unrooted, Value};
@@ -40,9 +41,9 @@ pub struct ObjectVTable {
4041
pub(crate) js_set_prototype: unsafe fn(*const (), &mut LocalScope<'_>, Value) -> Result<(), Value>,
4142
pub(crate) js_get_prototype: unsafe fn(*const (), &mut LocalScope<'_>) -> Result<Value, Value>,
4243
pub(crate) js_apply:
43-
unsafe fn(*const (), &mut LocalScope<'_>, ObjectId, This, Vec<Value>) -> Result<Unrooted, Unrooted>,
44+
unsafe fn(*const (), &mut LocalScope<'_>, ObjectId, This, CallArgs) -> Result<Unrooted, Unrooted>,
4445
pub(crate) js_construct:
45-
unsafe fn(*const (), &mut LocalScope<'_>, ObjectId, This, Vec<Value>, ObjectId) -> Result<Unrooted, Unrooted>,
46+
unsafe fn(*const (), &mut LocalScope<'_>, ObjectId, This, CallArgs, ObjectId) -> Result<Unrooted, Unrooted>,
4647
pub(crate) js_internal_slots: unsafe fn(*const (), &Vm) -> Option<*const dyn InternalSlots>,
4748
pub(crate) js_extract_type_raw: unsafe fn(*const (), &Vm, TypeId) -> Option<NonNull<()>>,
4849
pub(crate) js_own_keys: unsafe fn(*const (), sc: &mut LocalScope<'_>) -> Result<Vec<Value>, Value>,

0 commit comments

Comments
 (0)