Skip to content
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 (ToString) #21935

Closed
wants to merge 3 commits into from

Conversation

ryzokuken
Copy link
Contributor

Remove all calls to deprecated v8 functions (here: Value::ToString) inside
the code (src directory only).

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

/cc @hashseed

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Jul 22, 2018
@ryzokuken
Copy link
Contributor Author

ryzokuken commented Jul 22, 2018

Testing locally, but what we have:

not ok 1381 parallel/test-process-env-symbols
  ---
  duration_ms: 0.413
  severity: crashed
  exitcode: -6
  stack: |-
    FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal.
     1: 0x834fe0 node::Abort() [out/Release/node]
     2: 0x8351d2  [out/Release/node]
     3: 0x9dc661 v8::V8::ToLocalEmpty() [out/Release/node]
     4: 0x837aef  [out/Release/node]
     5: 0xded05e v8::internal::PropertyCallbackArguments::CallNamedSetter(v8::internal::Handle<v8::internal::InterceptorInfo>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>) [out/Release/node]
     6: 0xe7500a  [out/Release/node]
     7: 0xe8439f v8::internal::Object::SetPropertyInternal(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::LanguageMode, v8::internal::Object::StoreFromKeyed, bool*) [out/Release/node]
     8: 0xe84237 v8::internal::Object::SetProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::LanguageMode, v8::internal::Object::StoreFromKeyed) [out/Release/node]
     9: 0xde338c v8::internal::StoreIC::Store(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [out/Release/node]
    10: 0xde5365 v8::internal::KeyedStoreIC::Store(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>) [out/Release/node]
    11: 0xde92e7 v8::internal::Runtime_KeyedStoreIC_Miss(int, v8::internal::Object**, v8::internal::Isolate*) [out/Release/node]
    12: 0x9e04e8841bd 
  ...

Looks related?

@ryzokuken
Copy link
Contributor Author

Okay, one of the ToLocalChecked must have failed on me, but idk which one?

@addaleax good enough opportunity to add error checking for each MaybeLocal?

@addaleax
Copy link
Member

@ryzokuken Yes, as far as I can tell, all of these can fail. We do need proper error handling here rather than using ToLocalChecked().

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

LGTM with a bunch of nits

if (!decoder.Decode(env, args[0].As<String>(), args[1], UTF8))
bool result;
if (!decoder.Decode(env, args[0].As<String>(), args[1], UTF8).To(&result) ||
!result)
Copy link
Member

Choose a reason for hiding this comment

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

tiny nit: if (!decoder.Decode(…).FromMaybe(false)) also does the trick and is a bit more idiomatic (here and below)

if (r.IsNothing()) {
return -1;
}
return r.FromJust();
Copy link
Member

Choose a reason for hiding this comment

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

ditto, return StringBytes::Size(…).FromMaybe(-1) is just as fine

if (maybe_r.IsNothing()) {
return v8::Nothing<bool>();
}
r = maybe_r.FromJust();
Copy link
Member

Choose a reason for hiding this comment

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

if (!ParseOptions(options).To(&r)) return v8::Nothing<bool>();?

HandleScope scope(env()->isolate());
int r;

if (!js_value->IsObject())
return UV_EINVAL;
return v8::Just(static_cast<int>(UV_EINVAL));
Copy link
Member

Choose a reason for hiding this comment

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

v8::Just<int>(UV_EINVAL)?

if (r_file.IsNothing()) {
return v8::Nothing<int>();
}
r = r_file.FromJust();
Copy link
Member

Choose a reason for hiding this comment

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

ditto, using .To(&r) is a bit more succinct

src/util.cc Outdated
StringBytes::StorageSize(isolate, string, UTF8);
if (maybe_storage.IsNothing())
return;
const size_t storage = maybe_storage.FromJust() + 1;
Copy link
Member

Choose a reason for hiding this comment

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

and finally, ditto :)

HandleScope scope(env()->isolate());
int r;

if (!js_value->IsObject())
return UV_EINVAL;
return v8::Just<int>(UV_EINVAL);

Local<Context> context = env()->context();
Local<Object> js_options = js_value.As<Object>();

Local<Value> js_file =
js_options->Get(context, env()->file_string()).ToLocalChecked();
Copy link
Member

Choose a reason for hiding this comment

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

Now, I know that you are a huuuuge fan of PR scope creep, but ... feel free to take care of other such places in the functions you're already touching as well, if you like?

@targos
Copy link
Member

targos commented Aug 28, 2018

This needs a rebase. Apart from that, is it ready?

targos added 3 commits August 29, 2018 15:39
Remove all calls to deprecated v8 functions (here: Value::ToString)
inside the code (src directory only).
Rework all affected functions to use Maybes, thus improving error
handling substantially in internal functions, API functions as well as
utilities.
@targos
Copy link
Member

targos commented Aug 29, 2018

Rebased, fixed conflicts and added using statements for v8::Just, v8::Maybe, v8::Nothing, etc.

CI: https://ci.nodejs.org/job/node-test-pull-request/16857/

@targos
Copy link
Member

targos commented Aug 29, 2018

Note: I also recreated the commits to apply make format-cpp. I forgot to reset the author to @ryzokuken after that. This should be done before landing.

@targos
Copy link
Member

targos commented Aug 31, 2018

Ping. CI is green

@targos
Copy link
Member

targos commented Sep 1, 2018

@addaleax also this one :)

@addaleax
Copy link
Member

addaleax commented Sep 2, 2018

Landed in 67403b3, a55c57b

@addaleax addaleax closed this Sep 2, 2018
addaleax pushed a commit that referenced this pull request Sep 2, 2018
Remove all calls to deprecated v8 functions (here: Value::ToString)
inside the code (src directory only).

PR-URL: #21935
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
addaleax pushed a commit that referenced this pull request Sep 2, 2018
Rework all affected functions to use Maybes, thus improving error
handling substantially in internal functions, API functions as well as
utilities.

Co-authored-by: Michaël Zasso <targos@protonmail.com>
PR-URL: #21935
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
targos pushed a commit that referenced this pull request Sep 2, 2018
Remove all calls to deprecated v8 functions (here: Value::ToString)
inside the code (src directory only).

PR-URL: #21935
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
targos added a commit that referenced this pull request Sep 2, 2018
Rework all affected functions to use Maybes, thus improving error
handling substantially in internal functions, API functions as well as
utilities.

Co-authored-by: Michaël Zasso <targos@protonmail.com>
PR-URL: #21935
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
targos pushed a commit that referenced this pull request Sep 3, 2018
Remove all calls to deprecated v8 functions (here: Value::ToString)
inside the code (src directory only).

PR-URL: #21935
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
targos added a commit that referenced this pull request Sep 3, 2018
Rework all affected functions to use Maybes, thus improving error
handling substantially in internal functions, API functions as well as
utilities.

Co-authored-by: Michaël Zasso <targos@protonmail.com>
PR-URL: #21935
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
targos pushed a commit that referenced this pull request Sep 6, 2018
Remove all calls to deprecated v8 functions (here: Value::ToString)
inside the code (src directory only).

PR-URL: #21935
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
targos added a commit that referenced this pull request Sep 6, 2018
Rework all affected functions to use Maybes, thus improving error
handling substantially in internal functions, API functions as well as
utilities.

Co-authored-by: Michaël Zasso <targos@protonmail.com>
PR-URL: #21935
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants