Example #1
0
void ETW::EnableProvider(const FunctionCallbackInfo<Value>& args)
{
    GUID nodeGuid;
    int wchars_num =  MultiByteToWideChar(CP_UTF8 , 0 , *String::Utf8Value(args[0]), -1, NULL , 0 );
    wchar_t* szGuid = new wchar_t[wchars_num];
    MultiByteToWideChar(CP_UTF8, 0, *String::Utf8Value(args[0]), -1, szGuid, wchars_num);
    ZeroMemory(&nodeGuid, sizeof(GUID));        
    if (IIDFromString(szGuid, &nodeGuid) != S_OK)        
    {
        delete[] szGuid;
        Nan::ThrowTypeError("First argument must be a valid GUID in the form of \"{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}\"");
        return;
    }
    
    delete[] szGuid;

    UCHAR logLevel = args[1]->Uint32Value();

    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);
    ETW* obj = ObjectWrap::Unwrap<ETW>(args.Holder());
    args.GetReturnValue().Set(Boolean::New(isolate, obj->m_pTraceSession->EnableProvider(nodeGuid, logLevel)));
}
void PassArray(const FunctionCallbackInfo<Value>& args) {
    Isolate * isolate = args.GetIsolate();
    Local<Array> array = Local<Array>::Cast(args[0]);

    if ( args.Length() < 1 || ! args[0]->IsArray()) {
        return;
    }

    if (array->Length() < 3) {
        return;
    }

    Local<String> prop = String::NewFromUtf8(isolate, "not_index");
    if (array->Get(prop)->IsUndefined() ){
        return;
    }

    for (unsigned int i = 0; i < 3; i++ ) {
      if (array->Has(i)) {
        Local<Value> v = array->Get(i);
        if ( !v->IsNumber()) return;

        double value = v->NumberValue();
        array->Set(i, Number::New(isolate, value + 1));
      }
      else {
        return;
      }
    }

    Local<Array> a = Array::New(isolate);
    a->Set(0, array->Get(0));
    a->Set(1, array->Get(prop));
    a->Set(2, array->Get(2));

    args.GetReturnValue().Set(a);
}
static void
gum_script_process_on_enumerate_threads (
    const FunctionCallbackInfo<Value> & info)
{
  GumScriptMatchContext ctx;

  ctx.self = static_cast<GumScriptProcess *> (
      info.Data ().As<External> ()->Value ());
  ctx.isolate = info.GetIsolate ();

  Local<Value> callbacks_value = info[0];
  if (!callbacks_value->IsObject ())
  {
    ctx.isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (
        ctx.isolate, "Process.enumerateThreads: argument must be "
        "a callback object")));
    return;
  }

  Local<Object> callbacks = Local<Object>::Cast (callbacks_value);
  if (!_gum_script_callbacks_get (callbacks, "onMatch", &ctx.on_match,
      ctx.self->core))
  {
    return;
  }
  if (!_gum_script_callbacks_get (callbacks, "onComplete", &ctx.on_complete,
      ctx.self->core))
  {
    return;
  }

  ctx.receiver = info.This ();

  gum_process_enumerate_threads (gum_script_process_thread_match, &ctx);

  ctx.on_complete->Call (ctx.receiver, 0, 0);
}
Example #4
0
void MySQL::JS_Connect(const FunctionCallbackInfo<Value> & args){
	auto mysql = Instance(args.Holder());
	auto mysqlconn = ConnectionInstance(args.Holder());
	
	string host = JS2STRING(args[0]);
	string user = JS2STRING(args[1]);
	string password = JS2STRING(args[2]);
	string database = JS2STRING(args[3]);

	if (args[4]->IsFunction()){
		Persistent<Function,CopyablePersistentTraits<Function>> func;
		func.Reset(args.GetIsolate(), Local<Function>::Cast(args[4]));

		thread( [mysql, mysqlconn, host, user, password, database,func](){
			mysql_thread_init();
			std::lock_guard<std::mutex> lock{ mysqlconn->lock };
			mysql->ConnectAsync(mysqlconn->id, host, user, password, database,func);
			mysql_thread_end();
		}).detach();
	}
	else {
		if (mysql_real_connect(
			mysqlconn->mysql,
			host.c_str(),
			user.c_str(),
			password.c_str(),
			database.c_str(),
			0,
			NULL,
			0) == NULL){
			sjs::logger::error("MySQL Connect Error: %s", mysql_error(mysqlconn->mysql));
			args.GetReturnValue().Set(false);
			return;
		}
	}
	args.GetReturnValue().Set(true);
}
Example #5
0
void Query::exec(const FunctionCallbackInfo<Value>& args)
{
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);

    if (args.Length() != 1) {
        Local<String> str = String::NewFromUtf8(isolate, "Baloo.Query.exec expects 1 agument");
        isolate->ThrowException(Exception::TypeError(str));
        return;
    }

    if (!args[0]->IsFunction()) {
        Local<String> str = String::NewFromUtf8(isolate, "Argument must be a callback function");
        isolate->ThrowException(Exception::TypeError(str));
        return;
    }

    Query* query = ObjectWrap::Unwrap<Query>(args.Holder());
    Baloo::Query q = query->m_query;
    Baloo::ResultIterator it = q.exec();

    QStringList results;
    while (it.next()) {
        results << it.filePath();
    }

    Handle<Array> array = Array::New(isolate, results.size());
    for (int i = 0; i < results.length(); i++) {
        const QByteArray arr = results[i].toUtf8();
        Local<String> str = String::NewFromUtf8(isolate, arr.constData());
        array->Set(i, str);
    }

    Local<Function> cb = Local<Function>::Cast(args[0]);
    Local<Value> argv[1] = { array };
    cb->Call(isolate->GetCurrentContext()->Global(), 1, argv);
}
void BoilerControlWrapper::New(const FunctionCallbackInfo<Value>& args) {
  Isolate* isolate = Isolate::GetCurrent();
  HandleScope scope(isolate);

  if (args.IsConstructCall()) {
    // Invoked as constructor: `new MyObject(...)`
    int pin = args[0]->IsUndefined() ? 0 : args[0]->NumberValue();
    BoilerControlWrapper* obj;
    if(args[1]->IsUndefined()) {
      obj = new BoilerControlWrapper(pin);
    }
    else {
      obj = new BoilerControlWrapper(pin, args[1]->NumberValue());
    }
    obj->Wrap(args.This());
    args.GetReturnValue().Set(args.This());
  } else {
    // Invoked as plain function `MyObject(...)`, turn into construct call.
    const int argc = 1;
    Local<Value> argv[argc] = { args[0] };
    Local<Function> cons = Local<Function>::New(isolate, constructor);
    args.GetReturnValue().Set(cons->NewInstance(argc, argv));
  }
}
Example #7
0
void LCDWrapper::New(const FunctionCallbackInfo<Value>& args){
  Isolate* isolate = Isolate::GetCurrent();
  HandleScope scope(isolate);

  uint8_t _add = 0x01;
  // If there are two params: First Param => i2c address, second => Port number
  // - Only one Param, this means that the given param is the Port Number,
  LCDWrapper* obj;
  uint8_t _argc = args.Length();
  if(args.IsConstructCall()){
    // Invoked as constructor: `new MyObject(...)`
    switch(_argc){
      case 0:
        obj = new LCDWrapper();
        obj->Wrap(args.This());
        args.GetReturnValue().Set(args.This());
        break;
      case 1:
        _add = (uint8_t) args[0]->NumberValue();
        obj = new LCDWrapper(_add);
        obj->Wrap(args.This());
        args.GetReturnValue().Set(args.This());
        break;
      default:
        isolate->ThrowException(Exception::TypeError(
        String::NewFromUtf8(isolate, "Wrong arguments...")));
    }
  }else{
    // Invoked as plain function `MyObject(...)`, turn into construct call.
    if(_argc > 1){
      isolate->ThrowException(Exception::TypeError(
      String::NewFromUtf8(isolate, "Wrong arguments...")));
    }
    Local<Value>* argv = new Local<Value>[_argc];
    for(uint8_t i = 0; i < _argc; i++){
      argv[i] = args[i];
    }
    Local<Function> cons = Local<Function>::New(isolate, constructor);
    args.GetReturnValue().Set(cons->NewInstance(_argc, argv));
  }
}
Example #8
0
void SAMPJS::JS_GlobalEvent(const FunctionCallbackInfo<Value> &args){
	for (auto scriptv : scripts){
		//Isolate *isolate = script.second->GetIsolate();
	//	Local<Context> context = Local<Context>::New(isolate, script.second->GetContext());
		auto script = scripts_map[scriptv];
		string name;
		if (args.Length() > 0){
			if (!args[0]->IsString()){
				return;
			}

			name = JS2STRING(args[0]);
			Local<Value> * argv = NULL;
			int argc = args.Length() - 1;
			if (args.Length() > 1){
				argv = new Local<Value>[args.Length() - 1];
				for (int i = 1; i < args.Length(); i++){
					argv[i-1] = args[i];
				}
			}
			script->Server()->FireEvent(name, argc, argv );
		}
	}
}
Example #9
0
void WeakRef::ClearCallback(const FunctionCallbackInfo<Value>& args)
{
	try
	{
		auto holder = args.This();
		auto isolate = args.GetIsolate();

		holder->SetHiddenValue(V8StringConstants::GetTarget(), External::New(isolate, nullptr));
	}
	catch (NativeScriptException& e)
	{
		e.ReThrowToV8();
	}
	catch (std::exception e) {
		stringstream ss;
		ss << "Error: c++ exception: " << e.what() << endl;
		NativeScriptException nsEx(ss.str());
		nsEx.ReThrowToV8();
	}
	catch (...) {
		NativeScriptException nsEx(std::string("Error: c++ exception!"));
		nsEx.ReThrowToV8();
	}
}
void PassString(const FunctionCallbackInfo<Value>& args) {
    Isolate * isolate = args.GetIsolate();

    if ( args.Length() < 1 ) {
        return;
    }
    else if ( args[0]->IsNull() ) {
        return;
    }
    else if ( args[0]->IsUndefined() ) {
        return;
    }
    else if (!args[0]->IsString()) {
        // This clause would catch IsNull and IsUndefined too...
        return ;
    }

    v8::String::Utf8Value s(args[0]);
    std::string str(*s, s.length());
    std::reverse(str.begin(), str.end());

    Local<String> retval = String::NewFromUtf8(isolate, str.c_str());
    args.GetReturnValue().Set(retval);
}
Example #11
0
/*
 * Prototype:
 * Stalker.unfollow(thread_id)
 *
 * Docs:
 * TBW
 *
 * Example:
 * TBW
 */
