nikseras / js-test-driver

Automatically exported from code.google.com/p/js-test-driver
0 stars 0 forks source link

Extending "Object" prototype crashes. #374

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a single JS file with the following code:

Object.prototype.extend = function() {
    throw new Error('#epicfail');
};

2. Include it as the only file you want to load inside the captured browser.

What is the expected output? What do you see instead?
In normal conditions, this code should not do anything at all. But it seems 
that this extension interferes with something and makes the JsTestDriver 
JavaScript code to crash.

What version of the product are you using? On what operating system?
Currently using the featured download of JsTestDriver.jar, at version 1.3.4.b.

Please provide any additional information below.
It seems that the problem is not related with JsTestDriver, but with jQuery. 
The point where the bug happens is at the "param" function (located at 
jQuery.param). This function has a for ... in with no "hasOwnProperty" control, 
including inside the loop the "extend" method added by the code.

Unfortunately, this "bug" is still present in jQuery 1.7, so it needs to be 
manually fixed:

This: "for(var f in a)ca(f,a[f],b,e)"
Needs to be changed to this: "for(var f in 
a){a.hasOwnProperty(f)&&ca(f,a[f],b,e)}"

(without quotes!)

Original issue reported on code.google.com by miguel.j...@gmail.com on 20 May 2012 at 12:39

GoogleCodeExporter commented 8 years ago
I'm not even going to try to retrofit the code to deal with extending the core 
Object. Yes, I know this means that prototype.js won't work, as well as a 
couple of other frameworks.

I will take patches, though.

Original comment by corbinrs...@gmail.com on 7 Jun 2012 at 9:00