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
This commit is contained in:
Jeff Walden 2013-12-14 22:29:53 -05:00
Родитель 990a0c99a7
Коммит 40ae057c1d
5 изменённых файлов: 64 добавлений и 0 удалений

Просмотреть файл

@ -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;

Просмотреть файл

Просмотреть файл

@ -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");

Просмотреть файл

Просмотреть файл

@ -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");