[Webkit-unassigned] [Bug 120112] Typed Arrays have no public facing API

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Sep 21 22:12:23 PDT 2015


--- Comment #13 from Filip Pizlo <fpizlo at apple.com> ---
(In reply to comment #11)
> Facebook's react-native isn't able to send or receive binary data over
> WebSockets or XHR, because there's still no native API:
> https://github.com/facebook/react-native/issues/1424
> I already wrote a Typed Array API for JSC that has served us extremely well
> for a few _years_ now [1]. Let me know if there's anything I can do to get
> this into JSC proper.

How about submitting a patch?

> [1]
> https://github.com/phoboslab/JavaScriptCore-iOS/blob/typed-arrays/
> JavaScriptCore/API/JSTypedArray.h

This looks pretty good, but you need to clarify semantics.

JS_EXPORT JSObjectRef JSTypedArrayMake(JSContextRef ctx, JSTypedArrayType arrayType, size_t numElements);

What happens when arrayType is kJSTypedArrayTypeNone? or kJSTypedArrayTypeArrayBuffer? Probably any answer other than UB is a good answer.

JS_EXPORT void * JSTypedArrayGetDataPtr(JSContextRef ctx, JSValueRef value, size_t * byteLength);

Can you clarify what the caller must do to ensure that the returned pointer continues to point to valid memory? Is the caller expected to just keep the array alive? If so, then that's probably not what we want. It would mean that the following program would probably run fine in debug and maybe in release as well if you got lucky, but would actually be wrong because "array" is not live after the GC.

void foo()
    JSValueRef array = JSTypedArrayMake(ctx, kJSTypedArrayTypeInt8Array, 100);
    int8_t* data = JSTypedArrayGetDataPtr(ctx, array, 100);
    for (var i = 0; i < 100; ++i)

I think it's best if it was hard to write a program with such a mistake. One way to do this is to have GetDataPtr increment the ref count of the underlying buffer, and have an API like JSTypedArrayReleaseDataPtr(ctx, value, ptr) that decremented the ref count.

You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-unassigned/attachments/20150922/31096eeb/attachment.html>

More information about the webkit-unassigned mailing list