<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Typed Arrays have no public facing API"
   href="https://bugs.webkit.org/show_bug.cgi?id=120112#c24">Comment # 24</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Typed Arrays have no public facing API"
   href="https://bugs.webkit.org/show_bug.cgi?id=120112">bug 120112</a>
              from <span class="vcard"><a class="email" href="mailto:dominic.szablewski&#64;gmail.com" title="Dominic Szablewski &lt;dominic.szablewski&#64;gmail.com&gt;"> <span class="fn">Dominic Szablewski</span></a>
</span></b>
        <pre><span class="quote">&gt; [Passing pointer to size_t to receive byteLength] I don't believe we have any other api that behaves in this way.</span >
All API functions that may throw an exception use this semantic (if I understood your concerns correctly).

JSValueRef exception = NULL;
JSValueToObject(ctx, value, &amp;exception);

I would argue that doing the same thing with a size_t is not really different. However...

<span class="quote">&gt; Mixing and matching what unit the length you're using is a recipe for mistakes.</span >

Point taken. 

So I propose the following set of functions:

JSTypedArrayType JSObjectGetTypedArrayType(JSContextRef ctx, JSObjectRef object);
JSObjectRef JSObjectMakeTypedArray(JSContextRef ctx, JSTypedArrayType arrayType, size_t numElements);
void * JSObjectGetTypedArrayDataPtr(JSContextRef ctx, JSObjectRef object);
size_t JSObjectGetTypedArrayByteLength(JSContextRef ctx, JSObjectRef object);
size_t JSObjectGetTypedArrayNumElements(JSContextRef ctx, JSObjectRef object);


<span class="quote">&gt; Also this API fails to allow sharing of data allocated elsewhere (...) Most other data related APIs on OS X allow specifying the external buffer</span >

The JSC API *nowhere* adheres to this. Everything is copied all over the place. Even the somewhat lower level JSString functions copy everything.

Also, as far as I can tell, none of the existing Typed Array or ArrayBuffer constructors allow for using an external data pointer. The data is always allocated internally. The existing WebGL implementation in WebKit gets along just fine with this.

My proposed Typed Array API would still allow for most use cases to avoid copying. E.g. in Ejecta, the Canvas2D .getImageData() functions uses glReadPixels() directly with a Typed Array dataPtr I.e.:


void *dataPtr = JSObjectGetTypedArrayDataPtr(ctx, array);
size_t byteLength = JSObjectGetTypedArrayByteLength(ctx, array);
if( byteLength &gt;= width * height * bytesPerPixel ) {
    glReadPixels(x, y, width, height, format, type, dataPtr);
}


An additional &quot;JSObjectMakeTypedArrayWithDataPtrNoCopy&quot; function (not sure what's the right phrasing here) may have its place, but I still don't believe it's critical and it may even be more confusing than helpful.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>