static void (*JSSynchronousGarbageCollectForDebugging$)(JSContextRef);
-void CYGarbageCollect(JSContextRef context) {
+_visible void CYGarbageCollect(JSContextRef context) {
(JSSynchronousGarbageCollectForDebugging$ ?: &JSGarbageCollect)(context);
}
JSValueRef toCYON(CYGetProperty(context, object, toCYON_s));
if (CYIsCallable(context, toCYON)) {
// XXX: this needs to be abstracted behind some kind of function
- JSValueRef arguments[1] = {CYCastJSValue(context, static_cast<double>(reinterpret_cast<uintptr_t>(&objects)))};
+ JSValueRef arguments[1] = {CYCastJSValue(context, reinterpret_cast<uintptr_t>(&objects))};
JSValueRef value(CYCallAsFunction(context, (JSObjectRef) toCYON, object, 1, arguments));
_assert(value != NULL);
return CYPoolCString(pool, context, value);
static JSValueRef Type_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
Type_privateData *internal(reinterpret_cast<Type_privateData *>(JSObjectGetPrivate(_this)));
CYLocalPool pool;
- std::ostringstream out;
+ std::stringbuf out;
CYOptions options;
CYOutput output(out, options);
(new(pool) CYEncodedType(Decode(pool, internal->type_)))->Output(output, CYNoFlags);
static JSObjectRef (*JSObjectMakeArray$)(JSContextRef, size_t, const JSValueRef[], JSValueRef *);
-void CYSetArgs(int argc, const char *argv[]) {
+_visible void CYSetArgs(int argc, const char *argv[]) {
JSContextRef context(CYGetJSContext());
JSValueRef args[argc];
for (int i(0); i != argc; ++i)
}
};
-const char *CYExecute(JSContextRef context, CYPool &pool, CYUTF8String code) {
+static volatile bool cancel_;
+
+static bool CYShouldTerminate(JSContextRef context, void *arg) {
+ return cancel_;
+}
+
+_visible const char *CYExecute(JSContextRef context, CYPool &pool, CYUTF8String code) {
JSValueRef exception(NULL);
+ if (false) error:
+ return CYPoolCString(pool, context, CYJSString(context, exception));
ExecutionHandle handle(context);
- JSValueRef result; try {
- result = JSEvaluateScript(context, CYJSString(code), NULL, NULL, 0, &exception);
- } catch (const char *error) {
- return error;
- }
+ cancel_ = false;
+ if (&JSContextGroupSetExecutionTimeLimit != NULL)
+ JSContextGroupSetExecutionTimeLimit(JSContextGetGroup(context), 0.5, &CYShouldTerminate, NULL);
- if (exception != NULL) error:
- return CYPoolCString(pool, context, CYJSString(context, exception));
+ JSValueRef result(JSEvaluateScript(context, CYJSString(code), NULL, NULL, 0, &exception));
+ if (exception != NULL)
+ goto error;
if (JSValueIsUndefined(context, result))
return NULL;
- const char *json; try {
- std::set<void *> objects;
- json = CYPoolCCYON(pool, context, result, objects, &exception);
- } catch (const char *error) {
- return error;
- }
-
+ std::set<void *> objects;
+ const char *json(CYPoolCCYON(pool, context, result, objects, &exception));
if (exception != NULL)
goto error;
return json;
}
+_visible void CYCancel() {
+ cancel_ = true;
+}
+
static bool initialized_ = false;
void CYInitializeDynamic() {
return reinterpret_cast<Context *>(JSObjectGetPrivate(CYCastJSObject(context, CYGetProperty(context, CYGetGlobalObject(context), cy_s))))->context_;
}
-extern "C" bool CydgetMemoryParse(const uint16_t **data, size_t *size);
-
void *CYMapFile(const char *path, size_t *psize) {
int fd(_syscall_(open(path, O_RDONLY), 1, ENOENT));
if (fd == -1)
static JSGlobalContextRef context_;
-JSGlobalContextRef CYGetJSContext() {
+_visible JSGlobalContextRef CYGetJSContext() {
CYInitializeDynamic();
if (context_ == NULL) {
return context_;
}
-void CYDestroyContext() {
+_visible void CYDestroyContext() {
if (context_ == NULL)
return;
JSGlobalContextRelease(context_);