Skip to content

Commit

Permalink
make &mut LocalScope the last parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Dec 29, 2024
1 parent 76bdcf4 commit b9b3a36
Show file tree
Hide file tree
Showing 50 changed files with 588 additions and 560 deletions.
4 changes: 2 additions & 2 deletions crates/dash_dlloader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use dash_middle::compiler::StaticImportKind;
use dash_rt::module::ModuleLoader;
use dash_vm::localscope::LocalScope;
use dash_vm::throw;
use dash_vm::value::Value;
use dash_vm::value::function::native::CallContext;
use dash_vm::value::function::{Function, FunctionKind};
use dash_vm::value::object::{NamedObject, Object, PropertyValue};
use dash_vm::value::ops::conversions::ValueConversion;
use dash_vm::value::string::JsString;
use dash_vm::value::Value;
use libloading::Library;

type InitFunction = unsafe extern "C" fn(*mut CallContext, *mut Result<Value, Value>);
Expand All @@ -27,7 +27,7 @@ impl ModuleLoader for DllModule {
let load = sc.intern("load");
let load_sync = Function::new(sc, Some(load.into()), FunctionKind::Native(load_sync));
let load_sync = sc.register(load_sync);
object.set_property(sc, load.into(), PropertyValue::static_default(Value::object(load_sync)))?;
object.set_property(load.into(), PropertyValue::static_default(Value::object(load_sync)), sc)?;

Ok(Some(Value::object(sc.register(object))))
}
Expand Down
12 changes: 6 additions & 6 deletions crates/dash_node_impl/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub fn init_module(sc: &mut LocalScope<'_>) -> Result<Value, Value> {
};
let wu32be = register_native_fn(sc, wu32be_sym, |cx| write_byte(cx, Endianness::Big, 4));
let wu32le = register_native_fn(sc, wu32le_sym, |cx| write_byte(cx, Endianness::Little, 4));
buffer_prototype.set_property(sc, wu32be_sym.into(), PropertyValue::static_default(wu32be.into()))?;
buffer_prototype.set_property(sc, wu32le_sym.into(), PropertyValue::static_default(wu32le.into()))?;
buffer_prototype.set_property(wu32be_sym.into(), PropertyValue::static_default(wu32be.into()), sc)?;
buffer_prototype.set_property(wu32le_sym.into(), PropertyValue::static_default(wu32le.into()), sc)?;

