Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 345720 - [libraries] Window.prototype.setTimeout has wrong return type
Summary: [libraries] Window.prototype.setTimeout has wrong return type
Status: RESOLVED FIXED
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 minor (vote)
Target Milestone: 3.2.5   Edit
Assignee: Lalit Somavarapha CLA
QA Contact: Nitin Dahyabhai CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-13 07:44 EDT by Dusan Smolnikar CLA
Modified: 2011-09-23 11:42 EDT (History)
2 users (show)

See Also:
thatnitind: review+
cmjaun: review+


Attachments
Patch (804 bytes, patch)
2011-06-15 13:27 EDT, Lalit Somavarapha CLA
no flags Details | Diff
patch (1.10 KB, patch)
2011-06-16 09:40 EDT, Lalit Somavarapha CLA
no flags Details | Diff
updated patch (1.09 KB, patch)
2011-06-17 11:51 EDT, Lalit Somavarapha CLA
cmjaun: iplog+
llsomava: review?
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.