Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different JS execution contexts are not supported by isBasicObject() #9

Open
SimonSimCity opened this issue Feb 2, 2020 · 1 comment

Comments

@SimonSimCity
Copy link

Today I had a hard time debugging when trying to find out why a library I use doesn't work as expected.
The base root cause is by this library which checks if an object is a base-object.

It tries to do so by checking the prototype of new Object().

As I found out today, the prototype of a new object is not always the same. This becomes evident when running your code in a NodeJS vm.

const vm = require('vm');
global.MongoObject = require('mongo-object').default;


console.log(vm.runInNewContext(`MongoObject.isBasicObject({})`, { MongoObject: MongoObject }));
console.log(vm.runInThisContext(`MongoObject.isBasicObject({})`));

console.log(MongoObject.isBasicObject({}));

The code produces the following output:

false
true
true

Please find a way to check for plain objects without using the constructor or note at a place that this package is not stable when using in more than one NodeJS contexts.

@aldeed
Copy link
Collaborator

aldeed commented Feb 28, 2020

Any suggestions? A lot of trial and error went into getting the proper logic in isBasicObject a long time ago. So I'm hesitant to change it, but if there's some solution to this problem that's been documented elsewhere and all tests still pass, it's worth trying to support this use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants