The experience of creating my own JavaScript runtime - #1
source link: https://dev.to/victoriarose/the-experience-of-creating-my-own-javascript-runtime-1-4h9j
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Posted on Jun 10
The experience of creating my own JavaScript runtime - #1
Hello everyone, for a while (a few months) I came up with the idea of developing my own JavaScript runtime, written in C# using Jint. At first it seemed unfeasible, or at least difficult enough, but I had already tried to assemble a project (for a hobby, like this one) using its own JavaScript engine, HTAPPS, whose focus was to do the same thing as Electron, however, in a lightweight way (and only for windows, as it used the standard IE frame to execute).
The current development repository can be accessed here.
But why? I decided to start this project as a pure hobby, and among the main reasons why I started the project are:
- I thought about how Node.js was created in its beginnings, it was the opportunity to build something similar in CSharp, my specialty
- I needed my own automation tool, I'm not very into Python but TypeScript/JavaScript would be a perfect thing to do it. Node can handle it, but there are some "raw" things that make me very uncomfortable
- I need something to present as my college graduation project (yes)
First steps
MelonRuntime is based on Jint, a JavaScript interpreter created by Sébastien Ros, software developer in the ASP.NET team at Microsoft. Melon works from bindings and functionalities injected into this interpreter together with external typing (provided by another package that comes with the default project generated by the command npx melon new
) and built-in tools.
The first days were very fun, I had to learn how to inject functionality into the engine (binding what is C# and what is JavaScript) and being able to call them from within the code. For that I had (and still have the help) of a library that I created myself, called CLI.NET, to create command interfaces quickly.
- Tip: I do not recommend using CLI.NET for production, there is no Nuget package and I had to perform some optimizations, the original repository needs attention
The first binding was to implement a basic console
tool, and the first function was obviously log
:
The implementation was a mess (I think it still), but I like it, and I have to improve it more and more. Currently, there is the implementation:
public static void Write(object obj, int color)
{
CLNConsole.Write("< ", ConsoleColor.Red);
try
{
JsonSerializerOptions options = new()
{
ReferenceHandler = ReferenceHandler.IgnoreCycles,
WriteIndented = true
};
var serialized = JsonSerializer.Serialize(obj, options);
CLNConsole.Write(serialized, color);
}
catch
{
CLNConsole.Write(obj.ToString() ?? "null", color);
}
Console.WriteLine();
}
After that, I was focused in turning the errors more readable, like that:
There is still a long way to go.
Recommend
-
10
Ever considered setting up and running your very own git server? It’s actually quite easy! In this post, I’ll outline the steps I took to set upmy own so that you can give it a try yourself. But first, why might you even...
-
3
Flutter: Creating your own Inherited WidgetsWhile we generally use Provider or GetIt to pass things around in Flutter, there are times when you don...
-
4
How to Get Started on Creating Your Own CryptocurrencyMay 13th 2021 268,642 reads8
-
2
Creating Our Own Custom Messaging Solution for IoT DevicesAugust 26th 2021 new story5
-
4
@anatoliiAnatolii KabanovDeveloping and enjoying life.NEWABOUT PAGE
-
8
Creating Your Own IdentityServer4 Storage Library Over the years I’ve experienced many opinions about the default IdentityServer4 storage libraries; however, no matter your views on entity framework, clustered indexes, an...
-
2
Creating my own bespoke binary format 1 September 2021 — 15 min # Don’t do it Well first off the bat, I want to repeat somethi...
-
3
As an Ubuntu user, I find myself typing apt install ... frequently as a way to install software on my system. But what if I wanted to distribute my code to others via an apt repository? In this post I’ll cover how to 1) create a deb p...
-
3
This post is a continuation of Roll your own JavaScript runtime. There are many reasons you may want to roll your own JavaScript runtime, su...
-
6
Creating Your Own Media Plugin For Capacitor: An iOS Tutorial Logan Brade
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK