-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
utils: add helper to create a Uint8Array while copying the data
- Loading branch information
Showing
2 changed files
with
14 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
|
||
/* | ||
* QuickJS libuv bindings | ||
* txiki.js | ||
* | ||
* Copyright (c) 2019-present Saúl Ibarra Corretgé <[email protected]> | ||
* | ||
|
@@ -271,6 +270,17 @@ JSValue TJS_NewUint8Array(JSContext *ctx, uint8_t *data, size_t size) { | |
return buf; | ||
} | ||
|
||
JSValue TJS_NewUint8ArrayCopy(JSContext *ctx, uint8_t *data, size_t size) { | ||
JSValue abuf = JS_NewArrayBufferCopy(ctx, data, size); | ||
if (JS_IsException(abuf)) | ||
return abuf; | ||
TJSRuntime *qrt = TJS_GetRuntime(ctx); | ||
CHECK_NOT_NULL(qrt); | ||
JSValue buf = JS_CallConstructor(ctx, qrt->builtins.u8array_ctor, 1, &abuf); | ||
JS_FreeValue(ctx, abuf); | ||
return buf; | ||
} | ||
|
||
JSValue TJS_NewDate(JSContext *ctx, double epoch_ms) { | ||
TJSRuntime *qrt = TJS_GetRuntime(ctx); | ||
CHECK_NOT_NULL(qrt); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* QuickJS libuv bindings | ||
* txiki.js | ||
* | ||
* Copyright (c) 2019-present Saúl Ibarra Corretgé <[email protected]> | ||
* | ||
|
@@ -122,6 +122,7 @@ JSValue TJS_NewResolvedPromise(JSContext *ctx, int argc, JSValueConst *argv); | |
JSValue TJS_NewRejectedPromise(JSContext *ctx, int argc, JSValueConst *argv); | ||
|
||
JSValue TJS_NewUint8Array(JSContext *ctx, uint8_t *data, size_t size); | ||
JSValue TJS_NewUint8ArrayCopy(JSContext *ctx, uint8_t *data, size_t size); | ||
JSValue TJS_NewDate(JSContext *ctx, double epoch_ms); | ||
|
||
extern const char *tjs_signal_map[]; | ||
|