Re: Array.prototype.contains solutions

2015-01-20 Thread Fabrício Matté
I faintly remember seeing a sort of proposal containing many different
approaches as how to solve this generic built-ins extensions problem in
future editions of ECMAScript.
I believe it was authored by Domenic Denicola, in Gist/GitHub format if
memory serves me right.

I can't seem to find it, does anyone have a link?
Or is memory tricking me and this thread was the end point for this topic?
Thanks.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains solutions

2015-01-20 Thread Brendan Eich

Domenic Denicola wrote:

https://www.google.com/search?q=site%3Aesdiscuss.org+Array.prototype.contains+solutions
  leads tohttps://esdiscuss.org/topic/array-prototype-contains-solutions  which 
is probably what you were thinking of.

They were not very good ideas.


It's a hard problem. Original-JS2/ES4 had namespaces, after Common Lisp 
symbol packages, as a proposed solution. You'd have to open a namespace, 
e.g.


  use namespace intrinsic;
  if (myArray.contains(someValue)) ...;

or explicitly quality:

  if (myArray.intrinsic::contains(someValue)) ...;

in case you needed to mix MooTools' contains with the new built-in one.

Namespaces were decisively rejected from the Harmony agenda at its 
founding in Oslo, July 2008:


https://mail.mozilla.org/pipermail/es-discuss/2008-August/006837.html

General hacks tend to generalize to namespaces if you push them. 
Specific hacks as you say are not very good ideas. This leaves picking 
good-enough names that don't collide. AFAIK this is the state of the 
art. Just recapitulating for anyone new to es-discuss, and calling for 
better ideas. Thanks,


/be

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


RE: Array.prototype.contains solutions

2015-01-20 Thread Domenic Denicola
https://www.google.com/search?q=site%3Aesdiscuss.org+Array.prototype.contains+solutions
 leads to https://esdiscuss.org/topic/array-prototype-contains-solutions which 
is probably what you were thinking of.

They were not very good ideas.

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains solutions

2015-01-20 Thread Fabrício Matté


 https://www.google.com/search?q=site%3Aesdiscuss.org+Array.prototype.contains+solutions
 leads to https://esdiscuss.org/topic/array-prototype-contains-solutions
 which is probably what you were thinking of.

 They were not very good ideas.


For some reason I thought you had evolved those ideas further after that
post, but if you don't recall it then my memory was wrong. Thanks for the
quick answer.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains solutions

2014-10-01 Thread Brendan Eich

Mark S. Miller wrote:
On Tue, Sep 30, 2014 at 4:58 PM, Domenic Denicola 
dome...@domenicdenicola.com mailto:dome...@domenicdenicola.com wrote:


I see a few options:

1. Rename. The leading candidate would be `Array.prototype.has`. I
outlined in [1] why `contains` is better; note especially the DOM
classes. But you could stretch things, especially by removing the
`fromIndex` parameter, into an argument that `has` is OK.
(Basically, you'd be saying that an array is more like a set than
a map, and that its analogy with String is mostly accidental.)


If we do rename, it should be almost anything other than .has. Arrays 
are clearly single-valued-mapping-like, not set-like, in that they map 
from indexes to values. If Array.prototype.has were to exist, it would 
need to test possible indexes.


Absolutely.


2. Specific hacks. I am thinking of e.g. making
`Array.prototype.contains` a getter, with a setter that does
[[DefineOwnProperty]].


This could work, and it requires no new kernel mechanisms. If we do 
adopt this solution, the setter should be careful to play the same 
games that SES plays to work around the override mistake: If the this 
being set is not Array.prototype itself, the setter should use 
[[DefineOwnProperty]] to emulate an assignment to that this's own 
.contains.


Important safety tip with setters and Proxies -- Reflect helpers help.


3. General hacks. I joked about @@unMooToolsables, but seriously,
we could do something similar to @@unscopables of using MOP hooks
to fix this problem. One idea that seems reasonable is
@@enumerableWhenAssigned, so that `Array.prototype.contains`
starts non-enumerable, but when you do `Array.prototype.contains =
x`, it becomes enumerable. You could even generalize this into
something that also fixes the override mistake [2], e.g.
@@defineOwnPropertyOnAssign or @@assignIgnoresProto or similar. Or
you could attack the problem at the for-in level


I suggest we focus on the override mistake. If we come up with a way 
of fixing it and .contains with one new kernel mechanism, that would 
be great. If we only fix the override mistake, still likely worth it. 
But if a new kernel mechanism only fixes .contains, it likely isn't 
worth it and we should return to #1 or #2.


I wouldn't count on fixing the override mistake (inevitably by adding 
something new under the sun) to help extant code like MooTools, though.


The most painful use case is the existence of perfectly reasonable ES5 
code like:



function Point(x, y) { this.x = x; this.y = y; }

Point.prototype.toString() { return `${x},${y}`; };


You mean

Point.prototype.toString = function () { return ...; };

of course -- but you're using template string new syntax, so why not use 
Object.defineProperty here? Just sayin' ;-).


Because of the override mistake, this reasonable code no longer works 
after


Object.freeze(Object.prototype);

This sucks.

SES goes out of its way to not break code that follows ES5 best 
practices. The above Point code does. That's why SES's 
tamperProof(Object.prototype) replaces the data properties on 
Object.prototype with accessor properties whose setter uses 
[[DefineOwnProperty]] to emulate assignment on a this that is not 
Object.prototype itself.


Yup, Domenic's #2.

With your #3, perhaps we'd have a less painful way to working around 
the override mistake.


I think #3, if hacked via @@enumerableWhenAssigned or any such thing, 
will just lead to more bugs. It's too implicit, modal.


Here's an alternative: add an assignment operator variant, spell it :=, 
that overrides. Boom, new code can work around the override mistake.


Point.prototype.toString := function () { return ...; };

Yeah, I remember := being mooted as [[DefineOwnProperty]] sugar taking a 
property descriptor, but I'm throwing this out here. It's simpler and 
does not confusingly vary the RHS to be a propdesc where regular 
assignment evaluates an arbitrary RHS assignment-expression.


Old code will need magic frozen-proto-setter hacks anyway. That ship 
sailed with ES5.


/be
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains solutions

2014-10-01 Thread Andrea Giammarchi
  1. I wasn't advocating to break the web but to **not** change the name
because of a library bug, the initial thread spoiler was not needed
  2. the `@@enumerableWhenAssigned` might lead to shenanigans but it's
*polyfillable* which is IMO preferable if it can solve somehow the problem

```js

enumerableWhenAssigned(
  Array.prototype,
  'contains',
  Array.prototype.contains
);

function enumerableWhenAssigned(obj, prop, value) {
  Object.defineProperty(
obj,
prop,
{
  configurable: true,
  get: function () {
return value;
  },
  set: function (value) {
Object.defineProperty(
  this,
  prop,
  {
value: value,
// writable: true, // maybe ?
configurable: true,
enumerable: true
  }
);
  }
}
  );
}
```

my .02

Regards


On Wed, Oct 1, 2014 at 8:21 AM, Brendan Eich bren...@mozilla.org wrote:

 Mark S. Miller wrote:

 On Tue, Sep 30, 2014 at 4:58 PM, Domenic Denicola 
 dome...@domenicdenicola.com mailto:dome...@domenicdenicola.com wrote:

 I see a few options:

 1. Rename. The leading candidate would be `Array.prototype.has`. I
 outlined in [1] why `contains` is better; note especially the DOM
 classes. But you could stretch things, especially by removing the
 `fromIndex` parameter, into an argument that `has` is OK.
 (Basically, you'd be saying that an array is more like a set than
 a map, and that its analogy with String is mostly accidental.)


 If we do rename, it should be almost anything other than .has. Arrays are
 clearly single-valued-mapping-like, not set-like, in that they map from
 indexes to values. If Array.prototype.has were to exist, it would need to
 test possible indexes.


 Absolutely.

  2. Specific hacks. I am thinking of e.g. making
 `Array.prototype.contains` a getter, with a setter that does
 [[DefineOwnProperty]].


 This could work, and it requires no new kernel mechanisms. If we do adopt
 this solution, the setter should be careful to play the same games that SES
 plays to work around the override mistake: If the this being set is not
 Array.prototype itself, the setter should use [[DefineOwnProperty]] to
 emulate an assignment to that this's own .contains.


 Important safety tip with setters and Proxies -- Reflect helpers help.

  3. General hacks. I joked about @@unMooToolsables, but seriously,
 we could do something similar to @@unscopables of using MOP hooks
 to fix this problem. One idea that seems reasonable is
 @@enumerableWhenAssigned, so that `Array.prototype.contains`
 starts non-enumerable, but when you do `Array.prototype.contains =
 x`, it becomes enumerable. You could even generalize this into
 something that also fixes the override mistake [2], e.g.
 @@defineOwnPropertyOnAssign or @@assignIgnoresProto or similar. Or
 you could attack the problem at the for-in level


 I suggest we focus on the override mistake. If we come up with a way of
 fixing it and .contains with one new kernel mechanism, that would be great.
 If we only fix the override mistake, still likely worth it. But if a new
 kernel mechanism only fixes .contains, it likely isn't worth it and we
 should return to #1 or #2.


 I wouldn't count on fixing the override mistake (inevitably by adding
 something new under the sun) to help extant code like MooTools, though.

  The most painful use case is the existence of perfectly reasonable ES5
 code like:


 function Point(x, y) { this.x = x; this.y = y; }

 Point.prototype.toString() { return `${x},${y}`; };


 You mean

 Point.prototype.toString = function () { return ...; };

 of course -- but you're using template string new syntax, so why not use
 Object.defineProperty here? Just sayin' ;-).

  Because of the override mistake, this reasonable code no longer works
 after

 Object.freeze(Object.prototype);

 This sucks.

 SES goes out of its way to not break code that follows ES5 best
 practices. The above Point code does. That's why SES's
 tamperProof(Object.prototype) replaces the data properties on
 Object.prototype with accessor properties whose setter uses
 [[DefineOwnProperty]] to emulate assignment on a this that is not
 Object.prototype itself.


 Yup, Domenic's #2.

  With your #3, perhaps we'd have a less painful way to working around the
 override mistake.


 I think #3, if hacked via @@enumerableWhenAssigned or any such thing, will
 just lead to more bugs. It's too implicit, modal.

 Here's an alternative: add an assignment operator variant, spell it :=,
 that overrides. Boom, new code can work around the override mistake.

 Point.prototype.toString := function () { return ...; };

 Yeah, I remember := being mooted as [[DefineOwnProperty]] sugar taking a
 property descriptor, but I'm throwing this out here. It's simpler and does
 not confusingly vary the RHS to be a propdesc where regular assignment
 evaluates an 

Re: Array.prototype.contains solutions

2014-10-01 Thread Brendan Eich

Andrea Giammarchi wrote:
  1. I wasn't advocating to break the web but to **not** change the 
name because of a library bug, the initial thread spoiler was not needed


I wasn't responding to you, here on this thread (where you hadn't posted 
till now) or on the other one, so why are you jumping in and talking 
about what you were not advocating?


  2. the `@@enumerableWhenAssigned` might lead to shenanigans but it's 
*polyfillable* which is IMO preferable if it can solve somehow the problem


No need to write lots of code. The problem I see with these 
implicit/modal hacks is that they can easily break other code that 
doesn't want an override of a non-enumerable to be enumerable.


The magic proto-setter (Domenic's option 2) is polyfillable, as Mark 
noted: no new kernel-language semantics required. It's also simpler than 
what you wrote, and doesn't risk blowback by breaking other code 
expecting non-enumerability to be preserved.


/be
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains solutions

2014-10-01 Thread Claude Pache

Le 1 oct. 2014 à 04:43, Mark S. Miller erig...@google.com a écrit :

 
 I suggest we focus on the override mistake. If we come up with a way of 
 fixing it and .contains with one new kernel mechanism, that would be great. 
 If we only fix the override mistake, still likely worth it. But if a new 
 kernel mechanism only fixes .contains, it likely isn't worth it and we should 
 return to #1 or #2.
 

I have thought about the possibility to have an overridable state attached to 
properties. That state may be implemented as an attribute, or as a mechanism à 
la @@unscopables.

(I have noted Brendan's reserve for such a mechanism; still, I think it is 
worth to consider how it could work with some details.)

The overridable state modifies the semantics of assignment (o.p = v) in the 
following ways (in short, it corrects override mistakes):

(1) it is not disallowed to set to a given property if there exists a 
nonwritable inherited property of same name.
(2) overwriting a nonenumerable property will make it enumerable (unless the 
property is nonconfigurable, of course).

In case it is implemented à la @@unscopables, we could even, in order to 
minimise the API surface, decide that @@overridables === @@unscopables.

I expect that the overridable state won't need to be examined very often. 
Indeed, consider the following:

o.p = v
o.p = w

If the first assignement succeeds, the implementation doesn't need to check the 
overridable state in order to perform the second assignment, because the 
property will be (1) writable and (2) either enumerable or nonconfigurable.

—Claude


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


RE: Array.prototype.contains solutions

2014-10-01 Thread Domenic Denicola
Thanks Claude for filling in some of the details in my vague thinking. I guess 
I/we should try to come up with something more detailed, and see how/if it is 
able to address Mark's use cases, and how implementable it would be, and how 
extensively it would help (or not).

I tend to agree with Mark that unless this solves a larger problem, it does not 
pay its own way just for Array.prototype.contains (and potentially 
Array.prototype.flatten).


From: Claude Pache [mailto:claude.pa...@gmail.com]
Sent: Wednesday, October 1, 2014 09:36
To: Mark S. Miller
Cc: Domenic Denicola; es-discuss@mozilla.org
Subject: Re: Array.prototype.contains solutions


Le 1 oct. 2014 à 04:43, Mark S. Miller 
erig...@google.commailto:erig...@google.com a écrit :



I suggest we focus on the override mistake. If we come up with a way of fixing 
it and .contains with one new kernel mechanism, that would be great. If we only 
fix the override mistake, still likely worth it. But if a new kernel mechanism 
only fixes .contains, it likely isn't worth it and we should return to #1 or #2.


I have thought about the possibility to have an overridable state attached to 
properties. That state may be implemented as an attribute, or as a mechanism à 
la @@unscopables.

(I have noted Brendan's reserve for such a mechanism; still, I think it is 
worth to consider how it could work with some details.)

The overridable state modifies the semantics of assignment (o.p = v) in the 
following ways (in short, it corrects override mistakes):

(1) it is not disallowed to set to a given property if there exists a 
nonwritable inherited property of same name.
(2) overwriting a nonenumerable property will make it enumerable (unless the 
property is nonconfigurable, of course).

In case it is implemented à la @@unscopables, we could even, in order to 
minimise the API surface, decide that @@overridables === @@unscopables.

I expect that the overridable state won't need to be examined very often. 
Indeed, consider the following:

o.p = v
o.p = w

If the first assignement succeeds, the implementation doesn't need to check the 
overridable state in order to perform the second assignment, because the 
property will be (1) writable and (2) either enumerable or nonconfigurable.

-Claude


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains solutions

2014-10-01 Thread Claude Pache
The more I consider the issue, the more I think that the most elegant solution 
is to complete data properties with an additional overridable attribute, 
whose purpose is to refine the meaning of the writable attribute in the 
manner sketched below (in opposition of having an @@unscopables-like hack). At 
first glance, I expect that the addition of such an attribute should not 
trigger much BC issues, but that needs to be examined more closely.

—Claude

Le 1 oct. 2014 à 10:47, Domenic Denicola dome...@domenicdenicola.com a écrit :

 Thanks Claude for filling in some of the details in my vague thinking. I 
 guess I/we should try to come up with something more detailed, and see how/if 
 it is able to address Mark’s use cases, and how implementable it would be, 
 and how extensively it would help (or not).
  
 I tend to agree with Mark that unless this solves a larger problem, it does 
 not pay its own way just for Array.prototype.contains (and potentially 
 Array.prototype.flatten).
  
  
 From: Claude Pache [mailto:claude.pa...@gmail.com] 
 Sent: Wednesday, October 1, 2014 09:36
 To: Mark S. Miller
 Cc: Domenic Denicola; es-discuss@mozilla.org
 Subject: Re: Array.prototype.contains solutions
  
  
 Le 1 oct. 2014 à 04:43, Mark S. Miller erig...@google.com a écrit :
 
 
  
 I suggest we focus on the override mistake. If we come up with a way of 
 fixing it and .contains with one new kernel mechanism, that would be great. 
 If we only fix the override mistake, still likely worth it. But if a new 
 kernel mechanism only fixes .contains, it likely isn't worth it and we should 
 return to #1 or #2.
  
  
 I have thought about the possibility to have an overridable state attached 
 to properties. That state may be implemented as an attribute, or as a 
 mechanism à la @@unscopables.
  
 (I have noted Brendan's reserve for such a mechanism; still, I think it is 
 worth to consider how it could work with some details.)
  
 The overridable state modifies the semantics of assignment (o.p = v) in the 
 following ways (in short, it corrects override mistakes):
  
 (1) it is not disallowed to set to a given property if there exists a 
 nonwritable inherited property of same name.
 (2) overwriting a nonenumerable property will make it enumerable (unless the 
 property is nonconfigurable, of course).
  
 In case it is implemented à la @@unscopables, we could even, in order to 
 minimise the API surface, decide that @@overridables === @@unscopables.
  
 I expect that the overridable state won't need to be examined very often. 
 Indeed, consider the following:
  
 o.p = v
 o.p = w
 
 If the first assignement succeeds, the implementation doesn't need to check 
 the overridable state in order to perform the second assignment, because the 
 property will be (1) writable and (2) either enumerable or nonconfigurable.
  
 —Claude

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains solutions

2014-10-01 Thread Mark Miller
On Wed, Oct 1, 2014 at 12:21 AM, Brendan Eich bren...@mozilla.org wrote:


  The most painful use case is the existence of perfectly reasonable ES5
 code like:


 function Point(x, y) { this.x = x; this.y = y; }

 Point.prototype.toString() { return `${x},${y}`; };


 You mean

 Point.prototype.toString = function () { return ...; };

 of course -- but you're using template string new syntax, so why not use
 Object.defineProperty here? Just sayin' ;-).


I did indeed mean the assignment in your correction.





  Because of the override mistake, this reasonable code no longer works
 after

 Object.freeze(Object.prototype);

 This sucks.

 SES goes out of its way to not break code that follows ES5 best
 practices. The above Point code does. That's why SES's
 tamperProof(Object.prototype) replaces the data properties on
 Object.prototype with accessor properties whose setter uses
 [[DefineOwnProperty]] to emulate assignment on a this that is not
 Object.prototype itself.


 Yup, Domenic's #2.

  With your #3, perhaps we'd have a less painful way to working around the
 override mistake.


 I think #3, if hacked via @@enumerableWhenAssigned or any such thing, will
 just lead to more bugs. It's too implicit, modal.

 Here's an alternative: add an assignment operator variant, spell it :=,
 that overrides. Boom, new code can work around the override mistake.

 Point.prototype.toString := function () { return ...; };

 Yeah, I remember := being mooted as [[DefineOwnProperty]] sugar taking a
 property descriptor, but I'm throwing this out here. It's simpler and does
 not confusingly vary the RHS to be a propdesc where regular assignment
 evaluates an arbitrary RHS assignment-expression.

 Old code will need magic frozen-proto-setter hacks anyway. That ship
 sailed with ES5.


My concern is old code like Point co-existing with new framework code, like
SES, that wants to freeze old prototypes, but is ignorant about all the
particular old client abstractions, like Point, that need to work within
that framework. The new framework code currently must use tamperProof
rather than freeze, which is expensive and not a fully transparent fix.
With #3, the new framework code might instead install an @@something on
these frozen prototypes, leaving the properties on that prototype as data
properties that do not suffer from the override mistake. The result could
be efficient and adequately transparent.

-- 

  Cheers,
  --MarkM
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains solutions

2014-10-01 Thread Brendan Eich

Claude Pache wrote:
The more I consider the issue, the more I think that the most elegant 
solution is to complete data properties with an additional 
overridable attribute, whose purpose is to refine the meaning of the 
writable attribute in the manner sketched below (in opposition of 
having an @@unscopables-like hack).


A new attribute, per property, is safer in general (backward 
compatibility) than a per-object flag. A per-object list seems an obtuse 
way to encode an attribute, and I am quite sure implementations would 
prefer an attribute.


At first glance, I expect that the addition of such an attribute 
should not trigger much BC issues, but that needs to be examined more 
closely.


If it's opt-in, e.g. we define Array.prototype.contains with 
[[Overridable]] among its attributes, then at least MooTools works.


What could break? Code that did not expect 'contains' to exist on 
Array.prototype, but did expect assigning to someArray.contains would 
make a non-enumerable and/or non-own property. That would seem like 
nonsense or broken code, but it could exist for some name and prototypal 
relation, you're right.


Only way to find out is to implement and test at scale.

It would be good to hear from implementors on the idea of an 
[[Overridable]] attribute. SpiderMonkey has something similar but more 
restricted (see 
http://dxr.mozilla.org/mozilla-central/source/js/src/vm/Shape.h?from=SHADOWABLEcase=true#1013).


/be
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains solutions

2014-10-01 Thread Mark S. Miller
Does the [[Overridable]] you have in mind also fix the override mistake? It
sounds like it should.

Regarding shadowable, is there any better documentation than the
doc-comment:

/* * For ES5 compatibility, we allow properties with
PropertyOp-flavored * setters to be shadowed when set. The own
property thereby created in * the directly referenced object will
have the same getter and setter as * the prototype property. See
bug 552432. */



Is there any observable effect of shadowable? Example?


On Wed, Oct 1, 2014 at 11:50 AM, Brendan Eich bren...@mozilla.org wrote:

 Claude Pache wrote:

 The more I consider the issue, the more I think that the most elegant
 solution is to complete data properties with an additional overridable
 attribute, whose purpose is to refine the meaning of the writable
 attribute in the manner sketched below (in opposition of having an
 @@unscopables-like hack).


 A new attribute, per property, is safer in general (backward
 compatibility) than a per-object flag. A per-object list seems an obtuse
 way to encode an attribute, and I am quite sure implementations would
 prefer an attribute.

  At first glance, I expect that the addition of such an attribute should
 not trigger much BC issues, but that needs to be examined more closely.


 If it's opt-in, e.g. we define Array.prototype.contains with
 [[Overridable]] among its attributes, then at least MooTools works.

 What could break? Code that did not expect 'contains' to exist on
 Array.prototype, but did expect assigning to someArray.contains would make
 a non-enumerable and/or non-own property. That would seem like nonsense or
 broken code, but it could exist for some name and prototypal relation,
 you're right.

 Only way to find out is to implement and test at scale.

 It would be good to hear from implementors on the idea of an
 [[Overridable]] attribute. SpiderMonkey has something similar but more
 restricted (see http://dxr.mozilla.org/mozilla-central/source/js/src/
 vm/Shape.h?from=SHADOWABLEcase=true#1013).

 /be




-- 
Cheers,
--MarkM
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains solutions

2014-10-01 Thread Brendan Eich

Mark S. Miller wrote:
Does the [[Overridable]] you have in mind also fix the override 
mistake? It sounds like it should.


Yes, definitely.

Regarding shadowable, is there any better documentation than the 
doc-comment:


|/*|
|  * For ES5 compatibility, we allow properties with PropertyOp-flavored|
|  * setters to be shadowed when set. The own property thereby created in|
|  * the directly referenced object will have the same getter and setter as|
|  * the prototype property. Seebug 552432.|
|  */|


Is there any observable effect of shadowable? Example?


The comment is a bit misleading. The compatibility at stake is old 
SpiderMonkey C API, by which the DOM can make pseudo-data properties 
that have native (C function) get and set accessors, but which should 
appear to be overridable (as data properties are, if writable). I'm not 
sure if I wrote ES5 there or someone else did, but ES5 helped 
straighten out old internal/pre-standard SpiderMonkey interfaces, and 
collided under the hood with the pseudo-data property support.


/be


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains solutions

2014-10-01 Thread Jason Orendorff
I'd love to be able to get rid of SHADOWABLE, actually! I just
recently found out we can do it with a little rearranging. Extra
state-space in property attributes is unavoidable complexity for us.
My own preference would be not to standardize it. :)

There's also the [Replaceable] attribute in WebIDL, which arises from
similar compatibility needs. It's implemented as a setter that
redefines the property being set.

This is a bad bunch of options. I think renaming (hasValue?) is
probably least-worst, followed by waiting a year and trying again.

-j


On Wed, Oct 1, 2014 at 1:50 PM, Brendan Eich bren...@mozilla.org wrote:
 Claude Pache wrote:

 The more I consider the issue, the more I think that the most elegant
 solution is to complete data properties with an additional overridable
 attribute, whose purpose is to refine the meaning of the writable
 attribute in the manner sketched below (in opposition of having an
 @@unscopables-like hack).


 A new attribute, per property, is safer in general (backward compatibility)
 than a per-object flag. A per-object list seems an obtuse way to encode an
 attribute, and I am quite sure implementations would prefer an attribute.

 At first glance, I expect that the addition of such an attribute should
 not trigger much BC issues, but that needs to be examined more closely.


 If it's opt-in, e.g. we define Array.prototype.contains with [[Overridable]]
 among its attributes, then at least MooTools works.

 What could break? Code that did not expect 'contains' to exist on
 Array.prototype, but did expect assigning to someArray.contains would make a
 non-enumerable and/or non-own property. That would seem like nonsense or
 broken code, but it could exist for some name and prototypal relation,
 you're right.

 Only way to find out is to implement and test at scale.

 It would be good to hear from implementors on the idea of an [[Overridable]]
 attribute. SpiderMonkey has something similar but more restricted (see
 http://dxr.mozilla.org/mozilla-central/source/js/src/vm/Shape.h?from=SHADOWABLEcase=true#1013).

 /be

 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains solutions

2014-10-01 Thread Brendan Eich

Jason Orendorff wrote:

I'd love to be able to get rid of SHADOWABLE, actually! I just
recently found out we can do it with a little rearranging. Extra
state-space in property attributes is unavoidable complexity for us.
My own preference would be not to standardize it.:)

There's also the [Replaceable] attribute in WebIDL, which arises from
similar compatibility needs. It's implemented as a setter that
redefines the property being set.


Nature is trying to tell you something :-P.


This is a bad bunch of options. I think renaming (hasValue?) is
probably least-worst, followed by waiting a year and trying again.


Maybe, but if we fail then, we can't keep waiting. ES7 is 2015-2016, no 
slipping that train.


/be
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


RE: Array.prototype.contains solutions

2014-09-30 Thread Domenic Denicola
From: es-discuss [mailto:es-discuss-boun...@mozilla.org] On Behalf Of Domenic 
Denicola

 Or you could attack the problem at the for-in level

This half-sentence was a leftover from an earlier pass; please ignore it.

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains solutions

2014-09-30 Thread John-David Dalton
A more general solution seems like a good idea.
Renaming doesn't really solve the deeper issue.
Extending native prototypes is a JavaScript thing and something that will
most likely continue continue.

Ember adds methods to Array.prototype and Function.prototype by default:
http://emberjs.com/api/classes/Ember.Array.html#method_contains (btw their
Array#contains is not ES7 spec compliant either)

then there's the oldie Prototype.js:
http://api.prototypejs.org/

and alternatives like Sugar.js:
http://sugarjs.com/api

that's a lot to watch out for.

JDD


On Tue, Sep 30, 2014 at 5:03 PM, Domenic Denicola 
dome...@domenicdenicola.com wrote:

 From: es-discuss [mailto:es-discuss-boun...@mozilla.org] On Behalf Of
 Domenic Denicola

  Or you could attack the problem at the for-in level

 This half-sentence was a leftover from an earlier pass; please ignore it.

 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains solutions

2014-09-30 Thread Boris Zbarsky

On 9/30/14, 8:12 PM, John-David Dalton wrote:

Extending native prototypes is a JavaScript thing and something that
will most likely continue continue.


Note that if people were extending in nice ways, using defineProperty 
and making their props non-enumerable instead of just doing a [[Set]], 
that would significantly reduce issues like this...


-Boris
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains solutions

2014-09-30 Thread John-David Dalton
Maybe.
Though there would still be issues with implementations not aligning, like
Ember which does use defineProperty to make them non-enumerable and doesn't
pave existing methods,
as well as issues with scripts that support pre-ES5 environments that don't
want enumerable inconsistency.

JDD


On Tue, Sep 30, 2014 at 5:15 PM, Boris Zbarsky bzbar...@mit.edu wrote:

 On 9/30/14, 8:12 PM, John-David Dalton wrote:

 Extending native prototypes is a JavaScript thing and something that
 will most likely continue continue.


 Note that if people were extending in nice ways, using defineProperty and
 making their props non-enumerable instead of just doing a [[Set]], that
 would significantly reduce issues like this...

 -Boris

 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains solutions

2014-09-30 Thread Mark S. Miller
On Tue, Sep 30, 2014 at 4:58 PM, Domenic Denicola 
dome...@domenicdenicola.com wrote:

 This is a follow-up thread to discuss how to solve the problem identified
 in
 http://esdiscuss.org/topic/having-a-non-enumerable-array-prototype-contains-may-not-be-web-compatible
 without breaking the web. (Any arguments that it is OK to break sites using
 MooTools, please stay in that thread and respectfully do *not* reply to
 this one.)

 ---

 So, guess that proves I should never say this will be easy! before
 working on a feature. Yay, the web.

 I see a few options:

 1. Rename. The leading candidate would be `Array.prototype.has`. I
 outlined in [1] why `contains` is better; note especially the DOM classes.
 But you could stretch things, especially by removing the `fromIndex`
 parameter, into an argument that `has` is OK. (Basically, you'd be saying
 that an array is more like a set than a map, and that its analogy with
 String is mostly accidental.)


If we do rename, it should be almost anything other than .has. Arrays are
clearly single-valued-mapping-like, not set-like, in that they map from
indexes to values. If Array.prototype.has were to exist, it would need to
test possible indexes.




 2. Specific hacks. I am thinking of e.g. making `Array.prototype.contains`
 a getter, with a setter that does [[DefineOwnProperty]].


This could work, and it requires no new kernel mechanisms. If we do adopt
this solution, the setter should be careful to play the same games that SES
plays to work around the override mistake: If the this being set is not
Array.prototype itself, the setter should use [[DefineOwnProperty]] to
emulate an assignment to that this's own .contains.



 3. General hacks. I joked about @@unMooToolsables, but seriously, we could
 do something similar to @@unscopables of using MOP hooks to fix this
 problem. One idea that seems reasonable is @@enumerableWhenAssigned, so
 that `Array.prototype.contains` starts non-enumerable, but when you do
 `Array.prototype.contains = x`, it becomes enumerable. You could even
 generalize this into something that also fixes the override mistake [2],
 e.g. @@defineOwnPropertyOnAssign or @@assignIgnoresProto or similar. Or you
 could attack the problem at the for-in level


I suggest we focus on the override mistake. If we come up with a way of
fixing it and .contains with one new kernel mechanism, that would be great.
If we only fix the override mistake, still likely worth it. But if a new
kernel mechanism only fixes .contains, it likely isn't worth it and we
should return to #1 or #2.





 ---

 1 is tempting in its simplicity. 2 is pretty gross and we'd probably be
 better of throwing out the feature. 3 is intriguing, although it obviously
 adds complexity cost to a feature that was supposed to be trivial.

 I am curious if there is any support for 3, or proposals for a better hack
 in that vein. Because we will also have this problem for any other
 prototype extensions that work in the same way, e.g. MooTools's `flatten`
 (which seems like something we'd likely want) or their `associate`, `link`,
 `getRandom`, `combine`, or `pick` (which seem less likely). And I assume
 the problem could extend beyond MooTools, and possibly beyond Array.
 (Although, Array is a special case in that we can't make any of its methods
 enumerable.)

 Especially if we choose something more general, e.g. @@assignIgnoresProto,
 I could see this being a powerful tool for fighting such problems in the
 future, and maybe for helping fix the override mistake (although I don't
 understand all of the use cases involved there).

 [1]:
 https://github.com/domenic/Array.prototype.contains/#why-contains-instead-of-has
 [2]:
 http://wiki.ecmascript.org/doku.php?id=strawman:fixing_override_mistake


The most painful use case is the existence of perfectly reasonable ES5 code
like:


function Point(x, y) { this.x = x; this.y = y; }

Point.prototype.toString() { return `${x},${y}`; };

Because of the override mistake, this reasonable code no longer works after

Object.freeze(Object.prototype);

This sucks.

SES goes out of its way to not break code that follows ES5 best practices.
The above Point code does. That's why SES's tamperProof(Object.prototype)
replaces the data properties on Object.prototype with accessor properties
whose setter uses [[DefineOwnProperty]] to emulate assignment on a this
that is not Object.prototype itself.

With your #3, perhaps we'd have a less painful way to working around the
override mistake.



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss




-- 
Cheers,
--MarkM
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-07-24 Thread Will Ray
Would Array.prototype.removeAll(element); be worth considering? In the same
vein as querySelector/querySelectorAll?


On Wed, Jul 23, 2014 at 4:05 PM, Alex Vincent ajvinc...@gmail.com wrote:

 On Wed, Jul 23, 2014 at 2:00 PM, Michael Haufe t...@thenewobjective.com
 wrote:

 Array.prototype.removeAt(index);
 Array.prototype.remove(element);


 We already have an equivalent of removeAt:  Array.prototype.splice(index,
 1).  My concern about remove still stands.

 --
 The first step in confirming there is a bug in someone else's work is
 confirming there are no bugs in your own.
 -- Alexander J. Vincent, June 30, 2001

 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


RE: Array.prototype.contains

2014-07-24 Thread Andrea Giammarchi
What is this about? Not an answer nor a solution to what I've said...
Just think that NaN is rarely an explicit value, rather something
potentially generated at runtime. Would
you .some(Number.isNAN.bind(Number)) all the Arrays? I don't think so,
at least I wouldn't

Sent from my Windows Phone From: Garrett Smith
Sent: ‎7/‎23/‎2014 22:31
To: Andrea Giammarchi
Cc: Alex Vincent; es-discuss@mozilla.org
Subject: Re: Array.prototype.contains
On 7/23/14, Andrea Giammarchi andrea.giammar...@gmail.com wrote:
 agreed, already imagining loops like

 ```js
 while (arr.contains(value)) arr.remove(value);
 ```

 although that looks a bit nicer than

 ```js
 var i;
 while (-1  (i = arr.indexOf(value))) arr.splice(i, 1);
 ```

 my main concern about `.contains()` is its potentially un-optimal
 implementation and error prone logic.

 Most of the time we want to know if an array contains something to avoid
 duplicated because we are missing `.unique()`

 ```js
 if (!arr.contains(obj)) arr.push(obj);
 ```

 Most other times we want to do some action with that contained value or its
 index and here we have a redundant and error prone cases:

 ```js
 if (arr.contains(obj)) {
   // need the index anyway
   var i = arr.indexOf(obj); // but this might fail 
   // splice or do other things ...
 }
 ```

 AFAIR the latter `.contains()` does not suffer same problems `.indexOf()`
 does and this will result in incompatible operations with array indexes,
 assuming contains told us we are good to go.

 As example, `.contains(NaN)` can cause disaster-prone logics if followed by
 `.indexOf(NaN)` because the first check will tell the developer at runtime
 for sure something was there while the second check will return a lovely -1
 most likely unexpected inside the block that believe `.contains(value)` was
 a safe bet.



// Contains NaN:
[1, NaN, ].some(function(e) {return Number.isNaN(e);})
-- 
Garrett
@xkit
ChordCycles.com
garretts.github.io
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-07-24 Thread Garrett Smith
On 7/24/14, Andrea Giammarchi andrea.giammar...@gmail.com wrote:
 What is this about? Not an answer nor a solution to what I've said...
 Just think that NaN is rarely an explicit value, rather something
 potentially generated at runtime. Would
 you .some(Number.isNAN.bind(Number)) all the Arrays? I don't think so,
 at least I wouldn't


It looked like you were trying to determine if a finite number is in
an array. Is that right? That answer to how to do that would be:

Number.isFinite(v)  arr.indexOf(v) != -1;
-- 
Garrett
@xkit
ChordCycles.com
garretts.github.io
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-07-24 Thread Andrea Giammarchi
no, my concern is about having different results between .contains() and
.indexOf() in production code ... the NaN was the most obvious case/example
on how that could go deadly wrong.

if a.contains(v) i = a.indexOf(v); now enjoy inconsistency with what you
were expecting ^_^

Just to clarify, I am not saying .contains() should not exist in first
place, I am saying we should fix bloody indexOf too ... we can easily fix
broken old gotchas and polyfill them on top instead of mixing up methods
used for potentially similar intent but absolutely not replaceable for the
same ... if tomorrow everyone will swap from -1  a.indexOf() to
a.contains() maybe that's desired but surely not the same thing, and vice
versa when the contained index is needed.

Best Regards



On Thu, Jul 24, 2014 at 11:30 AM, Garrett Smith dhtmlkitc...@gmail.com
wrote:

 On 7/24/14, Andrea Giammarchi andrea.giammar...@gmail.com wrote:
  What is this about? Not an answer nor a solution to what I've said...
  Just think that NaN is rarely an explicit value, rather something
  potentially generated at runtime. Would
  you .some(Number.isNAN.bind(Number)) all the Arrays? I don't think so,
  at least I wouldn't
 

 It looked like you were trying to determine if a finite number is in
 an array. Is that right? That answer to how to do that would be:

 Number.isFinite(v)  arr.indexOf(v) != -1;
 --
 Garrett
 @xkit
 ChordCycles.com
 garretts.github.io

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-07-23 Thread Maël Nison
Isn't replacing DOMStringList a different issue than adding
Array.prototype.contains ?

Using indexOf is possible, but a .contains() method would give a stronger
notice of intent when reading code.


On 7 March 2014 15:11, Boris Zbarsky bzbar...@mit.edu wrote:

 On 3/6/14 6:15 PM, Joshua Bell wrote:

 FWIW, Blink uses DOMStringList only in IndexedDB and apparently in
 Location.ancestorOrigins


 Indeed.  And Location.ancestorOrigins is fairly new and not broadly
 implemented, so I don't expect its behavior to be a strong compat
 constraint.

 So I guess that leaves us with a few questions:

 1)  Is it still early enough in the indexeddb world that we can change the
 thing it uses from DOMStringList to Array.  And if so whether that's a
 change we want to make.

 2)  If we want to keep the non-writing behavior for indexeddb or for some
 other reason (insufficiently flexible bindings systems?) can't switch ti to
 Array for now, can we just remove item() and contains() from DOMStringList
 to make the switch easier later?


 -Boris
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss




-- 
Maël Nison (arcanis https://twitter.com/arcanis)
Frontend Developer @ Sketchfab
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-07-23 Thread Will Ray
Additionally, .contains() can be used in a conditional statement directly,
while .indexOf() requires the result of a comparison with -1 (or a bitwise
inversion, which is not terribly intuitive). It's just more room for simple
typos.

Will Ray


On Wed, Jul 23, 2014 at 5:29 AM, Maël Nison nison.m...@gmail.com wrote:

 Isn't replacing DOMStringList a different issue than adding
 Array.prototype.contains ?

 Using indexOf is possible, but a .contains() method would give a stronger
 notice of intent when reading code.


 On 7 March 2014 15:11, Boris Zbarsky bzbar...@mit.edu wrote:

 On 3/6/14 6:15 PM, Joshua Bell wrote:

 FWIW, Blink uses DOMStringList only in IndexedDB and apparently in
 Location.ancestorOrigins


 Indeed.  And Location.ancestorOrigins is fairly new and not broadly
 implemented, so I don't expect its behavior to be a strong compat
 constraint.

 So I guess that leaves us with a few questions:

 1)  Is it still early enough in the indexeddb world that we can change
 the thing it uses from DOMStringList to Array.  And if so whether that's a
 change we want to make.

 2)  If we want to keep the non-writing behavior for indexeddb or for some
 other reason (insufficiently flexible bindings systems?) can't switch ti to
 Array for now, can we just remove item() and contains() from DOMStringList
 to make the switch easier later?


 -Boris
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss




 --
 Maël Nison (arcanis https://twitter.com/arcanis)
 Frontend Developer @ Sketchfab



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-07-23 Thread Rick Waldron
Array.prototype.contains has been approved for the ES7 process:
https://github.com/rwaldron/tc39-notes/blob/master/es6/2014-04/apr-9.md#45-arrayprototypecontains

Rick


On Wed, Jul 23, 2014 at 12:41 PM, Will Ray wray...@gmail.com wrote:

 Additionally, .contains() can be used in a conditional statement directly,
 while .indexOf() requires the result of a comparison with -1 (or a bitwise
 inversion, which is not terribly intuitive). It's just more room for simple
 typos.

 Will Ray


 On Wed, Jul 23, 2014 at 5:29 AM, Maël Nison nison.m...@gmail.com wrote:

 Isn't replacing DOMStringList a different issue than adding
 Array.prototype.contains ?

 Using indexOf is possible, but a .contains() method would give a stronger
 notice of intent when reading code.


 On 7 March 2014 15:11, Boris Zbarsky bzbar...@mit.edu wrote:

 On 3/6/14 6:15 PM, Joshua Bell wrote:

 FWIW, Blink uses DOMStringList only in IndexedDB and apparently in
 Location.ancestorOrigins


 Indeed.  And Location.ancestorOrigins is fairly new and not broadly
 implemented, so I don't expect its behavior to be a strong compat
 constraint.

 So I guess that leaves us with a few questions:

 1)  Is it still early enough in the indexeddb world that we can change
 the thing it uses from DOMStringList to Array.  And if so whether that's a
 change we want to make.

 2)  If we want to keep the non-writing behavior for indexeddb or for
 some other reason (insufficiently flexible bindings systems?) can't switch
 ti to Array for now, can we just remove item() and contains() from
 DOMStringList to make the switch easier later?


 -Boris
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss




 --
 Maël Nison (arcanis https://twitter.com/arcanis)
 Frontend Developer @ Sketchfab



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


RE: Array.prototype.contains

2014-07-23 Thread Domenic Denicola
Yes. Everyone agrees .contains is good. It will happen.

There was some debate about .has vs. .contains, but from what I recall I was 
one of the only people pushing for .has, and I have since changed my mind.

I am hopeful in fact that .contains is so simple and uncontroversial that we 
can push it through the post-ES6 spec process very quickly, including into 
implementations.

From: es-discuss [mailto:es-discuss-boun...@mozilla.org] On Behalf Of Will Ray
Sent: Wednesday, July 23, 2014 12:42
To: Maël Nison
Cc: Brendan Eich; es-discuss@mozilla.org
Subject: Re: Array.prototype.contains

Additionally, .contains() can be used in a conditional statement directly, 
while .indexOf() requires the result of a comparison with -1 (or a bitwise 
inversion, which is not terribly intuitive). It's just more room for simple 
typos.

Will Ray

On Wed, Jul 23, 2014 at 5:29 AM, Maël Nison 
nison.m...@gmail.commailto:nison.m...@gmail.com wrote:
Isn't replacing DOMStringList a different issue than adding 
Array.prototype.contains ?

Using indexOf is possible, but a .contains() method would give a stronger 
notice of intent when reading code.

On 7 March 2014 15:11, Boris Zbarsky 
bzbar...@mit.edumailto:bzbar...@mit.edu wrote:
On 3/6/14 6:15 PM, Joshua Bell wrote:
FWIW, Blink uses DOMStringList only in IndexedDB and apparently in
Location.ancestorOrigins

Indeed.  And Location.ancestorOrigins is fairly new and not broadly 
implemented, so I don't expect its behavior to be a strong compat constraint.

So I guess that leaves us with a few questions:

1)  Is it still early enough in the indexeddb world that we can change the 
thing it uses from DOMStringList to Array.  And if so whether that's a change 
we want to make.

2)  If we want to keep the non-writing behavior for indexeddb or for some other 
reason (insufficiently flexible bindings systems?) can't switch ti to Array for 
now, can we just remove item() and contains() from DOMStringList to make the 
switch easier later?


-Boris
___
es-discuss mailing list
es-discuss@mozilla.orgmailto:es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss



--
Maël Nison (arcanishttps://twitter.com/arcanis)
Frontend Developer @ Sketchfab



___
es-discuss mailing list
es-discuss@mozilla.orgmailto:es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-07-23 Thread Garrett Smith
On 7/23/14, Maël Nison nison.m...@gmail.com wrote:
 Isn't replacing DOMStringList a different issue than adding
 Array.prototype.contains ?

 Using indexOf is possible, but a .contains() method would give a stronger
 notice of intent when reading code.


So too, for cases of removing an item, would Array.prototype.remove(v)
show clear intent.


 On 7 March 2014 15:11, Boris Zbarsky bzbar...@mit.edu wrote:

 On 3/6/14 6:15 PM, Joshua Bell wrote:

 FWIW, Blink uses DOMStringList only in IndexedDB and apparently in
 Location.ancestorOrigins


 Indeed.  And Location.ancestorOrigins is fairly new and not broadly
 implemented, so I don't expect its behavior to be a strong compat
 constraint.

 So I guess that leaves us with a few questions:

 1)  Is it still early enough in the indexeddb world that we can change
 the
 thing it uses from DOMStringList to Array.  And if so whether that's a
 change we want to make.

 2)  If we want to keep the non-writing behavior for indexeddb or for some
 other reason (insufficiently flexible bindings systems?) can't switch ti
 to
 Array for now, can we just remove item() and contains() from
 DOMStringList
 to make the switch easier later?


 -Boris
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss




 --
 Maël Nison (arcanis https://twitter.com/arcanis)
 Frontend Developer @ Sketchfab



-- 
Garrett
@xkit
ChordCycles.com
garretts.github.io
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-07-23 Thread Alex Vincent
On Wed, Jul 23, 2014 at 11:18 AM, es-discuss-requ...@mozilla.org wrote:

 So too, for cases of removing an item, would Array.prototype.remove(v)
 show clear intent.


I would actually raise a concern about that method.  Suppose v shows up in
the array more than once.  Do you remove the first appearance, the last, or
all of them?

-- 
The first step in confirming there is a bug in someone else's work is
confirming there are no bugs in your own.
-- Alexander J. Vincent, June 30, 2001
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-07-23 Thread Michael Haufe
Array.prototype.removeAt(index);
Array.prototype.remove(element);



On Wed, Jul 23, 2014 at 3:12 PM, Alex Vincent ajvinc...@gmail.com wrote:

 On Wed, Jul 23, 2014 at 11:18 AM, es-discuss-requ...@mozilla.org wrote:

 So too, for cases of removing an item, would Array.prototype.remove(v)
 show clear intent.


 I would actually raise a concern about that method.  Suppose v shows up in
 the array more than once.  Do you remove the first appearance, the last, or
 all of them?

 --
 The first step in confirming there is a bug in someone else's work is
 confirming there are no bugs in your own.
 -- Alexander J. Vincent, June 30, 2001

 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-07-23 Thread Alex Vincent
On Wed, Jul 23, 2014 at 2:00 PM, Michael Haufe t...@thenewobjective.com
wrote:

 Array.prototype.removeAt(index);
 Array.prototype.remove(element);


We already have an equivalent of removeAt:  Array.prototype.splice(index,
1).  My concern about remove still stands.

-- 
The first step in confirming there is a bug in someone else's work is
confirming there are no bugs in your own.
-- Alexander J. Vincent, June 30, 2001
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-07-23 Thread Andrea Giammarchi
agreed, already imagining loops like

```js
while (arr.contains(value)) arr.remove(value);
```

although that looks a bit nicer than

```js
var i;
while (-1  (i = arr.indexOf(value))) arr.splice(i, 1);
```

my main concern about `.contains()` is its potentially un-optimal
implementation and error prone logic.

Most of the time we want to know if an array contains something to avoid
duplicated because we are missing `.unique()`

```js
if (!arr.contains(obj)) arr.push(obj);
```

Most other times we want to do some action with that contained value or its
index and here we have a redundant and error prone cases:

```js
if (arr.contains(obj)) {
  // need the index anyway
  var i = arr.indexOf(obj); // but this might fail 
  // splice or do other things ...
}
```

AFAIR the latter `.contains()` does not suffer same problems `.indexOf()`
does and this will result in incompatible operations with array indexes,
assuming contains told us we are good to go.

As example, `.contains(NaN)` can cause disaster-prone logics if followed by
`.indexOf(NaN)` because the first check will tell the developer at runtime
for sure something was there while the second check will return a lovely -1
most likely unexpected inside the block that believe `.contains(value)` was
a safe bet.

Just my 2 cents on an issue I see coming soon on your screens

Regards




On Wed, Jul 23, 2014 at 2:05 PM, Alex Vincent ajvinc...@gmail.com wrote:

 On Wed, Jul 23, 2014 at 2:00 PM, Michael Haufe t...@thenewobjective.com
 wrote:

 Array.prototype.removeAt(index);
 Array.prototype.remove(element);


 We already have an equivalent of removeAt:  Array.prototype.splice(index,
 1).  My concern about remove still stands.

 --
 The first step in confirming there is a bug in someone else's work is
 confirming there are no bugs in your own.
 -- Alexander J. Vincent, June 30, 2001

 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-07-23 Thread Garrett Smith
On 7/23/14, Andrea Giammarchi andrea.giammar...@gmail.com wrote:
 agreed, already imagining loops like

 ```js
 while (arr.contains(value)) arr.remove(value);
 ```

 although that looks a bit nicer than

 ```js
 var i;
 while (-1  (i = arr.indexOf(value))) arr.splice(i, 1);
 ```

 my main concern about `.contains()` is its potentially un-optimal
 implementation and error prone logic.

 Most of the time we want to know if an array contains something to avoid
 duplicated because we are missing `.unique()`

 ```js
 if (!arr.contains(obj)) arr.push(obj);
 ```

 Most other times we want to do some action with that contained value or its
 index and here we have a redundant and error prone cases:

 ```js
 if (arr.contains(obj)) {
   // need the index anyway
   var i = arr.indexOf(obj); // but this might fail 
   // splice or do other things ...
 }
 ```

 AFAIR the latter `.contains()` does not suffer same problems `.indexOf()`
 does and this will result in incompatible operations with array indexes,
 assuming contains told us we are good to go.

 As example, `.contains(NaN)` can cause disaster-prone logics if followed by
 `.indexOf(NaN)` because the first check will tell the developer at runtime
 for sure something was there while the second check will return a lovely -1
 most likely unexpected inside the block that believe `.contains(value)` was
 a safe bet.



// Contains NaN:
[1, NaN, ].some(function(e) {return Number.isNaN(e);})
-- 
Garrett
@xkit
ChordCycles.com
garretts.github.io
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


RE: Array.prototype.contains

2014-03-07 Thread medikoo
Domenic Denicola-2 wrote
 Personally I think the more useful model to follow than
 `String.prototype.contains` is `Set.prototype.has`.

API wise, arrays have much more in common with strings than with sets.

Thinking ES5, they're both array-likes, set isn't. They share `length`
property,  their values can be accessed through indexes arr[0], str[0], they
share few method names (`indexOf`, `lastIndexOf`), and all non destructive
array methods can be successfully executed on strings, while they won't work
with sets.

I think it would be more appropriate to stick with `arr.contains` especially
that we already have `arr.indexOf` and `str.indexOf`, and both `indexOf` and
`contains` share same signature.

`arr.has` could be fine, if we also rename `str.contains` to `str.has`.







--
View this message in context: 
http://mozilla.6506.n7.nabble.com/Array-prototype-contains-tp309926p310234.html
Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at 
Nabble.com.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-03-07 Thread Domenic Denicola
If that's the argument, then Array.prototype.contains should accept another 
Array, not an element to check.

 On Mar 7, 2014, at 5:49, medikoo medikoo+mozilla@medikoo.com wrote:
 
 Domenic Denicola-2 wrote
 Personally I think the more useful model to follow than
 `String.prototype.contains` is `Set.prototype.has`.
 
 API wise, arrays have much more in common with strings than with sets.
 
 Thinking ES5, they're both array-likes, set isn't. They share `length`
 property,  their values can be accessed through indexes arr[0], str[0], they
 share few method names (`indexOf`, `lastIndexOf`), and all non destructive
 array methods can be successfully executed on strings, while they won't work
 with sets.
 
 I think it would be more appropriate to stick with `arr.contains` especially
 that we already have `arr.indexOf` and `str.indexOf`, and both `indexOf` and
 `contains` share same signature.
 
 `arr.has` could be fine, if we also rename `str.contains` to `str.has`.
 
 
 
 
 
 
 
 --
 View this message in context: 
 http://mozilla.6506.n7.nabble.com/Array-prototype-contains-tp309926p310234.html
 Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at 
 Nabble.com.
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-03-07 Thread Mariusz Nowak
...and same for indexOf and lastIndexOf? ;-)

On 7 mar 2014, at 13:33, Domenic Denicola dome...@domenicdenicola.com wrote:

 If that's the argument, then Array.prototype.contains should accept another 
 Array, not an element to check.
 
 On Mar 7, 2014, at 5:49, medikoo medikoo+mozilla@medikoo.com wrote:
 
 Domenic Denicola-2 wrote
 Personally I think the more useful model to follow than
 `String.prototype.contains` is `Set.prototype.has`.
 
 API wise, arrays have much more in common with strings than with sets.
 
 Thinking ES5, they're both array-likes, set isn't. They share `length`
 property,  their values can be accessed through indexes arr[0], str[0], they
 share few method names (`indexOf`, `lastIndexOf`), and all non destructive
 array methods can be successfully executed on strings, while they won't work
 with sets.
 
 I think it would be more appropriate to stick with `arr.contains` especially
 that we already have `arr.indexOf` and `str.indexOf`, and both `indexOf` and
 `contains` share same signature.
 
 `arr.has` could be fine, if we also rename `str.contains` to `str.has`.
 
 
 
 
 
 
 
 --
 View this message in context: 
 http://mozilla.6506.n7.nabble.com/Array-prototype-contains-tp309926p310234.html
 Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at 
 Nabble.com.
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-03-07 Thread Boris Zbarsky

On 3/6/14 6:45 PM, C. Scott Ananian wrote:

And don't forget the related `DOMTokenList`, which is in
Element.classList and thus used by everyone always.


How is it related?  DOMTokenList is indeed an API for a list of strings 
(sort of; they're pretty restricted in terms of what strings they can 
be), but has a bunch of other functionality that DOMStringList does not 
have and that ES arrays don't have and shouldn't have.  toggle() doesn't 
make sense on arrays in general, for example.



The `contains` and `item` methods are in `DOMTokenList`, so they
probably shouldn't be removed from `DOMStringList`.


I think I missed a logical connection here.  Can you expand on the 
reasoning here?



But I don't think anyone was seriously proposing that


_I_ am seriously proposing that DOMStringList go away compeletely and 
APIs that return it just return Arrays.  Not subclasses of Arrays, just 
Arrays.



(and maybe `DOMTokenList` would also be related to `Array`?)


DOMTokenList is writable and the writes must enforce all sorts of 
invariants that Arrays do not enforce, so making it a subclass of Array 
would be slightly odd, actually.  The main benefit would be to get map() 
and company working on it, which may be worth it.


-Boris

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-03-07 Thread Boris Zbarsky

On 3/6/14 6:15 PM, Joshua Bell wrote:

FWIW, Blink uses DOMStringList only in IndexedDB and apparently in
Location.ancestorOrigins


Indeed.  And Location.ancestorOrigins is fairly new and not broadly 
implemented, so I don't expect its behavior to be a strong compat 
constraint.


So I guess that leaves us with a few questions:

1)  Is it still early enough in the indexeddb world that we can change 
the thing it uses from DOMStringList to Array.  And if so whether that's 
a change we want to make.


2)  If we want to keep the non-writing behavior for indexeddb or for 
some other reason (insufficiently flexible bindings systems?) can't 
switch ti to Array for now, can we just remove item() and contains() 
from DOMStringList to make the switch easier later?


-Boris
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


RE: Array.prototype.contains

2014-03-06 Thread Domenic Denicola
 That would not allow us to kill DOMStringList.

Can we get more background on DOMStringList? It seems unlikely that you could 
get away with replacing a string-only type, which, from the specs I can find, 
seems to be immutable and have an additional index() method, with an actual 
mutable any-type-containing array.

It's not in http://dom.spec.whatwg.org (except as don't implement this) and 
https://developer.mozilla.org/en-US/docs/Web/API/DOMStringList implies it's not 
implemented in Mozilla, and only used by an obscure property.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-03-06 Thread Boris Zbarsky

On 3/6/14 3:58 PM, Domenic Denicola wrote:

That would not allow us to kill DOMStringList.


Can we get more background on DOMStringList?


Sure.  It's used in the following places in Gecko, as far as I can tell:

1) document.styleSheetSets.
2) Microdata API.
3) Various places in indexeddb.
4) The DataTransfer API.
5) Some sort of offline resource list API that's not part of any 
standard I can find.


#1 is not implemented by anyone but Gecko, and the spec is claiming it's 
a DOMString[], which no on implements at all.


#2 is likewise not implemented by anyone but Gecko at this point, and 
the spec likewise claims DOMString[] (which again no one implements).


For #3 I've heard Jonas claim he'd like to just moving ES arrays there.

#4 is specced as a DOMString[], which again no one implements.

I don't know offhand what other UAs do for #3 and #4.


It seems unlikely that you could get away with replacing a string-only type, 
which, from the specs I can find, seems to be immutable and have an additional 
index() method


DOMStringList in Gecko does not have an index() method.  Did you mean 
item()?


Whether it's OK to replace with a mutable and any-type-containing thing 
is an interesting philosophical question.  Some of the above use cases 
may be OK with using a frozen array, for example, or not care if the 
page changes it around, since the browser doesn't plan to use it itself.


But yes, it's not a priori obvious that one can replace the other.


https://developer.mozilla.org/en-US/docs/Web/API/DOMStringList implies it's not 
implemented in Mozilla


That page was a bald-faced lie.  Note the in need of a technical 
review bit.  ;)  I've removed the completely bogus part for now.


-Boris
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


RE: Array.prototype.contains

2014-03-06 Thread Domenic Denicola
Thanks very much Boris. It sounds like there isn't much of a cross-browser or 
standardized story on where `DOMStringList`, with its `contains()` and `item()` 
methods (yeah, I meant `item`) shows up.

I'd be curious where it shows up in Blink, IE, and WebKit codebases. If the 
intersection is small enough, such that no web developers are relying on 
`contains()` and `item()` being present on certain APIs, then maybe 
`DOMStringList` can be killed and replaced with arrays and/or frozen arrays, 
without adding `contains()`/`item()` to `Array.prototype`...
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-03-06 Thread Brendan Eich

Boris Zbarsky wrote:

1) document.styleSheetSets.
2) Microdata API.
3) Various places in indexeddb.
4) The DataTransfer API.
5) Some sort of offline resource list API that's not part of any 
standard I can find.


#1 is not implemented by anyone but Gecko, and the spec is claiming 
it's a DOMString[], which no on implements at all.


#2 is likewise not implemented by anyone but Gecko at this point, and 
the spec likewise claims DOMString[] (which again no one implements).


For #3 I've heard Jonas claim he'd like to just moving ES arrays there.

#4 is specced as a DOMString[], which again no one implements. 


What's with all the no one implements (including #3) stuff in specs? 
Are the specs new? Are we in a situation (even in #3, _pace_ Jonas) 
where the specs should be changed to reflect reality?


/be
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-03-06 Thread Boris Zbarsky

On 3/6/14 4:49 PM, Brendan Eich wrote:

What's with all the no one implements (including #3) stuff in specs?


IDL Arrays in general are not implemented by anyone that I know of (and 
possibly ever).  They were a new concept added in WebIDL that hasn't 
really caught on with implementations.  In Gecko's case that was because 
we never got around to it, and it was simpler to use the infrastructure 
we needed to create anyway or already had for indexed getters (c.f. 
DOMStringList, NodeList, etc) than to create a bunch of new 
infrastructure for IDL Arrays.


And then people realized that in some ways IDL Arrays are an attractive 
nuisance even if they were implemented, which made the priority on 
implementing them even less.


https://www.w3.org/Bugs/Public/show_bug.cgi?id=23682 has discussion 
that's worth reading, if people haven't already, about the various use 
cases that arise for arrays and arraylikes and how to best solve them.



Are the specs new?


Somewhat.


Are we in a situation (even in #3, _pace_ Jonas)
where the specs should be changed to reflect reality?


Yes.  Need to figure out what reality is or should be, first.

-Boris
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-03-06 Thread Joshua Bell
FWIW, Blink uses DOMStringList only in IndexedDB and apparently in
Location.ancestorOrigins



On Thu, Mar 6, 2014 at 1:59 PM, Boris Zbarsky bzbar...@mit.edu wrote:

 On 3/6/14 4:49 PM, Brendan Eich wrote:

 What's with all the no one implements (including #3) stuff in specs?


 IDL Arrays in general are not implemented by anyone that I know of (and
 possibly ever).  They were a new concept added in WebIDL that hasn't really
 caught on with implementations.  In Gecko's case that was because we never
 got around to it, and it was simpler to use the infrastructure we needed to
 create anyway or already had for indexed getters (c.f. DOMStringList,
 NodeList, etc) than to create a bunch of new infrastructure for IDL Arrays.

 And then people realized that in some ways IDL Arrays are an attractive
 nuisance even if they were implemented, which made the priority on
 implementing them even less.

 https://www.w3.org/Bugs/Public/show_bug.cgi?id=23682 has discussion
 that's worth reading, if people haven't already, about the various use
 cases that arise for arrays and arraylikes and how to best solve them.

  Are the specs new?


 Somewhat.


  Are we in a situation (even in #3, _pace_ Jonas)
 where the specs should be changed to reflect reality?


 Yes.  Need to figure out what reality is or should be, first.

 -Boris

 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-03-06 Thread Claude Pache

Le 7 mars 2014 à 00:45, C. Scott Ananian ecmascr...@cscott.net a écrit :

 And don't forget the related `DOMTokenList`, which is in
 Element.classList and thus used by everyone always.
 

Indeed, and there is also the (less known) `htmlFor` property of  the output 
element, which is precisely a `DOMSettableTokenList`.

Since arraylike interfaces from the DOM uses `.contains()`, for the sake of 
consistency, the corresponding method on `Array.prototype` ought to be named 
`.contains()`. Sets are quite different from Arrays, so it is less important to 
have the same naming scheme as Sets than as all other arraylikes. (And another 
weaker reason to prefer `.contains()`: Maps and WeakMaps uses `.has()` for 
*keys*, and here we are talking about the *values* of an Array.)

—Claude

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-03-05 Thread David Bruant

Le 05/03/2014 09:24, Eric Elliott a écrit :
What ever happened to Array.prototype.contains? There's an old 
strawman for Array.prototype.has ( 
http://wiki.ecmascript.org/doku.php?id=strawman:array.prototype.has ) 
that references this thread: ( 
https://mail.mozilla.org/pipermail/es-discuss/2012-February/020745.html )

Let's try to add it to the next meeting agenda
https://github.com/tc39/agendas/pull/27

But it seems the thread fizzled out a couple years ago, and 
Array.prototype.contains didn't seem to make its way into ES6. That 
seems odd, since we do have String.prototype.contains, and it seemed 
like it was desirable for DOM.

The DOM won't inherit from it directly, shall it?



It's also a standard utility function in several libraries.

Was it left out on purpose? If so, what was the justification?

I predict code like this without it:

''.contains.call([1,2,3],2);// true

.indexOf === -1 works today for this use case and will continue to.
I'd be happy to see !~arr.indexOf(el) disappear in favor of a use of 
.contains() though.


David
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-03-05 Thread Eric Elliott
According to the thread:

* On Thu, Feb 23, 2012 at 3:15 PM, Erik Arvidsson erik.arvidsson at gmail.com 
https://mail.mozilla.org/listinfo/es-discuss
** wrote:*

* DOM4 added a new interface called DOMStringList for the sole reason
** that Array does not have contains. Before this the return type was an
** Array of Strings so we could use indexOf, map, forEach etc. Now that
** it is using a non Array we lost all of that.

 *We (WebKit) used to return a true JS Array (created by JSC or V8).


Author, Programming JavaScript Applications (O'Reilly)
http://ericleads.com/


On Wed, Mar 5, 2014 at 2:07 AM, David Bruant bruan...@gmail.com wrote:

  Le 05/03/2014 09:24, Eric Elliott a écrit :

 What ever happened to Array.prototype.contains? There's an old strawman
 for Array.prototype.has (
 http://wiki.ecmascript.org/doku.php?id=strawman:array.prototype.has )
 that references this thread: (
 https://mail.mozilla.org/pipermail/es-discuss/2012-February/020745.html )

 Let's try to add it to the next meeting agenda
 https://github.com/tc39/agendas/pull/27


   But it seems the thread fizzled out a couple years ago, and
 Array.prototype.contains didn't seem to make its way into ES6. That seems
 odd, since we do have String.prototype.contains, and it seemed like it was
 desirable for DOM.

 The DOM won't inherit from it directly, shall it?



  It's also a standard utility function in several libraries.

  Was it left out on purpose? If so, what was the justification?

 I predict code like this without it:

 ''.contains.call([1, 2, 3], 2);  // true

 .indexOf === -1 works today for this use case and will continue to.
 I'd be happy to see !~arr.indexOf(el) disappear in favor of a use of
 .contains() though.

 David

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-03-05 Thread Sebastian Zartner

   But it seems the thread fizzled out a couple years ago, and
 Array.prototype.contains didn't seem to make its way into ES6. That seems
 odd, since we do have String.prototype.contains, and it seemed like it was
 desirable for DOM.

 The DOM won't inherit from it directly, shall it?


Why not? A use case would be to check whether a specific node is within a
NodeList.

  It's also a standard utility function in several libraries.

  Was it left out on purpose? If so, what was the justification?

 I predict code like this without it:

 ''.contains.call([1, 2, 3], 2);  // true

 .indexOf === -1 works today for this use case and will continue to.
 I'd be happy to see !~arr.indexOf(el) disappear in favor of a use of
 .contains() though.


While .indexOf() just gets you the index of one item, .contains() could
even be extended to allow to check whether an array contains several items.
E.g.

.contains([1, 2, 3], [1, 3]) // true
.contains([1, 2, 3], [1, 4]) // false

Sebastian
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-03-05 Thread Boris Zbarsky

On 3/5/14 7:04 AM, Sebastian Zartner wrote:

Why not? A use case would be to check whether a specific node is within
a NodeList.


NodeLists don't have have Array.prototype on their proto chain in 
browsers at the moment, and might never get there; there are compat 
concerns.


I'd love to get rid of DOMStringList, though.

-Boris
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-03-05 Thread Rick Waldron
On Wed, Mar 5, 2014 at 4:07 AM, David Bruant bruan...@gmail.com wrote:

  Le 05/03/2014 09:24, Eric Elliott a écrit :

 What ever happened to Array.prototype.contains? There's an old strawman
 for Array.prototype.has (
 http://wiki.ecmascript.org/doku.php?id=strawman:array.prototype.has )
 that references this thread: (
 https://mail.mozilla.org/pipermail/es-discuss/2012-February/020745.html )

 Let's try to add it to the next meeting agenda
 https://github.com/tc39/agendas/pull/27


   But it seems the thread fizzled out a couple years ago, and
 Array.prototype.contains didn't seem to make its way into ES6. That seems
 odd, since we do have String.prototype.contains, and it seemed like it was
 desirable for DOM.

 The DOM won't inherit from it directly, shall it?


The forth-coming-still-in-design Elements class will inherit from Array.

Rick
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-03-05 Thread Rick Waldron
On Wed, Mar 5, 2014 at 7:04 AM, Sebastian Zartner 
sebastianzart...@gmail.com wrote:

But it seems the thread fizzled out a couple years ago, and
 Array.prototype.contains didn't seem to make its way into ES6. That seems
 odd, since we do have String.prototype.contains, and it seemed like it was
 desirable for DOM.

 The DOM won't inherit from it directly, shall it?


 Why not? A use case would be to check whether a specific node is within a
 NodeList.

   It's also a standard utility function in several libraries.

  Was it left out on purpose? If so, what was the justification?

 I predict code like this without it:

 ''.contains.call([1, 2, 3], 2);  // true

 .indexOf === -1 works today for this use case and will continue to.
 I'd be happy to see !~arr.indexOf(el) disappear in favor of a use of
 .contains() though.


 While .indexOf() just gets you the index of one item, .contains() could
 even be extended to allow to check whether an array contains several items.
 E.g.

 .contains([1, 2, 3], [1, 3]) // true
 .contains([1, 2, 3], [1, 4]) // false



String.prototype.contains already has a second parameter for position
(similar to String.prototype.indexOf), for consistency an
Array.prototype.contains should have the same second fromIndex parameter
as Array.prototype.indexOf.

Rick
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


RE: Array.prototype.contains

2014-03-05 Thread Domenic Denicola
Personally I think the more useful model to follow than 
`String.prototype.contains` is `Set.prototype.has`.



From: es-discuss es-discuss-boun...@mozilla.org on behalf of Rick Waldron 
waldron.r...@gmail.com
Sent: Wednesday, March 05, 2014 11:11
To: Sebastian Zartner
Cc: es-discuss
Subject: Re: Array.prototype.contains




On Wed, Mar 5, 2014 at 7:04 AM, Sebastian Zartner 
sebastianzart...@gmail.commailto:sebastianzart...@gmail.com wrote:
But it seems the thread fizzled out a couple years ago, and 
Array.prototype.contains didn't seem to make its way into ES6. That seems odd, 
since we do have String.prototype.contains, and it seemed like it was desirable 
for DOM.
The DOM won't inherit from it directly, shall it?

Why not? A use case would be to check whether a specific node is within a 
NodeList.
It's also a standard utility function in several libraries.

Was it left out on purpose? If so, what was the justification?

I predict code like this without it:

''.contains.call([1, 2, 3], 2);  // true
.indexOf === -1 works today for this use case and will continue to.
I'd be happy to see !~arr.indexOf(el) disappear in favor of a use of 
.contains() though.

While .indexOf() just gets you the index of one item, .contains() could even be 
extended to allow to check whether an array contains several items. E.g.

.contains([1, 2, 3], [1, 3]) // true
.contains([1, 2, 3], [1, 4]) // false


String.prototype.contains already has a second parameter for position 
(similar to String.prototype.indexOf), for consistency an 
Array.prototype.contains should have the same second fromIndex parameter as 
Array.prototype.indexOf.

Rick


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-03-05 Thread Mathias Bynens
On 5 Mar 2014, at 17:19, Domenic Denicola dome...@domenicdenicola.com wrote:

 Personally I think the more useful model to follow than 
 `String.prototype.contains` is `Set.prototype.has`.

But then DOM4 `DOMStringList` would still have its own `contains` _and_ the 
`has` it inherits from `Array.prototype`. That seems confusing, no?
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2014-03-05 Thread Anne van Kesteren
On Wed, Mar 5, 2014 at 11:19 PM, Domenic Denicola
dome...@domenicdenicola.com wrote:
 Personally I think the more useful model to follow than
 `String.prototype.contains` is `Set.prototype.has`.

That would not allow us to kill DOMStringList.


-- 
http://annevankesteren.nl/
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-14 Thread Jason Orendorff
 On Fri, Nov 2, 2012 at 4:30 PM, Allen Wirfs-Brock al...@wirfs-brock.comwrote:

 There is no verifiable formal contract.  But there can be an informal
 contract.  In my experience, it is very important when using a dynamic
 language to recognize and try to support such informal contracts.


Well, I sort of agree. But even Ruby, as much as it owes to Smalltalk,
provides same-named methods in Array and Hash with completely incompatible
semantics. Hash»delete takes a key argument; Array»delete takes a value.
Array»each yields values; Hash»each yields key-value pairs. I expect this
is just because the operations you need from an Array vs. a Hash are really
different in practice. Their abstract conceptual similarity doesn't seem to
make the jump to the real world.

Returning to JS: is there really an informal contract that unifies Array,
Map, and strings? In the current spec, there's not a single method that
works the same way across all three!

The only thing that even *exists* across all three is .@@iterator(), which
is no small thing. But note that Array.prototype.@@iterator yields element
values, String.prototype.@@iterator yields UTF-16-encoded characters, and
Map.prototype.@@iterator yields key-value pairs.

A common protocol could certainly be added. For the sake of concreteness:
they could all have .hasKey(k), .hasValue(v), .get(k), .size, .keys(),
.values(), .items(), .forEach(f); and on mutable collections, .set(k, v),
.delete(k), .clear(). But I think the aesthetic appeal of this sort of
thing is way out of proportion to its practical value.

-j
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-08 Thread Jeff Walden
On 11/03/2012 11:06 PM, Mark S. Miller wrote:
 On Sat, Nov 3, 2012 at 10:13 PM, Axel Rauschmayer a...@rauschma.de 
 mailto:a...@rauschma.de wrote:
 (I am still sad we did not fix indexOf, lastIndexOf, and switch when we 
 arguably had the chance.)
 
 Can you elaborate? We don’t have the chance, any more? Would anything 
 break (or did, in tests)?
 
 I am not aware of anyone gathering any evidence one way or the other about 
 what breakage this might cause. So it is not necessarily too late. If someone 
 does gather actual evidence that the breakage would be small enough, I could 
 see us reconsider this. But I doubt we would revisit in the absence of such 
 evidence. 

Just to note, there was a (at least this one) long thread on the topic (well, 
not including switch -- I don't remember a thread that considered changing 
switch) back in the day, if someone's invested enough in this to read it.

https://mail.mozilla.org/pipermail/es5-discuss/2009-August/003006.html

Jeff
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-04 Thread Mark S. Miller
On Sat, Nov 3, 2012 at 10:13 PM, Axel Rauschmayer a...@rauschma.de wrote:

 (I am still sad we did not fix indexOf, lastIndexOf, and switch when we
 arguably had the chance.)


 Can you elaborate? We don’t have the chance, any more? Would anything
 break (or did, in tests)?


I am not aware of anyone gathering any evidence one way or the other about
what breakage this might cause. So it is not necessarily too late. If
someone does gather actual evidence that the breakage would be small
enough, I could see us reconsider this. But I doubt we would revisit in the
absence of such evidence.



 How about only letting those methods find NaN, while letting them consider
 +0 and -0 equal?


In one way, that would be a big improvement on the status quo: such a rule
would still form an equivalence class. (By contrast, === does not form an
equivalence class since it is not reflexive.)

OTOH, it would make for yet a fourth built-in equality-like test. I don't
think the payoff is worth the complexity.



 Axel

 --
 Dr. Axel Rauschmayer
 a...@rauschma.de

 home: rauschma.de
 twitter: twitter.com/rauschma
 blog: 2ality.com




-- 
Cheers,
--MarkM
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-04 Thread Claus Reinke

The set of values actually contained by the WeakMap at any moment is
non-deterministic, depending on the scheduling of gc. But this
non-determinism is non-observable. WeakMap.contains would make it
observable.


a) this concise elaboration should be part of the spec, to reduce
   guessing about the design intentions

b) there is at least one use case where observing gc would be
   useful: instrumenting code for heap profiling; 

   since built-in heap profiling is supported in too few JS debuggers 
   atm, I was wondering whether there could be some reflection-

   level language support for this object is no longer referenced,
   perhaps as an iterator for WeakMap; then tool builders could 
   use that, and standard users would be aware that this isn't a

   normal-level feature.

Claus

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-04 Thread Jason Orendorff
On Sun, Nov 4, 2012 at 3:58 AM, Claus Reinke claus.rei...@talk21.comwrote:

 The set of values actually contained by the WeakMap at any moment is
 non-deterministic, depending on the scheduling of gc. But this
 non-determinism is non-observable. WeakMap.contains would make it
 observable.


 a) this concise elaboration should be part of the spec, to reduce
guessing about the design intentions


Definitely worth a note.

b) there is at least one use case where observing gc would be
useful: instrumenting code for heap profiling; [...]


Firefox has a function,
Components.utils.nonDeterministicGetWeakMapKeys(weakmap), that can observe
GC in this way. Only privileged code (the browser itself, addons, and
certain tests) can use it. Web scripts can't.

When implementation details get exposed as part of a platform, programs
start depending (often unintentionally) on them. Let's not expose memory
management implementation details to the Web.

-j
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-03 Thread Rick Waldron
On Fri, Nov 2, 2012 at 9:55 PM, Axel Rauschmayer a...@rauschma.de wrote:

 +1

 I have always found Java’s collection API fairly intuitive. It could serve
 as a role model, at least partially.
 - Map: containsKey, containsValue


I'd rather see Set.prototype.values() defined for Map.prototype


 - Set: contains







 Note that it has an isEmpty() method.


.size get-accessor property, which will be 0 if it's empty. I honestly
believe in api growth should address a need, if this turns out to be a pain
point, then we should consider it for Collection extras in ES7, but I've
_never_ seen anyone extend Array.prototype with an isEmpty method. There
are user land implementations of isEmpty() and isEmptyObject() that are
used to make up for Object.prototype not having any way of determining if
there are any own-enumerable properties.

var o = {};

isEmpty(o); // true

o.p = 1;

isEmpty(o); // false

but Map and Set shouldn't need anything like this, because like Array, they
have a mechanism for disclosing how many things I have



 I would also want to have its methods for combining collections such as
 removeAll() and retainAll().


A more generic .filter() method would allow user code to create these
methods if the need was sufficient.

Rick




 http://docs.oracle.com/javase/6/docs/api/java/util/Map.html
 http://docs.oracle.com/javase/6/docs/api/java/util/Set.html


 [[[Sent from a mobile device. Please forgive brevity and typos.]]]

 Dr. Axel Rauschmayer
 a...@rauschma.de
 Home: http://rauschma.de
 Blog: http://2ality.com

 On 02.11.2012, at 22:30, Allen Wirfs-Brock al...@wirfs-brock.com wrote:


 On Nov 2, 2012, at 10:56 AM, Jason Orendorff wrote:

 On Fri, Nov 2, 2012 at 12:29 PM, Domenic Denicola 
 dome...@domenicdenicola.com wrote:

  If we call it has, should we also rename String.prototype.contains?

 I'd say no; the distinction between collections having an element and
 strings containing a substring seems very sensible. It's a bit more
 awkward to say a string has a substring, and a string is definitely not a
 collection of substrings in any reasonable sense.


 Well, you could also note that array.has(x) looks for a particular value,
 while map.has(x) looks for a particular key.

 But that's not the point. There's no common formal contract implemented by
 all these methods; what they share is an informal hey, look in this thing,
 and tell me if you see that thing vibe.


 There is no verifiable formal contract.  But there can be an informal
 contract.  In my experience, it is very important when using a dynamic
 language to recognize and try to support such informal contracts.

 All the uses of has we have defined so far are about the keys.  Having
 one place that is about the values to create unnecessary confusion

 Note that we (the JS/ES designers) already have a history of being being
 inconsistent in our use of names.  Consider String indexOf and Array
 indexOf they are named the same and appear to have signatures.  But they
 logically are doing quite different things.  String indexOf is looking for
 the index of the first element of a subsequence of character elements that
 matches a specific character sequence.  Array indexOf is looking for the
 index of a single element that contains a specific value.  You might want
 to implement a logically similar subsequence search for Array's but if you
 do, you can't call it indexOf because that name was already used for
 something with different semantics.  We should try to do better as people
 for our example.

 Allen



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-03 Thread Mark S. Miller
On Fri, Nov 2, 2012 at 5:26 PM, Allen Wirfs-Brock al...@wirfs-brock.comwrote:


 Also any reason contains should be provided for WeakMap? I not seeing why
 it shouldn't be there too.


Yes!

The set of values actually contained by the WeakMap at any moment is
non-deterministic, depending on the scheduling of gc. But this
non-determinism is non-observable. WeakMap.contains would make it
observable.


-- 
Cheers,
--MarkM
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-03 Thread Allen Wirfs-Brock

On Nov 3, 2012, at 4:53 PM, Mark S. Miller wrote:

 On Fri, Nov 2, 2012 at 5:26 PM, Allen Wirfs-Brock al...@wirfs-brock.com 
 wrote:
 
 Also any reason contains should be provided for WeakMap? I not seeing why it 
 shouldn't be there too.
 
 Yes!
 
 The set of values actually contained by the WeakMap at any moment is 
 non-deterministic, depending on the scheduling of gc. But this 
 non-determinism is non-observable. WeakMap.contains would make it observable.


yup



  
 
 -- 
 Cheers,
 --MarkM

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-03 Thread Brendan Eich
Is this true? I can see how enumeration and size would leak the GC 
schedule, but to test has or contains, you need a strong ref, which 
means the key or value cannot yet be garbage. If you have the 
capability, there's no non-determinism. What am I missing?


/be

Allen Wirfs-Brock wrote:


On Nov 3, 2012, at 4:53 PM, Mark S. Miller wrote:

On Fri, Nov 2, 2012 at 5:26 PM, Allen Wirfs-Brock 
al...@wirfs-brock.com mailto:al...@wirfs-brock.com wrote:



Also any reason contains should be provided for WeakMap? I not
seeing why it shouldn't be there too.


Yes!

The set of values actually contained by the WeakMap at any moment is 
non-deterministic, depending on the scheduling of gc. But this 
non-determinism is non-observable. WeakMap.contains would make it 
observable.



yup





--
Cheers,
--MarkM


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-03 Thread Mark S. Miller
WeakMap.has is fine (and already speced) because the presence of the
association depends on the key. However, if the key is garbage, a strong
ref to the value does not preserve the association in the map.


On Sat, Nov 3, 2012 at 6:05 PM, Brendan Eich bren...@mozilla.org wrote:

 Is this true? I can see how enumeration and size would leak the GC
 schedule, but to test has or contains, you need a strong ref, which means
 the key or value cannot yet be garbage. If you have the capability, there's
 no non-determinism. What am I missing?

 /be

 Allen Wirfs-Brock wrote:


 On Nov 3, 2012, at 4:53 PM, Mark S. Miller wrote:

  On Fri, Nov 2, 2012 at 5:26 PM, Allen Wirfs-Brock 
 al...@wirfs-brock.commailto:
 al...@wirfs-brock.com** wrote:


 Also any reason contains should be provided for WeakMap? I not
 seeing why it shouldn't be there too.


 Yes!

 The set of values actually contained by the WeakMap at any moment is
 non-deterministic, depending on the scheduling of gc. But this
 non-determinism is non-observable. WeakMap.contains would make it
 observable.



 yup




 --
 Cheers,
 --MarkM


 __**_
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/**listinfo/es-discusshttps://mail.mozilla.org/listinfo/es-discuss




-- 
Cheers,
--MarkM
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-03 Thread Brendan Eich

Mark S. Miller wrote:
WeakMap.has is fine (and already speced) because the presence of the 
association depends on the key. However, if the key is garbage, a 
strong ref to the value does not preserve the association in the map.


Right! Thanks.

/be



On Sat, Nov 3, 2012 at 6:05 PM, Brendan Eich bren...@mozilla.org 
mailto:bren...@mozilla.org wrote:


Is this true? I can see how enumeration and size would leak the GC
schedule, but to test has or contains, you need a strong ref,
which means the key or value cannot yet be garbage. If you have
the capability, there's no non-determinism. What am I missing?

/be

Allen Wirfs-Brock wrote:


On Nov 3, 2012, at 4:53 PM, Mark S. Miller wrote:

On Fri, Nov 2, 2012 at 5:26 PM, Allen Wirfs-Brock
al...@wirfs-brock.com mailto:al...@wirfs-brock.com
mailto:al...@wirfs-brock.com
mailto:al...@wirfs-brock.com wrote:


Also any reason contains should be provided for
WeakMap? I not
seeing why it shouldn't be there too.


Yes!

The set of values actually contained by the WeakMap at any
moment is non-deterministic, depending on the scheduling
of gc. But this non-determinism is non-observable.
WeakMap.contains would make it observable.



yup




-- 
Cheers,

--MarkM


___
es-discuss mailing list
es-discuss@mozilla.org mailto:es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss




--
Cheers,
--MarkM
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-03 Thread Axel Rauschmayer
 (I am still sad we did not fix indexOf, lastIndexOf, and switch when we 
 arguably had the chance.)

Can you elaborate? We don’t have the chance, any more? Would anything break (or 
did, in tests)? How about only letting those methods find NaN, while letting 
them consider +0 and -0 equal?

Axel

-- 
Dr. Axel Rauschmayer
a...@rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Allen Wirfs-Brock

On Nov 1, 2012, at 11:04 AM, Joshua Bell wrote:

 Bump.
 
 I don't think Array.prototype.contains ever materialized on the proposals 
 page, and hasn't shown up in an ES6 draft.
 
 Officially out for ES6, stuck in the queue, or dropped on the floor?

Probably dropped on the floor, unless somebody can find something about it in 
meeting notes.

It looks to me from scanning just this thread that it was an idea that was 
floated here with generally positive responses, but had some unresolved issues, 
and nobody ever signed on as champion to write an actual proposal.  

Allen







 
 On Fri, Feb 24, 2012 at 4:40 PM, Rick Waldron waldron.r...@gmail.com wrote:
 Allen, thank you for the clarification there
 
 
 Rick
 
 
 On Feb 24, 2012, at 7:19 PM, Allen Wirfs-Brock al...@wirfs-brock.com wrote:
 
 
 On Feb 24, 2012, at 11:09 AM, Rick Waldron wrote:
 
 
 
 On Thu, Feb 23, 2012 at 3:15 PM, Erik Arvidsson erik.arvids...@gmail.com 
 wrote:
 DOM4 added a new interface called DOMStringList for the sole reason
 that Array does not have contains. Before this the return type was an
 Array of Strings so we could use indexOf, map, forEach etc. Now that
 it is using a non Array we lost all of that.
 
 Wouldn't the return type (or [[Class]]) still be restricted from using 
 Array? 
 
 From 8.6.2
 
 The value of the [[Class]] internal property is defined by this 
 specification for every kind of built-in object. The value of the [[Class]] 
 internal property of a host object may be any String value except one of 
 Arguments, Array, Boolean, Date, Error, Function, JSON, 
 Math, Number, Object, RegExp, and String. 
 
 
 So it can't be an Array by name, right?
 
 
 It can be, as long as it really is a ES array.  host object doesn't mean 
 any object created by the host.  It means new kinds of objects created by 
 the host that implement primitive behaviors (generally internal methods) 
 differently from what is specified by the ES spec.  
 
 So, from the ES perspective, no problem.  When I originally asked the 
 question I was thinking more about from the Web IDL perspective.  Does Web 
 IDL require things (for example throwing if extra arguments are passed) that 
 ES Arrays do not do.
 
 
 Allen
 
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss
 
 
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Erik Arvidsson
I'll put up a proposal once electricity is back. I'll use the same
comparison as done in maps.
On Nov 2, 2012 2:03 AM, Allen Wirfs-Brock al...@wirfs-brock.com wrote:


 On Nov 1, 2012, at 11:04 AM, Joshua Bell wrote:

 Bump.

 I don't think Array.prototype.contains ever materialized on the
 proposals page, and hasn't shown up in an ES6 draft.

 Officially out for ES6, stuck in the queue, or dropped on the floor?


 Probably dropped on the floor, unless somebody can find something about it
 in meeting notes.

 It looks to me from scanning just this thread that it was an idea that was
 floated here with generally positive responses, but had some unresolved
 issues, and nobody ever signed on as champion to write an actual proposal.

 Allen








 On Fri, Feb 24, 2012 at 4:40 PM, Rick Waldron waldron.r...@gmail.comwrote:

 Allen, thank you for the clarification there


 Rick


 On Feb 24, 2012, at 7:19 PM, Allen Wirfs-Brock al...@wirfs-brock.com
 wrote:


 On Feb 24, 2012, at 11:09 AM, Rick Waldron wrote:



 On Thu, Feb 23, 2012 at 3:15 PM, Erik Arvidsson erik.arvids...@gmail.com
  wrote:

 DOM4 added a new interface called DOMStringList for the sole reason
 that Array does not have contains. Before this the return type was an
 Array of Strings so we could use indexOf, map, forEach etc. Now that
 it is using a non Array we lost all of that.


 Wouldn't the return type (or [[Class]]) still be restricted from using
 Array?

 From 8.6.2

 The value of the [[Class]] internal property is defined by this
 specification for every kind of built-in object. The value of the [[Class]]
 internal property of a host object may be any String value except one of
 Arguments, Array, Boolean, Date, Error, Function, JSON,
 Math, Number, Object, RegExp, and String.


 So it can't be an Array by name, right?


 It can be, as long as it really is a ES array.  host object doesn't
 mean any object created by the host.  It means new kinds of objects created
 by the host that implement primitive behaviors (generally internal methods)
 differently from what is specified by the ES spec.

 So, from the ES perspective, no problem.  When I originally asked the
 question I was thinking more about from the Web IDL perspective.  Does Web
 IDL require things (for example throwing if extra arguments are passed)
 that ES Arrays do not do.


 Allen


 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Allen Wirfs-Brock
There is also the compat issue with Mootools  with String contains...

If we decided we needed to rename String contains then it might also impact 
what we call a similar Array method

Allen


On Nov 2, 2012, at 8:19 AM, Erik Arvidsson wrote:

 I'll put up a proposal once electricity is back. I'll use the same comparison 
 as done in maps.
 
 On Nov 2, 2012 2:03 AM, Allen Wirfs-Brock al...@wirfs-brock.com wrote:
 
 On Nov 1, 2012, at 11:04 AM, Joshua Bell wrote:
 
 Bump.
 
 I don't think Array.prototype.contains ever materialized on the proposals 
 page, and hasn't shown up in an ES6 draft.
 
 Officially out for ES6, stuck in the queue, or dropped on the floor?
 
 Probably dropped on the floor, unless somebody can find something about it in 
 meeting notes.
 
 It looks to me from scanning just this thread that it was an idea that was 
 floated here with generally positive responses, but had some unresolved 
 issues, and nobody ever signed on as champion to write an actual proposal.  
 
 Allen
 
 
 
 
 
 
 
 
 On Fri, Feb 24, 2012 at 4:40 PM, Rick Waldron waldron.r...@gmail.com wrote:
 Allen, thank you for the clarification there
 
 
 Rick
 
 
 On Feb 24, 2012, at 7:19 PM, Allen Wirfs-Brock al...@wirfs-brock.com wrote:
 
 
 On Feb 24, 2012, at 11:09 AM, Rick Waldron wrote:
 
 
 
 On Thu, Feb 23, 2012 at 3:15 PM, Erik Arvidsson erik.arvids...@gmail.com 
 wrote:
 DOM4 added a new interface called DOMStringList for the sole reason
 that Array does not have contains. Before this the return type was an
 Array of Strings so we could use indexOf, map, forEach etc. Now that
 it is using a non Array we lost all of that.
 
 Wouldn't the return type (or [[Class]]) still be restricted from using 
 Array? 
 
 From 8.6.2
 
 The value of the [[Class]] internal property is defined by this 
 specification for every kind of built-in object. The value of the 
 [[Class]] internal property of a host object may be any String value 
 except one of Arguments, Array, Boolean, Date, Error, 
 Function, JSON, Math, Number, Object, RegExp, and String. 
 
 
 So it can't be an Array by name, right?
 
 
 It can be, as long as it really is a ES array.  host object doesn't mean 
 any object created by the host.  It means new kinds of objects created by 
 the host that implement primitive behaviors (generally internal methods) 
 differently from what is specified by the ES spec.  
 
 So, from the ES perspective, no problem.  When I originally asked the 
 question I was thinking more about from the Web IDL perspective.  Does Web 
 IDL require things (for example throwing if extra arguments are passed) 
 that ES Arrays do not do.
 
 
 Allen
 
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss
 
 
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss
 
 
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss
 

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Rick Waldron
On Fri, Nov 2, 2012 at 11:25 AM, Allen Wirfs-Brock al...@wirfs-brock.comwrote:

 There is also the compat issue with Mootools  with String contains...

 If we decided we needed to rename String contains then it might also
 impact what we call a similar Array method



Perhaps it should be has instead of contains? Consistent with the other
collections.

Rick



 Allen



 On Nov 2, 2012, at 8:19 AM, Erik Arvidsson wrote:

 I'll put up a proposal once electricity is back. I'll use the same
 comparison as done in maps.
 On Nov 2, 2012 2:03 AM, Allen Wirfs-Brock al...@wirfs-brock.com wrote:


 On Nov 1, 2012, at 11:04 AM, Joshua Bell wrote:

 Bump.

 I don't think Array.prototype.contains ever materialized on the
 proposals page, and hasn't shown up in an ES6 draft.

 Officially out for ES6, stuck in the queue, or dropped on the floor?


 Probably dropped on the floor, unless somebody can find something about
 it in meeting notes.

 It looks to me from scanning just this thread that it was an idea that
 was floated here with generally positive responses, but had some unresolved
 issues, and nobody ever signed on as champion to write an actual proposal.

 Allen








 On Fri, Feb 24, 2012 at 4:40 PM, Rick Waldron waldron.r...@gmail.comwrote:

 Allen, thank you for the clarification there


 Rick


 On Feb 24, 2012, at 7:19 PM, Allen Wirfs-Brock al...@wirfs-brock.com
 wrote:


 On Feb 24, 2012, at 11:09 AM, Rick Waldron wrote:



 On Thu, Feb 23, 2012 at 3:15 PM, Erik Arvidsson 
 erik.arvids...@gmail.com wrote:

 DOM4 added a new interface called DOMStringList for the sole reason
 that Array does not have contains. Before this the return type was an
 Array of Strings so we could use indexOf, map, forEach etc. Now that
 it is using a non Array we lost all of that.


 Wouldn't the return type (or [[Class]]) still be restricted from using
 Array?

 From 8.6.2

 The value of the [[Class]] internal property is defined by this
 specification for every kind of built-in object. The value of the [[Class]]
 internal property of a host object may be any String value except one of
 Arguments, Array, Boolean, Date, Error, Function, JSON,
 Math, Number, Object, RegExp, and String.


 So it can't be an Array by name, right?


 It can be, as long as it really is a ES array.  host object doesn't
 mean any object created by the host.  It means new kinds of objects created
 by the host that implement primitive behaviors (generally internal methods)
 differently from what is specified by the ES spec.

 So, from the ES perspective, no problem.  When I originally asked the
 question I was thinking more about from the Web IDL perspective.  Does Web
 IDL require things (for example throwing if extra arguments are passed)
 that ES Arrays do not do.


 Allen


 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Mark S. Miller
On Fri, Nov 2, 2012 at 8:19 AM, Erik Arvidsson erik.arvids...@gmail.comwrote:

 I'll put up a proposal once electricity is back. I'll use the same
 comparison as done in maps.


With it being the same comparison as maps (which use SameValue), +1. Note
that this makes contains/has inconsistent with indexOf (which uses ===).

I also support calling it has as Rick suggests. Perhaps this also helps
suggest that it is like the other hass, which use SameValue, and not like
indexOf.

(I am still sad we did not fix indexOf, lastIndexOf, and switch when we
arguably had the chance.)


  On Nov 2, 2012 2:03 AM, Allen Wirfs-Brock al...@wirfs-brock.com
 wrote:


 On Nov 1, 2012, at 11:04 AM, Joshua Bell wrote:

 Bump.

 I don't think Array.prototype.contains ever materialized on the
 proposals page, and hasn't shown up in an ES6 draft.

 Officially out for ES6, stuck in the queue, or dropped on the floor?


 Probably dropped on the floor, unless somebody can find something about
 it in meeting notes.

 It looks to me from scanning just this thread that it was an idea that
 was floated here with generally positive responses, but had some unresolved
 issues, and nobody ever signed on as champion to write an actual proposal.

 Allen








 On Fri, Feb 24, 2012 at 4:40 PM, Rick Waldron waldron.r...@gmail.comwrote:

 Allen, thank you for the clarification there


 Rick


 On Feb 24, 2012, at 7:19 PM, Allen Wirfs-Brock al...@wirfs-brock.com
 wrote:


 On Feb 24, 2012, at 11:09 AM, Rick Waldron wrote:



 On Thu, Feb 23, 2012 at 3:15 PM, Erik Arvidsson 
 erik.arvids...@gmail.com wrote:

 DOM4 added a new interface called DOMStringList for the sole reason
 that Array does not have contains. Before this the return type was an
 Array of Strings so we could use indexOf, map, forEach etc. Now that
 it is using a non Array we lost all of that.


 Wouldn't the return type (or [[Class]]) still be restricted from using
 Array?

 From 8.6.2

 The value of the [[Class]] internal property is defined by this
 specification for every kind of built-in object. The value of the [[Class]]
 internal property of a host object may be any String value except one of
 Arguments, Array, Boolean, Date, Error, Function, JSON,
 Math, Number, Object, RegExp, and String.


 So it can't be an Array by name, right?


 It can be, as long as it really is a ES array.  host object doesn't
 mean any object created by the host.  It means new kinds of objects created
 by the host that implement primitive behaviors (generally internal methods)
 differently from what is specified by the ES spec.

 So, from the ES perspective, no problem.  When I originally asked the
 question I was thinking more about from the Web IDL perspective.  Does Web
 IDL require things (for example throwing if extra arguments are passed)
 that ES Arrays do not do.


 Allen


 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss




-- 
Cheers,
--MarkM
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Andrea Giammarchi
I was wondering the same ... if `contains()` is the new indexOf then why
other collections are using `has()` ... I like has() more but it might be
me lazy typer ... still it should be consistent.


On Fri, Nov 2, 2012 at 9:14 AM, Rick Waldron waldron.r...@gmail.com wrote:



 On Fri, Nov 2, 2012 at 11:25 AM, Allen Wirfs-Brock 
 al...@wirfs-brock.comwrote:

 There is also the compat issue with Mootools  with String contains...

 If we decided we needed to rename String contains then it might also
 impact what we call a similar Array method



 Perhaps it should be has instead of contains? Consistent with the
 other collections.

 Rick



 Allen



 On Nov 2, 2012, at 8:19 AM, Erik Arvidsson wrote:

 I'll put up a proposal once electricity is back. I'll use the same
 comparison as done in maps.
 On Nov 2, 2012 2:03 AM, Allen Wirfs-Brock al...@wirfs-brock.com
 wrote:


 On Nov 1, 2012, at 11:04 AM, Joshua Bell wrote:

 Bump.

 I don't think Array.prototype.contains ever materialized on the
 proposals page, and hasn't shown up in an ES6 draft.

 Officially out for ES6, stuck in the queue, or dropped on the floor?


 Probably dropped on the floor, unless somebody can find something about
 it in meeting notes.

 It looks to me from scanning just this thread that it was an idea that
 was floated here with generally positive responses, but had some unresolved
 issues, and nobody ever signed on as champion to write an actual proposal.

 Allen








 On Fri, Feb 24, 2012 at 4:40 PM, Rick Waldron waldron.r...@gmail.comwrote:

 Allen, thank you for the clarification there


 Rick


 On Feb 24, 2012, at 7:19 PM, Allen Wirfs-Brock al...@wirfs-brock.com
 wrote:


 On Feb 24, 2012, at 11:09 AM, Rick Waldron wrote:



 On Thu, Feb 23, 2012 at 3:15 PM, Erik Arvidsson 
 erik.arvids...@gmail.com wrote:

 DOM4 added a new interface called DOMStringList for the sole reason
 that Array does not have contains. Before this the return type was an
 Array of Strings so we could use indexOf, map, forEach etc. Now that
 it is using a non Array we lost all of that.


 Wouldn't the return type (or [[Class]]) still be restricted from using
 Array?

 From 8.6.2

 The value of the [[Class]] internal property is defined by this
 specification for every kind of built-in object. The value of the [[Class]]
 internal property of a host object may be any String value except one of
 Arguments, Array, Boolean, Date, Error, Function, JSON,
 Math, Number, Object, RegExp, and String.


 So it can't be an Array by name, right?


 It can be, as long as it really is a ES array.  host object doesn't
 mean any object created by the host.  It means new kinds of objects created
 by the host that implement primitive behaviors (generally internal methods)
 differently from what is specified by the ES spec.

 So, from the ES perspective, no problem.  When I originally asked the
 question I was thinking more about from the Web IDL perspective.  Does Web
 IDL require things (for example throwing if extra arguments are passed)
 that ES Arrays do not do.


 Allen


 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Erik Arvidsson
On Fri, Nov 2, 2012 at 12:30 PM, Mark S. Miller erig...@google.com wrote:
 I also support calling it has as Rick suggests. Perhaps this also helps
 suggest that it is like the other hass, which use SameValue, and not like
 indexOf.

 (I am still sad we did not fix indexOf, lastIndexOf, and switch when we
 arguably had the chance.)

If we call it has, should we also rename String.prototype.contains?

-- 
erik
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Rick Waldron
On Fri, Nov 2, 2012 at 1:20 PM, Erik Arvidsson erik.arvids...@gmail.comwrote:

 On Fri, Nov 2, 2012 at 12:30 PM, Mark S. Miller erig...@google.com
 wrote:
  I also support calling it has as Rick suggests. Perhaps this also helps
  suggest that it is like the other hass, which use SameValue, and not
 like
  indexOf.
 
  (I am still sad we did not fix indexOf, lastIndexOf, and switch when we
  arguably had the chance.)

 If we call it has, should we also rename String.prototype.contains?


Blitzed! I was just drafting a reply asking the same thing.

I think for consistency, yes... Although I'm not sure about using SameValue


Rick




 --
 erik
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Andrea Giammarchi
+1 ... but funny that for Strings I would naturally use mychunk in
mystring rather than mystring.has(mychunk)  I believe contains comes
from XSL, isn't it? Was it W3C suggestion or what?


On Fri, Nov 2, 2012 at 10:20 AM, Erik Arvidsson erik.arvids...@gmail.comwrote:

 On Fri, Nov 2, 2012 at 12:30 PM, Mark S. Miller erig...@google.com
 wrote:
  I also support calling it has as Rick suggests. Perhaps this also helps
  suggest that it is like the other hass, which use SameValue, and not
 like
  indexOf.
 
  (I am still sad we did not fix indexOf, lastIndexOf, and switch when we
  arguably had the chance.)

 If we call it has, should we also rename String.prototype.contains?

 --
 erik
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


RE: Array.prototype.contains

2012-11-02 Thread Domenic Denicola
-Original Message-
From: es-discuss-boun...@mozilla.org [mailto:es-discuss-boun...@mozilla.org] On 
Behalf Of Erik Arvidsson
Sent: Friday, November 2, 2012 13:21

 If we call it has, should we also rename String.prototype.contains?

I'd say no; the distinction between collections having an element and strings 
containing a substring seems very sensible. It's a bit more awkward to say a 
string has a substring, and a string is definitely not a collection of 
substrings in any reasonable sense.

If anyone had proposed String.prototype.has(singleCharOrMaybeCodePoint), then 
perhaps that name would make sense.

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Joshua Bell
On Fri, Nov 2, 2012 at 9:14 AM, Rick Waldron waldron.r...@gmail.com wrote:


 On Fri, Nov 2, 2012 at 11:25 AM, Allen Wirfs-Brock 
 al...@wirfs-brock.comwrote:

 There is also the compat issue with Mootools  with String contains...

 If we decided we needed to rename String contains then it might also
 impact what we call a similar Array method


 Perhaps it should be has instead of contains? Consistent with the
 other collections.


If you dig back far enough in this thread [1], you'll see that one of the
motivations for suggesting this was to be able to obsolete DOMStringList
[2] and quietly switch existing methods to returning plain old Arrays. That
would argue for keeping the name as contains.

But given that DOMStringList also has an explicit items method, and the
implications of the restriction to strings - e.g. calling d.contains(1) or
d.contains(undefined) follow WebIDL rules for stringifying the argument -
it is probably too late to actually remove DOMStringList from the platform.

[1] https://mail.mozilla.org/pipermail/es-discuss/2012-February/020726.html
[2] http://www.w3.org/TR/DOM-Level-3-Core/core.html#DOMStringList
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Jason Orendorff
On Fri, Nov 2, 2012 at 12:29 PM, Domenic Denicola 
dome...@domenicdenicola.com wrote:

  If we call it has, should we also rename String.prototype.contains?

 I'd say no; the distinction between collections having an element and
 strings containing a substring seems very sensible. It's a bit more
 awkward to say a string has a substring, and a string is definitely not a
 collection of substrings in any reasonable sense.


Well, you could also note that array.has(x) looks for a particular value,
while map.has(x) looks for a particular key.

But that's not the point. There's no common formal contract implemented by
all these methods; what they share is an informal hey, look in this thing,
and tell me if you see that thing vibe.

I like the idea of being able to say str.has(,) or str.has(=) or
str.has(@jorendorff) and have them all just work.

-j
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Rick Waldron


On Friday, November 2, 2012 at 1:56 PM, Jason Orendorff wrote:

 On Fri, Nov 2, 2012 at 12:29 PM, Domenic Denicola 
 dome...@domenicdenicola.com (mailto:dome...@domenicdenicola.com) wrote:
   If we call it has, should we also rename String.prototype.contains?
  
  I'd say no; the distinction between collections having an element and 
  strings containing a substring seems very sensible. It's a bit more 
  awkward to say a string has a substring, and a string is definitely not a 
  collection of substrings in any reasonable sense.
 
 Well, you could also note that array.has(x) looks for a particular value, 
 while map.has(x) looks for a particular key.
 
 But that's not the point. There's no common formal contract implemented by 
 all these methods; what they share is an informal hey, look in this thing, 
 and tell me if you see that thing vibe.
 
 I like the idea of being able to say str.has(,) or str.has(=) or 
 str.has(@jorendorff) and have them all just work.
This is definitely nice :)

Jason, Erik, Mark,

Any specific thoughts about the SameValue case as it likely doesn't apply to a 
hypothetical String.prototype.has impl.? I suspect that a string had would 
still use indexOf which would introduce an internal inconsistency for the sake 
of API consistency (which I'm all for). Unless I'm overlooking?

Rick 
 
 
 -j
 
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss
 
 


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Erik Arvidsson
http://wiki.ecmascript.org/doku.php?id=strawman:array.prototype.has

On Fri, Nov 2, 2012 at 2:04 PM, Rick Waldron waldron.r...@gmail.com wrote:

 On Friday, November 2, 2012 at 1:56 PM, Jason Orendorff wrote:

 On Fri, Nov 2, 2012 at 12:29 PM, Domenic Denicola
 dome...@domenicdenicola.com wrote:

 If we call it has, should we also rename String.prototype.contains?

 I'd say no; the distinction between collections having an element and
 strings containing a substring seems very sensible. It's a bit more
 awkward to say a string has a substring, and a string is definitely not a
 collection of substrings in any reasonable sense.


 Well, you could also note that array.has(x) looks for a particular value,
 while map.has(x) looks for a particular key.

 But that's not the point. There's no common formal contract implemented by
 all these methods; what they share is an informal hey, look in this thing,
 and tell me if you see that thing vibe.

 I like the idea of being able to say str.has(,) or str.has(=) or
 str.has(@jorendorff) and have them all just work.

 This is definitely nice :)

 Jason, Erik, Mark,

 Any specific thoughts about the SameValue case as it likely doesn't apply to
 a hypothetical String.prototype.has impl.? I suspect that a string had would
 still use indexOf which would introduce an internal inconsistency for the
 sake of API consistency (which I'm all for). Unless I'm overlooking?

 Rick



 -j

 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss




-- 
erik
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Mark S. Miller
Fortunately, strings cannot contain -0.0 or NaN, so neither string.contains
nor string.has sets any relevant precedent. FWIW, neither does
string.indexOf nor string.lastIndexOf.

The only consistency issue is: should array.has agree with sense and all
other collections, or should it agree with array.indexOf / lastIndexOf.
FWIW, I would prefer not to add any more conveniences that further entrench
unexpected === checks.


[NaN].has(NaN) // false

makes little sense.

[0.0].has(-0.0) // true

makes somewhat more sense, but not enough. Please let's either use add
has using SameValue or not add anything at all.



On Fri, Nov 2, 2012 at 11:04 AM, Rick Waldron waldron.r...@gmail.comwrote:


 On Friday, November 2, 2012 at 1:56 PM, Jason Orendorff wrote:

 On Fri, Nov 2, 2012 at 12:29 PM, Domenic Denicola 
 dome...@domenicdenicola.com wrote:

  If we call it has, should we also rename String.prototype.contains?

 I'd say no; the distinction between collections having an element and
 strings containing a substring seems very sensible. It's a bit more
 awkward to say a string has a substring, and a string is definitely not a
 collection of substrings in any reasonable sense.


 Well, you could also note that array.has(x) looks for a particular value,
 while map.has(x) looks for a particular key.

 But that's not the point. There's no common formal contract implemented by
 all these methods; what they share is an informal hey, look in this thing,
 and tell me if you see that thing vibe.

 I like the idea of being able to say str.has(,) or str.has(=) or
 str.has(@jorendorff) and have them all just work.

 This is definitely nice :)

 Jason, Erik, Mark,

 Any specific thoughts about the SameValue case as it likely doesn't apply
 to a hypothetical String.prototype.has impl.? I suspect that a string had
 would still use indexOf which would introduce an internal inconsistency for
 the sake of API consistency (which I'm all for). Unless I'm overlooking?

 Rick



 -j

 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss




-- 
Cheers,
--MarkM
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread David Herman
On Nov 2, 2012, at 11:55 AM, Mark S. Miller erig...@google.com wrote:

 The only consistency issue is: should array.has agree with sense and all 
 other collections, or should it agree with array.indexOf / lastIndexOf. FWIW, 
 I would prefer not to add any more conveniences that further entrench 
 unexpected === checks.
 
 
 [NaN].has(NaN) // false
 
 makes little sense.
 
 [0.0].has(-0.0) // true
 
 makes somewhat more sense, but not enough. Please let's either use add has 
 using SameValue or not add anything at all.

Sorry to complicate the opinion landscape further, but I'm not convinced that 
any collections should be using SameValue. Looking over my personal notes from 
an earlier conversation Mark and I had about maps and sets, I think we came to 
something where the default equivalence should be the tightest possible one 
(SameValue), but it should be possible to provide your own equality predicate 
as an optional constructor argument. We don't have that option for arrays.

There are plenty of operations that can result in a -0 without the programmer 
being aware, such as Math functions. I shudder to imagine debugging a program 
like this:

[Math.round(-0.1)].has(0) // false!

I agree that NaN should be equated, but I'm pretty nervous about the idea of 
distinguishing 0 and -0, especially when there's no way to override that 
behavior.

Dave

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Asen Bozhilov
Erik Arvidsson



 If we call it has, should we also rename String.prototype.contains?



Most of the JS libraries use `has` method for checking property and key
existence. I am wondering if there is Array.prototype.has how they would
overload their `has` methods to work as expected with arrays, array-like
and regular native objects.  Also their is and
Object.prototype.hasOwnProperty. For example this code is a little bit
confusing for me:

var arr = [1, 2, 3];
arr.hasOwnProperty(0); //true
arr.has(0); //false
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Brendan Eich

David Herman wrote:

 [Math.round(-0.1)].has(0) // false!


Could be a problem, but my position is that anyone using Math.round has 
to deal with -0. It is observably different from 0 via other Math 
functions, even if ===.


/be
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Allen Wirfs-Brock

On Nov 2, 2012, at 10:56 AM, Jason Orendorff wrote:

 On Fri, Nov 2, 2012 at 12:29 PM, Domenic Denicola 
 dome...@domenicdenicola.com wrote:
  If we call it has, should we also rename String.prototype.contains?
 
 I'd say no; the distinction between collections having an element and 
 strings containing a substring seems very sensible. It's a bit more awkward 
 to say a string has a substring, and a string is definitely not a 
 collection of substrings in any reasonable sense.
 
 Well, you could also note that array.has(x) looks for a particular value, 
 while map.has(x) looks for a particular key.
 
 But that's not the point. There's no common formal contract implemented by 
 all these methods; what they share is an informal hey, look in this thing, 
 and tell me if you see that thing vibe.

There is no verifiable formal contract.  But there can be an informal contract. 
 In my experience, it is very important when using a dynamic language to 
recognize and try to support such informal contracts. 

All the uses of has we have defined so far are about the keys.  Having one 
place that is about the values to create unnecessary confusion

Note that we (the JS/ES designers) already have a history of being being 
inconsistent in our use of names.  Consider String indexOf and Array indexOf 
they are named the same and appear to have signatures.  But they logically are 
doing quite different things.  String indexOf is looking for the index of the 
first element of a subsequence of character elements that matches a specific 
character sequence.  Array indexOf is looking for the index of a single element 
that contains a specific value.  You might want to implement a logically 
similar subsequence search for Array's but if you do, you can't call it indexOf 
because that name was already used for something with different semantics.  We 
should try to do better as people for our example.

Allen



___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Andrea Giammarchi
I actually agree on this, but Set.has() is misleading then, imho. Shouldn't
be specified that `has()` is key related and `contains()` is value related?
Also a magic Object.has(obj, key) with smart obj recognition and
Object.contains(obj, value) would be probably cool


On Fri, Nov 2, 2012 at 2:30 PM, Allen Wirfs-Brock al...@wirfs-brock.comwrote:


 On Nov 2, 2012, at 10:56 AM, Jason Orendorff wrote:

 On Fri, Nov 2, 2012 at 12:29 PM, Domenic Denicola 
 dome...@domenicdenicola.com wrote:

  If we call it has, should we also rename String.prototype.contains?

 I'd say no; the distinction between collections having an element and
 strings containing a substring seems very sensible. It's a bit more
 awkward to say a string has a substring, and a string is definitely not a
 collection of substrings in any reasonable sense.


 Well, you could also note that array.has(x) looks for a particular value,
 while map.has(x) looks for a particular key.

 But that's not the point. There's no common formal contract implemented by
 all these methods; what they share is an informal hey, look in this thing,
 and tell me if you see that thing vibe.


 There is no verifiable formal contract.  But there can be an informal
 contract.  In my experience, it is very important when using a dynamic
 language to recognize and try to support such informal contracts.

 All the uses of has we have defined so far are about the keys.  Having
 one place that is about the values to create unnecessary confusion

 Note that we (the JS/ES designers) already have a history of being being
 inconsistent in our use of names.  Consider String indexOf and Array
 indexOf they are named the same and appear to have signatures.  But they
 logically are doing quite different things.  String indexOf is looking for
 the index of the first element of a subsequence of character elements that
 matches a specific character sequence.  Array indexOf is looking for the
 index of a single element that contains a specific value.  You might want
 to implement a logically similar subsequence search for Array's but if you
 do, you can't call it indexOf because that name was already used for
 something with different semantics.  We should try to do better as people
 for our example.

 Allen




 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Brendan Eich

Allen Wirfs-Brock wrote:

On Nov 2, 2012, at 10:56 AM, Jason Orendorff wrote:
On Fri, Nov 2, 2012 at 12:29 PM, Domenic Denicola 
dome...@domenicdenicola.com mailto:dome...@domenicdenicola.com wrote:


 If we call it has, should we also rename
String.prototype.contains?

I'd say no; the distinction between collections having an
element and strings containing a substring seems very sensible.
It's a bit more awkward to say a string has a substring, and a
string is definitely not a collection of substrings in any
reasonable sense.


Well, you could also note that array.has(x) looks for a particular 
value, while map.has(x) looks for a particular key.


But that's not the point. There's no common formal contract 
implemented by all these methods; what they share is an informal 
hey, look in this thing, and tell me if you see that thing vibe.


There is no verifiable formal contract.  But there can be an informal 
contract.  In my experience, it is very important when using a dynamic 
language to recognize and try to support such informal contracts.


All the uses of has we have defined so far are about the keys. 
 Having one place that is about the values to create unnecessary 
confusion


Note that we (the JS/ES designers) already have a history of being 
being inconsistent in our use of names.  Consider String indexOf and 
Array indexOf


http://stackoverflow.com/questions/4962361/where-is-javas-array-indexof

they are named the same and appear to have signatures.  But they 
logically are doing quite different things.  String indexOf is looking 
for the index of the first element of a subsequence of character 
elements that matches a specific character sequence.  Array indexOf is 
looking for the index of a single element that contains a specific 
value.  You might want to implement a logically similar subsequence 
search for Array's but if you do, you can't call it indexOf because 
that name was already used for something with different semantics.  We 
should try to do better as people for our example.


That one never bugged me, and I suppose one could fix it by allowing 
by-value search for a sub-array from Array.prototype.indexOf. I've never 
seen anyone do that.


has for keys (and possibly values of a Set, to preserve the value 
mapped to boolean future option that forEach also supports), contains 
for values in arrays?


/be

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Brendan Eich

Andrea Giammarchi wrote:
I actually agree on this, but Set.has() is misleading then, imho. 
Shouldn't be specified that `has()` is key related and `contains()` is 
value related?


The forEach signature has (value, key, collection), and for a Set is 
called with (value, value, theSet). We discussed this at the Boston f2f 
and recently on list. It allows us to extend Sets in the future (under 
object model reformation, e.g.) to map value to boolean has-result.


Apart from the Set special case, using contains for values and has for 
keys seems better and better to me. But that means 
String.prototype.contains, not has. The test is for values, not keys, in 
that case. Same thing with Array.prototype.contains (and MooTools must 
adapt).


/be

Also a magic Object.has(obj, key) with smart obj recognition and 
Object.contains(obj, value) would be probably cool



On Fri, Nov 2, 2012 at 2:30 PM, Allen Wirfs-Brock 
al...@wirfs-brock.com mailto:al...@wirfs-brock.com wrote:



On Nov 2, 2012, at 10:56 AM, Jason Orendorff wrote:


On Fri, Nov 2, 2012 at 12:29 PM, Domenic Denicola
dome...@domenicdenicola.com
mailto:dome...@domenicdenicola.com wrote:

 If we call it has, should we also rename
String.prototype.contains?

I'd say no; the distinction between collections having an
element and strings containing a substring seems very
sensible. It's a bit more awkward to say a string has a
substring, and a string is definitely not a collection of
substrings in any reasonable sense.


Well, you could also note that array.has(x) looks for a
particular value, while map.has(x) looks for a particular key.

But that's not the point. There's no common formal contract
implemented by all these methods; what they share is an informal
hey, look in this thing, and tell me if you see that thing vibe.


There is no verifiable formal contract.  But there can be an
informal contract.  In my experience, it is very important when
using a dynamic language to recognize and try to support such
informal contracts.

All the uses of has we have defined so far are about the keys.
 Having one place that is about the values to create unnecessary
confusion

Note that we (the JS/ES designers) already have a history of being
being inconsistent in our use of names.  Consider String indexOf
and Array indexOf they are named the same and appear to have
signatures.  But they logically are doing quite different things.
 String indexOf is looking for the index of the first element of a
subsequence of character elements that matches a specific
character sequence.  Array indexOf is looking for the index of a
single element that contains a specific value.  You might want to
implement a logically similar subsequence search for Array's but
if you do, you can't call it indexOf because that name was already
used for something with different semantics.  We should try to do
better as people for our example.

Allen




___
es-discuss mailing list
es-discuss@mozilla.org mailto:es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Allen Wirfs-Brock

On Nov 2, 2012, at 4:54 PM, Brendan Eich wrote:

 Allen Wirfs-Brock wrote:
 ...
 Note that we (the JS/ES designers) already have a history of being being 
 inconsistent in our use of names.  Consider String indexOf and Array indexOf
 
 http://stackoverflow.com/questions/4962361/where-is-javas-array-indexof
 
 they are named the same and appear to have signatures.  But they logically 
 are doing quite different things.  String indexOf is looking for the index 
 of the first element of a subsequence of character elements that matches a 
 specific character sequence.  Array indexOf is looking for the index of a 
 single element that contains a specific value.  You might want to implement 
 a logically similar subsequence search for Array's but if you do, you can't 
 call it indexOf because that name was already used for something with 
 different semantics.  We should try to do better as people for our example.
 
 That one never bugged me, and I suppose one could fix it by allowing 
 by-value search for a sub-array from Array.prototype.indexOf. I've never seen 
 anyone do that.

It never bothered me either up to now. Probably because we usually don't think 
about JS strings as a collections  (immutable array of uint16s) all that 
much.  But if you starting thinking about  strings as a kind of collection and 
look for uniformity in collection interfaces, indexOf stands out as being 
problematic. 


 
 has for keys (and possibly values of a Set, to preserve the value mapped to 
 boolean future option that forEach also supports), contains for values in 
 arrays
 

sounds ok, except we get the same issue for contains that we have for indexOf.  
II guess the big thing with contains is that it can be applied no non-indexed 
collections (maps, sets, etc.). 

Also any reason contains should be provided for WeakMap? I not seeing why it 
shouldn't be there too.

Allen
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Brendan Eich

Allen Wirfs-Brock wrote:

has for keys (and possibly values of a Set, to preserve the value mapped to boolean 
future option that forEach also supports), contains for values in arrays


sounds ok, except we get the same issue for contains that we have for indexOf.  
II guess the big thing with contains is that it can be applied no non-indexed 
collections (maps, sets, etc.).


I'm not sure there's enough of a problem with using contains (or 
indexOf) to justify splitting contains-names, which has its own problems 
(inconsistency with indexOf, also with other languages, _mutatis 
mutandis_, e.g. Java).



Also any reason contains should be provided for WeakMap? I not seeing why it 
shouldn't be there too.


How about Map contains (as well as has)?

How about Set for that matter?

/be
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Allen Wirfs-Brock

On Nov 2, 2012, at 5:45 PM, Brendan Eich wrote:

 Allen Wirfs-Brock wrote:
 has for keys (and possibly values of a Set, to preserve the value mapped 
 to boolean future option that forEach also supports), contains for values 
 in arrays
 
 sounds ok, except we get the same issue for contains that we have for 
 indexOf.  II guess the big thing with contains is that it can be applied no 
 non-indexed collections (maps, sets, etc.).
 
 I'm not sure there's enough of a problem with using contains (or indexOf) to 
 justify splitting contains-names, which has its own problems (inconsistency 
 with indexOf, also with other languages, _mutatis mutandis_, e.g. Java).

me neither...just a wart




 
 Also any reason contains should be provided for WeakMap? I not seeing why it 
 shouldn't be there too.
 
 How about Map contains (as well as has)?
 
 How about Set for that matter?

Because people might actually use Map contains not realizing it isn't a near 
constant time probe like has.  But, that concern is offset by the disability  
of having a consistent set of collection interfaces plus we don't like being a 
nannies.

I'd probably be on board with with having both for Set/Map/WeakMap


Allen 

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-02 Thread Axel Rauschmayer
+1

I have always found Java’s collection API fairly intuitive. It could serve as a 
role model, at least partially.
- Map: containsKey, containsValue
- Set: contains

Note that it has an isEmpty() method. I would also want to have its methods for 
combining collections such as removeAll() and retainAll().

http://docs.oracle.com/javase/6/docs/api/java/util/Map.html
http://docs.oracle.com/javase/6/docs/api/java/util/Set.html


[[[Sent from a mobile device. Please forgive brevity and typos.]]]

Dr. Axel Rauschmayer
a...@rauschma.de
Home: http://rauschma.de
Blog: http://2ality.com

On 02.11.2012, at 22:30, Allen Wirfs-Brock al...@wirfs-brock.com wrote:

 
 On Nov 2, 2012, at 10:56 AM, Jason Orendorff wrote:
 
 On Fri, Nov 2, 2012 at 12:29 PM, Domenic Denicola 
 dome...@domenicdenicola.com wrote:
  If we call it has, should we also rename String.prototype.contains?
 
 I'd say no; the distinction between collections having an element and 
 strings containing a substring seems very sensible. It's a bit more 
 awkward to say a string has a substring, and a string is definitely not a 
 collection of substrings in any reasonable sense.
 
 Well, you could also note that array.has(x) looks for a particular value, 
 while map.has(x) looks for a particular key.
 
 But that's not the point. There's no common formal contract implemented by 
 all these methods; what they share is an informal hey, look in this thing, 
 and tell me if you see that thing vibe.
 
 There is no verifiable formal contract.  But there can be an informal 
 contract.  In my experience, it is very important when using a dynamic 
 language to recognize and try to support such informal contracts. 
 
 All the uses of has we have defined so far are about the keys.  Having 
 one place that is about the values to create unnecessary confusion
 
 Note that we (the JS/ES designers) already have a history of being being 
 inconsistent in our use of names.  Consider String indexOf and Array indexOf 
 they are named the same and appear to have signatures.  But they logically 
 are doing quite different things.  String indexOf is looking for the index of 
 the first element of a subsequence of character elements that matches a 
 specific character sequence.  Array indexOf is looking for the index of a 
 single element that contains a specific value.  You might want to implement a 
 logically similar subsequence search for Array's but if you do, you can't 
 call it indexOf because that name was already used for something with 
 different semantics.  We should try to do better as people for our example.
 
 Allen
 
 
 
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-11-01 Thread Joshua Bell
Bump.

I don't think Array.prototype.contains ever materialized on the proposals
page, and hasn't shown up in an ES6 draft.

Officially out for ES6, stuck in the queue, or dropped on the floor?

On Fri, Feb 24, 2012 at 4:40 PM, Rick Waldron waldron.r...@gmail.comwrote:

 Allen, thank you for the clarification there


 Rick


 On Feb 24, 2012, at 7:19 PM, Allen Wirfs-Brock al...@wirfs-brock.com
 wrote:


 On Feb 24, 2012, at 11:09 AM, Rick Waldron wrote:



 On Thu, Feb 23, 2012 at 3:15 PM, Erik Arvidsson 
 erik.arvids...@gmail.comwrote:

 DOM4 added a new interface called DOMStringList for the sole reason
 that Array does not have contains. Before this the return type was an
 Array of Strings so we could use indexOf, map, forEach etc. Now that
 it is using a non Array we lost all of that.


 Wouldn't the return type (or [[Class]]) still be restricted from using
 Array?

 From 8.6.2

 The value of the [[Class]] internal property is defined by this
 specification for every kind of built-in object. The value of the [[Class]]
 internal property of a host object may be any String value except one of
 Arguments, Array, Boolean, Date, Error, Function, JSON,
 Math, Number, Object, RegExp, and String.


 So it can't be an Array by name, right?


 It can be, as long as it really is a ES array.  host object doesn't mean
 any object created by the host.  It means new kinds of objects created by
 the host that implement primitive behaviors (generally internal methods)
 differently from what is specified by the ES spec.

 So, from the ES perspective, no problem.  When I originally asked the
 question I was thinking more about from the Web IDL perspective.  Does Web
 IDL require things (for example throwing if extra arguments are passed)
 that ES Arrays do not do.


 Allen


 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-02-24 Thread Rick Waldron
On Thu, Feb 23, 2012 at 3:15 PM, Erik Arvidsson erik.arvids...@gmail.comwrote:

 DOM4 added a new interface called DOMStringList for the sole reason
 that Array does not have contains. Before this the return type was an
 Array of Strings so we could use indexOf, map, forEach etc. Now that
 it is using a non Array we lost all of that.


Wouldn't the return type (or [[Class]]) still be restricted from using
Array?

From 8.6.2

The value of the [[Class]] internal property is defined by this
specification for every kind of built-in object. The value of the [[Class]]
internal property of a host object may be any String value except one of
Arguments, Array, Boolean, Date, Error, Function, JSON,
Math, Number, Object, RegExp, and String.


So it can't be an Array by name, right?


(I'm not trying to be contrary, just looking for clarity :D )



 Proposal: Add Array.prototype.contains, implemented as:

 Object.defineProperty(Array.prototype, 'contains', {
  value: function(value) {
return this.indexOf(value) !== -1;
  },
  enumerable: false,
  configurable: true,
  writable: true
 }{);


 This is trivial enough to do in user code but since DOM4 depends on it
 we should just put it in the right place; In ES6.







 --
 erik
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-02-24 Thread Erik Arvidsson
On Fri, Feb 24, 2012 at 11:09, Rick Waldron waldron.r...@gmail.com wrote:


 On Thu, Feb 23, 2012 at 3:15 PM, Erik Arvidsson erik.arvids...@gmail.com
 wrote:

 DOM4 added a new interface called DOMStringList for the sole reason
 that Array does not have contains. Before this the return type was an
 Array of Strings so we could use indexOf, map, forEach etc. Now that
 it is using a non Array we lost all of that.


 Wouldn't the return type (or [[Class]]) still be restricted from using
 Array?

No. We (WebKit) used to return a true JS Array (created by JSC or V8).

-- 
erik
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-02-24 Thread Allen Wirfs-Brock

On Feb 24, 2012, at 11:09 AM, Rick Waldron wrote:

 
 
 On Thu, Feb 23, 2012 at 3:15 PM, Erik Arvidsson erik.arvids...@gmail.com 
 wrote:
 DOM4 added a new interface called DOMStringList for the sole reason
 that Array does not have contains. Before this the return type was an
 Array of Strings so we could use indexOf, map, forEach etc. Now that
 it is using a non Array we lost all of that.
 
 Wouldn't the return type (or [[Class]]) still be restricted from using 
 Array? 
 
 From 8.6.2
 
 The value of the [[Class]] internal property is defined by this specification 
 for every kind of built-in object. The value of the [[Class]] internal 
 property of a host object may be any String value except one of Arguments, 
 Array, Boolean, Date, Error, Function, JSON, Math, Number, 
 Object, RegExp, and String. 
 
 
 So it can't be an Array by name, right?
 

It can be, as long as it really is a ES array.  host object doesn't mean any 
object created by the host.  It means new kinds of objects created by the host 
that implement primitive behaviors (generally internal methods) differently 
from what is specified by the ES spec.  

So, from the ES perspective, no problem.  When I originally asked the question 
I was thinking more about from the Web IDL perspective.  Does Web IDL require 
things (for example throwing if extra arguments are passed) that ES Arrays do 
not do.


Allen___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Array.prototype.contains

2012-02-24 Thread Rick Waldron
Allen, thank you for the clarification there


Rick

On Feb 24, 2012, at 7:19 PM, Allen Wirfs-Brock al...@wirfs-brock.com wrote:

 
 On Feb 24, 2012, at 11:09 AM, Rick Waldron wrote:
 
 
 
 On Thu, Feb 23, 2012 at 3:15 PM, Erik Arvidsson erik.arvids...@gmail.com 
 wrote:
 DOM4 added a new interface called DOMStringList for the sole reason
 that Array does not have contains. Before this the return type was an
 Array of Strings so we could use indexOf, map, forEach etc. Now that
 it is using a non Array we lost all of that.
 
 Wouldn't the return type (or [[Class]]) still be restricted from using 
 Array? 
 
 From 8.6.2
 
 The value of the [[Class]] internal property is defined by this 
 specification for every kind of built-in object. The value of the [[Class]] 
 internal property of a host object may be any String value except one of 
 Arguments, Array, Boolean, Date, Error, Function, JSON, 
 Math, Number, Object, RegExp, and String. 
 
 
 So it can't be an Array by name, right?
 
 
 It can be, as long as it really is a ES array.  host object doesn't mean 
 any object created by the host.  It means new kinds of objects created by the 
 host that implement primitive behaviors (generally internal methods) 
 differently from what is specified by the ES spec.  
 
 So, from the ES perspective, no problem.  When I originally asked the 
 question I was thinking more about from the Web IDL perspective.  Does Web 
 IDL require things (for example throwing if extra arguments are passed) that 
 ES Arrays do not do.
 
 
 Allen
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


RE: Array.prototype.contains

2012-02-23 Thread Domenic Denicola
Perhaps using indexOfIdentical from 
http://wiki.ecmascript.org/doku.php?id=harmony:simple_maps_and_sets

From: es-discuss-boun...@mozilla.org [es-discuss-boun...@mozilla.org] on behalf 
of Erik Arvidsson [erik.arvids...@gmail.com]
Sent: Thursday, February 23, 2012 15:15
To: es-discuss@mozilla.org
Subject: Array.prototype.contains

DOM4 added a new interface called DOMStringList for the sole reason
that Array does not have contains. Before this the return type was an
Array of Strings so we could use indexOf, map, forEach etc. Now that
it is using a non Array we lost all of that.

Proposal: Add Array.prototype.contains, implemented as:

Object.defineProperty(Array.prototype, 'contains', {
  value: function(value) {
return this.indexOf(value) !== -1;
  },
  enumerable: false,
  configurable: true,
  writable: true
}{);


This is trivial enough to do in user code but since DOM4 depends on it
we should just put it in the right place; In ES6.

--
erik
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


  1   2   >