Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

PhantomJS doesn't iterate over the arguments object #11558

Closed
mgol opened this issue Aug 11, 2013 · 7 comments
Closed

PhantomJS doesn't iterate over the arguments object #11558

mgol opened this issue Aug 11, 2013 · 7 comments

Comments

@mgol
Copy link

mgol commented Aug 11, 2013

With the following test.js file:

var success = false;
(function f() {
    for (var i in arguments) {
        success = true;
    }
})(1);
console.log(success ? "Test passed!" : "Test failed!");

PhantomJS logs:

$ phantomjs test.js
Test failed!
@davidsmejia
Copy link

FWIW the following "passes"

var success = false;

(function f() {
    var args = Array.prototype.slice.call(arguments);
    for (var i in args) {
        success = true;
    }
})(1);

console.log(success ? "Test passed!" : "Test failed!");

@jdalton
Copy link
Contributor

jdalton commented Sep 5, 2013

Yap, this is just a bug in JavaScriptCore. I've worked around this in Lo-Dash, lodash.compat.js, with methods like _.forOwn and _.forIn. @kitcambridge wrote a great post over other issues in environments equiv to Safari < 5.1 that we've handled as well. Might make working in PhantomJS a bit easier.

@mgol
Copy link
Author

mgol commented Sep 5, 2013

@jdalton The problem is when you have such iteration in a library code. Since this is not polyfillable, the only way to make it work in PhantomJS is to patch vendor libraries which I try to avoid; every such a fork is a maintenance burden.

@jdalton
Copy link
Contributor

jdalton commented Sep 5, 2013

The problem is when you have such iteration in a library code

PhantomJS is based on WebKit/JSC and has bugs that can be found in equiv Safari browsers (desktop & mobile). If your library code doesn't work then you may want to extend support, as I did with Lodash. It's not insurmountable. If you don't want to support Safari ~5 then just be aware of its limitations/gotchas when you construct your test cases & usage scenarios for PhantomJS is all.

@mgol
Copy link
Author

mgol commented Sep 5, 2013

@jdalton That's the thing, I generally don't need to support Safari ~5 and some libs I use don't target it as well. jQuery 2.1/1.11 will even drop Safari 5.1, not mentioning 5.0.

This means that if you don't target old Safari and use libraries that don't do it either, you often can't do tests in PhantomJS. And it will only get worse over time.

@jdalton
Copy link
Contributor

jdalton commented Sep 5, 2013

This means that if you don't target old Safari and use libraries that don't do it either, you often can't do tests in PhantomJS. And it will only get worse over time.

Yes, not supporting an environment will make it harder to test in.
In the meantime, on the JSC side libs like es5-shim & Lodash can help with most compat issues.

@ariya
Copy link
Owner

ariya commented Aug 16, 2014

Fixed in Qt5-based master branch.

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

No branches or pull requests

4 participants