Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Issue 29369365: Issue #4692 - Rewrite `SetTimeout` facility to avoid `JsValuePtr` and `JsValueList`

Created:
Dec. 19, 2016, 8:09 p.m. by Eric
Modified:
Jan. 16, 2017, 2:07 p.m.
Reviewers:
sergei, Felix Dahlke
Visibility:
Public.

Description

Issue #4692 - Rewrite `SetTimeout` facility to avoid `JsValuePtr` and `JsValueList` Rewrite the implementation of `SetTimeout` to use new classes that avoid the use of classes with embedded shared pointers to the engine. The focus of this is the class `TimeoutTask`. Redeclare its member `function` from `JsValuePtr` to a v8 Persistent. Redeclare its member `functionArguments from `JsValueList` to an allocated array of v8 Persistent. Rework its constructor, factory function, and `operator()` method to accomodate these changes. Move most of the code from the `TimeoutTask` constructor to `CallbackForSetTimeout`, which intrinsically acts as its factory method. Add "JsEngineInternal.h" to hold engine interfaces that do not belong in the public API. Add class `JsEngineInternal`, derived from `JsEngine`, to be the new instantiation class. Move `context` out of the external class as allocated member into the internal class as an ordinary member. Rework the engine factory and constructors, doing more in the constructors and documenting better the code necessarily inside the factory. Add class `V8PersistentNG`. This class mimics the interface and behavior of v8::Persistent in versions of v8 more recent than our current one. Add class `AllocatedArray`. This utility class wraps a heap-allocated array in a `unique_ptr` for automatic memory management. Add class `PersistentValueArray` to hold v8 argument lists that must persist across thread invocations. It has a utility method `GetAsLocal` to convert its persistent handles into the local ones needed for function invocation. Add `MakeCallback()`, `ExtractEngine()`, `ApplyFunction()` (all on the internal side) to replace `NewCallback`. `FromArguments`, and `CallFunction`. The replacements do not hold shared pointers anywhere, as well as being cleaner and shorter. The legacy functions will remain until all their callers have been rewritten. Add class `V8ExecutionScope`, constructed with `JsEngineInternal*` (plain pointer) rather with than `JsEnginePtr` (shared pointer). Rewrote `JsContext` as a legacy wrapper around the new class. Add `JsEngineInternal::GetGlobalObject()` to supersede the old one that uses `JsValuePtr`. Clean up legacy global object handling a bit, needed for the rewrite of `JsContext`. Add file `JsEngineTransition.h` to hold declarations that are only expected to be needed during the transition away from using shared pointer classes within the implementations of engine tasks. Add `ToInternal()` to extract an internal pointer out of `JsEnginePtr`.

Patch Set 1 : #

Total comments: 3
Unified diffs Side-by-side diffs Delta from patch set Stats (+625 lines, -75 lines) Patch
M include/AdblockPlus/JsEngine.h View 3 chunks +7 lines, -5 lines 0 comments Download
M libadblockplus.gyp View 3 chunks +4 lines, -0 lines 0 comments Download
A src/AllocatedArray.h View 1 chunk +90 lines, -0 lines 0 comments Download
M src/GlobalJsObject.h View 1 chunk +5 lines, -2 lines 0 comments Download
M src/GlobalJsObject.cpp View 3 chunks +76 lines, -38 lines 2 comments Download
M src/JsContext.h View 2 chunks +2 lines, -11 lines 0 comments Download
M src/JsContext.cpp View 1 chunk +3 lines, -6 lines 0 comments Download
M src/JsEngine.cpp View 6 chunks +118 lines, -10 lines 1 comment Download
A src/JsEngineInternal.h View 1 chunk +171 lines, -0 lines 0 comments Download
A src/JsEngineTransition.h View 1 chunk +31 lines, -0 lines 0 comments Download
M src/JsValue.cpp View 2 chunks +2 lines, -3 lines 0 comments Download
A src/V8Upgrade.h View 1 chunk +116 lines, -0 lines 0 comments Download

Messages

Total messages: 1
Eric
Dec. 19, 2016, 10:39 p.m. (2016-12-19 22:39:53 UTC) #1
There's lots of code here, but it's all conceptually straitforward: if there was
a facility that used a shared engine pointer to implement "SetTimeout", there's
a new facility that does the same thing that does not use a shared pointer.
Everything else follows from that principle. That includes rework for clarity,
since the early versions that were simple, direct substitutes left a lot of
cruft around the edges.

A secondary principle, one that follows from the first, is that the API does not
already expose v8 types, and we won't start now because we're changing the
internals. That's the reason for "JsEngineInternal.h". This is the conservative
choice; we can always change the API later.

There's a single remaining use of `JsEnginePtr` in the implementation, but it
can't be removed until the scheduler matures.

https://codereview.adblockplus.org/29369365/diff/29369391/src/GlobalJsObject.cpp
File src/GlobalJsObject.cpp (left):

https://codereview.adblockplus.org/29369365/diff/29369391/src/GlobalJsObject....
src/GlobalJsObject.cpp:110: obj->SetProperty("setTimeout",
jsEngine->NewCallback(::SetTimeoutCallback));
Old initialization of global object that used `JsEnginePtr`

https://codereview.adblockplus.org/29369365/diff/29369391/src/GlobalJsObject.cpp
File src/GlobalJsObject.cpp (right):

https://codereview.adblockplus.org/29369365/diff/29369391/src/GlobalJsObject....
src/GlobalJsObject.cpp:71: AdblockPlus::JsEnginePtr jsEnginePtr;
This is the only `JsEnginePtr` in the entirety of the new "SetTimeout"
implementation in the present change set.

https://codereview.adblockplus.org/29369365/diff/29369391/src/JsEngine.cpp
File src/JsEngine.cpp (right):

https://codereview.adblockplus.org/29369365/diff/29369391/src/JsEngine.cpp#ne...
src/JsEngine.cpp:113: globalObject->Set(propertyName,
MakeCallback(::CallbackForSetTimeout));
New initialization of global object without any use of `JsEnginePtr`.

Powered by Google App Engine
This is Rietveld