deprecation extension: mark Array#reduce() as removed. [#569 state:resolved] (Tobie Langel)

This commit is contained in:
Tobie Langel 2009-03-23 16:06:01 +01:00
parent 0b4e142d8a
commit 827e6ee1ae
3 changed files with 29 additions and 3 deletions

View File

@ -1,3 +1,5 @@
* deprecation extension: mark Array#reduce() as removed. [#569 state:resolved] (Tobie Langel)
* `Form.serialize` now works safely with forms that have "length"-named elements. [#77 state:resolved] (Peter Adrianov, John-David Dalton, kangax)
* `Element#update` now takes care of SCRIPT elements in IE. [#573 state:resolved] (Martin, Tobie Langel, kangax)

View File

@ -6,8 +6,8 @@
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="../../dist/prototype.js" type="text/javascript"></script>
<script src="../../dist/prototype_update_helper.js" type="text/javascript"></script>
<script src="../../test/lib/unittest.js" type="text/javascript"></script>
<link rel="stylesheet" href="../../test/test.css" type="text/css" />
<script src="../../vendor/unittest_js/assets/unittest.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="../../vendor/unittest_js/assets/unittest.css" type="text/css" charset="utf-8" />
</head>
<body>
<h1>Prototype Unit test file</h1>
@ -259,6 +259,14 @@
this.assertRespondsTo('toJSON', h)
},
testArray: function() {
var a = [0, 1, 2, 3];
a.reduce(function(){});
this.assertErrorNotified('Array#reduce is no longer supported.\n' +
'This is due to an infortunate naming collision with Mozilla\'s soon to be standardized (as of EcmaScript 3.1) Array#reduce implementation (whhich is similar to Prototype\'s Array#inject).')
},
testClass: function() {
Class.create();
this.assertInfoNotified('The class API has been fully revised and now allows for mixins and inheritance.\n' +

View File

@ -253,6 +253,14 @@ var prototypeUpdateHelper = new UpdateHelper([
type: 'warn'
},
{
methodName: 'reduce',
namespace: Array.prototype,
message: 'Array#reduce is no longer supported.\n' +
'This is due to an infortunate naming collision with Mozilla\'s soon to be standardized (as of EcmaScript 3.1) Array#reduce implementation (whhich is similar to Prototype\'s Array#inject).',
type: 'error'
},
{
methodName: 'unloadCache',
namespace: Event,
@ -290,6 +298,7 @@ var prototypeUpdateHelper = new UpdateHelper([
}
function defineSetters(obj, prop) {
storeProperties(obj);
if (obj.__properties.include(prop)) return;
obj.__properties.push(prop);
obj.__defineGetter__(prop, function() {
@ -303,6 +312,7 @@ var prototypeUpdateHelper = new UpdateHelper([
}
function checkProperties(hash) {
storeProperties(hash);
var current = Object.keys(hash);
if (current.length == hash.__properties.length)
return;
@ -313,6 +323,12 @@ var prototypeUpdateHelper = new UpdateHelper([
});
}
function storeProperties(h) {
if (typeof h.__properties === 'undefined')
h.__properties = __properties.clone();
return h;
}
Hash.prototype.set = Hash.prototype.set.wrap(function(proceed, property, value) {
defineSetters(this, property);
return proceed(property, value);
@ -335,7 +351,7 @@ var prototypeUpdateHelper = new UpdateHelper([
});
Hash.prototype.initialize = Hash.prototype.initialize.wrap(function(proceed, object) {
this.__properties = __properties.clone();
storeProperties(this);
for (var prop in object) defineSetters(this, prop);
proceed(object);
});