Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare optional parameters according to HTML standard #98

Merged
merged 1 commit into from
Nov 21, 2014

Conversation

lbolla
Copy link
Contributor

@lbolla lbolla commented Nov 21, 2014

According to
https://html.spec.whatwg.org/multipage/webappapis.html#timers timeout
and handles of setTimeout and friends are optional.

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

avikchaudhuri added a commit that referenced this pull request Nov 21, 2014
Declare optional parameters according to HTML standard
@avikchaudhuri avikchaudhuri merged commit 4693ff4 into facebook:master Nov 21, 2014
declare function clearTimeout(timeoutId: any): void;
declare function setTimeout(callback: any, ms: number, ...args: Array<any>): number;
declare function setInterval(callback: any, ms: number, ...args: Array<any>): number;
declare function clearInterval(intervalId?: number): void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these arguments to the clear functions should be optional?

@lbolla
Copy link
Contributor Author

lbolla commented Nov 22, 2014

From the HTML standard, it looks like the parameters of clearInterval and clearTimeout are indeed optional: https://html.spec.whatwg.org/#dom-windowtimers-cleartimeout
I hope I am not misinterpreting the standard, though.

@sophiebits
Copy link
Contributor

I see, the IDL does indeed mark them optional (though I'm unsure when that would be useful). I got confused by this section which makes them look required:

image

Still feels weird to me though – if you're just calling clearTimeout() or clearInterval() with no arguments, that sounds like a bug to me.

@fkling
Copy link

fkling commented Nov 22, 2014

It's true, the parameter is defined as optional:

interface WindowTimers {
  long setTimeout(Function handler, optional long timeout = 0, any... arguments);
  long setTimeout(DOMString handler, optional long timeout = 0, any... arguments);
  void clearTimeout(optional long handle = 0);
  long setInterval(Function handler, optional long timeout = 0, any... arguments);
  long setInterval(DOMString handler, optional long timeout = 0, any... arguments);
  void clearInterval(optional long handle = 0);
};

in which case 0 is assigned to handle.

However, I'd argue that 99% of the cases where no handle is passed, are errors.

@Daniel15
Copy link
Member

Wow, that's really strange. What's the expected behaviour if you call clearInterval or clearTimeout with no handle? How could that possibly ever be useful?

@fkling
Copy link

fkling commented Nov 22, 2014

@Daniel15 : The spec says that the function does nothing if the handle is not found in the handle list (I guess the handle 0 (the default value) is never in the list).

@Daniel15
Copy link
Member

@fkling Well, that's silly. I don't see any actual use for having a default value for handle. I'd love to meet whoever added that to the spec and ask them what they were thinking :)

@help999me
Copy link

I am being hack and is it i open an account for u all to use my mobile as conterbution ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants