EJConvert.h 967 B

1234567891011121314151617181920212223242526272829303132
  1. #import <Foundation/Foundation.h>
  2. #import <JavaScriptCore/JavaScriptCore.h>
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. NSString *JSValueToNSString( JSContextRef ctx, JSValueRef v );
  7. JSValueRef NSStringToJSValue( JSContextRef ctx, NSString *string );
  8. double JSValueToNumberFast( JSContextRef ctx, JSValueRef v );
  9. void JSValueUnprotectSafe( JSContextRef ctx, JSValueRef v );
  10. JSValueRef NSObjectToJSValue( JSContextRef ctx, NSObject *obj );
  11. NSObject *JSValueToNSObject( JSContextRef ctx, JSValueRef value );
  12. static inline void *JSValueGetPrivate(JSValueRef v) {
  13. // On 64bit systems we can not safely call JSObjectGetPrivate with any
  14. // JSValueRef. Doing so with immediate values (numbers, null, bool,
  15. // undefined) will crash the app. So we check for these first.
  16. #if __LP64__
  17. return !((int64_t)v & 0xffff000000000002ll)
  18. ? JSObjectGetPrivate((JSObjectRef)v)
  19. : NULL;
  20. #else
  21. return JSObjectGetPrivate((JSObjectRef)v);
  22. #endif
  23. }
  24. #ifdef __cplusplus
  25. }
  26. #endif