On 04/10/2015 07:47 PM, Ehsan Akhgari wrote:
On 2015-04-10 1:41 PM, Nicolas B. Pierron wrote:
Also, what is the alternative? Acquiring a nsCOMPtr/nsRefPtr inside the
Lambda constructor (or whatever it's called)?
Yes, another option would be to ensure that the lambda cannot be used
after a specific point.
nsINode* myNode;
auto callFoo = MakeScopedLambda([&]() {
myNode->Foo();
})
TakeLambda(callFoo);
Any reference to the lambda after the end of the innermost scope where
MakeScopedLambda is used can cause a MOZ_CRASH.
How would you detect that at compile/run time?
Simply by replacing the reference to the lambda inside callFoo at the end of
the scope, and replace it by a constructing a dummy function which expects
the same type of arguments as the lambda, but calls MOZ_CRASH instead.
I guess I would have wrote the auto as ScopedLambda<void (*)()> for the
example.
--
Nicolas B. Pierron
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform