Primitives don't find prototyped methods added by eval from another frame

RESOLVED WORKSFORME

Status

()

Core
JavaScript Engine
RESOLVED WORKSFORME
11 years ago
5 years ago

People

(Reporter: Ish, Unassigned)

Tracking

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(URL)

(Reporter)

Description

11 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0

When adding methods/properties to prototypes of primitives (such as String/Number) via eval() through a different frame, they cannot be found by the primitives. This works fine for non-primitives (new String instead of ""). 

Reproducible: Always

Steps to Reproduce:
Scenario: a single frame in a frameset, trying to add the .test method to primitive strings in the "top" window via "eval".

Code that fails with "s.test is not a function":
top.eval("String.prototype.test=function () {}; var s='hello'; s.test();");

Code that works:
top.eval("String.prototype.test=function () {}; var s=new String('hello'); s.test();");
I can reproduce this.
Status: UNCONFIRMED → NEW
Ever confirmed: true
I can't reproduce in Firefox 19 or in a nightly, using this testcase:

data:text/html;charset=UTF-8,<iframe%20src="data:text/html;charset=UTF-8,&lt;script&gt;%20top.eval(&quot;String.prototype.test%20=%20function(){};%20%20var%20s%20=%20'hello';%20try%20{%20s.test();%20alert('PASS');%20}%20catch%20(e)%20{%20alert('FAIL:%20'%20+%20e);%20}&quot;);%20%20&lt;/script&gt;"></iframe>

Given the original URL reported here is 404, and given the above, I think this is WFM.  But maybe some other testcase would demonstrate the bug, or maybe my testcase is wrong somehow.  Please point out where I've gone wrong here!
I just check and Firefox 17 seems to be the last mayor release where this bug reproduces.
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.