diff --git a/lib/connection.js b/lib/connection.js index 2f847bffc2f..247fe8f58a9 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -81,7 +81,7 @@ function Connection(base) { * Inherit from EventEmitter */ -Connection.prototype.__proto__ = EventEmitter.prototype; +Object.setPrototypeOf(Connection.prototype, EventEmitter.prototype); /** * Connection ready state diff --git a/lib/drivers/node-mongodb-native/collection.js b/lib/drivers/node-mongodb-native/collection.js index b390fa1f349..54963c40c7d 100644 --- a/lib/drivers/node-mongodb-native/collection.js +++ b/lib/drivers/node-mongodb-native/collection.js @@ -34,7 +34,7 @@ function NativeCollection(name, conn, options) { * Inherit from abstract Collection. */ -NativeCollection.prototype.__proto__ = MongooseCollection.prototype; +Object.setPrototypeOf(NativeCollection.prototype, MongooseCollection.prototype); /** * Called when the connection opens. diff --git a/lib/drivers/node-mongodb-native/connection.js b/lib/drivers/node-mongodb-native/connection.js index 1adad7cd8b5..5c6976d92b4 100644 --- a/lib/drivers/node-mongodb-native/connection.js +++ b/lib/drivers/node-mongodb-native/connection.js @@ -32,7 +32,7 @@ NativeConnection.STATES = STATES; * Inherits from Connection. */ -NativeConnection.prototype.__proto__ = MongooseConnection.prototype; +Object.setPrototypeOf(NativeConnection.prototype, MongooseConnection.prototype); /** * Switches to a different database using the same connection pool. diff --git a/lib/model.js b/lib/model.js index 7ed676f0677..0c835c4ec01 100644 --- a/lib/model.js +++ b/lib/model.js @@ -126,7 +126,7 @@ function Model(doc, fields, skipId) { * top level (non-sub) documents. */ -Model.prototype.__proto__ = Document.prototype; +Object.setPrototypeOf(Model.prototype, Document.prototype); Model.prototype.$isMongooseModelPrototype = true; /** @@ -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]; - d.prototype.__proto__ = this.prototype; + Object.setPrototypeOf(d.prototype, this.prototype); Object.defineProperty(d, 'baseModelName', { value: this.modelName, configurable: true, @@ -4944,8 +4944,8 @@ Model.compile = function compile(name, schema, collectionName, connection, base) model.modelName = name; if (!(model.prototype instanceof Model)) { - model.__proto__ = Model; - model.prototype.__proto__ = Model.prototype; + Object.setPrototypeOf(model, Model); + Object.setPrototypeOf(model.prototype, Model.prototype); } model.model = function model(name) { return this.db.model(name); @@ -5037,8 +5037,8 @@ Model.__subclass = function subclass(conn, schema, collection) { _this.call(this, doc, fields, skipId); }; - Model.__proto__ = _this; - Model.prototype.__proto__ = _this.prototype; + Object.setPrototypeOf(Model, _this); + Object.setPrototypeOf(Model.prototype, _this.prototype); Model.db = conn; Model.prototype.db = conn; Model.prototype[modelDbSymbol] = conn; diff --git a/test/document.isselected.test.js b/test/document.isselected.test.js index d013eed5efb..3f25b34ac2f 100644 --- a/test/document.isselected.test.js +++ b/test/document.isselected.test.js @@ -27,7 +27,7 @@ function TestDocument() { * Inherits from Document. */ -TestDocument.prototype.__proto__ = Document.prototype; +Object.setPrototypeOf(TestDocument.prototype, Document.prototype); for (const i in EventEmitter.prototype) { TestDocument[i] = EventEmitter.prototype[i]; diff --git a/test/document.populate.test.js b/test/document.populate.test.js index 45a7c308ba8..efb8848cd98 100644 --- a/test/document.populate.test.js +++ b/test/document.populate.test.js @@ -30,7 +30,7 @@ function TestDocument() { * Inherits from Document. */ -TestDocument.prototype.__proto__ = Document.prototype; +Object.setPrototypeOf(TestDocument.prototype, Document.prototype); /** * Set a dummy schema to simulate compilation. diff --git a/test/document.test.js b/test/document.test.js index 816d6885f18..d1f36fd4b03 100644 --- a/test/document.test.js +++ b/test/document.test.js @@ -38,7 +38,7 @@ function TestDocument() { * Inherits from Document. */ -TestDocument.prototype.__proto__ = Document.prototype; +Object.setPrototypeOf(TestDocument.prototype, Document.prototype); for (const i in EventEmitter.prototype) { TestDocument[i] = EventEmitter.prototype[i]; diff --git a/test/document.unit.test.js b/test/document.unit.test.js index 0ebdc16dc1b..dbae16908ac 100644 --- a/test/document.unit.test.js +++ b/test/document.unit.test.js @@ -22,7 +22,7 @@ describe('sharding', function() { this.$__schema = mockSchema; this.$__ = {}; }; - Stub.prototype.__proto__ = mongoose.Document.prototype; + Object.setPrototypeOf(Stub.prototype, mongoose.Document.prototype); const d = new Stub(); const currentTime = new Date(); d._doc = { date: currentTime }; diff --git a/test/model.discriminator.test.js b/test/model.discriminator.test.js index 337dae25d6d..22f33166acf 100644 --- a/test/model.discriminator.test.js +++ b/test/model.discriminator.test.js @@ -96,8 +96,6 @@ 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() { diff --git a/test/schema.test.js b/test/schema.test.js index 4b7129ca46a..c09895de3b3 100644 --- a/test/schema.test.js +++ b/test/schema.test.js @@ -33,7 +33,7 @@ function TestDocument() { * Inherits from Document. */ -TestDocument.prototype.__proto__ = Document.prototype; +Object.setPrototypeOf(TestDocument.prototype, Document.prototype); /** * Test. diff --git a/test/types.document.test.js b/test/types.document.test.js index fc101692390..d30f6e45119 100644 --- a/test/types.document.test.js +++ b/test/types.document.test.js @@ -33,7 +33,7 @@ describe('types.document', function() { mongoose.Document.call(this, {}); } Dummy = _Dummy; - Dummy.prototype.__proto__ = mongoose.Document.prototype; + Object.setPrototypeOf(Dummy.prototype, mongoose.Document.prototype); Dummy.prototype.$__setSchema(new Schema()); function _Subdocument() { @@ -43,7 +43,7 @@ describe('types.document', function() { } Subdocument = _Subdocument; - Subdocument.prototype.__proto__ = ArraySubdocument.prototype; + Object.setPrototypeOf(Subdocument.prototype, ArraySubdocument.prototype); for (const i in EventEmitter.prototype) { Subdocument[i] = EventEmitter.prototype[i]; diff --git a/test/types.documentarray.test.js b/test/types.documentarray.test.js index 6ee188f9eb4..1ab1447e25d 100644 --- a/test/types.documentarray.test.js +++ b/test/types.documentarray.test.js @@ -29,7 +29,7 @@ function TestDoc(schema) { * Inherits from ArraySubdocument. */ - Subdocument.prototype.__proto__ = ArraySubdocument.prototype; + Object.setPrototypeOf(Subdocument.prototype, ArraySubdocument.prototype); /** * Set schema.