X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/f9bf01c6616d5ddcf65b13b33cedf9e387ff7a63..14957cd040308e3eeec43d26bae5d76da13fcd85:/API/JSValueRef.cpp?ds=sidebyside diff --git a/API/JSValueRef.cpp b/API/JSValueRef.cpp index a12cc34..d1603e2 100644 --- a/API/JSValueRef.cpp +++ b/API/JSValueRef.cpp @@ -26,19 +26,21 @@ #include "config.h" #include "JSValueRef.h" -#include #include "APICast.h" #include "APIShims.h" #include "JSCallbackObject.h" #include +#include #include +#include #include #include #include #include #include +#include #include // for std::min @@ -127,10 +129,10 @@ bool JSValueIsObjectOfClass(JSContextRef ctx, JSValueRef value, JSClassRef jsCla JSValue jsValue = toJS(exec, value); if (JSObject* o = jsValue.getObject()) { - if (o->inherits(&JSCallbackObject::info)) + if (o->inherits(&JSCallbackObject::s_info)) return static_cast*>(o)->inherits(jsClass); - else if (o->inherits(&JSCallbackObject::info)) - return static_cast*>(o)->inherits(jsClass); + if (o->inherits(&JSCallbackObject::s_info)) + return static_cast*>(o)->inherits(jsClass); } return false; } @@ -211,7 +213,13 @@ JSValueRef JSValueMakeNumber(JSContextRef ctx, double value) ExecState* exec = toJS(ctx); APIEntryShim entryShim(exec); - return toRef(exec, jsNumber(exec, value)); + // Our JSValue representation relies on a standard bit pattern for NaN. NaNs + // generated internally to JavaScriptCore naturally have that representation, + // but an external NaN might not. + if (isnan(value)) + value = NaN; + + return toRef(exec, jsNumber(value)); } JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string) @@ -222,6 +230,32 @@ 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); + UString str = string->ustring(); + LiteralParser parser(exec, str.characters(), str.length(), 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); @@ -262,7 +296,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)