Note: this article compiled and tested on CentOS 7, based on commit 246 on the master branch.
In jsconf2018, Ryan Dahl gave a talk, Design Mistakes in Node, and brought his next generation server-side TypeScript runtime, deno, to the public. At this moment, deno is still a very early stage project. It has no stable API and actually, even a very basic runnable binary is not provided. Re-deno is a project which aims to recreate deno from scratch, and to understand the underlying technology of deno's implementation.
Since deno was created, it has already been refactored and recreated few times. The first version of deno, Dahl used a golang V8 binding to handle the communication between TypeScript and the native API. In the recent commits, Dahl dropped golang to avoid double GC problems and started using a C++ and Rust backend. So, currently the communication between TypeScript and V8 is handled by a C++ and C library,
libdeno and the language logic, compiler driver, deno's native APIs are implemented in Rust.
What is V8?
NodeJS, Deno and V8
deno.readFileSync only deals with ArrayBuffers and does not have an encoding parameter to return strings.) The intention is to make very easy to extend and link in external modules which can then add this functionality.
Deno does not aim to be API compatible with Node in any respect. Deno will export a single flat namespace "deno" under which all core functions are defined. We leave it up to users to wrap Deno's namespace to provide some compatibility with Node.
Basic concepts in V8
Before we start, let's review some concepts in V8 engine.
isolateis a VM instance with its own heap.
- In V8, a
local handleis a pointer to an object. All V8 objects are accessed using handles. They are necessary because of the way the V8 garbage collector works. A
handle scopecan be thought of as a container for any number of handles. When you've finished with your handles, instead of deleting each one individually you can simply delete their scope.
To be more clear to beginers, an
isolate is a
process and a
context is a
handler scope and
handler can be considered as a
function and a
variable. When the scope is released, all handlers inside the scope will be released as well.
So, to achive our goal, we need to
- create an isolate
- create a context
- create a handler scope
- create handler inside scope to represent the values
- execute the code inside context
- get result
- clean up
Now let's take a look at the main function in hello world example.