php-technolog / wicked-good-xpath

Automatically exported from code.google.com/p/wicked-good-xpath
0 stars 0 forks source link

Error: Object doesn't support property or method 'each' when using IE8 #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Extract the attached zip file
2. Open the "test.html" file with IE
3. Click on the text box saying "click here"

What is the expected output? What do you see instead?
The expected output if an alert box with the Id of the text box "NOTWorksId", 
what I see instead is an error message saying: "Object doesn't support property 
or method 'each'"

What version of the product are you using? On what operating system?
Tested with the latest version and the error still occurs

Please provide any additional information below.
It only reproduces on IE8, I added the following tag to reproduce it also on 
IE9: 
"<meta http-equiv="X-UA-Compatible" content="IE=8" />"

Also, the order in which the scripts are added to the page matter, when 
switching them so that "wgxpath.install.js" will be before the "otherScript.js" 
it work fine. Unfortunately this is not an option for us.

We deliver some code together with wgxpath as a 3rd party for other sites to 
use, some sites have javascript similar to the javascript in the 
"otherScript.js" file, so we have no control over it.

You can place a breakpoint in the "filter" method in the "otherScript.js" file 
just before the error happens.

Original issue reported on code.google.com by michael....@gmail.com on 11 Feb 2013 at 10:58

Attachments:

GoogleCodeExporter commented 9 years ago
I haven't looked closely yet, but I wanted to let you know I do see this report 
and will be investigating soon.

Original comment by gden...@google.com on 12 Feb 2013 at 2:19

GoogleCodeExporter commented 9 years ago
Thanks for your quick response! 
Please let me know if you need any additional information.

Original comment by michael....@gmail.com on 17 Feb 2013 at 10:17

GoogleCodeExporter commented 9 years ago
I think there may be something wrong with your attached code. Take this snippet 
of code from otherScript.js:

1  function _each(iterator, context) {
2    for (var i = 0, length = this.length >>> 0; i < length; i++) {
3      if (i in this) iterator.call(context, this[i], i, this);
4    }
5  }
6  arrayProto.filter = MyEnumerable.filter;
7  arrayProto._each = MyEnumerable._each;

The definition of _each on line (1) appears to be unused, and 
MyEnumerable._each is never assigned, so line (7) appears to have no effect.

Original comment by gden...@google.com on 19 Feb 2013 at 7:20

GoogleCodeExporter commented 9 years ago
You are right, however the problem still remains even if you remove the _each 
method.
I investigated further our scenario and it seems to happen when ever 
prototype.js of version 1.7 is used (the was a bug there that caused this 
problem and they fixed it in 1.7.1).

I only now noticed that it is possible to compile the sources with the 
goog.NATIVE_ARRAY_PROTOTYPES flag set to "false" which will force the library 
not to use the Array.prototype functions.

Thank you for your time and I apologize for the taking up yours.

Original comment by michael....@gmail.com on 21 Feb 2013 at 5:46

GoogleCodeExporter commented 9 years ago
For your test case, wgxpath will call goog.array.filter when the document mode 
is older than that of IE9. In the presence of Array.proto.filter(), 
goog.array.filter calls the that particular filter function. In this case, the 
function resolves to the user-implemented one in otherScript.js.

  function each(iterator, context) {
    var index = 0;
    this._each(function(value) {
      iterator.call(context, value, index++);
    });
    return this;
  }

  function filter(iterator, context) {
    var results = [];
    this.each(function(value, index) {
      if (iterator.call(context, value, index))
        results.push(value);
    });
    return results;
  }

However, I don't see how calling "this.each()" in filter() should succeed, 
given that there's no each() function taking the argument (a function) you are 
passing. I am not sure if I was missing something or your implementation has 
issue. Could you check that? Thanks.

Original comment by zhoumoto...@gmail.com on 22 Feb 2013 at 11:00

GoogleCodeExporter commented 9 years ago
BTW, if you set goog.NATIVE_ARRAY_PROTOTYPES to "false", goog.array.filter will 
instead use the implementation in the Closure library, which avoids calling 
your own filter() function.

Original comment by zhoumoto...@gmail.com on 22 Feb 2013 at 11:03

GoogleCodeExporter commented 9 years ago
That's exactly what I want to achieve, I do not want a bad implementation of 
the Array functions to have an impact of the way that wgxpath works.

Original comment by michael....@gmail.com on 24 Feb 2013 at 7:38

GoogleCodeExporter commented 9 years ago
Since it was a buggy version of prototype.js adding a bogus method to the Array 
prototype, and since it can be fixed by upgrading to a newer version of 
prototype.js, I'm closing the bug.

Original comment by gden...@google.com on 25 Feb 2013 at 2:22