[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] Typed Array slice() renamed to subarray() (was: subset())




First, sorry!

Second, at the last minute (after some discussion with wider JS folks), we ended up renaming this to subarray() instead of subset().  The argument was that there was no "set" to "sub", so subset didn't really make sense since it has a mathematical meaning.  I believe WebKit has also been updated.  So, here's an updated (though untested) shim:

function setupTypedArraySubsetCompatibilityShim() {
  var types = [Int8Array, Uint8Array, Int16Array, Uint16Array,
    Int32Array, Uint32Array, Float32Array, Float64Array];
  var original, shim;
  for (var i = 0; i < types.length; ++i) {
    if (!types[i])
      continue;
    if (types[i].prototype.slice === undefined) {
      original = "subarray";
      shim = "slice";
    } else if (types[i].prototype.subarray === undefined) {
      original = "slice";
      shim = "subarray";
    }
    Object.defineProperty(types[i].prototype, shim, { value:
      types[i].prototype[original], enumerable: false});
  }
}

Third, sorry again for the second quick rename!

    - Vlad

----- Original Message -----
> Of course, since Float64Array isn't implemented everywhere yet, this
> requires a definition and an additional guard, e.g.
> 
> 
> var Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array,
> Uint32Array, Float32Array, Float64Array; // define names, just in
> case...
> 
> 
> var types = [Int8Array, Uint8Array, Int16Array, Uint16Array,
> Int32Array, Uint32Array, Float32Array, Float64Array];
> types.forEach(function(type) {
> if (type) {
> ...
> }
> });
> 
> 
> 
> 
> 
> 
> On Mon, Jan 31, 2011 at 9:18 AM, Joshua Bell < josh@lindenlab.com >
> wrote:
> 
> 
> Don't forget Float64Array!
> 
> 
> (Also, while nitpicking: using forEach() over the types array would
> probably be more readable than iterating by index, if we're expecting
> this code to be widely copied and pasted. YMMV)
> 
> 
> 
> 
> 
> On Thu, Jan 27, 2011 at 11:05 PM, Cedric Vivier < cedricv@neonux.com >
> wrote:
> 
> 
> 
> 
> 
> 
> David Sheets highlighted to me that the shim could be even less
> intrusive if added method was set not to be enumerable, so here's an
> improved shim (again) :
> 
> 
> 
> function setupTypedArraySubsetCompatibilityShim() {
> var types = [Int8Array, Uint8Array, Int16Array, Uint16Array,
> Int32Array, Uint32Array, Float32Array];
> var original, shim;
> 
> for (var i = 0; i < types.length; ++i) {
> if (types[i].prototype.slice === undefined) {
> original = "subset";
> shim = "slice";
> 
> } else if (types[i].prototype.subset === undefined) {
> original = "slice";
> shim = "subset";
> }
> Object.defineProperty(types[i].prototype, shim, { value:
> types[i].prototype[original], enumerable: false});
> }
> }
> 
> 
> It's nicer but also brings to light the issue that Typed Arrays
> specification does not define any behavior regarding this.
> This leads currently to inconsistent behavior between Mozilla and
> Chrome when using the for...in construct with a typed array, Mozilla
> enumerates only its indexed properties (eg. 0 to 10 on a typed array
> of length 10) while the latter enumerate all properties (ie. also
> enumerates "length" and prototype methods).
> 
> I think Mozilla's behavior makes more sense and propose the following
> additions to the spec :
> 
> 
> in 4 The ArrayBufferView Type:
> The properties "buffer", "byteOffset" and "byteLength" are
> non-enumerable as if they were created with Object.defineProperty with
> {enumerable:false}.
> 
> in 5 The Typed Array View Types:
> The properties "BYTES_PER_ELEMENT", "length", "get", "set" and
> "subset" are non-enumerable as if they were created with
> Object.defineProperty with {enumerable:false}.
> 
> 
> 
> 
> 
> 
> Regards,
> -----------------------------------------------------------
> You are currently subscribed to public_webgl@khronos.org .
> To unsubscribe, send an email to majordomo@khronos.org with
> the following command in the body of your email:
> unsubscribe public_webgl
> -----------------------------------------------------------
-----------------------------------------------------------
You are currently subscribed to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email:
unsubscribe public_webgl
-----------------------------------------------------------