But I don't seen any clear indication of if this stuff is intended to
be exposed or how it should be used from either C++ or JavaScript
code.
I know I can compile and run to decode but that has security implications.
I don't have a problem adding JSON support via my own code or finding
some JavaScript to do the job. I just want to know If I am missing
the obvious.
--
Bryan White
-- Christian
The whole point of JSON is to be representing objects in valid
JavaScript syntax. If parsing JSON using V8's internal parser is too
slow for you, then it doesn't really make sense to use V8 at all. ;-)
Besides, my example generates JSON. Ragel can only be used to parse it.
I'm not doubting that Ragel is an excellent state machine compiler,
but you're already using one compiler for your code, why not use the
same for your data, when you even have the luxury that your code and
your data is in the same format?
- Simon
2008/10/8 <Morgain...@googlemail.com>:
- Simon
2008/10/9 Pete Gontier <pe...@gontier.org>:
It's not just for server-side JavaScript. There are any number of
conditions where an interpreter might parse JSON from an unknown or
untrusted source.
That's why there are four implementations of JSON parsers for JavaScript
at json.org, each of which strictly parses JSON instead of blindly
eval()ing. Has anyone done performance analysis to show that it even
needs to be reimplemented?
--
-D. d...@uchicago.edu NSIT University of Chicago
Can you mention an example or two? I'm interested, because I couldn't
think of other examples. :-)
I'll incorporate what Pete Gontier said by reference, then add that
you seem to be thinking of V8 only in terms of its role in Google
Chrome. Once you begin to think of it simply as an embeddable ECMA-262
implementation, the possibilities for this situation are endless.
* People are talking about V8 as a scripting engine for games. Consider
downloadable skins, extensions, modules, etc for such a game which might
store certain data in JSON object files.
* JavaScript could be a platform implementation language for components
in any web application framework; JSON data might be loaded from
any data provision source (with or without an HTTP proxy involved).
Imagine, say, an analysis engine for electoral data which allows the
user to point the applicaton to any source of data accessible by the
browser. It need not necessarily be a browser (i.e., application
hosting platform) that provides standard XSS privilege limitations.
* I might develop a GPS interface program that downloads tracking data
from my GPS device and stores it in JSON format. Some visualization
product using V8 JavaScript as an internal implementation language loads
that data and does something clever with it.
I don't know, I just made those up off the top of my head. Keep going,
it's easy once you stop thinking of JS as an exclusive property of web
browsers. :)
Data source trust issues are important to consider. It is, however,
fairly irrelevant to the original criticism, which was related to the
performance of parsing JSON structures using eval() in V8.
Using eval() is always dangerous. But I fail to see the need for an
external parser just for JSON. If you are exchanging data with an
external source over an unencrypted connection, then yes, using eval()
is a critical bug. But there are other ways.
For instance, it would be fairly simple to implement an evalJSON()
method that rejects all function calls. To obtain production-ready
security, you probably need more than that, but I'm just throwing
examples out there.
- Simon
2008/10/9 David Champion <d...@uchicago.edu>:
For instance, I have a project where V8 is used as a scripting engine
for a game, and data files are stored in JSON format. Here, trust
isn't really an issue. Of course, as soon as network traffic is
involved, different solutions need to be evaluated.
Oh, and right, by encryption I wrongly implied identity certificate
checks and secure key exchange methods etc. You're right.
- Simon
2008/10/10 Pete Gontier <pe...@gontier.org>:
http://partcounter.blogspot.com/2008/10/debut-json.html