dodona-edu / universal-judge

Universal judge for educational software testing
https://docs.dodona.be/en/tested
MIT License
9 stars 4 forks source link

JavaScript: consider alternative ways to create object as alternatives #505

Closed pdawyndt closed 4 weeks ago

pdawyndt commented 2 months ago

Initializing a JavaScript object as {} or as Object.create(null) should make no difference when checking object equality. However, this is currently not the case.

Example: https://dodona.be/exercises/1331474531/ To reproduce: replace {} by Object.create(null) in sample solution; where sample solution is evaluated as correct, the modified solution is not

niknetniko commented 2 months ago

This is the case because we currently use the constructor to detect if something is a "plain" object: value?.constructor === Object.

We can of course add a special case for objects created with Object.create(null), but is this what we want? I ask, since it isn't entirely clear to me what we should do, since:

> Object.create(null) === {}
false
> Object.create(null) == {}
false