On Thursday 12 April 2012 at 14:55, Tim Caswell wrote: > Very cool Stéphan. Also doesn't V8 come with it's own typed array > implementation now? I know it didn't when node added one.
There doesn't seem to be any. It only provides tools to allow indexing of any object with raw data backing. (ExternalData) > Is it possible for native addons to use this pure js implementation? I have > webgl bindings I wrote for node knockout. I wonder if it would be possible to > use your implementation for my bindings. github.com/creationix/node-webgl > (http://github.com/creationix/node-webgl) I was looking at how to make standard I/O in Node accept ArrayBuffer and friends, but only now that you mention it realize how important native bindings are. As it stands now, the best you can do is wrap/unwrap the underlying Buffer in JS. (All types have a `nodeBuffer` attribute, and all types accept a Buffer in the constructor.) I'm not sure if we do or don't want code on the C++ side of things that deals with types defined in JS. Buffer (ie. FastBuffer), a pure-JS type, works around this using trickery. `Buffer::HasInstance`, `Buffer::Data` and `Buffer::Length` work with any object that has ExternalData set up with kExternalUnsignedByteArray. So the checks pass for SlowBuffer, Buffer, and also Uint8Array. They can be easily modified to handle other types of ExternalData, so that e.g. FloatArray can be made to work. But it'd still exclude ArrayBuffer itself and DataView, which are not indexable at all, per the TypedArrays spec. Would love to hear ideas on how to fix this; I'm not really sure. -- Stéphan Kochen
