Enforce linking to spec for method implementations via macros

This commit is contained in:
Corey Farwell 2015-08-31 19:19:08 -04:00
parent 7474b29510
commit 3a1d140ab5
23 changed files with 137 additions and 11 deletions

View file

@ -334,5 +334,6 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
rval rval
} }
// https://drafts.csswg.org/cssom/#cssstyledeclaration
css_properties_accessors!(css_properties); css_properties_accessors!(css_properties);
} }

View file

@ -357,6 +357,7 @@ impl DedicatedWorkerGlobalScopeMethods for DedicatedWorkerGlobalScope {
Ok(()) Ok(())
} }
// https://html.spec.whatwg.org/multipage/#handler-dedicatedworkerglobalscope-onmessage
event_handler!(message, GetOnmessage, SetOnmessage); event_handler!(message, GetOnmessage, SetOnmessage);
} }

View file

@ -1842,7 +1842,10 @@ impl DocumentMethods for Document {
// This method intentionally does nothing // This method intentionally does nothing
} }
// https://html.spec.whatwg.org/multipage/#globaleventhandlers
global_event_handlers!(); global_event_handlers!();
// https://html.spec.whatwg.org/multipage/#handler-onreadystatechange
event_handler!(readystatechange, GetOnreadystatechange, SetOnreadystatechange); event_handler!(readystatechange, GetOnreadystatechange, SetOnreadystatechange);
} }

View file

