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 CFStringRef JSValueToJSONCopy(JSContextRef ctx, JSValueRef value);
25 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
27 std::cout << ">>> " << std::flush;
30 if (!std::getline(std::cin, line))
33 JSStringRef script(JSStringCreateWithUTF8CString(line.c_str()));
36 JSValueRef result(JSEvaluateScript(JSGetContext(), script, NULL, NULL, 0, &exception));
39 JSStringRelease(script);
41 if (!JSValueIsUndefined(JSGetContext(), result)) {
42 CFStringRef json(JSValueToJSONCopy(JSGetContext(), result));
43 std::cout << [reinterpret_cast<const NSString *>(json) UTF8String] << std::endl;