Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
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();
  }
Ejemplo n.º 3
0
/*
 * Class:     org_appcelerator_kroll_runtime_v8_V8Runtime
 * Method:    nativeRunModule
 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_org_appcelerator_kroll_runtime_v8_V8Runtime_nativeRunModule
	(JNIEnv *env, jobject self, jstring source, jstring filename, jobject activityProxy)
{
	ENTER_V8(V8Runtime::globalContext);
	titanium::JNIScope jniScope(env);

	if (moduleObject.IsEmpty()) {
		moduleObject = Persistent<Object>::New(
			V8Runtime::krollGlobalObject->Get(String::New("Module"))->ToObject());

		runModuleFunction = Persistent<Function>::New(
			Handle<Function>::Cast(moduleObject->Get(String::New("runModule"))));
	}

	Handle<Value> jsSource = TypeConverter::javaStringToJsString(source);
	Handle<Value> jsFilename = TypeConverter::javaStringToJsString(filename);
	Handle<Value> jsActivity = TypeConverter::javaObjectToJsValue(activityProxy);

	Handle<Value> args[] = { jsSource, jsFilename, jsActivity };
	TryCatch tryCatch;

	runModuleFunction->Call(moduleObject, 3, args);

	if (tryCatch.HasCaught()) {
		V8Util::openJSErrorDialog(tryCatch);
		V8Util::reportException(tryCatch, true);
	}
}
Ejemplo n.º 4
0
  /*
   * 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);
  }
Ejemplo n.º 5
0
GraphosBehavior::GraphosBehavior( Persistent<Object> instance, GameObject* owner /*= nullptr */ )
	: IComponent( owner ), instance( instance )
{
	updateFunction = Handle<Function>::Cast( instance->Get( String::New( "Update" ) ) );

	if( !updateFunction->IsFunction() )
		OutputController::PrintMessage( OutputType::Warning, "Invalid Update function." );
}
Ejemplo n.º 6
0
Archivo: edge.cpp Proyecto: slavah/edge
void init(Handle<Object> target) 
{
    DBG("edge::init");
    V8SynchronizationContext::Initialize();
    bufferConstructor = Persistent<Function>::New(Handle<Function>::Cast(
        Context::GetCurrent()->Global()->Get(String::New("Buffer")))); 
    json = Persistent<v8::Object>::New(Context::GetCurrent()->Global()->Get(String::New("JSON"))->ToObject());
    jsonParse = Persistent<Function>::New(Handle<Function>::Cast(json->Get(String::New("parse"))));
    debugMode = (0 < GetEnvironmentVariable("EDGE_DEBUG", NULL, 0));
    NODE_SET_METHOD(target, "initializeClrFunc", initializeClrFunc);
}
Ejemplo n.º 7
0
	//! 発話開始時のコールバック
	void on_speech_start(Recog* recog)
	{
		Locker lock;
		HandleScope handle;
		v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(
			module_target->Get( v8::String::New("onSpeechStart") )
		);
		if (callback->IsFunction()) {
			callback->Call(module_target, 0, nullptr);
		} else {
			std::cerr << "[Julius] Error! onSpeechStart is not Function." << std::endl;
		}
	}
