@@ -39,10 +39,16 @@ const transformer = new Webidl2js({
3939 } ,
4040 // https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributes
4141 processReflect ( idl , implObj ) {
42- const reflectAttr = idl . extAttrs . find ( attr => attr . name === "Reflect" ) ;
43- const attrName = ( reflectAttr && reflectAttr . rhs && JSON . parse ( reflectAttr . rhs . value ) ) || idl . name . toLowerCase ( ) ;
42+ const reflectAttr = idl . extAttrs . find (
43+ attr => attr . name === "Reflect" || attr . name === "ReflectURL" || attr . name === "ReflectNonNegative"
44+ ) ;
45+ const attrName = reflectAttr ?. rhs ? JSON . parse ( reflectAttr . rhs . value ) : idl . name . toLowerCase ( ) ;
4446
45- if ( idl . extAttrs . find ( attr => attr . name === "ReflectURL" ) ) {
47+ // TODO: [ReflectDefault] is only used for `long` right now; also use it for `unsigned long` and `double`.
48+ const reflectDefaultAttr = idl . extAttrs . find ( attr => attr . name === "ReflectDefault" ) ;
49+ const reflectDefault = reflectDefaultAttr ?. rhs ? JSON . parse ( reflectDefaultAttr . rhs . value ) : undefined ;
50+
51+ if ( reflectAttr . name === "ReflectURL" ) {
4652 // Allow DOMString also due to https://github.com/whatwg/html/issues/5241.
4753 if ( ! isSimpleIDLType ( idl . idlType , "USVString" ) && ! isSimpleIDLType ( idl . idlType , "DOMString" ) ) {
4854 throw new Error ( "[ReflectURL] specified on non-USV/DOMString attribute" ) ;
@@ -68,6 +74,13 @@ const transformer = new Webidl2js({
6874 } ;
6975 }
7076
77+ if ( reflectAttr . name === "ReflectNonNegative" ) {
78+ if ( ! isSimpleIDLType ( idl . idlType , "long" ) ) {
79+ throw new Error ( "[ReflectNonNegative] specified on non-long attribute" ) ;
80+ }
81+ // We'll actually do the processing in the long case, later.
82+ }
83+
7184 if ( isSimpleIDLType ( idl . idlType , "DOMString" ) || isSimpleIDLType ( idl . idlType , "USVString" ) ) {
7285 if ( idl . idlType . nullable ) {
7386 // Nonstandard; see https://github.com/whatwg/html/issues/10037. This passes the WPTs though.
@@ -113,18 +126,46 @@ const transformer = new Webidl2js({
113126 }
114127
115128 if ( isSimpleIDLType ( idl . idlType , "long" ) ) {
116- const parseInteger = this . addImport ( "../helpers/strings" , "parseInteger" ) ;
129+ const parser = this . addImport (
130+ "../helpers/strings" ,
131+ reflectAttr . name === "ReflectNonNegative" ? "parseNonNegativeInteger" : "parseInteger"
132+ ) ;
133+
134+ let defaultValue ;
135+ if ( reflectDefault !== undefined ) {
136+ defaultValue = reflectDefault ;
137+ } else if ( reflectAttr . name === "ReflectNonNegative" ) {
138+ defaultValue = - 1 ;
139+ } else {
140+ defaultValue = 0 ;
141+ }
142+
143+ let setterPrefix = "" ;
144+ if ( reflectAttr . name === "ReflectNonNegative" ) {
145+ const createDOMException = this . addImport ( "./DOMException" , "create" ) ;
146+ setterPrefix = `
147+ if (V < 0) {
148+ throw ${ createDOMException } (
149+ globalObject,
150+ [\`The negative value \${V} cannot be set for the ${ idl . name } property.\`, "IndexSizeError"]
151+ );
152+ }
153+ ` ;
154+ }
117155
118156 return {
119157 get : `
120158 let value = ${ implObj } ._reflectGetTheContentAttribute("${ attrName } ");
121- if (value === null) {
122- return 0;
159+ if (value !== null) {
160+ value = ${ parser } (value);
161+ if (value !== null && conversions.long(value) === value) {
162+ return value;
163+ }
123164 }
124- value = ${ parseInteger } (value);
125- return value !== null && conversions.long(value) === value ? value : 0;
165+ return ${ defaultValue } ;
126166 ` ,
127167 set : `
168+ ${ setterPrefix }
128169 ${ implObj } ._reflectSetTheContentAttribute("${ attrName } ", String(V));
129170 `
130171 } ;
0 commit comments