Bug 1086527 - Make sure PluralForm.get can be called from strict mode. r=Mossop, a=lsblakk
authorCosmin Malutan <cosmin.malutan@softvision.ro>
Thu, 23 Oct 2014 23:29:00 +0200
changeset 225839 363ef26f9bee
parent 225838 4197f5318fd8
child 225840 776f967418e1
push id4034
push userryanvm@gmail.com
push date2014-10-28 14:16 +0000
treeherdermozilla-beta@363ef26f9bee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop, lsblakk
bugs1086527
milestone34.0
Bug 1086527 - Make sure PluralForm.get can be called from strict mode. r=Mossop, a=lsblakk
intl/locale/PluralForm.jsm
intl/locale/tests/unit/test_bug1086527.js
intl/locale/tests/unit/xpcshell.ini
--- a/intl/locale/PluralForm.jsm
+++ b/intl/locale/PluralForm.jsm
@@ -130,17 +130,17 @@ this.PluralForm = {
       let words = aWords ? aWords.split(/;/) : [""];
 
       // Explicitly check bounds to avoid strict warnings
       let ret = index < words.length ? words[index] : undefined;
 
       // Check for array out of bounds or empty strings
       if ((ret == undefined) || (ret == "")) {
         // Report the caller to help figure out who is causing badness
-        let caller = PluralForm.get.caller ? PluralForm.get.caller.name : "top";
+        let caller = Components.stack.caller ? Components.stack.caller.name : "top";
 
         // Display a message in the error console
         log(["Index #", index, " of '", aWords, "' for value ", aNum,
             " is invalid -- plural rule #", aRuleNum, "; called by ", caller]);
 
         // Default to the first entry (which might be empty, but not undefined)
         ret = words[0];
       }
new file mode 100644
--- /dev/null
+++ b/intl/locale/tests/unit/test_bug1086527.js
@@ -0,0 +1,20 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * This unit test makes sure that PluralForm.get can be called from strict mode
+ */
+
+Components.utils.import("resource://gre/modules/PluralForm.jsm");
+
+delete PluralForm.numForms;
+delete PluralForm.get;
+[PluralForm.get, PluralForm.numForms] = PluralForm.makeGetter(9);
+
+function run_test() {
+  "use strict";
+
+  do_check_eq(3, PluralForm.numForms());
+  do_check_eq("one", PluralForm.get(5, 'one;many'));
+}
--- a/intl/locale/tests/unit/xpcshell.ini
+++ b/intl/locale/tests/unit/xpcshell.ini
@@ -5,11 +5,12 @@ skip-if = toolkit == 'gonk'
 
 [test_bug22310.js]
 run-if = toolkit == "windows" || toolkit == "cocoa"
 
 [test_bug371611.js]
 [test_bug374040.js]
 skip-if = toolkit == "windows" || toolkit == "cocoa"
 
+[test_bug1086527.js]
 [test_pluralForm.js]
 [test_pluralForm_english.js]
 [test_pluralForm_makeGetter.js]