From eea1f5cc9b0a69012b9f66cb1d05d50d0b087f3b Mon Sep 17 00:00:00 2001 From: Cosmin Malutan Date: Thu, 23 Oct 2014 23:29:00 +0200 Subject: [PATCH] Bug 1086527 - Make sure PluralForm.get can be called from strict mode. r=Mossop --- intl/locale/PluralForm.jsm | 2 +- intl/locale/tests/unit/test_bug1086527.js | 20 ++++++++++++++++++++ intl/locale/tests/unit/xpcshell.ini | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 intl/locale/tests/unit/test_bug1086527.js diff --git a/intl/locale/PluralForm.jsm b/intl/locale/PluralForm.jsm index 36f3471896a7..d1ee8ea0d81f 100644 --- a/intl/locale/PluralForm.jsm +++ b/intl/locale/PluralForm.jsm @@ -135,7 +135,7 @@ this.PluralForm = { // 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, diff --git a/intl/locale/tests/unit/test_bug1086527.js b/intl/locale/tests/unit/test_bug1086527.js new file mode 100644 index 000000000000..ae0c5b17a276 --- /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')); +} diff --git a/intl/locale/tests/unit/xpcshell.ini b/intl/locale/tests/unit/xpcshell.ini index d97a93fb3e64..06d23bf49a83 100644 --- a/intl/locale/tests/unit/xpcshell.ini +++ b/intl/locale/tests/unit/xpcshell.ini @@ -13,6 +13,7 @@ skip-if = toolkit == "windows" || toolkit == "cocoa" [test_collation_mac_icu.js] run-if = toolkit == "cocoa" +[test_bug1086527.js] [test_pluralForm.js] [test_pluralForm_english.js] [test_pluralForm_makeGetter.js]