Open Bug 1758868 Opened 2 years ago Updated 2 years ago

lambda callback declared as `std::function` cannot be marked as MOZ_CAN_RUN_SCRIPT

Categories

(Developer Infrastructure :: Source Code Analysis, enhancement, P3)

enhancement

Tracking

(Not tracked)

People

(Reporter: masayuki, Unassigned)

Details

If a function is defined as:

MOZ_CAN_RUN_SCRIPT nsresult DoSomething(
  std::function<nsresult(Element&)>&& aCallback);

And call it like:

nsresult rv = DoSomething(
  [&](Element& aElement) MOZ_CAN_RUN_SCRIPT {
    // Do something unsafe
    return NS_OK;
  });

Then, I got this error:

 0:34.57 C:/PROGRA~2/MIB055~1/2019/PROFES~1/VC/Tools/MSVC/1429~1.301/include\type_traits(1493,21): error: functions marked as MOZ_CAN_RUN_SCRIPT can only be called from functions also marked as MOZ_CAN_RUN_SCRIPT
 0:34.57         -> decltype(static_cast<_Callable&&>(_Obj)(static_cast<_Types&&>(_Args)...)) {
 0:34.57                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 0:34.57 C:/PROGRA~2/MIB055~1/2019/PROFES~1/VC/Tools/MSVC/1429~1.301/include\type_traits(1491,27): note: caller function declared here
 0:34.57     static constexpr auto _Call(_Callable&& _Obj, _Types&&... _Args) noexcept(
 0:34.57                           ^
 0:34.57 C:/PROGRA~2/MIB055~1/2019/PROFES~1/VC/Tools/MSVC/1429~1.301/include\type_traits(1595,16): error: functions marked as MOZ_CAN_RUN_SCRIPT can only be called from functions also marked as MOZ_CAN_RUN_SCRIPT
 0:34.57         return static_cast<_Callable&&>(_Obj)(static_cast<_Ty1&&>(_Arg1), static_cast<_Types2&&>(_Args2)...);
 0:34.57                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 0:34.57 C:/PROGRA~2/MIB055~1/2019/PROFES~1/VC/Tools/MSVC/1429~1.301/include\type_traits(1589,19): note: caller function declared here
 0:34.57 _CONSTEXPR17 auto invoke(_Callable&& _Obj, _Ty1&& _Arg1, _Types2&&... _Args2) noexcept(

Of course, MOZ_CAN_RUN_SCRIPT_BOUNDARY works, so I'm using it for avoiding this bustage.

The severity field is not set for this bug.
:andi, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(bpostelnicu)
Severity: -- → S3
Flags: needinfo?(bpostelnicu)
Priority: -- → P3
Type: defect → enhancement
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.