MatchCreator::Description ScriptMatchCreator::_getScriptDescription(QString path) const { MatchCreator::Description result; result.experimental = true; shared_ptr<PluginContext> script(new PluginContext()); HandleScope handleScope; Context::Scope context_scope(script->getContext()); script->loadScript(path, "plugin"); Persistent<Object> plugin = ScriptMatchVisitor::getPlugin(script); Handle<String> descriptionStr = String::New("description"); if (plugin->Has(descriptionStr)) { Handle<v8::Value> value = plugin->Get(descriptionStr); result.description = toCpp<QString>(value); } Handle<String> experimentalStr = String::New("experimental"); if (plugin->Has(experimentalStr)) { Handle<v8::Value> value = plugin->Get(experimentalStr); result.experimental = toCpp<bool>(value); } QFileInfo fi(path); result.className = (QString::fromStdString(className()) + "," + fi.fileName()).toStdString(); return result; }
/* * This is meant to run one time when the match creator is initialized. */ void customScriptInit() { Context::Scope context_scope(_script->getContext()); HandleScope handleScope; Persistent<Object> plugin = getPlugin(); Handle<String> initStr = String::New("init"); if (plugin->Has(initStr) == false) { throw HootException("Error finding 'init' function."); } Handle<v8::Value> value = plugin->Get(initStr); if (value->IsFunction() == false) { throw HootException("init is not a function."); } Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(value); Handle<Value> jsArgs[1]; int argc = 0; HandleScope scope; assert(_map.get()); OsmMapPtr copiedMap(new OsmMap(_map)); jsArgs[argc++] = OsmMapJs::create(copiedMap); func->Call(plugin, argc, jsArgs); //this is meant to have been set externally in a js rules file _searchRadius = getNumber(plugin, "searchRadius", -1.0, 15.0); }
bool isMatchCandidate(ConstElementPtr e) { Context::Scope context_scope(_script->getContext()); HandleScope handleScope; Persistent<Object> plugin = getPlugin(); Handle<String> isMatchCandidateStr = String::New("isMatchCandidate"); if (plugin->Has(isMatchCandidateStr) == false) { throw HootException("Error finding 'isMatchCandidate' function."); } Handle<v8::Value> value = plugin->Get(isMatchCandidateStr); if (value->IsFunction() == false) { throw HootException("isMatchCandidate is not a function."); } Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(value); Handle<Value> jsArgs[2]; int argc = 0; jsArgs[argc++] = OsmMapJs::create(_map); jsArgs[argc++] = ElementJs::New(e); Handle<Value> f = func->Call(plugin, argc, jsArgs); return f->BooleanValue(); }
static Handle<Value> TitaniumCountlyAndroidMessaging_getBinding(const Arguments& args) { HandleScope scope; if (args.Length() == 0) { return ThrowException(Exception::Error(String::New("TitaniumCountlyAndroidMessaging.getBinding requires 1 argument: binding"))); } if (bindingCache.IsEmpty()) { bindingCache = Persistent<Object>::New(Object::New()); } Handle<String> binding = args[0]->ToString(); if (bindingCache->Has(binding)) { return bindingCache->Get(binding); } String::Utf8Value bindingValue(binding); LOGD(TAG, "Looking up binding: %s", *bindingValue); titanium::bindings::BindEntry *extBinding = ::TitaniumCountlyAndroidMessagingBindings::lookupGeneratedInit( *bindingValue, bindingValue.length()); if (!extBinding) { LOGE(TAG, "Couldn't find binding: %s, returning undefined", *bindingValue); return Undefined(); } Handle<Object> exports = Object::New(); extBinding->bind(exports); bindingCache->Set(binding, exports); return exports; }