Edge JsRT: External indexed properties

Several of the features that Chakra added to the hosting APIs for Edge were inspired/required by the port of node.js on top of Chakra. One of the biggies, I believe, is the new ability to override the numerically indexed properties on an object using a native blob of data. The APIs in question are JsHasIndexedPropertiesExternalData, JsSetIndexedPropertiesExternalData, and JsGetIndexedProeprtiesExternalData.

The way they work is that you have a blob of some particular native type (say, 32-bit integer) and you can say “hey, when someone asks for this object’s numerically indexed properties (i.e. obj[1], obj[2], etc.), give them back the answer from this blob.” It’s a quick way to make a JS object look like an array and back the array with a native blob (instead of having to set every individual index).

The V8 hosting API has a very similar API, and I believe the node.js Buffer object uses this to quickly set the contents of a Buffer before passing it into JS. When I worked on the original port of node.js on top of Chakra, there were all sorts of hacky hacks we had to make to get this to work–and it was always fragile–so I’m not surprised this API makes an appearance. (Ironically, I think that everyone might be better off using ArrayBuffer/TypedArray, but you work with the code you have, not the code you want to have…)

You should also follow me on Twitter here.

Leave a Reply

Your email address will not be published. Required fields are marked *