Skip to content

Commit

Permalink
Optimized ngx_qjs_string().
Browse files Browse the repository at this point in the history
Doing JS_IsString() check first before a heavy-weight call to
JS_GetTypedArrayBuffer() which throws an exception when argument is not
a typed array.
  • Loading branch information
xeioex committed Oct 8, 2024
1 parent 30a9658 commit 3a4349e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions nginx/ngx_js.c
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,10 @@ ngx_qjs_string(ngx_engine_t *e, JSValueConst val, ngx_str_t *dst)

cx = e->u.qjs.ctx;

if (JS_IsString(val)) {
goto string;
}

buffer = JS_GetTypedArrayBuffer(cx, val, &byte_offset, &byte_length, NULL);
if (!JS_IsException(buffer)) {
start = JS_GetArrayBuffer(cx, &dst->len, buffer);
Expand All @@ -1492,6 +1496,8 @@ ngx_qjs_string(ngx_engine_t *e, JSValueConst val, ngx_str_t *dst)
}
}

string:

str = JS_ToCString(cx, val);
if (str == NULL) {
return NGX_ERROR;
Expand Down

0 comments on commit 3a4349e

Please sign in to comment.