From 40ae057c1d4f1faff51cccbb3eecb36c5372010a Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Sat, 14 Dec 2013 22:29:53 -0500 Subject: [PATCH] Bug 843004 - Make detecting-ful evaluations of undefined properties in self-hosted code not warn, so that self-hosted code can use that pattern when it wants to. r=jorendorff --HG-- extra : rebase_source : da9765d3ccf46758101d082b01de761c5ceed14e --- js/src/jsobj.cpp | 8 +++++ js/src/tests/Intl/extensions/browser.js | 0 .../options-value-emulates-undefined.js | 29 +++++++++++++++++++ js/src/tests/Intl/extensions/shell.js | 0 .../extensions/selfhosted-detecting-strict.js | 27 +++++++++++++++++ 5 files changed, 64 insertions(+) create mode 100644 js/src/tests/Intl/extensions/browser.js create mode 100644 js/src/tests/Intl/extensions/options-value-emulates-undefined.js create mode 100644 js/src/tests/Intl/extensions/shell.js create mode 100644 js/src/tests/js1_8_5/extensions/selfhosted-detecting-strict.js diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index 5decfbdef895..795e88dd779d 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -4200,6 +4200,14 @@ GetPropertyHelperInline(JSContext *cx, if (!script || script->warnedAboutUndefinedProp()) return true; + /* + * Don't warn in self-hosted code (where the further presence of + * JS::ContextOptions::werror() would result in impossible-to-avoid + * errors to entirely-innocent client code). + */ + if (script->selfHosted()) + return true; + /* We may just be checking if that object has an iterator. */ if (JSID_IS_ATOM(id, cx->names().iteratorIntrinsic)) return true; diff --git a/js/src/tests/Intl/extensions/browser.js b/js/src/tests/Intl/extensions/browser.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/js/src/tests/Intl/extensions/options-value-emulates-undefined.js b/js/src/tests/Intl/extensions/options-value-emulates-undefined.js new file mode 100644 index 000000000000..e7af6a4860de --- /dev/null +++ b/js/src/tests/Intl/extensions/options-value-emulates-undefined.js @@ -0,0 +1,29 @@ +// |reftest| skip-if(!xulRuntime.shell) +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 843004; +var summary = + "Use of an object that emulates |undefined| as the sole option must " + + "preclude imputing default values"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +var opt = objectEmulatingUndefined(); +opt.toString = function() { return "long"; }; + +var str = new Date(2013, 12 - 1, 14).toLocaleString("en-US", { weekday: opt }); + +// Because "weekday" was present and not undefined (stringifying to "long"), +// this must be a string like "Saturday" (in this implementation, that is). +assertEq(str, "Saturday"); + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("Tests complete"); diff --git a/js/src/tests/Intl/extensions/shell.js b/js/src/tests/Intl/extensions/shell.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/js/src/tests/js1_8_5/extensions/selfhosted-detecting-strict.js b/js/src/tests/js1_8_5/extensions/selfhosted-detecting-strict.js new file mode 100644 index 000000000000..cb4c026eaa83 --- /dev/null +++ b/js/src/tests/js1_8_5/extensions/selfhosted-detecting-strict.js @@ -0,0 +1,27 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 843004; +var summary = + "Don't emit a strict warning for the undefined-property detection pattern in self-hosted code"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +options("strict", "werror"); + +// Don't strict-warn (and throw, because of strict) when self-hosted code uses +// detecting-safe undefined-property accesses (|options.weekday !== undefined| +// and similar in ToDateTimeOptions, to be precise). +new Date().toLocaleString("en-US", {}); + +// If we get here, the test passed. + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("Tests complete");