Skip to content

Commit 2de1a86

Browse files
Merge pull request #12314 from Automattic/revert-12313-vkarpov15/gh-9056
Revert "Use setPrototypeOf() instead of __proto__ to allow running on Deno"
2 parents ca5cc2c + 0453a91 commit 2de1a86

12 files changed

+19
-17
lines changed

lib/connection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function Connection(base) {
8181
* Inherit from EventEmitter
8282
*/
8383

84-
Object.setPrototypeOf(Connection.prototype, EventEmitter.prototype);
84+
Connection.prototype.__proto__ = EventEmitter.prototype;
8585

8686
/**
8787
* Connection ready state

lib/drivers/node-mongodb-native/collection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function NativeCollection(name, conn, options) {
3434
* Inherit from abstract Collection.
3535
*/
3636

37-
Object.setPrototypeOf(NativeCollection.prototype, MongooseCollection.prototype);
37+
NativeCollection.prototype.__proto__ = MongooseCollection.prototype;
3838

3939
/**
4040
* Called when the connection opens.

lib/drivers/node-mongodb-native/connection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ NativeConnection.STATES = STATES;
3232
* Inherits from Connection.
3333
*/
3434

35-
Object.setPrototypeOf(NativeConnection.prototype, MongooseConnection.prototype);
35+
NativeConnection.prototype.__proto__ = MongooseConnection.prototype;
3636

3737
/**
3838
* Switches to a different database using the same connection pool.

lib/model.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function Model(doc, fields, skipId) {
126126
* top level (non-sub) documents.
127127
*/
128128

129-
Object.setPrototypeOf(Model.prototype, Document.prototype);
129+
Model.prototype.__proto__ = Document.prototype;
130130
Model.prototype.$isMongooseModelPrototype = true;
131131

132132
/**
@@ -1218,7 +1218,7 @@ Model.discriminator = function(name, schema, options) {
12181218
model = this.db.model(model || name, schema, this.$__collection.name);
12191219
this.discriminators[name] = model;
12201220
const d = this.discriminators[name];
1221-
Object.setPrototypeOf(d.prototype, this.prototype);
1221+
d.prototype.__proto__ = this.prototype;
12221222
Object.defineProperty(d, 'baseModelName', {
12231223
value: this.modelName,
12241224
configurable: true,
@@ -4944,8 +4944,8 @@ Model.compile = function compile(name, schema, collectionName, connection, base)
49444944
model.modelName = name;
49454945

49464946
if (!(model.prototype instanceof Model)) {
4947-
Object.setPrototypeOf(model, Model);
4948-
Object.setPrototypeOf(model.prototype, Model.prototype);
4947+
model.__proto__ = Model;
4948+
model.prototype.__proto__ = Model.prototype;
49494949
}
49504950
model.model = function model(name) {
49514951
return this.db.model(name);
@@ -5037,8 +5037,8 @@ Model.__subclass = function subclass(conn, schema, collection) {
50375037
_this.call(this, doc, fields, skipId);
50385038
};
50395039

5040-
Object.setPrototypeOf(Model, _this);
5041-
Object.setPrototypeOf(Model.prototype, _this.prototype);
5040+
Model.__proto__ = _this;
5041+
Model.prototype.__proto__ = _this.prototype;
50425042
Model.db = conn;
50435043
Model.prototype.db = conn;
50445044
Model.prototype[modelDbSymbol] = conn;

test/document.isselected.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function TestDocument() {
2727
* Inherits from Document.
2828
*/
2929

30-
Object.setPrototypeOf(TestDocument.prototype, Document.prototype);
30+
TestDocument.prototype.__proto__ = Document.prototype;
3131

3232
for (const i in EventEmitter.prototype) {
3333
TestDocument[i] = EventEmitter.prototype[i];

test/document.populate.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function TestDocument() {
3030
* Inherits from Document.
3131
*/
3232

33-
Object.setPrototypeOf(TestDocument.prototype, Document.prototype);
33+
TestDocument.prototype.__proto__ = Document.prototype;
3434

3535
/**
3636
* Set a dummy schema to simulate compilation.

test/document.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function TestDocument() {
3838
* Inherits from Document.
3939
*/
4040

41-
Object.setPrototypeOf(TestDocument.prototype, Document.prototype);
41+
TestDocument.prototype.__proto__ = Document.prototype;
4242

4343
for (const i in EventEmitter.prototype) {
4444
TestDocument[i] = EventEmitter.prototype[i];

test/document.unit.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('sharding', function() {
2222
this.$__schema = mockSchema;
2323
this.$__ = {};
2424
};
25-
Object.setPrototypeOf(Stub.prototype, mongoose.Document.prototype);
25+
Stub.prototype.__proto__ = mongoose.Document.prototype;
2626
const d = new Stub();
2727
const currentTime = new Date();
2828
d._doc = { date: currentTime };

test/model.discriminator.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ describe('model', function() {
9696
const employee = new Employee();
9797
assert.ok(employee instanceof Person);
9898
assert.ok(employee instanceof Employee);
99+
assert.strictEqual(employee.__proto__.constructor, Employee);
100+
assert.strictEqual(employee.__proto__.__proto__.constructor, Person);
99101
});
100102

101103
it('can define static and instance methods', function() {

test/schema.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function TestDocument() {
3333
* Inherits from Document.
3434
*/
3535

36-
Object.setPrototypeOf(TestDocument.prototype, Document.prototype);
36+
TestDocument.prototype.__proto__ = Document.prototype;
3737

3838
/**
3939
* Test.

test/types.document.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('types.document', function() {
3333
mongoose.Document.call(this, {});
3434
}
3535
Dummy = _Dummy;
36-
Object.setPrototypeOf(Dummy.prototype, mongoose.Document.prototype);
36+
Dummy.prototype.__proto__ = mongoose.Document.prototype;
3737
Dummy.prototype.$__setSchema(new Schema());
3838

3939
function _Subdocument() {
@@ -43,7 +43,7 @@ describe('types.document', function() {
4343
}
4444
Subdocument = _Subdocument;
4545

46-
Object.setPrototypeOf(Subdocument.prototype, ArraySubdocument.prototype);
46+
Subdocument.prototype.__proto__ = ArraySubdocument.prototype;
4747

4848
for (const i in EventEmitter.prototype) {
4949
Subdocument[i] = EventEmitter.prototype[i];

test/types.documentarray.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function TestDoc(schema) {
2929
* Inherits from ArraySubdocument.
3030
*/
3131

32-
Object.setPrototypeOf(Subdocument.prototype, ArraySubdocument.prototype);
32+
Subdocument.prototype.__proto__ = ArraySubdocument.prototype;
3333

3434
/**
3535
* Set schema.

0 commit comments

Comments
 (0)