Implement native JS(src/js/*.js) modules as c builtin code
We have to discuss the following topics.
- Benifit
- size
- performance
- Feasibility
function foo() {
do something
}
IMHO, replacing do something part with c builtin function is only thing we can do now.
Q. how to replace the whole foo function with c builtin not affecting module system ?
What if we can implement not by level of function() but by functionality, such as file, socket, server, can it be possible?
It's possible to create builtin object and add properties with native handlers.
Like @seanshpark suggests it will look like:
File.open ("aaa") // open is native handler
simple function() implementation as built-in is ok.
as iotjs modules uses exports to export functions, it will be different.
function foo() {
do something
}
exports.foo = foo;
We can do that.
JHandler(Foo, handler) {
// do somthing
}
...
Module* module = GetBuiltinModule(SOME_MODULE);
module->module = new JObject();
module->module->SetMethod("foo", Foo);
var some_module = process.binding(process.binding.some_module);
exports.foo = some_module.foo;
Closing.
C code will be harder to read, write, and maintain, etc. It can decrease development productivity, especially for current IoT.js whose milestone 1 has not been finished yet. And it can be a bigger problem for developers who are familliar with node.js and v8 APIs, but not IoT.js and JerryScript APIs. They may even want to refer to existing codes when their new module implemetation, but it will be harder to do if everything is written in C.
On the other hand, it is not straightforward how much benefit we can achieve. For example, when reading a named property of JS object (simple obj.prop), to perfectly describe the behavior of JS equivalence in C, we should execute complex operations like: catch and throw proper error when property getter throws, sometimes check if property exists before actually reading it, etc.
So I think it's better to open a new issue when a specific module really needs a re-implementation. (like PR #393)