@ -253,11 +253,22 @@ impl FileReader {
} }
impl FileReaderMethods for FileReader { impl FileReaderMethods for FileReader {
// https://w3c.github.io/FileAPI/#dfn-onloadstart
event_handler!(loadstart, GetOnloadstart, SetOnloadstart); event_handler!(loadstart, GetOnloadstart, SetOnloadstart);
// https://w3c.github.io/FileAPI/#dfn-onprogress
event_handler!(progress, GetOnprogress, SetOnprogress); event_handler!(progress, GetOnprogress, SetOnprogress);
// https://w3c.github.io/FileAPI/#dfn-onload
event_handler!(load, GetOnload, SetOnload); event_handler!(load, GetOnload, SetOnload);
// https://w3c.github.io/FileAPI/#dfn-onabort
event_handler!(abort, GetOnabort, SetOnabort); event_handler!(abort, GetOnabort, SetOnabort);
// https://w3c.github.io/FileAPI/#dfn-onerror
event_handler!(error, GetOnerror, SetOnerror); event_handler!(error, GetOnerror, SetOnerror);
// https://w3c.github.io/FileAPI/#dfn-onloadend
event_handler!(loadend, GetOnloadend, SetOnloadend); event_handler!(loadend, GetOnloadend, SetOnloadend);
//TODO https://w3c.github.io/FileAPI/#dfn-readAsArrayBuffer //TODO https://w3c.github.io/FileAPI/#dfn-readAsArrayBuffer

View file

@ -54,6 +54,8 @@ impl HTMLAppletElement {
impl HTMLAppletElementMethods for HTMLAppletElement { impl HTMLAppletElementMethods for HTMLAppletElement {
// https://html.spec.whatwg.org/#the-applet-element:dom-applet-name // https://html.spec.whatwg.org/#the-applet-element:dom-applet-name
make_getter!(Name); make_getter!(Name);
// https://html.spec.whatwg.org/#the-applet-element:dom-applet-name
make_atomic_setter!(SetName, "name"); make_atomic_setter!(SetName, "name");
} }

View file

@ -71,6 +71,8 @@ impl HTMLBodyElement {
impl HTMLBodyElementMethods for HTMLBodyElement { impl HTMLBodyElementMethods for HTMLBodyElement {
// https://html.spec.whatwg.org/multipage#dom-body-bgcolor // https://html.spec.whatwg.org/multipage#dom-body-bgcolor
make_getter!(BgColor, "bgcolor"); make_getter!(BgColor, "bgcolor");
// https://html.spec.whatwg.org/multipage#dom-body-bgcolor
make_setter!(SetBgColor, "bgcolor"); make_setter!(SetBgColor, "bgcolor");
// https://html.spec.whatwg.org/multipage/#the-body-element // https://html.spec.whatwg.org/multipage/#the-body-element

View file

@ -98,22 +98,29 @@ impl HTMLButtonElementMethods for HTMLButtonElement {
// https://html.spec.whatwg.org/multipage/#dom-button-type // https://html.spec.whatwg.org/multipage/#dom-button-type
make_setter!(SetType, "type"); make_setter!(SetType, "type");
// https://html.spec.whatwg.org/multipage/#htmlbuttonelement // https://html.spec.whatwg.org/multipage/#dom-fs-formaction
make_url_or_base_getter!(FormAction); make_url_or_base_getter!(FormAction);
// https://html.spec.whatwg.org/multipage/#dom-fs-formaction
make_setter!(SetFormAction, "formaction"); make_setter!(SetFormAction, "formaction");
// https://html.spec.whatwg.org/multipage/#dom-fs-formenctype
make_enumerated_getter!( make_enumerated_getter!(
FormEnctype, "application/x-www-form-urlencoded", ("text/plain") | ("multipart/form-data")); FormEnctype, "application/x-www-form-urlencoded", ("text/plain") | ("multipart/form-data"));
// https://html.spec.whatwg.org/multipage/#dom-fs-formenctype
make_setter!(SetFormEnctype, "formenctype"); make_setter!(SetFormEnctype, "formenctype");
// https://html.spec.whatwg.org/multipage/#dom-fs-formmethod
make_enumerated_getter!(FormMethod, "get", ("post") | ("dialog")); make_enumerated_getter!(FormMethod, "get", ("post") | ("dialog"));
// https://html.spec.whatwg.org/multipage/#dom-fs-formmethod
make_setter!(SetFormMethod, "formmethod"); make_setter!(SetFormMethod, "formmethod");
// https://html.spec.whatwg.org/multipage/#dom-fs-formtarget
make_getter!(FormTarget); make_getter!(FormTarget);
// https://html.spec.whatwg.org/multipage/#dom-fs-formtarget
make_setter!(SetFormTarget, "formtarget"); make_setter!(SetFormTarget, "formtarget");
// https://html.spec.whatwg.org/multipage/#dom-fe-name // https://html.spec.whatwg.org/multipage/#dom-fe-name

View file

@ -130,16 +130,22 @@ impl HTMLElementMethods for HTMLElement {
}) })
} }
// https://html.spec.whatwg.org/multipage/#attr-title
make_getter!(Title); make_getter!(Title);
// https://html.spec.whatwg.org/multipage/#attr-title
make_setter!(SetTitle, "title"); make_setter!(SetTitle, "title");
// https://html.spec.whatwg.org/multipage/#attr-lang
make_getter!(Lang); make_getter!(Lang);
// https://html.spec.whatwg.org/multipage/#attr-lang
make_setter!(SetLang, "lang"); make_setter!(SetLang, "lang");
// https://html.spec.whatwg.org/multipage/#dom-hidden // https://html.spec.whatwg.org/multipage/#dom-hidden
make_bool_getter!(Hidden); make_bool_getter!(Hidden);
// https://html.spec.whatwg.org/multipage/#dom-hidden
make_bool_setter!(SetHidden, "hidden"); make_bool_setter!(SetHidden, "hidden");
// https://html.spec.whatwg.org/multipage/#globaleventhandlers
global_event_handlers!(NoOnload); global_event_handlers!(NoOnload);
// https://html.spec.whatwg.org/multipage/#dom-dataset // https://html.spec.whatwg.org/multipage/#dom-dataset

View file

@ -50,7 +50,10 @@ impl HTMLFontElement {
} }
impl HTMLFontElementMethods for HTMLFontElement { impl HTMLFontElementMethods for HTMLFontElement {
// https://html.spec.whatwg.org/multipage/#dom-font-color
make_getter!(Color, "color"); make_getter!(Color, "color");
// https://html.spec.whatwg.org/multipage/#dom-font-color
make_setter!(SetColor, "color"); make_setter!(SetColor, "color");
} }

View file

@ -122,6 +122,8 @@ impl HTMLFormElementMethods for HTMLFormElement {
// https://html.spec.whatwg.org/multipage/#dom-form-name // https://html.spec.whatwg.org/multipage/#dom-form-name
make_getter!(Name); make_getter!(Name);
// https://html.spec.whatwg.org/multipage/#dom-form-name
make_atomic_setter!(SetName, "name"); make_atomic_setter!(SetName, "name");
// https://html.spec.whatwg.org/multipage/#dom-fs-novalidate // https://html.spec.whatwg.org/multipage/#dom-fs-novalidate

View file

@ -339,12 +339,14 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
Err(NotSupported) Err(NotSupported)
} }
// https://html.spec.whatwg.org/multipage/#dom-dim-width
make_getter!(Width); make_getter!(Width);
// https://html.spec.whatwg.org/multipage/#dom-dim-width
make_setter!(SetWidth, "width"); make_setter!(SetWidth, "width");
// https://html.spec.whatwg.org/multipage/#dom-dim-height
make_getter!(Height); make_getter!(Height);
// https://html.spec.whatwg.org/multipage/#dom-dim-height
make_setter!(SetHeight, "height"); make_setter!(SetHeight, "height");
} }

