The "name" and "length" property of JSON.parse and JSON.stringify

# 程劭非 (13 years ago)

Just noticed that there is no description about "name" and "length" property of JSON.parse and JSON.stringify in ES5. Are they implement-dependent?

(I saw test262 require JSON.stringify.length to be 3, but no such case for JSON.parse. )

Thanks, Shaofei Cheng

# Lasse Reichstein (13 years ago)

On Mon, Mar 12, 2012 at 8:33 AM, 程劭非 <csf178 at gmail.com> wrote:

Hi all, Just noticed that there is no description about "name" and "length" property of JSON.parse and JSON.stringify in ES5. Are they implement-dependent?

(I saw test262 require JSON.stringify.length to be 3, but no such case for JSON.parse. )

The first part of section 15 says: "Every built-in Function object described in this clause—whether as a constructor, an ordinary function, or both—has a length property whose value is an integer. Unless otherwise specified, this value is equal to the largest number of named arguments shown in the subclause headings for the function description, including optional parameters."

I.e., the lengths are specified. I don't believe the name properties for function objects are specified anywhere in ES5, so they are entirely outside the spec.

# 程劭非 (13 years ago)

Thank you. It's my fault that I didn't read it carefully.

2012/3/12 Lasse Reichstein <reichsteinatwork at gmail.com>

# Dave Fugate (13 years ago)

I believe there’s a test case for JSON.parse.length as well:) /** * …

  • @path ch15/15.12/15.12.2/15.12.2-0-2.js

  • @description JSON.parse must exist as a function taking 2 parameters */ function testcase() { var f = JSON.parse;

    if (typeof(f) === "function" && f.length === 2) { return true; } } runTestCase(testcase);

My best,