Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-11618] Adding back the 'toJSON' instance method.
This change, in parallel to a fix in stapler bind.js, would maximize the
backward compatibility.
  • Loading branch information
kohsuke committed Mar 2, 2012
1 parent 728fc8a commit 34e8117
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions war/src/main/webapp/scripts/prototype.js
Expand Up @@ -711,6 +711,10 @@ Object.extend(String.prototype, (function() {
return "'" + escapedString.replace(/'/g, '\\\'') + "'";
}

function toJSON() {
return this.inspect(true);
}

function unfilterJSON(filter) {
return this.replace(filter || Prototype.JSONFilter, '$1');
}
Expand Down Expand Up @@ -791,6 +795,7 @@ Object.extend(String.prototype, (function() {
dasherize: dasherize,
inspect: inspect,
unfilterJSON: unfilterJSON,
toJSON: toJSON,
isJSON: isJSON,
evalJSON: NATIVE_JSON_PARSE_SUPPORT ? parseJSON : evalJSON,
include: include,
Expand Down Expand Up @@ -1182,6 +1187,15 @@ Array.from = $A;
return '[' + this.map(Object.inspect).join(', ') + ']';
}

function toJSON() {
var results = [];
this.each(function(object) {
var value = Object.toJSON(object);
if (value !== undefined) results.push(value);
});
return '[' + results.join(', ') + ']';
}

function indexOf(item, i) {
i || (i = 0);
var length = this.length;
Expand Down Expand Up @@ -1227,6 +1241,7 @@ Array.from = $A;
reverse: reverse,
uniq: uniq,
intersect: intersect,
toJSON: toJSON,
clone: clone,
toArray: clone,
size: size,
Expand Down Expand Up @@ -1337,6 +1352,10 @@ var Hash = Class.create(Enumerable, (function() {
}).join(', ') + '}>';
}

function toJSON() {
return this.toObject().toJSON();
}

function clone() {
return new Hash(this);
}
Expand All @@ -1356,7 +1375,7 @@ var Hash = Class.create(Enumerable, (function() {
update: update,
toQueryString: toQueryString,
inspect: inspect,
toJSON: toObject,
toJSON: toJSON,
clone: clone
};
})());
Expand All @@ -1381,6 +1400,10 @@ Object.extend(Number.prototype, (function() {
return '0'.times(length - string.length) + string;
}

function toJSON() {
return isFinite(this) ? this.toString() : 'null';
}

function abs() {
return Math.abs(this);
}
Expand All @@ -1402,6 +1425,7 @@ Object.extend(Number.prototype, (function() {
succ: succ,
times: times,
toPaddedString: toPaddedString,
toJSON: toJSON,
abs: abs,
round: round,
ceil: ceil,
Expand Down Expand Up @@ -1507,7 +1531,7 @@ Ajax.Base = Class.create({

if (Object.isHash(this.options.parameters))
this.options.parameters = this.options.parameters.toObject();

// KK patch -- handle crumb for POST automatically by adding a header
if(this.options.method=="post") {
if(this.options.requestHeaders==undefined)
Expand Down

0 comments on commit 34e8117

Please sign in to comment.