From b9b3a36dc07074e5af11aaa99cb993bfeb30b01d Mon Sep 17 00:00:00 2001 From: y21 <30553356+y21@users.noreply.github.com> Date: Sun, 29 Dec 2024 04:57:28 +0100 Subject: [PATCH] make `&mut LocalScope` the last parameter --- crates/dash_dlloader/src/lib.rs | 4 +- crates/dash_node_impl/src/buffer.rs | 12 +- crates/dash_node_impl/src/events.rs | 8 +- crates/dash_node_impl/src/lib.rs | 30 +-- crates/dash_node_impl/src/native.rs | 2 +- crates/dash_node_impl/src/path.rs | 6 +- crates/dash_node_impl/src/stream.rs | 17 +- crates/dash_node_impl/src/util.rs | 20 +- crates/dash_node_impl/src/zlib.rs | 15 +- crates/dash_rt/src/inspect.rs | 8 +- crates/dash_rt/src/runtime.rs | 4 +- crates/dash_rt_fetch/src/lib.rs | 2 +- crates/dash_rt_fs/src/promises.rs | 2 +- crates/dash_rt_fs/src/sync.rs | 4 +- crates/dash_rt_http/src/lib.rs | 4 +- crates/dash_rt_net/src/lib.rs | 4 +- crates/dash_rt_net/src/listener/mod.rs | 18 +- crates/dash_rt_timers/src/lib.rs | 4 +- crates/dash_vm/src/dispatch.rs | 128 ++++++++----- crates/dash_vm/src/eval.rs | 4 +- crates/dash_vm/src/gc/mod.rs | 55 +++--- crates/dash_vm/src/js_std/array.rs | 108 +++++------ crates/dash_vm/src/js_std/array_iterator.rs | 4 +- crates/dash_vm/src/js_std/error.rs | 2 +- crates/dash_vm/src/js_std/function.rs | 6 +- crates/dash_vm/src/js_std/generator.rs | 4 +- crates/dash_vm/src/js_std/map.rs | 6 +- crates/dash_vm/src/js_std/object.rs | 32 ++-- crates/dash_vm/src/js_std/promise.rs | 11 +- crates/dash_vm/src/js_std/set.rs | 2 +- crates/dash_vm/src/js_std/typedarray.rs | 4 +- crates/dash_vm/src/js_std/weakmap.rs | 6 +- crates/dash_vm/src/js_std/weakset.rs | 2 +- crates/dash_vm/src/lib.rs | 12 +- crates/dash_vm/src/test/mod.rs | 4 +- crates/dash_vm/src/value/array/mod.rs | 30 +-- crates/dash_vm/src/value/arraybuffer.rs | 4 +- crates/dash_vm/src/value/boxed.rs | 6 +- crates/dash_vm/src/value/error.rs | 20 +- crates/dash_vm/src/value/function/async.rs | 14 +- crates/dash_vm/src/value/function/bound.rs | 5 +- .../dash_vm/src/value/function/generator.rs | 4 +- crates/dash_vm/src/value/function/mod.rs | 22 +-- crates/dash_vm/src/value/mod.rs | 144 +++++++------- crates/dash_vm/src/value/object.rs | 179 +++++++++--------- crates/dash_vm/src/value/ops/conversions.rs | 10 +- crates/dash_vm/src/value/primitive.rs | 70 +++---- crates/dash_vm/src/value/promise.rs | 56 +++--- crates/dash_vm/src/value/string.rs | 10 +- crates/dash_vm/src/value/typedarray.rs | 20 +- 50 files changed, 588 insertions(+), 560 deletions(-) diff --git a/crates/dash_dlloader/src/lib.rs b/crates/dash_dlloader/src/lib.rs index 878512aa..0d731a3c 100644 --- a/crates/dash_dlloader/src/lib.rs +++ b/crates/dash_dlloader/src/lib.rs @@ -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); @@ -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)))) } diff --git a/crates/dash_node_impl/src/buffer.rs b/crates/dash_node_impl/src/buffer.rs index b0a4b23c..ea7d8f6a 100644 --- a/crates/dash_node_impl/src/buffer.rs +++ b/crates/dash_node_impl/src/buffer.rs @@ -39,8 +39,8 @@ pub fn init_module(sc: &mut LocalScope<'_>) -> Result { }; 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, @@ -52,9 +52,9 @@ pub fn init_module(sc: &mut LocalScope<'_>) -> Result { 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, @@ -150,7 +150,7 @@ fn from(cx: CallContext) -> Result { 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)); diff --git a/crates/dash_node_impl/src/events.rs b/crates/dash_node_impl/src/events.rs index 5f7267a2..12bf2ac9 100644 --- a/crates/dash_node_impl/src/events.rs +++ b/crates/dash_node_impl/src/events.rs @@ -36,9 +36,9 @@ pub fn init_module(sc: &mut LocalScope<'_>) -> Result { 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) }; @@ -72,9 +72,9 @@ pub fn init_module(sc: &mut LocalScope<'_>) -> Result { }); event_emitter_ctor.set_property( - sc, event_emitter_sym.into(), PropertyValue::static_default(event_emitter_ctor.into()), + sc, )?; Ok(Value::object(event_emitter_ctor)) @@ -158,7 +158,7 @@ fn emit(cx: CallContext) -> Result { 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; } diff --git a/crates/dash_node_impl/src/lib.rs b/crates/dash_node_impl/src/lib.rs index c76f038a..5a91e9ad 100644 --- a/crates/dash_node_impl/src/lib.rs +++ b/crates/dash_node_impl/src/lib.rs @@ -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(); @@ -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"); @@ -157,7 +157,7 @@ fn create_process_object(sc: &mut LocalScope<'_>) -> ObjectId { .collect::>(); 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"); @@ -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) @@ -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 @@ -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))?; @@ -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 { let Some(ValueKind::String(raw_arg)) = args.first().unpack() else { throw!(scope, Error, "require() expects a string argument"); @@ -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) { @@ -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()) @@ -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 diff --git a/crates/dash_node_impl/src/native.rs b/crates/dash_node_impl/src/native.rs index 9b666e52..238886bd 100644 --- a/crates/dash_node_impl/src/native.rs +++ b/crates/dash_node_impl/src/native.rs @@ -69,6 +69,6 @@ fn init_fs_module(sc: &mut LocalScope<'_>) -> Result { 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) } diff --git a/crates/dash_node_impl/src/path.rs b/crates/dash_node_impl/src/path.rs index 491d718b..55b6e8e6 100644 --- a/crates/dash_node_impl/src/path.rs +++ b/crates/dash_node_impl/src/path.rs @@ -15,8 +15,8 @@ pub fn init_module(sc: &mut LocalScope<'_>) -> Result { 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()) } @@ -38,9 +38,9 @@ fn parse_path(cx: CallContext) -> Result { 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()) } diff --git a/crates/dash_node_impl/src/stream.rs b/crates/dash_node_impl/src/stream.rs index c2f6bdfe..686fc1c8 100644 --- a/crates/dash_node_impl/src/stream.rs +++ b/crates/dash_node_impl/src/stream.rs @@ -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; @@ -46,19 +46,16 @@ pub fn init_module(sc: &mut LocalScope<'_>) -> Result { 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()) } diff --git a/crates/dash_node_impl/src/util.rs b/crates/dash_node_impl/src/util.rs index 26f6562c..6aa3764d 100644 --- a/crates/dash_node_impl/src/util.rs +++ b/crates/dash_node_impl/src/util.rs @@ -20,8 +20,8 @@ pub fn init_module(sc: &mut LocalScope<'_>) -> Result { 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()) } @@ -40,18 +40,22 @@ fn inherits(cx: CallContext) -> Result { } 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()) diff --git a/crates/dash_node_impl/src/zlib.rs b/crates/dash_node_impl/src/zlib.rs index 5e56121e..810cad64 100644 --- a/crates/dash_node_impl/src/zlib.rs +++ b/crates/dash_node_impl/src/zlib.rs @@ -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; @@ -42,18 +42,15 @@ pub fn init_module(sc: &mut LocalScope<'_>) -> Result { 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()) } diff --git a/crates/dash_rt/src/inspect.rs b/crates/dash_rt/src/inspect.rs index 8c378867..1a0e6bb3 100644 --- a/crates/dash_rt/src/inspect.rs +++ b/crates/dash_rt/src/inspect.rs @@ -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())) @@ -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)) @@ -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 += ", "; diff --git a/crates/dash_rt/src/runtime.rs b/crates/dash_rt/src/runtime.rs index 8959d440..35f5b555 100644 --- a/crates/dash_rt/src/runtime.rs +++ b/crates/dash_rt/src/runtime.rs @@ -76,10 +76,10 @@ impl Runtime { }); global - .get_property(scope, sym::console.into()) + .get_property(sym::console.into(), scope) .root(scope) .unwrap() - .set_property(scope, sym::log.into(), PropertyValue::static_default(log.into())) + .set_property(sym::log.into(), PropertyValue::static_default(log.into()), scope) .unwrap(); } diff --git a/crates/dash_rt_fetch/src/lib.rs b/crates/dash_rt_fetch/src/lib.rs index a630cd38..f99a311f 100644 --- a/crates/dash_rt_fetch/src/lib.rs +++ b/crates/dash_rt_fetch/src/lib.rs @@ -81,7 +81,7 @@ fn fetch(cx: CallContext) -> Result { let text_fun = Function::new(&sc, Some(text.into()), FunctionKind::Native(http_response_text)); let text_fun = Value::object(sc.register(text_fun)); - obj.set_property(&mut sc, text.into(), PropertyValue::static_default(text_fun)) + obj.set_property(text.into(), PropertyValue::static_default(text_fun), &mut sc) .unwrap(); (Value::object(sc.register(obj)), PromiseAction::Resolve) diff --git a/crates/dash_rt_fs/src/promises.rs b/crates/dash_rt_fs/src/promises.rs index 6d9d5e2c..0066d7a2 100644 --- a/crates/dash_rt_fs/src/promises.rs +++ b/crates/dash_rt_fs/src/promises.rs @@ -14,9 +14,9 @@ pub fn init_module(sc: &mut LocalScope) -> Result { let module = NamedObject::new(sc); module.set_property( - sc, name.into(), PropertyValue::static_default(Value::object(read_file_value)), + sc, )?; Ok(Value::object(sc.register(module))) diff --git a/crates/dash_rt_fs/src/sync.rs b/crates/dash_rt_fs/src/sync.rs index 0fb417a8..d0ea800f 100644 --- a/crates/dash_rt_fs/src/sync.rs +++ b/crates/dash_rt_fs/src/sync.rs @@ -18,14 +18,14 @@ pub fn init_module(sc: &mut LocalScope) -> Result { let module = NamedObject::new(sc); module.set_property( - sc, read_file_sync_sym.into(), PropertyValue::static_default(Value::object(read_file_sync_value)), + sc, )?; module.set_property( - sc, write_file_sync_sym.into(), PropertyValue::static_default(Value::object(write_file_sync_value)), + sc, )?; Ok(Value::object(sc.register(module))) diff --git a/crates/dash_rt_http/src/lib.rs b/crates/dash_rt_http/src/lib.rs index 5e0be87b..74918fd1 100644 --- a/crates/dash_rt_http/src/lib.rs +++ b/crates/dash_rt_http/src/lib.rs @@ -42,7 +42,7 @@ impl ModuleLoader for HttpModule { let listen = Function::new(sc, None, FunctionKind::Native(listen)); let listen = sc.register(listen); let key = sc.intern("listen"); - module.set_property(sc, key.into(), PropertyValue::static_default(listen.into()))?; + module.set_property(key.into(), PropertyValue::static_default(listen.into()), sc)?; let module = sc.register(module); Ok(Some(module.into())) @@ -95,7 +95,7 @@ pub fn listen(cx: CallContext) -> Result { let name = scope.intern("respond"); let fun = Function::new(&scope, Some(name.into()), FunctionKind::Native(ctx_respond)); let fun = scope.register(fun); - ctx.set_property(&mut scope, name.into(), PropertyValue::static_default(fun.into())) + ctx.set_property(name.into(), PropertyValue::static_default(fun.into()), &mut scope) .unwrap(); let ctx = Value::object(scope.register(ctx)); diff --git a/crates/dash_rt_net/src/lib.rs b/crates/dash_rt_net/src/lib.rs index 0ba0e5da..f3e8a04e 100644 --- a/crates/dash_rt_net/src/lib.rs +++ b/crates/dash_rt_net/src/lib.rs @@ -1,9 +1,9 @@ use dash_middle::compiler::StaticImportKind; use dash_rt::module::ModuleLoader; use dash_vm::localscope::LocalScope; +use dash_vm::value::Value; use dash_vm::value::object::{NamedObject, Object, PropertyValue}; use dash_vm::value::string::JsString; -use dash_vm::value::Value; use crate::listener::TcpListenerConstructor; @@ -27,9 +27,9 @@ impl ModuleLoader for NetModule { let tcplistener = sc.register(TcpListenerConstructor {}); let name = sc.intern("TcpListener"); exports.set_property( - sc, name.into(), PropertyValue::static_default(Value::object(tcplistener)), + sc, )?; Ok(Some(Value::object(sc.register(exports)))) diff --git a/crates/dash_rt_net/src/listener/mod.rs b/crates/dash_rt_net/src/listener/mod.rs index 75f5ad7e..d175f125 100644 --- a/crates/dash_rt_net/src/listener/mod.rs +++ b/crates/dash_rt_net/src/listener/mod.rs @@ -29,33 +29,33 @@ pub struct TcpListenerConstructor {} impl Object for TcpListenerConstructor { fn get_own_property_descriptor( &self, - _sc: &mut dash_vm::localscope::LocalScope, _key: PropertyKey, + _sc: &mut dash_vm::localscope::LocalScope, ) -> Result, dash_vm::value::Unrooted> { Ok(None) } fn set_property( &self, - _sc: &mut dash_vm::localscope::LocalScope, _key: PropertyKey, _value: dash_vm::value::object::PropertyValue, + _sc: &mut dash_vm::localscope::LocalScope, ) -> Result<(), dash_vm::value::Value> { Ok(()) } fn delete_property( &self, - _sc: &mut dash_vm::localscope::LocalScope, _key: PropertyKey, + _sc: &mut dash_vm::localscope::LocalScope, ) -> Result { Ok(Unrooted::new(Value::undefined())) } fn set_prototype( &self, - _sc: &mut dash_vm::localscope::LocalScope, _value: dash_vm::value::Value, + _sc: &mut dash_vm::localscope::LocalScope, ) -> Result<(), dash_vm::value::Value> { Ok(()) } @@ -69,21 +69,21 @@ impl Object for TcpListenerConstructor { fn apply( &self, - scope: &mut dash_vm::localscope::LocalScope, _callee: dash_vm::gc::ObjectId, _this: This, _args: CallArgs, + scope: &mut dash_vm::localscope::LocalScope, ) -> Result { throw!(scope, Error, "TcpListener should be called as a constructor") } fn construct( &self, - scope: &mut dash_vm::localscope::LocalScope, _callee: dash_vm::gc::ObjectId, _this: This, args: CallArgs, new_target: ObjectId, + scope: &mut dash_vm::localscope::LocalScope, ) -> Result { let Some(value) = args.first() else { throw!( @@ -177,7 +177,7 @@ impl TcpListenerHandle { let name = sc.intern("accept"); let accept_fn = Function::new(sc, Some(name.into()), FunctionKind::Native(tcplistener_accept)); let accept_fn = sc.register(accept_fn); - object.set_property(sc, name.into(), PropertyValue::static_default(Value::object(accept_fn)))?; + object.set_property(name.into(), PropertyValue::static_default(Value::object(accept_fn)), sc)?; Ok(Self { object, sender }) } } @@ -229,17 +229,17 @@ impl TcpStreamHandle { let write_fn = Function::new(scope, Some(name.into()), FunctionKind::Native(tcpstream_write)); let write_fn = scope.register(write_fn); object.set_property( - scope, name.into(), PropertyValue::static_default(Value::object(write_fn)), + scope, )?; let name = scope.intern("read"); let read_fn = Function::new(scope, Some(name.into()), FunctionKind::Native(tcpstream_read)); let read_fn = scope.register(read_fn); object.set_property( - scope, name.into(), PropertyValue::static_default(Value::object(read_fn)), + scope, )?; Ok(Self { object, diff --git a/crates/dash_rt_timers/src/lib.rs b/crates/dash_rt_timers/src/lib.rs index 1b86c9a5..0c4eb799 100644 --- a/crates/dash_rt_timers/src/lib.rs +++ b/crates/dash_rt_timers/src/lib.rs @@ -42,17 +42,17 @@ pub fn import(sc: &mut LocalScope<'_>) -> Result { let set_timeout = register_native_fn(sc, set_timeout_sym, set_timeout); obj.set_property( - sc, set_timeout_sym.into(), PropertyValue::static_default(set_timeout.into()), + sc, )?; let set_immediate_sym = sc.intern("setImmediate"); let set_immediate = register_native_fn(sc, set_immediate_sym, set_immediate); obj.set_property( - sc, set_immediate_sym.into(), PropertyValue::static_default(set_immediate.into()), + sc, )?; Ok(Value::object(sc.register(obj))) diff --git a/crates/dash_vm/src/dispatch.rs b/crates/dash_vm/src/dispatch.rs index c090a079..76848af0 100755 --- a/crates/dash_vm/src/dispatch.rs +++ b/crates/dash_vm/src/dispatch.rs @@ -518,7 +518,7 @@ mod extract { } ExportPropertyKind::Global => { let ident = extract::(cx).0; - let value = cx.global().get_property(&mut cx.scope, ident.into())?; + let value = cx.global().get_property(ident.into(), &mut cx.scope)?; Self(value, ident) } }) @@ -931,7 +931,7 @@ mod handlers { throw!(&mut cx, ReferenceError, "{} is not defined", name) } }, - None => cx.global.get_property(&mut cx, name.into())?, + None => cx.global.get_property(name.into(), &mut cx.scope)?, }; cx.push_stack(value); @@ -949,13 +949,15 @@ mod handlers { let value = cx .global .clone() - .get_property(&mut cx, PropertyKey::String(name)) + .get_property(PropertyKey::String(name), &mut cx.scope) .root(&mut cx.scope)?; let res = $op(value, right, &mut cx)?; - cx.global - .clone() - .set_property(&mut cx, name.into(), PropertyValue::static_default(res.clone()))?; + cx.global.clone().set_property( + name.into(), + PropertyValue::static_default(res.clone()), + &mut cx.scope, + )?; cx.stack.push(res); }}; } @@ -965,15 +967,17 @@ mod handlers { let value = cx .global .clone() - .get_property(&mut cx, PropertyKey::String(name)) + .get_property(PropertyKey::String(name), &mut cx.scope) .root(&mut cx.scope)?; let value = Value::number(value.to_number(&mut cx)?); let right = Value::number(1.0); let res = $op(value, right, &mut cx)?; - cx.global - .clone() - .set_property(&mut cx, name.into(), PropertyValue::static_default(res.clone()))?; + cx.global.clone().set_property( + name.into(), + PropertyValue::static_default(res.clone()), + &mut cx.scope, + )?; cx.stack.push(res); }}; } @@ -983,7 +987,7 @@ mod handlers { let value = cx .global .clone() - .get_property(&mut cx, PropertyKey::String(name)) + .get_property(PropertyKey::String(name), &mut cx.scope) .root(&mut cx.scope)?; let value = Value::number(value.to_number(&mut cx)?); @@ -991,7 +995,7 @@ mod handlers { let res = $op(value, right, &mut cx)?; cx.global .clone() - .set_property(&mut cx, name.into(), PropertyValue::static_default(res))?; + .set_property(name.into(), PropertyValue::static_default(res), &mut cx.scope)?; cx.stack.push(value); }}; } @@ -1002,7 +1006,7 @@ mod handlers { cx.global .clone() - .set_property(&mut cx, name.into(), PropertyValue::static_default(value))?; + .set_property(name.into(), PropertyValue::static_default(value), &mut cx.scope)?; cx.stack.push(value); } AssignKind::AddAssignment => op!(Value::add), @@ -1092,7 +1096,7 @@ mod handlers { for i in 0..length { let i = cx.scope.intern_usize(i); - let value = iterable.get_property(&mut cx, i.into())?.root(&mut cx.scope); + let value = iterable.get_property(i.into(), &mut cx.scope)?.root(&mut cx.scope); splice_args.push(value); } cx.stack.splice( @@ -1153,7 +1157,7 @@ mod handlers { let len = value.length_of_array_like(&mut cx.scope)?; for i in 0..len { let i = cx.scope.intern_usize(i); - let value = value.get_property(&mut cx, i.into())?.root(&mut cx.scope); + let value = value.get_property(i.into(), &mut cx.scope)?.root(&mut cx.scope); // NB: no need to push into `refs` since we already rooted it args.push(value); } @@ -1170,12 +1174,12 @@ mod handlers { cx.scope.add_many(&args); let ret = match function_call_kind { - FunctionCallKind::Constructor => callee.construct(&mut cx.scope, this, args.into())?, + FunctionCallKind::Constructor => callee.construct(this, args.into(), &mut cx.scope)?, FunctionCallKind::Super => { let new_target = cx.active_frame().new_target().unwrap(); - callee.construct_with_target(&mut cx.scope, this, args.into(), new_target)? + callee.construct_with_target(this, args.into(), new_target, &mut cx.scope)? } - FunctionCallKind::Function => callee.apply_with_debug(&mut cx.scope, this, args.into(), call_ip)?, + FunctionCallKind::Function => callee.apply_with_debug(this, args.into(), call_ip, &mut cx.scope)?, }; // SAFETY: no need to root, we're directly pushing into the value stack which itself is a root @@ -1478,7 +1482,7 @@ mod handlers { for i in 0..len { let i = cx.scope.intern_usize(i); - let value = source.get_property(&mut cx.scope, i.into())?.root(&mut cx.scope); + let value = source.get_property(i.into(), &mut cx.scope)?.root(&mut cx.scope); fun(ArrayElement::Single(value)); } } @@ -1552,7 +1556,7 @@ mod handlers { if let ValueKind::Object(object) = value.unpack() { for key in object.own_keys(&mut cx.scope)? { let key = PropertyKey::from_value(&mut cx.scope, key)?; - let value = object.get_property(&mut cx, key)?.root(&mut cx.scope); + let value = object.get_property(key, &mut cx.scope)?.root(&mut cx.scope); obj.insert(key, PropertyValue::static_default(value)); } } @@ -1577,9 +1581,9 @@ mod handlers { let is_getter = matches!(property, ObjectProperty::Getter { .. }); match property { - ObjectProperty::Static { key, value } => target.set_property(&mut cx.scope, key, value)?, + ObjectProperty::Static { key, value } => target.set_property(key, value, &mut cx.scope)?, ObjectProperty::Getter { key, value } | ObjectProperty::Setter { key, value } => { - let prop = target.get_property_descriptor(&mut cx.scope, key)?; + let prop = target.get_property_descriptor(key, &mut cx.scope)?; let prop = match prop { Some(mut prop) => { if let PropertyValueKind::Trap { get, set } = &mut prop.kind { @@ -1600,7 +1604,7 @@ mod handlers { } }; - target.set_property(&mut cx.scope, key, prop)?; + target.set_property(key, prop, &mut cx.scope)?; } ObjectProperty::Spread(_) => unimplemented!("spread operator in AssignProperties"), } @@ -1621,7 +1625,7 @@ mod handlers { cx.pop_stack_rooted() }; - let value = target.get_property(&mut cx, ident.into())?; + let value = target.get_property(ident.into(), &mut cx.scope)?; cx.push_stack(value); Ok(None) } @@ -1638,10 +1642,16 @@ mod handlers { let target = target.root(&mut cx.scope); let value = value.root(&mut cx.scope); - let p = target.get_property(&mut cx, key.into())?.root(&mut cx.scope); + let p = target + .get_property(key.into(), &mut cx.scope)? + .root(&mut cx.scope); let res = $op(p, value, &mut cx)?; - target.set_property(&mut cx, key.into(), PropertyValue::static_default(res.clone()))?; + target.set_property( + key.into(), + PropertyValue::static_default(res.clone()), + &mut cx.scope, + )?; cx.stack.push(res); }}; } @@ -1649,11 +1659,13 @@ mod handlers { macro_rules! postfix { ($op:expr) => {{ let target = cx.pop_stack_rooted(); - let prop = target.get_property(&mut cx, key.into())?.root(&mut cx.scope); + let prop = target + .get_property(key.into(), &mut cx.scope)? + .root(&mut cx.scope); let prop = Value::number(prop.to_number(&mut cx)?); let one = Value::number(1.0); let res = $op(prop, one, &mut cx)?; - target.set_property(&mut cx, key.into(), PropertyValue::static_default(res))?; + target.set_property(key.into(), PropertyValue::static_default(res), &mut cx.scope)?; cx.stack.push(prop); }}; } @@ -1661,12 +1673,18 @@ mod handlers { macro_rules! prefix { ($op:expr) => {{ let target = cx.pop_stack_rooted(); - let prop = target.get_property(&mut cx, key.into())?.root(&mut cx.scope); + let prop = target + .get_property(key.into(), &mut cx.scope)? + .root(&mut cx.scope); let prop = Value::number(prop.to_number(&mut cx)?); // TODO: check that it encodes at comptime, if not make a constant Value::ONE let one = Value::number(1.0); let res = $op(prop, one, &mut cx)?; - target.set_property(&mut cx, key.into(), PropertyValue::static_default(res.clone()))?; + target.set_property( + key.into(), + PropertyValue::static_default(res.clone()), + &mut cx.scope, + )?; cx.stack.push(res); }}; } @@ -1676,7 +1694,7 @@ mod handlers { let (target, value) = cx.pop_stack2_new(); let target = target.root(&mut cx.scope); let value = value.root(&mut cx.scope); - target.set_property(&mut cx, key.into(), PropertyValue::static_default(value))?; + target.set_property(key.into(), PropertyValue::static_default(value), &mut cx.scope)?; cx.stack.push(value); } AssignKind::AddAssignment => op!(Value::add), @@ -1708,11 +1726,13 @@ mod handlers { let (target, value, key) = cx.pop_stack3_rooted(); let key = PropertyKey::from_value(&mut cx, key)?; - let prop = target.get_property(&mut cx, key.clone())?.root(&mut cx.scope); + let prop = target + .get_property(key.clone(), &mut cx.scope)? + .root(&mut cx.scope); let result = $op(prop, value, &mut cx)?; - target.set_property(&mut cx, key, PropertyValue::static_default(result.clone()))?; + target.set_property(key, PropertyValue::static_default(result.clone()), &mut cx.scope)?; cx.stack.push(result); }}; } @@ -1721,11 +1741,13 @@ mod handlers { ($op:expr) => {{ let (target, key) = cx.pop_stack2_rooted(); let key = PropertyKey::from_value(&mut cx, key)?; - let prop = target.get_property(&mut cx, key.clone())?.root(&mut cx.scope); + let prop = target + .get_property(key.clone(), &mut cx.scope)? + .root(&mut cx.scope); let prop = Value::number(prop.to_number(&mut cx)?); let one = Value::number(1.0); let res = $op(prop, one, &mut cx)?; - target.set_property(&mut cx, key, PropertyValue::static_default(res))?; + target.set_property(key, PropertyValue::static_default(res), &mut cx.scope)?; cx.stack.push(prop); }}; } @@ -1734,11 +1756,13 @@ mod handlers { ($op:expr) => {{ let (target, key) = cx.pop_stack2_rooted(); let key = PropertyKey::from_value(&mut cx, key)?; - let prop = target.get_property(&mut cx, key.clone())?.root(&mut cx.scope); + let prop = target + .get_property(key.clone(), &mut cx.scope)? + .root(&mut cx.scope); let prop = Value::number(prop.to_number(&mut cx)?); let one = Value::number(1.0); let res = $op(prop, one, &mut cx)?; - target.set_property(&mut cx, key, PropertyValue::static_default(res.clone()))?; + target.set_property(key, PropertyValue::static_default(res.clone()), &mut cx.scope)?; cx.stack.push(res); }}; } @@ -1749,7 +1773,7 @@ mod handlers { let key = PropertyKey::from_value(&mut cx, key)?; - target.set_property(&mut cx, key, PropertyValue::static_default(value))?; + target.set_property(key, PropertyValue::static_default(value), &mut cx.scope)?; cx.stack.push(value); } AssignKind::AddAssignment => op!(Value::add), @@ -1786,7 +1810,7 @@ mod handlers { let key = PropertyKey::from_value(&mut cx, key)?; - let value = target.get_property(&mut cx, key)?; + let value = target.get_property(key, &mut cx.scope)?; cx.push_stack(value); Ok(None) } @@ -1910,7 +1934,7 @@ mod handlers { pub fn type_of_ident(mut cx: DispatchContext<'_>) -> Result, Unrooted> { let id = cx.fetchw_and_inc_ip(); let ident = JsString::from(cx.constants().symbols[SymbolConstant(id)]); - let prop = cx.global.get_property(&mut cx.scope, ident.into())?.root(&mut cx.scope); + let prop = cx.global.get_property(ident.into(), &mut cx.scope)?.root(&mut cx.scope); let ty = prop.type_of(&cx.scope).as_value(); cx.stack.push(ty); @@ -2035,9 +2059,9 @@ mod handlers { let value = cx.pop_stack_rooted(); let symbol_iterator = cx.statics.symbol_iterator; let iterable = value - .get_property(&mut cx, PropertyKey::Symbol(symbol_iterator))? + .get_property(PropertyKey::Symbol(symbol_iterator), &mut cx.scope)? .root(&mut cx.scope); - let iterator = iterable.apply(&mut cx, This::Bound(value), CallArgs::empty())?; + let iterator = iterable.apply(This::Bound(value), CallArgs::empty(), &mut cx.scope)?; cx.push_stack(iterator); Ok(None) } @@ -2065,7 +2089,7 @@ mod handlers { pub fn delete_property_dynamic(mut cx: DispatchContext<'_>) -> Result, Unrooted> { let (property, target) = cx.pop_stack2_rooted(); let key = PropertyKey::from_value(&mut cx, property)?; - let value = target.delete_property(&mut cx, key)?; + let value = target.delete_property(key, &mut cx.scope)?; // TODO: not correct, as `undefined` might have been the actual value let did_delete = !matches!(value.root(&mut cx.scope).unpack(), ValueKind::Undefined(..)); @@ -2077,7 +2101,7 @@ mod handlers { let target = cx.pop_stack_rooted(); let cid = cx.fetchw_and_inc_ip(); let con = JsString::from(cx.constants().symbols[SymbolConstant(cid)]); - let value = target.delete_property(&mut cx, con.into())?; + let value = target.delete_property(con.into(), &mut cx.scope)?; // TODO: not correct, as `undefined` might have been the actual value let did_delete = !matches!(value.root(&mut cx.scope).unpack(), ValueKind::Undefined(..)); @@ -2100,7 +2124,7 @@ mod handlers { idents.push(ident); } - let mut prop = obj.get_property(&mut cx, ident.into())?.root(&mut cx.scope); + let mut prop = obj.get_property(ident.into(), &mut cx.scope)?.root(&mut cx.scope); if has_default { // NB: we need to at least pop it from the stack even if the property exists let default = cx.pop_stack_rooted(); @@ -2124,8 +2148,8 @@ mod handlers { let rest = NamedObject::new(&cx.scope); let rest = cx.scope.register(rest); for key in keys { - let value = obj.get_property(&mut cx.scope, key.into())?.root(&mut cx.scope); - rest.set_property(&mut cx.scope, key.into(), PropertyValue::static_default(value))?; + let value = obj.get_property(key.into(), &mut cx.scope)?.root(&mut cx.scope); + rest.set_property(key.into(), PropertyValue::static_default(value), &mut cx.scope)?; } cx.set_local(rest_id.into(), Value::object(rest).into()); @@ -2143,7 +2167,7 @@ mod handlers { if let Some((has_default, NumberWConstant(id))) = id { let id = id as usize; let key = cx.scope.intern_usize(i); - let mut prop = array.get_property(&mut cx.scope, key.into())?.root(&mut cx.scope); + let mut prop = array.get_property(key.into(), &mut cx.scope)?.root(&mut cx.scope); if has_default { // NB: we need to at least pop it from the stack even if the property exists @@ -2273,15 +2297,15 @@ mod handlers { let k = cx .global .clone() - .get_property(&mut cx, $k.into())? + .get_property($k.into(), &mut cx.scope)? .root(&mut cx.scope); - let fun = k.get_property(&mut cx, $v.into())?.root(&mut cx.scope); - let result = fun.apply(&mut cx, This::Default, args)?; + let fun = k.get_property($v.into(), &mut cx.scope)?.root(&mut cx.scope); + let result = fun.apply(This::Default, args, &mut cx.scope)?; cx.push_stack(result); } else { // Fastpath: call builtin directly // TODO: should we add to externals? - let result = fun.apply(&mut cx, This::Default, args)?; + let result = fun.apply(This::Default, args, &mut cx.scope)?; cx.push_stack(result); } }}; diff --git a/crates/dash_vm/src/eval.rs b/crates/dash_vm/src/eval.rs index 750ae14b..1fa6294d 100644 --- a/crates/dash_vm/src/eval.rs +++ b/crates/dash_vm/src/eval.rs @@ -66,7 +66,7 @@ impl Vm { if let Some(default) = exports.default { let default = default.root(sc); - export_obj.set_property(sc, sym::default.into(), PropertyValue::static_default(default))?; + export_obj.set_property(sym::default.into(), PropertyValue::static_default(default), sc)?; } Value::object(sc.register(export_obj)) @@ -75,7 +75,7 @@ impl Vm { for (k, v) in exports.named { let v = v.root(sc); - export_obj.set_property(sc, k.into(), PropertyValue::static_default(v))?; + export_obj.set_property(k.into(), PropertyValue::static_default(v), sc)?; } Ok(export_obj.into()) diff --git a/crates/dash_vm/src/gc/mod.rs b/crates/dash_vm/src/gc/mod.rs index af7d42a2..a7c0aa20 100644 --- a/crates/dash_vm/src/gc/mod.rs +++ b/crates/dash_vm/src/gc/mod.rs @@ -30,21 +30,22 @@ pub struct ObjectVTable { pub(crate) trace: unsafe fn(*const (), &mut TraceCtxt<'_>), pub(crate) debug_fmt: unsafe fn(*const (), &mut core::fmt::Formatter<'_>) -> core::fmt::Result, pub(crate) js_get_own_property: - unsafe fn(*const (), &mut LocalScope<'_>, This, PropertyKey) -> Result, + unsafe fn(*const (), This, PropertyKey, &mut LocalScope<'_>) -> Result, pub(crate) js_get_own_property_descriptor: - unsafe fn(*const (), &mut LocalScope<'_>, PropertyKey) -> Result, Unrooted>, - pub(crate) js_get_property: unsafe fn(*const (), &mut LocalScope, This, PropertyKey) -> Result, + unsafe fn(*const (), PropertyKey, &mut LocalScope<'_>) -> Result, Unrooted>, + pub(crate) js_get_property: + unsafe fn(*const (), This, PropertyKey, &mut LocalScope<'_>) -> Result, pub(crate) js_get_property_descriptor: - unsafe fn(*const (), &mut LocalScope<'_>, PropertyKey) -> Result, Unrooted>, + unsafe fn(*const (), PropertyKey, &mut LocalScope<'_>) -> Result, Unrooted>, pub(crate) js_set_property: - unsafe fn(*const (), &mut LocalScope<'_>, PropertyKey, PropertyValue) -> Result<(), Value>, - pub(crate) js_delete_property: unsafe fn(*const (), &mut LocalScope<'_>, PropertyKey) -> Result, - pub(crate) js_set_prototype: unsafe fn(*const (), &mut LocalScope<'_>, Value) -> Result<(), Value>, + unsafe fn(*const (), PropertyKey, PropertyValue, &mut LocalScope<'_>) -> Result<(), Value>, + pub(crate) js_delete_property: unsafe fn(*const (), PropertyKey, &mut LocalScope<'_>) -> Result, + pub(crate) js_set_prototype: unsafe fn(*const (), Value, &mut LocalScope<'_>) -> Result<(), Value>, pub(crate) js_get_prototype: unsafe fn(*const (), &mut LocalScope<'_>) -> Result, pub(crate) js_apply: - unsafe fn(*const (), &mut LocalScope<'_>, ObjectId, This, CallArgs) -> Result, + unsafe fn(*const (), ObjectId, This, CallArgs, &mut LocalScope<'_>) -> Result, pub(crate) js_construct: - unsafe fn(*const (), &mut LocalScope<'_>, ObjectId, This, CallArgs, ObjectId) -> Result, + unsafe fn(*const (), ObjectId, This, CallArgs, ObjectId, &mut LocalScope<'_>) -> Result, pub(crate) js_internal_slots: unsafe fn(*const (), &Vm) -> Option<*const dyn InternalSlots>, pub(crate) js_extract_type_raw: unsafe fn(*const (), &Vm, TypeId) -> Option>, pub(crate) js_own_keys: unsafe fn(*const (), sc: &mut LocalScope<'_>) -> Result, Value>, @@ -61,33 +62,33 @@ macro_rules! object_vtable_for_ty { &$crate::gc::ObjectVTable { trace: |ptr, ctxt| unsafe { <$ty as $crate::gc::trace::Trace>::trace(&*(ptr.cast::<$ty>()), ctxt) }, debug_fmt: |ptr, f| unsafe { <$ty as std::fmt::Debug>::fmt(&*(ptr.cast::<$ty>()), f) }, - js_get_own_property: |ptr, scope, this, key| unsafe { - <$ty as Object>::get_own_property(&*(ptr.cast::<$ty>()), scope, this, key) + js_get_own_property: |ptr, this, key, scope| unsafe { + <$ty as Object>::get_own_property(&*(ptr.cast::<$ty>()), this, key, scope) }, - js_get_own_property_descriptor: |ptr, scope, key| unsafe { - <$ty as Object>::get_own_property_descriptor(&*(ptr.cast::<$ty>()), scope, key) + js_get_own_property_descriptor: |ptr, key, scope| unsafe { + <$ty as Object>::get_own_property_descriptor(&*(ptr.cast::<$ty>()), key, scope) }, - js_get_property: |ptr, scope, this, key| unsafe { - <$ty as Object>::get_property(&*(ptr.cast::<$ty>()), scope, this, key) + js_get_property: |ptr, this, key, scope| unsafe { + <$ty as Object>::get_property(&*(ptr.cast::<$ty>()), this, key, scope) }, - js_get_property_descriptor: |ptr, scope, key| unsafe { - <$ty as Object>::get_property_descriptor(&*(ptr.cast::<$ty>()), scope, key) + js_get_property_descriptor: |ptr, key, scope| unsafe { + <$ty as Object>::get_property_descriptor(&*(ptr.cast::<$ty>()), key, scope) }, - js_set_property: |ptr, scope, key, value| unsafe { - <$ty as Object>::set_property(&*(ptr.cast::<$ty>()), scope, key, value) + js_set_property: |ptr, key, value, scope| unsafe { + <$ty as Object>::set_property(&*(ptr.cast::<$ty>()), key, value, scope) }, - js_delete_property: |ptr, scope, key| unsafe { - <$ty as Object>::delete_property(&*(ptr.cast::<$ty>()), scope, key) + js_delete_property: |ptr, key, scope| unsafe { + <$ty as Object>::delete_property(&*(ptr.cast::<$ty>()), key, scope) }, - js_set_prototype: |ptr, scope, proto| unsafe { - <$ty as Object>::set_prototype(&*(ptr.cast::<$ty>()), scope, proto) + js_set_prototype: |ptr, proto, scope| unsafe { + <$ty as Object>::set_prototype(&*(ptr.cast::<$ty>()), proto, scope) }, js_get_prototype: |ptr, scope| unsafe { <$ty as Object>::get_prototype(&*(ptr.cast::<$ty>()), scope) }, - js_apply: |ptr, scope, callee, this, args| unsafe { - <$ty as Object>::apply(&*(ptr.cast::<$ty>()), scope, callee, this, args) + js_apply: |ptr, callee, this, args, scope| unsafe { + <$ty as Object>::apply(&*(ptr.cast::<$ty>()), callee, this, args, scope) }, - js_construct: |ptr, scope, callee, this, args, new_target| unsafe { - <$ty as Object>::construct(&*(ptr.cast::<$ty>()), scope, callee, this, args, new_target) + js_construct: |ptr, callee, this, args, new_target, scope| unsafe { + <$ty as Object>::construct(&*(ptr.cast::<$ty>()), callee, this, args, new_target, scope) }, js_internal_slots: |ptr, vm| unsafe { <$ty as Object>::internal_slots(&*(ptr.cast::<$ty>()), vm) diff --git a/crates/dash_vm/src/js_std/array.rs b/crates/dash_vm/src/js_std/array.rs index 3a596a90..d7ed2177 100644 --- a/crates/dash_vm/src/js_std/array.rs +++ b/crates/dash_vm/src/js_std/array.rs @@ -47,7 +47,7 @@ fn join_inner(sc: &mut LocalScope, array: Value, separator: JsString) -> Result< } let i = sc.intern_usize(i); - let element = array.get_property(sc, i.into()).root(sc)?; + let element = array.get_property(i.into(), sc).root(sc)?; if !element.is_nullish() { let s = element.to_js_string(sc)?; result.push_str(s.res(sc)); @@ -65,7 +65,7 @@ fn for_each_element( let len = this.length_of_array_like(scope)?; for k in 0..len { let pk = scope.intern_usize(k); - if let Some(value) = this.get_property_descriptor(scope, pk.into()).root_err(scope)? { + if let Some(value) = this.get_property_descriptor(pk.into(), scope).root_err(scope)? { let value = value.get_or_apply(scope, This::Bound(this)).root(scope)?; if let Break(value) = f(scope, value, Value::number(k as f64))? { return Ok(Break(value)); @@ -104,7 +104,7 @@ pub fn at(cx: CallContext) -> Result { } let index = cx.scope.intern_usize(index as usize); - this.get_property(cx.scope, index.into()).root(cx.scope) + this.get_property(index.into(), cx.scope).root(cx.scope) } pub fn concat(cx: CallContext) -> Result { @@ -116,7 +116,7 @@ pub fn concat(cx: CallContext) -> Result { let len = arg.length_of_array_like(cx.scope)?; for i in 0..len { let i = cx.scope.intern_usize(i); - let element = arg.get_property(cx.scope, i.into()).root(cx.scope)?; + let element = arg.get_property(i.into(), cx.scope).root(cx.scope)?; array.push(PropertyValue::static_default(element)); } } @@ -144,7 +144,7 @@ pub fn every(cx: CallContext) -> Result { let all_true = for_each_element(cx.scope, this, |scope, elem, idx| { if callback - .apply(scope, This::Bound(cb_this), [elem, idx, this].into()) + .apply(This::Bound(cb_this), [elem, idx, this].into(), scope) .root(scope)? .to_boolean(scope)? { @@ -168,7 +168,7 @@ pub fn some(cx: CallContext) -> Result { let any_true = for_each_element(cx.scope, this, |scope, elem, idx| { if callback - .apply(scope, This::Bound(cb_this), [elem, idx, this].into()) + .apply(This::Bound(cb_this), [elem, idx, this].into(), scope) .root(scope)? .to_boolean(scope)? { @@ -226,7 +226,7 @@ pub fn filter(cx: CallContext) -> Result { let (Break(()) | Continue(())) = for_each_element(cx.scope, this, |scope, elem, idx| { if callback - .apply(scope, This::Bound(cb_this), [elem, idx, this].into()) + .apply(This::Bound(cb_this), [elem, idx, this].into(), scope) .root(scope)? .to_boolean(scope)? { @@ -251,22 +251,22 @@ pub fn reduce(cx: CallContext) -> Result { (0, Some(_)) => return Ok(initial_value.unwrap()), (_, Some(initial)) => (0, initial), (1, None) => { - let pkv = this.get_property(cx.scope, sym::zero.into()).root(cx.scope)?; + let pkv = this.get_property(sym::zero.into(), cx.scope).root(cx.scope)?; return Ok(pkv); } (_, None) => { - let pkv = this.get_property(cx.scope, sym::zero.into()).root(cx.scope)?; - let pkv2 = this.get_property(cx.scope, sym::one.into()).root(cx.scope)?; + let pkv = this.get_property(sym::zero.into(), cx.scope).root(cx.scope)?; + let pkv2 = this.get_property(sym::one.into(), cx.scope).root(cx.scope)?; let args = [pkv, pkv2, Value::number(1_f64)].into(); - (2, callback.apply(cx.scope, This::Default, args).root(cx.scope)?) + (2, callback.apply(This::Default, args, cx.scope).root(cx.scope)?) } }; for k in start..len { let pk = cx.scope.intern_usize(k); - let pkv = this.get_property(cx.scope, pk.into()).root(cx.scope)?; + let pkv = this.get_property(pk.into(), cx.scope).root(cx.scope)?; let args = [accumulator, pkv, Value::number(k as f64), this].into(); - accumulator = callback.apply(cx.scope, This::Default, args).root(cx.scope)?; + accumulator = callback.apply(This::Default, args, cx.scope).root(cx.scope)?; } Ok(accumulator) @@ -282,7 +282,7 @@ pub fn find(cx: CallContext) -> Result { let element = for_each_element(cx.scope, this, |scope, elem, idx| { if callback - .apply(scope, This::Bound(cb_this), [elem, idx, this].into()) + .apply(This::Bound(cb_this), [elem, idx, this].into(), scope) .root(scope)? .to_boolean(scope)? { @@ -308,7 +308,7 @@ pub fn find_index(cx: CallContext) -> Result { let element = for_each_element(cx.scope, this, |scope, elem, idx| { if callback - .apply(scope, This::Bound(cb_this), [elem, idx, this].into()) + .apply(This::Bound(cb_this), [elem, idx, this].into(), scope) .root(scope)? .to_boolean(scope)? { @@ -338,7 +338,7 @@ pub fn for_each(cx: CallContext) -> Result { let (Break(()) | Continue(())) = for_each_element(cx.scope, this, |scope, elem, idx| { callback - .apply(scope, This::Bound(cb_this), [elem, idx, this].into()) + .apply(This::Bound(cb_this), [elem, idx, this].into(), scope) .root_err(scope)?; Ok(Continue(())) })?; @@ -353,7 +353,7 @@ pub fn includes(cx: CallContext) -> Result { for k in 0..len { let pk = cx.scope.intern_usize(k); - let pkv = this.get_property(cx.scope, pk.into()).root(cx.scope)?; + let pkv = this.get_property(pk.into(), cx.scope).root(cx.scope)?; if strict_eq(pkv, search_element) { return Ok(true.into()); } @@ -385,7 +385,7 @@ pub fn index_of(cx: CallContext) -> Result { for k in from_index..len { let pk = cx.scope.intern_usize(k); - let pkv = this.get_property(cx.scope, pk.into()).root(cx.scope)?; + let pkv = this.get_property(pk.into(), cx.scope).root(cx.scope)?; if strict_eq(pkv, search_element) { return Ok(Value::number(k as f64)); } @@ -417,7 +417,7 @@ pub fn last_index_of(cx: CallContext) -> Result { for k in (0..=from_index).rev() { let pk = cx.scope.intern_usize(k); - let pkv = this.get_property(cx.scope, pk.into()).root(cx.scope)?; + let pkv = this.get_property(pk.into(), cx.scope).root(cx.scope)?; if strict_eq(pkv, search_element) { return Ok(Value::number(k as f64)); } @@ -437,7 +437,7 @@ pub fn map(cx: CallContext) -> Result { let (Break(()) | Continue(())) = for_each_element(cx.scope, this, |scope, elem, idx| { let mapped = callback - .apply(scope, This::Bound(cb_this), [elem, idx, this].into()) + .apply(This::Bound(cb_this), [elem, idx, this].into(), scope) .root(scope)?; values.push(PropertyValue::static_default(mapped)); Ok(Continue(())) @@ -458,11 +458,11 @@ pub fn pop(cx: CallContext) -> Result { let new_len = len - 1; let new_len_sym = cx.scope.intern_usize(len - 1); - let value = this.delete_property(cx.scope, new_len_sym.into())?.root(cx.scope); + let value = this.delete_property(new_len_sym.into(), cx.scope)?.root(cx.scope); this.set_property( - cx.scope, sym::length.into(), PropertyValue::static_default(Value::number(new_len as f64)), + cx.scope, )?; Ok(value) @@ -476,7 +476,7 @@ pub fn push(cx: CallContext) -> Result { if cx.args.is_empty() { let len = cx.scope.intern_usize(len); - this.set_property(cx.scope, len.into(), PropertyValue::static_default(Value::undefined()))?; + this.set_property(len.into(), PropertyValue::static_default(Value::undefined()), cx.scope)?; } for (idx, arg) in cx.args.into_iter().enumerate() { @@ -494,11 +494,11 @@ pub fn reverse(cx: CallContext) -> Result { // Strategy: Given [1,2,3,4,5], swap `i` with `len - i - 1` for every index `i` in `0..len / 2` for k in 0..len / 2 { let pk = cx.scope.intern_usize(k); - let pkv = this.get_property(cx.scope, pk.into()).root(cx.scope)?; + let pkv = this.get_property(pk.into(), cx.scope).root(cx.scope)?; let pk2 = cx.scope.intern_usize(len - k - 1); - let pk2v = this.get_property(cx.scope, pk2.into()).root(cx.scope)?; - this.set_property(cx.scope, pk.into(), PropertyValue::static_default(pk2v))?; - this.set_property(cx.scope, pk2.into(), PropertyValue::static_default(pkv))?; + let pk2v = this.get_property(pk2.into(), cx.scope).root(cx.scope)?; + this.set_property(pk.into(), PropertyValue::static_default(pk2v), cx.scope)?; + this.set_property(pk2.into(), PropertyValue::static_default(pkv), cx.scope)?; } Ok(this) @@ -512,19 +512,19 @@ pub fn shift(cx: CallContext) -> Result { return Ok(Value::undefined()); } - let prop = this.delete_property(cx.scope, sym::zero.into())?.root(cx.scope); + let prop = this.delete_property(sym::zero.into(), cx.scope)?.root(cx.scope); for k in 1..len { let pk = cx.scope.intern_usize(k); let prev_pk = cx.scope.intern_usize(k - 1); - let pkv = this.get_property(cx.scope, pk.into()).root(cx.scope)?; - this.set_property(cx.scope, prev_pk.into(), PropertyValue::static_default(pkv))?; + let pkv = this.get_property(pk.into(), cx.scope).root(cx.scope)?; + this.set_property(prev_pk.into(), PropertyValue::static_default(pkv), cx.scope)?; } this.set_property( - cx.scope, sym::length.into(), PropertyValue::static_default(Value::number((len - 1) as f64)), + cx.scope, )?; Ok(prop) @@ -552,9 +552,9 @@ fn shift_array( // Technically this isn't needed, and we can just let the array grow as needed, but this is for clarity if range.end + shift_by > len as isize { arr.set_property( - scope, sym::length.into(), PropertyValue::static_default(Value::number(new_len as f64)), + scope, )?; } @@ -562,17 +562,17 @@ fn shift_array( for k in range { let pk = scope.intern_isize(k); let shift_pk = scope.intern_isize(k + shift_by); - let pkv = arr.get_property(scope, pk.into()).root(scope)?; - arr.set_property(scope, shift_pk.into(), PropertyValue::static_default(pkv))?; + let pkv = arr.get_property(pk.into(), scope).root(scope)?; + arr.set_property(shift_pk.into(), PropertyValue::static_default(pkv), scope)?; } // If the shift_by is negative, we need to delete the remaining elements at the end that were shifted // This must be done after the shifting, otherwise we would be deleting elements before they can be shifted if shift_by < 0 { arr.set_property( - scope, sym::length.into(), PropertyValue::static_default(Value::number(new_len as f64)), + scope, )?; } @@ -589,7 +589,7 @@ pub fn unshift(cx: CallContext) -> Result { for (idx, arg) in cx.args.into_iter().enumerate() { let idx = cx.scope.intern_usize(idx); - this.set_property(cx.scope, idx.into(), PropertyValue::static_default(arg))?; + this.set_property(idx.into(), PropertyValue::static_default(arg), cx.scope)?; } Ok(Value::number(new_len as f64)) @@ -625,7 +625,7 @@ pub fn slice(cx: CallContext) -> Result { for k in start..end { let pk = cx.scope.intern_usize(k); - let pkv = this.get_property(cx.scope, pk.into()).root(cx.scope)?; + let pkv = this.get_property(pk.into(), cx.scope).root(cx.scope)?; values.push(PropertyValue::static_default(pkv)); } @@ -650,14 +650,14 @@ pub fn for_each_js_iterator_element, Value) -> R iter: Value, mut f: F, ) -> Result, Value> { - let next = iter.get_property(scope, sym::next.into()).root(scope)?; + let next = iter.get_property(sym::next.into(), scope).root(scope)?; loop { - let item = next.apply(scope, This::Bound(iter), CallArgs::empty()).root(scope)?; - let done = item.get_property(scope, sym::done.into()).root(scope)?.is_truthy(scope); + let item = next.apply(This::Bound(iter), CallArgs::empty(), scope).root(scope)?; + let done = item.get_property(sym::done.into(), scope).root(scope)?.is_truthy(scope); if done { break; } - let value = item.get_property(scope, sym::value.into()).root(scope)?; + let value = item.get_property(sym::value.into(), scope).root(scope)?; if let Break(val) = f(scope, value)? { return Ok(Break(val)); } @@ -672,7 +672,7 @@ pub fn from(cx: CallContext) -> Result { for_each_js_iterator_element(scope, items, |scope, value| { let value = match &mapper { - Some(mapper) => mapper.apply(scope, This::Default, [value].into()).root(scope)?, + Some(mapper) => mapper.apply(This::Default, [value].into(), scope).root(scope)?, None => value, }; values.push(PropertyValue::static_default(value)); @@ -690,9 +690,9 @@ pub fn from(cx: CallContext) -> Result { for i in 0..len { let i = scope.intern_usize(i); - let value = items.get_property(scope, i.into()).root(scope)?; + let value = items.get_property(i.into(), scope).root(scope)?; let value = match &mapper { - Some(mapper) => mapper.apply(scope, This::Default, [value].into()).root(scope)?, + Some(mapper) => mapper.apply(This::Default, [value].into(), scope).root(scope)?, None => value, }; values.push(PropertyValue::static_default(value)); @@ -710,7 +710,7 @@ pub fn from(cx: CallContext) -> Result { let items_iterator = { let iterator = cx.scope.statics.symbol_iterator; items - .get_property(cx.scope, iterator.into()) + .get_property(iterator.into(), cx.scope) .root(cx.scope)? .into_option() }; @@ -718,7 +718,7 @@ pub fn from(cx: CallContext) -> Result { match items_iterator { Some(iterator) => { let iterator = iterator - .apply(cx.scope, This::Bound(items), CallArgs::empty()) + .apply(This::Bound(items), CallArgs::empty(), cx.scope) .root(cx.scope)?; with_iterator(cx.scope, iterator, mapper) } @@ -748,16 +748,16 @@ pub fn sort(cx: CallContext) -> Result { let idx = cx.scope.intern_usize(j); let prev_idx = cx.scope.intern_usize(j - 1); - let previous = this.get_property(cx.scope, prev_idx.into()).root(cx.scope)?; - let current = this.get_property(cx.scope, idx.into()).root(cx.scope)?; + let previous = this.get_property(prev_idx.into(), cx.scope).root(cx.scope)?; + let current = this.get_property(idx.into(), cx.scope).root(cx.scope)?; let ordering = compare_fn - .apply(cx.scope, This::Default, [previous, current].into()) + .apply(This::Default, [previous, current].into(), cx.scope) .root(cx.scope)? .to_int32(cx.scope)?; if ordering > 0 { - this.set_property(cx.scope, prev_idx.into(), PropertyValue::static_default(current))?; - this.set_property(cx.scope, idx.into(), PropertyValue::static_default(previous))?; + this.set_property(prev_idx.into(), PropertyValue::static_default(current), cx.scope)?; + this.set_property(idx.into(), PropertyValue::static_default(previous), cx.scope)?; } else { break; } @@ -790,7 +790,7 @@ pub fn splice(mut cx: CallContext) -> Result { let from = cx.scope.intern_usize(start + k); if let Some(delete_value) = this - .get_property_descriptor(cx.scope, PropertyKey::String(from.into())) + .get_property_descriptor(PropertyKey::String(from.into()), cx.scope) .root_err(cx.scope)? { values.push(delete_value); @@ -802,9 +802,9 @@ pub fn splice(mut cx: CallContext) -> Result { for (i, value) in cx.args.iter().skip(2).enumerate() { let i = cx.scope.intern_usize(i + start); this.set_property( - cx.scope, PropertyKey::String(i.into()), PropertyValue::static_default(*value), + cx.scope, )?; } @@ -833,9 +833,9 @@ pub fn splice(mut cx: CallContext) -> Result { for (i, value) in cx.args.iter().skip(2).enumerate() { let i = cx.scope.intern_usize(i + start); this.set_property( - cx.scope, PropertyKey::String(i.into()), PropertyValue::static_default(*value), + cx.scope, )?; } } diff --git a/crates/dash_vm/src/js_std/array_iterator.rs b/crates/dash_vm/src/js_std/array_iterator.rs index a8a08570..7b5cf505 100644 --- a/crates/dash_vm/src/js_std/array_iterator.rs +++ b/crates/dash_vm/src/js_std/array_iterator.rs @@ -14,14 +14,14 @@ pub fn next(cx: CallContext) -> Result { let obj = NamedObject::new(cx.scope); obj.set_property( - cx.scope, sym::value.into(), PropertyValue::static_default(next.unwrap_or_undefined()), + cx.scope, )?; obj.set_property( - cx.scope, sym::done.into(), PropertyValue::static_default(Value::boolean(done)), + cx.scope, )?; Ok(cx.scope.register(obj).into()) diff --git a/crates/dash_vm/src/js_std/error.rs b/crates/dash_vm/src/js_std/error.rs index 30f9d596..ec11207d 100644 --- a/crates/dash_vm/src/js_std/error.rs +++ b/crates/dash_vm/src/js_std/error.rs @@ -49,7 +49,7 @@ pub fn error_constructor(cx: CallContext) -> Result { pub fn to_string(cx: CallContext) -> Result { cx.this - .get_property(cx.scope, sym::stack.into()) + .get_property(sym::stack.into(), cx.scope) .root(cx.scope) .and_then(|v| v.to_js_string(cx.scope).map(Value::string)) } diff --git a/crates/dash_vm/src/js_std/function.rs b/crates/dash_vm/src/js_std/function.rs index 4ca5fd59..be499902 100644 --- a/crates/dash_vm/src/js_std/function.rs +++ b/crates/dash_vm/src/js_std/function.rs @@ -23,7 +23,7 @@ pub fn apply(cx: CallContext) -> Result { for i in 0..array.length_of_array_like(cx.scope)? { let sym = cx.scope.intern_usize(i).into(); - let arg_i = array.get_property(cx.scope, sym).root(cx.scope)?; + let arg_i = array.get_property(sym, cx.scope).root(cx.scope)?; target_args.push(arg_i); } target_args @@ -39,9 +39,9 @@ pub fn apply(cx: CallContext) -> Result { target_callee .apply( - cx.scope, target_this.map_or(This::Default, This::Bound), target_args.into(), + cx.scope, ) .root(cx.scope) } @@ -68,9 +68,9 @@ pub fn call(cx: CallContext) -> Result { target_callee .apply( - cx.scope, target_this.map_or(This::Default, This::Bound), target_args.into(), + cx.scope, ) .root(cx.scope) } diff --git a/crates/dash_vm/src/js_std/generator.rs b/crates/dash_vm/src/js_std/generator.rs index d7788a9d..950b234c 100644 --- a/crates/dash_vm/src/js_std/generator.rs +++ b/crates/dash_vm/src/js_std/generator.rs @@ -110,11 +110,11 @@ pub fn next(cx: CallContext) -> Result { fn create_generator_value(scope: &mut LocalScope, done: bool, value: Option) -> Result { let obj = NamedObject::new(scope); - obj.set_property(scope, sym::done.into(), PropertyValue::static_default(done.into()))?; + obj.set_property(sym::done.into(), PropertyValue::static_default(done.into()), scope)?; obj.set_property( - scope, sym::value.into(), PropertyValue::static_default(value.unwrap_or_undefined()), + scope, )?; Ok(scope.register(obj).into()) } diff --git a/crates/dash_vm/src/js_std/map.rs b/crates/dash_vm/src/js_std/map.rs index 77346c3e..a710e385 100644 --- a/crates/dash_vm/src/js_std/map.rs +++ b/crates/dash_vm/src/js_std/map.rs @@ -21,13 +21,13 @@ pub fn constructor(cx: CallContext) -> Result { for i in 0..len { let i = cx.scope.intern_usize(i); let item = iter - .get_property(cx.scope, PropertyKey::String(i.into())) + .get_property(PropertyKey::String(i.into()), cx.scope) .root(cx.scope)?; let k = item - .get_property(cx.scope, PropertyKey::String(sym::zero.into())) + .get_property(PropertyKey::String(sym::zero.into()), cx.scope) .root(cx.scope)?; let v = item - .get_property(cx.scope, PropertyKey::String(sym::one.into())) + .get_property(PropertyKey::String(sym::one.into()), cx.scope) .root(cx.scope)?; map.set(k, v); } diff --git a/crates/dash_vm/src/js_std/object.rs b/crates/dash_vm/src/js_std/object.rs index aab87edc..bd76c5a6 100644 --- a/crates/dash_vm/src/js_std/object.rs +++ b/crates/dash_vm/src/js_std/object.rs @@ -28,7 +28,7 @@ pub fn create(cx: CallContext) -> Result { let new_target = cx.new_target.unwrap_or(cx.scope.statics.object_ctor); let obj = NamedObject::instance_for_new_target(new_target, cx.scope)?; - obj.set_prototype(cx.scope, prototype)?; + obj.set_prototype(prototype, cx.scope)?; // TODO: second argument: ObjectDefineProperties @@ -46,9 +46,9 @@ pub fn keys(cx: CallContext) -> Result { pub fn to_string(cx: CallContext) -> Result { fn to_string_inner(scope: &mut LocalScope<'_>, o: ObjectId) -> Result { let constructor = o - .get_property(scope, sym::constructor.into()) + .get_property(sym::constructor.into(), scope) .root(scope)? - .get_property(scope, sym::name.into()) + .get_property(sym::name.into(), scope) .root(scope)? .to_js_string(scope)?; @@ -82,7 +82,7 @@ pub fn get_own_property_descriptor(cx: CallContext) -> Result { let k = cx.args.get(1).unwrap_or_undefined(); let k = PropertyKey::from_value(cx.scope, k)?; - Ok(o.get_property_descriptor(cx.scope, k) + Ok(o.get_property_descriptor(k, cx.scope) .root_err(cx.scope)? .map(|d| d.to_descriptor_value(cx.scope)) .transpose()? @@ -106,7 +106,7 @@ pub fn get_own_property_descriptors(cx: CallContext) -> Result { for key in keys { let key = PropertyKey::from_value(cx.scope, key)?; let descriptor = o - .get_property_descriptor(cx.scope, key) + .get_property_descriptor(key, cx.scope) .root_err(cx.scope)? .map(|d| d.to_descriptor_value(cx.scope)) .transpose()? @@ -131,7 +131,7 @@ pub fn has_own_property(cx: CallContext) -> Result { let key = cx.args.first().unwrap_or_undefined(); let key = PropertyKey::from_value(cx.scope, key)?; - let desc = o.get_property_descriptor(cx.scope, key).root_err(cx.scope)?; + let desc = o.get_property_descriptor(key, cx.scope).root_err(cx.scope)?; Ok(Value::boolean(desc.is_some())) } @@ -162,7 +162,7 @@ pub fn define_property(cx: CallContext) -> Result { let value = PropertyValue::from_descriptor_value(cx.scope, Value::object(descriptor))?; - object.set_property(cx.scope, property, value)?; + object.set_property(property, value, cx.scope)?; Ok(Value::object(object)) } @@ -180,9 +180,9 @@ pub fn define_properties(cx: CallContext) -> Result { let properties = cx.args.get(1).unwrap_or_undefined(); for key in properties.own_keys(cx.scope)? { let key = key.to_js_string(cx.scope)?; - let descriptor = properties.get_property(cx.scope, key.into()).root(cx.scope)?; + let descriptor = properties.get_property(key.into(), cx.scope).root(cx.scope)?; let descriptor = PropertyValue::from_descriptor_value(cx.scope, descriptor)?; - object.set_property(cx.scope, key.into(), descriptor)?; + object.set_property(key.into(), descriptor, cx.scope)?; } Ok(Value::object(object)) @@ -195,8 +195,8 @@ pub fn assign(cx: CallContext) -> Result { let source = source.to_object(cx.scope)?; for key in source.own_keys(cx.scope)? { let key = PropertyKey::from_value(cx.scope, key)?; - let desc = source.get_own_property(cx.scope, key).root(cx.scope)?; - to.set_property(cx.scope, key, PropertyValue::static_default(desc))?; + let desc = source.get_own_property(key, cx.scope).root(cx.scope)?; + to.set_property(key, PropertyValue::static_default(desc), cx.scope)?; } } Ok(Value::object(to)) @@ -207,7 +207,7 @@ pub fn entries(cx: CallContext) -> Result { let obj = cx.args.first().unwrap_or_undefined().to_object(cx.scope)?; for key in obj.own_keys(cx.scope)? { let key = PropertyKey::from_value(cx.scope, key)?; - let value = obj.get_own_property(cx.scope, key).root(cx.scope)?; + let value = obj.get_own_property(key, cx.scope).root(cx.scope)?; let entry = Array::from_vec(cx.scope, vec![ PropertyValue::static_default(key.as_value()), PropertyValue::static_default(value), @@ -227,7 +227,7 @@ pub fn get_prototype_of(cx: CallContext) -> Result { pub fn set_prototype_of(cx: CallContext) -> Result { let obj = cx.args.first().unwrap_or_undefined().to_object(cx.scope)?; let target = cx.args.get(1).unwrap_or_undefined(); - obj.set_prototype(cx.scope, target)?; + obj.set_prototype(target, cx.scope)?; Ok(Value::object(obj)) } @@ -254,7 +254,7 @@ pub fn is_prototype_of(cx: CallContext) -> Result { pub fn property_is_enumerable(cx: CallContext) -> Result { let prop = PropertyKey::from_value(cx.scope, cx.args.first().unwrap_or_undefined())?; let obj = cx.this.to_object(cx.scope)?; - let desc = obj.get_own_property_descriptor(cx.scope, prop).root_err(cx.scope)?; + let desc = obj.get_own_property_descriptor(prop, cx.scope).root_err(cx.scope)?; Ok(Value::boolean(desc.is_some_and(|val| { val.descriptor.contains(PropertyDataDescriptor::ENUMERABLE) }))) @@ -263,7 +263,7 @@ pub fn property_is_enumerable(cx: CallContext) -> Result { pub fn freeze(cx: CallContext) -> Result { let arg = cx.args.first().unwrap_or_undefined(); if let ValueKind::Object(o) = arg.unpack() { - o.set_integrity_level(cx.scope, IntegrityLevel::Frozen)?; + o.set_integrity_level(IntegrityLevel::Frozen, cx.scope)?; Ok(Value::object(o)) } else { Ok(arg) @@ -273,7 +273,7 @@ pub fn freeze(cx: CallContext) -> Result { pub fn seal(cx: CallContext) -> Result { let arg = cx.args.first().unwrap_or_undefined(); if let ValueKind::Object(o) = arg.unpack() { - o.set_integrity_level(cx.scope, IntegrityLevel::Sealed)?; + o.set_integrity_level(IntegrityLevel::Sealed, cx.scope)?; Ok(Value::object(o)) } else { Ok(arg) diff --git a/crates/dash_vm/src/js_std/promise.rs b/crates/dash_vm/src/js_std/promise.rs index 69796144..948a79e0 100644 --- a/crates/dash_vm/src/js_std/promise.rs +++ b/crates/dash_vm/src/js_std/promise.rs @@ -2,6 +2,7 @@ use dash_proc_macro::Trace; use crate::frame::This; use crate::gc::ObjectId; +use crate::localscope::LocalScope; use crate::value::function::args::CallArgs; use crate::value::function::bound::BoundFunction; use crate::value::function::native::CallContext; @@ -36,9 +37,9 @@ pub fn constructor(cx: CallContext) -> Result { initiator .apply( - cx.scope, This::Default, [Value::object(resolve), Value::object(reject)].into(), + cx.scope, ) .root_err(cx.scope)?; @@ -128,19 +129,19 @@ impl Object for ThenTask { fn apply( &self, - scope: &mut crate::localscope::LocalScope, _callee: ObjectId, _this: This, args: CallArgs, + scope: &mut LocalScope<'_>, ) -> Result { let resolved = args.first().unwrap_or_undefined(); let ret = self .handler - .apply(scope, This::Default, [resolved].into()) + .apply(This::Default, [resolved].into(), scope) .root(scope)?; let ret_then = ret - .get_property(scope, PropertyKey::String(sym::then.into()))? + .get_property(PropertyKey::String(sym::then.into()), scope)? .root(scope); match ret_then.unpack() { @@ -152,7 +153,7 @@ impl Object for ThenTask { } _ => { // Is a promise. Call value.then(resolver) - ret_then.apply(scope, This::Bound(ret), [Value::object(self.resolver)].into())?; + ret_then.apply(This::Bound(ret), [Value::object(self.resolver)].into(), scope)?; } } diff --git a/crates/dash_vm/src/js_std/set.rs b/crates/dash_vm/src/js_std/set.rs index 6cb25c56..4fcf8ab8 100644 --- a/crates/dash_vm/src/js_std/set.rs +++ b/crates/dash_vm/src/js_std/set.rs @@ -20,7 +20,7 @@ pub fn constructor(cx: CallContext) -> Result { for i in 0..len { let i = cx.scope.intern_usize(i); let item = iter - .get_property(cx.scope, PropertyKey::String(i.into())) + .get_property(PropertyKey::String(i.into()), cx.scope) .root(cx.scope)?; set.add(item); diff --git a/crates/dash_vm/src/js_std/typedarray.rs b/crates/dash_vm/src/js_std/typedarray.rs index cd9f1e99..35c93498 100644 --- a/crates/dash_vm/src/js_std/typedarray.rs +++ b/crates/dash_vm/src/js_std/typedarray.rs @@ -40,12 +40,12 @@ fn typedarray_constructor(cx: CallContext, kind: TypedArrayKind) -> Result Result { for i in 0..len { let i = cx.scope.intern_usize(i); let item = iter - .get_property(cx.scope, PropertyKey::String(i.into())) + .get_property(PropertyKey::String(i.into()), cx.scope) .root(cx.scope)?; let k = item - .get_property(cx.scope, PropertyKey::String(sym::zero.into())) + .get_property(PropertyKey::String(sym::zero.into()), cx.scope) .root(cx.scope)?; let v = item - .get_property(cx.scope, PropertyKey::String(sym::one.into())) + .get_property(PropertyKey::String(sym::one.into()), cx.scope) .root(cx.scope)?; weakmap.set(k, v); } diff --git a/crates/dash_vm/src/js_std/weakset.rs b/crates/dash_vm/src/js_std/weakset.rs index 8adc1eed..348661b0 100644 --- a/crates/dash_vm/src/js_std/weakset.rs +++ b/crates/dash_vm/src/js_std/weakset.rs @@ -20,7 +20,7 @@ pub fn constructor(cx: CallContext) -> Result { for i in 0..len { let i = cx.scope.intern_usize(i); let item = iter - .get_property(cx.scope, PropertyKey::String(i.into())) + .get_property(PropertyKey::String(i.into()), cx.scope) .root(cx.scope)?; weakset.add(item); diff --git a/crates/dash_vm/src/lib.rs b/crates/dash_vm/src/lib.rs index 58956bdc..61c63c08 100644 --- a/crates/dash_vm/src/lib.rs +++ b/crates/dash_vm/src/lib.rs @@ -153,8 +153,8 @@ impl Vm { // LocalScope needs to be the last parameter because we don't have two phase borrows in user code scope: &mut LocalScope<'_>, ) -> ObjectId { - base.set_property(scope, sym::constructor.into(), PropertyValue::static_non_enumerable(constructor.into())).unwrap(); - base.set_prototype(scope, prototype.into()).unwrap(); + base.set_property(sym::constructor.into(), PropertyValue::static_non_enumerable(constructor.into()),scope).unwrap(); + base.set_prototype(prototype.into(),scope).unwrap(); for (key, value) in methods { register( @@ -167,7 +167,7 @@ impl Vm { None, scope, ); - base.set_property(scope, key.into(), PropertyValue::static_non_enumerable(value.into())).unwrap(); + base.set_property(key.into(), PropertyValue::static_non_enumerable(value.into()), scope).unwrap(); } for (key, value) in symbols { @@ -181,7 +181,7 @@ impl Vm { None, scope, ); - base.set_property(scope, key.into(), PropertyValue::static_empty(value.into())).unwrap(); + base.set_property(key.into(), PropertyValue::static_empty(value.into()), scope).unwrap(); } for (key, value, descriptor) in fields { @@ -189,7 +189,7 @@ impl Vm { kind: PropertyValueKind::Static(value), descriptor: descriptor.unwrap_or_default() }; - base.set_property(scope, key.into(), value).unwrap(); + base.set_property(key.into(), value, scope).unwrap(); } if let Some((proto_name, proto_val)) = fn_prototype { @@ -1440,7 +1440,7 @@ impl Vm { scope.add_ref(task); debug!("process task {:?}", task); - if let Err(ex) = task.apply(&mut scope, This::Default, CallArgs::empty()) { + if let Err(ex) = task.apply(This::Default, CallArgs::empty(),&mut scope) { if let Some(callback) = scope.params.unhandled_task_exception_callback() { let ex = ex.root(&mut scope); error!("uncaught async task exception"); diff --git a/crates/dash_vm/src/test/mod.rs b/crates/dash_vm/src/test/mod.rs index f5ef4a3e..1d7e8586 100644 --- a/crates/dash_vm/src/test/mod.rs +++ b/crates/dash_vm/src/test/mod.rs @@ -120,7 +120,7 @@ fn simple() { .root(&mut scope); scope.perform_gc(); let value = array - .get_property(&mut scope, sym::zero.into()) + .get_property(sym::zero.into(), &mut scope) .unwrap() .root(&mut scope); assert_eq!(scope.stack.len(), 0); @@ -142,9 +142,9 @@ fn persistent_trace() { let key = scope.intern("foo"); object .set_property( - &mut scope, key.into(), PropertyValue::static_default(Value::object(dummy_string)), + &mut scope, ) .unwrap(); scope.register(object) diff --git a/crates/dash_vm/src/value/array/mod.rs b/crates/dash_vm/src/value/array/mod.rs index 06c8d17e..7fe0a6e3 100644 --- a/crates/dash_vm/src/value/array/mod.rs +++ b/crates/dash_vm/src/value/array/mod.rs @@ -215,8 +215,8 @@ impl Array { impl Object for Array { fn get_own_property_descriptor( &self, - sc: &mut LocalScope, key: PropertyKey, + sc: &mut LocalScope, ) -> Result, Unrooted> { let items = self.items.borrow(); @@ -240,10 +240,10 @@ impl Object for Array { } } - self.obj.get_property_descriptor(sc, key) + self.obj.get_property_descriptor(key, sc) } - fn set_property(&self, sc: &mut LocalScope, key: PropertyKey, value: PropertyValue) -> Result<(), Value> { + fn set_property(&self, key: PropertyKey, value: PropertyValue, sc: &mut LocalScope) -> Result<(), Value> { if let PropertyKey::String(key) = &key { if key.sym() == sym::length { // TODO: this shouldnt be undefined @@ -265,10 +265,10 @@ impl Object for Array { } } - self.obj.set_property(sc, key, value) + self.obj.set_property(key, value, sc) } - fn delete_property(&self, sc: &mut LocalScope, key: PropertyKey) -> Result { + fn delete_property(&self, key: PropertyKey, sc: &mut LocalScope) -> Result { if let PropertyKey::String(key) = &key { if key.sym() == sym::length { return Ok(Unrooted::new(Value::undefined())); @@ -287,21 +287,21 @@ impl Object for Array { } } - self.obj.delete_property(sc, key) + self.obj.delete_property(key, sc) } fn apply( &self, - scope: &mut LocalScope, callee: ObjectId, this: This, args: CallArgs, + scope: &mut LocalScope, ) -> Result { - self.obj.apply(scope, callee, this, args) + self.obj.apply(callee, this, args, scope) } - fn set_prototype(&self, sc: &mut LocalScope, value: Value) -> Result<(), Value> { - self.obj.set_prototype(sc, value) + fn set_prototype(&self, value: Value, sc: &mut LocalScope) -> Result<(), Value> { + self.obj.set_prototype(value, sc) } fn get_prototype(&self, sc: &mut LocalScope) -> Result { @@ -340,12 +340,12 @@ impl Object for ArrayIterator { fn apply( &self, - scope: &mut LocalScope, callee: ObjectId, this: This, args: CallArgs, + scope: &mut LocalScope, ) -> Result { - self.obj.apply(scope, callee, this, args) + self.obj.apply(callee, this, args, scope) } extract!(self); @@ -381,7 +381,7 @@ impl ArrayIterator { if index < self.length { self.index.set(index + 1); let index = sc.intern_usize(index); - self.value.get_property(sc, index.into()).map(Some) + self.value.get_property(index.into(), sc).map(Some) } else { Ok(None) } @@ -411,7 +411,7 @@ pub fn spec_array_get_property(scope: &mut LocalScope<'_>, target: &Value, index } let index = scope.intern_usize(index); - match target.get_property(scope, index.into()) { + match target.get_property(index.into(), scope) { Ok(v) => Ok(v), Err(v) => Ok(v), } @@ -437,5 +437,5 @@ pub fn spec_array_set_property( } let index = scope.intern_usize(index); - target.set_property(scope, index.into(), value) + target.set_property(index.into(), value, scope) } diff --git a/crates/dash_vm/src/value/arraybuffer.rs b/crates/dash_vm/src/value/arraybuffer.rs index 5e6370ca..72697e85 100644 --- a/crates/dash_vm/src/value/arraybuffer.rs +++ b/crates/dash_vm/src/value/arraybuffer.rs @@ -77,12 +77,12 @@ impl Object for ArrayBuffer { fn apply( &self, - scope: &mut LocalScope, callee: ObjectId, this: This, args: CallArgs, + scope: &mut LocalScope, ) -> Result { - self.obj.apply(scope, callee, this, args) + self.obj.apply(callee, this, args, scope) } extract!(self); diff --git a/crates/dash_vm/src/value/boxed.rs b/crates/dash_vm/src/value/boxed.rs index 2928790c..0e3034ad 100644 --- a/crates/dash_vm/src/value/boxed.rs +++ b/crates/dash_vm/src/value/boxed.rs @@ -49,14 +49,14 @@ macro_rules! boxed_primitive { fn get_own_property_descriptor( &self, - sc: &mut LocalScope, key: PropertyKey, + sc: &mut LocalScope, ) -> Result, Unrooted> { - if let Some(x) = self.inner.get_own_property_descriptor(sc, key.clone())? { + if let Some(x) = self.inner.get_own_property_descriptor(key.clone(), sc)? { return Ok(Some(x)); } - return self.obj.get_own_property_descriptor(sc, key); + return self.obj.get_own_property_descriptor(key, sc); } fn internal_slots(&self, _: &Vm) -> Option<&dyn InternalSlots> { diff --git a/crates/dash_vm/src/value/error.rs b/crates/dash_vm/src/value/error.rs index 5ece0aeb..edac9451 100644 --- a/crates/dash_vm/src/value/error.rs +++ b/crates/dash_vm/src/value/error.rs @@ -82,8 +82,8 @@ impl Error { impl Object for Error { fn get_own_property_descriptor( &self, - sc: &mut LocalScope, key: PropertyKey, + sc: &mut LocalScope, ) -> Result, Unrooted> { match key { PropertyKey::String(s) if s.sym() == sym::name => { @@ -95,32 +95,32 @@ impl Object for Error { PropertyKey::String(s) if s.sym() == sym::stack => { Ok(Some(PropertyValue::static_default(Value::string(self.stack)))) } - _ => self.obj.get_property_descriptor(sc, key), + _ => self.obj.get_property_descriptor(key, sc), } } - fn set_property(&self, sc: &mut LocalScope, key: PropertyKey, value: PropertyValue) -> Result<(), Value> { + fn set_property(&self, key: PropertyKey, value: PropertyValue, sc: &mut LocalScope) -> Result<(), Value> { // TODO: this should special case name/stack - self.obj.set_property(sc, key, value) + self.obj.set_property(key, value, sc) } - fn delete_property(&self, sc: &mut LocalScope, key: PropertyKey) -> Result { + fn delete_property(&self, key: PropertyKey, sc: &mut LocalScope) -> Result { // TODO: delete/clear property - self.obj.delete_property(sc, key) + self.obj.delete_property(key, sc) } fn apply( &self, - scope: &mut LocalScope, callee: ObjectId, this: This, args: CallArgs, + scope: &mut LocalScope, ) -> Result { - self.obj.apply(scope, callee, this, args) + self.obj.apply(callee, this, args, scope) } - fn set_prototype(&self, sc: &mut LocalScope, value: Value) -> Result<(), Value> { - self.obj.set_prototype(sc, value) + fn set_prototype(&self, value: Value, sc: &mut LocalScope) -> Result<(), Value> { + self.obj.set_prototype(value, sc) } fn get_prototype(&self, sc: &mut LocalScope) -> Result { diff --git a/crates/dash_vm/src/value/function/async.rs b/crates/dash_vm/src/value/function/async.rs index fdb38a1b..e8400027 100644 --- a/crates/dash_vm/src/value/function/async.rs +++ b/crates/dash_vm/src/value/function/async.rs @@ -42,11 +42,11 @@ impl AsyncFunction { .statics .generator_iterator_next .clone() - .apply(scope, This::Bound(generator_iter), CallArgs::empty()) + .apply(This::Bound(generator_iter), CallArgs::empty(), scope) .root(scope) .and_then(|result| { result - .get_property(scope, PropertyKey::String(sym::value.into())) + .get_property(PropertyKey::String(sym::value.into()), scope) .root(scope) }); @@ -75,12 +75,12 @@ impl AsyncFunction { .promise_then .clone() .apply( - scope, This::Bound(match result { Ok(value) => value, Err(value) => value, }), [Value::object(then_task)].into(), + scope, ) .root_err(scope)?; @@ -127,10 +127,10 @@ impl Object for ThenTask { fn apply( &self, - scope: &mut LocalScope, _callee: ObjectId, _this: This, args: CallArgs, + scope: &mut LocalScope, ) -> Result { let promise_value = args.first().unwrap_or_undefined(); @@ -140,11 +140,11 @@ impl Object for ThenTask { .statics .generator_iterator_next .clone() - .apply(scope, This::Bound(self.generator_iter), [promise_value].into()) + .apply(This::Bound(self.generator_iter), [promise_value].into(), scope) .root(scope) .and_then(|result| { result - .get_property(scope, PropertyKey::String(sym::value.into())) + .get_property(PropertyKey::String(sym::value.into()), scope) .root(scope) }); @@ -175,9 +175,9 @@ impl Object for ThenTask { let value = wrap_promise(scope, value); scope.statics.promise_then.clone().apply( - scope, This::Bound(value), [Value::object(then_task)].into(), + scope, )?; } } diff --git a/crates/dash_vm/src/value/function/bound.rs b/crates/dash_vm/src/value/function/bound.rs index 31210636..288c1c0c 100644 --- a/crates/dash_vm/src/value/function/bound.rs +++ b/crates/dash_vm/src/value/function/bound.rs @@ -2,6 +2,7 @@ use dash_proc_macro::Trace; use crate::frame::This; use crate::gc::ObjectId; +use crate::localscope::LocalScope; use crate::value::object::{NamedObject, Object}; use crate::value::{Typeof, Unrooted, Value}; use crate::{Vm, delegate, extract}; @@ -42,17 +43,17 @@ impl Object for BoundFunction { fn apply( &self, - scope: &mut crate::localscope::LocalScope, _callee: ObjectId, this: This, args: CallArgs, + scope: &mut LocalScope, ) -> Result { let target_this = self.this.map_or(this, This::Bound); let mut target_args = self.args.clone(); target_args.extend(args); - self.callee.apply(scope, target_this, target_args) + self.callee.apply(target_this, target_args, scope) } fn type_of(&self, _: &Vm) -> Typeof { diff --git a/crates/dash_vm/src/value/function/generator.rs b/crates/dash_vm/src/value/function/generator.rs index 1a8ef9a6..b6043b98 100644 --- a/crates/dash_vm/src/value/function/generator.rs +++ b/crates/dash_vm/src/value/function/generator.rs @@ -162,12 +162,12 @@ impl Object for GeneratorIterator { fn apply( &self, - scope: &mut LocalScope, callee: ObjectId, this: This, args: CallArgs, + scope: &mut LocalScope, ) -> Result { - self.obj.apply(scope, callee, this, args) + self.obj.apply(callee, this, args, scope) } fn type_of(&self, _: &Vm) -> Typeof { diff --git a/crates/dash_vm/src/value/function/mod.rs b/crates/dash_vm/src/value/function/mod.rs index 18e7326b..3551b752 100755 --- a/crates/dash_vm/src/value/function/mod.rs +++ b/crates/dash_vm/src/value/function/mod.rs @@ -181,7 +181,7 @@ fn handle_call( pub fn this_for_new_target(scope: &mut LocalScope<'_>, new_target: ObjectId) -> Result { let ValueKind::Object(prototype) = new_target - .get_property(scope, sym::prototype.into()) + .get_property(sym::prototype.into(), scope) .root(scope)? .unpack() else { @@ -196,8 +196,8 @@ pub fn this_for_new_target(scope: &mut LocalScope<'_>, new_target: ObjectId) -> impl Object for Function { fn get_own_property_descriptor( &self, - sc: &mut LocalScope, key: PropertyKey, + sc: &mut LocalScope, ) -> Result, Unrooted> { if let Some(key) = key.as_string() { match key.sym() { @@ -224,10 +224,10 @@ impl Object for Function { } } - self.obj.get_own_property_descriptor(sc, key) + self.obj.get_own_property_descriptor(key, sc) } - fn set_property(&self, sc: &mut LocalScope, key: PropertyKey, value: PropertyValue) -> Result<(), Value> { + fn set_property(&self, key: PropertyKey, value: PropertyValue, sc: &mut LocalScope) -> Result<(), Value> { if let Some(sym::prototype) = key.as_string().map(JsString::sym) { let prototype = value.get_or_apply(sc, This::Default).root(sc)?; // TODO: function prototype does not need to be an object @@ -235,30 +235,30 @@ impl Object for Function { return Ok(()); } - self.obj.set_property(sc, key, value) + self.obj.set_property(key, value, sc) } - fn delete_property(&self, sc: &mut LocalScope, key: PropertyKey) -> Result { - self.obj.delete_property(sc, key) + fn delete_property(&self, key: PropertyKey, sc: &mut LocalScope) -> Result { + self.obj.delete_property(key, sc) } fn apply( &self, - scope: &mut LocalScope, callee: ObjectId, this: This, args: CallArgs, + scope: &mut LocalScope, ) -> Result { handle_call(self, scope, callee, this, args, None) } fn construct( &self, - scope: &mut LocalScope, callee: ObjectId, _this: This, args: CallArgs, new_target: ObjectId, + scope: &mut LocalScope, ) -> Result { let this = 'this: { if let Some(user) = self.inner_user_function() { @@ -280,8 +280,8 @@ impl Object for Function { handle_call(self, scope, callee, this, args, Some(new_target)) } - fn set_prototype(&self, sc: &mut LocalScope, value: Value) -> Result<(), Value> { - self.obj.set_prototype(sc, value) + fn set_prototype(&self, value: Value, sc: &mut LocalScope) -> Result<(), Value> { + self.obj.set_prototype(value, sc) } fn get_prototype(&self, sc: &mut LocalScope) -> Result { diff --git a/crates/dash_vm/src/value/mod.rs b/crates/dash_vm/src/value/mod.rs index 593cbb44..0ac054d0 100755 --- a/crates/dash_vm/src/value/mod.rs +++ b/crates/dash_vm/src/value/mod.rs @@ -221,57 +221,57 @@ unsafe impl Trace for Value { impl Object for Value { fn get_own_property_descriptor( &self, - sc: &mut LocalScope, key: PropertyKey, + sc: &mut LocalScope, ) -> Result, Unrooted> { match self.unpack() { - ValueKind::Number(n) => n.get_own_property_descriptor(sc, key), - ValueKind::Boolean(b) => b.get_own_property_descriptor(sc, key), - ValueKind::String(s) => s.get_own_property_descriptor(sc, key), - ValueKind::Undefined(u) => u.get_own_property_descriptor(sc, key), - ValueKind::Null(n) => n.get_own_property_descriptor(sc, key), - ValueKind::Symbol(s) => s.get_own_property_descriptor(sc, key), - ValueKind::Object(o) => o.get_own_property_descriptor(sc, key), - ValueKind::External(e) => e.get_own_property_descriptor(sc, key), + ValueKind::Number(n) => n.get_own_property_descriptor(key, sc), + ValueKind::Boolean(b) => b.get_own_property_descriptor(key, sc), + ValueKind::String(s) => s.get_own_property_descriptor(key, sc), + ValueKind::Undefined(u) => u.get_own_property_descriptor(key, sc), + ValueKind::Null(n) => n.get_own_property_descriptor(key, sc), + ValueKind::Symbol(s) => s.get_own_property_descriptor(key, sc), + ValueKind::Object(o) => o.get_own_property_descriptor(key, sc), + ValueKind::External(e) => e.get_own_property_descriptor(key, sc), } } - fn set_property(&self, sc: &mut LocalScope, key: PropertyKey, value: PropertyValue) -> Result<(), Value> { + fn set_property(&self, key: PropertyKey, value: PropertyValue, sc: &mut LocalScope) -> Result<(), Value> { match self.unpack() { - ValueKind::Object(h) => h.set_property(sc, key, value), - ValueKind::Number(n) => n.set_property(sc, key, value), - ValueKind::Boolean(b) => b.set_property(sc, key, value), - ValueKind::String(s) => s.set_property(sc, key, value), - ValueKind::External(h) => h.set_property(sc, key, value), - ValueKind::Undefined(u) => u.set_property(sc, key, value), - ValueKind::Null(n) => n.set_property(sc, key, value), - ValueKind::Symbol(s) => s.set_property(sc, key, value), + ValueKind::Object(h) => h.set_property(key, value, sc), + ValueKind::Number(n) => n.set_property(key, value, sc), + ValueKind::Boolean(b) => b.set_property(key, value, sc), + ValueKind::String(s) => s.set_property(key, value, sc), + ValueKind::External(h) => h.set_property(key, value, sc), + ValueKind::Undefined(u) => u.set_property(key, value, sc), + ValueKind::Null(n) => n.set_property(key, value, sc), + ValueKind::Symbol(s) => s.set_property(key, value, sc), } } - fn delete_property(&self, sc: &mut LocalScope, key: PropertyKey) -> Result { + fn delete_property(&self, key: PropertyKey, sc: &mut LocalScope) -> Result { match self.unpack() { - ValueKind::Object(o) => o.delete_property(sc, key), - ValueKind::Number(n) => n.delete_property(sc, key), - ValueKind::Boolean(b) => b.delete_property(sc, key), - ValueKind::String(s) => s.delete_property(sc, key), - ValueKind::External(o) => o.delete_property(sc, key), - ValueKind::Undefined(u) => u.delete_property(sc, key), - ValueKind::Null(n) => n.delete_property(sc, key), - ValueKind::Symbol(s) => s.delete_property(sc, key), + ValueKind::Object(o) => o.delete_property(key, sc), + ValueKind::Number(n) => n.delete_property(key, sc), + ValueKind::Boolean(b) => b.delete_property(key, sc), + ValueKind::String(s) => s.delete_property(key, sc), + ValueKind::External(o) => o.delete_property(key, sc), + ValueKind::Undefined(u) => u.delete_property(key, sc), + ValueKind::Null(n) => n.delete_property(key, sc), + ValueKind::Symbol(s) => s.delete_property(key, sc), } } - fn set_prototype(&self, sc: &mut LocalScope, value: Value) -> Result<(), Value> { + fn set_prototype(&self, value: Value, sc: &mut LocalScope) -> Result<(), Value> { match self.unpack() { - ValueKind::Number(n) => n.set_prototype(sc, value), - ValueKind::Boolean(b) => b.set_prototype(sc, value), - ValueKind::String(s) => s.set_prototype(sc, value), - ValueKind::Undefined(u) => u.set_prototype(sc, value), - ValueKind::Null(n) => n.set_prototype(sc, value), - ValueKind::Symbol(s) => s.set_prototype(sc, value), - ValueKind::Object(o) => o.set_prototype(sc, value), - ValueKind::External(e) => e.set_prototype(sc, value), + ValueKind::Number(n) => n.set_prototype(value, sc), + ValueKind::Boolean(b) => b.set_prototype(value, sc), + ValueKind::String(s) => s.set_prototype(value, sc), + ValueKind::Undefined(u) => u.set_prototype(value, sc), + ValueKind::Null(n) => n.set_prototype(value, sc), + ValueKind::Symbol(s) => s.set_prototype(value, sc), + ValueKind::Object(o) => o.set_prototype(value, sc), + ValueKind::External(e) => e.set_prototype(value, sc), } } @@ -288,8 +288,8 @@ impl Object for Value { } } - fn apply(&self, scope: &mut LocalScope, _: ObjectId, this: This, args: CallArgs) -> Result { - self.apply(scope, this, args) + fn apply(&self, _: ObjectId, this: This, args: CallArgs, scope: &mut LocalScope) -> Result { + self.apply(this, args, scope) } fn own_keys(&self, sc: &mut LocalScope<'_>) -> Result, Value> { @@ -320,13 +320,13 @@ impl Object for Value { fn construct( &self, - scope: &mut LocalScope, _: ObjectId, this: This, args: CallArgs, new_target: ObjectId, + scope: &mut LocalScope, ) -> Result { - self.construct_with_target(scope, this, args, new_target) + self.construct_with_target(this, args, new_target, scope) } fn internal_slots(&self, _: &Vm) -> Option<&dyn InternalSlots> { @@ -607,23 +607,23 @@ impl Object for ExternalValue { fn apply( &self, - scope: &mut LocalScope, _callee: ObjectId, this: This, args: CallArgs, + scope: &mut LocalScope, ) -> Result { - self.inner.apply(scope, this, args) + self.inner.apply(this, args, scope) } fn construct( &self, - scope: &mut LocalScope, _callee: ObjectId, this: This, args: CallArgs, new_target: ObjectId, + scope: &mut LocalScope, ) -> Result { - self.inner.construct_with_target(scope, this, args, new_target) + self.inner.construct_with_target(this, args, new_target, scope) } } @@ -634,24 +634,24 @@ impl Value { Some(unsafe { ptr.cast::().as_ref() }) } - pub fn get_property(&self, sc: &mut LocalScope, key: PropertyKey) -> Result { + pub fn get_property(&self, key: PropertyKey, sc: &mut LocalScope) -> Result { match self.unpack() { - ValueKind::Object(o) => o.get_property(sc, key), + ValueKind::Object(o) => o.get_property(key, sc), // TODO: autobox primitives - ValueKind::Number(n) => n.get_property(sc, This::Bound(*self), key), - ValueKind::Boolean(b) => b.get_property(sc, This::Bound(*self), key), - ValueKind::String(s) => s.get_property(sc, This::Bound(*self), key), - ValueKind::External(o) => o.inner(sc).get_property(sc, key), - ValueKind::Undefined(u) => u.get_property(sc, This::Bound(*self), key), - ValueKind::Null(n) => n.get_property(sc, This::Bound(*self), key), - ValueKind::Symbol(s) => s.get_property(sc, This::Bound(*self), key), + ValueKind::Number(n) => n.get_property(This::Bound(*self), key, sc), + ValueKind::Boolean(b) => b.get_property(This::Bound(*self), key, sc), + ValueKind::String(s) => s.get_property(This::Bound(*self), key, sc), + ValueKind::External(o) => o.inner(sc).get_property(key, sc), + ValueKind::Undefined(u) => u.get_property(This::Bound(*self), key, sc), + ValueKind::Null(n) => n.get_property(This::Bound(*self), key, sc), + ValueKind::Symbol(s) => s.get_property(This::Bound(*self), key, sc), } } - pub fn apply(&self, sc: &mut LocalScope, this: This, args: CallArgs) -> Result { + pub fn apply(&self, this: This, args: CallArgs, sc: &mut LocalScope) -> Result { match self.unpack() { - ValueKind::Object(o) => o.apply(sc, this, args), - ValueKind::External(o) => o.inner(sc).apply(sc, this, args), + ValueKind::Object(o) => o.apply(this, args, sc), + ValueKind::External(o) => o.inner(sc).apply(this, args, sc), ValueKind::Number(n) => throw!(sc, TypeError, "{} is not a function", n), ValueKind::Boolean(b) => throw!(sc, TypeError, "{} is not a function", b), ValueKind::String(s) => { @@ -667,14 +667,14 @@ impl Value { /// Calls a function with debug information. This will print the function being attempted to call as written in the source code. pub(crate) fn apply_with_debug( &self, - sc: &mut LocalScope, this: This, args: CallArgs, ip: u16, + sc: &mut LocalScope, ) -> Result { match self.unpack() { - ValueKind::Object(o) => o.apply(sc, this, args), - ValueKind::External(o) => o.inner(sc).apply(sc, this, args), + ValueKind::Object(o) => o.apply(this, args, sc), + ValueKind::External(o) => o.inner(sc).apply(this, args, sc), _ => { cold_path(); @@ -691,10 +691,10 @@ impl Value { } } - pub fn construct(&self, sc: &mut LocalScope, this: This, args: CallArgs) -> Result { + pub fn construct(&self, this: This, args: CallArgs, sc: &mut LocalScope) -> Result { match self.unpack() { - ValueKind::Object(o) => o.construct(sc, this, args), - ValueKind::External(o) => o.inner(sc).construct(sc, this, args), + ValueKind::Object(o) => o.construct(this, args, sc), + ValueKind::External(o) => o.inner(sc).construct(this, args, sc), ValueKind::Number(n) => throw!(sc, TypeError, "{} is not a constructor", n), ValueKind::Boolean(b) => throw!(sc, TypeError, "{} is not a constructor", b), ValueKind::String(s) => { @@ -709,14 +709,14 @@ impl Value { pub fn construct_with_target( &self, - sc: &mut LocalScope, this: This, args: CallArgs, new_target: ObjectId, + sc: &mut LocalScope, ) -> Result { match self.unpack() { - ValueKind::Object(o) => o.construct_with_target(sc, this, args, new_target), - ValueKind::External(o) => o.inner(sc).construct_with_target(sc, this, args, new_target), + ValueKind::Object(o) => o.construct_with_target(this, args, new_target, sc), + ValueKind::External(o) => o.inner(sc).construct_with_target(this, args, new_target, sc), ValueKind::Number(n) => throw!(sc, TypeError, "{} is not a constructor", n), ValueKind::Boolean(b) => throw!(sc, TypeError, "{} is not a constructor", b), ValueKind::String(s) => { @@ -786,7 +786,7 @@ impl Value { } // Look if self[prototype] == ctor.prototype, repeat for all objects in self's prototype chain - let target_proto = ctor.get_property(sc, sym::prototype.into()).root(sc)?; + let target_proto = ctor.get_property(sym::prototype.into(), sc).root(sc)?; self.for_each_prototype(sc, |_, proto| { Ok(if proto == &target_proto { ControlFlow::Break(()) @@ -925,19 +925,19 @@ impl Object for PureBuiltin { type_of ); - fn set_property(&self, sc: &mut LocalScope, key: PropertyKey, value: PropertyValue) -> Result<(), Value> { + fn set_property(&self, key: PropertyKey, value: PropertyValue, sc: &mut LocalScope) -> Result<(), Value> { sc.impure_builtins(); - self.inner.set_property(sc, key, value) + self.inner.set_property(key, value, sc) } - fn delete_property(&self, sc: &mut LocalScope, key: PropertyKey) -> Result { + fn delete_property(&self, key: PropertyKey, sc: &mut LocalScope) -> Result { sc.impure_builtins(); - self.inner.delete_property(sc, key) + self.inner.delete_property(key, sc) } - fn set_prototype(&self, sc: &mut LocalScope, value: Value) -> Result<(), Value> { + fn set_prototype(&self, value: Value, sc: &mut LocalScope) -> Result<(), Value> { sc.impure_builtins(); - self.inner.set_prototype(sc, value) + self.inner.set_prototype(value, sc) } fn own_keys(&self, sc: &mut LocalScope<'_>) -> Result, Value> { diff --git a/crates/dash_vm/src/value/object.rs b/crates/dash_vm/src/value/object.rs index c6f4fe19..9a9a440e 100755 --- a/crates/dash_vm/src/value/object.rs +++ b/crates/dash_vm/src/value/object.rs @@ -27,58 +27,58 @@ use super::{Root, Typeof, Unpack, Unrooted, Value, ValueContext, ValueKind}; pub type ObjectMap = hashbrown::HashMap>; pub trait Object: Debug + Trace { - fn get_own_property(&self, sc: &mut LocalScope, this: This, key: PropertyKey) -> Result { + fn get_own_property(&self, this: This, key: PropertyKey, sc: &mut LocalScope<'_>) -> Result { delegate_get_own_property(self, this, sc, key) } fn get_own_property_descriptor( &self, - sc: &mut LocalScope, key: PropertyKey, + sc: &mut LocalScope, ) -> Result, Unrooted>; - fn get_property(&self, sc: &mut LocalScope, this: This, key: PropertyKey) -> Result { + fn get_property(&self, this: This, key: PropertyKey, sc: &mut LocalScope<'_>) -> Result { delegate_get_property(self, this, sc, key) } fn get_property_descriptor( &self, - sc: &mut LocalScope, key: PropertyKey, + sc: &mut LocalScope, ) -> Result, Unrooted> { - let own_descriptor = self.get_own_property_descriptor(sc, key)?; + let own_descriptor = self.get_own_property_descriptor(key, sc)?; if own_descriptor.is_some() { return Ok(own_descriptor); } match self.get_prototype(sc)?.unpack() { - ValueKind::Object(object) => object.get_property_descriptor(sc, key), - ValueKind::External(object) => object.get_own_property_descriptor(sc, key), + ValueKind::Object(object) => object.get_property_descriptor(key, sc), + ValueKind::External(object) => object.get_own_property_descriptor(key, sc), ValueKind::Null(..) => Ok(None), _ => unreachable!(), } } - fn set_property(&self, sc: &mut LocalScope, key: PropertyKey, value: PropertyValue) -> Result<(), Value>; + fn set_property(&self, key: PropertyKey, value: PropertyValue, sc: &mut LocalScope) -> Result<(), Value>; - fn delete_property(&self, sc: &mut LocalScope, key: PropertyKey) -> Result; + fn delete_property(&self, key: PropertyKey, sc: &mut LocalScope) -> Result; - fn set_prototype(&self, sc: &mut LocalScope, value: Value) -> Result<(), Value>; + fn set_prototype(&self, value: Value, sc: &mut LocalScope) -> Result<(), Value>; fn get_prototype(&self, sc: &mut LocalScope) -> Result; - fn apply(&self, scope: &mut LocalScope, callee: ObjectId, this: This, args: CallArgs) + fn apply(&self, callee: ObjectId, this: This, args: CallArgs, scope: &mut LocalScope) -> Result; fn construct( &self, - scope: &mut LocalScope, callee: ObjectId, this: This, args: CallArgs, _new_target: ObjectId, + scope: &mut LocalScope, ) -> Result { - self.apply(scope, callee, this, args) + self.apply(callee, this, args, scope) } // TODO: require returning a special kind of pointer wrapper that needs unsafe to construct @@ -103,53 +103,53 @@ macro_rules! delegate { (override $field:ident, get_own_property_descriptor) => { fn get_own_property_descriptor( &self, - sc: &mut $crate::localscope::LocalScope, key: $crate::value::propertykey::PropertyKey, + sc: &mut $crate::localscope::LocalScope, ) -> Result, $crate::value::Unrooted> { - self.$field.get_own_property_descriptor(sc, key) + self.$field.get_own_property_descriptor(key, sc) } }; (override $field:ident, get_property) => { fn get_property( &self, - sc: &mut $crate::localscope::LocalScope, this: $crate::frame::This, key: $crate::value::propertykey::PropertyKey, + sc: &mut $crate::localscope::LocalScope, ) -> Result<$crate::value::Unrooted, $crate::value::Unrooted> { - $crate::value::object::Object::get_property(&self.$field, sc, this, key) + $crate::value::object::Object::get_property(&self.$field, this, key, sc) } }; (override $field:ident, get_property_descriptor) => { fn get_property_descriptor( &self, - sc: &mut $crate::localscope::LocalScope, key: $crate::value::propertykey::PropertyKey, + sc: &mut $crate::localscope::LocalScope, ) -> Result, $crate::value::Unrooted> { - self.$field.get_property_descriptor(sc, key) + self.$field.get_property_descriptor(key, sc) } }; (override $field:ident, set_property) => { fn set_property( &self, - sc: &mut $crate::localscope::LocalScope, key: $crate::value::propertykey::PropertyKey, value: $crate::value::object::PropertyValue, + sc: &mut $crate::localscope::LocalScope, ) -> Result<(), $crate::value::Value> { - self.$field.set_property(sc, key, value) + self.$field.set_property(key, value, sc) } }; (override $field:ident, delete_property) => { fn delete_property( &self, - sc: &mut $crate::localscope::LocalScope, key: $crate::value::propertykey::PropertyKey, + sc: &mut $crate::localscope::LocalScope, ) -> Result<$crate::value::Unrooted, $crate::value::Value> { - self.$field.delete_property(sc, key) + self.$field.delete_property(key, sc) } }; (override $field:ident, set_prototype) => { - fn set_prototype(&self, sc: &mut $crate::localscope::LocalScope, value: $crate::value::Value) -> Result<(), $crate::value::Value> { - self.$field.set_prototype(sc, value) + fn set_prototype(&self, value: $crate::value::Value, sc: &mut $crate::localscope::LocalScope) -> Result<(), $crate::value::Value> { + self.$field.set_prototype(value, sc) } }; (override $field:ident, get_prototype) => { @@ -165,24 +165,24 @@ macro_rules! delegate { (override $field:ident, apply) => { fn apply( &self, - sc: &mut $crate::localscope::LocalScope, id: $crate::gc::ObjectId, this: $crate::frame::This, args: $crate::value::function::args::CallArgs, + sc: &mut $crate::localscope::LocalScope, ) -> Result<$crate::value::Unrooted, $crate::value::Unrooted> { - $crate::value::object::Object::apply(&self.$field, sc, id, this, args) + $crate::value::object::Object::apply(&self.$field, id, this, args, sc) } }; (override $field:ident, construct) => { fn construct( &self, - sc: &mut $crate::localscope::LocalScope, id: $crate::gc::ObjectId, this: $crate::frame::This, args: $crate::value::function::args::CallArgs, new_target: $crate::gc::ObjectId, + sc: &mut $crate::localscope::LocalScope, ) -> Result<$crate::value::Unrooted, $crate::value::Unrooted> { - $crate::value::object::Object::construct(&self.$field, sc, id, this, args, new_target) + $crate::value::object::Object::construct(&self.$field, id, this, args, new_target, sc) } }; (override $field:ident, type_of) => { @@ -302,38 +302,38 @@ impl PropertyValue { match self.kind { PropertyValueKind::Static(value) => { - obj.set_property(sc, sym::value.into(), PropertyValue::static_default(value))?; + obj.set_property(sym::value.into(), PropertyValue::static_default(value), sc)?; } PropertyValueKind::Trap { get, set } => { let get = get.map(Value::object).unwrap_or_undefined(); let set = set.map(Value::object).unwrap_or_undefined(); - obj.set_property(sc, sym::get.into(), PropertyValue::static_default(get))?; - obj.set_property(sc, sym::set.into(), PropertyValue::static_default(set))?; + obj.set_property(sym::get.into(), PropertyValue::static_default(get), sc)?; + obj.set_property(sym::set.into(), PropertyValue::static_default(set), sc)?; } } obj.set_property( - sc, sym::writable.into(), PropertyValue::static_default(Value::boolean( self.descriptor.contains(PropertyDataDescriptor::WRITABLE), )), + sc, )?; obj.set_property( - sc, sym::enumerable.into(), PropertyValue::static_default(Value::boolean( self.descriptor.contains(PropertyDataDescriptor::ENUMERABLE), )), + sc, )?; obj.set_property( - sc, sym::configurable.into(), PropertyValue::static_default(Value::boolean( self.descriptor.contains(PropertyDataDescriptor::CONFIGURABLE), )), + sc, )?; Ok(Value::object(sc.register(obj))) @@ -341,9 +341,9 @@ impl PropertyValue { pub fn from_descriptor_value(sc: &mut LocalScope<'_>, value: Value) -> Result { let mut flags = PropertyDataDescriptor::empty(); - let configurable = value.get_property(sc, sym::configurable.into()).root(sc)?.into_option(); - let enumerable = value.get_property(sc, sym::enumerable.into()).root(sc)?.into_option(); - let writable = value.get_property(sc, sym::writable.into()).root(sc)?.into_option(); + let configurable = value.get_property(sym::configurable.into(), sc).root(sc)?.into_option(); + let enumerable = value.get_property(sym::enumerable.into(), sc).root(sc)?.into_option(); + let writable = value.get_property(sym::writable.into(), sc).root(sc)?.into_option(); if configurable.is_some_and(|v| v.is_truthy(sc)) { flags |= PropertyDataDescriptor::CONFIGURABLE; @@ -357,12 +357,12 @@ impl PropertyValue { // TODO: make sure that if value is set, get/set are not - let static_value = value.get_property(sc, sym::value.into()).root(sc)?.into_option(); + let static_value = value.get_property(sym::value.into(), sc).root(sc)?.into_option(); let kind = match static_value { Some(static_value) => PropertyValueKind::Static(static_value), None => { let get = value - .get_property(sc, sym::get.into()) + .get_property(sym::get.into(), sc) .root(sc)? .into_option() .and_then(|v| match v.unpack() { @@ -370,7 +370,7 @@ impl PropertyValue { _ => None, }); let set = value - .get_property(sc, sym::set.into()) + .get_property(sym::set.into(), sc) .root(sc)? .into_option() .and_then(|v| match v.unpack() { @@ -425,7 +425,7 @@ impl PropertyValueKind { match *self { Self::Static(value) => Ok(value.into()), Self::Trap { get, .. } => match get { - Some(id) => id.apply(sc, this, CallArgs::empty()), + Some(id) => id.apply(this, CallArgs::empty(), sc), None => Ok(Value::undefined().into()), }, } @@ -464,7 +464,7 @@ impl NamedObject { /// Takes a constructor `new_target` and instantiates it pub fn instance_for_new_target(new_target: ObjectId, scope: &mut LocalScope) -> Result { let ValueKind::Object(prototype) = new_target - .get_property(scope, sym::prototype.into()) + .get_property(sym::prototype.into(), scope) .root(scope)? .unpack() else { @@ -519,8 +519,8 @@ unsafe impl Trace for NamedObject { impl Object for NamedObject { fn get_own_property_descriptor( &self, - sc: &mut LocalScope, key: PropertyKey, + sc: &mut LocalScope, ) -> Result, Unrooted> { if let PropertyKey::String(st) = &key { match st.sym() { @@ -542,13 +542,16 @@ impl Object for NamedObject { Ok(None) } - fn set_property(&self, sc: &mut LocalScope, key: PropertyKey, value: PropertyValue) -> Result<(), Value> { + fn set_property(&self, key: PropertyKey, value: PropertyValue, sc: &mut LocalScope) -> Result<(), Value> { match key.as_string().map(JsString::sym) { Some(sym::__proto__) => { - return self.set_prototype(sc, match value.into_kind() { - PropertyValueKind::Static(value) => value, - _ => throw!(sc, TypeError, "Prototype cannot be a trap"), - }); + return self.set_prototype( + match value.into_kind() { + PropertyValueKind::Static(value) => value, + _ => throw!(sc, TypeError, "Prototype cannot be a trap"), + }, + sc, + ); } Some(sym::constructor) => { let obj = if let PropertyValueKind::Static(val) = value.kind { @@ -584,7 +587,7 @@ impl Object for NamedObject { Ok(()) } - fn delete_property(&self, sc: &mut LocalScope, key: PropertyKey) -> Result { + fn delete_property(&self, key: PropertyKey, sc: &mut LocalScope) -> Result { let mut values = self.values.borrow_mut(); let value = values.remove(&key); @@ -614,15 +617,15 @@ impl Object for NamedObject { fn apply( &self, - _sc: &mut LocalScope, _handle: ObjectId, _this: This, _args: CallArgs, + _sc: &mut LocalScope, ) -> Result { Ok(Value::undefined().into()) } - fn set_prototype(&self, sc: &mut LocalScope, value: Value) -> Result<(), Value> { + fn set_prototype(&self, value: Value, sc: &mut LocalScope) -> Result<(), Value> { match value.unpack() { ValueKind::Null(_) => self.prototype.replace(None), ValueKind::Object(handle) => self.prototype.replace(Some(handle)), @@ -661,40 +664,40 @@ impl ObjectId { // TODO: can these be inherent methods? or do we actually require the `ObjectId: Object` trait obligation anywhere? // then they also wouldn't need to take &self impl Object for ObjectId { - fn get_own_property(&self, sc: &mut LocalScope, this: This, key: PropertyKey) -> Result { - unsafe { (self.vtable(sc).js_get_own_property)(self.data_ptr(sc), sc, this, key) } + fn get_own_property(&self, this: This, key: PropertyKey, sc: &mut LocalScope) -> Result { + unsafe { (self.vtable(sc).js_get_own_property)(self.data_ptr(sc), this, key, sc) } } fn get_own_property_descriptor( &self, - sc: &mut LocalScope, key: PropertyKey, + sc: &mut LocalScope, ) -> Result, Unrooted> { - unsafe { (self.vtable(sc).js_get_own_property_descriptor)(self.data_ptr(sc), sc, key) } + unsafe { (self.vtable(sc).js_get_own_property_descriptor)(self.data_ptr(sc), key, sc) } } - fn get_property(&self, sc: &mut LocalScope, this: This, key: PropertyKey) -> Result { - unsafe { (self.vtable(sc).js_get_property)(self.data_ptr(sc), sc, this, key) } + fn get_property(&self, this: This, key: PropertyKey, sc: &mut LocalScope) -> Result { + unsafe { (self.vtable(sc).js_get_property)(self.data_ptr(sc), this, key, sc) } } fn get_property_descriptor( &self, - sc: &mut LocalScope, key: PropertyKey, + sc: &mut LocalScope, ) -> Result, Unrooted> { - unsafe { (self.vtable(sc).js_get_property_descriptor)(self.data_ptr(sc), sc, key) } + unsafe { (self.vtable(sc).js_get_property_descriptor)(self.data_ptr(sc), key, sc) } } - fn set_property(&self, sc: &mut LocalScope, key: PropertyKey, value: PropertyValue) -> Result<(), Value> { - unsafe { (self.vtable(sc).js_set_property)(self.data_ptr(sc), sc, key, value) } + fn set_property(&self, key: PropertyKey, value: PropertyValue, sc: &mut LocalScope) -> Result<(), Value> { + unsafe { (self.vtable(sc).js_set_property)(self.data_ptr(sc), key, value, sc) } } - fn delete_property(&self, sc: &mut LocalScope, key: PropertyKey) -> Result { - unsafe { (self.vtable(sc).js_delete_property)(self.data_ptr(sc), sc, key) } + fn delete_property(&self, key: PropertyKey, sc: &mut LocalScope) -> Result { + unsafe { (self.vtable(sc).js_delete_property)(self.data_ptr(sc), key, sc) } } - fn set_prototype(&self, sc: &mut LocalScope, value: Value) -> Result<(), Value> { - unsafe { (self.vtable(sc).js_set_prototype)(self.data_ptr(sc), sc, value) } + fn set_prototype(&self, value: Value, sc: &mut LocalScope) -> Result<(), Value> { + unsafe { (self.vtable(sc).js_set_prototype)(self.data_ptr(sc), value, sc) } } fn get_prototype(&self, sc: &mut LocalScope) -> Result { @@ -703,23 +706,23 @@ impl Object for ObjectId { fn apply( &self, - scope: &mut LocalScope, callee: ObjectId, this: This, args: CallArgs, + scope: &mut LocalScope, ) -> Result { - unsafe { (self.vtable(scope).js_apply)(self.data_ptr(scope), scope, callee, this, args) } + unsafe { (self.vtable(scope).js_apply)(self.data_ptr(scope), callee, this, args, scope) } } fn construct( &self, - scope: &mut LocalScope, callee: ObjectId, this: This, args: CallArgs, new_target: ObjectId, + scope: &mut LocalScope, ) -> Result { - unsafe { (self.vtable(scope).js_construct)(self.data_ptr(scope), scope, callee, this, args, new_target) } + unsafe { (self.vtable(scope).js_construct)(self.data_ptr(scope), callee, this, args, new_target, scope) } } fn own_keys(&self, sc: &mut LocalScope<'_>) -> Result, Value> { @@ -750,47 +753,47 @@ impl ObjectId { extract_type::(self, vm) } - pub fn get_property(self, sc: &mut LocalScope, key: PropertyKey) -> Result { - Object::get_property(&self, sc, This::Bound(Value::object(self)), key) + pub fn get_property(self, key: PropertyKey, sc: &mut LocalScope) -> Result { + Object::get_property(&self, This::Bound(Value::object(self)), key, sc) } - pub fn get_own_property(self, sc: &mut LocalScope, key: PropertyKey) -> Result { - Object::get_own_property(&self, sc, This::Bound(Value::object(self)), key) + pub fn get_own_property(self, key: PropertyKey, sc: &mut LocalScope) -> Result { + Object::get_own_property(&self, This::Bound(Value::object(self)), key, sc) } - pub fn apply(&self, sc: &mut LocalScope, this: This, args: CallArgs) -> Result { + pub fn apply(&self, this: This, args: CallArgs, sc: &mut LocalScope) -> Result { let callee = *self; - Object::apply(self, sc, callee, this, args) + Object::apply(self, callee, this, args, sc) } - pub fn construct(&self, sc: &mut LocalScope, this: This, args: CallArgs) -> Result { - Object::construct(self, sc, *self, this, args, *self) + pub fn construct(&self, this: This, args: CallArgs, sc: &mut LocalScope) -> Result { + Object::construct(self, *self, this, args, *self, sc) } pub fn construct_with_target( &self, - sc: &mut LocalScope, this: This, args: CallArgs, new_target: ObjectId, + sc: &mut LocalScope, ) -> Result { - Object::construct(self, sc, *self, this, args, new_target) + Object::construct(self, *self, this, args, new_target, sc) } - pub fn set_integrity_level(self, sc: &mut LocalScope<'_>, level: IntegrityLevel) -> Result<(), Value> { + pub fn set_integrity_level(self, level: IntegrityLevel, sc: &mut LocalScope<'_>) -> Result<(), Value> { // TODO: invoke [[PreventExtensions]] let keys = self.own_keys(sc)?; for key in keys { let key = PropertyKey::from_value(sc, key)?; - if let Some(mut desc) = self.get_own_property_descriptor(sc, key).root_err(sc)? { + if let Some(mut desc) = self.get_own_property_descriptor(key, sc).root_err(sc)? { desc.descriptor.remove(PropertyDataDescriptor::CONFIGURABLE); if let IntegrityLevel::Frozen = level { if let PropertyValueKind::Static(_) = desc.kind { desc.descriptor.remove(PropertyDataDescriptor::WRITABLE); } } - self.set_property(sc, key, desc)?; + self.set_property(key, desc, sc)?; } } Ok(()) @@ -804,15 +807,15 @@ pub enum IntegrityLevel { impl Persistent { pub fn get_property(&self, sc: &mut LocalScope, key: PropertyKey) -> Result { - self.id().get_property(sc, key) + self.id().get_property(key, sc) } pub fn apply(&self, sc: &mut LocalScope, this: This, args: CallArgs) -> Result { - self.id().apply(sc, this, args) + self.id().apply(this, args, sc) } pub fn construct(&self, sc: &mut LocalScope, this: This, args: CallArgs) -> Result { - self.id().construct(sc, this, args) + self.id().construct(this, args, sc) } // FIXME: should override typeof, internal_slots, etc. @@ -825,7 +828,7 @@ pub fn delegate_get_property( sc: &mut LocalScope, key: PropertyKey, ) -> Result { - this.get_property_descriptor(sc, key) + this.get_property_descriptor(key, sc) .map(|x| x.unwrap_or_else(|| PropertyValue::static_default(Value::undefined()))) .and_then(|x| x.get_or_apply(sc, this_value)) } @@ -836,7 +839,7 @@ pub fn delegate_get_own_property( sc: &mut LocalScope, key: PropertyKey, ) -> Result { - this.get_own_property_descriptor(sc, key) + this.get_own_property_descriptor(key, sc) .map(|x| x.unwrap_or_else(|| PropertyValue::static_default(Value::undefined()))) .and_then(|x| x.get_or_apply(sc, this_value)) } diff --git a/crates/dash_vm/src/value/ops/conversions.rs b/crates/dash_vm/src/value/ops/conversions.rs index 5fe6aaab..5f8ecc30 100755 --- a/crates/dash_vm/src/value/ops/conversions.rs +++ b/crates/dash_vm/src/value/ops/conversions.rs @@ -119,7 +119,7 @@ impl ValueConversion for Value { // a. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). let to_primitive = sc.statics.symbol_to_primitive; - let exotic_to_prim = self.get_property(sc, to_primitive.into()).root(sc)?.into_option(); + let exotic_to_prim = self.get_property(to_primitive.into(), sc).root(sc)?.into_option(); // b. If exoticToPrim is not undefined, then if let Some(exotic_to_prim) = exotic_to_prim { @@ -130,7 +130,7 @@ impl ValueConversion for Value { // iv. Let result be ? Call(exoticToPrim, input, « hint »). let result = exotic_to_prim - .apply(sc, This::Bound(*self), [preferred_type].into()) + .apply(This::Bound(*self), [preferred_type].into(), sc) .root(sc)?; // If Type(result) is not Object, return result. @@ -151,7 +151,7 @@ impl ValueConversion for Value { } fn length_of_array_like(&self, sc: &mut LocalScope) -> Result { - self.get_property(sc, sym::length.into()).root(sc)?.to_length_u(sc) + self.get_property(sym::length.into(), sc).root(sc)?.to_length_u(sc) } fn to_object(&self, sc: &mut LocalScope) -> Result { @@ -200,9 +200,9 @@ impl Value { }; for name in method_names { - let method = self.get_property(sc, name.into()).root(sc)?; + let method = self.get_property(name.into(), sc).root(sc)?; if matches!(method.type_of(sc), Typeof::Function) { - let result = method.apply(sc, This::Bound(*self), CallArgs::empty()).root(sc)?; + let result = method.apply(This::Bound(*self), CallArgs::empty(), sc).root(sc)?; if !matches!(result.unpack(), ValueKind::Object(_)) { return Ok(result); } diff --git a/crates/dash_vm/src/value/primitive.rs b/crates/dash_vm/src/value/primitive.rs index de5ca5eb..23eb9443 100644 --- a/crates/dash_vm/src/value/primitive.rs +++ b/crates/dash_vm/src/value/primitive.rs @@ -26,21 +26,21 @@ pub const MIN_SAFE_INTEGERF: f64 = -9007199254740991f64; impl Object for f64 { fn get_own_property_descriptor( &self, - _sc: &mut LocalScope, _key: PropertyKey, + _sc: &mut LocalScope, ) -> Result, Unrooted> { Ok(None) } - fn set_property(&self, _sc: &mut LocalScope, _key: PropertyKey, _value: PropertyValue) -> Result<(), Value> { + fn set_property(&self, _key: PropertyKey, _value: PropertyValue, _sc: &mut LocalScope) -> Result<(), Value> { Ok(()) } - fn delete_property(&self, _sc: &mut LocalScope, _key: PropertyKey) -> Result { + fn delete_property(&self, _key: PropertyKey, _sc: &mut LocalScope) -> Result { Ok(Unrooted::new(Value::undefined())) } - fn set_prototype(&self, _sc: &mut LocalScope, _value: Value) -> Result<(), Value> { + fn set_prototype(&self, _value: Value, _sc: &mut LocalScope) -> Result<(), Value> { // TODO: Reflect.setPrototypeOf(this, value); should throw Ok(()) } @@ -51,10 +51,10 @@ impl Object for f64 { fn apply( &self, - scope: &mut LocalScope, _callee: ObjectId, _this: This, _args: CallArgs, + scope: &mut LocalScope, ) -> Result { throw!(scope, TypeError, "number is not a function") } @@ -77,21 +77,21 @@ impl Object for f64 { impl Object for bool { fn get_own_property_descriptor( &self, - _sc: &mut LocalScope, _key: PropertyKey, + _sc: &mut LocalScope, ) -> Result, Unrooted> { Ok(None) } - fn set_property(&self, _sc: &mut LocalScope, _key: PropertyKey, _value: PropertyValue) -> Result<(), Value> { + fn set_property(&self, _key: PropertyKey, _value: PropertyValue, _sc: &mut LocalScope) -> Result<(), Value> { Ok(()) } - fn delete_property(&self, _sc: &mut LocalScope, _key: PropertyKey) -> Result { + fn delete_property(&self, _key: PropertyKey, _sc: &mut LocalScope) -> Result { Ok(Unrooted::new(Value::undefined())) } - fn set_prototype(&self, _sc: &mut LocalScope, _value: Value) -> Result<(), Value> { + fn set_prototype(&self, _value: Value, _sc: &mut LocalScope) -> Result<(), Value> { Ok(()) } @@ -101,10 +101,10 @@ impl Object for bool { fn apply( &self, - scope: &mut LocalScope, _callee: ObjectId, _this: This, _args: CallArgs, + scope: &mut LocalScope, ) -> Result { throw!(scope, TypeError, "boolean is not a function") } @@ -140,8 +140,8 @@ pub struct Null; impl Object for Undefined { fn get_own_property_descriptor( &self, - sc: &mut LocalScope, key: PropertyKey, + sc: &mut LocalScope, ) -> Result, Unrooted> { let key = match key { PropertyKey::String(s) => s.res(sc).to_owned(), @@ -150,7 +150,7 @@ impl Object for Undefined { throw!(sc, TypeError, "Cannot read property {} of undefined", key) } - fn set_property(&self, sc: &mut LocalScope, key: PropertyKey, _value: PropertyValue) -> Result<(), Value> { + fn set_property(&self, key: PropertyKey, _value: PropertyValue, sc: &mut LocalScope) -> Result<(), Value> { let key = match key { PropertyKey::String(s) => s.res(sc).to_owned(), PropertyKey::Symbol(s) => sc.interner.resolve(s.sym()).to_owned(), @@ -158,11 +158,11 @@ impl Object for Undefined { throw!(sc, TypeError, "Cannot set property {:?} of undefined", key) } - fn delete_property(&self, _sc: &mut LocalScope, _key: PropertyKey) -> Result { + fn delete_property(&self, _key: PropertyKey, _sc: &mut LocalScope) -> Result { Ok(Unrooted::new(Value::undefined())) } - fn set_prototype(&self, sc: &mut LocalScope, _value: Value) -> Result<(), Value> { + fn set_prototype(&self, _value: Value, sc: &mut LocalScope) -> Result<(), Value> { throw!(sc, TypeError, "Cannot set prototype of undefined") } @@ -172,10 +172,10 @@ impl Object for Undefined { fn apply( &self, - sc: &mut LocalScope, _callee: ObjectId, _this: This, _args: CallArgs, + sc: &mut LocalScope, ) -> Result { throw!(sc, TypeError, "undefined is not a function") } @@ -194,8 +194,8 @@ impl Object for Undefined { impl Object for Null { fn get_own_property_descriptor( &self, - sc: &mut LocalScope, key: PropertyKey, + sc: &mut LocalScope, ) -> Result, Unrooted> { let key = match key { PropertyKey::String(s) => s.res(sc).to_owned(), @@ -204,7 +204,7 @@ impl Object for Null { throw!(sc, TypeError, "Cannot read property {} of null", key) } - fn set_property(&self, sc: &mut LocalScope, key: PropertyKey, _value: PropertyValue) -> Result<(), Value> { + fn set_property(&self, key: PropertyKey, _value: PropertyValue, sc: &mut LocalScope) -> Result<(), Value> { let key = match key { PropertyKey::String(s) => s.res(sc).to_owned(), PropertyKey::Symbol(s) => sc.interner.resolve(s.sym()).to_owned(), @@ -212,11 +212,11 @@ impl Object for Null { throw!(sc, TypeError, "Cannot set property {:?} of null", key) } - fn delete_property(&self, _sc: &mut LocalScope, _key: PropertyKey) -> Result { + fn delete_property(&self, _key: PropertyKey, _sc: &mut LocalScope) -> Result { Ok(Unrooted::new(Value::undefined())) } - fn set_prototype(&self, sc: &mut LocalScope, _value: Value) -> Result<(), Value> { + fn set_prototype(&self, _value: Value, sc: &mut LocalScope) -> Result<(), Value> { throw!(sc, TypeError, "Cannot set prototype of null") } @@ -226,10 +226,10 @@ impl Object for Null { fn apply( &self, - sc: &mut LocalScope, _callee: ObjectId, _this: This, _args: CallArgs, + sc: &mut LocalScope, ) -> Result { throw!(sc, TypeError, "null is not a function") } @@ -260,21 +260,21 @@ impl Symbol { impl Object for Symbol { fn get_own_property_descriptor( &self, - _sc: &mut LocalScope, _key: PropertyKey, + _sc: &mut LocalScope, ) -> Result, Unrooted> { Ok(None) } - fn set_property(&self, _sc: &mut LocalScope, _key: PropertyKey, _value: PropertyValue) -> Result<(), Value> { + fn set_property(&self, _key: PropertyKey, _value: PropertyValue, _sc: &mut LocalScope) -> Result<(), Value> { Ok(()) } - fn delete_property(&self, _sc: &mut LocalScope, _key: PropertyKey) -> Result { + fn delete_property(&self, _key: PropertyKey, _sc: &mut LocalScope) -> Result { Ok(Unrooted::new(Value::undefined())) } - fn set_prototype(&self, _sc: &mut LocalScope, _value: Value) -> Result<(), Value> { + fn set_prototype(&self, _value: Value, _sc: &mut LocalScope) -> Result<(), Value> { Ok(()) } @@ -284,10 +284,10 @@ impl Object for Symbol { fn apply( &self, - scope: &mut LocalScope, _callee: ObjectId, _this: This, _args: CallArgs, + scope: &mut LocalScope, ) -> Result { throw!(scope, TypeError, "symbol is not a function") } @@ -499,22 +499,22 @@ impl Hash for Number { impl Object for Number { fn get_own_property_descriptor( &self, - sc: &mut LocalScope, key: PropertyKey, + sc: &mut LocalScope, ) -> Result, Unrooted> { - self.0.get_own_property_descriptor(sc, key) + self.0.get_own_property_descriptor(key, sc) } - fn set_property(&self, sc: &mut LocalScope, key: PropertyKey, value: PropertyValue) -> Result<(), Value> { - self.0.set_property(sc, key, value) + fn set_property(&self, key: PropertyKey, value: PropertyValue, sc: &mut LocalScope) -> Result<(), Value> { + self.0.set_property(key, value, sc) } - fn delete_property(&self, sc: &mut LocalScope, key: PropertyKey) -> Result { - self.0.delete_property(sc, key) + fn delete_property(&self, key: PropertyKey, sc: &mut LocalScope) -> Result { + self.0.delete_property(key, sc) } - fn set_prototype(&self, sc: &mut LocalScope, value: Value) -> Result<(), Value> { - self.0.set_prototype(sc, value) + fn set_prototype(&self, value: Value, sc: &mut LocalScope) -> Result<(), Value> { + self.0.set_prototype(value, sc) } fn get_prototype(&self, sc: &mut LocalScope) -> Result { @@ -523,12 +523,12 @@ impl Object for Number { fn apply( &self, - scope: &mut LocalScope, callee: ObjectId, this: This, args: CallArgs, + scope: &mut LocalScope, ) -> Result { - self.0.apply(scope, callee, this, args) + self.0.apply(callee, this, args, scope) } fn own_keys(&self, sc: &mut LocalScope<'_>) -> Result, Value> { diff --git a/crates/dash_vm/src/value/promise.rs b/crates/dash_vm/src/value/promise.rs index 42109f3b..518fff4d 100644 --- a/crates/dash_vm/src/value/promise.rs +++ b/crates/dash_vm/src/value/promise.rs @@ -79,22 +79,22 @@ impl Promise { impl Object for Promise { fn get_own_property_descriptor( &self, - sc: &mut LocalScope, key: PropertyKey, + sc: &mut LocalScope, ) -> Result, Unrooted> { - self.obj.get_own_property_descriptor(sc, key) + self.obj.get_own_property_descriptor(key, sc) } - fn set_property(&self, sc: &mut LocalScope, key: PropertyKey, value: PropertyValue) -> Result<(), Value> { - self.obj.set_property(sc, key, value) + fn set_property(&self, key: PropertyKey, value: PropertyValue, sc: &mut LocalScope) -> Result<(), Value> { + self.obj.set_property(key, value, sc) } - fn delete_property(&self, sc: &mut LocalScope, key: PropertyKey) -> Result { - self.obj.delete_property(sc, key) + fn delete_property(&self, key: PropertyKey, sc: &mut LocalScope) -> Result { + self.obj.delete_property(key, sc) } - fn set_prototype(&self, sc: &mut LocalScope, value: Value) -> Result<(), Value> { - self.obj.set_prototype(sc, value) + fn set_prototype(&self, value: Value, sc: &mut LocalScope) -> Result<(), Value> { + self.obj.set_prototype(value, sc) } fn get_prototype(&self, sc: &mut LocalScope) -> Result { @@ -103,12 +103,12 @@ impl Object for Promise { fn apply( &self, - scope: &mut LocalScope, callee: ObjectId, this: This, args: CallArgs, + scope: &mut LocalScope, ) -> Result { - self.obj.apply(scope, callee, this, args) + self.obj.apply(callee, this, args, scope) } fn own_keys(&self, sc: &mut LocalScope<'_>) -> Result, Value> { @@ -136,22 +136,22 @@ impl PromiseResolver { impl Object for PromiseResolver { fn get_own_property_descriptor( &self, - sc: &mut LocalScope, key: PropertyKey, + sc: &mut LocalScope, ) -> Result, Unrooted> { - self.obj.get_own_property_descriptor(sc, key) + self.obj.get_own_property_descriptor(key, sc) } - fn set_property(&self, sc: &mut LocalScope, key: PropertyKey, value: PropertyValue) -> Result<(), Value> { - self.obj.set_property(sc, key, value) + fn set_property(&self, key: PropertyKey, value: PropertyValue, sc: &mut LocalScope) -> Result<(), Value> { + self.obj.set_property(key, value, sc) } - fn delete_property(&self, sc: &mut LocalScope, key: PropertyKey) -> Result { - self.obj.delete_property(sc, key) + fn delete_property(&self, key: PropertyKey, sc: &mut LocalScope) -> Result { + self.obj.delete_property(key, sc) } - fn set_prototype(&self, sc: &mut LocalScope, value: Value) -> Result<(), Value> { - self.obj.set_prototype(sc, value) + fn set_prototype(&self, value: Value, sc: &mut LocalScope) -> Result<(), Value> { + self.obj.set_prototype(value, sc) } fn get_prototype(&self, sc: &mut LocalScope) -> Result { @@ -160,10 +160,10 @@ impl Object for PromiseResolver { fn apply( &self, - scope: &mut LocalScope, _callee: ObjectId, _this: This, args: CallArgs, + scope: &mut LocalScope, ) -> Result { scope.drive_promise( PromiseAction::Resolve, @@ -203,22 +203,22 @@ impl PromiseRejecter { impl Object for PromiseRejecter { fn get_own_property_descriptor( &self, - sc: &mut LocalScope, key: PropertyKey, + sc: &mut LocalScope, ) -> Result, Unrooted> { - self.obj.get_own_property_descriptor(sc, key) + self.obj.get_own_property_descriptor(key, sc) } - fn set_property(&self, sc: &mut LocalScope, key: PropertyKey, value: PropertyValue) -> Result<(), Value> { - self.obj.set_property(sc, key, value) + fn set_property(&self, key: PropertyKey, value: PropertyValue, sc: &mut LocalScope) -> Result<(), Value> { + self.obj.set_property(key, value, sc) } - fn delete_property(&self, sc: &mut LocalScope, key: PropertyKey) -> Result { - self.obj.delete_property(sc, key) + fn delete_property(&self, key: PropertyKey, sc: &mut LocalScope) -> Result { + self.obj.delete_property(key, sc) } - fn set_prototype(&self, sc: &mut LocalScope, value: Value) -> Result<(), Value> { - self.obj.set_prototype(sc, value) + fn set_prototype(&self, value: Value, sc: &mut LocalScope) -> Result<(), Value> { + self.obj.set_prototype(value, sc) } fn get_prototype(&self, sc: &mut LocalScope) -> Result { @@ -227,10 +227,10 @@ impl Object for PromiseRejecter { fn apply( &self, - scope: &mut LocalScope, _callee: ObjectId, _this: This, args: CallArgs, + scope: &mut LocalScope, ) -> Result { scope.drive_promise( PromiseAction::Reject, diff --git a/crates/dash_vm/src/value/string.rs b/crates/dash_vm/src/value/string.rs index fd95526e..b6de4f85 100644 --- a/crates/dash_vm/src/value/string.rs +++ b/crates/dash_vm/src/value/string.rs @@ -78,8 +78,8 @@ impl ValueConversion for JsString { impl Object for JsString { fn get_own_property_descriptor( &self, - sc: &mut LocalScope, key: PropertyKey, + sc: &mut LocalScope, ) -> Result, Unrooted> { if let PropertyKey::String(st) = key { if st.sym() == sym::length { @@ -98,15 +98,15 @@ impl Object for JsString { Ok(None) } - fn set_property(&self, _: &mut LocalScope, _: PropertyKey, _: PropertyValue) -> Result<(), Value> { + fn set_property(&self, _: PropertyKey, _: PropertyValue, _: &mut LocalScope) -> Result<(), Value> { Ok(()) } - fn delete_property(&self, _: &mut LocalScope, _: PropertyKey) -> Result { + fn delete_property(&self, _: PropertyKey, _: &mut LocalScope) -> Result { Ok(Unrooted::new(Value::undefined())) } - fn set_prototype(&self, _: &mut LocalScope, _: Value) -> Result<(), Value> { + fn set_prototype(&self, _: Value, _: &mut LocalScope) -> Result<(), Value> { Ok(()) } @@ -116,10 +116,10 @@ impl Object for JsString { fn apply( &self, - scope: &mut LocalScope, _: crate::gc::ObjectId, _: This, _: CallArgs, + scope: &mut LocalScope, ) -> Result { let v = self.res(scope).to_owned(); throw!(scope, TypeError, "'{}' is not a function", v) diff --git a/crates/dash_vm/src/value/typedarray.rs b/crates/dash_vm/src/value/typedarray.rs index df5a0db9..2292d1d9 100644 --- a/crates/dash_vm/src/value/typedarray.rs +++ b/crates/dash_vm/src/value/typedarray.rs @@ -86,8 +86,8 @@ impl TypedArray { impl Object for TypedArray { fn get_own_property_descriptor( &self, - sc: &mut LocalScope, key: PropertyKey, + sc: &mut LocalScope, ) -> Result, Unrooted> { if let Some(Ok(index)) = key.as_string().map(|k| k.res(sc).parse::()) { let arraybuffer = self.arraybuffer(sc); @@ -132,10 +132,10 @@ impl Object for TypedArray { return Ok(Some(PropertyValue::static_default(Value::number(len as f64)))); } - self.obj.get_own_property_descriptor(sc, key) + self.obj.get_own_property_descriptor(key, sc) } - fn set_property(&self, sc: &mut LocalScope, key: PropertyKey, value: PropertyValue) -> Result<(), Value> { + fn set_property(&self, key: PropertyKey, value: PropertyValue, sc: &mut LocalScope) -> Result<(), Value> { if let Some(Ok(index)) = key.as_string().map(|k| k.res(sc).parse::()) { let arraybuffer = self.arraybuffer.extract::(sc); @@ -178,15 +178,15 @@ impl Object for TypedArray { } } - self.obj.set_property(sc, key, value) + self.obj.set_property(key, value, sc) } - fn delete_property(&self, sc: &mut LocalScope, key: PropertyKey) -> Result { - self.obj.delete_property(sc, key) + fn delete_property(&self, key: PropertyKey, sc: &mut LocalScope) -> Result { + self.obj.delete_property(key, sc) } - fn set_prototype(&self, sc: &mut LocalScope, value: Value) -> Result<(), Value> { - self.obj.set_prototype(sc, value) + fn set_prototype(&self, value: Value, sc: &mut LocalScope) -> Result<(), Value> { + self.obj.set_prototype(value, sc) } fn get_prototype(&self, sc: &mut LocalScope) -> Result { @@ -195,12 +195,12 @@ impl Object for TypedArray { fn apply( &self, - scope: &mut LocalScope, callee: ObjectId, this: This, args: CallArgs, + scope: &mut LocalScope, ) -> Result { - self.obj.apply(scope, callee, this, args) + self.obj.apply(callee, this, args, scope) } fn own_keys(&self, sc: &mut LocalScope<'_>) -> Result, Value> {