+JSStringRef JSValueCreateJSONString(JSContextRef ctx, JSValueRef apiValue, unsigned indent, JSValueRef* exception)
+{
+ if (!ctx) {
+ ASSERT_NOT_REACHED();
+ return 0;
+ }
+ ExecState* exec = toJS(ctx);
+ JSLockHolder locker(exec);
+ JSValue value = toJS(exec, apiValue);
+ String result = JSONStringify(exec, value, indent);
+ if (exception)
+ *exception = 0;
+ if (exec->hadException()) {
+ JSValue exceptionValue = exec->exception();
+ if (exception)
+ *exception = toRef(exec, exceptionValue);
+ exec->clearException();
+#if ENABLE(REMOTE_INSPECTOR)
+ exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
+#endif
+ return 0;
+ }
+ return OpaqueJSString::create(result).leakRef();