Ejemplo n.º 1
0
	Type(Protobuf* _protobuf, google::protobuf::Message *_message, Handle<Object> self, size_t _index) {
		protobuf = _protobuf;
		message = _message;
		descriptor = _message->GetDescriptor();
		index = _index;

		// Generate functions for bulk conversion between a JS object
		// and an array in descriptor order:
		//   from = function(arr) { this.f0 = arr[0]; this.f1 = arr[1]; ... }
		//   to   = function()    { return [ this.f0, this.f1, ... ] }
		// This is faster than repeatedly calling Get/Set on a v8::Object.
		std::ostringstream from, to;
		from << "(function(arr) { if(arr) {";
		to << "(function() { return [ ";
		for (int i = 0; i < descriptor->field_count(); i++) {
			std::string name = descriptor->field(i)->name();
			from << "var x = arr[" << i << "]; if (x !== undefined) this['" << name << "'] = x; ";
			if (i > 0) to << ", ";
			to << "this['" << name << "']";
		}
		from << " }})";
		to << " ]; })";

		// managed type->schema link
		self->SetInternalField(1, protobuf->handle_);
		self->SetInternalField(2, Script::Compile(String::New(from.str().c_str()))->Run());
		self->SetInternalField(3, Script::Compile(String::New(to.str().c_str()))->Run());

		Wrap(self);
	}
