Comment by est

2 months ago

I really appreciate the engineering effort went into this "JavaScript interpreter"

https://github.com/yt-dlp/yt-dlp/blob/2025.09.23/yt_dlp/jsin...

This is the buried lede in this announcement for me - I had no idea they were already going to such lengths. It's really impressive!

This is perfect for the problem they were solving. Really cool that they took it this far to avoid adding further overhead.

It's a subset of Javascript. HN discussion here https://news.ycombinator.com/item?id=32794081

  • This description reminds me of program language wars excerpt I saw somewhere years ago about how c was obviously superior to Pascal, because with enough preprocessor macros you can compile any Pascal program in c. Followed by some hideous and humorous examples.

  • This is amazing, an old school but effective approach in this modern age. I was afraid they were going to embed a browser.

I decided just to look at the code for a moment and discovered ChainMap in Python.

  • This is excellent for some of my usages. I want to have my AI agents "fork" their context in some ways, this could be useful for that instead of juggling a tree of dictionaries.

  • Ha, that's cool. I have implemented a crappy and probably broken version of this type before. Next time I won't have to!

I'm on mobile, this seems like an actual js interpreter that only does objects and arithmetic. Impressive that it went that far

Heh, now I wonder how much JavaScript it actually interprets and given that it’s < 1000 lines, whether it could be used towards an introductory course in compilers.

  • Obviously not. An introductory course would introduce concepts like lexers, parsers, AST, etc, instead of working on strings.

    Here are lines 431 through 433:

        if expr.startswith('new '):
            obj = expr[4:]
                if obj.startswith('Date('):

  • There’s a famous presentation by David Beazley where he implements a WASM interpreter in Python in under an hour. Highly recommended.

Wait I thought they were running an entire browser engine

  • Over time they probably will require that. I believe YT still allows most of these things because of "legacy" apps, which they have been killing off bit by bit. I'm not sure if anyone is cataloging the oldest supported app, but most things like using YT from a slightly older game console don't work anymore.

    Basically any publicly known method that can sip video content with doing the least work and authentication will be a common point of attack for this.

I wonder how long until it gets split off into its own project. For the time being, it could do with a lot more documentation. At least they've got some tests for it!

  • > I wonder how long until it gets split off into its own project

    The submission is literally about them moving away from it in favor of Deno, so I think "never" probably gets pretty close.

  • Aside from the fact that the point of the announcement is that they're dropping it entirely, this "interpreter" is a hack that definitely is nowhere near capable of interpreting arbitrary JS. For example, the only use of `new` it handles is for Date objects, which it does by balancing parens to deduce the arguments for the call, then treating the entire group of arguments as a string and applying regexes to that.