void JSCExecutor::loadApplicationScript( const std::string& script, const std::string& sourceURL) { ReactMarker::logMarker("loadApplicationScript_startStringConvert"); #if WITH_FBJSCEXTENSIONS JSStringRef jsScriptRef; if (usePreparsingAndStringRef()){ jsScriptRef = JSStringCreateWithUTF8CStringExpectAscii(script.c_str(), script.size()); } else { jsScriptRef = JSStringCreateWithUTF8CString(script.c_str()); } String jsScript = String::adopt(jsScriptRef); #else String jsScript = String::createExpectingAscii(script); #endif ReactMarker::logMarker("loadApplicationScript_endStringConvert"); String jsSourceURL(sourceURL.c_str()); #ifdef WITH_FBSYSTRACE FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "JSCExecutor::loadApplicationScript", "sourceURL", sourceURL); #endif if (!jsSourceURL || !usePreparsingAndStringRef()) { evaluateScript(m_context, jsScript, jsSourceURL); } else { // If we're evaluating a script, get the device's cache dir // in which a cache file for that script will be stored. evaluateScript(m_context, jsScript, jsSourceURL, m_deviceCacheDir.c_str()); } flush(); ReactMarker::logMarker("CREATE_REACT_CONTEXT_END"); }
bool SkAnimatorScript::evaluate(const char* original, SkScriptValue* result, SkDisplayTypes type) { const char* script = original; bool success = evaluateScript(&script, result); if (success == false || result->fType != type) { fMaker.setScriptError(*this); return false; } return true; }
static JSValueRef nativeInjectHMRUpdate( JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { String execJSString = Value(ctx, arguments[0]).toString(); String jsURL = Value(ctx, arguments[1]).toString(); evaluateScript(ctx, execJSString, jsURL); return JSValueMakeUndefined(ctx); }
void JSCExecutor::executeApplicationScript( const std::string& script, const std::string& sourceURL) { ReactMarker::logMarker("executeApplicationScript_startStringConvert"); String jsScript = String::createExpectingAscii(script); ReactMarker::logMarker("executeApplicationScript_endStringConvert"); String jsSourceURL(sourceURL.c_str()); #ifdef WITH_FBSYSTRACE FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "JSCExecutor::executeApplicationScript", "sourceURL", sourceURL); #endif if (!jsSourceURL) { evaluateScript(m_context, jsScript, jsSourceURL); } else { // If we're evaluating a script, get the device's cache dir // in which a cache file for that script will be stored. evaluateScript(m_context, jsScript, jsSourceURL, m_deviceCacheDir.c_str()); } }
void ScriptElementData::execute(CachedScript* cachedScript) { ASSERT(cachedScript); if (cachedScript->errorOccurred()) m_scriptElement->dispatchErrorEvent(); else { evaluateScript(ScriptSourceCode(cachedScript)); m_scriptElement->dispatchLoadEvent(); } cachedScript->removeClient(this); }
commandDialog::commandDialog(commandHandler *comHandler, QWidget *parent) : QDialog(parent) { this->commands = comHandler; this->textOutput = new textOutputDisplay(this); this->commandInput = new commandInputWidget(this->commands,this); QVBoxLayout *commandLayout = new QVBoxLayout(this); commandLayout->addWidget(this->textOutput); commandLayout->addWidget(this->commandInput); connect(this->commandInput,SIGNAL(executeScript(QString)),this->commands,SLOT(evaluateScript(QString))); connect(this->commands,SIGNAL(generatedError(QString)),this->textOutput,SLOT(addError(QString))); connect(this->commands,SIGNAL(generatedInfo(QString)),this->textOutput,SLOT(addInfo(QString))); this->commandInput->updateAutocompletion(); this->hide(); }
void JSCExecutor::loadApplicationScript( const std::string& script, const std::string& sourceURL) { ReactMarker::logMarker("loadApplicationScript_startStringConvert"); String jsScript = String::createExpectingAscii(script); ReactMarker::logMarker("loadApplicationScript_endStringConvert"); String jsSourceURL(sourceURL.c_str()); #ifdef WITH_FBSYSTRACE FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "JSCExecutor::loadApplicationScript", "sourceURL", sourceURL); #endif evaluateScript(m_context, jsScript, jsSourceURL); flush(); ReactMarker::logMarker("CREATE_REACT_CONTEXT_END"); }
void JSCWebWorker::initJSVMAndLoadScript() { CHECK(!isTerminated()) << "Worker was already finished!"; CHECK(!context_) << "Worker JS VM was already created!"; context_ = JSGlobalContextCreateInGroup( NULL, // use default JS 'global' object NULL // create new group (i.e. new VM) ); s_globalContextRefToJSCWebWorker[context_] = this; // TODO(9604438): Protect against script does not exist std::unique_ptr<const JSBigString> script = WebWorkerUtil::loadScriptFromAssets(scriptName_); evaluateScript(context_, jsStringFromBigString(*script), String(scriptName_.c_str())); installGlobalFunction(context_, "postMessage", nativePostMessage); }
void JSCWebWorker::initJSVMAndLoadScript() { FBASSERTMSGF(!isTerminated(), "Worker was already finished!"); FBASSERTMSGF(!context_, "Worker JS VM was already created!"); context_ = JSGlobalContextCreateInGroup( NULL, // use default JS 'global' object NULL // create new group (i.e. new VM) ); s_globalContextRefToJSCWebWorker[context_] = this; // TODO(9604438): Protect against script does not exist std::string script = loadScriptFromAssets(scriptName_); evaluateScript(context_, String(script.c_str()), String(scriptName_.c_str())); installGlobalFunction(context_, "postMessage", nativePostMessage); }
static std::string executeJSCallWithJSC( JSGlobalContextRef ctx, const std::string& methodName, const std::vector<folly::dynamic>& arguments) { #ifdef WITH_FBSYSTRACE FbSystraceSection s( TRACE_TAG_REACT_CXX_BRIDGE, "JSCExecutor.executeJSCall", "method", methodName); #endif // Evaluate script with JSC folly::dynamic jsonArgs(arguments.begin(), arguments.end()); auto js = folly::to<folly::fbstring>( "__fbBatchedBridge.", methodName, ".apply(null, ", folly::toJson(jsonArgs), ")"); auto result = evaluateScript(ctx, String(js.c_str()), nullptr); return Value(ctx, result).toJSONString(); }
void ScriptElementData::notifyFinished(CachedResource* o) { CachedScript* cs = static_cast<CachedScript*>(o); ASSERT(cs == m_cachedScript); // Evaluating the script could lead to a garbage collection which can // delete the script element so we need to protect it and us with it! RefPtr<Element> protector(m_element); if (cs->errorOccurred()) m_scriptElement->dispatchErrorEvent(); else { evaluateScript(ScriptSourceCode(cs)); m_scriptElement->dispatchLoadEvent(); } stopLoadRequest(); }
/*! \brief \param fileInfo \param log \param QHash<QString \param tags \param QHash<QString \param tagsCopy \return QList<M3uEntry> */ QList<M3uEntry> PlayList::processFile(const QFileInfo& fileInfo, bool keepTags, const QString &format, QString* log, QHash<QString, Tag*> *tags, QHash<QString, Tag*> *tagsCopy, bool *wasCanceled ) const { QList<M3uEntry> list; QString file = fileInfo.fileName(); QString fullfile = fileInfo.absoluteFilePath(); bool redirectCerr = guiSettings->value("RedirectCerr").toBool(); std::streambuf *sbuf=0; std::stringstream *buffer=0; if(redirectCerr){ sbuf = std::cerr.rdbuf(); buffer = new std::stringstream; std::cerr.rdbuf(buffer->rdbuf()); } Tag *tag=0; if (includeExtInf_) { //take tag from the inital copy of tags. If it doesnt exist there, read it, and insert into //the original qhash of tags tag = tagsCopy->take(fullfile); if (!tag) { tag = new Tag(fullfile,0,true,true); //read both tags and frames if (keepTags) { tags->insert(fullfile, tag); } } } QString cerr = QString(buffer->str().c_str()); if(!cerr.isEmpty()&&log!=0){ log->append(cerr); } std::cerr.rdbuf(sbuf); delete buffer; buffer=0; //loop list of individual files. If file matches one of the indiviudally specified files, it is //added. /* //if the file equals one of the specified individual files, //always include it regardless of rules for (int i = 0; i < individualFiles_.size(); i++) { if (file == individualFiles_[i].absoluteFilePath()) { skipRules = true; break; } } */ //process script QString extInf; QString sortBy; QString errorLog; bool include = evaluateScript( tag, fileInfo, &errorLog, &extInf, &sortBy ); if( !errorLog.isEmpty() ){ //Cancel generation if an error is found in the script *wasCanceled = true; log->append("\nError occurred in script: "+errorLog); return list; } //decide to include or not M3uEntry e; if ( include ) { //extinf info for m3u if (includeExtInf_) { if(!extInf.isEmpty()){ e.setExtInf(extInf); }else{ e.setExtInf(createExtInfString(tag, file, format)); } } e.setSortBy(sortBy); e.setOriginalFile(fileInfo); list.append(e); } if(!keepTags){ delete tag; } return list; }
void JSCExecutor::loadModule(uint32_t moduleId) { auto module = m_unbundle->getModule(moduleId); auto sourceUrl = String::createExpectingAscii(module.name); auto source = String::createExpectingAscii(module.code); evaluateScript(m_context, source, sourceUrl); }