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

[Public WebGL] Typed Array slice() renamed to subset()

The slice() method on Typed Array views has been renamed to subset().
This decision was made at the last WebGL working group face-to-face
meeting to avoid collision with the slice() method on ECMAScript
arrays. Typed Arrays' slice() method had different semantics; the
slice referred to the same storage, so modifications to the slice were
visible in the parent typed array.

We considered keeping Typed Array slice() and making it behave
similarly to ECMAScript arrays' slice() method, allocating a new Typed
Array and backing store and copying data into it, but decided against
doing so for two reasons. First, doing so could cause slight changes
in behavior for existing WebGL applications. Second, and more
importantly, applications unaffected by the semantic change might
suddenly run more slowly.

The associated changes in WebKit and Firefox should be in place within
a few days.

You can make your code resilient to these changes, and switch to the
new subset() method now, by defining and using a helper function like

function fixupTypedArray(array) {
  function newSlice(begin, end) {
    var result = this.originalSlice(begin, end);
    return result;

  if (array.slice && !array.subset) {
    array.originalSlice = array.slice;
    array.slice = newSlice;
    array.subset = newSlice;

  return array;

and then wrapping constructor invocations like this:

    var array = fixupTypedArray(new Float32Array(16));

If anyone has a suggestion on how to make this cleaner, please post to the list.

Apologies for making this sort of content-breaking change this close
to reaching version 1.0 of the WebGL and Typed Array specs.

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