Ejemplo n.º 2
0
void Shape::New(const v8::FunctionCallbackInfo<Value>& args)
{
  HandleScope scope;
  Handle<Object> self = args.Holder();
  Shape *shape;

  if (args[0]->IsExternal())
  {
    Local<External> ext = Local<External>::Cast(args[0]);
    void *ptr = ext->Value();
    shape = static_cast<Shape*>(ptr);
    shape->Wrap(args.Holder());
  }
  else
  {
    shapeObj *s = (shapeObj *)msSmallMalloc(sizeof(shapeObj));

    msInitShape(s);
    if(args.Length() >= 1) {
      s->type = args[0]->Int32Value();
    }
    else {
      s->type = MS_SHAPE_NULL;
    }

    shape = new Shape(s);
    shape->Wrap(self);
  }

  /* create the attribute template. should use ObjectWrap in future */
  Handle<ObjectTemplate> attributes_templ = ObjectTemplate::New();
  attributes_templ->SetInternalFieldCount(2);
  attributes_templ->SetNamedPropertyHandler(attributeGetValue,
                                            attributeSetValue);
  Handle<Object> attributes = attributes_templ->NewInstance();
  map<string, int> *attributes_map = new map<string, int>();
  attributes->SetInternalField(0, External::New(attributes_map));
  attributes->SetInternalField(1, External::New(shape->get()->values));  
  attributes->SetHiddenValue(String::New("__parent__"), self);

  if (shape->layer) {
    for (int i=0; i<shape->layer->numitems; ++i) {
      (*attributes_map)[string(shape->layer->items[i])] = i;
    }
  }

  Persistent<Object> pattributes;
  pattributes.Reset(Isolate::GetCurrent(), attributes);
  pattributes.MakeWeak(attributes_map, attributeWeakCallback);
  pattributes.MarkIndependent();

  self->Set(String::New("attributes"), attributes);
}
Ejemplo n.º 3
0
Handle<Object> HoneydNodeJs::WrapPort(Port *port)
{
    HandleScope scope;  

    // Setup the template for the type if it hasn't been already
    if( m_portTemplate.IsEmpty() )
    {
        Handle<FunctionTemplate> nodeTemplate = FunctionTemplate::New();
        nodeTemplate->InstanceTemplate()->SetInternalFieldCount(1);
        m_portTemplate = Persistent<FunctionTemplate>::New(nodeTemplate);

        // Javascript methods
        Local<Template> proto = m_portTemplate->PrototypeTemplate();
        proto->Set("GetPortName",    FunctionTemplate::New(InvokeMethod<std::string, Nova::Port, &Nova::Port::GetPortName>) );
        proto->Set("GetPortNum",     FunctionTemplate::New(InvokeMethod<std::string, Nova::Port, &Nova::Port::GetPortNum>) );
        proto->Set("GetType",        FunctionTemplate::New(InvokeMethod<std::string, Nova::Port, &Nova::Port::GetType>) );
        proto->Set("GetBehavior",    FunctionTemplate::New(InvokeMethod<std::string, Nova::Port, &Nova::Port::GetBehavior>) );
        proto->Set("GetScriptName",  FunctionTemplate::New(InvokeMethod<std::string, Nova::Port, &Nova::Port::GetScriptName>) );
        proto->Set("GetService",  FunctionTemplate::New(InvokeMethod<std::string, Nova::Port, &Nova::Port::GetService>) );
        proto->Set("GetIsInherited",  FunctionTemplate::New(InvokeMethod<bool, Nova::Port, &Nova::Port::GetIsInherited>) );
    }

    // Get the constructor from the template
    Handle<Function> ctor = m_portTemplate->GetFunction();
    // Instantiate the object with the constructor
    Handle<Object> result = ctor->NewInstance();
    // Wrap the native object in an handle and set it in the internal field to get at later.
    Handle<External> portPtr = External::New(port);
    result->SetInternalField(0,portPtr);

    return scope.Close(result);
}
Ejemplo n.º 4
0
Handle<Object> HoneydNodeJs::WrapNode(Node* node)
{
	HandleScope scope;
	// Setup the template for the type if it hasn't been already
	if( m_NodeTemplate.IsEmpty() )
	{
		Handle<FunctionTemplate> nodeTemplate = FunctionTemplate::New();
		nodeTemplate->InstanceTemplate()->SetInternalFieldCount(1);
		m_NodeTemplate = Persistent<FunctionTemplate>::New(nodeTemplate);

		// Javascript methods
		Local<Template> proto = m_NodeTemplate->PrototypeTemplate();
		proto->Set("GetName",       FunctionTemplate::New(InvokeMethod<string, Node, &Nova::Node::GetName>) );
		proto->Set("GetInterface",  FunctionTemplate::New(InvokeMethod<string, Node, &Nova::Node::GetInterface>) );
		proto->Set("GetProfile",    FunctionTemplate::New(InvokeMethod<string, Node, &Nova::Node::GetProfile>) );
		proto->Set("GetIP",         FunctionTemplate::New(InvokeMethod<string, Node, &Nova::Node::GetIP>) );
		proto->Set("GetMAC",        FunctionTemplate::New(InvokeMethod<string, Node, &Nova::Node::GetMAC>) );
		proto->Set("IsEnabled",     FunctionTemplate::New(InvokeMethod<bool, Node, &Nova::Node::IsEnabled>) );
	}

	// Get the constructor from the template
	Handle<Function> ctor = m_NodeTemplate->GetFunction();
	// Instantiate the object with the constructor
	Handle<Object> result = ctor->NewInstance();
	// Wrap the native object in an handle and set it in the internal field to get at later.
	Handle<External> nodePtr = External::New(node);
	result->SetInternalField(0,nodePtr);

	return scope.Close(result);
}
Ejemplo n.º 5
0
Handle<Object> HoneydNodeJs::WrapPortSet(PortSet *portSet)
{
	HandleScope scope;

	// Setup the template for the type if it hasn't been already
	if( portSetTemplate.IsEmpty() )
	{
		Handle<FunctionTemplate> protoTemplate = FunctionTemplate::New();
		protoTemplate->InstanceTemplate()->SetInternalFieldCount(1);
		portSetTemplate = Persistent<FunctionTemplate>::New(protoTemplate);

		// Javascript methods
		Local<Template> proto = portSetTemplate->PrototypeTemplate();
		proto->Set("GetTCPBehavior",	FunctionTemplate::New(InvokeMethod<std::string, Nova::PortSet, &Nova::PortSet::GetTCPBehavior>) );
		proto->Set("GetUDPBehavior",	FunctionTemplate::New(InvokeMethod<std::string, Nova::PortSet, &Nova::PortSet::GetUDPBehavior>) );
		proto->Set("GetICMPBehavior",	FunctionTemplate::New(InvokeMethod<std::string, Nova::PortSet, &Nova::PortSet::GetICMPBehavior>) );

		proto->Set(String::NewSymbol("GetPorts"),FunctionTemplate::New(GetPorts)->GetFunction());
	}

	// Get the constructor from the template
	Handle<Function> ctor = portSetTemplate->GetFunction();
	// Instantiate the object with the constructor
	Handle<Object> result = ctor->NewInstance();
	// Wrap the native object in an handle and set it in the internal field to get at later.
	Handle<External> portSetPtr = External::New(portSet);
	result->SetInternalField(0,portSetPtr);

	return scope.Close(result);
}
Ejemplo n.º 6
0
Handle<Object> HoneydNodeJs::WrapBroadcast(Broadcast* bcast)
{
	HandleScope scope;

	if (broadcastTemplate.IsEmpty() )
	{
		Handle<FunctionTemplate> protoTemplate = FunctionTemplate::New();
		protoTemplate->InstanceTemplate()->SetInternalFieldCount(1);
		broadcastTemplate = Persistent<FunctionTemplate>::New(protoTemplate);
		
		Local<Template> proto = broadcastTemplate->PrototypeTemplate();
		proto->Set("GetScript",  FunctionTemplate::New(InvokeMethod<string, Broadcast, &Nova::Broadcast::GetScript>) );
		proto->Set("GetSrcPort",  FunctionTemplate::New(InvokeMethod<int, Broadcast, &Nova::Broadcast::GetSrcPort>) );
		proto->Set("GetDstPort",  FunctionTemplate::New(InvokeMethod<int, Broadcast, &Nova::Broadcast::GetDstPort>) );
		proto->Set("GetTime",  FunctionTemplate::New(InvokeMethod<int, Broadcast, &Nova::Broadcast::GetTime>) );
	}
	
	
	// Get the constructor from the template
	Handle<Function> ctor = broadcastTemplate->GetFunction();
	// Instantiate the object with the constructor
	Handle<Object> result = ctor->NewInstance();
	// Wrap the native object in an handle and set it in the internal field to get at later.
	Handle<External> broadcastPtr = External::New(bcast);
	result->SetInternalField(0,broadcastPtr);

	return scope.Close(result);
}
Ejemplo n.º 7
0
void V8Templates::fillSkinOption(Handle<Object> v8Obj, SkinOption *obj)
{
	HandleScope scope;
	
	_ASSERT(!v8Obj.IsEmpty());

	v8Obj->SetInternalField(0, External::New(obj));
}
Ejemplo n.º 8
0
void V8Templates::fillBorderState(Handle<Object> v8Obj, BorderState *obj)
{
	HandleScope scope;
	
	_ASSERT(!v8Obj.IsEmpty());

	v8Obj->SetInternalField(0, External::New(obj));
}
Ejemplo n.º 9
0
Archivo: jsh.cpp Proyecto: jhanssen/jsh
static NAN_GETTER(GetTermios)
{
    NanScope();
    JSH* obj = ObjectWrap::Unwrap<JSH>(args.Holder());
    Handle<External> ext = External::New(Isolate::GetCurrent(), obj->term());
    Handle<Object> ret = NanNew<ObjectTemplate>(obj->templ())->NewInstance();
    ret->SetInternalField(0, ext);
    NanReturnValue(ret);
}
Ejemplo n.º 10
0
void V8Templates::fillFieldState(Handle<Object> v8Obj, FieldState *obj)
{
	HandleScope scope;
	
	_ASSERT(!v8Obj.IsEmpty());

	v8Obj->SetInternalField(0, External::New(obj));
	fillBorderState(Handle<Object>::Cast(v8Obj->Get(String::New("bordersRaw"))), obj->getBorders());
}
Ejemplo n.º 11
0
Handle<Value> WrapObject(void* obj) {

  HandleScope scope;

  Persistent<ObjectTemplate> obj_template = Persistent<ObjectTemplate>::New(ObjectTemplate::New());
  obj_template->SetInternalFieldCount(1);

  Handle<Object> self = obj_template->NewInstance();

  self->SetInternalField(0, External::New(obj));

  return scope.Close(self);
}
Ejemplo n.º 12
0
Handle<Object> Log::Wrap()
{
	Isolate *isolate = jsCompiler_.GetIsolate();
	HandleScope scope(isolate);

	if (logTemplate.IsEmpty()) {
		Handle<ObjectTemplate> objTemplate = MakeLogTemplate(isolate);
		logTemplate.Reset(isolate, objTemplate);
	}
	Handle<ObjectTemplate> local = Local<ObjectTemplate>::New(isolate, logTemplate);
	Handle<Object> obj = local->NewInstance();
	Handle<External> log_ptr = External::New(this);
	obj->SetInternalField(0, log_ptr);
	return scope.Close(obj);
}
Ejemplo n.º 13
0
Handle<Object> HoneydNodeJs::WrapProfile(NodeProfile *pfile)
{
    HandleScope scope;  
    // Setup the template for the type if it hasn't been already
    if( m_profileTemplate.IsEmpty() )
    {
        Handle<FunctionTemplate> nodeTemplate = FunctionTemplate::New();
        nodeTemplate->InstanceTemplate()->SetInternalFieldCount(1);
        m_profileTemplate = Persistent<FunctionTemplate>::New(nodeTemplate);

        // Javascript methods
        Local<Template> proto = m_profileTemplate->PrototypeTemplate();
        proto->Set("GetName",           FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetName>));
        proto->Set("GetPortNames",		FunctionTemplate::New(InvokeMethod<std::vector<std::string>, NodeProfile, &Nova::NodeProfile::GetPortNames>));
        proto->Set("GetTcpAction",      FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetTcpAction>));
        proto->Set("GetUdpAction",      FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetUdpAction>));
        proto->Set("GetIcmpAction",     FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetIcmpAction>));
        proto->Set("GetPersonality",    FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetPersonality>));
        proto->Set("GetEthernet",       FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetEthernet>));
        proto->Set("GetUptimeMin",      FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetUptimeMin>));
        proto->Set("GetUptimeMax",      FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetUptimeMax>));
        proto->Set("GetDropRate",       FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetDropRate>));
        proto->Set("GetGenerated",       FunctionTemplate::New(InvokeMethod<bool, NodeProfile, &Nova::NodeProfile::GetGenerated>));
        proto->Set("GetDistribution",       FunctionTemplate::New(InvokeMethod<double, NodeProfile, &Nova::NodeProfile::GetDistribution>));
        proto->Set("GetParentProfile",  FunctionTemplate::New(InvokeMethod<std::string, NodeProfile, &Nova::NodeProfile::GetParentProfile>));
        proto->Set("GetVendors",        FunctionTemplate::New(InvokeMethod<std::vector<std::string>, NodeProfile, &Nova::NodeProfile::GetVendors>));
        proto->Set("GetVendorDistributions",       FunctionTemplate::New(InvokeMethod<std::vector<double>, NodeProfile, &Nova::NodeProfile::GetVendorDistributions>));
        
        
        proto->Set("isTcpActionInherited",  FunctionTemplate::New(InvokeMethod<bool, NodeProfile, &Nova::NodeProfile::isTcpActionInherited>));
        proto->Set("isUdpActionInherited",  FunctionTemplate::New(InvokeMethod<bool, NodeProfile, &Nova::NodeProfile::isUdpActionInherited>));
        proto->Set("isIcmpActionInherited", FunctionTemplate::New(InvokeMethod<bool, NodeProfile, &Nova::NodeProfile::isIcmpActionInherited>));
        proto->Set("isPersonalityInherited",FunctionTemplate::New(InvokeMethod<bool, NodeProfile, &Nova::NodeProfile::isPersonalityInherited>));
        proto->Set("isEthernetInherited",   FunctionTemplate::New(InvokeMethod<bool, NodeProfile, &Nova::NodeProfile::isEthernetInherited>));
        proto->Set("isUptimeInherited",     FunctionTemplate::New(InvokeMethod<bool, NodeProfile, &Nova::NodeProfile::isUptimeInherited>));
        proto->Set("isDropRateInherited",   FunctionTemplate::New(InvokeMethod<bool, NodeProfile, &Nova::NodeProfile::isDropRateInherited>));
    }

    // Get the constructor from the template
    Handle<Function> ctor = m_profileTemplate->GetFunction();
    // Instantiate the object with the constructor
    Handle<Object> result = ctor->NewInstance();
    // Wrap the native object in an handle and set it in the internal field to get at later.
    Handle<External> profilePtr = External::New(pfile);
    result->SetInternalField(0,profilePtr);

    return scope.Close(result);
}
Handle<Value> def_timestep_image_map_constructor(const Arguments &args) {
	int arg_length = args.Length();
	Handle<Object> thiz = Handle<Object>::Cast(args.This());

	timestep_image_map *map = timestep_image_map_init();
	Local<External> m = External::New(map);
	thiz->SetInternalField(0, m);
	
	map->x = args[1]->NumberValue();
	map->y = args[2]->NumberValue();
	map->width = args[3]->NumberValue();
	map->height = args[4]->NumberValue();

	// to support both marcus-spritemaps (TM) as well as 
	// normal old style image maps (those that don't have explicit margins),
	// check the argument length.  If there are only 6 arguments, there are not
	// specified margins.  Set them to 0.
	Handle<Value> url_val;
	if (arg_length == 6) {
		url_val = args[5];
		map->margin_top = 0;
		map->margin_right = 0;
		map->margin_bottom = 0;
		map->margin_left = 0;
	} else {
		url_val = args[9];
		map->margin_top = args[5]->NumberValue();
		map->margin_right = args[6]->NumberValue();
		map->margin_bottom = args[7]->NumberValue();
		map->margin_left = args[8]->NumberValue();
	}
	
	// WARNING: must not forget to free this at some point
	String::Utf8Value str(url_val);
	map->url = strdup(ToCString(str));

	Persistent<Object> ref = Persistent<Object>::New(thiz);
	ref.MakeWeak(map, image_map_finalize);
	
	return thiz;
}
Ejemplo n.º 15
0
Handle<Object> HoneydNodeJs::WrapProfile(Profile *pfile)
{
	HandleScope scope;
	// Setup the template for the type if it hasn't been already
	if( profileTemplate.IsEmpty() )
	{
		Handle<FunctionTemplate> protoTemplate = FunctionTemplate::New();
		protoTemplate->InstanceTemplate()->SetInternalFieldCount(1);
		profileTemplate = Persistent<FunctionTemplate>::New(protoTemplate);

		// Javascript methods
		Local<Template> proto = profileTemplate->PrototypeTemplate();
		proto->Set("GetName",			FunctionTemplate::New(InvokeMethod<std::string, Profile, &Nova::Profile::GetName>));
		proto->Set("GetPersonality",	FunctionTemplate::New(InvokeMethod<std::string, const Profile, &Nova::Profile::GetPersonality>));
		proto->Set("GetUptimeMin",		FunctionTemplate::New(InvokeMethod<uint, const Profile, &Nova::Profile::GetUptimeMin>));
		proto->Set("GetUptimeMax",		FunctionTemplate::New(InvokeMethod<uint, const Profile, &Nova::Profile::GetUptimeMax>));
		proto->Set("GetDropRate",		FunctionTemplate::New(InvokeMethod<std::string, const Profile, &Nova::Profile::GetDropRate>));
		proto->Set("GetCount",			FunctionTemplate::New(InvokeMethod<uint32_t, Profile, &Nova::Profile::GetCount>));
		proto->Set("GetParentProfile",	FunctionTemplate::New(InvokeMethod<std::string, const Profile, &Nova::Profile::GetParentProfile>));
		proto->Set("GetVendors",		FunctionTemplate::New(InvokeMethod<std::vector<std::string>, Profile, &Nova::Profile::GetVendors>));
		proto->Set("GetVendorCounts",	FunctionTemplate::New(InvokeMethod<std::vector<uint>, Profile, &Nova::Profile::GetVendorCounts>));

		proto->Set("IsPersonalityInherited",FunctionTemplate::New(InvokeMethod<bool, const Profile, &Nova::Profile::IsPersonalityInherited>));
		proto->Set("IsUptimeInherited",     FunctionTemplate::New(InvokeMethod<bool, const Profile, &Nova::Profile::IsUptimeInherited>));
		proto->Set("IsDropRateInherited",   FunctionTemplate::New(InvokeMethod<bool, const Profile, &Nova::Profile::IsDropRateInherited>));
	}

	// Get the constructor from the template
	Handle<Function> ctor = profileTemplate->GetFunction();
	// Instantiate the object with the constructor
	Handle<Object> result = ctor->NewInstance();
	// Wrap the native object in an handle and set it in the internal field to get at later.
	Handle<External> profilePtr = External::New(pfile);
	result->SetInternalField(0,profilePtr);

	return scope.Close(result);
}
Ejemplo n.º 16
0
Handle<Object> HoneydNodeJs::WrapScript(Nova::Script *script)
{
	HandleScope scope;

	if (scriptTemplate.IsEmpty()) {
		Handle<FunctionTemplate> protoTemplate = FunctionTemplate::New();
        protoTemplate->InstanceTemplate()->SetInternalFieldCount(1);
        scriptTemplate = Persistent<FunctionTemplate>::New(protoTemplate);

        // Javascript methods
        Local<Template> proto = scriptTemplate->PrototypeTemplate();
        proto->Set("GetName",	FunctionTemplate::New(InvokeMethod<std::string, Nova::Script, &Nova::Script::GetName>) );
        proto->Set("GetService",	FunctionTemplate::New(InvokeMethod<std::string, Nova::Script, &Nova::Script::GetService>) );
        proto->Set("GetOsClass",	FunctionTemplate::New(InvokeMethod<std::string, Nova::Script, &Nova::Script::GetOsClass>) );
        proto->Set("GetPath",	FunctionTemplate::New(InvokeMethod<std::string, Nova::Script, &Nova::Script::GetPath>) );
        
		proto->Set("GetDefaultProtocol",	FunctionTemplate::New(InvokeMethod<std::string, Nova::Script, &Nova::Script::GetDefaultProtocol>) );
        proto->Set("GetDefaultPort",	FunctionTemplate::New(InvokeMethod<std::string, Nova::Script, &Nova::Script::GetDefaultPort>) );

        proto->Set("GetIsConfigurable",	FunctionTemplate::New(InvokeMethod<bool, Nova::Script, &Nova::Script::GetIsConfigurable>) );
        proto->Set("GetOptions",	FunctionTemplate::New(InvokeMethod<std::map<std::string, std::vector<std::string>> , Nova::Script, &Nova::Script::GetOptions>) );
        proto->Set("GetOptionDescriptions",	FunctionTemplate::New(InvokeMethod<std::map<std::string, std::string> , Nova::Script, &Nova::Script::GetOptionDescriptions>) );


    }

    // Get the constructor from the template
    Handle<Function> ctor = scriptTemplate->GetFunction();
    // Instantiate the object with the constructor
    Handle<Object> result = ctor->NewInstance();
    // Wrap the native object in an handle and set it in the internal field to get at later.
    Handle<External> scriptPtr = External::New(script);
    result->SetInternalField(0,scriptPtr);

    return scope.Close(result);
	
}