let buffer_ctor = Function::new(
sc,
Expand All @@ -52,9 +52,9 @@ pub fn init_module(sc: &mut LocalScope<'_>) -> Result<Value, Value> {

let from_fn = register_native_fn(sc, sym::from, from);
let alloc_fn = register_native_fn(sc, alloc_sym, alloc);
buffer_ctor.set_property(sc, sym::from.into(), PropertyValue::static_default(from_fn.into()))?;
buffer_ctor.set_property(sc, buffer_sym.into(), PropertyValue::static_default(buffer_ctor.into()))?;
buffer_ctor.set_property(sc, alloc_sym.into(), PropertyValue::static_default(alloc_fn.into()))?;
buffer_ctor.set_property(sym::from.into(), PropertyValue::static_default(from_fn.into()), sc)?;
buffer_ctor.set_property(buffer_sym.into(), PropertyValue::static_default(buffer_ctor.into()), sc)?;
buffer_ctor.set_property(alloc_sym.into(), PropertyValue::static_default(alloc_fn.into()), sc)?;

State::from_vm_mut(sc).store.insert(BufferKey, BufferState {
buffer_prototype,
Expand Down Expand Up @@ -150,7 +150,7 @@ fn from(cx: CallContext) -> Result<Value, Value> {
for i in 0..length {
let i = cx.scope.intern_usize(i);
let item = source
.get_property(cx.scope, i.into())
.get_property(i.into(), cx.scope)
.root(cx.scope)?
.to_number(cx.scope)? as u8;
buf.push(Cell::new(item));
Expand Down
8 changes: 4 additions & 4 deletions crates/dash_node_impl/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ pub fn init_module(sc: &mut LocalScope<'_>) -> Result<Value, Value> {
handlers: RefCell::new(FxHashMap::default()),
};
let on_fn = register_native_fn(sc, on_sym, on);
event_emitter_prototype.set_property(sc, on_sym.into(), PropertyValue::static_default(on_fn.into()))?;
event_emitter_prototype.set_property(on_sym.into(), PropertyValue::static_default(on_fn.into()), sc)?;
let emit_fn = register_native_fn(sc, emit_sym, emit);
event_emitter_prototype.set_property(sc, emit_sym.into(), PropertyValue::static_default(emit_fn.into()))?;
event_emitter_prototype.set_property(emit_sym.into(), PropertyValue::static_default(emit_fn.into()), sc)?;
sc.register(event_emitter_prototype)
};

Expand Down Expand Up @@ -72,9 +72,9 @@ pub fn init_module(sc: &mut LocalScope<'_>) -> Result<Value, Value> {
});

event_emitter_ctor.set_property(
sc,
event_emitter_sym.into(),
PropertyValue::static_default(event_emitter_ctor.into()),
sc,
)?;

Ok(Value::object(event_emitter_ctor))
Expand Down Expand Up @@ -158,7 +158,7 @@ fn emit(cx: CallContext) -> Result<Value, Value> {
if let Some(handlers) = this.handlers.borrow().get(&name.sym()) {
for handler in handlers {
handler
.apply(sc, This::Bound(cx.this), CallArgs::from(args))
.apply(This::Bound(cx.this), CallArgs::from(args), sc)
.root_err(sc)?;
did_emit = true;
}
Expand Down
30 changes: 15 additions & 15 deletions crates/dash_node_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,28 @@ async fn run_inner_fallible(path: &str, opt: OptLevel, initial_gc_threshold: Opt
global
.clone()
.set_property(
scope,
global_sym.into(),
PropertyValue::static_default(Value::object(global)),
scope,
)
.unwrap();

let process = create_process_object(scope);
global
.set_property(scope, process_sym.into(), PropertyValue::static_default(process.into()))
.set_property(process_sym.into(), PropertyValue::static_default(process.into()), scope)
.unwrap();

let buffer = buffer::init_module(scope).unwrap();
global
.set_property(scope, buffer_sym.into(), PropertyValue::static_default(buffer))
.set_property(buffer_sym.into(), PropertyValue::static_default(buffer), scope)
.unwrap();
let timer = dash_rt_timers::import(scope).unwrap();
let set_timeout = timer.get_property(scope, set_timeout_sym.into()).unwrap().root(scope);
let set_timeout = timer.get_property(set_timeout_sym.into(), scope).unwrap().root(scope);
global
.set_property(
scope,
set_timeout_sym.into(),
PropertyValue::static_default(set_timeout),
scope,
)
.unwrap();

Expand Down Expand Up @@ -148,7 +148,7 @@ fn create_process_object(sc: &mut LocalScope<'_>) -> ObjectId {
let env = NamedObject::new(sc);
let env = sc.register(env);
let env_k = sc.intern("env");
obj.set_property(sc, env_k.into(), PropertyValue::static_default(env.into()))
obj.set_property(env_k.into(), PropertyValue::static_default(env.into()), sc)
.unwrap();

let argv_k = sc.intern("argv");
Expand All @@ -157,7 +157,7 @@ fn create_process_object(sc: &mut LocalScope<'_>) -> ObjectId {
.collect::<Vec<_>>();
let argv = Array::from_vec(sc, argv);
let argv = sc.register(argv);
obj.set_property(sc, argv_k.into(), PropertyValue::static_default(argv.into()))
obj.set_property(argv_k.into(), PropertyValue::static_default(argv.into()), sc)
.unwrap();

let versions_k = sc.intern("versions");
Expand All @@ -166,13 +166,13 @@ fn create_process_object(sc: &mut LocalScope<'_>) -> ObjectId {
let version = sc.intern(env!("CARGO_PKG_VERSION"));
versions
.set_property(
sc,
dash_k.into(),
PropertyValue::static_default(Value::string(version.into())),
sc,
)
.unwrap();
let versions = sc.register(versions);
obj.set_property(sc, versions_k.into(), PropertyValue::static_default(versions.into()))
obj.set_property(versions_k.into(), PropertyValue::static_default(versions.into()), sc)
.unwrap();

sc.register(obj)
Expand Down Expand Up @@ -212,7 +212,7 @@ fn execute_node_module(
}));
let key = scope.intern("exports");
module
.set_property(scope, key.into(), PropertyValue::static_default(exports))
.set_property(key.into(), PropertyValue::static_default(exports), scope)
.unwrap();

global_state
Expand All @@ -232,9 +232,9 @@ fn execute_node_module(
let dirname = Value::string(scope.intern(dir_path.to_str().expect("invalid utf-8 path")).into());
let filename = Value::string(scope.intern(file_path.to_str().expect("invalid utf-8 path")).into());
fun.apply(
scope,
This::Default,
[exports, module, require, dirname, filename].into(),
scope,
)
.map_err(|err| (EvalError::Exception(err), code))?;

Expand Down Expand Up @@ -280,10 +280,10 @@ impl Object for RequireFunction {

fn apply(
&self,
scope: &mut LocalScope,
_callee: dash_vm::gc::ObjectId,
_this: This,
args: CallArgs,
scope: &mut LocalScope,
) -> Result<Unrooted, Unrooted> {
let Some(ValueKind::String(raw_arg)) = args.first().unpack() else {
throw!(scope, Error, "require() expects a string argument");
Expand All @@ -309,7 +309,7 @@ impl Object for RequireFunction {

if let Some(module) = self.state.ongoing_requires.borrow().get(&canonicalized_path) {
debug!(%arg, "resolved module (cache)");
return module.get_property(scope, exports.into());
return module.get_property(exports.into(), scope);
}

let source = match std::fs::read_to_string(&canonicalized_path) {
Expand Down Expand Up @@ -339,7 +339,7 @@ impl Object for RequireFunction {
}
};

module.get_property(scope, exports.into())
module.get_property(exports.into(), scope)
}
} else if let Some(o) = native::load_native_module(scope, raw_arg)? {
Ok(o.into())
Expand Down Expand Up @@ -384,7 +384,7 @@ impl Object for RequireFunction {
}
};

module.get_property(scope, exports.into())
module.get_property(exports.into(), scope)
};
debug!(%arg, "resolved module");
result
Expand Down
2 changes: 1 addition & 1 deletion crates/dash_node_impl/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ fn init_fs_module(sc: &mut LocalScope<'_>) -> Result<Value, Value> {
let sync = dash_rt_fs::sync::init_module(sc)?;
let promises = dash_rt_fs::promises::init_module(sc)?;
let key = state_mut(sc).sym.promises;
sync.set_property(sc, key.into(), PropertyValue::static_default(promises))?;
sync.set_property(key.into(), PropertyValue::static_default(promises), sc)?;
Ok(sync)
}
6 changes: 3 additions & 3 deletions crates/dash_node_impl/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub fn init_module(sc: &mut LocalScope<'_>) -> Result<Value, Value> {
let parse_sym = state_mut(sc).sym.parse;
let parse_path = register_native_fn(sc, parse_sym, parse_path);
let join_path = register_native_fn(sc, sym::join, join_path);
exports.set_property(sc, parse_sym.into(), PropertyValue::static_default(parse_path.into()))?;
exports.set_property(sc, sym::join.into(), PropertyValue::static_default(join_path.into()))?;
exports.set_property(parse_sym.into(), PropertyValue::static_default(parse_path.into()), sc)?;
exports.set_property(sym::join.into(), PropertyValue::static_default(join_path.into()), sc)?;

Ok(sc.register(exports).into())
}
Expand All @@ -38,9 +38,9 @@ fn parse_path(cx: CallContext) -> Result<Value, Value> {
let object = cx.scope.register(object);
let dir_sym = state_mut(cx.scope).sym.dir;
object.set_property(
cx.scope,
dir_sym.into(),
PropertyValue::static_default(Value::string(dir.into())),
cx.scope,
)?;
Ok(cx.scope.register(object).into())
}
Expand Down
17 changes: 7 additions & 10 deletions crates/dash_node_impl/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use dash_rt::state::State;
use dash_rt::typemap::Key;
use dash_vm::gc::ObjectId;
use dash_vm::localscope::LocalScope;
use dash_vm::value::Value;
use dash_vm::value::function::native::register_native_fn;
use dash_vm::value::function::{Function, FunctionKind};
use dash_vm::value::object::{NamedObject, Object, PropertyValue};
use dash_vm::value::Value;
use dash_vm::{delegate, extract};

use crate::state::state_mut;
Expand Down Expand Up @@ -46,19 +46,16 @@ pub fn init_module(sc: &mut LocalScope<'_>) -> Result<Value, Value> {

let readable_fn = register_native_fn(sc, readable_sym, |_sc| Ok(Value::undefined()));
stream_ctor.set_property(
sc,
readable_sym.into(),
PropertyValue::static_default(readable_fn.into()),
sc,
)?;
stream_ctor.set_property(sc, stream_sym.into(), PropertyValue::static_default(stream_ctor.into()))?;
stream_ctor.set_property(stream_sym.into(), PropertyValue::static_default(stream_ctor.into()), sc)?;

State::from_vm_mut(sc).store.insert(
StreamKey,
StreamState {
stream_prototype,
stream_ctor,
},
);
State::from_vm_mut(sc).store.insert(StreamKey, StreamState {
stream_prototype,
stream_ctor,
});

Ok(stream_ctor.into())
}
Expand Down
20 changes: 12 additions & 8 deletions crates/dash_node_impl/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub fn init_module(sc: &mut LocalScope<'_>) -> Result<Value, Value> {

let inherits = register_native_fn(sc, inherits_sym, inherits);
let inspect = register_native_fn(sc, inspect_sym, inspect);
exports.set_property(sc, inherits_sym.into(), PropertyValue::static_default(inherits.into()))?;
exports.set_property(sc, inspect_sym.into(), PropertyValue::static_default(inspect.into()))?;
exports.set_property(inherits_sym.into(), PropertyValue::static_default(inherits.into()), sc)?;
exports.set_property(inspect_sym.into(), PropertyValue::static_default(inspect.into()), sc)?;

Ok(exports.into())
}
Expand All @@ -40,18 +40,22 @@ fn inherits(cx: CallContext) -> Result<Value, Value> {
}

let super_inst = super_ctor
.construct(cx.scope, This::Default, CallArgs::empty())
.construct(This::Default, CallArgs::empty(), cx.scope)
.root(cx.scope)?;

super_inst.set_property(cx.scope, sym::constructor.into(), PropertyValue {
kind: PropertyValueKind::Static(ctor),
descriptor: PropertyDataDescriptor::WRITABLE | PropertyDataDescriptor::CONFIGURABLE,
})?;
super_inst.set_property(
sym::constructor.into(),
PropertyValue {
kind: PropertyValueKind::Static(ctor),
descriptor: PropertyDataDescriptor::WRITABLE | PropertyDataDescriptor::CONFIGURABLE,
},
cx.scope,
)?;

ctor.set_property(
cx.scope,
sym::prototype.into(),
PropertyValue::static_default(super_inst),
cx.scope,
)?;

Ok(Value::undefined())
Expand Down
15 changes: 6 additions & 9 deletions crates/dash_node_impl/src/zlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use dash_rt::state::State;
use dash_rt::typemap::Key;
use dash_vm::gc::ObjectId;
use dash_vm::localscope::LocalScope;
use dash_vm::value::Value;
use dash_vm::value::function::{Function, FunctionKind};
use dash_vm::value::object::{NamedObject, Object, PropertyValue};
use dash_vm::value::Value;
use dash_vm::{delegate, extract};

use crate::state::state_mut;
Expand Down Expand Up @@ -42,18 +42,15 @@ pub fn init_module(sc: &mut LocalScope<'_>) -> Result<Value, Value> {

let exports = sc.register(NamedObject::new(sc));
exports.set_property(
sc,
inflate_sym.into(),
PropertyValue::static_default(inflate_ctor.into()),
sc,
)?;

State::from_vm_mut(sc).store.insert(
ZlibKey,
ZlibState {
inflate_prototype,
inflate_ctor,
},
);
State::from_vm_mut(sc).store.insert(ZlibKey, ZlibState {
inflate_prototype,
inflate_ctor,
});

Ok(exports.into())
}
Expand Down
8 changes: 4 additions & 4 deletions crates/dash_rt/src/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ fn inspect_inner_into(
}),
ValueKind::Object(object) => {
let constructor = object
.get_property(scope, sym::constructor.into())
.get_property(sym::constructor.into(), scope)
.root(scope)?
.into_option();
let constructor_name = constructor
.map(|c| c.get_property(scope, sym::name.into()))
.map(|c| c.get_property(sym::name.into(), scope))
.transpose()
.root(scope)?
.map(|n| n.to_js_string(scope).map(|s| s.sym()))
Expand All @@ -165,7 +165,7 @@ fn inspect_inner_into(

if object.type_of(scope) == Typeof::Function {
let name = object
.get_own_property(scope, sym::name.into())
.get_own_property(sym::name.into(), scope)
.root(scope)?
.into_option()
.map(|v| v.to_js_string(scope))
Expand All @@ -188,7 +188,7 @@ fn inspect_inner_into(
for (i, key) in keys.into_iter().enumerate() {
let key = PropertyKey::from_value(scope, key)?;

if let Some(property_value) = object.get_own_property_descriptor(scope, key).root_err(scope)? {
if let Some(property_value) = object.get_own_property_descriptor(key, scope).root_err(scope)? {
if property_value.descriptor.contains(PropertyDataDescriptor::ENUMERABLE) {
if i > 0 {
*out += ", ";
Expand Down
Loading

0 comments on commit b9b3a36

Please sign in to comment.