Loading ...
Sorry, an error occurred while loading the content.

Re: IE hosted objects and toJSON check

Expand Messages
  • Douglas Crockford
    ... I am happy that you were able to get it working, but I have to tell you, I have absolutely no interest in supporting VBScript or typeof unknown. I have a
    Message 1 of 3 , Apr 3, 2011
    • 0 Attachment
      --- In json@yahoogroups.com, Andrea Giammarchi <andrea.giammarchi@...> wrote:
      >
      > This is mainly for Mr D and it's about json2.js ( probably the sans eval as
      > well )
      >
      > If I create an object through a VBScript class definition and this object
      > has a hosted toJSON public method the parser will fail, while it does not
      > fail with native IE8 and IE9 implementation.
      >
      > The change should be straight forward, where there is a check about the
      > method type there should be an "unknown" as well.
      >
      > In few words:
      >
      > if (typeof object === "object" && (typeof object.toJSON === "function" ||
      > typeof object.toJSON === "unknown")) {
      > value = object.toJSON(key);
      > }
      >
      > Above code will already work as expected but to be honest I would rather
      > make the check more portable
      >
      > function invokeToJSON(object, method, key) {
      > switch (typeof object[method]) {
      > case "function":
      > case "unknown":
      > try {
      > return typeof key === "string" ?
      > object[method]() :
      > object[method](key)
      > ;
      > } catch(e) {
      > // notify something here
      > }
      > }
      > }
      >
      > // so that ...
      >
      > if (typeof object === "object") {
      > value = invokeToJSON(object, "toJSON", key);
      > }
      >
      > // then if value is not undefined ...
      >
      > the function could be reused for toString and valueOf, if necessary, without
      > a key argument since VBScript methods are sensible to arguments length.
      >
      > Any comment/improvement will be appreciated, any update on github more than
      > welcome.
      >
      > Best Regards,
      > Andrea Giammarchi
      >
      > P.S. "unknown" is IE specific

      I am happy that you were able to get it working, but I have to tell you, I have absolutely no interest in supporting VBScript or typeof unknown. I have a very strong interest in seeing that crap go extinct.
    • Andrea Giammarchi
      Me too, unfortunately that crap may be useful to create HTML5 shims due getters/setters possibility: e.g. Objet.create, localStorage with direct property
      Message 2 of 3 , Apr 4, 2011
      • 0 Attachment
        Me too, unfortunately that crap may be useful to create HTML5 shims due
        getters/setters possibility: e.g. Objet.create, localStorage with direct
        property assignment, etc. Since this is a IE 7 or less case only, since IE8
        supports VBScript with a toJSON method, I don't think it can arm anybody
        else, also because json2.js is the file that hopefully gonna be extinct
        soon, isn't it?

        Moreover, if IE8 native JSON.stringify supports that, isnt's this json2.js
        goal to bring this object in those browsers that do not support it?

        Best Regards,
        Andrea Giammarchi


        [Non-text portions of this message have been removed]
      Your message has been successfully submitted and would be delivered to recipients shortly.