Skip to content

Commit 930778c

Browse files
authored
Return this in Map#set and Set#add (#1104)
1 parent 79b9073 commit 930778c

File tree

8 files changed

+427
-140
lines changed

8 files changed

+427
-140
lines changed

std/assembly/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ interface RegExp {}
15351535
declare class Map<K,V> {
15361536
readonly size: i32;
15371537
has(key: K): bool;
1538-
set(key: K, value: V): void;
1538+
set(key: K, value: V): this;
15391539
get(key: K): V;
15401540
delete(key: K): bool;
15411541
clear(): void;
@@ -1547,7 +1547,7 @@ declare class Map<K,V> {
15471547
declare class Set<K> {
15481548
readonly size: i32;
15491549
has(value: K): bool;
1550-
add(value: K): void;
1550+
add(value: K): this;
15511551
delete(value: K): bool;
15521552
clear(): void;
15531553
values(): K[]; // preliminary

std/assembly/map.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class Map<K,V> {
113113
}
114114

115115
@operator("[]=")
116-
set(key: K, value: V): void {
116+
set(key: K, value: V): this {
117117
var hashCode = HASH<K>(key);
118118
var entry = this.find(key, hashCode); // unmanaged!
119119
if (entry) {
@@ -151,6 +151,7 @@ export class Map<K,V> {
151151
entry.taggedNext = load<usize>(bucketPtrBase);
152152
store<usize>(bucketPtrBase, changetype<usize>(entry));
153153
}
154+
return this;
154155
}
155156

156157
delete(key: K): bool {

std/assembly/set.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class Set<T> {
101101
return this.find(key, HASH<T>(key)) !== null;
102102
}
103103

104-
add(key: T): void {
104+
add(key: T): this {
105105
var hashCode = HASH<T>(key);
106106
var entry = this.find(key, hashCode); // unmanaged!
107107
if (!entry) {
@@ -124,6 +124,7 @@ export class Set<T> {
124124
entry.taggedNext = load<usize>(bucketPtrBase);
125125
store<usize>(bucketPtrBase, changetype<usize>(entry));
126126
}
127+
return this;
127128
}
128129

129130
@operator("[]=")

0 commit comments

Comments
 (0)