1. 22

  2. 4

    I follow Chockenberry on RSS, so I saw this when it was posted and thought yeah, but I already have Node and Deno installed so why would I ever use this? Is that too negative? Like I get that if you’re Mac developer and don’t have Node installed, this is cool to be aware of. But everything in the article makes it sound like it’s a worse Node, not a better one, so why would I personally ever use it? Anyone who does modern web dev already has Node, which is less quirky than this, and if you’re ambitious you may also have Deno, which is even less quirky. So this really just exists for the scenario of wanting to distribute some JS to Mac users but not have to install anything. Which is fine, but extremely niche, and at that point, I’d be more likely to the JS version of AppleScript anyway.

    “JSC: my new extremely niche tool for distributing JavaScript to Mac users” is not a good article title.

    In conclusion, bring back Rhino.

    1. 5

      I guess it might come in handy if you want to add JS scripting to a native Mac app and don’t want to add a hard dependency on or bundle your app with node/deno. Come to think of it, that’s probably what it exists for in the first place (to service first-party apps).

      I like that it’s not part of the v8/node monoculture. Also, I think the objc/C API might be available to sandboxes macOS/iOS apps?

      1. 4

        I feel you are missing the point.

        All jsc is is a naked browser web page JS environment – without a web page. The reason Node is useful starts with the fact that it adds an entire I/O system on top of that. JSC just has a handful of utility functions to allow it to even be useful at all – the only I/O available in jsc is reading stdin and writing to stdout. (And in fact, reading lines from stdin. Not even getc. You can barely do anything interesting with that.)

        That’s not even attempting to be even an awful Node. All it’s good for is testing and maybe replacing the occasional AWK/sed script. And in that capacity, it’s relevant that it’s there without you having to install anything.

        And that’s the article.

        I think you went in hoping to find something JSC isn’t even meant to be – which is more about your expectations than about the value of the tool. Your alternative title would be bad not because it would drive off readers but because it doesn’t match the article, and nobody would write that article.

          1. 2

            Much better question!

            1. I can’t figure out how to read from stdin in JXA (while conversely I can’t figure out how to get command line arguments in jsc). This is the only real answer I can think of.

            2. There’s also the apparent actual purpose of jsc – it has a small bunch of profiling-related functionality, both in its command line switches and in the built-in functions. A real answer if you have use for this, otherwise uninteresting.

            3. osascript has a perceptible startup delay and jsc doesn’t (<15ms for jsc vs ~110ms for osascript on my machine).

              (I am always surprised and dismayed at how slow AppleScript is. When JXA came out I assumed it would fix this but apparently it’s the runtime environment rather than the language that’s slow, and so JXA doesn’t run materially faster than equivalent AppleScript. Oh well.)

      2. 4

        It’s also available in WebKitGTK. It was featured in the famous “Wat” presentation. And that’s about all the interesting facts about it.

        1. 2

          I wasn’t familiar with this but was a little curious if it was bespoke or something widely available enough to actually use for anything portable.

          It looks like it comes from https://github.com/WebKit/WebKit/blob/main/Source/JavaScriptCore/jsc.cpp. I haven’t actually tried to install webkit since I don’t want to fall down a rabbit-hole today, but I did check the build logs for the webkitgtk nixpkg and notice this was output at /nix/store/…-webkitgtk-2.32.3/libexec/webkit2gtk-4.0/jsc

          1. 2

            On my 10.14.6 system it’s at /System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/Resources/jsc (note the “Resources” instead of “Helpers”).

            1. 4

              And, a quick test shows that a jsc “Hello World” runs in 14ms, while a Node “Hello World” runs in 76ms. Running simple utilities in 1/5 the time isn’t anything to sniff at.

            2. 2

              FWIW Windows had something like this built-in over a decade ago. I think it was the JScript engine, and I actually ported my JS template engine to it, which was trivial.

              Just like you could use VBScript to invoke any COM objects, you could also use JScript. It’s probably still there, but I don’t use Windows anymore, so I can’t check.

              1. 4

                It is still there. One of the games I used to play has a popular addon that accepts user-contributed data. You run a bat file that runs JScript to upload your local saved variables file to some server.

                1. 2

                  Many years ago I played around with it, missing some stuff I take for granted on Linux. Here’s an example for “right-click send a file via scp to a host, then copy the full path to the clipboard”: dropSCP.js - it’s a little clunky but it worked without installing anything besides putty.