Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 345720

Summary: [libraries] Window.prototype.setTimeout has wrong return type
Product: [WebTools] JSDT Reporter: Dusan Smolnikar <dusan.smolnikar>
Component: GeneralAssignee: Lalit Somavarapha <llsomava>
Status: RESOLVED FIXED QA Contact: Nitin Dahyabhai <thatnitind>
Severity: minor    
Priority: P3 CC: cmjaun, llsomava
Version: unspecifiedFlags: thatnitind: review+
cmjaun: review+
Target Milestone: 3.2.5   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
Patch
none
patch
none
updated patch cmjaun: iplog+, llsomava: review?

Description Dusan Smolnikar CLA 2011-05-13 07:44:50 EDT
Build Identifier: M20110210-1200

In js.browserWindow file, setTimeout function is defined:
/**
 * function setTimeout(arg1, arg2) 
 * @param {Object} arg1
 * @param {Number} arg2
 * @memberOf  Window
 * @returns {Object}
 */
Window.prototype.setTimeout=function(arg1, arg2){return new Object();};

However, the return type of setTimeout function is a number, as seen using the test code:
var test = window.setTimeout(function(){}, 1); alert(typeof test);
Tested on Firefox 4, Safari 5 and Opera 11.

Reproducible: Always

Steps to Reproduce:
In eclipse preferences go to:
JavaScript > Validator > Error/Warnings
and enable JavaScript semantic validation.

Now in a javascript file, enter the following code:

var test = { to : -1 };
test.to = window.setTimeout(function(){}, 1);

Second line now throws a warning:
cannot convert from Object to Number
Comment 1 Lalit Somavarapha CLA 2011-06-15 13:27:31 EDT
Created attachment 198042 [details]
Patch
Comment 2 Nitin Dahyabhai CLA 2011-06-15 16:02:25 EDT
I suspect the JSDoc is overriding what the InferEngine would do with the returned value itself, because I'd expect it to need to return a number rather than Number itself.
Comment 3 Chris Jaun CLA 2011-06-15 16:22:23 EDT
Yeah....I think the JSdoc takes over....it still should return just a "1" or something like that to keep it simple.
Comment 4 Dusan Smolnikar CLA 2011-06-15 16:51:05 EDT
I think the same should be applied to window.setInterval() as well
Comment 5 Lalit Somavarapha CLA 2011-06-16 09:40:23 EDT
Created attachment 198103 [details]
patch
Comment 6 Nitin Dahyabhai CLA 2011-06-16 15:10:40 EDT
Lalit, please incorporate Chris' feedback from comment 3.  The function contents should return *a* number, not Number itself.
Comment 7 Lalit Somavarapha CLA 2011-06-17 11:51:56 EDT
Created attachment 198190 [details]
updated patch
Comment 8 Chris Jaun CLA 2011-06-17 14:30:53 EDT
Good to go as soon as we get Nitin's "+".
Comment 9 Chris Jaun CLA 2011-06-17 14:52:31 EDT
Checked into HEAD and 3.2.5.