Skip to content

Instantly share code, notes, and snippets.

@ozcanzaferayan
Created February 6, 2020 10:30
Show Gist options
  • Save ozcanzaferayan/3ab345d4b828d09f48c4790fd669fde4 to your computer and use it in GitHub Desktop.
Save ozcanzaferayan/3ab345d4b828d09f48c4790fd669fde4 to your computer and use it in GitHub Desktop.
jsi::Value JSCRuntime::evaluateJavaScript(
const std::shared_ptr<const jsi::Buffer> &buffer,
const std::string &sourceURL) {
std::string tmp(
reinterpret_cast<const char *>(buffer->data()), buffer->size());
JSStringRef sourceRef = JSStringCreateWithUTF8CString(tmp.c_str());
JSStringRef sourceURLRef = nullptr;
if (!sourceURL.empty()) {
sourceURLRef = JSStringCreateWithUTF8CString(sourceURL.c_str());
}
JSValueRef exc = nullptr;
JSValueRef res =
JSEvaluateScript(ctx_, sourceRef, nullptr, sourceURLRef, 0, &exc);
JSStringRelease(sourceRef);
if (sourceURLRef) {
JSStringRelease(sourceURLRef);
}
checkException(res, exc);
return createValue(res);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment