forked from cory/tildefriends
Move some things to C that probably should have never been in JS, especially sha1. Minor refactors, cleanup, and deletes along the way.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4154 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
@ -823,25 +823,13 @@ void _socket_onRead(uv_stream_t* stream, ssize_t readSize, const uv_buf_t* buffe
|
||||
JS_FreeValue(context, ref);
|
||||
}
|
||||
|
||||
static JSValue _newUint8Array(JSContext* context, const void* data, size_t length)
|
||||
{
|
||||
JSValue arrayBuffer = JS_NewArrayBufferCopy(context, (const uint8_t*)data, length);
|
||||
JSValue global = JS_GetGlobalObject(context);
|
||||
JSValue constructor = JS_GetPropertyStr(context, global, "Uint8Array");
|
||||
JSValue typedArray = JS_CallConstructor(context, constructor, 1, &arrayBuffer);
|
||||
JS_FreeValue(context, constructor);
|
||||
JS_FreeValue(context, global);
|
||||
JS_FreeValue(context, arrayBuffer);
|
||||
return typedArray;
|
||||
}
|
||||
|
||||
void _socket_notifyDataRead(socket_t* socket, const char* data, size_t length)
|
||||
{
|
||||
if (data && length > 0)
|
||||
{
|
||||
JSContext* context = tf_task_get_context(socket->_task);
|
||||
JSValue ref = JS_DupValue(context, socket->_object);
|
||||
JSValue typedArray = _newUint8Array(context, data, length);
|
||||
JSValue typedArray = tf_util_new_uint8_array(context, (const uint8_t*)data, length);
|
||||
JSValue args[] = { typedArray };
|
||||
if (!JS_IsUndefined(socket->_onRead))
|
||||
{
|
||||
@ -1072,7 +1060,7 @@ JSValue _socket_getPeerCertificate(JSContext* context, JSValueConst this_val, in
|
||||
int result = tf_tls_session_get_peer_certificate(socket->_tls, buffer, sizeof(buffer));
|
||||
if (result > 0)
|
||||
{
|
||||
return _newUint8Array(tf_task_get_context(socket->_task), buffer, sizeof(buffer));
|
||||
return tf_util_new_uint8_array(tf_task_get_context(socket->_task), (const uint8_t*)buffer, sizeof(buffer));
|
||||
}
|
||||
}
|
||||
return JS_UNDEFINED;
|
||||
|
Reference in New Issue
Block a user