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

IE Non-Enumerable properties #2064

Merged
merged 3 commits into from
Feb 20, 2015
Merged

Conversation

jridgewell
Copy link
Collaborator

I’m not sure what we were doing before with the FuncProto

@jdalton: mind giving this a review?

@paulfalgout
Copy link
Contributor

This seems to work in IE8. Beat me to it. If you're waiting for @jdalton to review.. it might be awhile.. he's been banned.

@jridgewell
Copy link
Collaborator Author

I've got it working in IE6 and 8, so I think we're set.

If you're waiting for @jdalton to review.. it might be awhile.. he's been banned.

Well, it's been one of those days.

@jashkenas
Copy link
Owner

What's the difference from the previous implementation?

@jridgewell
Copy link
Collaborator Author

The only important change is determining the prototype to compare to.

@@ -894,17 +896,21 @@

   // Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
   var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString');
-  var nonEnumerableProps = ['constructor', 'valueOf', 'isPrototypeOf', 'toString',
+  var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
                       'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];

   function collectNonEnumProps(obj, keys) {
     var nonEnumIdx = nonEnumerableProps.length;
-    var proto = typeof obj.constructor === 'function' ? FuncProto : ObjProto;
+    var constructor = obj.constructor;
+    var proto = (_.isFunction(constructor) && constructor.prototype) || ObjProto;
+
+    // Constructor is a special case.
+    var prop = 'constructor';
+    if (_.has(obj, prop) && !_.contains(keys, prop)) keys.push(prop);

     while (nonEnumIdx--) {
-      var prop = nonEnumerableProps[nonEnumIdx];
-      if (prop === 'constructor' ? _.has(obj, prop) : prop in obj &&
-        obj[prop] !== proto[prop] && !_.contains(keys, prop)) {
+      prop = nonEnumerableProps[nonEnumIdx];
+      if (prop in obj && obj[prop] !== proto[prop] && !_.contains(keys, prop)) {
         keys.push(prop);
       }
     }

@paulfalgout
Copy link
Contributor

The only functional change I see really is using obj.constructor.prototype vs FuncProto

@jashkenas
Copy link
Owner

Kill the "fasley"s?

@megawac
Copy link
Collaborator

megawac commented Feb 20, 2015

LGTM 👍

@jridgewell
Copy link
Collaborator Author

The only functional change I see really is using obj.constructor.prototype vs FuncProto

That's what I meant.

Kill the "fasley"s?

But they pass? And it's good to test edge cases.


Travis is erroring because of issues with 173a7fa. #2065

@paulfalgout
Copy link
Contributor

That's what I meant.

You're too quick for me

The tests should say "falsey" I think right?

jashkenas added a commit that referenced this pull request Feb 20, 2015
@jashkenas jashkenas merged commit 3abc3c9 into jashkenas:master Feb 20, 2015

//null edge cases
var oCon = {'constructor': Object};
deepEqual(_.map([null, undefined, 5, {}], _.partial(_.isMatch, _, oCon)), [false, false, false, true], 'doesnt fasley match constructor on undefined/null');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"fasley" should be "falsey"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants