Skip to content

src: handle empty Maybe(Local) in node_util.cc - #33867

Closed
addaleax wants to merge 3 commits into
nodejs:masterfrom
addaleax:util-binding-maybe
Closed

src: handle empty Maybe(Local) in node_util.cc#33867
addaleax wants to merge 3 commits into
nodejs:masterfrom
addaleax:util-binding-maybe

Conversation

@addaleax

@addaleaxaddaleax commented Jun 13, 2020

Copy link
Copy Markdown
Member

Refs: https://github.com/nodejs/node/blob/master/src/README.md#checked-conversion

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. util Issues and PRs related to the built-in util module. labels Jun 13, 2020
Comment threadsrc/node_util.cc
Comment threadsrc/node_util.cc
if (!args[1]->Uint32Value(env->context()).To(&index)) return;
Local<Private> private_symbol = IndexToPrivateSymbol(env, index);
Local<Value> ret;
if (obj->GetPrivate(env->context(), private_symbol).ToLocal(&ret))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure but I don't think GetPrivate() can actually fail provided that obj->IsObject().

@addaleax

Copy link
Copy Markdown
MemberAuthor

@bnoordhuis The point isn’t so much as to whether these ops can currently fail or not, it’s more that I want to move more of our code into a state where it is “obviously not broken”, and be consistent about that. At least the SetPrivate() call can fail, and if we didn’t use .ToLocalChecked() & friends as excessively as we currently do, we probably wouldn’t have used it for that call either.

@bnoordhuis

Copy link
Copy Markdown
Member

We'll have to disagree on what "obviously not broken" means.

Replacing CHECK(args[1]->IsUint32()) with a (recoverable) JS exception just makes it harder to diagnose bugs, IMO.

Point ceded on the SetPrivate() call, although I'd still like people to report it when it fails, because that's likely a bug we need to fix.

(You can probably trigger it if you go out of your way to poison the runtime but normally I would expect it to be a bug on our side.)

@addaleax

Copy link
Copy Markdown
MemberAuthor

Point ceded on the SetPrivate() call, although I'd still like people to report it when it fails, because that's likely a bug we need to fix.

Like a lot of operations, it fails when JS execution is being terminated. That’s one of the main points here – it is only obvious that .ToLocalChecked() doesn’t fail in very few cases, so it’s better to avoid it as much as possible.

@bnoordhuis

Copy link
Copy Markdown
Member

If TerminateExecution() compatibility is the goal here, why don't you mention that in the commit log? That would have avoided this back and forth.

My point about changing the CHECK remains though: it serves no point that I can see.

@addaleax

Copy link
Copy Markdown
MemberAuthor

If TerminateExecution() compatibility is the goal here, why don't you mention that in the commit log? That would have avoided this back and forth.

Because I thought it was obvious, sorry. I’ll add Refs: https://github.com/nodejs/node/blob/master/src/README.md#checked-conversion for PRs like this in the future.

My point about changing the CHECK remains though: it serves no point that I can see.

Okay, since you feel strongly about it, I’ve restored it, and switched to the variant that we use when we CHECK() the type (i.e. .As<Uint32>()->Value() instead of ->Uint32Value(…)), as consistency is half of the point of this PR.

Comment threadsrc/node_util.cc
@addaleaxaddaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jun 19, 2020
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

jasnell pushed a commit that referenced this pull request Jun 25, 2020
PR-URL: #33867
Refs: https://github.com/nodejs/node/blob/master/src/README.md#checked-conversion
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
@jasnell

Copy link
Copy Markdown
Member

Landed in 8e12962

@jasnelljasnell closed this Jun 25, 2020
codebytere pushed a commit that referenced this pull request Jun 27, 2020
PR-URL: #33867
Refs: https://github.com/nodejs/node/blob/master/src/README.md#checked-conversion
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
@codebyterecodebytere mentioned this pull request Jun 28, 2020
codebytere pushed a commit that referenced this pull request Jun 30, 2020
PR-URL: #33867
Refs: https://github.com/nodejs/node/blob/master/src/README.md#checked-conversion
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
codebytere pushed a commit that referenced this pull request Jul 10, 2020
PR-URL: #33867
Refs: https://github.com/nodejs/node/blob/master/src/README.md#checked-conversion
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
codebytere pushed a commit that referenced this pull request Jul 12, 2020
PR-URL: #33867
Refs: https://github.com/nodejs/node/blob/master/src/README.md#checked-conversion
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
@codebyterecodebytere mentioned this pull request Jul 13, 2020
codebytere pushed a commit that referenced this pull request Jul 14, 2020
PR-URL: #33867
Refs: https://github.com/nodejs/node/blob/master/src/README.md#checked-conversion
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.c++Issues and PRs that require attention from people who are familiar with C++.utilIssues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@addaleax@bnoordhuis@nodejs-github-bot@jasnell@cjihrig