Skip to content

Commit

Permalink
deprecation extension: mark Array#reduce() as removed. [#569 state:re…
Browse files Browse the repository at this point in the history
…solved] (Tobie Langel)
  • Loading branch information
tobie committed Mar 23, 2009
1 parent 0b4e142 commit 827e6ee
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -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)
Expand Down
12 changes: 10 additions & 2 deletions ext/update_helper/prototype_update_helper.html
Expand Up @@ -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>
Expand Down Expand Up @@ -259,6 +259,14 @@ <h1>Prototype Unit test file</h1>
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).')

This comment has been minimized.

Copy link
@kangax

kangax Mar 23, 2009

Collaborator

Maybe also mention that Array#reduce is not only included in ES3.1 draft but that, more importantly, is already implemented in JS1.8 which is part of a quite rapidly growing Firefox 3.x (afaik, FF2 is no longer officially supported)

},

testClass: function() {
Class.create();
this.assertInfoNotified('The class API has been fully revised and now allows for mixins and inheritance.\n' +
Expand Down
18 changes: 17 additions & 1 deletion ext/update_helper/prototype_update_helper.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
});
Expand Down

1 comment on commit 827e6ee

@tobie
Copy link
Collaborator Author

@tobie tobie commented on 827e6ee Mar 23, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.