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

Revert "Use setPrototypeOf() instead of __proto__ to allow running on Deno" #12314

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function Connection(base) {
* Inherit from EventEmitter
*/

Object.setPrototypeOf(Connection.prototype, EventEmitter.prototype);
Connection.prototype.__proto__ = EventEmitter.prototype;

/**
* Connection ready state
Expand Down
2 changes: 1 addition & 1 deletion lib/drivers/node-mongodb-native/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function NativeCollection(name, conn, options) {
* Inherit from abstract Collection.
*/

Object.setPrototypeOf(NativeCollection.prototype, MongooseCollection.prototype);
NativeCollection.prototype.__proto__ = MongooseCollection.prototype;

/**
* Called when the connection opens.
Expand Down
2 changes: 1 addition & 1 deletion lib/drivers/node-mongodb-native/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ NativeConnection.STATES = STATES;
* Inherits from Connection.
*/

Object.setPrototypeOf(NativeConnection.prototype, MongooseConnection.prototype);
NativeConnection.prototype.__proto__ = MongooseConnection.prototype;

/**
* Switches to a different database using the same connection pool.
Expand Down
12 changes: 6 additions & 6 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function Model(doc, fields, skipId) {
* top level (non-sub) documents.
*/

Object.setPrototypeOf(Model.prototype, Document.prototype);
Model.prototype.__proto__ = Document.prototype;
Model.prototype.$isMongooseModelPrototype = true;

/**
Expand Down Expand Up @@ -1218,7 +1218,7 @@ Model.discriminator = function(name, schema, options) {
model = this.db.model(model || name, schema, this.$__collection.name);
this.discriminators[name] = model;
const d = this.discriminators[name];
Object.setPrototypeOf(d.prototype, this.prototype);
d.prototype.__proto__ = this.prototype;
Object.defineProperty(d, 'baseModelName', {
value: this.modelName,
configurable: true,
Expand Down Expand Up @@ -4944,8 +4944,8 @@ Model.compile = function compile(name, schema, collectionName, connection, base)
model.modelName = name;

if (!(model.prototype instanceof Model)) {
Object.setPrototypeOf(model, Model);
Object.setPrototypeOf(model.prototype, Model.prototype);
model.__proto__ = Model;
model.prototype.__proto__ = Model.prototype;
}
model.model = function model(name) {
return this.db.model(name);
Expand Down Expand Up @@ -5037,8 +5037,8 @@ Model.__subclass = function subclass(conn, schema, collection) {
_this.call(this, doc, fields, skipId);
};

Object.setPrototypeOf(Model, _this);
Object.setPrototypeOf(Model.prototype, _this.prototype);
Model.__proto__ = _this;
Model.prototype.__proto__ = _this.prototype;
Model.db = conn;
Model.prototype.db = conn;
Model.prototype[modelDbSymbol] = conn;
Expand Down
2 changes: 1 addition & 1 deletion test/document.isselected.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function TestDocument() {
* Inherits from Document.
*/

Object.setPrototypeOf(TestDocument.prototype, Document.prototype);
TestDocument.prototype.__proto__ = Document.prototype;

for (const i in EventEmitter.prototype) {
TestDocument[i] = EventEmitter.prototype[i];
Expand Down
2 changes: 1 addition & 1 deletion test/document.populate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function TestDocument() {
* Inherits from Document.
*/

Object.setPrototypeOf(TestDocument.prototype, Document.prototype);
TestDocument.prototype.__proto__ = Document.prototype;

/**
* Set a dummy schema to simulate compilation.
Expand Down
2 changes: 1 addition & 1 deletion test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function TestDocument() {
* Inherits from Document.
*/

Object.setPrototypeOf(TestDocument.prototype, Document.prototype);
TestDocument.prototype.__proto__ = Document.prototype;

for (const i in EventEmitter.prototype) {
TestDocument[i] = EventEmitter.prototype[i];
Expand Down
2 changes: 1 addition & 1 deletion test/document.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('sharding', function() {
this.$__schema = mockSchema;
this.$__ = {};
};
Object.setPrototypeOf(Stub.prototype, mongoose.Document.prototype);
Stub.prototype.__proto__ = mongoose.Document.prototype;
const d = new Stub();
const currentTime = new Date();
d._doc = { date: currentTime };
Expand Down
2 changes: 2 additions & 0 deletions test/model.discriminator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ describe('model', function() {
const employee = new Employee();
assert.ok(employee instanceof Person);
assert.ok(employee instanceof Employee);
assert.strictEqual(employee.__proto__.constructor, Employee);
assert.strictEqual(employee.__proto__.__proto__.constructor, Person);
});

it('can define static and instance methods', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function TestDocument() {
* Inherits from Document.
*/

Object.setPrototypeOf(TestDocument.prototype, Document.prototype);
TestDocument.prototype.__proto__ = Document.prototype;

/**
* Test.
Expand Down
4 changes: 2 additions & 2 deletions test/types.document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('types.document', function() {
mongoose.Document.call(this, {});
}
Dummy = _Dummy;
Object.setPrototypeOf(Dummy.prototype, mongoose.Document.prototype);
Dummy.prototype.__proto__ = mongoose.Document.prototype;
Dummy.prototype.$__setSchema(new Schema());

function _Subdocument() {
Expand All @@ -43,7 +43,7 @@ describe('types.document', function() {
}
Subdocument = _Subdocument;

Object.setPrototypeOf(Subdocument.prototype, ArraySubdocument.prototype);
Subdocument.prototype.__proto__ = ArraySubdocument.prototype;

for (const i in EventEmitter.prototype) {
Subdocument[i] = EventEmitter.prototype[i];
Expand Down
2 changes: 1 addition & 1 deletion test/types.documentarray.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function TestDoc(schema) {
* Inherits from ArraySubdocument.
*/

Object.setPrototypeOf(Subdocument.prototype, ArraySubdocument.prototype);
Subdocument.prototype.__proto__ = ArraySubdocument.prototype;

/**
* Set schema.
Expand Down