-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src: remove calls to deprecated v8 functions (Uint32Value) #22143
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4f11f8f
src: remove calls to deprecated v8 functions (Uint32Value)
ryzokuken 14afa7d
fixup! some nits
targos ccfe17d
fixup! always uint32
targos b19df2e
fixup! typo
targos 7cdabd5
fixup! return-on-error
targos f8219c4
fix warnings in zlib
targos 05aa50f
fixup! revert to casting in Buffer::Fill
targos 58156f9
fixup! coerce to uint32 before calling indexOf
targos 0bf15c5
fixup! zlib
targos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -49,6 +49,7 @@ using v8::Local; | |
using v8::Number; | ||
using v8::Object; | ||
using v8::String; | ||
using v8::Uint32; | ||
using v8::Uint32Array; | ||
using v8::Value; | ||
|
||
|
@@ -155,7 +156,11 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork { | |
|
||
CHECK_EQ(false, args[0]->IsUndefined() && "must provide flush value"); | ||
|
||
unsigned int flush = args[0]->Uint32Value(); | ||
Environment* env = ctx->env(); | ||
Local<Context> context = env->context(); | ||
|
||
unsigned int flush; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess CI is going to tell us whether it’s a real problem, but at least in theory this would be |
||
if (!args[0]->Uint32Value(context).To(&flush)) return; | ||
|
||
if (flush != Z_NO_FLUSH && | ||
flush != Z_PARTIAL_FLUSH && | ||
|
@@ -170,8 +175,7 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork { | |
|
||
Bytef* in; | ||
Bytef* out; | ||
size_t in_off, in_len, out_off, out_len; | ||
Environment* env = ctx->env(); | ||
uint32_t in_off, in_len, out_off, out_len; | ||
|
||
if (args[1]->IsNull()) { | ||
// just a flush | ||
|
@@ -181,18 +185,18 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork { | |
} else { | ||
CHECK(Buffer::HasInstance(args[1])); | ||
Local<Object> in_buf; | ||
in_buf = args[1]->ToObject(env->context()).ToLocalChecked(); | ||
in_off = args[2]->Uint32Value(); | ||
in_len = args[3]->Uint32Value(); | ||
in_buf = args[1]->ToObject(context).ToLocalChecked(); | ||
if (!args[2]->Uint32Value(context).To(&in_off)) return; | ||
if (!args[3]->Uint32Value(context).To(&in_len)) return; | ||
|
||
CHECK(Buffer::IsWithinBounds(in_off, in_len, Buffer::Length(in_buf))); | ||
in = reinterpret_cast<Bytef *>(Buffer::Data(in_buf) + in_off); | ||
} | ||
|
||
CHECK(Buffer::HasInstance(args[4])); | ||
Local<Object> out_buf = args[4]->ToObject(env->context()).ToLocalChecked(); | ||
out_off = args[5]->Uint32Value(); | ||
out_len = args[6]->Uint32Value(); | ||
Local<Object> out_buf = args[4]->ToObject(context).ToLocalChecked(); | ||
if (!args[5]->Uint32Value(context).To(&out_off)) return; | ||
if (!args[6]->Uint32Value(context).To(&out_len)) return; | ||
CHECK(Buffer::IsWithinBounds(out_off, out_len, Buffer::Length(out_buf))); | ||
out = reinterpret_cast<Bytef *>(Buffer::Data(out_buf) + out_off); | ||
|
||
|
@@ -438,32 +442,38 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork { | |
ZCtx* ctx; | ||
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Holder()); | ||
|
||
Local<Context> context = args.GetIsolate()->GetCurrentContext(); | ||
|
||
// windowBits is special. On the compression side, 0 is an invalid value. | ||
// But on the decompression side, a value of 0 for windowBits tells zlib | ||
// to use the window size in the zlib header of the compressed stream. | ||
int windowBits = args[0]->Uint32Value(); | ||
uint32_t windowBits; | ||
if (!args[0]->Uint32Value(context).To(&windowBits)) return; | ||
|
||
if (!((windowBits == 0) && | ||
(ctx->mode_ == INFLATE || | ||
ctx->mode_ == GUNZIP || | ||
ctx->mode_ == UNZIP))) { | ||
CHECK((windowBits >= Z_MIN_WINDOWBITS && | ||
windowBits <= Z_MAX_WINDOWBITS) && "invalid windowBits"); | ||
CHECK( | ||
(windowBits >= Z_MIN_WINDOWBITS && windowBits <= Z_MAX_WINDOWBITS) && | ||
"invalid windowBits"); | ||
} | ||
|
||
int level = args[1]->Int32Value(); | ||
CHECK((level >= Z_MIN_LEVEL && level <= Z_MAX_LEVEL) && | ||
"invalid compression level"); | ||
|
||
int memLevel = args[2]->Uint32Value(); | ||
uint32_t memLevel; | ||
if (!args[2]->Uint32Value(context).To(&memLevel)) return; | ||
CHECK((memLevel >= Z_MIN_MEMLEVEL && memLevel <= Z_MAX_MEMLEVEL) && | ||
"invalid memlevel"); | ||
|
||
int strategy = args[3]->Uint32Value(); | ||
CHECK((strategy == Z_FILTERED || | ||
strategy == Z_HUFFMAN_ONLY || | ||
strategy == Z_RLE || | ||
strategy == Z_FIXED || | ||
strategy == Z_DEFAULT_STRATEGY) && "invalid strategy"); | ||
"invalid memlevel"); | ||
|
||
uint32_t strategy; | ||
if (!args[3]->Uint32Value(context).To(&strategy)) return; | ||
CHECK((strategy == Z_FILTERED || strategy == Z_HUFFMAN_ONLY || | ||
strategy == Z_RLE || strategy == Z_FIXED || | ||
strategy == Z_DEFAULT_STRATEGY) && | ||
"invalid strategy"); | ||
|
||
CHECK(args[4]->IsUint32Array()); | ||
Local<Uint32Array> array = args[4].As<Uint32Array>(); | ||
|
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure but perhaps
FromMaybe
version is clearer?Though this will result in function actually continuing execution if provided with invalid value (but wasn't this how it was before -
Uint32Value()
returns 0 on invalid values AFAIK? )?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is the previous behaviour, which is buggy in that it will swallow exceptions if both calls fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 shouldn't this then be semver-major to avoid possible breakage?
Also, perhaps we can
in this case (tests seem to pass)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only place where we pass in invalid arguments is from a
process.binding()
test. We could/should probably remove that test in a follow-up PR, and revert 05aa50f (which is pretty close to your suggestion)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I thought that this was expected somewhere else, therefore the test. The suggested commit is even better, with the above I wanted to somehow mitigate that test.