Skip to content

Commit a64f6df

Browse files
committed
set.add should return the string-coerced value.
1 parent a7cb015 commit a64f6df

4 files changed

Lines changed: 6 additions & 4 deletions

File tree

d3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@
370370
d3_class(d3_Set, {
371371
has: d3_map_has,
372372
add: function(key) {
373-
this._[d3_map_escape(key)] = true;
373+
this._[d3_map_escape(key += "")] = true;
374374
return key;
375375
},
376376
remove: d3_map_remove,

d3.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/arrays/set.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function d3_Set() {
1414
d3_class(d3_Set, {
1515
has: d3_map_has,
1616
add: function(key) {
17-
this._[d3_map_escape(key)] = true;
17+
this._[d3_map_escape(key += "")] = true;
1818
return key;
1919
},
2020
remove: d3_map_remove,

test/arrays/set-test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,11 @@ suite.addBatch({
157157
}
158158
},
159159
"add": {
160-
"returns the set value": function(set) {
160+
"returns the set value, coerced to a string": function(set) {
161161
var s = set();
162162
assert.equal(s.add("foo"), "foo");
163+
assert.strictEqual(s.add(2), "2");
164+
assert.deepEqual(s.values().sort(), ["2", "foo"]);
163165
},
164166
"can add values using built-in names": function(set) {
165167
var s = set();

0 commit comments

Comments
 (0)