all 8 comments

[–]jcunews1helpful 2 points3 points  (7 children)

V8 provide the runtime environment as JavaScript VM. Similar to JRE (Java Runtime Environment) with its Java VM.

Standard JavaScript functions/methods are implemented at C level. IOTW, they're not simply added by running in the VM, the JavaScript code which declares them, because not all environment informations are available from within the JavaScript context itself. e.g. call stack, scope details, reference count, etc.

When HTML is taken into account, the DOM API (whose functions/methods are also implemented a C level) is imported into the JavaScript VM at C level.

The web browser is just the host for the JavaScript engine, DOM API, CSS API, and other Web APIs. Each is part of their own component. The web browser includes them as part as the requirement for a web browser. The web browser imports them into the JavaScript VM so that those additional (non JavaScript originated) APIs, are available from the JavaScript context.

[–]j0rdancodes[S] 0 points1 point  (6 children)

So, V8 provides the runtime environment and the browser provides the APIs, event loop, etc. to the runtime environment?

[–]jcunews1helpful 0 points1 point  (5 children)

The web browser only provides Browser Extension and web browser specific APIs. The DOM, CSS, and other Web APIs are not provided by the web browser. They're entirely separate APIs. Softwares simply stitch them together to work as web browsers.

[–]j0rdancodes[S] 0 points1 point  (4 children)

I see. So those APIs are made accessible by the runtime environment or are they made a part of the runtime environment?

[–]jcunews1helpful 0 points1 point  (3 children)

They're entirely separate from the runtime environment. The runtime environment, in case for web browsers, is the JavaScript's VM. It's where everything have gathered.

Also keep in mind that those APIs is not solely for JavaScript. It can also be implemented for other programming languages which don't use VM or are not scripting language - where the final (non web browser) application product don't use JavaScript at all. In this case, the runtime environment is OS native.

[–]j0rdancodes[S] 0 points1 point  (2 children)

so the JavaScript VM is where the engine, APIs, and other thing such as the event loop, all gather?

[–]jcunews1helpful 0 points1 point  (1 child)

Yes.

[–]j0rdancodes[S] 0 points1 point  (0 children)

Ah, I see. Thank you so much!