Ignore:
Timestamp:
Mar 18, 2010, 1:51:23 PM (15 years ago)
Author:
[email protected]
Message:

2010-03-18 Oliver Hunt <[email protected]>

Reviewed by Sam Weinig.

Add API to directly expose JSON parsing
https://bugs.webkit.org/show_bug.cgi?id=34887

Add API to expose JSON parsing directly, and add tests to testapi

  • API/JSValueRef.cpp: (JSValueMakeFromJSONString): (JSValueCreateJSONString):
  • API/tests/testapi.c: (main):
  • JavaScriptCore.exp:
  • runtime/JSONObject.cpp: (JSC::JSONStringify):
  • runtime/JSONObject.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSValueRef.cpp

    r55633 r56189  
    3232
    3333#include <runtime/JSGlobalObject.h>
     34#include <runtime/JSONObject.h>
    3435#include <runtime/JSString.h>
     36#include <runtime/LiteralParser.h>
    3537#include <runtime/Operations.h>
    3638#include <runtime/Protect.h>
     
    222224}
    223225
     226JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string)
     227{
     228    ExecState* exec = toJS(ctx);
     229    APIEntryShim entryShim(exec);
     230    LiteralParser parser(exec, string->ustring(), LiteralParser::StrictJSON);
     231    return toRef(exec, parser.tryLiteralParse());
     232}
     233
     234JSStringRef JSValueCreateJSONString(JSContextRef ctx, JSValueRef apiValue, unsigned indent, JSValueRef* exception)
     235{
     236    ExecState* exec = toJS(ctx);
     237    APIEntryShim entryShim(exec);
     238    JSValue value = toJS(exec, apiValue);
     239    UString result = JSONStringify(exec, value, indent);
     240    if (exception)
     241        *exception = 0;
     242    if (exec->hadException()) {
     243        if (exception)
     244            *exception = toRef(exec, exec->exception());
     245        exec->clearException();
     246        return 0;
     247    }
     248    return OpaqueJSString::create(result).releaseRef();
     249}
     250
    224251bool JSValueToBoolean(JSContextRef ctx, JSValueRef value)
    225252{
Note: See TracChangeset for help on using the changeset viewer.