View file

@ -197,18 +197,22 @@ impl LayoutHTMLImageElementHelpers for LayoutJS<HTMLImageElement> {
} }
impl HTMLImageElementMethods for HTMLImageElement { impl HTMLImageElementMethods for HTMLImageElement {
// https://html.spec.whatwg.org/multipage/#dom-img-alt
make_getter!(Alt); make_getter!(Alt);
// https://html.spec.whatwg.org/multipage/#dom-img-alt
make_setter!(SetAlt, "alt"); make_setter!(SetAlt, "alt");
// https://html.spec.whatwg.org/multipage/#dom-img-src
make_url_getter!(Src); make_url_getter!(Src);
// https://html.spec.whatwg.org/multipage/#dom-img-src
make_setter!(SetSrc, "src"); make_setter!(SetSrc, "src");
// https://html.spec.whatwg.org/multipage/#dom-img-usemap
make_getter!(UseMap); make_getter!(UseMap);
// https://html.spec.whatwg.org/multipage/#dom-img-usemap
make_setter!(SetUseMap, "usemap"); make_setter!(SetUseMap, "usemap");
// https://html.spec.whatwg.org/multipage/#dom-img-ismap
make_bool_getter!(IsMap); make_bool_getter!(IsMap);
// https://html.spec.whatwg.org/multipage/#dom-img-ismap // https://html.spec.whatwg.org/multipage/#dom-img-ismap
@ -269,28 +273,40 @@ impl HTMLImageElementMethods for HTMLImageElement {
image.is_some() image.is_some()
} }
// https://html.spec.whatwg.org/#dom-img-name // https://html.spec.whatwg.org/multipage/#dom-img-name
make_getter!(Name); make_getter!(Name);
// https://html.spec.whatwg.org/multipage/#dom-img-name
make_atomic_setter!(SetName, "name"); make_atomic_setter!(SetName, "name");
// https://html.spec.whatwg.org/multipage/#dom-img-align
make_getter!(Align); make_getter!(Align);
// https://html.spec.whatwg.org/multipage/#dom-img-align
make_setter!(SetAlign, "align"); make_setter!(SetAlign, "align");
// https://html.spec.whatwg.org/multipage/#dom-img-hspace
make_uint_getter!(Hspace); make_uint_getter!(Hspace);
// https://html.spec.whatwg.org/multipage/#dom-img-hspace
make_uint_setter!(SetHspace, "hspace"); make_uint_setter!(SetHspace, "hspace");
// https://html.spec.whatwg.org/multipage/#dom-img-vspace
make_uint_getter!(Vspace); make_uint_getter!(Vspace);
// https://html.spec.whatwg.org/multipage/#dom-img-vspace
make_uint_setter!(SetVspace, "vspace"); make_uint_setter!(SetVspace, "vspace");
// https://html.spec.whatwg.org/multipage/#dom-img-longdesc
make_getter!(LongDesc); make_getter!(LongDesc);
// https://html.spec.whatwg.org/multipage/#dom-img-longdesc
make_setter!(SetLongDesc, "longdesc"); make_setter!(SetLongDesc, "longdesc");
// https://html.spec.whatwg.org/multipage/#dom-img-border
make_getter!(Border); make_getter!(Border);
// https://html.spec.whatwg.org/multipage/#dom-img-border
make_setter!(SetBorder, "border"); make_setter!(SetBorder, "border");
} }

