Git Product home page Git Product logo

txiki.js's Introduction

txiki.js — The tiny JavaScript runtime

Overview

txikia (basque): small, tiny.

txiki.js is a small and powerful JavaScript runtime. It targets state-of-the-art ECMAScript and implements many web platform features.

It's built on the shoulders of giants: it uses QuickJS-ng as its JavaScript engine and libuv as the platform layer.

See it in action here:

Building a tiny JavaScript runtime with QuickJS

Getting started

First head over to building and build the runtime.

$ ./build/tjs eval "console.log('hello world')"
hello world
$

If you want to run a script you can use tjs run:

$ ./build/tjs run examples/hello_world.js
hello world
$

Explore all the options:

$ ./build/tjs --help

For TS support see @txikijs/types.

Features

Support for the ES2023 specification (almost complete).

Web Platform APIs

(1): All of them are async.

(2): No subtle support.

(3): No tables, globals or memory support.

Runtime features

  • TCP and UDP sockets
  • Unix sockets / named pipes
  • Signal handling
  • File operations
  • Child processes
  • DNS (getaddrinfo)
  • WASI
  • Miscellaneous utility functions

See the full API documentation.

Other extras:

  • Import directly from HTTP(S) URLs
  • Import JSON files
  • Builtin test runner

Standard library

The following modules compose the standard library:

Supported platforms

  • GNU/Linux
  • macOS
  • Windows (beta)
  • Other Unixes (please test!)

Building

CMake is necessary.

NOTE: The txiki.js build depends on a number of git submodules (libffi, libuv and wasm3). If you didn't already clone this repository recursively, make sure you initialize these submodules with git submodule update --init before proceeding to the build.

GNU/Linux

Install dependencies (libcurl, build-essential, cmake, makeinfo, autoreconf, libtool):

# On Debian / Ubuntu
sudo apt install libcurl4-openssl-dev build-essential cmake autoconf texinfo libtool

macOS

Install dependencies (cmake, autoconf):

brew install cmake autoconf automake libtool texinfo

Unix systems

# Get the code
git clone --recursive https://github.com/saghul/txiki.js --shallow-submodules && cd txiki.js
# Compile it!
make
# Run the REPL
./build/tjs

Windows (beta)

Windows support it's currently considered beta. Tests do pass, but building it is not as easy as it should be.

Building has only been tested in 64bit Windows.

Prerequisites

First make sure you have MSYS2 installed. The mingw64 and clang64 environments are currently tested.

Then install the required dependencies:

pacman -S git make pactoys
pacboy -S curl-winssl:p toolchain:p cmake:p ninja:p

Build

These commands must be run in a MinGW64 or clang64 shell.

make

This will build the executable just like on Unix. Note that at this point there are a number of dynamically linked libraries, so if you want to use the executable on a different system you'll need to copy those too. Check the list with ldd build/tjs.exe.

Running the tests

Make sure these commands are run from Windows Terminal (mintty, what MSYS2 provides is not supported).

make test

Versioning

At this time txiki.js uses calendar versioning with the form YY.MM.MICRO.



Built with ❤️ by saghul and these awesome contributors.

txiki.js's People

Contributors

bnoordhuis avatar dependabot[bot] avatar doodlewind avatar guest271314 avatar humphd avatar itsthewhale avatar jimmywarting avatar johnrobinsn avatar juanarbol avatar lal12 avatar lmangani avatar lulzx avatar rickyes avatar saghul avatar samuelbrian avatar stevefan1999-personal avatar sxs7513 avatar tbmale avatar thebrokenrail avatar vladimyr avatar vr5 avatar zeromake avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

txiki.js's Issues

Top level await

Hi,

One killer feature for simple scripting could be top level await.

Currently, top level await isn't supported by either quickjs or txiki.js, I can't tell for sure.

Failed to link on linux

[ 11%] Built target qjs
[ 25%] Built target m3
make[3]: Entering directory '/home/me/src/txiki.js/build'
[ 68%] Built target uv_a
make[3]: Leaving directory '/home/me/src/txiki.js/build'
[ 71%] Built target qjsc
make[3]: Entering directory '/home/me/src/txiki.js/build'
make[3]: Leaving directory '/home/me/src/txiki.js/build'
make[3]: Entering directory '/home/me/src/txiki.js/build'
[ 72%] Linking C executable tjs
/usr/bin/ld: CMakeFiles/tjs.dir/src/wasm.c.o: in function `tjs_wasm_linkwasi':
wasm.c:(.text+0x88f): undefined reference to `m3_LinkWASI'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/tjs.dir/build.make:443: tjs] Error 1
make[3]: Leaving directory '/home/me/src/txiki.js/build'
make[2]: *** [CMakeFiles/Makefile2:187: CMakeFiles/tjs.dir/all] Error 2
make[2]: Leaving directory '/home/me/src/txiki.js/build'
make[1]: *** [Makefile:149: all] Error 2
make[1]: Leaving directory '/home/me/src/txiki.js/build'
make: *** [Makefile:9: build] Error 2

qjsc-like compiler

Would it be possible to have a qjsc-like compiler built into txiki that would allow bundling user code with the txiki runtime?

Disable WASM

Hi,

Maybe I'm missing something, but shouldn't the line 128 of bootstrap.c be

#ifndef DISABLE_WASM
    CHECK_EQ(0, tjs__eval_binary(ctx, wasm, wasm_size));
#endif

?

Native module not working on Linux

I've got a very simple example with a JS file importing a native module (shared object).

It works fine under qjs but fails under tjs interpreter.

The .so file is exporting a couple of functions, and I can call them fine with qjs, so this seems to be strictly an issue with tjs.

JS file:

import * as test from "./libtest.so";

Output:

SyntaxError: unexpected token in expression: ''
    at libtest.so:1

Any idea where it's going wrong?

TypeError redirecting stdout?

▲ cat hello.js
console.log('heyoooo')

▲ txiki.js/build/tjs hello.js
heyoooo

▲ txiki.js/build/tjs hello.js > output.log
TypeError: cannot read property 'write' of undefined
    at print (bundle.js:12858)
    at log (bundle.js:12934)
    at <anonymous> (test.js:1)

▲ txiki.js/build/tjs --version
v22.2.1

Add deno style api support for stream API

