4 #include <CoreFoundation/CoreFoundation.h>
5 #include <CoreFoundation/CFLogUtilities.h>
7 #include <Foundation/Foundation.h>
9 #include <JavaScriptCore/JSBase.h>
10 #include <JavaScriptCore/JSValueRef.h>
11 #include <JavaScriptCore/JSObjectRef.h>
12 #include <JavaScriptCore/JSContextRef.h>
13 #include <JavaScriptCore/JSStringRef.h>
14 #include <JavaScriptCore/JSStringRefCF.h>
16 #define _trace() do { \
17 CFLog(kCFLogLevelNotice, CFSTR("_trace(%u)"), __LINE__); \
20 JSContextRef JSGetContext(void);
21 void CYThrow(JSContextRef context, id error, JSValueRef *exception);
22 CFStringRef JSValueToJSONCopy(JSContextRef context, JSValueRef value);
26 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
28 std::cout << ">>> " << std::flush;
31 if (!std::getline(std::cin, line))
34 JSStringRef script(JSStringCreateWithUTF8CString(line.c_str()));
36 JSContextRef context(JSGetContext());
38 JSValueRef exception(NULL);
39 JSValueRef result(JSEvaluateScript(context, script, NULL, NULL, 0, &exception));
40 JSStringRelease(script);
42 if (exception != NULL)
45 if (!JSValueIsUndefined(context, result)) {
49 json = JSValueToJSONCopy(context, result);
51 CYThrow(context, error, &result);
55 std::cout << [reinterpret_cast<const NSString *>(json) UTF8String] << std::endl;