return CYUTF16String(JSStringGetCharactersPtr(value), JSStringGetLength(value));
}
+const char *CYPoolCString(CYPool &pool, CYUTF8String utf8) {
+ return pool.strndup(utf8.data, utf8.size);
+}
+
CYUTF8String CYPoolUTF8String(CYPool &pool, JSContextRef context, JSStringRef value) {
return CYPoolUTF8String(pool, CYCastUTF16String(value));
}
static JSValueRef Cycript_compile_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
CYPool pool;
CYUTF8String before(CYPoolUTF8String(pool, context, CYJSString(context, arguments[0])));
- std::stringbuf value(std::string(before.data, before.size));
- CYUTF8String after(CYPoolCode(pool, value));
+ CYUTF8String after(CYPoolCode(pool, before));
return CYCastJSValue(context, CYJSString(after));
} CYCatch_(NULL, "SyntaxError") }
} CYCatch(NULL) }
static JSValueRef Type_callAsFunction_blockWith(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) {
+#ifdef CY_OBJECTIVEC
sig::Block type;
return Type_callAsFunction_$With(context, object, _this, count, arguments, type, exception);
+#else
+ _assert(false);
+#endif
}
static JSValueRef Type_callAsFunction_constant(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
}
};
+#ifndef __ANDROID__
static volatile bool cancel_;
static bool CYShouldTerminate(JSContextRef context, void *arg) {
return cancel_;
}
+#endif
_visible const char *CYExecute(JSContextRef context, CYPool &pool, CYUTF8String code) {
ExecutionHandle handle(context);
+#ifndef __ANDROID__
cancel_ = false;
if (&JSContextGroupSetExecutionTimeLimit != NULL)
JSContextGroupSetExecutionTimeLimit(JSContextGetGroup(context), 0.5, &CYShouldTerminate, NULL);
+#endif
try {
JSValueRef result(_jsccall(JSEvaluateScript, context, CYJSString(code), NULL, NULL, 0));
}
}
+#ifndef __ANDROID__
_visible void CYCancel() {
cancel_ = true;
}
+#endif
const char *CYPoolLibraryPath(CYPool &pool);
char *lib(pool.strdup(addr.dli_fname));
char *slash(strrchr(lib, '/'));
- _assert(slash != NULL);
+ if (slash == NULL)
+ return ".";
*slash = '\0';
slash = strrchr(lib, '/');