Skip to content

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

@SimonSimCity

Description

@SimonSimCity

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions