Native JSON breakage

20 views
Skip to first unread message

Bob Aman

unread,
Nov 30, 2009, 8:47:04 PM11/30/09
to prototy...@googlegroups.com
Tobie et al,

Currently, large sections of the Google JavaScript APIs, most notably
the Friend Connect bits, are being broken in FF 3.5 anytime that
Prototype also appears on a page. (Typically WordPress sites.) This
is causing all kinds of support issues because it's easily
misdiagnosed as some other bug. Is there any chance that this can be
resolved in a 1.6 point release rather than waiting until 1.7?

Associated bugs:
https://prototype.lighthouseapp.com/projects/8886/tickets/453
https://prototype.lighthouseapp.com/projects/8886/tickets/730-prototypejs-breaks-firefox-35-native-json

-Bob Aman
Developer Programs Engineer
Google Friend Connect

Yaffle

unread,
Dec 1, 2009, 7:40:46 AM12/1/09
to Prototype: Core
Add this code after prototype.js =). Also this code replaces FF 3.5
Native JSON.stringify with ES compatible...
It breaks compatibility!

delete String.prototype.toJSON; //! deleting this properties required
to save FF 3.5 Native JSON.stringify
delete Array.prototype.toJSON; //!
delete Number.prototype.toJSON;

Hash.prototype.toJSON = function() {
return this.toObject();
};

Date.prototype.toISOString = function() {
return this.getUTCFullYear() + '-' +
(this.getUTCMonth() + 1).toPaddedString(2) + '-' +
this.getUTCDate().toPaddedString(2) + 'T' +
this.getUTCHours().toPaddedString(2) + ':' +
this.getUTCMinutes().toPaddedString(2) + ':' +
this.getUTCSeconds().toPaddedString(2) + '.' +
this.getUTCMilliseconds().toPaddedString(3) + 'Z';
};

Date.prototype.toJSON = function(key) {
return (Object.isNumber(this) && !isFinite(this) ? null :
this.toISOString());
};

Object.isBoolean = function(object) {
return Object.prototype.toString.call(object) === "[object
Boolean]";
};

Object.toJSON = (function() {
var stack, gap, propertyList, replacerFunction;

function quote(string) {
return String(string).inspect(true);
}
function str(key, holder, indent) {
var value = holder[key];

if (value !== null && (typeof value === 'object' || typeof value
=== 'function') && Object.isFunction(value.toJSON)) {
value = value.toJSON(key);
}

if (Object.isElement(value)) { return; }

value = replacerFunction.call(holder, key, value);

if (value === null || Object.isBoolean(value)) {
return String(value);
}

if (Object.isString(value)) {
return quote(value);
}

if (Object.isNumber(value)) {
return (isFinite(value) ? String(value) : 'null');
}

if (typeof value === 'object') {
if (stack.indexOf(value) !== -1) {
throw new TypeError();
}
stack.push(value);

var partial = [],
braces = ['{', '}'], i, strP, length, k;

if (Object.isArray(value)) {
braces = ['[', ']'];
for(i = 0, length = value.length; i < length; i++) {
strP = str(i, value, indent + gap);
partial.push(Object.isUndefined(strP) ? 'null' : strP);
}
} else {
k = propertyList || Object.keys(value);
for(i = 0, length = k.length; i < length; i++) {
strP = str(k[i], value, indent + gap);
if (!Object.isUndefined(strP)) {
partial.push(quote(k[i]) + (gap ? ': ' : ':') + strP);
}
}
}

stack.pop();
return braces[0] + (partial.length && gap ? '\n' + indent + gap
+ partial.join(',\n' + indent + gap) + '\n' + indent : partial.join
(',')) + braces[1];
}
}

return function(value /*, replacer, space */) {
var replacer = arguments[1],
space = arguments[2] || '';
stack = [];

replacerFunction = (Object.isFunction(replacer) ? replacer :
function(k, v) { return v; });

if (Object.isArray(replacer)) {
var hash = {};
propertyList = replacer.inject([], function(array, v) {
if ((Object.isString(v) || Object.isNumber(v)) && !
hash.hasOwnProperty(' ' + v)) {
hash[' ' + v] = 1;
array.push(String(v));
}
return array;
});
} else {
propertyList = null;
}

if (Object.isNumber(space)) {
space = Math.min(Math.floor(+space) || 0, 10);
gap = ' '.times(space);
} else if (Object.isString(space)) {
gap = space.substr(0, 10);
} else {
gap = '';
}

return str('', {'': value}, '');
};
}());

(window.JSON = window.JSON || {}).stringify = Object.toJSON;// FF 3.5
uses diff. implementation

Bob Aman

unread,
Dec 1, 2009, 12:50:33 PM12/1/09
to prototy...@googlegroups.com
> Add this code after prototype.js =)

Thus far, this is the technique we've already been advocating, though
in considerably shorter form. It's a stop-gap measure at best, and
brittle at worst. However, my issue here is that while we're waiting
for a newer version of Prototype, more sites are deploying the current
version, and every time they do, that's one more site that's now
incompatible with some of our APIs. Plus, there's not exactly an
auto-update feature for JavaScript libraries. For every user that
contacts our support team (and hopefully, gets correctly diagnosed and
given a fix) there are ten more that give up before even talking to
support. Of those ten users, most will assume the problem is Google's
fault, because the visible breakage happens in our code even though
the bug is Prototype's. I'm happy to contribute patches or do
whatever you guys need to make this fix happen.

-Bob Aman

Yaffle

unread,
Dec 1, 2009, 1:42:46 PM12/1/09
to Prototype: Core
I'm waiting prototype.js 1.7 too.

Tobie Langel

