top | item 39280554

(no title)

OscarDC | 2 years ago

To add to this, a lot of those "W3C API" (most?) (to which I'll also add WHATWG API, like HTML5 - or fetch) have actually no relation to ECMAScript and thus aren't generally in v8 because they are not JavaScript.

Those API could be thought as from the "environment" in which JavaScript run. For example we often call web-only APIs "DOM API": `fetch`, `xmlHttpRequest` and so on.

Node.js also has its own environment. For example both `setTimeout` and `setInterval`, though present in both web and node.js, are implemented differently by browsers and node.js (it's just that node.js decided to go with roughly the same API - see below for code examples for both).

Taking requests as examples there are both declared in blink, the rendering engine and not v8 again because they aren't JS:

- fetch (https://source.chromium.org/chromium/chromium/src/+/main:thi...)

- XMLHttpRequest (https://source.chromium.org/chromium/chromium/src/+/main:thi...)

For the fun of looking even more at some code of reputable projects: for setTimeout / setInterval, I would guess they are declared here in blink: https://source.chromium.org/chromium/chromium/src/+/main:thi...

And maybe here for Node.js: https://github.com/nodejs/node/blob/8a41d9b636be86350cd32847...

To note that "filesystem" API also exist in web world: https://fs.spec.whatwg.org

Again, this API is completely different than in Node.JS

discuss

order

DanielHB|2 years ago

Good points, I always wondered why it took so long for NodeJS to support fetch() and WebSockets and other standard APIs. I thought those were part of V8, but I guess not!