Пример #1
0
void ElementCriterionJs::Init(Handle<Object> target)
{
  vector<string> opNames =
    Factory::getInstance().getObjectNamesByBase(ElementCriterion::className());

  for (size_t i = 0; i < opNames.size(); i++)
  {
    QByteArray utf8 = QString::fromStdString(opNames[i]).replace("hoot::", "").toUtf8();
    const char* n = utf8.data();

    // Prepare constructor template
    Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
    tpl->SetClassName(String::NewSymbol(opNames[i].data()));
    tpl->InstanceTemplate()->SetInternalFieldCount(2);
    // Prototype
    tpl->PrototypeTemplate()->Set(String::NewSymbol("addCriterion"),
        FunctionTemplate::New(addCriterion)->GetFunction());
    tpl->PrototypeTemplate()->Set(String::NewSymbol("isSatisfied"),
        FunctionTemplate::New(isSatisfied)->GetFunction());
    tpl->PrototypeTemplate()->Set(PopulateConsumersJs::baseClass(),
                                  String::New(ElementCriterion::className().data()));

    Persistent<Function> constructor = Persistent<Function>::New(tpl->GetFunction());
    target->Set(String::NewSymbol(n), constructor);
  }
}
void ALCaptureDevice::Init(Handle<Object> exports) {
	// Prepare constructor template
	Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
	tpl->SetClassName(Nan::New<String>("CaptureDevice").ToLocalChecked());
	tpl->InstanceTemplate()->SetInternalFieldCount(1);

	tpl->PrototypeTemplate()->Set(Nan::New<String>("on").ToLocalChecked(), Nan::New<FunctionTemplate>(On)->GetFunction());
	tpl->PrototypeTemplate()->Set(Nan::New<String>("start").ToLocalChecked(), Nan::New<FunctionTemplate>(Start)->GetFunction());
	tpl->PrototypeTemplate()->Set(Nan::New<String>("stop").ToLocalChecked(), Nan::New<FunctionTemplate>(Stop)->GetFunction());

	exports->Set(Nan::New<String>("CaptureDevice").ToLocalChecked(), tpl->GetFunction());
}
void ResourcesDictionaryDriver::Init()
{
    // prepare the form xobject driver interfrace template
    Local<FunctionTemplate> ft = FunctionTemplate::New(New);
    ft->SetClassName(String::NewSymbol("ResourcesDictionary"));
    ft->InstanceTemplate()->SetInternalFieldCount(1);
    
    ft->PrototypeTemplate()->Set(String::NewSymbol("addFormXObjectMapping"),FunctionTemplate::New(AddFormXObjectMapping)->GetFunction());
    ft->PrototypeTemplate()->Set(String::NewSymbol("addImageXObjectMapping"),FunctionTemplate::New(AddImageXObjectMapping)->GetFunction());
    ft->PrototypeTemplate()->Set(String::NewSymbol("addProcsetResource"),FunctionTemplate::New(AddProcsetResource)->GetFunction());
    constructor = Persistent<Function>::New(ft->GetFunction());
}
Пример #4
0
void nj::ScriptEncapsulated::Init(Handle<Object> exports)
{
   Local<FunctionTemplate> T = FunctionTemplate::New(New);

   T->SetClassName(String::NewSymbol("Script"));
   T->InstanceTemplate()->SetInternalFieldCount(1);
   T->PrototypeTemplate()->Set(String::NewSymbol("getPath"),FunctionTemplate::New(getPath)->GetFunction());
   T->PrototypeTemplate()->Set(String::NewSymbol("getModuleName"),FunctionTemplate::New(getModuleName)->GetFunction());
   T->PrototypeTemplate()->Set(String::NewSymbol("exec"),FunctionTemplate::New(exec)->GetFunction());
   constructor = Persistent<Function>::New(T->GetFunction());
   exports->Set(String::NewSymbol("Script"),constructor);
}
Пример #5
0
void PDFDateDriver::Init(Handle<Object> inExports)
{
    // prepare the page interfrace template
    Local<FunctionTemplate> t = FunctionTemplate::New(New);
    t->SetClassName(String::NewSymbol("PDFDate"));
    t->InstanceTemplate()->SetInternalFieldCount(1);
    t->PrototypeTemplate()->Set(String::NewSymbol("toString"),FunctionTemplate::New(ToString)->GetFunction());
    t->PrototypeTemplate()->Set(String::NewSymbol("setToCurrentTime"),FunctionTemplate::New(SetToCurrentTime)->GetFunction());
    
    constructor = Persistent<Function>::New(t->GetFunction());
    inExports->Set(String::NewSymbol("PDFDate"),constructor);
}
Пример #6
0
// --------------------------------------------------------
void NodeOpenALSource::Init(Handle<Object> exports) {
  // Prepare constructor template
  Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
  tpl->SetClassName(String::NewSymbol("Source"));
  tpl->InstanceTemplate()->SetInternalFieldCount(1);

  tpl->PrototypeTemplate()->Set(String::NewSymbol("Play"), FunctionTemplate::New(Play)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("SetPosition"), FunctionTemplate::New(SetPosition)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("SetLoop"), FunctionTemplate::New(SetLoop)->GetFunction());

  Persistent<Function> constructor = Persistent<Function>::New(tpl->GetFunction());
  exports->Set(String::NewSymbol("Source"), constructor);
}
Пример #7
0
void OsmMapJs::Init(Handle<Object> target) {
  // Prepare constructor template
  Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
  tpl->SetClassName(String::NewSymbol("OsmMap"));
  tpl->InstanceTemplate()->SetInternalFieldCount(1);
  // Prototype
  tpl->PrototypeTemplate()->Set(String::NewSymbol("clone"),
      FunctionTemplate::New(clone)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("getElement"),
      FunctionTemplate::New(getElement)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("getElementCount"),
      FunctionTemplate::New(getElementCount)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("getParents"),
      FunctionTemplate::New(getParents)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("removeElement"),
      FunctionTemplate::New(removeElement)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("visit"),
      FunctionTemplate::New(visit)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("setIdGenerator"),
      FunctionTemplate::New(setIdGenerator)->GetFunction());
  tpl->PrototypeTemplate()->Set(PopulateConsumersJs::baseClass(),
                                String::New(OsmMap::className().data()));

  _constructor = Persistent<Function>::New(tpl->GetFunction());
  target->Set(String::NewSymbol("OsmMap"), _constructor);
}
Пример #8
0
void PageContentContextDriver::Init()
{
    // prepare the context driver interfrace template
    Local<FunctionTemplate> t = FunctionTemplate::New(New);
    constructor_template = Persistent<FunctionTemplate>::New(t);
    constructor_template->SetClassName(String::NewSymbol("PageContentContext"));
    constructor_template->InstanceTemplate()->SetInternalFieldCount(1);

    AbstractContentContextDriver::Init(constructor_template);
    t->PrototypeTemplate()->Set(String::NewSymbol("getCurrentPageContentStream"),FunctionTemplate::New(GetCurrentPageContentStream)->GetFunction());
    t->PrototypeTemplate()->Set(String::NewSymbol("getAssociatedPage"),FunctionTemplate::New(GetAssociatedPage)->GetFunction());
    
    constructor = Persistent<Function>::New(constructor_template->GetFunction());
}
Пример #9
0
// --------------------------------------------------------
void NodeOpenALStream::Init(Handle<Object> exports) {
	// Prepare constructor template
	Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
	tpl->SetClassName(String::NewSymbol("Stream"));
	tpl->InstanceTemplate()->SetInternalFieldCount(1);

	tpl->PrototypeTemplate()->Set(String::NewSymbol("Ready"), FunctionTemplate::New(Ready)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("Buffer"), FunctionTemplate::New(Buffer)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("SetPosition"), FunctionTemplate::New(SetPosition)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("GetPosition"), FunctionTemplate::New(GetPosition)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("SetGain"), FunctionTemplate::New(SetGain)->GetFunction());

	Persistent<Function> constructor = Persistent<Function>::New(tpl->GetFunction());
	exports->Set(String::NewSymbol("Stream"), constructor);
}
Пример #10
0
void NodeMap::init(Local<Object> target) {
    Nan::HandleScope scope;

    Local<FunctionTemplate> constructor = Nan::New<FunctionTemplate>(Constructor);

    // got to do the Symbol.iterator function by hand, no Nan support
    Local<Symbol> symbol_iterator = Symbol::GetIterator(Isolate::GetCurrent());
    Local<FunctionTemplate> entries_templt = Nan::New<FunctionTemplate>(
        Entries
        , Local<Value>()
        , Nan::New<Signature>(constructor));
    constructor->PrototypeTemplate()->Set(symbol_iterator, entries_templt);
    entries_templt->SetClassName(Nan::New("Symbol(Symbol.iterator)").ToLocalChecked());

    constructor->SetClassName(Nan::New("NodeMap").ToLocalChecked());
    constructor->InstanceTemplate()->SetInternalFieldCount(1);

    Nan::SetPrototypeMethod(constructor, "set", Set);
    Nan::SetPrototypeMethod(constructor, "get", Get);
    Nan::SetPrototypeMethod(constructor, "has", Has);
    Nan::SetPrototypeMethod(constructor, "entries", Entries);
    Nan::SetPrototypeMethod(constructor, "keys", Keys);
    Nan::SetPrototypeMethod(constructor, "values", Values);
    Nan::SetPrototypeMethod(constructor, "delete", Delete);
    Nan::SetPrototypeMethod(constructor, "clear", Clear);
    Nan::SetPrototypeMethod(constructor, "forEach", ForEach);
    Nan::SetAccessor(constructor->InstanceTemplate(), Nan::New("size").ToLocalChecked(), Size);

    target->Set(Nan::New("NodeMap").ToLocalChecked(), constructor->GetFunction());

    PairNodeIterator::init(target);
}
Пример #11
0
void HoneydProfileBinding::Init(v8::Handle<Object> target)
{
	// Prepare constructor template
	Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
	tpl->SetClassName(String::NewSymbol("HoneydProfileBinding"));
	tpl->InstanceTemplate()->SetInternalFieldCount(1);
	// Prototype
	Local<Template> proto = tpl->PrototypeTemplate();

	proto->Set("SetPersonality",	FunctionTemplate::New(InvokeMethod<bool, HoneydProfileBinding,  std::string, &HoneydProfileBinding::SetPersonality>));
	proto->Set("SetCount",			FunctionTemplate::New(InvokeMethod<bool, HoneydProfileBinding,  int, 		&HoneydProfileBinding::SetCount>));
	proto->Set("AddPortSet",		FunctionTemplate::New(InvokeMethod<int, HoneydProfileBinding,  &HoneydProfileBinding::AddPortSet>));
	proto->Set("ClearPorts",		FunctionTemplate::New(InvokeMethod<bool, HoneydProfileBinding,  &HoneydProfileBinding::ClearPorts>));
	proto->Set("SetIsPersonalityInherited",	FunctionTemplate::New(InvokeMethod<bool, HoneydProfileBinding,  bool, &HoneydProfileBinding::SetIsPersonalityInherited>));
	proto->Set("SetIsDropRateInherited",	FunctionTemplate::New(InvokeMethod<bool, HoneydProfileBinding,  bool, &HoneydProfileBinding::SetIsDropRateInherited>));
	proto->Set("SetIsUptimeInherited",		FunctionTemplate::New(InvokeMethod<bool, HoneydProfileBinding,  bool, &HoneydProfileBinding::SetIsUptimeInherited>));
	proto->Set("Save",		FunctionTemplate::New(InvokeMethod<bool, HoneydProfileBinding, &HoneydProfileBinding::Save>));

	proto->Set("SetUptimeMin",		FunctionTemplate::New(InvokeWrappedMethod<bool, HoneydProfileBinding, Profile, uint, &Profile::SetUptimeMin>));
	proto->Set("SetUptimeMax",		FunctionTemplate::New(InvokeWrappedMethod<bool, HoneydProfileBinding, Profile,  uint, 		&Profile::SetUptimeMax>));
	proto->Set("SetDropRate",		FunctionTemplate::New(InvokeWrappedMethod<bool, HoneydProfileBinding, Profile,  std::string, &Profile::SetDropRate>));


	//Odd ball out, because it needs 5 parameters. More than InvoleWrappedMethod can handle
	proto->Set(String::NewSymbol("AddPort"),FunctionTemplate::New(AddPort)->GetFunction());
	proto->Set(String::NewSymbol("SetVendors"),FunctionTemplate::New(SetVendors)->GetFunction());
	proto->Set(String::NewSymbol("SetPortSetBehavior"),FunctionTemplate::New(SetPortSetBehavior)->GetFunction());

	Persistent<Function> constructor = Persistent<Function>::New(tpl->GetFunction());
	target->Set(String::NewSymbol("HoneydProfileBinding"), constructor);
}
Пример #12
0
Handle<Object> FixSession::wrapFixSession(FixSession* fixSession) {
	Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>();

	ctor->InstanceTemplate()->SetInternalFieldCount(1);
	ctor->SetClassName(NanNew("FixSession"));

	Local<ObjectTemplate> proto = ctor->PrototypeTemplate();

	NODE_SET_PROTOTYPE_METHOD(ctor, "disconnect", disconnect);
	NODE_SET_PROTOTYPE_METHOD(ctor, "getSessionID", getSessionID);
	NODE_SET_PROTOTYPE_METHOD(ctor, "isEnabled", isEnabled);
	NODE_SET_PROTOTYPE_METHOD(ctor, "isLoggedOn", isLoggedOn);
	NODE_SET_PROTOTYPE_METHOD(ctor, "logon", logon);
	NODE_SET_PROTOTYPE_METHOD(ctor, "logout", logout);
	NODE_SET_PROTOTYPE_METHOD(ctor, "refresh", refresh);
	NODE_SET_PROTOTYPE_METHOD(ctor, "reset", reset);

	proto->SetAccessor(NanNew("senderSeqNum"), getSenderSeqNum, setSenderSeqNum);
	proto->SetAccessor(NanNew("targetSeqNum"), getTargetSeqNum, setTargetSeqNum);

	Handle<Object> obj = ctor->InstanceTemplate()->NewInstance();

	//obj->SetAlignedPointerInInternalField(0, NanNew<External>(fixSession));
	fixSession->Wrap(obj);
	return obj;
}
Пример #13
0
void JsVlcVideo::initJsApi()
{
    JsVlcDeinterlace::initJsApi();

    using namespace v8;

    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope( isolate );

    Local<FunctionTemplate> constructorTemplate = FunctionTemplate::New( isolate, jsCreate );
    constructorTemplate->SetClassName(
        String::NewFromUtf8( isolate, "VlcVideo", v8::String::kInternalizedString ) );

    Local<ObjectTemplate> protoTemplate = constructorTemplate->PrototypeTemplate();
    Local<ObjectTemplate> instanceTemplate = constructorTemplate->InstanceTemplate();
    instanceTemplate->SetInternalFieldCount( 1 );

    SET_RO_PROPERTY( instanceTemplate, "count", &JsVlcVideo::count );

    SET_RO_PROPERTY( instanceTemplate, "deinterlace", &JsVlcVideo::deinterlace );

    SET_RW_PROPERTY( instanceTemplate, "track", &JsVlcVideo::track, &JsVlcVideo::setTrack );

    Local<Function> constructor = constructorTemplate->GetFunction();
    _jsConstructor.Reset( isolate, constructor );
}
void HttpClientInitBinding(Handle<Object> target) {
	NanScope();
	Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(newHttpClient);
	NanAssignPersistent(constructor, ctor);
	ctor->InstanceTemplate()->SetInternalFieldCount(1);
	ctor->SetClassName(NanNew("HttpClient"));
	Local<ObjectTemplate> proto = ctor->PrototypeTemplate();
	
	proto->SetAccessor(NanNew("url"), HttpClientGetUrl, HttpClientSetUrl);
	proto->SetAccessor(NanNew("returnType"), HttpClientGetReturnType, HttpClientSetReturnType);
	proto->SetAccessor(NanNew("method"), HttpClientGetMethod, HttpClientSetMethod);
	proto->SetAccessor(NanNew("requestHeaders"), HttpClientGetRequestHeaders, HttpClientSetRequestHeaders);
	proto->SetAccessor(NanNew("requestData"), HttpClientGetRequestData, HttpClientSetRequestData);
	proto->SetAccessor(NanNew("status"), HttpClientGetStatus, HttpClientSetStatus);
	proto->SetAccessor(NanNew("statusText"), HttpClientGetStatusText, HttpClientSetStatusText);
	proto->SetAccessor(NanNew("responseHeaders"), HttpClientGetResponseHeaders, HttpClientSetResponseHeaders);
	proto->SetAccessor(NanNew("responseText"), HttpClientGetResponseText, HttpClientSetResponseText);

	NAN_SET_PROTOTYPE_METHOD(ctor, "send", HttpClientSend);


	target->Set(NanNew("HttpClient"), ctor->GetFunction());

	HttpClient::init();
}
Пример #15
0
void JNIV8ClassInfo::_registerJavaMethod(JNIV8ObjectJavaCallbackHolder *holder) {
    Isolate* isolate = engine->getIsolate();
    HandleScope scope(isolate);

    Local<FunctionTemplate> ft = Local<FunctionTemplate>::New(isolate, functionTemplate);

    JNIEnv *env = JNIWrapper::getEnvironment();
    holder->javaClass = (jclass)env->NewGlobalRef(env->FindClass(container->canonicalName.c_str()));;
    javaCallbackHolders.push_back(holder);

    Local<External> data = External::New(isolate, (void*)holder);

    if(holder->isStatic) {
        Local<Function> f = ft->GetFunction();
        f->Set(String::NewFromUtf8(isolate, holder->methodName.c_str()), FunctionTemplate::New(isolate, v8JavaMethodCallback, data, Local<Signature>(), 0, ConstructorBehavior::kThrow)->GetFunction());
    } else {
        // ofc functions belong on the prototype, and not on the actual instance for performance/memory reasons
        // but interestingly enough, we MUST store them there because they simply are not "copied" from the InstanceTemplate when using inherit later
        // but other properties and accessors are copied without problems.
        // Thought: it is not allowed to store actual Functions on these templates - only FunctionTemplates
        // functions can only exist in a context once and probaly can not be duplicated/copied in the same way as scalars and accessors, so there IS a difference.
        // maybe when doing inherit the function template is instanced, and then inherit copies over properties to its own instance template which can not be done for instanced functions..
        Local<ObjectTemplate> instanceTpl = ft->PrototypeTemplate();
        instanceTpl->Set(String::NewFromUtf8(isolate, holder->methodName.c_str()),
                         FunctionTemplate::New(isolate, v8JavaMethodCallback, data, Signature::New(isolate, ft), 0, ConstructorBehavior::kThrow));
    }
}
Пример #16
0
    void Data::Init(Handle < Object > exports) {
        NanScope();

        // Prepare constructor template
        Local <FunctionTemplate> tpl = NanNew<FunctionTemplate>(New);

        tpl->SetClassName(NanNew("Data"));
        tpl->InstanceTemplate()->SetInternalFieldCount(1);

        // Methods
        tpl->PrototypeTemplate()->Set(NanNew("getValue"), NanNew < FunctionTemplate > (GetValue)->GetFunction());
        tpl->PrototypeTemplate()->Set(NanNew("getAttribute"), NanNew < FunctionTemplate > (GetAttribute)->GetFunction());

        NanAssignPersistent(constructor, tpl->GetFunction());
        exports->Set(NanNew("Data"), tpl->GetFunction());
    }
Пример #17
0
void ActorWrap::init( ) {
    Local<FunctionTemplate> tpl = FunctionTemplate::New( newObject );
    tpl->SetClassName( String::NewSymbol( CLASS_NAME ) );
    tpl->InstanceTemplate()->SetInternalFieldCount( 1 );

    tpl->PrototypeTemplate( )->Set( String::NewSymbol( "id" ),
        FunctionTemplate::New( id )->GetFunction( ) );
    tpl->PrototypeTemplate( )->Set( String::NewSymbol( "label" ),
        FunctionTemplate::New( label )->GetFunction( ) );
    tpl->PrototypeTemplate( )->Set( String::NewSymbol( "isDone" ),
        FunctionTemplate::New( isDone )->GetFunction( ) );
    tpl->PrototypeTemplate( )->Set( String::NewSymbol( "isReady" ),
        FunctionTemplate::New( isReady )->GetFunction( ) );

    CONSTRUCTOR = Persistent<Function>::New( tpl->GetFunction( ) );
}
void Watch::Init() {
	Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
	tpl->SetClassName(String::NewSymbol("Watch"));
	tpl->InstanceTemplate()->SetInternalFieldCount(1);

	tpl->PrototypeTemplate()->Set(String::NewSymbol("cancel"), FunctionTemplate::New(Cancel)->GetFunction());

	constructor = Persistent<Function>::New(tpl->GetFunction());
}
Пример #19
0
Handle<Value> mongoInject(const Arguments& args){
    jsassert( args.Length() == 1 , "mongoInject takes exactly 1 argument" );
    jsassert( args[0]->IsObject() , "mongoInject needs to be passed a prototype" );

    Local<v8::Object> o = args[0]->ToObject();
    
    o->Set( String::New( "init" ) , FunctionTemplate::New( mongoInit )->GetFunction() );
    o->Set( String::New( "find" ) , FunctionTemplate::New( mongoFind )->GetFunction() );
    o->Set( String::New( "insert" ) , FunctionTemplate::New( mongoInsert )->GetFunction() );
    o->Set( String::New( "remove" ) , FunctionTemplate::New( mongoRemove )->GetFunction() );
    o->Set( String::New( "update" ) , FunctionTemplate::New( mongoUpdate )->GetFunction() );
    
    Local<FunctionTemplate> t = FunctionTemplate::New( internalCursorCons );
    t->PrototypeTemplate()->Set( String::New("next") , FunctionTemplate::New( internalCursorNext ) );
    t->PrototypeTemplate()->Set( String::New("hasNext") , FunctionTemplate::New( internalCursorHasNext ) );
    o->Set( String::New( "internalCursor" ) , t->GetFunction() );
    
    return v8::Undefined();
}
Пример #20
0
void LoggerBinding::Init(Handle<Object> target) {
	Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
	tpl->SetClassName(String::NewSymbol("LoggerBinding"));
	tpl->InstanceTemplate()->SetInternalFieldCount(1);
    
	
	tpl->PrototypeTemplate()->Set(String::NewSymbol("Log"),FunctionTemplate::New(Log)->GetFunction());

	Persistent<Function> constructor = Persistent<Function>::New(tpl->GetFunction());
	target->Set(String::NewSymbol("LoggerBinding"), constructor);
}
Пример #21
0
  void FingerprintWrap::Initialize(Handle<Object> target) {
    Local<FunctionTemplate> tpl = FunctionTemplate::New(NewInstance);
    tpl->SetClassName(String::NewSymbol("fingerprint"));
    tpl->InstanceTemplate()->SetInternalFieldCount(1);

    tpl->PrototypeTemplate()->Set(String::NewSymbol("to_string"),
      FunctionTemplate::New(to_string)->GetFunction());

    target->Set(String::NewSymbol("fingerprint"),
      Persistent<Function>::New(tpl->GetFunction()));
  };
Пример #22
0
void Protobuf::Init(Handle<Object> exports) {
	// Prepare constructor template
	Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
	tpl->SetClassName(String::NewSymbol("Protobuf"));
	tpl->InstanceTemplate()->SetInternalFieldCount(2);

	// Prototype
	tpl->PrototypeTemplate()->Set(String::NewSymbol("Serialize"), FunctionTemplate::New(Serialize)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("Parse"), FunctionTemplate::New(Parse)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("MessageHandle"), FunctionTemplate::New(MessageHandle)->GetFunction());

	Persistent<Function> constructor = Persistent<Function>::New(tpl->GetFunction());
	exports->Set(String::NewSymbol("Protobuf"), constructor);

	KeySymbol = NODE_PSYMBOL("Key");
	ValueSymbol = NODE_PSYMBOL("Value");

	TypeTemplate = Persistent<FunctionTemplate>::New(FunctionTemplate::New());
    TypeTemplate->InstanceTemplate()->SetInternalFieldCount(4);
}
Пример #23
0
/*! Initialize our node object */
void MyExtension::MyExtension::Init( v8::Handle<v8::Object> target ) {
	// Prepare constructor template
	Local<FunctionTemplate> functionTemplate = FunctionTemplate::New( MyExtension::New );
	functionTemplate->SetClassName( String::NewSymbol("MyExtension") );
	functionTemplate->InstanceTemplate()->SetInternalFieldCount( 1 );

	// Setup functions here
	functionTemplate->PrototypeTemplate()->Set( String::NewSymbol("getHelloWorldString"), FunctionTemplate::New(MyExtension::getHelloWorldString)->GetFunction() );

	constructor = Persistent<Function>::New( functionTemplate->GetFunction() );
} // end MyExtension::Init()
Пример #24
0
void Fluorine::Init() {
    // Prepare constructor template
    Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
    tpl->SetClassName(String::NewSymbol("Fluorine"));
    tpl->InstanceTemplate()->SetInternalFieldCount(1);
    // Prototype
    tpl->PrototypeTemplate()->Set(String::NewSymbol("plusOne"),
                                  FunctionTemplate::New(PlusOne)->GetFunction());

    constructor = Persistent<Function>::New(tpl->GetFunction());
}
Пример #25
0
void TagsJs::Init(Handle<Object> target)
{
  // Prepare constructor template
  Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
  tpl->SetClassName(String::NewSymbol(Tags::className().data()));
  tpl->InstanceTemplate()->SetInternalFieldCount(1);
  // Prototype
  tpl->PrototypeTemplate()->Set(PopulateConsumersJs::baseClass(),
    String::New(Tags::className().data()));
  tpl->PrototypeTemplate()->Set(String::NewSymbol("contains"),
      FunctionTemplate::New(contains)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("get"),
      FunctionTemplate::New(get)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("toDict"),
      FunctionTemplate::New(toDict)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("toString"),
      FunctionTemplate::New(toString)->GetFunction());

  _constructor = Persistent<Function>::New(tpl->GetFunction());
  target->Set(String::NewSymbol("Tags"), _constructor);
}
Пример #26
0
void IESoRWrap::Init(Handle<Object> exports) {
   HandleScope scope;
  // Prepare constructor template
  Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
  tpl->SetClassName(String::NewSymbol("iesorWorld"));
  tpl->InstanceTemplate()->SetInternalFieldCount(1);
  
  // Prototype
  //load body into our iesor world (convert from network to body and insert into box2d world)
  tpl->PrototypeTemplate()->Set(String::NewSymbol("loadBodyFromNetwork"),
      FunctionTemplate::New(LoadBodyFromNetwork)->GetFunction());

  tpl->PrototypeTemplate()->Set(String::NewSymbol("convertNetworkToBody"),
      FunctionTemplate::New(ConvertNetworkToBody)->GetFunction());
  
  //simulate a time period inside the world (returns information about simulation)
  tpl->PrototypeTemplate()->Set(String::NewSymbol("simulateWorldMS"),
      FunctionTemplate::New(SimulateWorldMS)->GetFunction());

  tpl->PrototypeTemplate()->Set(String::NewSymbol("getWorldDrawList"),
      FunctionTemplate::New(GetWorldDrawList)->GetFunction());

  //for reseting worlds
  tpl->PrototypeTemplate()->Set(String::NewSymbol("clearWorld"),
      FunctionTemplate::New(ClearWorld)->GetFunction());

  //grab the current center of mass of a loaded object -- for fitness eval!
  tpl->PrototypeTemplate()->Set(String::NewSymbol("bodyCenterOfMass"),
      FunctionTemplate::New(BodyCenterOfMass)->GetFunction());


  constructor = Persistent<Function>::New(tpl->GetFunction());
  exports->Set(String::NewSymbol("iesorWorld"), constructor);
}
Пример #27
0
Local<FunctionTemplate> MetadataNode::GetConstructorFunctionTemplate(Isolate *isolate, MetadataTreeNode *treeNode, vector<MethodCallbackData*>& instanceMethodsCallbackData)
{
	SET_PROFILER_FRAME();

	Local<FunctionTemplate> ctorFuncTemplate;
	auto itFound = s_ctorFuncCache.find(treeNode);
	if (itFound != s_ctorFuncCache.end())
	{
		auto& ctorCacheItem = itFound->second;
		instanceMethodsCallbackData = ctorCacheItem.instanceMethodCallbacks;
		ctorFuncTemplate = Local<FunctionTemplate>::New(isolate, *ctorCacheItem.ft);
		return ctorFuncTemplate;
	}

	auto node = GetOrCreateInternal(treeNode);
	auto ctorCallbackData = External::New(isolate, node);
	auto isInterface = s_metadataReader.IsNodeTypeInterface(treeNode->type);
	auto funcCallback = isInterface ? InterfaceConstructorCallback : ClassConstructorCallback;
	ctorFuncTemplate = FunctionTemplate::New(isolate, funcCallback, ctorCallbackData);
	ctorFuncTemplate->InstanceTemplate()->SetInternalFieldCount(static_cast<int>(ObjectManager::MetadataNodeKeys::END));

	auto baseClass = s_metadataReader.GetBaseClassNode(treeNode);
	Local<Function> baseCtorFunc;
	vector<MethodCallbackData*> baseInstanceMethodsCallbackData;
	if ((baseClass != treeNode) && (baseClass != nullptr) && (baseClass->offsetValue > 0))
	{
		auto baseFuncTemplate = GetConstructorFunctionTemplate(isolate, baseClass, baseInstanceMethodsCallbackData);
		if (!baseFuncTemplate.IsEmpty())
		{
			ctorFuncTemplate->Inherit(baseFuncTemplate);
			baseCtorFunc = baseFuncTemplate->GetFunction();
		}
	}

	auto prototypeTemplate = ctorFuncTemplate->PrototypeTemplate();

	auto ctorFunc = node->SetMembers(isolate, ctorFuncTemplate, prototypeTemplate, instanceMethodsCallbackData, baseInstanceMethodsCallbackData, treeNode);
	if (!baseCtorFunc.IsEmpty())
	{
		ctorFunc->SetPrototype(baseCtorFunc);
	}

	auto pft = new Persistent<FunctionTemplate>(isolate, ctorFuncTemplate);
	CtorCacheItem ctorCacheItem(pft, instanceMethodsCallbackData);
	s_ctorFuncCache.insert(make_pair(treeNode, ctorCacheItem));

	SetInnnerTypes(isolate, ctorFunc, treeNode);

	SetTypeMetadata(isolate, ctorFunc, new TypeMetadata(s_metadataReader.ReadTypeName(treeNode)));

	return ctorFuncTemplate;
}
Пример #28
0
void PairNodeIterator::init() {
    Local<FunctionTemplate> tmplt = NanNew<FunctionTemplate>();
    tmplt->SetClassName(NanNew<String>("NodeIterator"));
    tmplt->InstanceTemplate()->SetInternalFieldCount(1);
    Local<ObjectTemplate> key_value_prototype = tmplt->PrototypeTemplate();
    NanAssignPersistent(key_value_tmplt, tmplt);

    tmplt = NanNew<FunctionTemplate>();
    tmplt->SetClassName(NanNew<String>("NodeIterator"));
    tmplt->InstanceTemplate()->SetInternalFieldCount(1);
    Local<ObjectTemplate> key_prototype = tmplt->PrototypeTemplate();
    NanAssignPersistent(key_tmplt, tmplt);

    tmplt = NanNew<FunctionTemplate>();
    tmplt->SetClassName(NanNew<String>("NodeIterator"));
    tmplt->InstanceTemplate()->SetInternalFieldCount(1);
    Local<ObjectTemplate> value_prototype = tmplt->PrototypeTemplate();
    NanAssignPersistent(value_tmplt, tmplt);

    PROTO(key_value_prototype, next, Next);
    PROTO(key_prototype, next, Next);
    PROTO(value_prototype, next, Next);
}
Пример #29
0
void ElementJs::_addBaseFunctions(Local<FunctionTemplate> tpl)
{
  tpl->PrototypeTemplate()->Set(PopulateConsumersJs::baseClass(),
      String::New(Element::className().data()));
  tpl->PrototypeTemplate()->Set(String::NewSymbol("getCircularError"),
      FunctionTemplate::New(getCircularError)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("getElementId"),
      FunctionTemplate::New(getElementId)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("getId"),
      FunctionTemplate::New(getId)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("getStatusString"),
      FunctionTemplate::New(getStatusString)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("getTags"),
      FunctionTemplate::New(getTags)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("setStatusString"),
      FunctionTemplate::New(setStatusString)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("setTags"),
      FunctionTemplate::New(setTags)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("toJSON"),
      FunctionTemplate::New(toString)->GetFunction());
  tpl->PrototypeTemplate()->Set(String::NewSymbol("toString"),
      FunctionTemplate::New(toString)->GetFunction());
}
Пример #30
0
void SerialportPoller::Init(Handle<Object> target) {
  NanScope();

  // Prepare constructor template
  Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New);
  tpl->SetClassName(NanNew<String>("SerialportPoller"));
  tpl->InstanceTemplate()->SetInternalFieldCount(1);


  // Prototype

  // SerialportPoller.close()
  tpl->PrototypeTemplate()->Set(NanNew<String>("close"),
      NanNew<FunctionTemplate>(Close)->GetFunction());

  // SerialportPoller.start()
  tpl->PrototypeTemplate()->Set(NanNew<String>("start"),
      NanNew<FunctionTemplate>(Start)->GetFunction());

  NanAssignPersistent<FunctionTemplate>(serialportpoller_constructor, tpl);

  target->Set(NanNew<String>("SerialportPoller"), tpl->GetFunction());
}