For Deno and Tjs(js engine quickjs) both support ES6, Tjs actually could leverage Deno third modules(via Deno bundle
e.g Buffer(https://deno.land/x/buffer)

cat test.js
import { Buffer } from "http://deno.land/x/node_buffer/index.ts";
export { Buffer }

deno bundle test.js >buffer.js
then
tjs could just use this deno third module (with provide node style buffer)

The inconvenience part come when leverage http/mqtt moudle(https://deno.land/x/deno_http_server) which depends on(Deno.accept,listen, read and write), most of these API tjs have according implementation
For read the inconvenience part is that Deno use conn.read(Buffer object) vs await data = conn.read([length])

so far i just use following WR, in js side

function toDenoRead(originRead) {
    return async function(buffer) {
        return originRead(buffer.length).then((data) => {
            data.forEach((item, index) => {
                buffer[index] = item;
            });
            return data.length;
        });
    };
}

TjsDeno.connect = async function(options) {
    let {hostname, port} = options;
    const t = new tjs.TCP();

    await t.connect({ip: hostname, port});
    let originRead = t.read.bind(t);
    t.read = toDenoRead(originRead);

    return t;
}

This WR could work but not efficiently,
I think it would be great if tjs could support Deno style stream API natively, then user could leverage Deno modules easily in Tjs land.

Redis library? Postgres?

Are you aware of any common libraries for these types of services compatible with QuickJS/txiki.hs?

How to use it?

I want to build a binary. but I dont know how to do it. qjsc -o doest not give me binary.
so how to use txiki.js?

building on windows

i encounter this error:

make

cd build; cmake ../ -DCMAKE_BUILD_TYPE=Release
-- Building for: NMake Makefiles
-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:3 (project):
The CMAKE_C_COMPILER:

cl

is not a full path and was not found in the PATH.

To use the NMake generator with Visual C++, cmake must be run from a shell
that can use the compiler cl from the command line. This environment is
unable to invoke the cl compiler. To fix this problem, run cmake from the
Visual Studio Command Prompt (vcvarsall.bat).

Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.

-- Configuring incomplete, errors occurred!
See also "C:/Users/Administrator/Desktop/qjs/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/Administrator/Desktop/qjs/build/CMakeFiles/CMakeError.log".

repl: ^D leaves console in raw mode

$ ./quv 
Welcome to quv — QuickJS + libuv
Type "\h" for help
> ^D
^D

The first ^D does nothing (or does it?), the second one terminates the process but leaves the console in raw mode.

Build fails on Windows

Hi, I'm following Windows.md - yet my build fails.

pcktm@pcktmpc MSYS /c/Users/pcktm/gitclone/txiki.js
$ make
cd build; cmake ../ -DCMAKE_BUILD_TYPE=Release
-- Building in Release mode
-- Building with GNU 9.1.0 on MSYS-3.0.7-338.x86_64
-- Build mode: Release
-- Compiler type GNU: /usr/bin/c++.exe
--   DISABLE_CURL: OFF
--   USE_SYSTEM_CURL: ON
-- Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR)
-- Not using system Curl, using built-in curl project instead.
CMake Warning at deps/curl/CMakeLists.txt:50 (message):
  the curl cmake build system is poorly maintained.  Be aware


-- curl version=[7.65.3-DEV]
-- Performing Test OPT-Wstrict-aliasing=3
-- Performing Test OPT-Wstrict-aliasing=3 - Success
CMake Warning at deps/curl/CMake/Macros.cmake:86 (message):
  Found no *nroff program
Call Stack (most recent call first):
  deps/curl/CMakeLists.txt:202 (curl_nroff_check)


CMake Error at /usr/share/cmake-3.15.5/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
  system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY
  OPENSSL_INCLUDE_DIR)
Call Stack (most recent call first):
  /usr/share/cmake-3.15.5/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.15.5/Modules/FindOpenSSL.cmake:413 (find_package_handle_standard_args)
  deps/curl/CMakeLists.txt:347 (find_package)


-- Configuring incomplete, errors occurred!
See also "/c/Users/pcktm/gitclone/txiki.js/CMakeFiles/CMakeOutput.log".
See also "/c/Users/pcktm/gitclone/txiki.js/CMakeFiles/CMakeError.log".
make: *** [Makefile:8: build] Błąd 1

I tried installing openssl via Pacman in MSYS but, unfortunately, I haven't been able to figure out a solution.

readFile('/dev/stdin')

I could not read /dev/stdin with the fs.readFile call, so I had to write my own. Is this intended behavior?

$ echo hithere | tjs readfile.js
hithere

Unhandled promise rejection: Error: invalid seek
    at <anonymous> (readfile.js:18)
#!tjs
async function readFile(filename='/dev/stdin') {
  const buffer = new ArrayBuffer(1024)

  const handle = await tjs.fs.open(filename, 'r')
  let string = ''
  let data = await handle.read(buffer.length)
  while (data.length) {
    string += new TextDecoder().decode(data)
    data = await handle.read(buffer.length)
  }
  return string
}

(async () => {
  console.log(await readFile('/dev/stdin')) 
  console.log(await tjs.fs.readFile('/dev/stdin'))
})()

How do i compile this to emscripen?

Your library seems to include fetch and many other things that existing ones do not have out of the box.

How could one use this project with emscripten / generate a JS file alongside a single .wasm file

That would allow me to instantiate this in a client / existing server via require() and pass evalCode into the wasm module

Update Wasm3, make use of exciting new API

With latest Wasm3 (master branch), new API is available which fixes many things in the public API:

  • Exported function signature introspection
  • Introspection of imported functions (see context argument)
  • Public api for calls with raw arguments (instead of strings)
  • Public API to get return values
  • Support recursive m3_Call invocation. I.e. calling exported function from within imported function callback.
  • m3_RunStart can be used to force the module initialization.

I think all this can greatly help txiki.js implementation. Let me know it you need any other public API, or have any ideas!

This is already implemented in Python bindings, you can use it as a reference:
https://github.com/wasm3/wasm3/blob/master/platforms/python/m3module.c
Tests (in Python):
https://github.com/wasm3/wasm3/blob/master/platforms/python/test/test_m3.py

Unify pipe names on posixes and windows

I believe it makes sense to unify pipe names use on Windows and Linuxes.

On all platforms pipe names are file names but having special locations.

The function compose_pipe_name below does pipe name composition in platform independent manner.

And so updated tjs_pipe_connect and tjs_pipe_bind:

static char* compose_pipe_name(const char* logical_pipe_name, char* buf, size_t len)
{
#ifdef _WIN32
  strcpy(buf, "\\\\.\\pipe\\");
  strncat(buf, logical_pipe_name, len - 10);
#else
  strcpy(buf,"/tmp/");
  strncat(buf, logical_pipe_name, len - 6);
#endif
  return buf;
}

static JSValue tjs_pipe_connect(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
    TJSStream *t = tjs_pipe_get(ctx, this_val);
    if (!t)
        return JS_EXCEPTION;

    const char *name = JS_ToCString(ctx, argv[0]);
    if (!name)
        return JS_EXCEPTION;

    TJSConnectReq *cr = js_malloc(ctx, sizeof(*cr));
    if (!cr) {
        JS_FreeCString(ctx, name);
        return JS_EXCEPTION;
    }
    cr->req.data = cr;

    char buf[512];

    uv_pipe_connect(&cr->req, &t->h.pipe, compose_pipe_name(name,buf,countof(buf)), uv__stream_connect_cb);

    JS_FreeCString(ctx, name);

    return TJS_InitPromise(ctx, &cr->result);
}

static JSValue tjs_pipe_bind(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
    TJSStream *t = tjs_pipe_get(ctx, this_val);
    if (!t)
        return JS_EXCEPTION;

    const char *name = JS_ToCString(ctx, argv[0]);
    if (!name)
        return JS_EXCEPTION;

    char buf[512];

    int r = uv_pipe_bind(&t->h.pipe, compose_pipe_name(name, buf, countof(buf)));
    if (r != 0)
        return tjs_throw_errno(ctx, r);

    return JS_UNDEFINED;
}

Add cross compile support

Could add cross compile support to make tjs could run on more platfrom

so far crossed build target (e.g arm) tjs on X86 depends on run qjsc on host. For qjsc is build from arm in this case, which stop the next build step.

RPC-FFI-like interop when embedding into a shared library

mildly related to https://github.com/saghul/txiki.js/pull/179/files

image

It's pretty clear that TJS_Run is most likely a blocking call. That's fine. You can get around that by putting TJS on its own thread.

My question to you is, how could the native calling code (for example a Win32 DLL in DllMain) interact with the TJS runtime? How could messages be passed to and from? Obviously you can do things like named pipes, shared memory, a queue, etc. but I'm looking if it's possible to inject events.

struct TJSRuntime {
    TJSRunOptions options;
    JSRuntime *rt;
    JSContext *ctx;

Is there any easy way to pass messages from the QuickJS runtime/context into native code, and back from native code into QuickJS runtime?

N-API support.

Many existing Node native addons are written in N-API which is engine agnostic. How about adding N-API support to txiki.js?

graceful exit after using accept()

Hello,

Once I compiled quickjs with DEBUG mode, below my test code encountered assert().
I doubted it looks from tjs_stream_accept(). But I have no idea for fixing it.
Or is there any example for graceful exit for tcp server.

$ ./build/tjs examples/echo-server.js
Listening on 127.0.0.1:1234
Object leaks:
       ADDRESS REFS SHRF          PROTO      CLASS PROPS
0x560049cdf150    1   0* 0x560049c282c0 PromiseResolveFunction { length: 1, name: 243'' }
0x560049cdf890    1   0* 0x560049c282c0 PromiseRejectFunction { length: 1, name: 243'' }
tjs: /home/junsik/WORK/junsik/txiki.js/deps/quickjs/src/quickjs.c:1911: JS_FreeRuntime: Assertion `list_empty(&rt->gc_obj_list)' failed.
Aborted (core dumped)

Here is my test code.

diff --git a/deps/libuv b/deps/libuv
index e45f1ec..8aa5636 160000
--- a/deps/libuv
+++ b/deps/libuv
@@ -1 +1 @@
-Subproject commit e45f1ec38db882f8dc17b51f51a6684027034609
+Subproject commit 8aa5636ec72990bb2856f81e14c95813024a5c2b
diff --git a/deps/quickjs/CMakeLists.txt b/deps/quickjs/CMakeLists.txt
index 2681f70..aaeb697 100644
--- a/deps/quickjs/CMakeLists.txt
+++ b/deps/quickjs/CMakeLists.txt
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.4)

 project(quickjs LANGUAGES C)

+set(CMAKE_BUILD_TYPE Debug)
 set(qjs_cflags -Wall)
 if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang")
     list(APPEND qjs_cflags
diff --git a/examples/echo-server.js b/examples/echo-server.js
index 49df46d..6130c66 100644
--- a/examples/echo-server.js
+++ b/examples/echo-server.js
@@ -39,8 +39,14 @@ async function handleConnection(conn) {

     console.log(`Listening on ${addr(t.getsockname())}`);

+    let running = true;
+    setTimeout(() => {
+        t.close();
+        running = false;
+    }, 5000);
+
     let conn;
-    while (true) {
+    while (running) {
         conn = await t.accept();
         handleConnection(conn);
         conn = undefined;

compile error

I compiled this project on

Linux node 4.18.0-25-generic #26~18.04.1-Ubuntu SMP Thu Jun 27 07:28:31 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

and got the infot:

[ 86%] Linking C executable qjsc
CMakeFiles/qjs_obj.dir/src/quickjs.c.o: In function `JS_ComputeMemoryUsage':
/home/ie/software/qjsuv/src/quickjs.c:5589: undefined reference to `round'
/home/ie/software/qjsuv/src/quickjs.c:5590: undefined reference to `round'
/home/ie/software/qjsuv/src/quickjs.c:5591: undefined reference to `round'
/home/ie/software/qjsuv/src/quickjs.c:5592: undefined reference to `round'
/home/ie/software/qjsuv/src/quickjs.c:5593: undefined reference to `round'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:/home/ie/software/qjsuv/src/quickjs.c:5594: more undefined references to `round' follow
CMakeFiles/qjs_obj.dir/src/quickjs.c.o: In function `js_fmin':
/home/ie/software/qjsuv/src/quickjs.c:37443: undefined reference to `fmin'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o: In function `js_fmax':
/home/ie/software/qjsuv/src/quickjs.c:37457: undefined reference to `fmax'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o: In function `JS_ToUint8ClampFree':
/home/ie/software/qjsuv/src/quickjs.c:9759: undefined reference to `lrint'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o: In function `js_math_hypot':
/home/ie/software/qjsuv/src/quickjs.c:37911: undefined reference to `hypot'
/home/ie/software/qjsuv/src/quickjs.c:37919: undefined reference to `sqrt'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o: In function `js_pow':
/home/ie/software/qjsuv/src/quickjs.c:10658: undefined reference to `pow'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o: In function `js_binary_arith_slow':
/home/ie/software/qjsuv/src/quickjs.c:11613: undefined reference to `fmod'
/home/ie/software/qjsuv/src/quickjs.c:11617: undefined reference to `fmod'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o: In function `js_pow':
/home/ie/software/qjsuv/src/quickjs.c:10658: undefined reference to `pow'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o: In function `js_binary_arith_slow':
/home/ie/software/qjsuv/src/quickjs.c:11460: undefined reference to `fmod'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o: In function `js_pow':
/home/ie/software/qjsuv/src/quickjs.c:10658: undefined reference to `pow'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x78): undefined reference to `floor'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x98): undefined reference to `ceil'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0xd8): undefined reference to `sqrt'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0xf8): undefined reference to `acos'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x118): undefined reference to `asin'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x138): undefined reference to `atan'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x158): undefined reference to `atan2'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x178): undefined reference to `cos'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x198): undefined reference to `exp'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x1b8): undefined reference to `log'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x1f8): undefined reference to `sin'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x218): undefined reference to `tan'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x238): undefined reference to `trunc'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x278): undefined reference to `cosh'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x298): undefined reference to `sinh'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x2b8): undefined reference to `tanh'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x2d8): undefined reference to `acosh'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x2f8): undefined reference to `asinh'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x318): undefined reference to `atanh'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x338): undefined reference to `expm1'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x358): undefined reference to `log1p'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x378): undefined reference to `log2'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x398): undefined reference to `log10'
CMakeFiles/qjs_obj.dir/src/quickjs.c.o:(.data.rel.ro+0x3b8): undefined reference to `cbrt'
collect2: error: ld returned 1 exit status
CMakeFiles/qjsc.dir/build.make:104: recipe for target 'qjsc' failed
make[3]: *** [qjsc] Error 1
make[3]: Leaving directory '/home/ie/software/qjsuv/build'
CMakeFiles/Makefile2:143: recipe for target 'CMakeFiles/qjsc.dir/all' failed
make[2]: *** [CMakeFiles/qjsc.dir/all] Error 2
make[2]: Leaving directory '/home/ie/software/qjsuv/build'
Makefile:129: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/home/ie/software/qjsuv/build'
Makefile:13: recipe for target 'build' failed
make: *** [build] Error 2

please help me! :-)

object leaks

(async () => {
const res = await fetch('http://www.baidu.com');
console.log(res);
})();

quv: ./quv/deps/quickjs/src/quickjs.c:1643: JS_FreeRuntime: Assertion `list_empty(&rt->obj_list)' failed.

[Idea Discussion] Plugins/Packages/Modules

Thinking in adding some module/package manager like support using libuv shared library handling and a build system like Ruby extensions or FFI like, i created a C wrapper for uWebSockets and want to add in txiki.js, but i want to create a more generic way to add packages or extensions because i plan to add, redis and postgres too.
http://docs.libuv.org/en/v1.x/dll.html

Proposal:
JSON file like gems:

{
    "packages": {
        "uws": {
            "git": "https://github.com/cirospaciari/uWebSockets.qjs.git",
            "branch": "v1.0", 
            "submodules": true
        }
    }
}

short version:

{
    "packages": {
        "uws": "github://cirospaciari/uWebSockets.qjs?branch=v1.0&submodules=true"
    }
}

Usage:

import { App } from  "uws";

App.new()
.get("/", (response, request)=> response.end("Hello World!"))
.listen(8082, (config)=>  console.log(`Listening on port ${config.port}`))
.run();

In this case adding the package will clone with submodules, call a make file with can use tcc, clang, gcc or mingw to generate an .so, .dll or .dylib, and at runtime using the libuv uv_dlsym we can call/register the module/extension (and cache)

folder for the packages/ files:
modules -> uws -> index.js, uws.so, tmp (temp folder for build)

A package manager could generate the index.js + libuv calls and modifying the import to lookup at modules folder to the index.js file

