flatMap and flat are now Stage 3. https://github.com/tc39/proposal-flatMap
I'd be keen on implementing this if it's not already planned for. Please let me know if an external contribution would be welcome here.
Go for it! I would expect these can be written as JS built-ins? @meg-gupta might have pointers here.
OK - I'll make a start and see how I get on, I think that for CC mechanics I can follow the model used for Array.prototype.filter so hopefully won't need much assistance. I'll also endeavour to test against all of the relevant test-262 tests before submitting anything.
ChakraCore/lib/Runtime/Library/JsBuiltIn/JsBuiltIn.js - has our builtins written in Javascript. Array.prototype.indexOf is also a good implementation to follow via the Js route.
One question I could do with help with, implementing a ethodwithin JsBuiltIn.js is it possible to have another JavaScript Function that it calls?
Motivation is that I cannot see a good way to .flat or .flatMap without using the FlattenIntoArray function described in the spec - I've written this function in JavaScript but for some reason including this inside JsBuiltIn.js and then trying to call it from within my Array.Flat implementation results in a hard crash at runtime - is there anything obvious I'm missing?
If I put the below into JsBuiltIn.js, regenerate bytecode, build CC and then call the Array.prototype.flat method at runtime I get a hard crash:
const FlattenIntoArray = function ( ) {}
platform.registerFunction(FunctionsEnum.ArrayFlat, function (depth) {
"use strict";
FlattenIntoArray(); // hard crash
}
Deleting the FlattenIntoArray() call results in the code running to completion.
A good example for such a helper function would be CreateArrayIterator in JsBuiltins.js. We register them via registerChakraLibraryFunction and which adds them to the __chakraLibrary object. Functions on __chakraLibrary will be treated internal and will not be visible outside. Unfortunately we have not added documentation on the process of adding a Js builtin, I'll try to make that happen soon.
Thanks for the help, it all seems to be working now, I'll sort out some appropriate tests then submit it.
Most helpful comment
I'd be keen on implementing this if it's not already planned for. Please let me know if an external contribution would be welcome here.