diff --git a/crates/dash_middle/src/interner.rs b/crates/dash_middle/src/interner.rs index 605c6e5b..8461a623 100644 --- a/crates/dash_middle/src/interner.rs +++ b/crates/dash_middle/src/interner.rs @@ -267,6 +267,7 @@ pub mod sym { zero: "0", one: "1", getPrototypeOf, + setPrototypeOf, isPrototypeOf, arguments, propertyIsEnumerable, diff --git a/crates/dash_node_impl/src/lib.rs b/crates/dash_node_impl/src/lib.rs index e2ee6bd7..034db8e0 100644 --- a/crates/dash_node_impl/src/lib.rs +++ b/crates/dash_node_impl/src/lib.rs @@ -65,6 +65,17 @@ async fn run_inner_fallible(path: &str, opt: OptLevel, initial_gc_threshold: Opt State::from_vm_mut(rt.vm_mut()).store.insert(Nodejs, state); rt.vm_mut().with_scope(|scope| { + let global = scope.global(); + let global_k = scope.intern("global"); + global + .clone() + .set_property( + scope, + global_k.into(), + PropertyValue::static_default(Value::Object(global)), + ) + .unwrap(); + anyhow::Ok( execute_node_module(scope, path, path, &entry, opt, global_state, Rc::new(package_state)).map_err( |err| match err { diff --git a/crates/dash_vm/src/js_std/object.rs b/crates/dash_vm/src/js_std/object.rs index 1826d01f..f85694b9 100644 --- a/crates/dash_vm/src/js_std/object.rs +++ b/crates/dash_vm/src/js_std/object.rs @@ -213,6 +213,13 @@ pub fn get_prototype_of(cx: CallContext) -> Result { obj.get_prototype(cx.scope) } +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)?; + Ok(Value::Object(obj)) +} + pub fn is_prototype_of(cx: CallContext) -> Result { let target_proto = Value::Object(cx.this.to_object(cx.scope)?); let this_proto = cx.args.first().unwrap_or_undefined(); diff --git a/crates/dash_vm/src/lib.rs b/crates/dash_vm/src/lib.rs index dc09ce31..58adfd19 100644 --- a/crates/dash_vm/src/lib.rs +++ b/crates/dash_vm/src/lib.rs @@ -244,6 +244,7 @@ impl Vm { (sym::entries, scope.statics.object_entries.clone()), (sym::assign, scope.statics.object_assign.clone()), (sym::getPrototypeOf, scope.statics.object_get_prototype_of.clone()), + (sym::setPrototypeOf, scope.statics.object_set_prototype_of.clone()), ], [], [], diff --git a/crates/dash_vm/src/statics.rs b/crates/dash_vm/src/statics.rs index 17b43a63..d0bea52c 100644 --- a/crates/dash_vm/src/statics.rs +++ b/crates/dash_vm/src/statics.rs @@ -82,6 +82,7 @@ pub struct Statics { pub object_assign: Handle, pub object_entries: Handle, pub object_get_prototype_of: Handle, + pub object_set_prototype_of: Handle, pub object_is_prototype_of: Handle, pub object_property_is_enumerable: Handle, pub number_ctor: Handle, @@ -298,6 +299,7 @@ impl Statics { object_assign: function(gc, sym::assign, js_std::object::assign), object_entries: function(gc, sym::entries, js_std::object::entries), object_get_prototype_of: function(gc, sym::getPrototypeOf, js_std::object::get_prototype_of), + object_set_prototype_of: function(gc, sym::setPrototypeOf, js_std::object::set_prototype_of), object_is_prototype_of: function(gc, sym::isPrototypeOf, js_std::object::is_prototype_of), object_property_is_enumerable: function( gc,