Handle<Value> FdbError::NewInstance(fdb_error_t code, const char *description) {
	HandleScope scope;

	Local<Value> constructor = module->Get( String::NewSymbol("FDBError") );
	Local<Object> instance;
	if (!constructor.IsEmpty() && constructor->IsFunction()) {
		Local<Value> constructorArgs[] = { String::New(description), Integer::New(code) };
		instance = Local<Function>::Cast(constructor)->NewInstance(2, constructorArgs);
	} else {
		// We can't find the (javascript) FDBError class, so construct and throw *something*
		instance = Exception::Error(String::New("FDBError class not found.  Unable to deliver error."))->ToObject();
	}

	return scope.Close(instance);
}
Ejemplo n.º 9
0
// callback that runs the javascript in main thread
static void Callback(int i)
{
    HandleScope scope;

    // locate callback from the module context if defined by script
    // texample = require('texample')
    // texample.callback = function( ... ) { ..
    Local<Value> callback_v = module_handle->Get(callback_symbol);
    if (!callback_v->IsFunction()) {
         // callback not defined, ignore
         return;
    }
    Local<Function> callback = Local<Function>::Cast(callback_v);

    Local<Value> argv[1];
    argv[0] = Local<Value>::New(Integer::New(i));

    // call the callback and handle possible exception
    callback->Call(module_handle, 1, argv);
}
Ejemplo n.º 10
0
	//! 認識結果が返された時のコールバック
	void on_result(Recog* recog)
	{
		// 結果を走査
		for (const RecogProcess *r = recog->process_list; r; r = r->next) {
			WORD_INFO *winfo = r->lm->winfo;

			// 仮説の数に応じてループ
			for (int n = 0; n < r->result.sentnum; ++n) {
				// Windows だと起こらないらしいが Ubuntu だとたまに起こる…
				if (r->result.sent == nullptr) break;

				Sentence s   = r->result.sent[n];
				WORD_ID *seq = s.word;
				int seqnum   = s.word_num;

				// 認識結果の文章を取得
				std::string output;
				for (int i = 1; i < seqnum-1; ++i) {
					// result[n][i] = winfo->woutput[seq[i]];
					output += winfo->woutput[seq[i]];
				}

				Locker lock;
				HandleScope handle;
				v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(
					module_target->Get( v8::String::New("onResult") )
				);
				if (callback->IsFunction()) {
					const int argc = 1;
					v8::Handle<v8::Value> argv[] = {v8::String::New(output.c_str())};
					callback->Call(module_target, argc, argv);
				} else {
					std::cerr << "[Julius] Error! onResult is not Function." << std::endl;
				}
			}
		}

	}
Ejemplo n.º 11
0
JNIEXPORT jobject JNICALL
Java_org_appcelerator_kroll_runtime_v8_V8Object_nativeCallProperty
	(JNIEnv* env, jclass clazz, jlong ptr, jstring propertyName, jobjectArray args)
{
	ENTER_V8(V8Runtime::globalContext);
	JNIScope jniScope(env);

	Handle<Value> jsPropertyName = TypeConverter::javaStringToJsString(env, propertyName);
	Persistent<Object> object = Persistent<Object>((Object*) ptr);
	Local<Value> property = object->Get(jsPropertyName);
	if (!property->IsFunction()) {
		return JNIUtil::undefinedObject;
	}

	int argc = 0;
	Handle<Value>* argv = NULL;
	if (args) {
		argv = TypeConverter::javaObjectArrayToJsArguments(args, &argc);
	}

	TryCatch tryCatch;
	Local<Function> function = Local<Function>::Cast(property);
	Local<Value> returnValue = function->Call(object, argc, argv);

	if (argv) {
		delete[] argv;
	}

	if (tryCatch.HasCaught()) {
		V8Util::openJSErrorDialog(tryCatch);
		V8Util::reportException(tryCatch);
		return JNIUtil::undefinedObject;
	}

	bool isNew;
	return TypeConverter::jsValueToJavaObject(env, returnValue, &isNew);
}
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;
}
Ejemplo n.º 13
0
char* ReadLineEditor::CompletionGenerator(const char* text, int state) {
  static unsigned current_index;
  static Persistent<Array> current_completions;
  if (state == 0) {
    i::SmartPointer<char> full_text(i::StrNDup(rl_line_buffer, rl_point));
    HandleScope scope;
    Handle<Array> completions =
      Shell::GetCompletions(String::New(text), String::New(*full_text));
    current_completions = Persistent<Array>::New(completions);
    current_index = 0;
  }
  if (current_index < current_completions->Length()) {
    HandleScope scope;
    Handle<Integer> index = Integer::New(current_index);
    Handle<Value> str_obj = current_completions->Get(index);
    current_index++;
    String::Utf8Value str(str_obj);
    return strdup(*str);
  } else {
    current_completions.Dispose();
    current_completions.Clear();
    return NULL;
  }
}