Live data from Hacker News

A small but complete JavaScript engine

bellard.org

51–60 of 151 posts

Re: A small but complete JavaScript engine

#51
It look like good (including there are some good features that I do not see in other implementations), although there are some things which may help:

- Support ISO-8859-1 encoding (true ISO-8859-1 encoding, not Windows-1252) in addition to UTF-8, for all of the functions that can read text from files and write text to files, to avoid having to implement it by yourself one byte at a time. This is useful when you want text which is mostly ASCII, but which may contain extended characters that aren't Unicode. (There is no need to support any other character sets or encodings, though.)

- Document the C API better. Currently, the documentation isn't very good.

- Implement WTF-8 (if it isn't already), so that arbitrary JavaScript strings (which are strings of 16-bit characters) can be represented as UTF-8 without losing data. Often the text will be ASCII anyways, and you will want to use ordinary C strings,

- Add a API function to read/write strings of 16-bit characters. (This is probably unnecessary for property names, although it is helpful for strings.)

- Add an option to disable use of Unicode tables, in case your program does not use them. (UTF-8, String.prototype.codePointAt, etc would still work regardless, since they don't need Unicode tables to work. However, it would prevent Unicode properties from being used in regular expressions, remove String.prototype.normalize, and case conversion would be limited to ASCII (or perhaps ISO-8859-1) only.)

Additional optional extensions may be wanted, even if not enabled or even included in the executable by default (due to complexity), such as:

- PCRE.

- Option to disable automatic semicolon insertion.

- A "goto" command; you cannot jump into blocks, past declarations at the same level (in either direction), or out of functions. You can otherwise jump forward and backward within a block (including past nested blocks) or out of a block.

- Possibility for a function called by one JavaScript program to suspend that program while executing a different JavaScript program (which may possibly share objects with the first one), and later resume execution.

Re: A small but complete JavaScript engine

#52
post #34

Currently composed of 85,624 lines of C code, mostly in quickjs.c (53,575 lines in that one file alone), but also with a couple other large ones. I can't say I understand the reason for such massive files. Surely it would be easier to maintain if it was split into a few well-defined modules? In addition to the maintenance concerns, a JavaScript engine has quite a few parts that could be used as individual components.…

Rather than trying to figure out which of dozens of files has what you're looking for, you can just search one or two large ones.

On the other hand, I hate finding a project that looks useful, but then the code is scattered across many files which are barely one screen long, or worse, also spread throughout different deeply nested directories. Regardless of whether the organisation makes sense, navigating directory trees is annoying.

Re: A small but complete JavaScript engine

#53

It look like good (including there are some good features that I do not see in other implementations), although there are some things which may help: - Support ISO-8859-1 encoding (true ISO-8859-1 encoding, not Windows-1252) in addition to UTF-8, for all of the functions that can read text from files and write text to files, to avoid having to implement it by yourself one byte at a time. This is useful when you want…

true ISO-8859-1 encoding, not Windows-1252

AFAIK, 8859-1 is a subset of 1252.

Re: A small but complete JavaScript engine

#54
post #18

Earlier quoted context omitted.

These individual technologies (DOM/html parser, js runtime, layout etc.) really aren't so bad. It's about a weekends worth of work to do one. What makes a "modern" browser is all of these technologies together not just quirk free, but matching quirks with whatever browser is popular. Even this won't really be enough since most people also depend on a bunch of online services provided by browser vendors at this point…

> about a weekends worth of work to do one “layout”, including CSS? Hey, good joke, that’s amusing.

From Fabrice's point of view, it might well be.

Re: A small but complete JavaScript engine

#58
post #34

Currently composed of 85,624 lines of C code, mostly in quickjs.c (53,575 lines in that one file alone), but also with a couple other large ones. I can't say I understand the reason for such massive files. Surely it would be easier to maintain if it was split into a few well-defined modules? In addition to the maintenance concerns, a JavaScript engine has quite a few parts that could be used as individual components.…

Rather than trying to figure out which of dozens of files has what you're looking for, you can just search one or two large ones. On the other hand, I hate finding a project that looks useful, but then the code is scattered across many files which are barely one screen long, or worse, also spread throughout different deeply nested directories. Regardless of whether the organisation makes sense, navigating directory t…

> Rather than trying to figure out which of dozens of files has what you're looking for, you can just search one or two large ones.

Why is this a good thing? The same amount of code and same number of results need to be scanned either way. With many files, you at least have the file name to give you some small amount of context without needing to read the code.

Re: A small but complete JavaScript engine

#59
post #29

Earlier quoted context omitted.

It has a very small standard library: https://bellard.org/quickjs/quickjs.html#std-module It would be enough for a good number of CLI tools, I'd think. But one big issue is going to be that every library on NPM is hardcoded to use Node's modules (e.g. fs) so you're not going to be able to use any external modules at all.

This is untrue. There are plenty of modules published to npm which don't use node APIs, often specifically so they can be used in many runtimes. Here's one example: https://www.npmjs.com/package/squat

OK, to be clearer: almost all the libraries published to NPM that would use the functions in QuickJS’s std module instead use Node modules and there is no compatibility layer.

So yes, there are plenty of pure JS modules. But if you want to read a file from a disk you’re going to end up with a library that assumes you’re using Node.

Post reply on HN