View file

@ -247,6 +247,8 @@ impl HTMLInputElementMethods for HTMLInputElement {
// https://html.spec.whatwg.org/multipage/#dom-input-size // https://html.spec.whatwg.org/multipage/#dom-input-size
make_uint_getter!(Size, "size", DEFAULT_INPUT_SIZE); make_uint_getter!(Size, "size", DEFAULT_INPUT_SIZE);
// https://html.spec.whatwg.org/multipage/#dom-input-size
make_limited_uint_setter!(SetSize, "size", DEFAULT_INPUT_SIZE); make_limited_uint_setter!(SetSize, "size", DEFAULT_INPUT_SIZE);
// https://html.spec.whatwg.org/multipage/#dom-input-type // https://html.spec.whatwg.org/multipage/#dom-input-type

View file

@ -209,19 +209,34 @@ impl HTMLLinkElement {
} }
impl HTMLLinkElementMethods for HTMLLinkElement { impl HTMLLinkElementMethods for HTMLLinkElement {
// https://html.spec.whatwg.org/multipage/#dom-link-href
make_url_getter!(Href); make_url_getter!(Href);
// https://html.spec.whatwg.org/multipage/#dom-link-href
make_setter!(SetHref, "href"); make_setter!(SetHref, "href");
// https://html.spec.whatwg.org/multipage/#dom-link-rel
make_getter!(Rel); make_getter!(Rel);
// https://html.spec.whatwg.org/multipage/#dom-link-rel
make_setter!(SetRel, "rel"); make_setter!(SetRel, "rel");
// https://html.spec.whatwg.org/multipage/#dom-link-media
make_getter!(Media); make_getter!(Media);
// https://html.spec.whatwg.org/multipage/#dom-link-media
make_setter!(SetMedia, "media"); make_setter!(SetMedia, "media");
// https://html.spec.whatwg.org/multipage/#dom-link-hreflang
make_getter!(Hreflang); make_getter!(Hreflang);
// https://html.spec.whatwg.org/multipage/#dom-link-hreflang
make_setter!(SetHreflang, "hreflang"); make_setter!(SetHreflang, "hreflang");
// https://html.spec.whatwg.org/multipage/#dom-link-type
make_getter!(Type); make_getter!(Type);
// https://html.spec.whatwg.org/multipage/#dom-link-type
make_setter!(SetType, "type"); make_setter!(SetType, "type");
// https://html.spec.whatwg.org/multipage/#dom-link-rellist // https://html.spec.whatwg.org/multipage/#dom-link-rellist

View file

@ -571,8 +571,9 @@ impl VirtualMethods for HTMLScriptElement {
} }
impl HTMLScriptElementMethods for HTMLScriptElement { impl HTMLScriptElementMethods for HTMLScriptElement {
// https://html.spec.whatwg.org/multipage/#dom-script-src
make_url_getter!(Src); make_url_getter!(Src);
// https://html.spec.whatwg.org/multipage/#dom-script-src
make_setter!(SetSrc, "src"); make_setter!(SetSrc, "src");
// https://www.whatwg.org/html/#dom-script-text // https://www.whatwg.org/html/#dom-script-text

View file

@ -77,6 +77,8 @@ impl HTMLTableCellElement {
impl HTMLTableCellElementMethods for HTMLTableCellElement { impl HTMLTableCellElementMethods for HTMLTableCellElement {
// https://html.spec.whatwg.org/multipage/#dom-tdth-colspan // https://html.spec.whatwg.org/multipage/#dom-tdth-colspan
make_uint_getter!(ColSpan, "colspan", DEFAULT_COLSPAN); make_uint_getter!(ColSpan, "colspan", DEFAULT_COLSPAN);
// https://html.spec.whatwg.org/multipage/#dom-tdth-colspan
make_uint_setter!(SetColSpan, "colspan"); make_uint_setter!(SetColSpan, "colspan");
} }

View file

@ -121,6 +121,8 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
// https://html.spec.whatwg.org/multipage/#dom-textarea-cols // https://html.spec.whatwg.org/multipage/#dom-textarea-cols
make_uint_getter!(Cols, "cols", DEFAULT_COLS); make_uint_getter!(Cols, "cols", DEFAULT_COLS);
// https://html.spec.whatwg.org/multipage/#dom-textarea-cols
make_limited_uint_setter!(SetCols, "cols", DEFAULT_COLS); make_limited_uint_setter!(SetCols, "cols", DEFAULT_COLS);
// https://www.whatwg.org/html/#dom-fe-disabled // https://www.whatwg.org/html/#dom-fe-disabled
@ -155,6 +157,8 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
// https://html.spec.whatwg.org/multipage/#dom-textarea-rows // https://html.spec.whatwg.org/multipage/#dom-textarea-rows
make_uint_getter!(Rows, "rows", DEFAULT_ROWS); make_uint_getter!(Rows, "rows", DEFAULT_ROWS);
// https://html.spec.whatwg.org/multipage/#dom-textarea-rows
make_limited_uint_setter!(SetRows, "rows", DEFAULT_ROWS); make_limited_uint_setter!(SetRows, "rows", DEFAULT_ROWS);
// https://html.spec.whatwg.org/multipage/#dom-textarea-wrap // https://html.spec.whatwg.org/multipage/#dom-textarea-wrap

View file

@ -228,9 +228,16 @@ impl WebSocket {
} }
impl WebSocketMethods for WebSocket { impl WebSocketMethods for WebSocket {
// https://html.spec.whatwg.org/multipage/#handler-websocket-onopen
event_handler!(open, GetOnopen, SetOnopen); event_handler!(open, GetOnopen, SetOnopen);
// https://html.spec.whatwg.org/multipage/#handler-websocket-onclose
event_handler!(close, GetOnclose, SetOnclose); event_handler!(close, GetOnclose, SetOnclose);
// https://html.spec.whatwg.org/multipage/#handler-websocket-onerror
event_handler!(error, GetOnerror, SetOnerror); event_handler!(error, GetOnerror, SetOnerror);
// https://html.spec.whatwg.org/multipage/#handler-websocket-onmessage
event_handler!(message, GetOnmessage, SetOnmessage); event_handler!(message, GetOnmessage, SetOnmessage);
// https://html.spec.whatwg.org/multipage/#dom-websocket-url // https://html.spec.whatwg.org/multipage/#dom-websocket-url

View file

@ -503,8 +503,13 @@ impl WindowMethods for Window {
}) })
} }
// https://html.spec.whatwg.org/multipage/#globaleventhandlers
global_event_handlers!(); global_event_handlers!();
// https://html.spec.whatwg.org/multipage/#handler-window-onunload
event_handler!(unload, GetOnunload, SetOnunload); event_handler!(unload, GetOnunload, SetOnunload);
// https://html.spec.whatwg.org/multipage/#handler-onerror
error_event_handler!(error, GetOnerror, SetOnerror); error_event_handler!(error, GetOnerror, SetOnerror);
// https://developer.mozilla.org/en-US/docs/Web/API/Window/screen // https://developer.mozilla.org/en-US/docs/Web/API/Window/screen