unread,
Dec 1, 2009, 6:19:52 PM12/1/09
to Prototype: Core
Hi, Bob.

Thanks for your post.

We'll be including fixes for native JSON in Prototype 1.7, a
prerelease of which is just around the corner.

I understand your frustration with this issue. It's on our top
priority list.

Best,

Tobie

Bob Aman

unread,
Dec 1, 2009, 6:37:08 PM12/1/09
to prototy...@googlegroups.com
> We'll be including fixes for native JSON in Prototype 1.7, a
> prerelease of which is just around the corner.

"Just around the corner" means different things on different projects.
Are we talking weeks, months? I'm trying to determine if Google
should be spending some engineering time on detecting and
auto-resolving the issue on our end or if it's better to wait for
1.7's release or a 1.6 point release and just ask users to upgrade to
resolve.

-Bob Aman

David Kaufman

unread,
Dec 2, 2009, 8:31:49 AM12/2/09
to prototy...@googlegroups.com
Hi Bob,

I'm sure there are a few things Google could do:

Bob Aman <bob...@google.com> wrote:
> [...] my issue here is that while we're waiting
> for a newer version of Prototype, more sites are deploying the current
> version, and every time they do, that's one more site that's now
> incompatible with some of our APIs. Plus, there's not exactly an
> auto-update feature for JavaScript libraries.

Sure there is (and Google provides it):

Prototype hosted on Google's servers
http://tinyurl.com/google-hosted-prototype

I guess the left hand doesn't always know what the right hand is doing
in an organization as large as Google :-)

> For every user that contacts our support team (and hopefully, gets
> correctly diagnosed and given a fix) there are ten more that give up
> before even talking to support. Of those ten users, most will assume
> the problem is Google's fault, because the visible breakage happens
> in our code even though the bug is Prototype's.

Why not enhance (and future-proof!) the Google Friend Connect code,
right where it fails, to simply check the (by now, already loaded)
Prototype.Version number, and if it's the version with the bug, throw an
error which says something helpful like:

Detected Prototype 1.6.1: This version of Prototype is not
compatible with Google Friend Connect. To resolve this issue:

A. Upgrade to the a newer release of Prototype

B. Run out patched version of Prototype 1.6 hosted at
http://ajax.googleapis.com/prototype/1.6-patched/prototype.js

C. See our http://support.url for more info, and other ways to
work-around the bug, and resolve this issue.

> I'm happy to contribute patches or do
> whatever you guys need to make this fix happen.

Mailing Tobie and Andrew bags of cash, or giving them great-paying
no-show jobs at Google probably couldn't hurt either :-)

-dave

Richard Quadling

unread,
Dec 2, 2009, 8:36:40 AM12/2/09
to prototy...@googlegroups.com
2009/12/2 David Kaufman <da...@gigawatt.com>:

> Mailing Tobie and Andrew bags of cash, or giving them great-paying
> no-show jobs at Google probably couldn't hurt either :-)

I wouldn't mind one of those great-paying jobs. I'll turn up! I'll
even wear the t-shirt.

--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

Tom Gregory

unread,
Dec 2, 2009, 11:21:28 AM12/2/09
to prototy...@googlegroups.com

On Dec 2, 2009, at 8:36 AM, Richard Quadling wrote:

> 2009/12/2 David Kaufman <da...@gigawatt.com>:
>
>> Mailing Tobie and Andrew bags of cash, or giving them great-paying
>> no-show jobs at Google probably couldn't hurt either :-)
>
> I wouldn't mind one of those great-paying jobs. I'll turn up! I'll
> even wear the t-shirt.
>
> --
> -----
> Richard Quadling

I'm sorry, but by volunteering to show up for a no-show job, you've violated the terms of employment, and are thus no-longer eligible for this position.

I, on the other hand, promise to not show up.

=)


TAG

Bob Aman

unread,
Dec 2, 2009, 12:34:10 PM12/2/09
to prototy...@googlegroups.com
> Sure there is (and Google provides it):
>
>   Prototype hosted on Google's servers
>   http://tinyurl.com/google-hosted-prototype
>
> I guess the left hand doesn't always know what the right hand is doing
> in an organization as large as Google :-)

You misunderstand. I'm well aware of this service, but the vast
majority of the people I've seen with this problem are hosting the
file themselves. And in most cases, that means we still have to
diagnose the problem and ask them to upgrade once there's an upgrade
available.

>  > For every user that contacts our support team (and hopefully, gets
>> correctly diagnosed and given a fix) there are ten more that give up
>> before even talking to support.  Of those ten users, most will assume
>> the problem is Google's fault, because the visible breakage happens
>> in our code even though the bug is Prototype's.
>
> Why not enhance (and future-proof!) the Google Friend Connect code,
> right where it fails, to simply check the (by now, already loaded)
> Prototype.Version number, and if it's the version with the bug, throw an
> error which says something helpful like:
>
>   Detected Prototype 1.6.1: This version of Prototype is not
>   compatible with Google Friend Connect.  To resolve this issue:
>
>   A. Upgrade to the a newer release of Prototype
>
>   B. Run out patched version of Prototype 1.6 hosted at
>      http://ajax.googleapis.com/prototype/1.6-patched/prototype.js
>
>   C. See our http://support.url for more info, and other ways to
>      work-around the bug, and resolve this issue.

Hmm, that's actually a good point. It's a lot less likely to be
brittle and has the desired effect.

>> I'm happy to contribute patches or do
>> whatever you guys need to make this fix happen.
>
> Mailing Tobie and Andrew bags of cash, or giving them great-paying
> no-show jobs at Google probably couldn't hurt either :-)

We're hiring, they're more than welcome to apply. :-)

-Bob Aman
Reply all
Reply to author
Forward
0 new messages