mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
stream: fix Writable instanceof for subclasses
The current custom instanceof for `Writable` subclasses previously returned false positives for instances of *other* subclasses of `Writable` because it was inherited by these subclasses. Fixes: https://github.com/nodejs/node/issues/14943 PR-URL: https://github.com/nodejs/node/pull/14945 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
2 files changed
+7
No files matched your search
@@ -179,6 +179,8 @@ if (typeof Symbol === 'function' && Symbol.hasInstance) {
|
||||
value: function(object) {
|
||||
if (realHasInstance.call(this, object))
|
||||
return true;
|
||||
if (this !== Writable)
|
||||
return false;
|
||||
|
||||
return object && object._writableState instanceof WritableState;
|
||||
}
|
||||
|
||||
@@ -56,3 +56,8 @@ common.expectsError(
|
||||
message: 'undefined does not inherit from CustomWritable'
|
||||
}
|
||||
);
|
||||
|
||||
class OtherCustomWritable extends Writable {}
|
||||
|
||||
assert(!(new OtherCustomWritable() instanceof CustomWritable));
|
||||
assert(!(new CustomWritable() instanceof OtherCustomWritable));
|
||||
Reference in new issue
Block a user