提交 34e8117a 编写于 作者: K Kohsuke Kawaguchi

[JENKINS-11618] Adding back the 'toJSON' instance method.

This change, in parallel to a fix in stapler bind.js, would maximize the
backward compatibility.
上级 728fc8aa
......@@ -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');
}
......@@ -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,
......@@ -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;
......@@ -1227,6 +1241,7 @@ Array.from = $A;
reverse: reverse,
uniq: uniq,
intersect: intersect,
toJSON: toJSON,
clone: clone,
toArray: clone,
size: size,
......@@ -1337,6 +1352,10 @@ var Hash = Class.create(Enumerable, (function() {
}).join(', ') + '}>';
}
function toJSON() {
return this.toObject().toJSON();
}
function clone() {
return new Hash(this);
}
......@@ -1356,7 +1375,7 @@ var Hash = Class.create(Enumerable, (function() {
update: update,
toQueryString: toQueryString,
inspect: inspect,
toJSON: toObject,
toJSON: toJSON,
clone: clone
};
})());
......@@ -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);
}
......@@ -1402,6 +1425,7 @@ Object.extend(Number.prototype, (function() {
succ: succ,
times: times,
toPaddedString: toPaddedString,
toJSON: toJSON,
abs: abs,
round: round,
ceil: ceil,
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册