зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1049041 - Remove scary warning about mutating [[Prototype]]. r=efaust.
--HG-- extra : commitid : JkYGz4dusnf extra : rebase_source : e23ad9b51c9b5f0049edd96ca3cb1fea879b3289
This commit is contained in:
Родитель
6d35e13d40
Коммит
aa43ed96ab
|
@ -383,10 +383,6 @@ obj_setPrototypeOf(JSContext* cx, unsigned argc, Value* vp)
|
|||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
RootedObject setPrototypeOf(cx, &args.callee());
|
||||
if (!GlobalObject::warnOnceAboutPrototypeMutation(cx, setPrototypeOf))
|
||||
return false;
|
||||
|
||||
if (args.length() < 2) {
|
||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_MORE_ARGS_NEEDED,
|
||||
"Object.setPrototypeOf", "1", "");
|
||||
|
@ -1054,13 +1050,6 @@ ProtoSetter(JSContext* cx, unsigned argc, Value* vp)
|
|||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
// Do this here, rather than after the this-check so even likely-buggy
|
||||
// use of the __proto__ setter on unacceptable values, where no subsequent
|
||||
// use occurs on an acceptable value, will trigger a warning.
|
||||
RootedObject callee(cx, &args.callee());
|
||||
if (!GlobalObject::warnOnceAboutPrototypeMutation(cx, callee))
|
||||
return false;
|
||||
|
||||
HandleValue thisv = args.thisv();
|
||||
if (thisv.isNullOrUndefined()) {
|
||||
ReportIncompatible(cx, args);
|
||||
|
|
|
@ -76,7 +76,6 @@ MSG_DEF(JSMSG_BAD_SURROGATE_CHAR, 1, JSEXN_TYPEERR, "bad surrogate characte
|
|||
MSG_DEF(JSMSG_UTF8_CHAR_TOO_LARGE, 1, JSEXN_TYPEERR, "UTF-8 character {0} too large")
|
||||
MSG_DEF(JSMSG_MALFORMED_UTF8_CHAR, 1, JSEXN_TYPEERR, "malformed UTF-8 character sequence at offset {0}")
|
||||
MSG_DEF(JSMSG_BUILTIN_CTOR_NO_NEW, 1, JSEXN_TYPEERR, "calling a builtin {0} constructor without new is forbidden")
|
||||
MSG_DEF(JSMSG_PROTO_SETTING_SLOW, 0, JSEXN_NONE, "mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create")
|
||||
MSG_DEF(JSMSG_BAD_GENERATOR_YIELD, 1, JSEXN_TYPEERR, "yield from closing generator {0}")
|
||||
MSG_DEF(JSMSG_EMPTY_ARRAY_REDUCE, 0, JSEXN_TYPEERR, "reduce of empty array with no initial value")
|
||||
MSG_DEF(JSMSG_UNEXPECTED_TYPE, 2, JSEXN_TYPEERR, "{0} is {1}")
|
||||
|
|
|
@ -9,14 +9,15 @@ print(BUGNUMBER + ": " + summary);
|
|||
|
||||
enableLastWarning();
|
||||
|
||||
eval(`({}).__proto__ = {};`);
|
||||
let line0 = new Error().lineNumber;
|
||||
assertEq("foo".contains("bar"), false);
|
||||
|
||||
var warning = getLastWarning();
|
||||
assertEq(warning !== null, true);
|
||||
assertEq(warning.name, "None");
|
||||
assertEq(warning.message.includes("mutating"), true);
|
||||
assertEq(warning.lineNumber, 1);
|
||||
assertEq(warning.columnNumber, 2);
|
||||
assertEq(warning.message.includes("deprecated"), true);
|
||||
assertEq(warning.lineNumber, line0 + 1);
|
||||
assertEq(warning.columnNumber, 10);
|
||||
|
||||
// Clear last warning.
|
||||
|
||||
|
|
|
@ -135,8 +135,7 @@ class GlobalObject : public NativeObject
|
|||
|
||||
enum WarnOnceFlag : int32_t {
|
||||
WARN_WATCH_DEPRECATED = 1 << 0,
|
||||
WARN_PROTO_SETTING_SLOW = 1 << 1,
|
||||
WARN_STRING_CONTAINS_DEPRECATED = 1 << 2,
|
||||
WARN_STRING_CONTAINS_DEPRECATED = 1 << 1,
|
||||
};
|
||||
|
||||
// Emit the specified warning if the given slot in |obj|'s global isn't
|
||||
|
@ -699,12 +698,6 @@ class GlobalObject : public NativeObject
|
|||
return true;
|
||||
}
|
||||
|
||||
// Warn about use of the given __proto__ setter to attempt to mutate an
|
||||
// object's [[Prototype]], if no prior warning was given.
|
||||
static bool warnOnceAboutPrototypeMutation(JSContext* cx, HandleObject protoSetter) {
|
||||
return warnOnceAbout(cx, protoSetter, WARN_PROTO_SETTING_SLOW, JSMSG_PROTO_SETTING_SLOW);
|
||||
}
|
||||
|
||||
// Warn about use of the deprecated String.prototype.contains method
|
||||
static bool warnOnceAboutStringContains(JSContext* cx, HandleObject strContains) {
|
||||
return warnOnceAbout(cx, strContains, WARN_STRING_CONTAINS_DEPRECATED,
|
||||
|
|
|
@ -31,11 +31,11 @@ namespace js {
|
|||
*
|
||||
* (If you're wondering, 0xb973c0de is used because it looks like "bytecode".)
|
||||
*/
|
||||
static const uint32_t XDR_BYTECODE_VERSION_SUBTRAHEND = 353;
|
||||
static const uint32_t XDR_BYTECODE_VERSION_SUBTRAHEND = 354;
|
||||
static const uint32_t XDR_BYTECODE_VERSION =
|
||||
uint32_t(0xb973c0de - XDR_BYTECODE_VERSION_SUBTRAHEND);
|
||||
|
||||
static_assert(JSErr_Limit == 420,
|
||||
static_assert(JSErr_Limit == 419,
|
||||
"GREETINGS, POTENTIAL SUBTRAHEND INCREMENTER! If you added or "
|
||||
"removed MSG_DEFs from js.msg, you should increment "
|
||||
"XDR_BYTECODE_VERSION_SUBTRAHEND and update this assertion's "
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1021258
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 1021258</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for proto mutation warnings. **/
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
var gLoads = 0;
|
||||
function loaded() {
|
||||
switch (++gLoads) {
|
||||
case 1:
|
||||
info("First load");
|
||||
SimpleTest.monitorConsole(function() { window[0].location.reload(true); },
|
||||
[ { message: /mutating/ } ], /* forbidUnexpectedMessages = */ true);
|
||||
window[0].eval('var foo = {}; Object.setPrototypeOf(foo, {});' +
|
||||
'var bar = {}; Object.getPrototypeOf(bar, {});');
|
||||
SimpleTest.endMonitorConsole();
|
||||
break;
|
||||
case 2:
|
||||
info("Second load");
|
||||
SimpleTest.monitorConsole(SimpleTest.finish.bind(SimpleTest),
|
||||
[ { message: /mutating/ } ], /* forbidUnexpectedMessages = */ true);
|
||||
window[0].eval('var foo = {}; foo.__proto__ = {};' +
|
||||
'var bar = {}; bar.__proto__ = {};');
|
||||
SimpleTest.endMonitorConsole();
|
||||
break;
|
||||
case 3:
|
||||
ok(false, "Shouldn't have 3 loads!");
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1021258">Mozilla Bug 1021258</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
<iframe id="ifr" src="file_empty.html" onload="loaded();"></iframe>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче