当前位置: 首页>>代码示例>>C++>>正文


C++ FunctionCallbackInfo::IsConstructCall方法代码示例

本文整理汇总了C++中FunctionCallbackInfo::IsConstructCall方法的典型用法代码示例。如果您正苦于以下问题:C++ FunctionCallbackInfo::IsConstructCall方法的具体用法?C++ FunctionCallbackInfo::IsConstructCall怎么用?C++ FunctionCallbackInfo::IsConstructCall使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FunctionCallbackInfo的用法示例。


在下文中一共展示了FunctionCallbackInfo::IsConstructCall方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: New

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

        if (args.IsConstructCall()) {
            // Invoked as constructor: `new IdPool(...)`
            double value = args[0]->IsUndefined() || !args[0]->IsNumber()?
                0 : args[0]->NumberValue() / 8;

            if (value > DEFAULT_CTOR_MAX_POSSIBLE_SIZE) {
                JS_THROW(isolate, "Size too large");
                return;
            }

            // ceil
            size_t poolSize = value + (size_t)((size_t)value != value);

            try {
                IdPool* obj = new IdPool(poolSize);
                obj->Wrap(args.This());
                args.GetReturnValue().Set(args.This());
            }
            catch (std::Exception e) {
                JS_THROW(isolate, e.what());
                return;
            }
        } else {
            // Invoked as plain function `IdPool(...)`, 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));
        }
    }
开发者ID:d3lio,项目名称:JSproj,代码行数:34,代码来源:id_pool.cpp

示例2: New

void CRF::New(const FunctionCallbackInfo<Value>& args) {
    Isolate* isolate = args.GetIsolate();
    
    if (args.IsConstructCall()) {
        // Invoked as constructor: `new CRF(...)`
        
        CRF* obj = new CRF();
        
        CRFPP::Tagger* tag = CRFPP::createTagger(get(args[0]));
        if(!tag){
            
            isolate->ThrowException(Exception::TypeError(
                                                       String::NewFromUtf8(isolate, (const char *) CRFPP::getTaggerError())));
            return;
            
        }
        
        v8::Local<v8::External> handle = v8::External::New(isolate, tag);
        v8::Persistent<v8::External, v8::CopyablePersistentTraits<v8::External> > tagger(isolate, handle);
        
        obj -> tagger = tagger;
        
        obj->Wrap(args.This());
        args.GetReturnValue().Set(args.This());
    } else {
        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));
    }
}
开发者ID:janez87,项目名称:node-crf,代码行数:31,代码来源:node-crf.cpp

示例3: New

void ETW::New(const FunctionCallbackInfo<Value>& args)
{
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);

    if (args.IsConstructCall()) 
    {
        if (args[0]->IsUndefined())
        {
            Nan::ThrowTypeError("Session name is required.");
            return;
        }

        int wchars_num =  MultiByteToWideChar(CP_UTF8 , 0 , *String::Utf8Value(args[0]), -1, NULL , 0 );
        wchar_t* szSessionName = new wchar_t[wchars_num];
        MultiByteToWideChar(CP_UTF8, 0, *String::Utf8Value(args[0]), -1, szSessionName, wchars_num);

        // Invoked as constructor: `new ETW(...)`
        ETW* obj = new ETW(szSessionName);
        obj->Wrap(args.This());
        args.GetReturnValue().Set(args.This());
    } 
    else 
    {
        // Invoked as plain function `ETW(...)`, 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));
    }
}
开发者ID:mattpodwysocki,项目名称:node-etw,代码行数:31,代码来源:etwtrace.cpp

示例4: New

    void Connection::New(const FunctionCallbackInfo<Value>& info)
    {
	   if (!info.IsConstructCall()) {
		  return;
	   }

	   auto c = new Connection();
	   c->Wrap(info.This());
	   info.GetReturnValue().Set(info.This());
    }
开发者ID:lizbowers,项目名称:node-sqlserver-v8,代码行数:10,代码来源:Connection.cpp

示例5: create

 //! \verbatim
 //! Quaternion()
 //! Quaternion( Radian rotation, Vector3 axis )
 //! Quaternion( Real w, Real x, Real y, Real z )
 //! Quaternion([Real w, Real x, Real y, Real z])
 //! Quaternion({Real w, Real x, Real y, Real z})
 //! \endverbatim
 void Quaternion::create( const FunctionCallbackInfo<v8::Value>& args )
 {
   HandleScope handleScope( args.GetIsolate() );
   if ( !args.IsConstructCall() )
   {
     args.GetIsolate()->ThrowException(
       Util::allocString( "Function called as non-constructor" ) );
     return;
   }
   Ogre::Quaternion qtn( Ogre::Quaternion::IDENTITY );
   if ( args.Length() == 4 )
   {
     qtn.w = args[0]->NumberValue();
     qtn.x = args[1]->NumberValue();
     qtn.y = args[2]->NumberValue();
     qtn.z = args[3]->NumberValue();
   }
   else if ( args.Length() == 2 )
   {
     Vector3* axis = Util::extractVector3( 1, args );
     qtn.FromAngleAxis( Ogre::Radian( args[0]->NumberValue() ), *axis );
   }
   else if ( args.Length() == 1 )
   {
     if ( args[0]->IsArray() )
     {
       v8::Local<v8::Array> arr = v8::Local<v8::Array>::Cast( args[0] );
       if ( arr->Length() == 4 )
       {
         qtn.w = arr->Get( 0 )->NumberValue();
         qtn.x = arr->Get( 1 )->NumberValue();
         qtn.y = arr->Get( 2 )->NumberValue();
         qtn.z = arr->Get( 3 )->NumberValue();
       }
     }
     else if ( args[0]->IsObject() )
     {
       v8::Local<v8::Value> val = args[0]->ToObject()->Get( Util::allocString( "w" ) );
       if ( val->IsNumber() )
         qtn.w = val->NumberValue();
       val = args[0]->ToObject()->Get( Util::allocString( "x" ) );
       if ( val->IsNumber() )
         qtn.x = val->NumberValue();
       val = args[0]->ToObject()->Get( Util::allocString( "y" ) );
       if ( val->IsNumber() )
         qtn.y = val->NumberValue();
       val = args[0]->ToObject()->Get( Util::allocString( "z" ) );
       if ( val->IsNumber() )
         qtn.z = val->NumberValue();
     }
   }
   Quaternion* object = new Quaternion( qtn );
   object->wrap( args.This() );
   args.GetReturnValue().Set( args.This() );
 }
开发者ID:noorus,项目名称:glacier2,代码行数:62,代码来源:JSQuaternion.cpp

示例6: New

	void Buffer::New(const FunctionCallbackInfo<Value>& args) {
		Isolate* isolate = args.GetIsolate();
		HandleScope handle_scope(isolate);

		if (args.IsConstructCall()) {
			Buffer* obj = new Buffer(args);
			args.GetReturnValue().Set(args.This());
		}
		else {
			std::array<Local<Value>, 1> argv{ args[0] };
			Local<Function> cons = Local<Function>::New(isolate, constructor.Get(isolate));
			args.GetReturnValue().Set(cons->NewInstance(SafeInt<int>(argv.size()), argv.data()));
		}
	}
开发者ID:codepilot,项目名称:vulkan,代码行数:14,代码来源:Buffer.cpp

示例7: Server

void Server(const FunctionCallbackInfo<Value> &args) {
    if (args.IsConstructCall()) {
        try {
            args.This()->SetAlignedPointerInInternalField(0, new uWS::Server(args[0]->IntegerValue(), true, args[1]->IntegerValue(), args[2]->IntegerValue()));

            // todo: these needs to be removed on destruction
            args.This()->SetAlignedPointerInInternalField(CONNECTION_CALLBACK, new Persistent<Function>);
            args.This()->SetAlignedPointerInInternalField(DISCONNECTION_CALLBACK, new Persistent<Function>);
            args.This()->SetAlignedPointerInInternalField(MESSAGE_CALLBACK, new Persistent<Function>);
        } catch (...) {
            args.This()->Set(String::NewFromUtf8(args.GetIsolate(), "error"), Boolean::New(args.GetIsolate(), true));
        }
        args.GetReturnValue().Set(args.This());
    }
}
开发者ID:cuongquay,项目名称:uWebSockets,代码行数:15,代码来源:addon.cpp

示例8: New

void DeviceNode::New(const FunctionCallbackInfo<Value>& args) {
  Isolate* isolate = Isolate::GetCurrent();
  HandleScope scope(isolate);

  if (args.IsConstructCall()) {
    // Invoked as constructor: `new DeviceNode()`
    DeviceNode* obj = new DeviceNode();
    obj->Wrap(args.This());
    args.GetReturnValue().Set(args.This());
  } else {
    // Invoked as plain function `DeviceNode(...)`, turn into construct call.
    Local<Function> cons = Local<Function>::New(isolate, constructor);
    args.GetReturnValue().Set(cons->NewInstance());
  }
}
开发者ID:egeback,项目名称:node-tellstick,代码行数:15,代码来源:device-node.cpp

示例9: File

static void
gum_v8_file_on_new_file (const FunctionCallbackInfo<Value> & info)
{
  GumV8File * self = static_cast<GumV8File *> (
      info.Data ().As<External> ()->Value ());
  Isolate * isolate = self->core->isolate;

  if (!info.IsConstructCall ())
  {
    isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (
        isolate, "Use `new File()` to create a new instance")));
    return;
  }

  Local<Value> filename_val = info[0];
  if (!filename_val->IsString ())
  {
    isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, 
        "File: first argument must be a string specifying filename")));
    return;
  }
  String::Utf8Value filename (filename_val);

  Local<Value> mode_val = info[1];
  if (!mode_val->IsString ())
  {
    isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, 
        "File: second argument must be a string specifying mode")));
    return;
  }
  String::Utf8Value mode (mode_val);

  FILE * handle = fopen (*filename, *mode);
  if (handle == NULL)
  {
    gchar * message = g_strdup_printf ("File: failed to open file (%s)",
        strerror (errno));
    isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate,
        message)));
    g_free (message);
    return;
  }

  Local<Object> instance (info.Holder ());
  GumFile * file = gum_file_new (instance, handle, self);
  instance->SetAlignedPointerInInternalField (0, file);
}
开发者ID:0xItx,项目名称:frida-gum,代码行数:47,代码来源:gumv8file.cpp

示例10: New

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));
  }
}
开发者ID:garvankeeley,项目名称:abp-filter-parser-cpp,代码行数:17,代码来源:ABPFilterParserWrap.cpp

示例11: New

void UiWindow::New(const FunctionCallbackInfo<Value>& args) {
    Isolate *isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);

    if (args.IsConstructCall() || args[0]->IsUndefined()) {
        UiWindow* _this = CreateUiWindow();
        Handle<Object> obj = Handle<Object>::Cast(args[0]);
        _this->_config = new WindowConfig(obj);
        _this->Wrap(args.This());

        Local<Value> emit = _this->handle()->Get(String::NewFromUtf8(isolate, "emit"));
        Local<Function> emitFn = Local<Function>::Cast(emit);
        _this->_emitFn.Reset(isolate, emitFn);

        args.GetReturnValue().Set(args.This());
    }
}
开发者ID:NextGenIntelligence,项目名称:io-ui,代码行数:17,代码来源:ui-window.cpp

示例12: New

void MyObject::New(const FunctionCallbackInfo<Value>& args) {
  Isolate* isolate = Isolate::GetCurrent();
  HandleScope scope(isolate);

  if (args.IsConstructCall()) {
    // Invoked as constructor: `new MyObject(...)`
    double value = args[0]->IsUndefined() ? 0 : args[0]->NumberValue();
    MyObject* obj = new MyObject(value);
    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));
  }
}
开发者ID:kordiak,项目名称:raspberry,代码行数:18,代码来源:myobject.cpp

示例13: ConstructorCallbackImpl

void WeakRef::ConstructorCallbackImpl(const FunctionCallbackInfo<Value>& args)
{
	auto isolate = args.GetIsolate();

	if (args.IsConstructCall())
	{
		if (args.Length() == 1)
		{
			auto target = args[0];

			if (target->IsObject())
			{
				auto targetObj = target.As<Object>();

				auto weakRef = m_objectManager->GetEmptyObject(isolate);

				auto poTarget = new Persistent<Object>(isolate, targetObj);
				auto poHolder = new Persistent<Object>(isolate, weakRef);
				auto callbackState = new CallbackState(poTarget, poHolder);

				poTarget->SetWeak(callbackState, WeakTargetCallback);
				poHolder->SetWeak(callbackState, WeakHolderCallback);

				weakRef->Set(ConvertToV8String("get"), GetGetterFunction(isolate));
				weakRef->Set(ConvertToV8String("clear"), GetClearFunction(isolate));
				weakRef->SetHiddenValue(V8StringConstants::GetTarget(), External::New(isolate, poTarget));

				args.GetReturnValue().Set(weakRef);
			}
			else
			{
				throw NativeScriptException(string("The WeakRef constructor expects an object argument."));
			}
		}
		else
		{
			throw NativeScriptException(string("The WeakRef constructor expects single parameter."));
		}
	}
	else
	{
		throw NativeScriptException(string("WeakRef must be used as a construct call."));
	}
}
开发者ID:Emat12,项目名称:android-runtime,代码行数:44,代码来源:WeakRef.cpp

示例14: New

void TempWrapper::New(const FunctionCallbackInfo<Value>& args){
  Isolate* isolate = Isolate::GetCurrent();
  HandleScope scope(isolate);

  uint8_t _addr = 0x00, _port = 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,
  // printf("Args Count: %d\n",args.Length());
  TempWrapper* obj;
  uint8_t _argc = args.Length();
  if(args.IsConstructCall()){
    // Invoked as constructor: `new MyObject(...)`
    switch(_argc){
      case 1: // Only the BCMWrapper is passed
        _port = (uint8_t) args[0]->NumberValue();
        obj = new TempWrapper(_port);
        obj->Wrap(args.This());
        args.GetReturnValue().Set(args.This());
        break;
      case 2:
        _port = (uint8_t) args[0]->NumberValue();
        _addr = (uint8_t) args[1]->NumberValue();
        obj = new TempWrapper(_port,_addr);
        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 > 2){
      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));
  }
}
开发者ID:Robotois,项目名称:eModules,代码行数:44,代码来源:TempWrapper.cpp

示例15: construct

void Bindings::construct(const FunctionCallbackInfo<Value>& args)
{
    Isolate* isolate(args.GetIsolate());
    HandleScope scope(isolate);

    if (args.IsConstructCall())
    {
        // Invoked as constructor with 'new'.
        Bindings* obj = new Bindings();
        obj->Wrap(args.Holder());
        args.GetReturnValue().Set(args.Holder());
    }
    else
    {
        // Invoked as a function, turn into construct call.
        Local<Function> ctor(Local<Function>::New(isolate, constructor));
        args.GetReturnValue().Set(ctor->NewInstance());
    }
}
开发者ID:andreyd75,项目名称:greyhound,代码行数:19,代码来源:bindings.cpp


注:本文中的FunctionCallbackInfo::IsConstructCall方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。