Closed Bug 902965 Opened 11 years ago Closed 11 years ago

setTimeout from content-script behaves crazy

Categories

(Add-on SDK Graveyard :: General, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: gkrizsanits, Assigned: gkrizsanits)

Details

Attachments

(2 files)

It has all sort of issues like Bug 689615 or throwing exceptions like 
error: mozwebcompatreporter: An exception occurred.
[object Object]

or forgetting xray waivers... 

from IRC:

17:40 <hallvors> something like this...
<hallvors> var elm = foo.wrappedJSObject;
<hallvors> setTimeout(function(){ elm.style.color='red' }, 100)
17:41 <hallvors> in normal JS, elm would be defined because the anonymous function has closure data
<hallvors> in the extension it seems elm is undefined when the timeout runs
Assignee: nobody → gkrizsanits
My best guess (not being familiar with any of this) is that XRay wrappers may not be properly reference counted in content scripts, so that the XRay objects are garbage collected or deleted before the timeout occurs, even though they should be referenced from the timeout's closure data. (But another reasonable guess is that scopes get messed up, so that the timeout runs in a scope where these variables really don't exist..)

Either way, fixing this needs spec'ing how setTimeout in a content-script should behave. IMO the code should run in the content-script scope, having to use unsafeWindow and similar APIs for more direct access to the page's scope.

(If any of this didn't make sense or wasn't useful please ignore this newbie ;-))
Further debugging (thanks zombie_ on IRC) shows that setTimeout() is not the culprit and I was imagining problems because the code is running in an unexpected scope to begin with.
please re-open if you think this is still a problem
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → INVALID
There is one remaining problem here: the "[object Object]" error console output makes no sense and the exception was most unhelpful for any debugging. That's obviously not as high-pri as a messed up scope or closure problem in the engine, but gabor might want to keep this bug open to track it and fix it. I'll leave that to him.
(In reply to Hallvord R. M. Steen from comment #5)
> There is one remaining problem here: the "[object Object]" error console
> output makes

Do you know where is it coming from? It looks to me that someone is throwing an object with no toString on it (other than the one on Object.prototype). Is there a way to create a minimalistic reproducible test case for this?
No idea, but I'll see if I can reproduce in a minimal extension..
Attached file testme-902965.xpi
basic extension - install it and load example.com, check error console..
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: