Closed Bug 742209 Opened 12 years ago Closed 12 years ago

Sort out the typed array reflection situation on the C++ side

Categories

(Core :: DOM: Core & HTML, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 747827

People

(Reporter: bzbarsky, Unassigned)

References

(Blocks 1 open bug)

Details

How do we really want to pass them?  Can we specialize to a Foo* + length in a struct in some cases?
Current proposal:


For arguments, we define a struct like so:

  template<typename T>
  struct TypedArray {
    T* const mData;
    const uint32_t mLength;
    JSObject* const mObj;
  };

and typedefs:

  typedef TypedArray<uint8_t> ArrayBuffer;
  typedef TypedArray<uint8_t> ArrayBufferView;

Typed arrays are converted to the corresponding struct of this type, which is then passed to the C++ by reference, with Uint8ClampedAray using T=uint8_t.  ArrayBuffer arguments end up using the ArrayBuffer typedef above; ArrayBufferView use the ArrayBufferView typedef.  Or we may create separate classes for ArrayBuffer and ArrayBufferView if we end up with function overloads that need to take either one of those or a Uint8TypedArray.

In all cases, the mObj will be set to the actual passed-in object.  This will allow consumers that need to store and/or return the object to do so.

An alternative would be to just pass the JSObject* and make sure we have JS APIs which work sanely on those.  If those do happen, would people prefer to do this instead of the struct idea above?  I will admit to still liking the struct thing because it's so explicit....

For return values, I think we'll just use JSObject*.  The typed array _creation_ APIs are pretty straightforward, and if we have to return an array we were given before then a JSObject* is really the best we can do.  An alternative would be to use a TypedArray struct as above, returned by value, and with either mData or mObj but not both non-null.  In that case the binding would create the typed array itself in the mData non-null case.  I'm not sure this is worth it, though.
Whoops.  This happened already...
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → DUPLICATE
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.