Fix of crash in async functions that throw unhandled errors

This change will fix crash on this code:

  async showDir() {
    let list = await sys.fs.readdir("non existent path");
    for await (const file of list) 
      console.log(file);
  } 

Note that this code

  async showDir() {
    try {
      let list = await sys.fs.readdir("non existent path");
      for await (const file of list) 
        console.log(file);
    } catch(e) {  }
  } 

works OK.

Performant HTTP server

While I doubt nobody is rushing to run this in production, I am also going to bet that:

let conn;
while (true) {
    conn = await t.accept();
    handleConnection(conn);
    conn = undefined;
}

won't lead to the most performant approach to serving HTTP requests.

What are your thoughts on putting epoll or kqueue or select or something? How does libuv achieve this for servers?

Windows MSVC build

Hello,

Would be possible to use MSVC for compiling binaries for Windows?

In my QuickJS repo, I ported most of the things for MSVC, so it should work. Here is list of things which works.

libuv handle lifecycle

Let me know if there is a better place to ask this... or discuss...

Currently the libuv (loop) manages the lifecycle of a set of uv handles. In txiki.js a loop is bound to the runtime rather than to a context. if contexts are allowed to be dynamically started and shutdown (maybe for an iframe like construct in a UI runtime). what's the best way to cleanly shutdown handles (timers, outstanding connections etc) that are scoped to a single context. Right now it seems a bit awkward given that the loop is held at the runtime level. I have a workaround now that seems to work OK for now... but would appreciate other thoughts on how best to manage.

Issue on Async Running Sequence

It seems that txiki's event loop doesn't follow the microtask / macrotask concepts strictly. For example:

console.log('Hello')

setTimeout(() => console.log('!'), 0)

Promise.resolve().then(() => console.log('World'))

This snippet has following output in Chrome's console and qjs:

Hello
World
!

Since Promise.then returns a microtask, and if my understanding is correct, it should be executed by JS_ExecutePendingJob synchronously right after each eval. So the log from Promise.then comes before the one from setTimeout.

While in txiki I got following output:

Hello
!
World

Currently microtasks are triggered by uv_check after each tick, while after the first time we eval the script, there isn't corresponding JS_ExecutePendingJob calls, so the Promise's microtask is kept until next tick's check phase in setTimeout's macrotask, which makes the difference in running sequence.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.