Example #1
0
void EnvWrap::setupExports(Handle<Object> exports) {
    // EnvWrap: Prepare constructor template
    Local<FunctionTemplate> envTpl = FunctionTemplate::New(EnvWrap::ctor);
    envTpl->SetClassName(String::NewSymbol("Env"));
    envTpl->InstanceTemplate()->SetInternalFieldCount(1);
    // EnvWrap: Add functions to the prototype
    envTpl->PrototypeTemplate()->Set(String::NewSymbol("open"), FunctionTemplate::New(EnvWrap::open)->GetFunction());
    envTpl->PrototypeTemplate()->Set(String::NewSymbol("close"), FunctionTemplate::New(EnvWrap::close)->GetFunction());
    envTpl->PrototypeTemplate()->Set(String::NewSymbol("beginTxn"), FunctionTemplate::New(EnvWrap::beginTxn)->GetFunction());
    envTpl->PrototypeTemplate()->Set(String::NewSymbol("openDbi"), FunctionTemplate::New(EnvWrap::openDbi)->GetFunction());
    envTpl->PrototypeTemplate()->Set(String::NewSymbol("sync"), FunctionTemplate::New(EnvWrap::sync)->GetFunction());
    // TODO: wrap mdb_env_copy too
    // TODO: wrap mdb_env_stat too
    // TODO: wrap mdb_env_info too
    // EnvWrap: Get constructor
    Persistent<Function> envCtor = Persistent<Function>::New(envTpl->GetFunction());
    
    // TxnWrap: Prepare constructor template
    Local<FunctionTemplate> txnTpl = FunctionTemplate::New(TxnWrap::ctor);
    txnTpl->SetClassName(String::NewSymbol("Txn"));
    txnTpl->InstanceTemplate()->SetInternalFieldCount(1);
    // TxnWrap: Add functions to the prototype
    txnTpl->PrototypeTemplate()->Set(String::NewSymbol("commit"), FunctionTemplate::New(TxnWrap::commit)->GetFunction());
    txnTpl->PrototypeTemplate()->Set(String::NewSymbol("abort"), FunctionTemplate::New(TxnWrap::abort)->GetFunction());
    txnTpl->PrototypeTemplate()->Set(String::NewSymbol("getString"), FunctionTemplate::New(TxnWrap::getString)->GetFunction());
    txnTpl->PrototypeTemplate()->Set(String::NewSymbol("getBinary"), FunctionTemplate::New(TxnWrap::getBinary)->GetFunction());
    txnTpl->PrototypeTemplate()->Set(String::NewSymbol("getNumber"), FunctionTemplate::New(TxnWrap::getNumber)->GetFunction());
    txnTpl->PrototypeTemplate()->Set(String::NewSymbol("getBoolean"), FunctionTemplate::New(TxnWrap::getBoolean)->GetFunction());
    txnTpl->PrototypeTemplate()->Set(String::NewSymbol("putString"), FunctionTemplate::New(TxnWrap::putString)->GetFunction());
    txnTpl->PrototypeTemplate()->Set(String::NewSymbol("putBinary"), FunctionTemplate::New(TxnWrap::putBinary)->GetFunction());
    txnTpl->PrototypeTemplate()->Set(String::NewSymbol("putNumber"), FunctionTemplate::New(TxnWrap::putNumber)->GetFunction());
    txnTpl->PrototypeTemplate()->Set(String::NewSymbol("putBoolean"), FunctionTemplate::New(TxnWrap::putBoolean)->GetFunction());
    txnTpl->PrototypeTemplate()->Set(String::NewSymbol("del"), FunctionTemplate::New(TxnWrap::del)->GetFunction());
    txnTpl->PrototypeTemplate()->Set(String::NewSymbol("reset"), FunctionTemplate::New(TxnWrap::reset)->GetFunction());
    txnTpl->PrototypeTemplate()->Set(String::NewSymbol("renew"), FunctionTemplate::New(TxnWrap::renew)->GetFunction());
    // TODO: wrap mdb_cmp too
    // TODO: wrap mdb_dcmp too
    // TxnWrap: Get constructor
    EnvWrap::txnCtor = Persistent<Function>::New(txnTpl->GetFunction());
    
    // DbiWrap: Prepare constructor template
    Local<FunctionTemplate> dbiTpl = FunctionTemplate::New(DbiWrap::ctor);
    dbiTpl->SetClassName(String::NewSymbol("Dbi"));
    dbiTpl->InstanceTemplate()->SetInternalFieldCount(1);
    // DbiWrap: Add functions to the prototype
    dbiTpl->PrototypeTemplate()->Set(String::NewSymbol("close"), FunctionTemplate::New(DbiWrap::close)->GetFunction());
    dbiTpl->PrototypeTemplate()->Set(String::NewSymbol("drop"), FunctionTemplate::New(DbiWrap::drop)->GetFunction());
    // TODO: wrap mdb_stat too
    // DbiWrap: Get constructor
    EnvWrap::dbiCtor = Persistent<Function>::New(dbiTpl->GetFunction());
    
    // Set exports
    exports->Set(String::NewSymbol("Env"), envCtor);
}
// Sets up everything for the Logger object when the addon is initialized
void Logger::Initialize(Handle<Object> target) {
    NanScope();

    Local<FunctionTemplate> lcons = NanNew<FunctionTemplate>(Logger::New);
    lcons->InstanceTemplate()->SetInternalFieldCount(1);
    lcons->SetClassName(NanNew("Logger"));

    // Static methods
    NODE_SET_METHOD(lcons->GetFunction(), "getSeverity", Logger::get_severity);
    NODE_SET_METHOD(lcons->GetFunction(), "setSeverity", Logger::set_severity);

    // Constants
    NODE_MAPNIK_DEFINE_CONSTANT(lcons->GetFunction(),"NONE",mapnik::logger::severity_type::none);
    NODE_MAPNIK_DEFINE_CONSTANT(lcons->GetFunction(),"ERROR",mapnik::logger::severity_type::error);
    NODE_MAPNIK_DEFINE_CONSTANT(lcons->GetFunction(),"DEBUG",mapnik::logger::severity_type::debug);
    NODE_MAPNIK_DEFINE_CONSTANT(lcons->GetFunction(),"WARN",mapnik::logger::severity_type::warn);

    // What about booleans like:
    // ENABLE_STATS
    // ENABLE_LOG
    // DEFAULT_LOG_SEVERITY
    // RENDERING_STATS
    // DEBUG

    // Not sure if needed...
    target->Set(NanNew("Logger"),lcons->GetFunction());
    NanAssignPersistent(constructor, lcons);

}
// Called during add-on initialization to add the "Message" template function
// to the target object.
void LS2Message::Initialize (Handle<Object> target)
{
    HandleScope scope;

    Local<FunctionTemplate> t = FunctionTemplate::New(New);

    t->SetClassName(String::New("palmbus/Message"));

    gMessageTemplate = Persistent<FunctionTemplate>::New(t);

    t->InstanceTemplate()->SetInternalFieldCount(1);

    NODE_SET_PROTOTYPE_METHOD(t, "payload", PayloadWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "responseToken", ResponseTokenWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "print", PrintWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "method", MethodWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "applicationID", ApplicationIDWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "sender", SenderWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "senderServiceName", SenderServiceNameWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "uniqueToken", UniqueTokenWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "kind", KindWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "category", CategoryWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "token", TokenWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "isSubscription", IsSubscriptionWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "respond", RespondWrapper);

    target->Set(String::NewSymbol("Message"), t->GetFunction());
}
Example #4
0
void ILob::Init(Handle<Object> target)
{
  NanScope();

  Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New);
  tpl->InstanceTemplate()->SetInternalFieldCount(1);
  tpl->SetClassName(NanNew<v8::String>("ILob"));

  NODE_SET_PROTOTYPE_METHOD(tpl, "release", Release);

  NODE_SET_PROTOTYPE_METHOD(tpl, "read", Read);

  NODE_SET_PROTOTYPE_METHOD(tpl, "write", Write);

  tpl->InstanceTemplate()->SetAccessor(NanNew<v8::String>("chunkSize"),
                                       ILob::GetChunkSize,
                                       ILob::SetChunkSize);

  tpl->InstanceTemplate()->SetAccessor(NanNew<v8::String>("length"),
                                       ILob::GetLength,
                                       ILob::SetLength);

  tpl->InstanceTemplate()->SetAccessor(NanNew<v8::String>("pieceSize"),
                                       ILob::GetPieceSize,
                                       ILob::SetPieceSize);

  tpl->InstanceTemplate()->SetAccessor(NanNew<v8::String>("offset"),
                                       ILob::GetOffset,
                                       ILob::SetOffset);

  NanAssignPersistent(iLobTemplate_s, tpl);
  target->Set(NanNew<v8::String>("ILob"), tpl->GetFunction());
}
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 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();
}
Example #7
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);
}
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;
}
Example #9
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);
}
Example #10
0
void Cache::Init(Local<Object> exports) {
  NanScope();

  Local<FunctionTemplate> cacheConstructorTemplate =
    NanNew<FunctionTemplate>(Cache::New);

  cacheConstructorTemplate->SetClassName(NanNew("Cache"));
  cacheConstructorTemplate->InstanceTemplate()->SetInternalFieldCount(1);

  NanSetPrototypeTemplate(cacheConstructorTemplate, "close",
      NanNew<FunctionTemplate>(Cache::Close)->GetFunction());
  NanSetPrototypeTemplate(cacheConstructorTemplate, "executeFunction",
      NanNew<FunctionTemplate>(Cache::ExecuteFunction)->GetFunction());
  NanSetPrototypeTemplate(cacheConstructorTemplate, "executeQuery",
      NanNew<FunctionTemplate>(Cache::ExecuteQuery)->GetFunction());
  NanSetPrototypeTemplate(cacheConstructorTemplate, "createRegion",
      NanNew<FunctionTemplate>(Cache::CreateRegion)->GetFunction());
  NanSetPrototypeTemplate(cacheConstructorTemplate, "getRegion",
      NanNew<FunctionTemplate>(Cache::GetRegion)->GetFunction());
  NanSetPrototypeTemplate(cacheConstructorTemplate, "rootRegions",
      NanNew<FunctionTemplate>(Cache::RootRegions)->GetFunction());
  NanSetPrototypeTemplate(cacheConstructorTemplate, "inspect",
      NanNew<FunctionTemplate>(Cache::Inspect)->GetFunction());

  exports->Set(NanNew("Cache"), cacheConstructorTemplate->GetFunction());
}
Example #11
0
/*! Initialize our node object */
void Audio::AudioEngine::Init( v8::Handle<v8::Object> target ) {
	// Prepare constructor template
	Local<FunctionTemplate> functionTemplate = NanNew<FunctionTemplate> (Audio::AudioEngine::New );
	functionTemplate->SetClassName( NanNew<String>("AudioEngine") );
	functionTemplate->InstanceTemplate()->SetInternalFieldCount( 1 );


    //Local<FunctionTemplate> constructorHandle = NanNew(constructor);
    //target->Set(NanNew<String>("AudioEngine"), functionTemplate->GetFunction());
	
    // Get
	//functionTemplate->PrototypeTemplate()->Set( NanNew<String>("isActive"), NanNew<FunctionTemplate>(Audio::AudioEngine::isActive)->GetFunction() );
	//functionTemplate->PrototypeTemplate()->Set( NanNew<String>("getDeviceName"), NanNew<FunctionTemplate>(Audio::AudioEngine::getDeviceName)->GetFunction() );
	//functionTemplate->PrototypeTemplate()->Set( NanNew<String>("getNumDevices"), NanNew<FunctionTemplate>(Audio::AudioEngine::getNumDevices)->GetFunction() );
    NODE_SET_PROTOTYPE_METHOD(functionTemplate, "isActive", Audio::AudioEngine::isActive);
    NODE_SET_PROTOTYPE_METHOD(functionTemplate, "getDeviceName", Audio::AudioEngine::getDeviceName);
    NODE_SET_PROTOTYPE_METHOD(functionTemplate, "getNumDevices", Audio::AudioEngine::getNumDevices);

	// Set
	//functionTemplate->PrototypeTemplate()->Set( NanNew<String>("setOptions"), NanNew<FunctionTemplate>(Audio::AudioEngine::setOptions)->GetFunction() );
	//functionTemplate->PrototypeTemplate()->Set( NanNew<String>("getOptions"), NanNew<FunctionTemplate>(Audio::AudioEngine::getOptions)->GetFunction() );
	//functionTemplate->PrototypeTemplate()->Set( NanNew<String>("write"), NanNew<FunctionTemplate>(Audio::AudioEngine::write)->GetFunction() );
	//functionTemplate->PrototypeTemplate()->Set( NanNew<String>("read"), NanNew<FunctionTemplate>(Audio::AudioEngine::read)->GetFunction() );
	//functionTemplate->PrototypeTemplate()->Set( NanNew<String>("isBufferEmpty"), NanNew<FunctionTemplate>(Audio::AudioEngine::isBufferEmpty)->GetFunction() );
    NODE_SET_PROTOTYPE_METHOD(functionTemplate, "setOptions", Audio::AudioEngine::setOptions);
    NODE_SET_PROTOTYPE_METHOD(functionTemplate, "getOptions", Audio::AudioEngine::getOptions);
    NODE_SET_PROTOTYPE_METHOD(functionTemplate, "write", Audio::AudioEngine::write);
    NODE_SET_PROTOTYPE_METHOD(functionTemplate, "read", Audio::AudioEngine::read);
    NODE_SET_PROTOTYPE_METHOD(functionTemplate, "isBufferEmpty", Audio::AudioEngine::isBufferEmpty);

	//constructor = Persistent<Function>::New( functionTemplate->GetFunction() );
    //Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(EOLFinder::New);
    NanAssignPersistent(constructor, functionTemplate->GetFunction());
} // end AudioEngine::Init()
Example #12
0
void Proxy::bindProxy(Local<Object> exports, Local<Context> context)
{
    Isolate* isolate = context->GetIsolate();
    Local<String> javaClass = NEW_SYMBOL(isolate, "__javaClass__");
    javaClassSymbol.Reset(isolate, javaClass);
    constructorSymbol.Reset(isolate, NEW_SYMBOL(isolate, "constructor"));
    inheritSymbol.Reset(isolate, NEW_SYMBOL(isolate, "inherit"));
    propertiesSymbol.Reset(isolate, NEW_SYMBOL(isolate, "_properties"));
    lengthSymbol.Reset(isolate, NEW_SYMBOL(isolate, "length"));
    sourceUrlSymbol.Reset(isolate, NEW_SYMBOL(isolate, "sourceUrl"));

    Local<FunctionTemplate> proxyTemplate = FunctionTemplate::New(isolate);
    Local<String> proxySymbol = NEW_SYMBOL(isolate, "Proxy");
    proxyTemplate->InstanceTemplate()->SetInternalFieldCount(kInternalFieldCount);
    proxyTemplate->SetClassName(proxySymbol);
    proxyTemplate->Inherit(EventEmitter::constructorTemplate.Get(isolate));

    proxyTemplate->Set(javaClass, External::New(isolate, JNIUtil::krollProxyClass),
                       static_cast<PropertyAttribute>(DontDelete | DontEnum));

    SetProtoMethod(isolate, proxyTemplate, "_hasListenersForEventType", hasListenersForEventType);
    SetProtoMethod(isolate, proxyTemplate, "onPropertiesChanged", proxyOnPropertiesChanged);
    SetProtoMethod(isolate, proxyTemplate, "_onEventFired", onEventFired);

    baseProxyTemplate.Reset(isolate, proxyTemplate);

    exports->Set(proxySymbol, proxyTemplate->GetFunction(context).ToLocalChecked());
}
Example #13
0
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);
}
void Transaction::Init() {
	Local<FunctionTemplate> tpl = FunctionTemplate::New(New);

	tpl->SetClassName(String::NewSymbol("Transaction"));
	tpl->InstanceTemplate()->SetInternalFieldCount(1);

	tpl->PrototypeTemplate()->Set(String::NewSymbol("get"), FunctionTemplate::New(Get)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("getRange"), FunctionTemplate::New(GetRange)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("getKey"), FunctionTemplate::New(GetKey)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("watch"), FunctionTemplate::New(Watch)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("set"), FunctionTemplate::New(Set)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("commit"), FunctionTemplate::New(Commit)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("clear"), FunctionTemplate::New(Clear)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("clearRange"), FunctionTemplate::New(ClearRange)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("addReadConflictRange"), FunctionTemplate::New(AddReadConflictRange)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("addWriteConflictRange"), FunctionTemplate::New(AddWriteConflictRange)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("onError"), FunctionTemplate::New(OnError)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("reset"), FunctionTemplate::New(Reset)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("getReadVersion"), FunctionTemplate::New(GetReadVersion)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("setReadVersion"), FunctionTemplate::New(SetReadVersion)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("getCommittedVersion"), FunctionTemplate::New(GetCommittedVersion)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("cancel"), FunctionTemplate::New(Cancel)->GetFunction());
	tpl->PrototypeTemplate()->Set(String::NewSymbol("getAddressesForKey"), FunctionTemplate::New(GetAddressesForKey)->GetFunction());
	
	constructor = Persistent<Function>::New(tpl->GetFunction());
}
Example #15
0
void Proxy::bindProxy(Handle<Object> exports)
{
	javaClassSymbol = SYMBOL_LITERAL("__javaClass__");
	constructorSymbol = SYMBOL_LITERAL("constructor");
	inheritSymbol = SYMBOL_LITERAL("inherit");
	propertiesSymbol = SYMBOL_LITERAL("_properties");
	lengthSymbol = SYMBOL_LITERAL("length");
	sourceUrlSymbol = SYMBOL_LITERAL("sourceUrl");

	Local<FunctionTemplate> proxyTemplate = FunctionTemplate::New();
	Local<String> proxySymbol = String::NewSymbol("Proxy");
	proxyTemplate->InstanceTemplate()->SetInternalFieldCount(kInternalFieldCount);
	proxyTemplate->SetClassName(proxySymbol);
	proxyTemplate->Inherit(EventEmitter::constructorTemplate);

	proxyTemplate->Set(javaClassSymbol, External::Wrap(JNIUtil::krollProxyClass),
		PropertyAttribute(DontDelete | DontEnum));

	DEFINE_PROTOTYPE_METHOD(proxyTemplate, "_hasListenersForEventType", hasListenersForEventType);
	DEFINE_PROTOTYPE_METHOD(proxyTemplate, "onPropertiesChanged", proxyOnPropertiesChanged);

	baseProxyTemplate = Persistent<FunctionTemplate>::New(proxyTemplate);

	exports->Set(proxySymbol, proxyTemplate->GetFunction());
}
Example #16
0
//Init
void DeviceNode::Init(v8::Handle<v8::Object> exports) {
  Isolate* isolate = exports->GetIsolate();

  // Prepare constructor template
  Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
  tpl->SetClassName(String::NewFromUtf8(isolate, "DeviceNode"));
  tpl->InstanceTemplate()->SetInternalFieldCount(1);

  // Prototype
  NODE_SET_PROTOTYPE_METHOD(tpl, "getName", DeviceNode::GetName);
  NODE_SET_PROTOTYPE_METHOD(tpl, "getId", DeviceNode::GetId);
  NODE_SET_PROTOTYPE_METHOD(tpl, "getModel", DeviceNode::GetModel);
  NODE_SET_PROTOTYPE_METHOD(tpl, "getProtocol", DeviceNode::GetProtocol);
  NODE_SET_PROTOTYPE_METHOD(tpl, "getDeviceType", DeviceNode::GetDeviceType);
  NODE_SET_PROTOTYPE_METHOD(tpl, "getLastSentValue", DeviceNode::GetLastSentValue);
  NODE_SET_PROTOTYPE_METHOD(tpl, "getMethods", DeviceNode::GetMethods);
  NODE_SET_PROTOTYPE_METHOD(tpl, "getDimValue", DeviceNode::GetDimValue);
  NODE_SET_PROTOTYPE_METHOD(tpl, "isOn", DeviceNode::IsOn);
  NODE_SET_PROTOTYPE_METHOD(tpl, "isDimmable", DeviceNode::IsDimmable);

  NODE_SET_PROTOTYPE_METHOD(tpl, "turnOff", DeviceNode::TurnOff);
  NODE_SET_PROTOTYPE_METHOD(tpl, "turnOn", DeviceNode::TurnOn);
  NODE_SET_PROTOTYPE_METHOD(tpl, "dim", DeviceNode::Dim);

  constructor.Reset(isolate, tpl->GetFunction());
  exports->Set(String::NewFromUtf8(isolate, "DeviceNode"),
               tpl->GetFunction());
}
Example #17
0
void Speaker::Init(Local<Object> exports) {
  Nan::HandleScope scope;

  // Prepare constructor template
  Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(New);
  ctor->SetClassName(Nan::New("Speaker").ToLocalChecked());
  ctor->InstanceTemplate()->SetInternalFieldCount(1);

  // Prototype
  Nan::SetPrototypeMethod(ctor, "open", Open);
  Nan::SetPrototypeMethod(ctor, "write", Write);
  Nan::SetPrototypeMethod(ctor, "close", Close);
  Nan::SetPrototypeMethod(ctor, "setVolume", SetVolume);

  // Constants
  #define CONST_INT(value) \
    Nan::ForceSet(exports, Nan::New(#value).ToLocalChecked(), Nan::New(value), \
      static_cast<PropertyAttribute>(ReadOnly|DontDelete));

  CONST_INT(AUDIO_FORMAT_PCM_8_BIT);
  CONST_INT(AUDIO_FORMAT_PCM_16_BIT);
  CONST_INT(AUDIO_FORMAT_PCM_FLOAT);
  CONST_INT(AUDIO_FORMAT_PCM_24_BIT_PACKED);

  constructor.Reset(ctor->GetFunction());
  exports->Set(Nan::New("Speaker").ToLocalChecked(), ctor->GetFunction());
}
// Called during add-on initialization to add the "Handle" template function
// to the target object.
void LS2Handle::Initialize(Handle<Object> target)
{
    HandleScope scope;

    Local<FunctionTemplate> t = FunctionTemplate::New(New);
    
    t->SetClassName(String::New("palmbus/Handle"));

    t->Inherit(EventEmitter::constructor_template);
    t->InstanceTemplate()->SetInternalFieldCount(1);

    NODE_SET_PROTOTYPE_METHOD(t, "call", CallWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "watch", WatchWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "subscribe", SubscribeWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "registerMethod", RegisterMethodWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "subscriptionAdd", SubscriptionAddWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "cancel", CancelWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "pushRole", PushRoleWrapper);
    NODE_SET_PROTOTYPE_METHOD(t, "unregister", UnregisterWrapper);

    cancel_symbol = NODE_PSYMBOL("cancel");
    request_symbol = NODE_PSYMBOL("request");

    target->Set(String::NewSymbol("Handle"), t->GetFunction());
}
Example #19
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);
}
Example #20
0
    void Quaternion::initialize( Handle<ObjectTemplate> exports )
    {
      Isolate* isolate = Isolate::GetCurrent();
      HandleScope handleScope( isolate );

      Local<FunctionTemplate> tpl = FunctionTemplate::New( isolate, Quaternion::create );

      tpl->SetClassName( Util::allocString( className.c_str() ) );
      tpl->InstanceTemplate()->SetInternalFieldCount( 1 );

      JS_TEMPLATE_ACCESSOR( tpl, "w", jsGetW, jsSetW );
      JS_TEMPLATE_ACCESSOR( tpl, "x", jsGetX, jsSetX );
      JS_TEMPLATE_ACCESSOR( tpl, "y", jsGetY, jsSetY );
      JS_TEMPLATE_ACCESSOR( tpl, "z", jsGetZ, jsSetZ );

      JS_TEMPLATE_SET( tpl, "toString", jsToString );
      JS_TEMPLATE_SET( tpl, "multiply", jsMultiply );
      JS_TEMPLATE_SET( tpl, "dot", jsDot );
      JS_TEMPLATE_SET( tpl, "norm", jsNorm );
      JS_TEMPLATE_SET( tpl, "normalise", jsNormalise );
      JS_TEMPLATE_SET( tpl, "inverse", jsInverse );
      JS_TEMPLATE_SET( tpl, "unitInverse", jsUnitInverse );
      JS_TEMPLATE_SET( tpl, "getRoll", jsGetRoll );
      JS_TEMPLATE_SET( tpl, "getPitch", jsGetPitch );
      JS_TEMPLATE_SET( tpl, "getYaw", jsGetYaw );

      exports->Set( isolate, className.c_str(), tpl );
      constructor.Set( isolate, tpl );
    }
/**
 * Generator for [UTFGrid](https://www.mapbox.com/guides/an-open-platform)
 * representations of data.
 *
 * @name mapnik.Grid
 * @class
 * @param {number} width
 * @param {number} height
 * @param {Object} [options={}] optional argument, which can have a 'key' property
 * @property {string} key
 */
void Grid::Initialize(Handle<Object> target) {

    NanScope();

    Local<FunctionTemplate> lcons = NanNew<FunctionTemplate>(Grid::New);
    lcons->InstanceTemplate()->SetInternalFieldCount(1);
    lcons->SetClassName(NanNew("Grid"));

    // methods
    NODE_SET_PROTOTYPE_METHOD(lcons, "encodeSync", encodeSync);
    NODE_SET_PROTOTYPE_METHOD(lcons, "encode", encode);
    NODE_SET_PROTOTYPE_METHOD(lcons, "addField", addField);
    NODE_SET_PROTOTYPE_METHOD(lcons, "fields", fields);
    NODE_SET_PROTOTYPE_METHOD(lcons, "view", view);
    NODE_SET_PROTOTYPE_METHOD(lcons, "width", width);
    NODE_SET_PROTOTYPE_METHOD(lcons, "height", height);
    NODE_SET_PROTOTYPE_METHOD(lcons, "painted", painted);
    NODE_SET_PROTOTYPE_METHOD(lcons, "clear", clear);
    NODE_SET_PROTOTYPE_METHOD(lcons, "clearSync", clearSync);
    // properties
    ATTR(lcons, "key", get_key, set_key);

    target->Set(NanNew("Grid"), lcons->GetFunction());
    NODE_MAPNIK_DEFINE_64_BIT_CONSTANT(lcons->GetFunction(), "base_mask", mapnik::grid::base_mask);

    NanAssignPersistent(constructor, lcons);
}
Example #22
0
	void QuickItem::Initialize(Handle<Object> target)
	{
		NanScope();

		Local<String> name = NanNew("QuickItem");

		/* Constructor template */
		Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(QuickItem::New);
		tpl->InstanceTemplate()->SetInternalFieldCount(1);  
		tpl->SetClassName(name);

		/* Prototype */
		NODE_SET_PROTOTYPE_METHOD(tpl, "create", QuickItem::create);
		NODE_SET_PROTOTYPE_METHOD(tpl, "getPropertyNames", QuickItem::getPropertyNames);
		NODE_SET_PROTOTYPE_METHOD(tpl, "getProperty", QuickItem::getProperty);
		NODE_SET_PROTOTYPE_METHOD(tpl, "setProperty", QuickItem::setProperty);
		NODE_SET_PROTOTYPE_METHOD(tpl, "setParent", QuickItem::setParent);
		NODE_SET_PROTOTYPE_METHOD(tpl, "invokeMethod", QuickItem::invokeMethod);
		NODE_SET_PROTOTYPE_METHOD(tpl, "emitEvent", QuickItem::emitEvent);
		NODE_SET_PROTOTYPE_METHOD(tpl, "on", QuickItem::on);

		NanAssignPersistent(constructor, tpl->GetFunction());

		target->Set(name, NanNew(constructor));
	}
Example #23
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 );
}
Example #24
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);
}
void
NodeSandbox::Init(Handle<Object> exports)
{
  Local<FunctionTemplate> tpl = FunctionTemplate::New(node_new);
  tpl->SetClassName(String::NewSymbol("Sandbox"));
  tpl->InstanceTemplate()->SetInternalFieldCount(2);
  node::SetPrototypeMethod(tpl, "spawn", node_spawn);
  node::SetPrototypeMethod(tpl, "kill", node_kill);
  node::SetPrototypeMethod(tpl, "finishIPC", node_finish_ipc);
  node::SetPrototypeMethod(tpl, "finishVFS", node_finish_vfs);
  s_constructor = Persistent<Function>::New(tpl->GetFunction());
  exports->Set(String::NewSymbol("Sandbox"), s_constructor);

  Local<FunctionTemplate> channelTpl = FunctionTemplate::New(node_new);
  channelTpl->SetClassName (String::NewSymbol ("Channel"));
  channelTpl->InstanceTemplate()->SetInternalFieldCount (2);
}
Example #26
0
Local<FunctionTemplate> ScriptObject::createClass(const std::string &name)
{
    HandleScope handleScope;

    Local<FunctionTemplate> functionTemplate = FunctionTemplate::New();
    functionTemplate->SetClassName(String::New(name.c_str()));

    return handleScope.Close(functionTemplate);
}
Example #27
0
	void Buffer::Init(Isolate* isolate) {
		Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
		tpl->SetClassName(String::NewFromUtf8(isolate, "Vulkan::Buffer"));
		tpl->InstanceTemplate()->SetInternalFieldCount(1);

		//NODE_SET_PROTOTYPE_METHOD(tpl, "getMemoryProperties", getMemoryProperties);

		constructor.Set(isolate, 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());
}
 void MessageProducer::Init( v8::Handle<v8::Object> exports ) 
 {
     Local<FunctionTemplate> tpl = FunctionTemplate::New( New ) ;
     tpl->SetClassName( NanNew( "FgiMessageProducer" ) );
     tpl->InstanceTemplate()->SetInternalFieldCount( 1 );
     NODE_SET_PROTOTYPE_METHOD( tpl, "send", Send );
     NanAssignPersistent( constructor, tpl->GetFunction() );
     exports->Set( NanNew( "FgiMessageProducer"), constructor );
 }
Example #30
0
/**
 * The C++ class represents a JS constructor as follows:
 *
 * function OutParam(type, options) {
 *   this._type = type || 0;
 *   this._size = options.size;
 *   this._inOut.hasInParam = options.in;
 * }
 */
void OutParam::Init(Handle<Object> target) {
  NanScope();

  Local<FunctionTemplate> t = NanNew<FunctionTemplate>(New);
  NanAssignPersistent(constructorTemplate, t);
  t->InstanceTemplate()->SetInternalFieldCount(1);
  t->SetClassName(NanNew<String>("OutParam"));
  target->Set(NanNew<String>("OutParam"),
      t->GetFunction());
}