Bug 34887

Summary: Add API to directly expose JSON parsing
Product: WebKit Reporter: Oliver Hunt <oliver>
Component: New BugsAssignee: Oliver Hunt <oliver>
Status: RESOLVED FIXED    
Severity: Normal CC: eric, ggaren
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Other   
OS: OS X 10.5   
Attachments:
Description Flags
Patch
none
Patch
none
Patch sam: review+

Description Oliver Hunt 2010-02-12 04:57:01 PST
Add API to directly expose JSON parsing
Comment 1 Oliver Hunt 2010-02-12 04:59:30 PST
Created attachment 48637 [details]
Patch
Comment 2 Maciej Stachowiak 2010-02-12 05:02:49 PST
Comment on attachment 48637 [details]
Patch

r=me but please put the declaration in a private header until this can go through Mac OS X API review.
Comment 3 Geoffrey Garen 2010-02-12 13:09:02 PST
I think "JSValueMakeFromJSONString" would be a better name than "JSValueMakeValueFromJSONString". All other functions like this are JSValueMake* rather than JSValueMakeValue*.

Did you decide to leave out JSValueCreateJSONString, or is that coming in another patch?
Comment 4 Eric Seidel (no email) 2010-02-17 14:23:37 PST
Attachment 48637 [details] was posted by a committer and has review+, assigning to Oliver Hunt for commit.
Comment 5 Oliver Hunt 2010-02-17 14:24:37 PST
Comment on attachment 48637 [details]
Patch

Clearing review flag, have changed api slightly and have new patch
Comment 6 Oliver Hunt 2010-03-11 01:00:32 PST
Created attachment 50479 [details]
Patch
Comment 7 Mark Rowe (bdash) 2010-03-11 11:55:22 PST
Comment on attachment 50479 [details]
Patch

> +/* Converting to and from JSON formatted strings */
> +
> +/*!
> + @function
> + @abstract       Creates a JavaScript value from a JSON formatted string.
> + @param ctx      The execution context to use.
> + @param string   The JSString containing the JSON string to be parsed.
> + @result         A JSValue containing the parsed value, or NULL if the input is invalid.
> + */
> +JS_EXPORT JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string);
> +
> +/*!
> + @function
> + @abstract       Creates a JavaScript string containing the JSON serialized representation of a JS value.
> + @param ctx      The execution context to use.
> + @param value    The value to serialize.
> + @param indent   The number of spaces to indent when nesting.  If 0, the resulting JSON will not contains newlines.  The size of the indent is clamped to 10 spaces.
> + @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
> + @result         A JSString with the result of serialization, or NULL if an exception is thrown.
> + */
> +JS_EXPORT JSStringRef JSValueCreateJSONString(JSContextRef ctx, JSValueRef value, unsigned indent, JSValueRef* exception);

These two functions need to be tagged in the header with availability macros indicating which version of JavaScriptCore they were introduced with.

> +    

Please don’t add trailing white space.

>  /*!
> @@ -248,7 +270,7 @@ JS_EXPORT JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JS
>  @result         The JSObject result of conversion, or NULL if an exception is thrown.
>  */
>  JS_EXPORT JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception);
> -
> +    

Same here!
Comment 8 Oliver Hunt 2010-03-18 13:38:04 PDT
Created attachment 51085 [details]
Patch
Comment 9 Eric Seidel (no email) 2010-03-18 13:43:35 PDT
Attachment 51085 [details] did not build on mac:
Build output: http://webkit-commit-queue.appspot.com/results/1021021
Comment 10 Oliver Hunt 2010-03-18 13:51:31 PDT
Committed r56189: <http://trac.webkit.org/changeset/56189>