Bug 1765391 Comment 71 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

(Following up comment #69)

Here's another variant of Stephen's last two patches:

https://treeherder.mozilla.org/jobs?repo=try&revision=468e76cc2d076d987cc8065b5c4022f65619bed0
https://hg.mozilla.org/try/rev/dfef7703281fe2f9d370ac619070d02b7f27df43
https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/TvCEPXixShyJsCPE4oPFqQ/runs/0/artifacts/public/build/target.dmg

This time I've guaranteed that `geckoWindow` and `hiddenWindowMenuBar` will still be alive in the "lambdas" to which they are passed. I tried doing this with `NS_DispatchToCurrentThread(NS_NewRunnableFunction())`, but was stymied by bug 1421435. So I ended up using an Objective-C block instead.

As best I can tell `std::function()` does nothing with the parameters it "captures". So we need to use `AddRef()` and `Release()` ourselves. But, like I just said, bug 1421435 prevents them from working in a `std::function()` lambda. [Apple's documentation on block usage](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Blocks/Articles/bxVariables.html#//apple_ref/doc/uid/TP40007502-CH6-SW3) is unclear, and partly just wrong. Local variables outside the block that are used in the block, and which which don't have the `__block` storage type, are copied by value. Looking at `XUL` in a disassembler shows this happens with both `geckoWindow` and `hiddenWindowMenuBar`. So once again we must guarantee their survival ourselves. But `Release()` works just fine in a block's lambda (or closure).
(Following up comment #69)

Here's another variant of Stephen's last two patches:

https://treeherder.mozilla.org/jobs?repo=try&revision=468e76cc2d076d987cc8065b5c4022f65619bed0
https://hg.mozilla.org/try/rev/dfef7703281fe2f9d370ac619070d02b7f27df43
https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/TvCEPXixShyJsCPE4oPFqQ/runs/0/artifacts/public/build/target.dmg

This time I've guaranteed that `geckoWindow` and `hiddenWindowMenuBar` will still be alive in the "lambdas" to which they are passed. I tried doing this with `NS_DispatchToCurrentThread(NS_NewRunnableFunction())`, but was stymied by bug 1421435. So I ended up using an Objective-C block instead.

As best I can tell `std::function()` does nothing with the parameters it "captures". So we need to use `AddRef()` and `Release()` ourselves. But, like I just said, bug 1421435 prevents them from working in a `std::function()` lambda. [Apple's documentation on block usage](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Blocks/Articles/bxVariables.html#//apple_ref/doc/uid/TP40007502-CH6-SW3) is unclear, and partly just wrong. Local variables outside the block that are used in the block, and which don't have the `__block` storage type, are copied by value. Looking at `XUL` in a disassembler shows this happens with both `geckoWindow` and `hiddenWindowMenuBar`. So once again we must guarantee their survival ourselves. But `Release()` works just fine in a block's lambda (or closure).
(Following up comment #69)

Here's another variant of Stephen's last two patches:

https://treeherder.mozilla.org/jobs?repo=try&revision=468e76cc2d076d987cc8065b5c4022f65619bed0
https://hg.mozilla.org/try/rev/dfef7703281fe2f9d370ac619070d02b7f27df43
https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/TvCEPXixShyJsCPE4oPFqQ/runs/0/artifacts/public/build/target.dmg

This time I've guaranteed that `geckoWindow` and `hiddenWindowMenuBar` will still be alive in the "lambdas" to which they are passed. I tried doing this with `NS_DispatchToCurrentThread(NS_NewRunnableFunction())`, but was stymied by bug 1421435. So I ended up using an Objective-C block instead.

As best I can tell `std::function()` does nothing with the parameters it "captures". So we need to use `AddRef()` and `Release()` ourselves. But bug 1421435 prevents them from working in a `std::function()` lambda. [Apple's documentation on block usage](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Blocks/Articles/bxVariables.html#//apple_ref/doc/uid/TP40007502-CH6-SW3) is unclear, and partly just wrong. Local variables outside the block that are used in the block, and which don't have the `__block` storage type, are copied by value. Looking at `XUL` in a disassembler shows this happens with both `geckoWindow` and `hiddenWindowMenuBar`. So once again we must guarantee their survival ourselves. But `Release()` works just fine in a block's lambda (or closure).

Back to Bug 1765391 Comment 71