static void
gum_v8_stalker_on_unfollow (const FunctionCallbackInfo<Value> & info)
{
  GumV8Stalker * self = static_cast<GumV8Stalker *> (
      info.Data ().As<External> ()->Value ());
  GumStalker * stalker;
  GumThreadId thread_id;

  stalker = _gum_v8_stalker_get (self);

  if (info.Length () > 0)
    thread_id = info[0]->IntegerValue ();
  else
    thread_id = gum_process_get_current_thread_id ();

  if (thread_id == gum_process_get_current_thread_id ())
  {
    self->pending_follow_level--;
  }
  else
  {
    gum_stalker_unfollow (stalker, thread_id);
  }
}
Example #12
0
void constructByteArray(const FunctionCallbackInfo<Value>& args)
{
	if (!args.IsConstructCall()) {
		Utility::throwException(args.GetIsolate(), Utility::ExceptionMustCallAsConstructor);
		return;
	}
	if (args.Length() == 0) {
		Utility::throwException(args.GetIsolate(), Utility::ExceptionInvalidArgumentCount);
		return;
	}

	QByteArray data;

	if (args[0]->IsArrayBuffer()) {
		data = Utility::toByteArray(args[0]);
	}
	else if (args[0]->IsString()) {
		int format = 0;
		if (args.Length() >= 2 && args[1]->IsInt32())
			format = args[1]->Int32Value();
		if (format < 0 || format > 3) {
			Utility::throwException(args.GetIsolate(), Utility::ExceptionInvalidArgumentValue);
			return;
		}
		data = byteArrayFromString(Utility::toString(args[0]).toLatin1(), format);
	}
	else {
		Utility::throwException(args.GetIsolate(), Utility::ExceptionInvalidArgumentType);
		return;
	}

	HandleScope handle_scope(args.GetIsolate());

	// Return the constructed object
	args.GetReturnValue().Set(ModuleByteArray::wrapByteArray(args.GetIsolate(), data));
}
Example #13
0
void GetProcessByName(const FunctionCallbackInfo<Value>& args)
{
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);

    /*if (args.Length() < 1)
    {
        isolate->ThrowException(Exception::TypeError(
            String::NewFromUtf8(isolate, "Wrong number of arguments")));
        return;
    }

    if (!args[0]->IsString())
    {
        isolate->ThrowException(Exception::TypeError(
            String::NewFromUtf8(isolate, "Wrong arguments")));
        return;
    }*/

    String::Utf8Value procName(args[0]->ToString());

    HANDLE hdl = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);;

    PROCESSENTRY32 pe32;
    pe32.dwSize = sizeof(PROCESSENTRY32);

    BOOL rval;
    for (rval = Process32First(hdl, &pe32);
         rval == TRUE && strcmpi(pe32.szExeFile, *procName) != 0;
         rval = Process32Next(hdl, &pe32));

    if (hdl != INVALID_HANDLE_VALUE)
    {
        CloseHandle(hdl);
    }

    Local<Number> num;
    if (rval == TRUE)
    {
        num = Number::New(isolate, pe32.th32ProcessID);
    }
    else
    {
        num = Number::New(isolate, 0);
    }

    args.GetReturnValue().Set(num);
}
Example #14
0
// Defines a Point() JS Object
void PointConstructor( const FunctionCallbackInfo<v8::Value>& args )
{
    //Locker lock;
    HandleScope scope;
	Handle<ObjectTemplate> t = v8::ObjectTemplate::New();

	//The JavaScript point object only has 1 C++ object
	t->SetInternalFieldCount(1);

	// Create x and y members with starting values of 0
	//t->Set(String::New("x"), Number::New(0));
	t->SetAccessor(String::New("x"), 
		(AccessorGetterCallback)GetPointX,
		(AccessorSetterCallback)SetPointX);

	//t->Set(String::New("y"), Number::New(0));
	t->SetAccessor(String::New("y"),
		(AccessorGetterCallback)GetPointY,
		(AccessorSetterCallback)SetPointY);

	// Create a mul(number) function that scales the point
	t->Set(String::New("mul"), FunctionTemplate::New(MulCallback));

	// for use in the if statement
	Point *p = NULL;
	Local<Object> obj;
	
	// If Point(x, y) ctor was passed in values assign them
	if(!args[0].IsEmpty() && args[0]->IsNumber() &&
		!args[1].IsEmpty() && args[1]->IsNumber()) {
			//t->Set(String::New("x"), args[0]);
			//t->Set(String::New("y"), args[1]);
			p = new Point(args[0]->Int32Value(), args[1]->Int32Value());
			obj = t->NewInstance();
			obj->SetInternalField(0, External::New(p));			
	} else {
		/**
		 * Wrap a point object
		 */
		p = new Point(0, 0);
		obj = t->NewInstance();
		obj->SetInternalField(0, External::New(p));
	}

	// Return this newly created object
	args.GetReturnValue().Set(obj);
}
Example #15
0
void get_master_player_by_cid(const FunctionCallbackInfo<Value>& args) {
	if (args.Length() != 2) {
		LOG_ERROR("get_master_player_by_cid args error, length: %d\n", args.Length());
		args.GetReturnValue().SetNull();
		return;
	}

	int gate_cid = args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromMaybe(0);
	int player_cid = args[1]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromMaybe(0);
	Master_Player *player = MASTER_MANAGER->find_gate_cid_master_player(gate_cid * 10000 + player_cid);
	if (player) {
		args.GetReturnValue().Set(wrap_master_player(args.GetIsolate(), player));
	} else {
		//设置对象为空
		args.GetReturnValue().SetNull();
		MASTER_MANAGER->close_client(gate_cid, player_cid, ERROR_CLIENT_PARAM);
	}
}
Example #16
0
void EModuleHelper::ProcessNextChunk( const FunctionCallbackInfo< Value >& args )
{
	Isolate* isolate = args.GetIsolate( );
	HandleScope scope( isolate );

	Local< Context > context = isolate->GetCurrentContext( );

	CAsyncWriter* pWrite = new CAsyncWriter;
	{
		pWrite->SetParams(
			isolate, 
			reinterpret_cast< CQuery* >( args[ 0 ]->IntegerValue( context ).FromJust( ) ), 
			args[ 1 ].As< Uint8Array >( ),
			args[ 2 ].As< Function >( )
			);
	}
	pWrite->RunOperation( );
}
Example #17
0
void EModuleHelper::RequestNextChunk( const FunctionCallbackInfo< Value >& args )
{
	Isolate* isolate = args.GetIsolate( );
	HandleScope scope( isolate );

	Local< Context > context = isolate->GetCurrentContext( );

	CAsyncReader* pRead = new CAsyncReader;
	{
		pRead->SetParams(
			isolate,
			reinterpret_cast< CQuery* >( args[ 0 ]->IntegerValue( context ).FromJust( ) ),
			static_cast< SQLUSMALLINT >( args[ 1 ]->Uint32Value( context ).FromJust( ) ),
			args[ 2 ].As<Function>( )
		);
	}
	pRead->RunOperation( );
}
  void BoilerControlWrapper::SendOffSignal(const FunctionCallbackInfo<Value>& args) {
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);

    BoilerControlWrapper* obj = ObjectWrap::Unwrap<BoilerControlWrapper>(args.Holder());

    TransmitPin* transmitPin;
    if(obj->nonRealtimeOffset != -1) {
      transmitPin = TransmitPinFactory::create(obj->pin, obj->nonRealtimeOffset);
    }
    else {
      transmitPin = TransmitPinFactory::create(obj->pin);
    }

    BoilerControl* boilercontrol = new BoilerControl(transmitPin);
    boilercontrol->sendOffSignal();
    delete boilercontrol;
  }
void Factorial(const FunctionCallbackInfo<Value>& args) {
	Isolate* isolate = Isolate::GetCurrent();
	HandleScope scope(isolate);

	if (args.Length() != 2) {
		isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments")));
	} else {
		if (!(args[0]->IsNumber() && args[1]->IsFunction())) {
			isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong arguments type")));
		} else {
			int result = factorial(args[0]->Int32Value());

			Local<Function> callbackFunction = Local<Function>::Cast(args[1]);
			const unsigned argc = 1;
			Local<Value> argv[argc] = { Number::New(isolate, result) };

			callbackFunction->Call(isolate->GetCurrentContext()->Global(), argc, argv);
		}
	}
}
void Initialize(const FunctionCallbackInfo<Value>& args)
{
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);

    if (args.Length() < 1){
        isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "init() requires an object")));
        return;
    }

    Local<Object> o = args[0].As<Object>();

    char* appName = NULL;
    char* tempDirPath = NULL;

    Local<String> appKey = String::NewFromUtf8(isolate, "appName");
    Local<String> tempDirKey = String::NewFromUtf8(isolate, "tempDir");

    if (o->Has(appKey)){
        String::Utf8Value v(o->Get(appKey)->ToString());
        size_t len = strlen(*v) + 1;
        appName = new char[len];
        sprintf(appName, "%s", *v);
    }

    if (o->Has(tempDirKey)){
        String::Utf8Value v(o->Get(tempDirKey)->ToString());
        size_t len = strlen(*v) + 1;
        tempDirPath = new char[len];
        sprintf(tempDirPath, "%s", *v);
    }

    if (appName == NULL || tempDirPath == NULL){
        isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "init() requires 'appName' and 'tempDir'")));
        return;
    }

    WindowsToastNotification::InitSystemProps(appName, tempDirPath);
    DELETE_IF(appName);
    DELETE_IF(tempDirPath);
}
Example #21
0
void EditorGetCurrentLine(const FunctionCallbackInfo<Value>& args)
{
	CComPtr<VirtualPoint> virtualPoint;
	CComPtr<EditPoint> editPoint;

	long lineLen;
	BSTR currentLine;
    BSTR retVal;

	g_Options.m_selection->get_ActivePoint(&virtualPoint);
	virtualPoint->CreateEditPoint(&editPoint);
	editPoint->StartOfLine();
	editPoint->get_LineLength(&lineLen);
	editPoint->GetText(CComVariant(lineLen), &currentLine);

    StripCarriageReturns(currentLine, &retVal);

    args.GetReturnValue().Set(String::New(retVal, SysStringLen(retVal)));

    SysFreeString(retVal);
}
Example #22
0
/*
 * Prototype:
 * Thread.sleep(delay)
 *
 * Docs:
 * TBW
 *
 * Example:
 * TBW
 */
