Opened on 03/27/2018 at 10:58:10 AM
Last modified on 08/08/2018 at 12:03:19 PM
#6526 new change
Stop using of deprecated V8 API.
Reported by: | sergz | Assignee: | sergz |
---|---|---|---|
Priority: | P3 | Milestone: | |
Module: | Libadblockplus | Keywords: | |
Cc: | rjeschke, hfiguiere | Blocked By: | |
Blocking: | Platform: | Unknown / Cross platform | |
Ready: | no | Confidential: | no |
Tester: | Unknown | Verified working: | no |
Review URL(s): |
https://codereview.adblockplus.org/29734562/ |
Description (last modified by sergz)
Background
We are using pretty a lot of deprecated V8 API, and in order to simplify our life, avoid unnecessary delays in such issues like #6063, and be able to experiment with new techniques like WebAssembly, we should update our code base to use up-to-date API.
What to change
The list of API
- [done] v8::TryCatch should accept v8::Isolate
- [done] v8::Isolate::IdleNotification is renamed to v8::Isolate::IdleNotitifcationDeadline
- [done] use maybe version of v8::Script::Compile, related #6448
- [done] use v8::Local instead of v8::Handle
- [done] use maybe version of v8::Message::GetLineNumber
- [question is below] use v8 functions which return maybe values, e.g.
- v8::Value::IntegerValue
- v8::FunctionTemplate::GetFunction
- v8::String::NewFromUtf8
- v8::Value::BooleanValue
- v8::Object::Get(uint32_t)
- v8::Object::GetOwnPropertyNames
- v8::Function::Call
- etc
- those maybe functions accept v8::Context, therefore we need to carefully check that we pass the correct context. Perhaps in the callbacks we should rather use v8::Isolate::GetCurrentContext instead of obtaining it from JsEngine. Additionally pay attention to JsContext which works with the context too.
- revisit ThrowExceptionInJS because failing throwing of an exception is not a good thing
- add actual tests simulating the state of the isolate when it starts to return empty values.
- to be continued ...
Here we need to decide regarding the behavior if there is no value in maybe value. The options are basically either to use an artificial default value, crash or propagate such resembling monadic approach to our API.
Attachments (0)
Change History (29)
comment:2 Changed on 03/27/2018 at 02:03:31 PM by abpbot
comment:3 Changed on 03/28/2018 at 08:31:09 AM by sergz
I would like to get your opinion especially regarding the dealing with the maybevalues in our code.
In order to get compiler warnings and errors one can add
'defines': [ 'V8_DEPRECATION_WARNINGS', 'V8_IMMINENT_DEPRECATION_WARNINGS' ],
to 'target_defaults' in common.gypi and compile our code with prebuilt V8.
comment:4 Changed on 03/29/2018 at 07:47:07 AM by abpbot
A commit referencing this issue has landed:
Issue 6526 - replace deprecated v8::Handle by v8::Local
comment:6 Changed on 06/14/2018 at 02:49:23 PM by sergz
- Owner set to sergz
comment:7 follow-up: ↓ 11 Changed on 06/14/2018 at 02:58:36 PM by hfiguiere
maybes are a good idea. As a Rust user I'm a big fan of Option<> (std::optional<> in C++ 17). While this often complicate code a bit, it definitely improve the code safety. It is like checking for nullptr.
I'm not sure if requiring C++17 for this is a good idea, but on the other hand we could have our own version of std::optional<> to implement this pattern.
comment:8 Changed on 06/15/2018 at 03:02:04 PM by oleksandr
I also think propagating to our API is probably best in the long term. Having default values could cause unintended consequences and crashing just doesn't seem right to me.
comment:10 Changed on 06/18/2018 at 10:31:36 AM by sergz
- Review URL(s) modified (diff)
comment:11 in reply to: ↑ 7 Changed on 06/18/2018 at 10:46:09 AM by sergz
Replying to hfiguiere:
I'm not sure if requiring C++17 for this is a good idea, but on the other hand we could have our own version of std::optional<> to implement this pattern.
Yeah, taking into account that it's compiled by android NDK and possibly other not so fast toolsets, C++17 can be a challenge. Own implementation of std::optional is also causing rather more questions so far.
I would propose to start with own implementation of std::optional, let's call it Maybe with the explicit template specification only for JsValue so far, since it seems can be implemented in a relatively efficient way. Perhaps it will also cover most cases of the deprecated API.
JIC, here I mean that there will be a special implementation to work with internals of JsValue, not a generic one.
Additionally what do you think about map/flatmap/bind/get/ifPresent/orElse/etc functions (of course add them only when they are required) either as a mixin (perhaps via CRTP) or just template functions? E.g. it seems we are not using thousands of operations with them, so any overhead like lambdas should not be an issue but perhaps it reduces a huge arising boilerplate code.
comment:12 Changed on 06/19/2018 at 05:13:19 PM by hfiguiere
- Review URL(s) modified (diff)
comment:13 Changed on 06/19/2018 at 05:41:38 PM by hfiguiere
- Review URL(s) modified (diff)
comment:14 Changed on 06/20/2018 at 02:54:41 PM by abpbot
A commit referencing this issue has landed:
Issue 6526 - pass v8::Isolate to more functions because old approach is deprecated
comment:15 Changed on 06/20/2018 at 03:16:21 PM by hfiguiere
- Review URL(s) modified (diff)
comment:16 Changed on 06/21/2018 at 01:42:56 PM by abpbot
A commit referencing this issue has landed:
Issue 6526 - Use the maybe version of Compile() and Run()
comment:17 Changed on 06/21/2018 at 01:56:10 PM by hfiguiere
- Description modified (diff)
comment:18 Changed on 06/21/2018 at 01:57:07 PM by hfiguiere
- Description modified (diff)
comment:19 Changed on 06/21/2018 at 09:04:52 PM by hfiguiere
- Review URL(s) modified (diff)
comment:20 Changed on 06/21/2018 at 11:18:12 PM by hfiguiere
- Review URL(s) modified (diff)
comment:21 Changed on 06/22/2018 at 03:07:24 AM by abpbot
A commit referencing this issue has landed:
Issue 6526 - Remove deprecated CreateDefaultPlatform()
comment:22 Changed on 06/22/2018 at 09:33:09 PM by hfiguiere
- Review URL(s) modified (diff)
comment:23 Changed on 08/06/2018 at 12:57:46 PM by hfiguiere
- Description modified (diff)
comment:24 Changed on 08/06/2018 at 01:02:03 PM by sergz
- Description modified (diff)
fix layout/formating
comment:25 Changed on 08/06/2018 at 03:36:11 PM by abpbot
A commit referencing this issue has landed:
Issue 6526 - *ToV8String() return MaybeLocal<> and check Call() return value
comment:26 Changed on 08/07/2018 at 05:02:44 PM by abpbot
A commit referencing this issue has landed:
Issue 6526 - Use Maybe<> version of soon to be deprecated API in v8 6.7
comment:27 Changed on 08/07/2018 at 05:31:09 PM by hfiguiere
- Review URL(s) modified (diff)
comment:28 Changed on 08/07/2018 at 06:02:08 PM by abpbot
A commit referencing this issue has landed:
Issue 6526 - Fix test by not exposing V8
comment:29 Changed on 08/08/2018 at 12:03:19 PM by sergz
- Review URL(s) modified (diff)
A commit referencing this issue has landed:
Issue 6526 - update usage of V8 API