[Node.js] Fix assertion failure panic on invalid argument type.

This commit is contained in:
Wilson Lin 2023-01-31 15:01:14 +11:00
parent c0f7ac99e1
commit dc43362203
3 changed files with 7 additions and 3 deletions

View File

@ -1,5 +1,9 @@
# minify-html changelog # minify-html changelog
## Pending
- [Node.js] Fix assertion failure panic on invalid argument type.
## 0.10.7 ## 0.10.7
- Bump [minify-js](https://github.com/wilsonzlin/minify-js) to 0.4.2. - Bump [minify-js](https://github.com/wilsonzlin/minify-js) to 0.4.2.

View File

@ -15,4 +15,4 @@ minify-html = "0.10.7"
[dependencies.neon] [dependencies.neon]
version = "0.10" version = "0.10"
default-features = false default-features = false
features = ["napi-1"] features = ["napi-1", "try-catch-api"]

View File

@ -2,10 +2,10 @@ use neon::prelude::*;
use neon::types::buffer::TypedArray; use neon::types::buffer::TypedArray;
fn minify(mut cx: FunctionContext) -> JsResult<JsBuffer> { fn minify(mut cx: FunctionContext) -> JsResult<JsBuffer> {
let Ok(src) = cx.argument::<JsBuffer>(0) else { let Ok(src) = cx.try_catch(|cx| cx.argument::<JsBuffer>(0)) else {
return cx.throw_type_error("the first argument is not a Buffer"); return cx.throw_type_error("the first argument is not a Buffer");
}; };
let Ok(opt) = cx.argument::<JsObject>(1) else { let Ok(opt) = cx.try_catch(|cx| cx.argument::<JsObject>(1)) else {
return cx.throw_type_error("the second argument is not an object"); return cx.throw_type_error("the second argument is not an object");
}; };
let cfg = minify_html::Cfg { let cfg = minify_html::Cfg {