Skip to content

Commit

Permalink
Make sure object prototype methods are not considered to be falsy (#2652
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lukastaegert committed Jan 19, 2019
1 parent 1633675 commit cb3829b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/ast/nodes/ObjectExpression.ts
Expand Up @@ -78,6 +78,7 @@ export default class ObjectExpression extends NodeBase {
if (
path.length === 1 &&
!this.propertyMap[key] &&
!objectMembers[key] &&
this.unmatchablePropertiesRead.length === 0
) {
if (!this.expressionsToBeDeoptimized[key]) {
Expand Down Expand Up @@ -167,8 +168,8 @@ export default class ObjectExpression extends NodeBase {
for (const property of typeof key !== 'string'
? this.properties
: this.propertyMap[key]
? this.propertyMap[key].propertiesRead
: []) {
? this.propertyMap[key].propertiesRead
: []) {
if (property.hasEffectsWhenAccessedAtPath(subPath, options)) return true;
}
return false;
Expand All @@ -191,10 +192,10 @@ export default class ObjectExpression extends NodeBase {
for (const property of typeof key !== 'string'
? this.properties
: path.length > 1
? this.propertyMap[key].propertiesRead
: this.propertyMap[key]
? this.propertyMap[key].propertiesSet
: []) {
? this.propertyMap[key].propertiesRead
: this.propertyMap[key]
? this.propertyMap[key].propertiesSet
: []) {
if (property.hasEffectsWhenAssignedAtPath(subPath, options)) return true;
}
return false;
Expand Down
@@ -0,0 +1,3 @@
module.exports = {
description: 'regards builtin methods as truthy in objects'
};
5 changes: 5 additions & 0 deletions test/function/samples/builtin-prototypes/truthiness/main.js
@@ -0,0 +1,5 @@
if (!{}.hasOwnProperty) {
throw new Error('Prototype method evaluated as falsy');
}

assert.strictEqual({}.hasOwnProperty ? true : false, true);

0 comments on commit cb3829b

Please sign in to comment.