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
|
||||
* @param {*} out
|
||||
* @param {*} error
|
||||
*/
|
||||
function printError(out, error) {
|
||||
function printError(error) {
|
||||
if (error.stackTrace) {
|
||||
out.print(error.fileName + ':' + error.lineNumber + ': ' + error.message);
|
||||
out.print(error.stackTrace);
|
||||
print(error.fileName + ':' + error.lineNumber + ': ' + error.message);
|
||||
print(error.stackTrace);
|
||||
} else {
|
||||
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) {
|
||||
process.app.makeFunction(['error'])(error);
|
||||
} else {
|
||||
printError({print: print}, error);
|
||||
printError(error);
|
||||
}
|
||||
} catch (e) {
|
||||
printError({print: print}, error);
|
||||
printError(error);
|
||||
}
|
||||
};
|
||||
imports.ssb = Object.fromEntries(
|
||||
@ -660,6 +659,7 @@ async function getProcessBlob(blobId, key, options) {
|
||||
);
|
||||
return process.sendPermissions();
|
||||
};
|
||||
ssb.registerImports(imports, process);
|
||||
process.task.setImports(imports);
|
||||
process.task.activate();
|
||||
let source = await ssb.blobGet(blobId);
|
||||
@ -686,7 +686,7 @@ async function getProcessBlob(blobId, key, options) {
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
printError({print: print}, e);
|
||||
printError(e);
|
||||
}
|
||||
broadcastEvent('onSessionBegin', [getUser(process, process)]);
|
||||
if (process.app) {
|
||||
@ -700,14 +700,10 @@ async function getProcessBlob(blobId, key, options) {
|
||||
sendStats();
|
||||
}
|
||||
} catch (error) {
|
||||
if (process.app) {
|
||||
if (process?.task?.onError) {
|
||||
process.task.onError(error);
|
||||
} else {
|
||||
printError({print: print}, error);
|
||||
}
|
||||
if (process?.app && process?.task?.onError) {
|
||||
process.task.onError(error);
|
||||
} else {
|
||||
printError({print: print}, error);
|
||||
printError(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
|
||||
{
|
||||
bool is_shutting_down;
|
||||
bool is_in_destroy;
|
||||
|
||||
tf_http_listener_t** listeners;
|
||||
int listeners_count;
|
||||
@ -395,7 +396,7 @@ static void _http_add_body_bytes(tf_http_connection_t* connection, const void* d
|
||||
|
||||
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");
|
||||
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)
|
||||
{
|
||||
if (http->is_in_destroy)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
http->is_shutting_down = true;
|
||||
http->is_in_destroy = true;
|
||||
|
||||
for (int i = 0; i < http->connections_count; i++)
|
||||
{
|
||||
@ -845,6 +852,10 @@ void tf_http_destroy(tf_http_t* http)
|
||||
|
||||
tf_free(http);
|
||||
}
|
||||
else
|
||||
{
|
||||
http->is_in_destroy = false;
|
||||
}
|
||||
}
|
||||
|
||||
const char* tf_http_status_text(int status)
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "task.h"
|
||||
|
||||
#include "api.js.h"
|
||||
#include "bcrypt.js.h"
|
||||
#include "database.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);
|
||||
tf_ssb_set_trace(task->_ssb, task->_trace);
|
||||
tf_ssb_register(context, task->_ssb);
|
||||
tf_api_register(context);
|
||||
tf_ssb_set_hitch_callback(task->_ssb, _tf_task_record_hitch, task);
|
||||
|
||||
if (task->_args)
|
||||
|
Loading…
x
Reference in New Issue
Block a user