Opened 5 years ago

Closed 2 years ago

#1863 closed change (fixed)

Make it possible to use JsValue in JsValueList in class constructor.

Reported by: sergz Assignee:
Priority: Unknown Milestone:
Module: Libadblockplus Keywords:
Cc: Blocked By:
Blocking: Platform: Unknown
Ready: no Confidential: no
Tester: Unknown Verified working: no
Review URL(s):

Description

To call any javascript function from the class constructor which accepts JsValuePtr (in particular Notification as well as Subscription and Filter) we need to pass the javascript object as argument, thus to put it into JsValueList which is a container of shared pointers of JsValue.

  • We cannot put jsValue constructor argument into JsValueList because its internal V8ValueHolder<v8::Value> value has been already transferred into value of the base class of the inheritor (Notification) class. In addition see #1550.
  • We cannot use shared_from_this in the constructor because internal weak_ptr of enable_shared_from_this is not initialized yet.
  • Even more, we cannot easily have JsValuePtr as a member of inheritor class because in that case we don't have the access to the protected member JsValue::jsEngine. Actually we can create another class which inherits from

from JsValue and which exposes JsEngine and store a pointer to this class as a member of inheritor class, but I'm afraid that it is even more confusing.
Although having JsValue as a private member looks very attractive, just in case sometimes we want to have the access to base JsValue.

What to change

The way how to achieve it should be actually discussed. So far I guess the easiest way is to add copy-ctr for JsValue and to avoid mistakes remove JsValue(JsValuePtr) which transfers the value. We could fix JsValue(JsValuePtr) but it seems will not be needed anymore.

Change History (1)

comment:1 Changed 2 years ago by sergz

  • Resolution set to fixed
  • Status changed from new to closed
  • Tester set to Unknown
  • Verified working unset

Currently there is the method JsValue JsValue::Call(const JsValue& arg) const; accepting a reference to JsValue, so the problem described in the issue description does not exist anylonger because one can simply pass *this to the JsValue::Call method.

Note: See TracTickets for help on using tickets.