mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
src: add FromV8Value<T>() for integral and enum types
Add a template utility method FromV8Value<T>() to replace the repetitive static_cast<...>(value.As<>()‑>Value()) pattern. It also additionally adds compile‑time range checks for integers. Refs: https://github.com/nodejs/node/pull/57146#discussion_r1963799600 PR-URL: https://github.com/nodejs/node/pull/57931 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
1 parent
2c205d857c
commit
74ef07f2e7
8 files changed
+43
-17
No files matched your search
+2
-5
@@ -53,7 +53,6 @@ using v8::Function;
|
||||
using v8::FunctionCallbackInfo;
|
||||
using v8::FunctionTemplate;
|
||||
using v8::HandleScope;
|
||||
using v8::Int32;
|
||||
using v8::Integer;
|
||||
using v8::Isolate;
|
||||
using v8::Local;
|
||||
@@ -687,8 +686,7 @@ class ZlibStream final : public CompressionStream<ZlibContext> {
|
||||
static void New(const FunctionCallbackInfo<Value>& args) {
|
||||
Environment* env = Environment::GetCurrent(args);
|
||||
CHECK(args[0]->IsInt32());
|
||||
node_zlib_mode mode =
|
||||
static_cast<node_zlib_mode>(args[0].As<Int32>()->Value());
|
||||
node_zlib_mode mode = FromV8Value<node_zlib_mode>(args[0]);
|
||||
new ZlibStream(env, args.This(), mode);
|
||||
}
|
||||
|
||||
@@ -793,8 +791,7 @@ class BrotliCompressionStream final :
|
||||
static void New(const FunctionCallbackInfo<Value>& args) {
|
||||
Environment* env = Environment::GetCurrent(args);
|
||||
CHECK(args[0]->IsInt32());
|
||||
node_zlib_mode mode =
|
||||
static_cast<node_zlib_mode>(args[0].As<Int32>()->Value());
|
||||
node_zlib_mode mode = FromV8Value<node_zlib_mode>(args[0]);
|
||||
new BrotliCompressionStream(env, args.This(), mode);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user