From dc43362203f9323f0f444df3898ea3f9a728721e Mon Sep 17 00:00:00 2001 From: Wilson Lin Date: Tue, 31 Jan 2023 15:01:14 +1100 Subject: [PATCH] [Node.js] Fix assertion failure panic on invalid argument type. --- CHANGELOG.md | 4 ++++ nodejs/Cargo.toml | 2 +- nodejs/src/lib.rs | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c06ce38..329f27a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # minify-html changelog +## Pending + +- [Node.js] Fix assertion failure panic on invalid argument type. + ## 0.10.7 - Bump [minify-js](https://github.com/wilsonzlin/minify-js) to 0.4.2. diff --git a/nodejs/Cargo.toml b/nodejs/Cargo.toml index c4b0bba..4f9b583 100644 --- a/nodejs/Cargo.toml +++ b/nodejs/Cargo.toml @@ -15,4 +15,4 @@ minify-html = "0.10.7" [dependencies.neon] version = "0.10" default-features = false -features = ["napi-1"] +features = ["napi-1", "try-catch-api"] diff --git a/nodejs/src/lib.rs b/nodejs/src/lib.rs index feaeadc..d676c82 100644 --- a/nodejs/src/lib.rs +++ b/nodejs/src/lib.rs @@ -2,10 +2,10 @@ use neon::prelude::*; use neon::types::buffer::TypedArray; fn minify(mut cx: FunctionContext) -> JsResult { - let Ok(src) = cx.argument::(0) else { + let Ok(src) = cx.try_catch(|cx| cx.argument::(0)) else { return cx.throw_type_error("the first argument is not a Buffer"); }; - let Ok(opt) = cx.argument::(1) else { + let Ok(opt) = cx.try_catch(|cx| cx.argument::(1)) else { return cx.throw_type_error("the second argument is not an object"); }; let cfg = minify_html::Cfg {