Skip to content

Commit 885f667

Browse files
committed
fix: defineProperty
1 parent 0f7d436 commit 885f667

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

crates/jsshaker/src/builtins/globals/object_constructor.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::borrow::BorrowMut;
22

3+
use oxc::allocator;
4+
35
use crate::{
46
Analyzer,
57
builtins::Builtins,
@@ -27,6 +29,10 @@ impl<'a> Builtins<'a> {
2729
"defineProperty" => self.create_object_define_property_impl(),
2830
"create" => self.create_object_create_impl(),
2931
"is" => self.create_object_is_impl(),
32+
"setPrototypeOf" => factory.unknown,
33+
"getPrototypeOf" => factory.pure_fn_returns_unknown,
34+
"defineProperties" => factory.unknown,
35+
"hasOwn" => factory.pure_fn_returns_boolean,
3036
"preventExtensions" => factory.unknown,
3137
"seal" => factory.unknown,
3238
"getOwnPropertyNames" => factory.unknown,
@@ -186,7 +192,8 @@ impl<'a> Builtins<'a> {
186192
break 'trackable;
187193
}
188194
let enumerated = descriptor.enumerate_properties(analyzer, dep);
189-
let mut value = analyzer.factory.undefined;
195+
let mut value = None;
196+
let mut deps = vec![];
190197
for (definite, key, value2) in enumerated.known.into_values() {
191198
if !definite {
192199
break 'trackable;
@@ -196,25 +203,42 @@ impl<'a> Builtins<'a> {
196203
};
197204
match key_str.as_str() {
198205
"value" => {
199-
value = self.factory.computed(value2, (key, value));
206+
value = Some(self.factory.computed(value2, (key, value)));
200207
}
201208
"get" => {
202209
// FIXME: This is not safe, but OK for now.
203-
value = self.factory.computed_unknown((value2, key, value));
210+
value = Some(self.factory.computed_unknown((value2, key, value)));
204211
}
205212
"set" | "enumerable" | "configurable" | "writable" => {
206213
// TODO: actually handle these
207-
value = self.factory.computed(value, (key, value2));
214+
deps.push(key);
215+
deps.push(value2);
208216
}
209217
_ => {}
210218
}
211219
}
220+
if value.is_none() {
221+
analyzer.push_non_det_cf_scope();
222+
}
223+
212224
object.set_property(
213225
analyzer,
214226
analyzer.factory.dep((enumerated.dep, descriptor.get_shallow_dep(analyzer))),
215227
key,
216-
value,
228+
{
229+
let value = value.unwrap_or(analyzer.factory.undefined);
230+
if deps.is_empty() {
231+
value
232+
} else {
233+
analyzer
234+
.factory
235+
.computed(value, allocator::Vec::from_iter_in(deps, analyzer.allocator))
236+
}
237+
},
217238
);
239+
if value.is_none() {
240+
analyzer.pop_cf_scope();
241+
}
218242
return object;
219243
}
220244

0 commit comments

Comments
 (0)