Compare commits
4 Commits
4c3df34950
...
68590cae33
Author | SHA1 | Date | |
---|---|---|---|
68590cae33 | |||
abf2bbaec2 | |||
0da7e2722f | |||
60d4b06057 |
28
core/core.js
28
core/core.js
@ -7,18 +7,17 @@ let kPingInterval = 60 * 1000;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* TODOC
|
* TODOC
|
||||||
* @param {*} out
|
|
||||||
* @param {*} error
|
* @param {*} error
|
||||||
*/
|
*/
|
||||||
function printError(out, error) {
|
function printError(error) {
|
||||||
if (error.stackTrace) {
|
if (error.stackTrace) {
|
||||||
out.print(error.fileName + ':' + error.lineNumber + ': ' + error.message);
|
print(error.fileName + ':' + error.lineNumber + ': ' + error.message);
|
||||||
out.print(error.stackTrace);
|
print(error.stackTrace);
|
||||||
} else {
|
} else {
|
||||||
for (let [k, v] of Object.entries(error)) {
|
for (let [k, v] of Object.entries(error)) {
|
||||||
out.print(k, v);
|
print(k, v);
|
||||||
}
|
}
|
||||||
out.print(error.toString());
|
print(error.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -461,10 +460,10 @@ async function getProcessBlob(blobId, key, options) {
|
|||||||
if (process.app) {
|
if (process.app) {
|
||||||
process.app.makeFunction(['error'])(error);
|
process.app.makeFunction(['error'])(error);
|
||||||
} else {
|
} else {
|
||||||
printError({print: print}, error);
|
printError(error);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
printError({print: print}, error);
|
printError(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
imports.ssb = Object.fromEntries(
|
imports.ssb = Object.fromEntries(
|
||||||
@ -660,6 +659,7 @@ async function getProcessBlob(blobId, key, options) {
|
|||||||
);
|
);
|
||||||
return process.sendPermissions();
|
return process.sendPermissions();
|
||||||
};
|
};
|
||||||
|
ssb.registerImports(imports, process);
|
||||||
process.task.setImports(imports);
|
process.task.setImports(imports);
|
||||||
process.task.activate();
|
process.task.activate();
|
||||||
let source = await ssb.blobGet(blobId);
|
let source = await ssb.blobGet(blobId);
|
||||||
@ -686,7 +686,7 @@ async function getProcessBlob(blobId, key, options) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
printError({print: print}, e);
|
printError(e);
|
||||||
}
|
}
|
||||||
broadcastEvent('onSessionBegin', [getUser(process, process)]);
|
broadcastEvent('onSessionBegin', [getUser(process, process)]);
|
||||||
if (process.app) {
|
if (process.app) {
|
||||||
@ -700,14 +700,10 @@ async function getProcessBlob(blobId, key, options) {
|
|||||||
sendStats();
|
sendStats();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (process.app) {
|
if (process?.app && process?.task?.onError) {
|
||||||
if (process?.task?.onError) {
|
process.task.onError(error);
|
||||||
process.task.onError(error);
|
|
||||||
} else {
|
|
||||||
printError({print: print}, error);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
printError({print: print}, error);
|
printError(error);
|
||||||
}
|
}
|
||||||
rejectReady(error);
|
rejectReady(error);
|
||||||
}
|
}
|
||||||
|
19
src/api.js.c
Normal file
19
src/api.js.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "api.js.h"
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
#include <quickjs.h>
|
||||||
|
|
||||||
|
static JSValue _tf_api_register_imports(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||||
|
{
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tf_api_register(JSContext* context)
|
||||||
|
{
|
||||||
|
JSValue global = JS_GetGlobalObject(context);
|
||||||
|
JSValue ssb = JS_GetPropertyStr(context, global, "ssb");
|
||||||
|
JS_SetPropertyStr(context, ssb, "registerImports", JS_NewCFunction(context, _tf_api_register_imports, "registerImports", 2));
|
||||||
|
JS_FreeValue(context, ssb);
|
||||||
|
JS_FreeValue(context, global);
|
||||||
|
}
|
18
src/api.js.h
Normal file
18
src/api.js.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
** \defgroup api_js JS API
|
||||||
|
** Functions that are ultimately exposed to apps.
|
||||||
|
** @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** A JS context. */
|
||||||
|
typedef struct JSContext JSContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
** Register JS API functions.
|
||||||
|
** @param context The JS context.
|
||||||
|
*/
|
||||||
|
void tf_api_register(JSContext* context);
|
||||||
|
|
||||||
|
/** @} */
|
13
src/http.c
13
src/http.c
@ -84,6 +84,7 @@ typedef struct _tf_http_listener_t
|
|||||||
typedef struct _tf_http_t
|
typedef struct _tf_http_t
|
||||||
{
|
{
|
||||||
bool is_shutting_down;
|
bool is_shutting_down;
|
||||||
|
bool is_in_destroy;
|
||||||
|
|
||||||
tf_http_listener_t** listeners;
|
tf_http_listener_t** listeners;
|
||||||
int listeners_count;
|
int listeners_count;
|
||||||
@ -395,7 +396,7 @@ static void _http_add_body_bytes(tf_http_connection_t* connection, const void* d
|
|||||||
|
|
||||||
if (fin)
|
if (fin)
|
||||||
{
|
{
|
||||||
if (connection->request->on_message)
|
if (connection->request && connection->request->on_message)
|
||||||
{
|
{
|
||||||
tf_trace_begin(connection->http->trace, connection->trace_name ? connection->trace_name : "websocket");
|
tf_trace_begin(connection->http->trace, connection->trace_name ? connection->trace_name : "websocket");
|
||||||
connection->request->on_message(connection->request, connection->fragment_length ? connection->fragment_op_code : op_code,
|
connection->request->on_message(connection->request, connection->fragment_length ? connection->fragment_op_code : op_code,
|
||||||
@ -786,7 +787,13 @@ static void _http_free_listener_on_close(uv_handle_t* handle)
|
|||||||
|
|
||||||
void tf_http_destroy(tf_http_t* http)
|
void tf_http_destroy(tf_http_t* http)
|
||||||
{
|
{
|
||||||
|
if (http->is_in_destroy)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
http->is_shutting_down = true;
|
http->is_shutting_down = true;
|
||||||
|
http->is_in_destroy = true;
|
||||||
|
|
||||||
for (int i = 0; i < http->connections_count; i++)
|
for (int i = 0; i < http->connections_count; i++)
|
||||||
{
|
{
|
||||||
@ -845,6 +852,10 @@ void tf_http_destroy(tf_http_t* http)
|
|||||||
|
|
||||||
tf_free(http);
|
tf_free(http);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
http->is_in_destroy = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* tf_http_status_text(int status)
|
const char* tf_http_status_text(int status)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "task.h"
|
#include "task.h"
|
||||||
|
|
||||||
|
#include "api.js.h"
|
||||||
#include "bcrypt.js.h"
|
#include "bcrypt.js.h"
|
||||||
#include "database.js.h"
|
#include "database.js.h"
|
||||||
#include "file.js.h"
|
#include "file.js.h"
|
||||||
@ -1697,6 +1698,7 @@ void tf_task_activate(tf_task_t* task)
|
|||||||
task->_ssb = tf_ssb_create(&task->_loop, task->_context, task->_db_path, task->_network_key);
|
task->_ssb = tf_ssb_create(&task->_loop, task->_context, task->_db_path, task->_network_key);
|
||||||
tf_ssb_set_trace(task->_ssb, task->_trace);
|
tf_ssb_set_trace(task->_ssb, task->_trace);
|
||||||
tf_ssb_register(context, task->_ssb);
|
tf_ssb_register(context, task->_ssb);
|
||||||
|
tf_api_register(context);
|
||||||
tf_ssb_set_hitch_callback(task->_ssb, _tf_task_record_hitch, task);
|
tf_ssb_set_hitch_callback(task->_ssb, _tf_task_record_hitch, task);
|
||||||
|
|
||||||
if (task->_args)
|
if (task->_args)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user