View file

@ -162,7 +162,10 @@ impl WorkerMethods for Worker {
Ok(()) Ok(())
} }
// https://html.spec.whatwg.org/multipage/#handler-dedicatedworkerglobalscope-onmessage
event_handler!(message, GetOnmessage, SetOnmessage); event_handler!(message, GetOnmessage, SetOnmessage);
// https://html.spec.whatwg.org/multipage/#handler-workerglobalscope-onerror
event_handler!(error, GetOnerror, SetOnerror); event_handler!(error, GetOnerror, SetOnerror);
} }

View file

@ -293,6 +293,7 @@ impl XMLHttpRequest {
} }
impl XMLHttpRequestMethods for XMLHttpRequest { impl XMLHttpRequestMethods for XMLHttpRequest {
// https://xhr.spec.whatwg.org/#handler-xhr-onreadystatechange
event_handler!(readystatechange, GetOnreadystatechange, SetOnreadystatechange); event_handler!(readystatechange, GetOnreadystatechange, SetOnreadystatechange);
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-readystate // https://xhr.spec.whatwg.org/#dom-xmlhttprequest-readystate

View file

@ -38,11 +38,24 @@ impl XMLHttpRequestEventTargetDerived for EventTarget {
} }
impl XMLHttpRequestEventTargetMethods for XMLHttpRequestEventTarget { impl XMLHttpRequestEventTargetMethods for XMLHttpRequestEventTarget {
// https://xhr.spec.whatwg.org/#handler-xhr-onloadstart
event_handler!(loadstart, GetOnloadstart, SetOnloadstart); event_handler!(loadstart, GetOnloadstart, SetOnloadstart);
// https://xhr.spec.whatwg.org/#handler-xhr-onprogress
event_handler!(progress, GetOnprogress, SetOnprogress); event_handler!(progress, GetOnprogress, SetOnprogress);
// https://xhr.spec.whatwg.org/#handler-xhr-onabort
event_handler!(abort, GetOnabort, SetOnabort); event_handler!(abort, GetOnabort, SetOnabort);
// https://xhr.spec.whatwg.org/#handler-xhr-onerror
event_handler!(error, GetOnerror, SetOnerror); event_handler!(error, GetOnerror, SetOnerror);
// https://xhr.spec.whatwg.org/#handler-xhr-onload
event_handler!(load, GetOnload, SetOnload); event_handler!(load, GetOnload, SetOnload);
// https://xhr.spec.whatwg.org/#handler-xhr-ontimeout
event_handler!(timeout, GetOntimeout, SetOntimeout); event_handler!(timeout, GetOntimeout, SetOntimeout);
// https://xhr.spec.whatwg.org/#handler-xhr-onloadend
event_handler!(loadend, GetOnloadend, SetOnloadend); event_handler!(loadend, GetOnloadend, SetOnloadend);
} }

View file

@ -323,6 +323,16 @@ def check_spec(file_name, contents):
raise StopIteration raise StopIteration
file_name = os.path.relpath(os.path.splitext(file_name)[0], base_path) file_name = os.path.relpath(os.path.splitext(file_name)[0], base_path)
patt = re.compile("^\s*\/\/.+") patt = re.compile("^\s*\/\/.+")
# Pattern representing a line with a macro
macro_patt = re.compile("^\s*\S+!(.*)$")
# Pattern representing a line with comment containing a spec link
link_patt = re.compile("^\s*///? https://.+$")
# Pattern representing a line with comment
comment_patt = re.compile("^\s*///?.+$")
pattern = "impl %sMethods for %s {" % (file_name, file_name) pattern = "impl %sMethods for %s {" % (file_name, file_name)
contents = contents.splitlines(True) contents = contents.splitlines(True)
brace_count = 0 brace_count = 0
@ -333,9 +343,16 @@ def check_spec(file_name, contents):
if not patt.match(line): if not patt.match(line):
if pattern.lower() in line.lower(): if pattern.lower() in line.lower():
in_impl = True in_impl = True
if "fn " in line and brace_count == 1: if ("fn " in line or macro_patt.match(line)) and brace_count == 1:
if "// https://" not in contents[idx - 1] and "// https://" not in contents[idx - 2]: for up_idx in range(1, idx + 1):
up_line = contents[idx - up_idx]
if link_patt.match(up_line):
# Comment with spec link exists
break
if not comment_patt.match(up_line):
# No more comments exist above, yield warning
yield (idx + 1, "method declared in webidl is missing a comment with a specification link") yield (idx + 1, "method declared in webidl is missing a comment with a specification link")
break
if '{' in line and in_impl: if '{' in line and in_impl:
brace_count += 1 brace_count += 1
if '}' in line and in_impl: if '}' in line and in_impl: