1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-14 23:33:38 +00:00

1. fixed bug, where return value was set incorrectly when calling _write

2. updated behavior, so if unshift is called with zero length buffer, it is a no-op
This commit is contained in:
Bryan Roe
2019-01-28 10:42:20 -08:00
parent 559928de5b
commit ba4028d2d6
2 changed files with 12 additions and 4 deletions

View File

@@ -402,6 +402,7 @@ duk_ret_t ILibDuktape_Polyfills_Buffer_alloc(duk_context *ctx)
duk_push_buffer_object(ctx, -1, 0, sz, DUK_BUFOBJ_NODEJS_BUFFER);
return(1);
}
void ILibDuktape_Polyfills_Buffer(duk_context *ctx)
{
char extras[] =
@@ -438,7 +439,6 @@ void ILibDuktape_Polyfills_Buffer(duk_context *ctx)
duk_push_c_function(ctx, ILibDuktape_Polyfills_Buffer_toString, DUK_VARARGS); // [g][Buffer][prototype][func]
duk_put_prop_string(ctx, -2, "toString"); // [g][Buffer][prototype]
duk_pop_2(ctx); // [g]
}
duk_ret_t ILibDuktape_Polyfills_String_startsWith(duk_context *ctx)
{
@@ -1487,7 +1487,7 @@ ILibTransport_DoneState ILibDuktape_Stream_Writable_WriteSink(struct ILibDuktape
duk_push_this(stream->ctx); // [writable]
duk_get_prop_string(stream->ctx, -1, "_write"); // [writable][_write]
duk_swap_top(stream->ctx, -2); // [_write][this]
if (stream->Reserved)
if (stream->Reserved == 0)
{
duk_push_external_buffer(stream->ctx); // [_write][this][extBuffer]
duk_insert(stream->ctx, -3); // [extBuffer][_write][this]
@@ -1512,6 +1512,10 @@ ILibTransport_DoneState ILibDuktape_Stream_Writable_WriteSink(struct ILibDuktape
{
ILibDuktape_Process_UncaughtExceptionEx(stream->ctx, "stream.writable.write(): "); retVal = ILibTransport_DoneState_ERROR;
}
else
{
retVal = duk_to_boolean(stream->ctx, -1) ? ILibTransport_DoneState_COMPLETE : ILibTransport_DoneState_INCOMPLETE;
}
duk_pop(stream->ctx); // ...
duk_push_heapptr(stream->ctx, h); // [callback]

View File

@@ -910,8 +910,12 @@ duk_ret_t ILibDuktape_ReadableStream_unshift(duk_context *ctx)
else
{
duk_size_t bufferLen;
rs->unshiftReserved = (char*)Duktape_GetBuffer(ctx, 0, &bufferLen);
duk_push_int(ctx, rs->UnshiftHandler(rs, (int)bufferLen, rs->user));
char *unshiftBuffer = (char*)Duktape_GetBuffer(ctx, 0, &bufferLen);
if (bufferLen > 0)
{
rs->unshiftReserved = unshiftBuffer;
duk_push_int(ctx, rs->UnshiftHandler(rs, (int)bufferLen, rs->user));
}
return(1);
}
}