[Prototype-core] Re: Making Joose compatible with Prototype
I know... only our API was mapped against the original one (which was at the time expected to go as is in ES 4). Thus we choose shorter names to avoid conflicting with the original toJSONString methods. Etc. Now that JSON has been formalized in ES 3.1, we'll be migrating to it probably for Prototype 2.0. Best, Tobie On Nov 19, 10:24 pm, "Malte Ubl" <[EMAIL PROTECTED]> wrote: > Might still be maintained buthttp://json.org/json2.jshas been > recommended for quite a while. json.js was severely broken, indeed. > > On Wed, Nov 19, 2008 at 10:20 PM, Tobie Langel <[EMAIL PROTECTED]> wrote: > > > Very old as in may 2008 ?http://json.org/json.js > > > ;) > > > On Nov 19, 10:10 pm, "Malte Ubl" <[EMAIL PROTECTED]> wrote: > >> OK, I turned to reading the docs :)http://www.prototypejs.org/learn/json > >> Although, they refer to a very old version of Crockford's json lib > >> which no longer extends Object.prototype the conclusion probably holds > >> true. > > >> Anyway, is there a way to have json2.js and prototype play nice with each > >> other? > > >> On Wed, Nov 19, 2008 at 9:40 PM, Malte Ubl <[EMAIL PROTECTED]> wrote: > >> > Hey, > > >> > is Prototype designed to use a built in JSON stringification mechanism? > > >> > The most popular library, json2.js (http://json.org/json2.js), states > >> > pretty clearly that the toJSON method is not supposed to return a > >> > serialized result (which it would turn into a string) but should > >> > rather return something that can be automatically stringified by the > >> > library itself. That might be any kind of value, but besides that it > >> > can be also be instances of Object. Joose.Storage thus returns an > >> > Object that represents the state of the Joose object and which > >> > includes extra info that can be used for reinstantiation. The nice > >> > side effect of this is, that complex structures of nested objects are > >> > no problem because the stringifier will once again call toJSON on the > >> > children (if toJSON would return a string it would have to implement > >> > this itself). > > >> > If Prototype does indeed need a more complex toJSON method, we could, > >> > of course, detect that and change our behavior. > > >> > Bye > >> > Malte > >> > -- > >> >http://code.google.com/p/joose-js/ > >> >http://blok.appspot.com/ > > >> > On Wed, Nov 19, 2008 at 3:51 PM, kangax <[EMAIL PROTECTED]> wrote: > > >> >> On Nov 15, 4:48 pm, "Malte Ubl" <[EMAIL PROTECTED]> wrote: > >> >> [...] > >> >>> The source code of the test is located > >> >>> athttp://code.google.com/p/joose-js/source/browse/trunk/tests/12_storag... > >> >>> Interestingly the statement at line 49 succeeds. (It stringifies a > >> >>> Joose object to JSON and and deserializes it again) > >> >>> The statement on line 81, howevery, fails to produce correct JSON. The > >> >>> produced string looks like this: > >> >>> {"test":"[[object Object]]","another":{"a":1} > > >> >>> When you set a firebug break point in Storage.js line 11 you can see > >> >>> that the code goes deeply into Prototype.js territory. > > >> >> The "joose" object (the one that's being tested against) seems to have > >> >> `toJSON` method: > > >> >> function () { > >> >> return this.pack(Joose.Storage.TEMP_SEEN); > >> >> } > > >> >> That method seems to return an object, rather than a string > >> >> representation of an object. Prototype's `Object.toJSON` just happens > >> >> to delegate its logic to passed object's `toJSON` (effectively letting > >> >> "joose" object decide "what to do"). "joose" object returned from > >> >> `toJSON` is then turned into "[[object Object]]" via > >> >> `Array.prototype.join` invoked on an array it's contained within (join > >> >> performs `toString` on each of array's items, if I'm not mistaken). > > >> >>> Bye > >> >>> Malte > > >> >> [...] > > >> >> -- > >> >> kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Making Joose compatible with Prototype
Might still be maintained but http://json.org/json2.js has been recommended for quite a while. json.js was severely broken, indeed. On Wed, Nov 19, 2008 at 10:20 PM, Tobie Langel <[EMAIL PROTECTED]> wrote: > > Very old as in may 2008 ? http://json.org/json.js > > ;) > > On Nov 19, 10:10 pm, "Malte Ubl" <[EMAIL PROTECTED]> wrote: >> OK, I turned to reading the docs :)http://www.prototypejs.org/learn/json >> Although, they refer to a very old version of Crockford's json lib >> which no longer extends Object.prototype the conclusion probably holds >> true. >> >> Anyway, is there a way to have json2.js and prototype play nice with each >> other? >> >> On Wed, Nov 19, 2008 at 9:40 PM, Malte Ubl <[EMAIL PROTECTED]> wrote: >> > Hey, >> >> > is Prototype designed to use a built in JSON stringification mechanism? >> >> > The most popular library, json2.js (http://json.org/json2.js), states >> > pretty clearly that the toJSON method is not supposed to return a >> > serialized result (which it would turn into a string) but should >> > rather return something that can be automatically stringified by the >> > library itself. That might be any kind of value, but besides that it >> > can be also be instances of Object. Joose.Storage thus returns an >> > Object that represents the state of the Joose object and which >> > includes extra info that can be used for reinstantiation. The nice >> > side effect of this is, that complex structures of nested objects are >> > no problem because the stringifier will once again call toJSON on the >> > children (if toJSON would return a string it would have to implement >> > this itself). >> >> > If Prototype does indeed need a more complex toJSON method, we could, >> > of course, detect that and change our behavior. >> >> > Bye >> > Malte >> > -- >> >http://code.google.com/p/joose-js/ >> >http://blok.appspot.com/ >> >> > On Wed, Nov 19, 2008 at 3:51 PM, kangax <[EMAIL PROTECTED]> wrote: >> >> >> On Nov 15, 4:48 pm, "Malte Ubl" <[EMAIL PROTECTED]> wrote: >> >> [...] >> >>> The source code of the test is located >> >>> athttp://code.google.com/p/joose-js/source/browse/trunk/tests/12_storag... >> >>> Interestingly the statement at line 49 succeeds. (It stringifies a >> >>> Joose object to JSON and and deserializes it again) >> >>> The statement on line 81, howevery, fails to produce correct JSON. The >> >>> produced string looks like this: >> >>> {"test":"[[object Object]]","another":{"a":1} >> >> >>> When you set a firebug break point in Storage.js line 11 you can see >> >>> that the code goes deeply into Prototype.js territory. >> >> >> The "joose" object (the one that's being tested against) seems to have >> >> `toJSON` method: >> >> >> function () { >> >> return this.pack(Joose.Storage.TEMP_SEEN); >> >> } >> >> >> That method seems to return an object, rather than a string >> >> representation of an object. Prototype's `Object.toJSON` just happens >> >> to delegate its logic to passed object's `toJSON` (effectively letting >> >> "joose" object decide "what to do"). "joose" object returned from >> >> `toJSON` is then turned into "[[object Object]]" via >> >> `Array.prototype.join` invoked on an array it's contained within (join >> >> performs `toString` on each of array's items, if I'm not mistaken). >> >> >>> Bye >> >>> Malte >> >> >> [...] >> >> >> -- >> >> kangax > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Making Joose compatible with Prototype
Very old as in may 2008 ? http://json.org/json.js ;) On Nov 19, 10:10 pm, "Malte Ubl" <[EMAIL PROTECTED]> wrote: > OK, I turned to reading the docs :)http://www.prototypejs.org/learn/json > Although, they refer to a very old version of Crockford's json lib > which no longer extends Object.prototype the conclusion probably holds > true. > > Anyway, is there a way to have json2.js and prototype play nice with each > other? > > On Wed, Nov 19, 2008 at 9:40 PM, Malte Ubl <[EMAIL PROTECTED]> wrote: > > Hey, > > > is Prototype designed to use a built in JSON stringification mechanism? > > > The most popular library, json2.js (http://json.org/json2.js), states > > pretty clearly that the toJSON method is not supposed to return a > > serialized result (which it would turn into a string) but should > > rather return something that can be automatically stringified by the > > library itself. That might be any kind of value, but besides that it > > can be also be instances of Object. Joose.Storage thus returns an > > Object that represents the state of the Joose object and which > > includes extra info that can be used for reinstantiation. The nice > > side effect of this is, that complex structures of nested objects are > > no problem because the stringifier will once again call toJSON on the > > children (if toJSON would return a string it would have to implement > > this itself). > > > If Prototype does indeed need a more complex toJSON method, we could, > > of course, detect that and change our behavior. > > > Bye > > Malte > > -- > >http://code.google.com/p/joose-js/ > >http://blok.appspot.com/ > > > On Wed, Nov 19, 2008 at 3:51 PM, kangax <[EMAIL PROTECTED]> wrote: > > >> On Nov 15, 4:48 pm, "Malte Ubl" <[EMAIL PROTECTED]> wrote: > >> [...] > >>> The source code of the test is located > >>> athttp://code.google.com/p/joose-js/source/browse/trunk/tests/12_storag... > >>> Interestingly the statement at line 49 succeeds. (It stringifies a > >>> Joose object to JSON and and deserializes it again) > >>> The statement on line 81, howevery, fails to produce correct JSON. The > >>> produced string looks like this: > >>> {"test":"[[object Object]]","another":{"a":1} > > >>> When you set a firebug break point in Storage.js line 11 you can see > >>> that the code goes deeply into Prototype.js territory. > > >> The "joose" object (the one that's being tested against) seems to have > >> `toJSON` method: > > >> function () { > >> return this.pack(Joose.Storage.TEMP_SEEN); > >> } > > >> That method seems to return an object, rather than a string > >> representation of an object. Prototype's `Object.toJSON` just happens > >> to delegate its logic to passed object's `toJSON` (effectively letting > >> "joose" object decide "what to do"). "joose" object returned from > >> `toJSON` is then turned into "[[object Object]]" via > >> `Array.prototype.join` invoked on an array it's contained within (join > >> performs `toString` on each of array's items, if I'm not mistaken). > > >>> Bye > >>> Malte > > >> [...] > > >> -- > >> kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Making Joose compatible with Prototype
OK, I turned to reading the docs :) http://www.prototypejs.org/learn/json Although, they refer to a very old version of Crockford's json lib which no longer extends Object.prototype the conclusion probably holds true. Anyway, is there a way to have json2.js and prototype play nice with each other? On Wed, Nov 19, 2008 at 9:40 PM, Malte Ubl <[EMAIL PROTECTED]> wrote: > Hey, > > is Prototype designed to use a built in JSON stringification mechanism? > > The most popular library, json2.js (http://json.org/json2.js), states > pretty clearly that the toJSON method is not supposed to return a > serialized result (which it would turn into a string) but should > rather return something that can be automatically stringified by the > library itself. That might be any kind of value, but besides that it > can be also be instances of Object. Joose.Storage thus returns an > Object that represents the state of the Joose object and which > includes extra info that can be used for reinstantiation. The nice > side effect of this is, that complex structures of nested objects are > no problem because the stringifier will once again call toJSON on the > children (if toJSON would return a string it would have to implement > this itself). > > If Prototype does indeed need a more complex toJSON method, we could, > of course, detect that and change our behavior. > > Bye > Malte > -- > http://code.google.com/p/joose-js/ > http://blok.appspot.com/ > > On Wed, Nov 19, 2008 at 3:51 PM, kangax <[EMAIL PROTECTED]> wrote: >> >> On Nov 15, 4:48 pm, "Malte Ubl" <[EMAIL PROTECTED]> wrote: >> [...] >>> The source code of the test is located >>> athttp://code.google.com/p/joose-js/source/browse/trunk/tests/12_storag... >>> Interestingly the statement at line 49 succeeds. (It stringifies a >>> Joose object to JSON and and deserializes it again) >>> The statement on line 81, howevery, fails to produce correct JSON. The >>> produced string looks like this: >>> {"test":"[[object Object]]","another":{"a":1} >>> >>> When you set a firebug break point in Storage.js line 11 you can see >>> that the code goes deeply into Prototype.js territory. >> >> The "joose" object (the one that's being tested against) seems to have >> `toJSON` method: >> >> function () { >> return this.pack(Joose.Storage.TEMP_SEEN); >> } >> >> That method seems to return an object, rather than a string >> representation of an object. Prototype's `Object.toJSON` just happens >> to delegate its logic to passed object's `toJSON` (effectively letting >> "joose" object decide "what to do"). "joose" object returned from >> `toJSON` is then turned into "[[object Object]]" via >> `Array.prototype.join` invoked on an array it's contained within (join >> performs `toString` on each of array's items, if I'm not mistaken). >> >>> >>> Bye >>> Malte >> >> [...] >> >> -- >> kangax >> >> >> > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Making Joose compatible with Prototype
Hey, is Prototype designed to use a built in JSON stringification mechanism? The most popular library, json2.js (http://json.org/json2.js), states pretty clearly that the toJSON method is not supposed to return a serialized result (which it would turn into a string) but should rather return something that can be automatically stringified by the library itself. That might be any kind of value, but besides that it can be also be instances of Object. Joose.Storage thus returns an Object that represents the state of the Joose object and which includes extra info that can be used for reinstantiation. The nice side effect of this is, that complex structures of nested objects are no problem because the stringifier will once again call toJSON on the children (if toJSON would return a string it would have to implement this itself). If Prototype does indeed need a more complex toJSON method, we could, of course, detect that and change our behavior. Bye Malte -- http://code.google.com/p/joose-js/ http://blok.appspot.com/ On Wed, Nov 19, 2008 at 3:51 PM, kangax <[EMAIL PROTECTED]> wrote: > > On Nov 15, 4:48 pm, "Malte Ubl" <[EMAIL PROTECTED]> wrote: > [...] >> The source code of the test is located >> athttp://code.google.com/p/joose-js/source/browse/trunk/tests/12_storag... >> Interestingly the statement at line 49 succeeds. (It stringifies a >> Joose object to JSON and and deserializes it again) >> The statement on line 81, howevery, fails to produce correct JSON. The >> produced string looks like this: >> {"test":"[[object Object]]","another":{"a":1} >> >> When you set a firebug break point in Storage.js line 11 you can see >> that the code goes deeply into Prototype.js territory. > > The "joose" object (the one that's being tested against) seems to have > `toJSON` method: > > function () { > return this.pack(Joose.Storage.TEMP_SEEN); > } > > That method seems to return an object, rather than a string > representation of an object. Prototype's `Object.toJSON` just happens > to delegate its logic to passed object's `toJSON` (effectively letting > "joose" object decide "what to do"). "joose" object returned from > `toJSON` is then turned into "[[object Object]]" via > `Array.prototype.join` invoked on an array it's contained within (join > performs `toString` on each of array's items, if I'm not mistaken). > >> >> Bye >> Malte > > [...] > > -- > kangax > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Making Joose compatible with Prototype
On Nov 15, 4:48 pm, "Malte Ubl" <[EMAIL PROTECTED]> wrote: [...] > The source code of the test is located > athttp://code.google.com/p/joose-js/source/browse/trunk/tests/12_storag... > Interestingly the statement at line 49 succeeds. (It stringifies a > Joose object to JSON and and deserializes it again) > The statement on line 81, howevery, fails to produce correct JSON. The > produced string looks like this: > {"test":"[[object Object]]","another":{"a":1} > > When you set a firebug break point in Storage.js line 11 you can see > that the code goes deeply into Prototype.js territory. The "joose" object (the one that's being tested against) seems to have `toJSON` method: function () { return this.pack(Joose.Storage.TEMP_SEEN); } That method seems to return an object, rather than a string representation of an object. Prototype's `Object.toJSON` just happens to delegate its logic to passed object's `toJSON` (effectively letting "joose" object decide "what to do"). "joose" object returned from `toJSON` is then turned into "[[object Object]]" via `Array.prototype.join` invoked on an array it's contained within (join performs `toString` on each of array's items, if I'm not mistaken). > > Bye > Malte [...] -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Making Joose compatible with Prototype
Hey, On Sat, Nov 15, 2008 at 8:18 PM, kangax <[EMAIL PROTECTED]> wrote: > > On Nov 15, 7:36 am, Malte <[EMAIL PROTECTED]> wrote: >> Joose provides a Role called Joose.Storage that makes Joose objects >> storable. The preferred method is JSON and a custom toJSON method is >> provided to make serialization with json2.js automatic. However, when >> used in conjunction with Prototype.js the resulting objects seems to >> be encoded again (More info: In effect the problem only occurs if the >> Joose objects is located with regular JS objects). > > Could you explain what "located with regular JS objects" means? It > would also be helpful to see a stripped down version of this bug - > the test suite doesn't provide any pointers as to what/where went > wrong (or at least I can't find any). In the sentence above, I meant "within", like if you serialize { foo: [jooseObject] } serializing the jooseObject by itself works. This seems to be due to a toJSON method that is injected into the Array prototype by Prototype.js. Can this be true. The source code of the test is located at http://code.google.com/p/joose-js/source/browse/trunk/tests/12_storage.t.js Interestingly the statement at line 49 succeeds. (It stringifies a Joose object to JSON and and deserializes it again) The statement on line 81, howevery, fails to produce correct JSON. The produced string looks like this: {"test":"[[object Object]]","another":{"a":1} When you set a firebug break point in Storage.js line 11 you can see that the code goes deeply into Prototype.js territory. Bye Malte >> We would really like to get Joose to pass all tests when run with >> Prototype. Could somebody give us a hint about what is going wrong? >> >> You can run the test individually and see the problem right >> here:http://joose-js.googlecode.com/svn/trunk/tests/test.html#test=12_stor... >> >> Thank You, >> >> Malte > > -- > kangax > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Making Joose compatible with Prototype
On Nov 15, 7:36 am, Malte <[EMAIL PROTECTED]> wrote: > Hey, > > we are working on making the JS meta system Joose (http:// > code.google.com/p/joose-js/) compatible with Prototype.js > > We had to make some pretty serious changes to cope with Prototype's > prototype extension and especially some global identifiers like > "Class" and "Prototype" that are used in both libraries. Anyway, > mostly everything works now, the only problem that remains is related > to JSON stringification. > > Joose provides a Role called Joose.Storage that makes Joose objects > storable. The preferred method is JSON and a custom toJSON method is > provided to make serialization with json2.js automatic. However, when > used in conjunction with Prototype.js the resulting objects seems to > be encoded again (More info: In effect the problem only occurs if the > Joose objects is located with regular JS objects). Could you explain what "located with regular JS objects" means? It would also be helpful to see a stripped down version of this bug - the test suite doesn't provide any pointers as to what/where went wrong (or at least I can't find any). > > We would really like to get Joose to pass all tests when run with > Prototype. Could somebody give us a hint about what is going wrong? > > You can run the test individually and see the problem right > here:http://joose-js.googlecode.com/svn/trunk/tests/test.html#test=12_stor... > > Thank You, > > Malte -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---