Closed Bug 1460719 Opened 7 years ago Closed 7 years ago

Unnecessary (unconditonal) cloning when using "async function" syntax in child/ext-*.js

Categories

(WebExtensions :: General, enhancement)

60 Branch
enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: robwu, Unassigned)

References

(Blocks 1 open bug)

Details

async functions in child/ext-*.js are handled by wrapPromise in ExtensionCommon.jsm When the async function syntax is used, the returned promise does not belong to context.cloneScope, and hence wrapPromise defaults to cloning the return value: https://searchfox.org/mozilla-central/rev/eb6c5214a63e20a3fff455e92c876287a8d2e188/toolkit/components/extensions/ExtensionCommon.jsm#416-417 This cloning becomes a problem if the returned value has functions, e.g.: - https://searchfox.org/mozilla-central/rev/eb6c5214a63e20a3fff455e92c876287a8d2e188/browser/components/extensions/child/ext-devtools-panels.js#260 - https://searchfox.org/mozilla-central/rev/eb6c5214a63e20a3fff455e92c876287a8d2e188/browser/components/extensions/child/ext-devtools-panels.js#279 - https://searchfox.org/mozilla-central/rev/eb6c5214a63e20a3fff455e92c876287a8d2e188/toolkit/components/extensions/child/ext-contentScripts.js#56 To work around this automatic cloning, those implementations in our code base do this: methodName() { return new context.cloneScope.Promise().resolve(() => { return somehowGenerateObjectInCloneScope(); }); } Ideally this verbose syntax should not be necessary, and we should just be able to do this: async methodName() { return somehowGenerateObbjectInCloneScope(); } There are two ways to do this. 1. Modify wrapPromise to check whether the resolved promise value is in cloneScope, and if so, skip cloning. 2. Modify the above functions to do this: async methodName() { let val = somehowGenerateObbjectInCloneScope(); return new ExtensionCommon.NoCloneSpreadArgs([val]); } The latter relies on the existing special logic for NoCloneSpreadArgs: https://searchfox.org/mozilla-central/rev/eb6c5214a63e20a3fff455e92c876287a8d2e188/toolkit/components/extensions/ExtensionCommon.jsm#461-464
Cloning is the expected default behavior. The current method of returning a Promise is the intended way to signal that we don't want cloning at the moment, and it's used rarely enough that it's not an issue.
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → WONTFIX
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.