diff options
Diffstat (limited to 'JavaScriptCore/API/JSValueRef.cpp')
| -rw-r--r-- | JavaScriptCore/API/JSValueRef.cpp | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/JavaScriptCore/API/JSValueRef.cpp b/JavaScriptCore/API/JSValueRef.cpp index 518fc7b..faf4712 100644 --- a/JavaScriptCore/API/JSValueRef.cpp +++ b/JavaScriptCore/API/JSValueRef.cpp @@ -26,19 +26,21 @@ #include "config.h" #include "JSValueRef.h" -#include <wtf/Platform.h> #include "APICast.h" #include "APIShims.h" #include "JSCallbackObject.h" #include <runtime/JSGlobalObject.h> +#include <runtime/JSONObject.h> #include <runtime/JSString.h> +#include <runtime/LiteralParser.h> #include <runtime/Operations.h> #include <runtime/Protect.h> #include <runtime/UString.h> #include <runtime/JSValue.h> #include <wtf/Assertions.h> +#include <wtf/text/StringHash.h> #include <algorithm> // for std::min @@ -129,8 +131,8 @@ bool JSValueIsObjectOfClass(JSContextRef ctx, JSValueRef value, JSClassRef jsCla if (JSObject* o = jsValue.getObject()) { if (o->inherits(&JSCallbackObject<JSGlobalObject>::info)) return static_cast<JSCallbackObject<JSGlobalObject>*>(o)->inherits(jsClass); - else if (o->inherits(&JSCallbackObject<JSObject>::info)) - return static_cast<JSCallbackObject<JSObject>*>(o)->inherits(jsClass); + else if (o->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::info)) + return static_cast<JSCallbackObject<JSObjectWithGlobalObject>*>(o)->inherits(jsClass); } return false; } @@ -217,7 +219,7 @@ JSValueRef JSValueMakeNumber(JSContextRef ctx, double value) if (isnan(value)) value = NaN; - return toRef(exec, jsNumber(exec, value)); + return toRef(exec, jsNumber(value)); } JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string) @@ -228,6 +230,31 @@ JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string) return toRef(exec, jsString(exec, string->ustring())); } +JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string) +{ + ExecState* exec = toJS(ctx); + APIEntryShim entryShim(exec); + LiteralParser parser(exec, string->ustring(), LiteralParser::StrictJSON); + return toRef(exec, parser.tryLiteralParse()); +} + +JSStringRef JSValueCreateJSONString(JSContextRef ctx, JSValueRef apiValue, unsigned indent, JSValueRef* exception) +{ + ExecState* exec = toJS(ctx); + APIEntryShim entryShim(exec); + JSValue value = toJS(exec, apiValue); + UString result = JSONStringify(exec, value, indent); + if (exception) + *exception = 0; + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); + return 0; + } + return OpaqueJSString::create(result).leakRef(); +} + bool JSValueToBoolean(JSContextRef ctx, JSValueRef value) { ExecState* exec = toJS(ctx); @@ -268,7 +295,7 @@ JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef* exec->clearException(); stringRef.clear(); } - return stringRef.release().releaseRef(); + return stringRef.release().leakRef(); } JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception) |
