/** Test for Bug 793969 **/
function checkThrows(f, desc, skipMessageCheck) {
try {
f();
ok(false, "Should have thrown for " + desc);
} catch (e) {
ok(true, "threw correctly");
if (!skipMessageCheck)
ok(/denied/.exec(e) ||
/can't redefine non-configurable property/.exec(e), "Correctly threw a security exception: " + e);
}
}
// NB: These sets will be no-ops (throw in strict mode) because setting an inherited readonly value prop has those semantics.
checkThrows(function() { "use strict"; location.valueOf = 'hah'; }, 'Shadow with string', /* skipMessageCheck = */ true);
checkThrows(function() { "use strict"; location.valueOf = function() { return {a: 'hah'};} }, 'Shadow with function', /* skipMessageCheck = */ true);
checkThrows(function() { Object.defineProperty(location, 'valueOf', { value: function() { return 'hah'; } }); }, 'defineProperty with value');
checkThrows(function() { delete location.valueOf; Object.defineProperty(location, 'valueOf', { value: function() { return 'hah'; } }); }, 'delete + defineProperty with value');
checkThrows(function() { Object.defineProperty(location, 'valueOf', { get: function() { return 'hah'; } }); }, 'defineProperty with getter');
checkThrows(function() { delete location.valueOf; Object.defineProperty(location, 'valueOf', { get: function() { return 'hah'; } }); }, 'delete + defineProperty with getter');
Object.prototype.valueOf = function() { return 'hah'; };
is(({}).valueOf(), 'hah', "Shadowing on Object.prototype works for vanilla objects");
is(location.valueOf(), location, "Shadowing on Object.prototype and Location.prototype doesn't for location objects");
location[Symbol.toPrimitive] = function() { return 'hah'; }
is(location + "", location.toString(), "Should't be able to shadow with toPrimitive");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.