Closed Bug 1073338 Opened 10 years ago Closed 10 years ago

"Too much recursion" error when using Pseudolocale

Categories

(Firefox OS Graveyard :: Gaia::L10n, defect)

x86
All
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: zbraniecki, Assigned: stas)

Details

Attachments

(1 file, 1 obsolete file)

STR: - switch language to Pseudolocale - dial - end the call Current result: E/Usage (22472): [JavaScript Error: "too much recursion" {file: "app://costcontrol.gaiamobile.org/gaia_build_message_handler.js" line: 128}]
Any idea what may cause this?
Flags: needinfo?(stas)
I'm able to reproduce and I'm currently investigating. It looks like the error is happening in walkContent here: https://github.com/mozilla-b2g/gaia/blob/19d33962bdab24acadc22d3e3d07a8ec0bed5fe9/shared/js/l10n.js#L921 which is why you see it for pseudolocales. walkContent is used to walk the en-US AST and pseudolocalize it.
Assignee: nobody → stas
Flags: needinfo?(stas)
This is caused by the notorious Object.prototype.extend in the Usage app. https://github.com/mozilla-b2g/gaia/blob/master/apps/costcontrol/js/utils/toolkit.js#L34 I'll have a fix in a minute.
Attached patch if (!node.hasOwnProperty(key)) (obsolete) (deleted) — Splinter Review
Pull request: https://github.com/mozilla-b2g/gaia/pull/24485 TBPL: https://tbpl.mozilla.org/?rev=2253bb27664c&tree=Gaia-Try Even if we use Object.create(null) to create new ASTs, if we take it from JSON, its objects will use Object.prototype. So we need this additional check here.
Attachment #8496107 - Flags: review?(gandalf)
Attachment #8496107 - Flags: review?(gandalf) → review+
(In reply to Staś Małolepszy :stas from comment #3) > This is caused by the notorious Object.prototype.extend in the Usage app. > > https://github.com/mozilla-b2g/gaia/blob/master/apps/costcontrol/js/utils/ > toolkit.js#L34 I filed bug 1073608 for this.
Attached patch Object.keys (deleted) — Splinter Review
https://github.com/mozilla-b2g/gaia/pull/24485 https://tbpl.mozilla.org/?rev=f132b7d624f1&tree=Gaia-Try The previous patch was wrong: for objects created with Object.create(null) we can't use obj.hasOwnProperty. Here's another approach that we employ elsewhere: use Object.keys and iterate over the object's own keys. The only trouble with this is that Object.keys throws if called on a non-object. I've added a check for falsyness, but it doesn't protect us against numbers. OTOH, we don't accept numbers as values in our AST, so we should never run into this problem. Gandalf, what do you think about this? Should this be more defensive, or is it okay as-is?
Attachment #8496107 - Attachment is obsolete: true
Attachment #8498068 - Flags: review?(gandalf)
Comment on attachment 8498068 [details] [diff] [review] Object.keys Review of attachment 8498068 [details] [diff] [review]: ----------------------------------------------------------------- ::: shared/js/l10n.js @@ +912,5 @@ > /* Utility functions */ > > // Recursively walk an AST node searching for content leaves > function walkContent(node, fn) { > + if (!node || typeof node === 'string') { In which scenario the node is falsy and yet you want to return fn(node) for it?
I was thinking about entities with null values, but I now realize that the AST simply won't contain the 'value' property at all in these cases. I'll remove that check.
New PR: https://github.com/mozilla-b2g/gaia/pull/24835 (the previous one was closed during the Great Closing of PRs).
Comment on attachment 8498068 [details] [diff] [review] Object.keys Review of attachment 8498068 [details] [diff] [review]: ----------------------------------------------------------------- ::: shared/js/l10n.js @@ +912,5 @@ > /* Utility functions */ > > // Recursively walk an AST node searching for content leaves > function walkContent(node, fn) { > + if (!node || typeof node === 'string') { in which condition you want to return fn(node) when node is falsy?
Attachment #8498068 - Flags: review?(gandalf) → review+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: