Page MenuHomePhabricator

jqueryMsg uses the same astCache for all parser objects
Closed, ResolvedPublic

Description

Oh man, this was annoying to discover…

jqueryMsg uses the same astCache for all parser objects. This is apparently expected behavior, but I'm pretty sure it's incorrect, as each parser can have different messages under the same key.

	mw.jqueryMsg.parser.prototype = {
		...
		 * This cache is shared by all instances of mw.jqueryMsg.parser.
		astCache: {},
		...
	}

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 1:47 AM
bzimport set Reference to bz52042.
bzimport added a subscriber: Unknown Object (MLST).

neilk wrote:

Seems like this would be easy to fix, just create astCache as a property upon initialization.

Seems to have been a bug since the beginning (sorry), but the fact that there's a comment makes me think that maybe someone has deliberately preserved this behavior now. I can't think of any situation where you want multiple instances to share a cache, is there?

If you need multiple newly-created objects to share a cache, write a singleton to wrap this class. Kind of an antipattern IMO but whatever.

I added the comment after I also discovered it the hard way. If it's desired behavior to allow different messages with the same key, I agree it needs to change. It would use more memory, but simplify things. I think this has come up for me when writing unit tests.

If this change is made, onlyCurlyBraceTransform can also be removed from the AST key, since that is a per-parser setting.

matmarex edited projects, added Technical-Debt; removed I18n.
matmarex set Security to None.
matmarex removed a subscriber: Unknown Object (MLST).

Change 246940 had a related patch set uploaded (by Bartosz Dziewoński):
mediawiki.jqueryMsg: Remove 'astCache'

https://gerrit.wikimedia.org/r/246940

Krinkle claimed this task.

Change 246940 merged by jenkins-bot:
mediawiki.jqueryMsg: Remove 'astCache'

https://gerrit.wikimedia.org/r/246940

Change 249133 had a related patch set uploaded (by Bartosz Dziewoński):
mediawiki.jqueryMsg: Remove 'astCache'

https://gerrit.wikimedia.org/r/249133

Change 249133 merged by jenkins-bot:
mediawiki.jqueryMsg: Remove 'astCache'

https://gerrit.wikimedia.org/r/249133