static void
gum_script_thread_on_sleep (const FunctionCallbackInfo<Value> & info)
{
  Isolate * isolate = info.GetIsolate ();

  Local<Value> delay_val = info[0];
  if (!delay_val->IsNumber ())
  {
    isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate,
        "Thread.sleep: argument must be a number specifying delay")));
    return;
  }
  double delay = delay_val->ToNumber ()->Value ();

  isolate->Exit ();
  {
    Unlocker ul (isolate);
    g_usleep (delay * G_USEC_PER_SEC);
  }
  isolate->Enter ();
}
        inline typename boost::enable_if<boost::is_member_function_pointer<TCallback>, Handle<Value> >::type
        operator () (const FunctionCallbackInfo<Value> &info)
        {
            typedef typename mpl::begin<TSignature>::type TSeqFirst;
            typedef typename TSeqFirst::type TResult;
            typedef typename mpl::next< TSeqFirst >::type TSeqInstanceType;
            
            typedef typename boost::remove_const<typename boost::remove_reference<typename TSeqInstanceType::type>::type >::type TInstanceType;
            
            /* Retrieve "this" from V8 */
            Local<Object> _this = info.Holder();
            
            /* Get address by casting the External saved value.
             Note that it was saved in NativeClass<TClass>::ctor */
            TInstanceType *instance = static_cast<TInstanceType *>(_this->GetAlignedPointerFromInternalField(_this->InternalFieldCount() - 2));
            
#if V8BRIDGE_DEBUG /* By default, we're always calling isInvokable before operator() (see NativeFunction), so we don't need this.
I'm leaving this validation in operator() too only for debugging sake. */
            if (!this->isInvokable(info)) {
                return v8::Undefined(this->m_isolationScope);
            }
#endif
            
# if N
#  define BOOST_PP_LOCAL_MACRO(i) V8_BRIDGE_SETUP_ARG(i, TSeqInstanceType)
#  define BOOST_PP_LOCAL_LIMITS (0, N-1)
#  include BOOST_PP_LOCAL_ITERATE()
# endif
            
            Handle<Value> result = bridge::detail::invoke_native(
                                                                 this->m_isolationScope,
                                                                 detail::invoke_tag<TResult, TPointer>()
                                                                 , this->m_callbackPointer
                                                                 , instance
                                                                 BOOST_PP_ENUM_TRAILING_PARAMS(N, resolvedArg)
                                                                 );
            
            
            return result;
        }
Example #24
0
void EditorGetContent(const FunctionCallbackInfo<Value>& args)
{
	CComPtr<TextPoint> startPoint;
	CComPtr<TextPoint> endPoint;
	CComPtr<EditPoint> startEditPoint;
	CComPtr<EditPoint> endEditPoint;
	BSTR buf;
    BSTR retVal;

	g_Options.m_textDoc->get_StartPoint(&startPoint);
	g_Options.m_textDoc->get_EndPoint(&endPoint);
	startPoint->CreateEditPoint(&startEditPoint);
	endPoint->CreateEditPoint(&endEditPoint);

	startEditPoint->GetText(CComVariant(endEditPoint), &buf);

    StripCarriageReturns(buf, &retVal);

	args.GetReturnValue().Set(String::New(retVal, SysStringLen(retVal)));

    SysFreeString(retVal);
}
void ABPFilterParserWrap::New(const FunctionCallbackInfo<Value>& args) {
  Isolate* isolate = args.GetIsolate();

  if (args.IsConstructCall()) {
    // Invoked as constructor: `new ABPFilterParser(...)`
    ABPFilterParserWrap* obj = new ABPFilterParserWrap();
    obj->Wrap(args.This());
    args.GetReturnValue().Set(args.This());
  } else {
    // Invoked as plain function `ABPFilterParser(...)`,
    // turn into construct call.
    const int argc = 1;
    Local<Value> argv[argc] = { args[0] };
    Local<Function> cons = Local<Function>::New(isolate, constructor);
    args.GetReturnValue().Set(cons->NewInstance(argc, argv));
  }
}
Example #26
0
void get_master_player_by_name(const FunctionCallbackInfo<Value>& args) {
	if (args.Length() != 1) {
		LOG_ERROR("get_master_player_by_name args error, length: %d\n", args.Length());
		args.GetReturnValue().SetNull();
		return;
	}

	String::Utf8Value str(args[0]);
	std::string role_name(ToCString(str));
	Master_Player *player = MASTER_MANAGER->find_role_name_master_player(role_name);
	if (player) {
		args.GetReturnValue().Set(wrap_master_player(args.GetIsolate(), player));
	} else {
		//设置对象为空
		args.GetReturnValue().SetNull();
	}
}
Example #27
0
void Proxy::getProperty(const FunctionCallbackInfo<Value>& args)
{
    Isolate* isolate = args.GetIsolate();
    // The name of the property can be passed either as
    // an argument or a data parameter.
    Local<String> name;
    if (args.Length() >= 1) {
        name = args[0]->ToString(isolate);
    } else if (args.Data()->IsString()) {
        name = args.Data().As<String>();
    } else {
        JSException::Error(isolate, "Requires property name.");
        return;
    }

    args.GetReturnValue().Set(getPropertyForProxy(isolate, name, args.Holder()));
}
Example #28
0
void EditorGetCurrentLineRange(const FunctionCallbackInfo<Value>& args)
{
	CComPtr<VirtualPoint> point;
	long charOffset;
	long lineLen;
	long absCharOffset;
	g_Options.m_selection->get_ActivePoint(&point);
	point->get_AbsoluteCharOffset(&absCharOffset);
	point->get_LineCharOffset(&charOffset);
	point->get_LineLength(&lineLen);

	long lineOffset = absCharOffset - charOffset;

	Local<Context> context = Isolate::GetCurrent()->GetCurrentContext();
	Handle<Function> fCreateRange =
		Handle<Function>::Cast(context->Global()->Get(String::New(L"createRange")));

	Handle<Value> argv[] = { Int32::New(lineOffset), Int32::New(lineOffset + lineLen) };

	Handle<Value> retVal = fCreateRange->Call(fCreateRange, 2, argv);

	args.GetReturnValue().Set(retVal);
}
Example #29
0
void WeakRef::ConstructorCallback(const FunctionCallbackInfo<Value>& args)
{
	try
	{
		auto extData = args.Data().As<External>();
		auto thiz = reinterpret_cast<WeakRef*>(extData->Value());
		thiz->ConstructorCallbackImpl(args);
	}
	catch (NativeScriptException& e)
	{
		e.ReThrowToV8();
	}
	catch (std::exception e) {
		stringstream ss;
		ss << "Error: c++ exception: " << e.what() << endl;
		NativeScriptException nsEx(ss.str());
		nsEx.ReThrowToV8();
	}
	catch (...) {
		NativeScriptException nsEx(std::string("Error: c++ exception!"));
		nsEx.ReThrowToV8();
	}
}
Example #30
0
/**
 * 吉里吉里クラスから Javascript クラスを生成
 * @param args 引数
 * @return 結果
 */
void
TJSInstance::createTJSClass(const FunctionCallbackInfo<Value>& args)
{
	Isolate *isolate = args.GetIsolate();
	HandleScope handle_scope(isolate);
	if (args.Length() < 1) {
		args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "invalid param")));
		return;
	}

	// TJSクラス情報取得
	String::Value tjsClassName(args[0]);
	tTJSVariant tjsClassObj;
	TVPExecuteExpression(*tjsClassName, &tjsClassObj);
	if (tjsClassObj.Type() != tvtObject || TJS_FAILED(tjsClassObj.AsObjectClosureNoAddRef().IsInstanceOf(0,NULL,NULL,L"Class",NULL))) {
		args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "invalid param")));
		return;
	}
	
	// クラステンプレートを生成
	Local<FunctionTemplate> classTemplate = FunctionTemplate::New(isolate, tjsConstructor, TJSObject::toJSObject(isolate, tjsClassObj));
	classTemplate->SetClassName(args[0]->ToString()); // 表示名
	
	// メンバ登録処理
	for (int i=args.Length()-1;i>=0;i--) {
		String::Value className(args[i]);
		tTJSVariant classObj;
		TVPExecuteExpression(*className, &classObj);
		if (classObj.Type() == tvtObject &&
			TJS_SUCCEEDED(classObj.AsObjectClosureNoAddRef().IsInstanceOf(0,NULL,NULL,L"Class",NULL))) {
			MemberRegister *caller = new MemberRegister(isolate, classTemplate);
			tTJSVariantClosure closure(caller);
			classObj.AsObjectClosureNoAddRef().EnumMembers(TJS_IGNOREPROP, &closure, NULL);
			caller->Release();
		}
	}

	// TJS機能メソッドを登録
	Local<ObjectTemplate> protoTemplate = classTemplate->PrototypeTemplate();
	protoTemplate->Set(String::NewFromUtf8(isolate, "tjsIsValid"), FunctionTemplate::New(isolate, tjsIsValid));
	protoTemplate->Set(String::NewFromUtf8(isolate, "tjsOverride"), FunctionTemplate::New(isolate, tjsOverride));
	
	args.GetReturnValue().Set(classTemplate->GetFunction());
}