3 ms·
Oh, I am indeed surprised! I guess I always assumed that most of the JavaScript standard library was written in C++
by internetter 2y ago
Oh, I am indeed surprised! I guess I always assumed that most of the JavaScript standard library was written in C++
- achierius 2y agoWell, most all of the compiler, runtime, allocator, garbage collector, object model, etc, are indeed written in C++ And so are many special operations (eg crypto functions, array sorts, walking the stack) But specifically with regards to library functions, like the other commentator said, losing out on in lining sucks, and crossing between JS and Native code can be pretty expensive, so even with things like sorting an array it can be better to do it in js to avoid the overhead... Eg esp in cases where you can provide a callback as your comparator, which is js, and thus you have to cross back into js for every element So it's a balancing game, and the various engines have gone back and forth on which functions are implemented in which language over time
- jitl 2y agoMuch of the standard library in v8 is written in Torque, a custom language. https://v8.dev/docs/torque https://v8.dev/docs/torque Example file for array.find(…): https://github.com/v8/v8/blob/5fe0aa3bc79c0a9d3ad546b79211f07105f09585/src/builtins/array-find.tq#L120 https://github.com/v8/v8/blob/5fe0aa3bc79c0a9d3ad546b79211f0...