diff --git a/core/core.js b/core/core.js index c5799555..7887b30c 100644 --- a/core/core.js +++ b/core/core.js @@ -840,7 +840,11 @@ loadSettings().then(function() { return response.end(data); } else if (match = /^\/mem$/.exec(request.uri)) { let data = JSON.stringify(getAllocations(), null, 2); - response.writeHead(200, {"Content-Type": "application/json; charset=utf-8", "Content-Length": data.length.toString()}); + response.writeHead(200, { + "Content-Type": "application/json; charset=utf-8", + "Content-Length": data.length.toString(), + "Access-Control-Allow-Origin": "*", + }); return response.end(data); } else if (request.uri == "/robots.txt") { return blobHandler(request, response, null, request.uri); diff --git a/src/mem.c b/src/mem.c index 5fa68623..32585105 100644 --- a/src/mem.c +++ b/src/mem.c @@ -218,6 +218,11 @@ static void* _tf_alloc(int64_t* total, size_t size) static void* _tf_realloc(int64_t* total, void* ptr, size_t size) { + if (!ptr && !size) + { + return NULL; + } + void* buffer[32]; int count = 0; size_t overhead = sizeof(size_t); diff --git a/src/task.c b/src/task.c index fa725655..b7fac2b5 100644 --- a/src/task.c +++ b/src/task.c @@ -322,8 +322,10 @@ static const char* _task_loadFile(const char* fileName) JSValue _tf_task_exit(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) { tf_task_t* task = JS_GetContextOpaque(context); + tf_trace_begin(task->_trace, __func__); int exitCode = 0; JS_ToInt32(task->_context, &exitCode, argv[0]); + tf_trace_end(task->_trace); exit(exitCode); return JS_UNDEFINED; } @@ -628,7 +630,10 @@ JSValue _tf_task_get_parent(JSContext* context, JSValueConst this_val, int argc, static JSValue _tf_task_version(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) { tf_task_t* task = JS_GetContextOpaque(context); - return JS_NewString(task->_context, k_version); + tf_trace_begin(task->_trace, __func__); + JSValue result = JS_NewString(task->_context, k_version); + tf_trace_end(task->_trace); + return result; } exportid_t tf_task_export_function(tf_task_t* task, tf_taskstub_t* to, JSValue function) @@ -697,15 +702,18 @@ static JSValue _tf_task_trace(JSContext* context, JSValueConst this_val, int arg return JS_UNDEFINED; } + tf_trace_begin(task->_trace, __func__); char* trace = tf_trace_export(task->_trace); JSValue result = JS_NewString(context, trace); tf_free(trace); + tf_trace_end(task->_trace); return result; } static JSValue _tf_task_getStats(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) { tf_task_t* task = JS_GetContextOpaque(context); + tf_trace_begin(task->_trace, __func__); JSValue result = JS_NewObject(context); JS_SetPropertyStr(context, result, "child_count", JS_NewInt32(context, task->_child_count)); JS_SetPropertyStr(context, result, "import_count", JS_NewInt32(context, task->_import_count)); @@ -742,6 +750,7 @@ static JSValue _tf_task_getStats(JSContext* context, JSValueConst this_val, int JS_SetPropertyStr(context, result, "requests", JS_NewInt32(context, ssb_stats.request_count)); } + tf_trace_end(task->_trace); return result; } @@ -785,6 +794,7 @@ static void _tf_backtrace_error(void* data, const char* message, int error) static JSValue _tf_task_getDebug(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) { tf_task_t* task = JS_GetContextOpaque(context); + tf_trace_begin(task->_trace, __func__); JSValue result = JS_NewObject(context); JSValue promises = JS_NewArray(context); @@ -820,12 +830,14 @@ static JSValue _tf_task_getDebug(JSContext* context, JSValueConst this_val, int JS_SetPropertyUint32(context, promises, j++, entry); } } - + tf_trace_end(task->_trace); return result; } static JSValue _tf_task_getAllocations(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) { + tf_task_t* task = JS_GetContextOpaque(context); + tf_trace_begin(task->_trace, __func__); JSValue result = JS_NewObject(context); int count = 0; @@ -843,22 +855,28 @@ static JSValue _tf_task_getAllocations(JSContext* context, JSValueConst this_val tf_free((void*)stack); JS_SetPropertyUint32(context, allocations, i, allocation); } - + tf_free(allocation_info); + tf_trace_end(task->_trace); return result; } static JSValue _tf_task_disconnectionsDebug(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) { tf_task_t* task = JS_GetContextOpaque(context); - return tf_ssb_get_disconnection_debug(task->_ssb, context); + tf_trace_begin(task->_trace, __func__); + JSValue result = tf_ssb_get_disconnection_debug(task->_ssb, context); + tf_trace_end(task->_trace); + return result; } static JSValue _tf_task_getFile(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) { tf_task_t* task = JS_GetContextOpaque(context); + tf_trace_begin(task->_trace, __func__); const char* name = JS_ToCString(context, argv[0]); JSValue result = JS_GetPropertyStr(context, task->_loadedFiles, name); JS_FreeCString(context, name); + tf_trace_end(task->_trace); return result; } diff --git a/src/util.js.c b/src/util.js.c index ef1226ca..cf9246c0 100644 --- a/src/util.js.c +++ b/src/util.js.c @@ -312,6 +312,7 @@ static JSValue _util_sha1_digest(JSContext* context, JSValueConst this_val, int const char* value = JS_ToCStringLen(context, &length, argv[0]); unsigned char digest[SHA_DIGEST_LENGTH] = { 0 }; SHA1((const unsigned char*)value, length, digest); + JS_FreeCString(context, value); return JS_NewArrayBufferCopy(context, digest, sizeof(digest)); }