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


C++ Local::NewInstance方法代码示例

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


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

示例1: ThrowTypeError

	static
	NAN_METHOD(New) {
		SHA3Hash *obj;
		int32_t hashlen;

		hashlen = info[0]->IsUndefined() ? 512 : info[0]->Int32Value();
		switch (hashlen) {
			case 224:
			case 256:
			case 384:
			case 512:
				break;
			default:
				return Nan::ThrowTypeError("Unsupported hash length");
		}

		if (info.IsConstructCall()) {
			// Invoked as constructor.
			obj = new SHA3Hash();
			obj->Wrap(info.This());
			obj->bitlen = hashlen;
			::FIPS202_SHA3_Init(&obj->state, hashlen);
			info.GetReturnValue().Set(info.This());
		} else {
			// Invoked as a plain function.
			const int argc = 1;
			Local<Value> argv[argc] = { Nan::New<Number>(hashlen) };
			Local<Function> cons = Nan::New<Function>(constructor);
			info.GetReturnValue().Set(cons->NewInstance(argc, argv));
		}
	}
开发者ID:steakknife,项目名称:node-sha3,代码行数:31,代码来源:addon.cpp

示例2: handle_scope

/**
 * Utility function that wraps a C++ http request object in a
 * JavaScript object.
 */
Local<Object> JsHttpRequestProcessor::WrapRequest(HttpRequest* request) {
  // Local scope for temporary handles.
  EscapableHandleScope handle_scope(GetIsolate());

  // Fetch the template for creating JavaScript http request wrappers.
  // It only has to be created once, which we do on demand.
  if (request_template_.IsEmpty()) {
    Local<ObjectTemplate> raw_template = MakeRequestTemplate(GetIsolate());
    request_template_.Reset(GetIsolate(), raw_template);
  }
  Local<ObjectTemplate> templ =
      Local<ObjectTemplate>::New(GetIsolate(), request_template_);

  // Create an empty http request wrapper.
  Local<Object> result =
      templ->NewInstance(GetIsolate()->GetCurrentContext()).ToLocalChecked();

  // Wrap the raw C++ pointer in an External so it can be referenced
  // from within JavaScript.
  Local<External> request_ptr = External::New(GetIsolate(), request);

  // Store the request pointer in the JavaScript wrapper.
  result->SetInternalField(0, request_ptr);

  // Return the result through the current handle scope.  Since each
  // of these handles will go away when the handle scope is deleted
  // we need to call Close to let one, the result, escape into the
  // outer handle scope.
  return handle_scope.Escape(result);
}
开发者ID:ACEZLY,项目名称:server,代码行数:34,代码来源:V8_Process.cpp

示例3: 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

示例4: exception

// Used by LSHandle to create a "Message" object that wraps a particular
// LSMessage structure.
Local<Value> LS2Message::NewFromMessage(LSMessage* message)
{
    TryCatch try_catch;

    Local<Function> function = gMessageTemplate->GetFunction();
    Local<Object> messageObject = function->NewInstance();

    // If we get an exception in LS2Message::New, then it will return
    // v8::ThrowException which adds a pending exception.
    // Function::NewInstance checks to see if the callee set an exception.
    // If it did, it returns an empty handle 
    if (!messageObject.IsEmpty()) {
        LS2Message *m = node::ObjectWrap::Unwrap<LS2Message>(messageObject);
        if (!m) {
            return Local<Value>::New(v8::ThrowException(v8::String::New("Unable to unwrap native object.")));
        }
        m->SetMessage(message);
    } else {
        // We got an exception; If we try to continue we're going to lose
        // a message, so just crash
        v8::String::Utf8Value exception(try_catch.Exception());
        syslog(LOG_USER | LOG_CRIT, "%s: exception: %s; aborting", __PRETTY_FUNCTION__, 
                                    *exception ? *exception : "no exception string");
        abort();
    }
    return messageObject;
}
开发者ID:liuzhiping,项目名称:nodejs-module-webos-sysbus,代码行数:29,代码来源:node_ls2_message.cpp

示例5: memcpy

Handle<Value> node_packet_client_encode(const Arguments& args)
{
    V8_CHECK_ARGUMENT_COUNT(2)
    V8_CHECK_ARGUMENT(0, Object)
    V8_CHECK_ARGUMENT(1, Number)

    Local<Object> buffer = args[0]->ToObject();
    int32_t serial = args[1]->Int32Value();
    unsigned char* buffer_ptr = (unsigned char*) node::Buffer::Data(buffer);
    int length = (int) node::Buffer::Length(buffer);

    packet pkt = packet_encode_client(buffer_ptr, serial);
    if (pkt.empty())
    {
        return scope.Close(Null());
    }

    int s = (int) pkt.size();
    Local<Object> globalObj = Context::GetCurrent()->Global();
    Local<Function> bufferConstructor = Local<Function>::Cast(globalObj->Get(String::New("Buffer")));
    Handle<Value> constructorArgs[1] = { v8::Integer::New(s)};
    Local<Object> actualBuffer = bufferConstructor->NewInstance(1, constructorArgs);
    memcpy(Buffer::Data(actualBuffer), pkt.data(), s);
    return scope.Close(actualBuffer);
}
开发者ID:WoLfulus,项目名称:node-mupacket,代码行数:25,代码来源:binding.cpp

示例6: 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

示例7:

Local<Object> ItemObject::createInstance()
{
	HandleScope handleScope;
	
	// Create the function template
	
	Local<FunctionTemplate> functionTemplate = FunctionTemplate::New();
	functionTemplate->SetClassName(String::New("Item"));
	
	// Create the object template
	
	Local<ObjectTemplate> objectTemplate = functionTemplate->InstanceTemplate();
	objectTemplate->SetInternalFieldCount(1);
	
	// Create an object instance
	
	Local<Object> objectInstance = objectTemplate->NewInstance();
	objectInstance->SetInternalField(0, External::New(this));
	
	// Add functions to object instance
	
	/*
	Local<FunctionTemplate> printTemplate = FunctionTemplate::New(print);
	Local<Function> printFunction = printTemplate->GetFunction();
	objectInstance->Set(String::New("print"), printFunction);
	
	Local<FunctionTemplate> inputTemplate = FunctionTemplate::New(input);
	Local<Function> inputFunction = inputTemplate->GetFunction();
	objectInstance->Set(String::New("input"), inputFunction);
	*/
	
	return handleScope.Close(objectInstance);
}
开发者ID:bagobor,项目名称:BitRPG,代码行数:33,代码来源:ItemObject.cpp

示例8: handle_scope

// コンストラクタ呼び出し共通処理
tjs_error
TJSInstance::createMethod(Isolate *isolate, Local<Object> &obj, const tjs_char *membername, iTJSDispatch2 **result, tjs_int numparams, tTJSVariant **param)
{
	if (membername) {
		return TJS_E_MEMBERNOTFOUND;
	}

	HandleScope handle_scope(isolate);
	Context::Scope context_scope(getContext());
	TryCatch try_catch;

	if (!obj->IsFunction()) {
		return TJS_E_NOTIMPL;
	}
	
	// 関数抽出
	Local<Function> func = Local<Function>::Cast(obj->ToObject());
	// 引数
	Handle<Value> *argv = new Handle<Value>[numparams];
	for (int i=0;i<numparams;i++) {
		argv[i] = toJSValue(isolate, *param[i]);
	}
	Local<Object> ret = func->NewInstance(numparams, argv);
	delete argv;
	
	if (ret.IsEmpty()) {
		JSEXCEPTION(isolate, &try_catch);
	} else {
		if (result) {
			*result = toVariant(isolate, ret);
		}
	}
	return TJS_S_OK;
}
开发者ID:xmoeproject,项目名称:X-moe,代码行数:35,代码来源:tjsinstance.cpp

示例9: 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

示例10: handle_scope

Local<Object> wrap_master_player(Isolate* isolate, Master_Player *player) {
	EscapableHandleScope handle_scope(isolate);

	Local<ObjectTemplate> localTemplate = ObjectTemplate::New(isolate);
	localTemplate->SetInternalFieldCount(1);
	Local<External> player_ptr = External::New(isolate, player);
	//将指针存在V8对象内部
	Local<Object> player_obj = localTemplate->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
	player_obj->SetInternalField(0, player_ptr);

	// 为当前对象设置其对外函数接口
	player_obj->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "get_save_data_buffer", NewStringType::kNormal).ToLocalChecked(),
		                    FunctionTemplate::New(isolate, get_master_player_save_data_buffer)->GetFunction()) ;

	player_obj->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "respond_success_result", NewStringType::kNormal).ToLocalChecked(),
	                    FunctionTemplate::New(isolate, master_player_respond_success_result)->GetFunction()) ;

	player_obj->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "respond_error_result", NewStringType::kNormal).ToLocalChecked(),
	                    FunctionTemplate::New(isolate, master_player_respond_error_result)->GetFunction()) ;

	player_obj->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "sync_data_to_game", NewStringType::kNormal).ToLocalChecked(),
			                    FunctionTemplate::New(isolate, sync_data_to_game)->GetFunction()) ;

	return handle_scope.Escape(player_obj);
}
开发者ID:firehot,项目名称:server,代码行数:25,代码来源:Player_Wrap.cpp

示例11: jsCreateMyClass

void jsCreateMyClass(const FunctionCallbackInfo<Value>& args)
{
	if (args.Length() != 1)
	{
		args.GetIsolate()->ThrowException(
			String::NewFromUtf8(args.GetIsolate(), "Bad parameters",
			NewStringType::kNormal).ToLocalChecked());
		return;
	}

	Isolate* isolate = args.GetIsolate();

	Local<ObjectTemplate> myClassTemplate =
		Local<ObjectTemplate>::New(isolate, gMyClassTemplate);

	Local<Object> myClassObj = myClassTemplate->NewInstance(
		isolate->GetCurrentContext()).ToLocalChecked();

	int numValue =
		args[0]->Int32Value(isolate->GetCurrentContext()).FromMaybe(0);

	gMyClass = new ObjectWrap(numValue);
	gMyClass->Wrap(myClassObj);

	args.GetReturnValue().Set(myClassObj);
}
开发者ID:ACEZLY,项目名称:server,代码行数:26,代码来源:MyClass_Wrap.cpp

示例12: handle_scope

v8::Local<v8::Object> Msg_Struct::build_msg_object(Isolate* isolate, int cid, int player_cid, int msg_id, int status, Block_Buffer &buffer) {
    EscapableHandleScope handle_scope(isolate);

    Local<ObjectTemplate> localTemplate = ObjectTemplate::New(isolate);
    Local<Object> buf_obj = localTemplate->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
    buf_obj->Set(isolate->GetCurrentContext(),
                 String::NewFromUtf8(isolate, "cid", NewStringType::kNormal).ToLocalChecked(),
                 Int32::New(isolate, cid)).FromJust();
    buf_obj->Set(isolate->GetCurrentContext(),
                 String::NewFromUtf8(isolate, "player_cid", NewStringType::kNormal).ToLocalChecked(),
                 Int32::New(isolate, player_cid)).FromJust();
    buf_obj->Set(isolate->GetCurrentContext(),
                 String::NewFromUtf8(isolate, "msg_id", NewStringType::kNormal).ToLocalChecked(),
                 Int32::New(isolate, msg_id)).FromJust();
    buf_obj->Set(isolate->GetCurrentContext(),
                 String::NewFromUtf8(isolate, "status", NewStringType::kNormal).ToLocalChecked(),
                 Int32::New(isolate, status)).FromJust();
    if (msg_id == SYNC_DB_GAME_LOAD_PLAYER || msg_id == SYNC_DB_GAME_CREATE_PLAYER) {
        std::string account = "";
        buffer.read_string(account);
        buf_obj->Set(isolate->GetCurrentContext(),
                     String::NewFromUtf8(isolate, "account", NewStringType::kNormal).ToLocalChecked(),
                     String::NewFromUtf8(isolate, account.c_str(), NewStringType::kNormal).ToLocalChecked()).FromJust();
    }

    //消息返回成功加载数据
    if (status == 0) {
        for(std::vector<Field_Info>::const_iterator iter = field_vec().begin();
                iter != field_vec().end(); iter++) {
            if(iter->field_label == "arg") {
                Local<Value> value = build_object_arg(*iter, buffer, isolate);
                buf_obj->Set(isolate->GetCurrentContext(),
                             String::NewFromUtf8(isolate, iter->field_name.c_str(), NewStringType::kNormal).ToLocalChecked(),
                             value).FromJust();
            }
            else if(iter->field_label == "vector") {
                Local<Array> array = build_object_vector(*iter, buffer, isolate);
                buf_obj->Set(isolate->GetCurrentContext(),
                             String::NewFromUtf8(isolate, iter->field_name.c_str(), NewStringType::kNormal).ToLocalChecked(),
                             array).FromJust();
            }
            else if(iter->field_label == "map") {
                Local<Map> map = build_object_map(*iter, buffer, isolate);
                buf_obj->Set(isolate->GetCurrentContext(),
                             String::NewFromUtf8(isolate, iter->field_name.c_str(), NewStringType::kNormal).ToLocalChecked(),
                             map).FromJust();
            }
            else if(iter->field_label == "struct") {
                Local<Object> object = build_object_struct(*iter, buffer, isolate);
                buf_obj->Set(isolate->GetCurrentContext(),
                             String::NewFromUtf8(isolate, iter->field_name.c_str(), NewStringType::kNormal).ToLocalChecked(),
                             object).FromJust();
            }
        }
    }
    return handle_scope.Escape(buf_obj);
}
开发者ID:jice1001,项目名称:server,代码行数:57,代码来源:Msg_Struct.cpp

示例13: NewInstance

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

		std::array<Local<Value>, 1> argv{ args[0] };
		Local<Function> cons = Local<Function>::New(isolate, constructor.Get(isolate));
		Local<Object> instance = cons->NewInstance(SafeInt<int>(argv.size()), argv.data());

		args.GetReturnValue().Set(instance);
	}
开发者ID:codepilot,项目名称:vulkan,代码行数:10,代码来源:Buffer.cpp

示例14: NewInstance

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

  const unsigned argc = 1;
  Handle<Value> argv[argc] = { args[0] };
  Local<Function> cons = Local<Function>::New(isolate, constructor);
  Local<Object> instance = cons->NewInstance(argc, argv);

  args.GetReturnValue().Set(instance);
}
开发者ID:egeback,项目名称:node-tellstick,代码行数:11,代码来源:device-node.cpp

示例15: scope

Handle<Value> PrecisionModel::New(const geos::geom::PrecisionModel *m) {
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);

    PrecisionModel *model = new PrecisionModel(m);
    Handle<Value> ext = External::New(isolate, model);
    Local<Function> cons = Local<Function>::New(isolate, constructor);
    Handle<Object> obj = cons->NewInstance(1, &ext);
    model->Wrap(obj);
    return obj;
}
开发者ID:kashif,项目名称:node-geos,代码行数:11,代码来源:precisionmodel.cpp


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