最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - What is JSON.parse written inIs it open source? - Stack Overflow

programmeradmin0浏览0评论

PHP funcitons are written in C and you can look at the source code if you like. For example here - session_start source

What about with Javascript? How are functions like JSON.parse implemented? Where can I go to view the source?

Thanks!

PHP funcitons are written in C and you can look at the source code if you like. For example here - session_start source

What about with Javascript? How are functions like JSON.parse implemented? Where can I go to view the source?

Thanks!

Share Improve this question edited Jun 11, 2013 at 11:42 asked Jan 13, 2012 at 0:18 user656925user656925 2
  • You might find it somewhere around here: hg.mozilla.org – mario Commented Jan 13, 2012 at 0:22
  • Is it just me, or does that username just beg out for downvotes? ;-) – T.J. Crowder Commented Jan 13, 2012 at 0:23
Add a comment  | 

4 Answers 4

Reset to default 15

JSON.parse is native. That means it's defined in the browser, the implementation of the method is browser implementation specific.

v8 (Chrome) has a C++ method for JsonParser::ParseJson

spidermonkey (Firefox) has a C++ function for js_json_parse

JavaScriptCore (Webkit / Safari) has a C++ function for JSONProtoFuncParse

Rhino (Mozilla) has a Java method for parseValue

the Opera and IE implementations are closed source. I also think Nitro's implementation is closed source aswell.

Note there are many other JavaScript engines.

Each JavaScript engine that supports it will have its own implementation of JSON.parse. You can view the code of the various open source engines (V8, SpiderMonkey) in their respective repositories. You can also view a JavaScript implementation on Crockford's github page (Crockford being the person who came up with JSON) — actually, more than one; there's a version that's a state machine, and another that's a recursive descent parser, and another that relies on eval (which is kind of cheating). There are also various implementations in various languages linked from the JSON home page.

It depends on the browser. You view the source of your favorite and see if you can find it there.

Depends on the browser.

For example: Chrome is using the V8 javascript engine. http://code.google.com/p/v8/ which may include that inside itself, or that could be a part of the Chromium project http://www.chromium.org/Home.

发布评论

评论列表(0)

  1. 暂无评论