Skip to content

Commit 92141b0

Browse files
committed
Support unnamed getter/setter/deleter operations
Change-Id: Ieb9f7a63142e604f3549ba81755b4cfc08eb3200
1 parent 5ac2c35 commit 92141b0

27 files changed

+555
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# IDLeDOM x.x.x (not yet released)
22
* Add interfaces for HTML IDL, in particular the HTML*Element classes.
3+
* Support "unnamed" getter/setters/deleters.
34

45
# IDLeDOM 0.3.0 (2021-04-12)
56
* Use interface (instead of class) for enumerations. This allows

WebIDL.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ In WebIDL [`interface`] types, the names `getIterator` and `count` are
8282
reserved. (These are used to implement [`IteratorAggregate`] and
8383
[`Countable`].)
8484

85+
If the WebIDL defines an "unnamed" indexed getter, named getter,
86+
indexed setter, named setter, indexed deleter or named deleter,
87+
the names `item`, `namedItem`, `setItem`, `setNamedItem`, `removeItem`,
88+
or `removeNamedItem` (respectively) are reserved.
89+
8590
### Resolution order
8691

8792
When determining the PHP escaped name corresponding to an WebIDL name,

spec/HTML.webidl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ interface TextTrackCue : EventTarget {
754754
interface TextTrackCueList {
755755
readonly attribute unsigned long length;
756756
getter TextTrackCue (unsigned long index);
757-
TextTrackCue? getCueById(DOMString id);
757+
[PHPExtension] getter TextTrackCue? getCueById(DOMString id);
758758
};
759759

760760

spec/misc.webidl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ partial interface Window {
136136
interface AudioTrackList : EventTarget {
137137
readonly attribute unsigned long length;
138138
getter AudioTrack (unsigned long index);
139-
AudioTrack? getTrackById(DOMString id);
139+
[PHPExtension] getter AudioTrack? getTrackById(DOMString id);
140140

141141
attribute EventHandler onchange;
142142
attribute EventHandler onaddtrack;
@@ -156,7 +156,7 @@ interface AudioTrack {
156156
interface VideoTrackList : EventTarget {
157157
readonly attribute unsigned long length;
158158
getter VideoTrack (unsigned long index);
159-
VideoTrack? getTrackById(DOMString id);
159+
[PHPExtension] getter VideoTrack? getTrackById(DOMString id);
160160
readonly attribute long selectedIndex;
161161

162162
attribute EventHandler onchange;
@@ -178,7 +178,7 @@ interface VideoTrack {
178178
interface TextTrackList : EventTarget {
179179
readonly attribute unsigned long length;
180180
getter TextTrack (unsigned long index);
181-
TextTrack? getTrackById(DOMString id);
181+
[PHPExtension] getter TextTrack? getTrackById(DOMString id);
182182

183183
attribute EventHandler onchange;
184184
attribute EventHandler onaddtrack;

src/AudioTrackList.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@
1616
* @property EventHandlerNonNull|callable|null $onremovetrack
1717
* @phan-forbid-undeclared-magic-properties
1818
*/
19-
interface AudioTrackList extends EventTarget {
19+
interface AudioTrackList extends EventTarget, \ArrayAccess {
2020
/**
2121
* @return int
2222
*/
2323
public function getLength() : int;
2424

25+
/**
26+
* @param int $index
27+
* @return AudioTrack
28+
*/
29+
public function item( int $index );
30+
2531
/**
2632
* @param string $id
2733
* @return AudioTrack|null

src/DOMStringMap.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@
1212
*
1313
* @phan-forbid-undeclared-magic-properties
1414
*/
15-
interface DOMStringMap {
15+
interface DOMStringMap extends \ArrayAccess {
16+
/**
17+
* @param string $name
18+
* @return string
19+
*/
20+
public function namedItem( string $name ) : string;
21+
22+
/**
23+
* @param string $name
24+
* @param string $value
25+
* @return void
26+
*/
27+
public function setNamedItem( string $name, string $value ) : void;
28+
29+
/**
30+
* @param string $name
31+
* @return void
32+
*/
33+
public function removeNamedItem( string $name ) : void;
1634

1735
}

src/HTMLOptionsCollection.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
* @phan-forbid-undeclared-magic-properties
1616
*/
1717
interface HTMLOptionsCollection extends HTMLCollection {
18+
/**
19+
* @param int $index
20+
* @param HTMLOptionElement|null $option
21+
* @return void
22+
*/
23+
public function setItem( int $index, /* ?HTMLOptionElement */ $option ) : void;
1824

1925
/**
2026
* @param HTMLOptionElement|HTMLOptGroupElement $element

src/HTMLSelectElement.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ public function namedItem( string $name );
184184
*/
185185
public function add( /* mixed */ $element, /* ?mixed */ $before = null ) : void;
186186

187+
/**
188+
* @param int $index
189+
* @param HTMLOptionElement|null $option
190+
* @return void
191+
*/
192+
public function setItem( int $index, /* ?HTMLOptionElement */ $option ) : void;
193+
187194
/**
188195
* @return HTMLCollection
189196
*/

src/Helper/AudioTrackList.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,75 @@ public function __unset( string $name ) : void {
113113
);
114114
}
115115

116+
/**
117+
* @param mixed $offset
118+
* @return bool
119+
*/
120+
public function offsetExists( $offset ): bool {
121+
return $this->offsetGet( $offset ) !== null;
122+
}
123+
124+
/**
125+
* @param mixed $offset
126+
* @return mixed
127+
*/
128+
public function offsetGet( $offset ) {
129+
'@phan-var \Wikimedia\IDLeDOM\AudioTrackList $this';
130+
// @var \Wikimedia\IDLeDOM\AudioTrackList $this
131+
if ( is_numeric( $offset ) ) {
132+
return $this->item( $offset );
133+
} elseif ( is_string( $offset ) ) {
134+
return $this->getTrackById( $offset );
135+
}
136+
$trace = debug_backtrace();
137+
trigger_error(
138+
'Undefined property via offsetGet(): ' . $offset .
139+
' in ' . $trace[0]['file'] .
140+
' on line ' . $trace[0]['line'],
141+
E_USER_NOTICE
142+
);
143+
return null;
144+
}
145+
146+
/**
147+
* @param mixed $offset
148+
* @param mixed $value
149+
*/
150+
public function offsetSet( $offset, $value ) : void {
151+
'@phan-var \Wikimedia\IDLeDOM\AudioTrackList $this';
152+
// @var \Wikimedia\IDLeDOM\AudioTrackList $this
153+
if ( is_numeric( $offset ) ) {
154+
/* Fall through */
155+
} elseif ( is_string( $offset ) ) {
156+
/* Fall through */
157+
}
158+
$trace = debug_backtrace();
159+
trigger_error(
160+
'Undefined property via offsetSet(): ' . $offset .
161+
' in ' . $trace[0]['file'] .
162+
' on line ' . $trace[0]['line'],
163+
E_USER_NOTICE
164+
);
165+
}
166+
167+
/**
168+
* @param mixed $offset
169+
*/
170+
public function offsetUnset( $offset ) : void {
171+
'@phan-var \Wikimedia\IDLeDOM\AudioTrackList $this';
172+
// @var \Wikimedia\IDLeDOM\AudioTrackList $this
173+
if ( is_numeric( $offset ) ) {
174+
/* Fall through */
175+
} elseif ( is_string( $offset ) ) {
176+
/* Fall through */
177+
}
178+
$trace = debug_backtrace();
179+
trigger_error(
180+
'Undefined property via offsetUnset(): ' . $offset .
181+
' in ' . $trace[0]['file'] .
182+
' on line ' . $trace[0]['line'],
183+
E_USER_NOTICE
184+
);
185+
}
186+
116187
}

src/Helper/DOMStringMap.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
// AUTOMATICALLY GENERATED. DO NOT EDIT.
4+
// Use `composer build` to regenerate.
5+
6+
namespace Wikimedia\IDLeDOM\Helper;
7+
8+
trait DOMStringMap {
9+
/**
10+
* @param mixed $offset
11+
* @return bool
12+
*/
13+
public function offsetExists( $offset ): bool {
14+
return $this->offsetGet( $offset ) !== null;
15+
}
16+
17+
/**
18+
* @param mixed $offset
19+
* @return mixed
20+
*/
21+
public function offsetGet( $offset ) {
22+
'@phan-var \Wikimedia\IDLeDOM\DOMStringMap $this';
23+
// @var \Wikimedia\IDLeDOM\DOMStringMap $this
24+
if ( is_numeric( $offset ) ) {
25+
/* Fall through */
26+
} elseif ( is_string( $offset ) ) {
27+
return $this->namedItem( $offset );
28+
}
29+
$trace = debug_backtrace();
30+
trigger_error(
31+
'Undefined property via offsetGet(): ' . $offset .
32+
' in ' . $trace[0]['file'] .
33+
' on line ' . $trace[0]['line'],
34+
E_USER_NOTICE
35+
);
36+
return null;
37+
}
38+
39+
/**
40+
* @param mixed $offset
41+
* @param mixed $value
42+
*/
43+
public function offsetSet( $offset, $value ) : void {
44+
'@phan-var \Wikimedia\IDLeDOM\DOMStringMap $this';
45+
// @var \Wikimedia\IDLeDOM\DOMStringMap $this
46+
if ( is_numeric( $offset ) ) {
47+
/* Fall through */
48+
} elseif ( is_string( $offset ) ) {
49+
$this->setNamedItem( $offset, $value );
50+
}
51+
$trace = debug_backtrace();
52+
trigger_error(
53+
'Undefined property via offsetSet(): ' . $offset .
54+
' in ' . $trace[0]['file'] .
55+
' on line ' . $trace[0]['line'],
56+
E_USER_NOTICE
57+
);
58+
}
59+
60+
/**
61+
* @param mixed $offset
62+
*/
63+
public function offsetUnset( $offset ) : void {
64+
'@phan-var \Wikimedia\IDLeDOM\DOMStringMap $this';
65+
// @var \Wikimedia\IDLeDOM\DOMStringMap $this
66+
if ( is_numeric( $offset ) ) {
67+
/* Fall through */
68+
} elseif ( is_string( $offset ) ) {
69+
$this->removeNamedItem( $offset );
70+
}
71+
$trace = debug_backtrace();
72+
trigger_error(
73+
'Undefined property via offsetUnset(): ' . $offset .
74+
' in ' . $trace[0]['file'] .
75+
' on line ' . $trace[0]['line'],
76+
E_USER_NOTICE
77+
);
78+
}
79+
80+
}

0 commit comments

Comments
 (0)