archives

« Bugzilla Issues Index

#1938 — 23.4.3.5: Add type check for input argument in WeakSet.prototype.has


23.4.3.5 WeakSet.prototype.has ( value )

Add after step 4:

5. If Type(value) is not Object, then throw a TypeError exception.


Also see "23.3.3.5 WeakMap.prototype.has ( key )" which already does this input validation.


I believe that there was a desire that non-object keys simply produce false. This algorithm does that but in rev19 I made it an explicit step of the algorithm.

I also changed WeakMap to have the same behavior.

MarkM should be able to verify the requirement.


Hmm, I'd assume that this implication holds:
weakmap.has(0) = false → weakmap.get(0) = undefined


I meant that implication should hold if `has()` returns false instead of throwing an exception.


(In reply to comment #3)
> I meant that implication should hold if `has()` returns false instead of
> throwing an exception.

That sounds right for Maps. But because Sets don't have a get so it isn't necessary for them.


Ok, instead of `get()` use `delete()` which is present for both, Maps and Sets:
weakmap.has(0) = false → weakmap.delete(0) = false


(In reply to comment #1)
> I believe that there was a desire that non-object keys simply produce false.
> This algorithm does that but in rev19 I made it an explicit step of the
> algorithm.
>
> I also changed WeakMap to have the same behavior.
>
> MarkM should be able to verify the requirement.

WeakSet.prototype.has looks correct, but WeakMap.prototype.has contains

6. If Type(key) is not Object, then throw a TypeError exception.

whereas it should be "then return false".

Likewise for WeakMap.prototype.delete and WeakMap.prototype.get.

6. If Type(key) is not Object, then throw a TypeError exception.

.delete should return false in this case, just as for an absent key. .get should return false for this case, just as for an absent key.

Obviously, the throw a TypeError in .set is correct.

Back to WeakSet:

.delete's "If Type(value) is not Object, then throw a TypeError exception." should return false, just as for an absent value.

.has is correct.

The throw in .add is correct.


(In reply to comment #6)

>
> Likewise for WeakMap.prototype.delete and WeakMap.prototype.get.
>
> 6. If Type(key) is not Object, then throw a TypeError exception.
>
> .... .get
> should return false for this case, just as for an absent key.
>
You presumably meant undefined for the get case


fixed in rev20 editor's draft

as per Mark's suggestions


fixed in rev20 draft, Oct. 28, 2013