use of org.graalvm.polyglot.nativeapi.PolyglotNativeAPITypes.PolyglotCallbackInfo in project graal by oracle.
the class PolyglotNativeAPI method polyglot_create_function.
@CEntryPoint(name = "polyglot_create_function")
public static PolyglotStatus polyglot_create_function(IsolateThread isolate_thread, PolyglotContextPointer polyglot_context, PolyglotCallbackPointer callback, VoidPointer data, PolyglotValuePointerPointer value) {
return withHandledErrors(() -> {
Context c = ObjectHandles.getGlobal().get(polyglot_context);
ProxyExecutable executable = (Value... arguments) -> {
ObjectHandle[] handleArgs = new ObjectHandle[arguments.length];
for (int i = 0; i < arguments.length; i++) {
handleArgs[i] = createHandle(arguments[i]);
}
PolyglotCallbackInfo cbInfo = (PolyglotCallbackInfo) createHandle(new PolyglotCallbackInfoInternal(handleArgs, data));
try {
PolyglotValuePointer result = callback.invoke(CEntryPointContext.getCurrentIsolateThread(), cbInfo);
CallbackException ce = exceptionsTL.get();
if (ce != null) {
exceptionsTL.remove();
throw ce;
} else {
return PolyglotNativeAPI.fetchHandle(result);
}
} finally {
PolyglotCallbackInfoInternal info = fetchHandle(cbInfo);
for (ObjectHandle arg : info.arguments) {
freeHandle(arg);
}
freeHandle(cbInfo);
}
};
value.write(createHandle(c.asValue(executable)));
});
}
Aggregations