本文整理汇总了C++中Handle::SetInternalField方法的典型用法代码示例。如果您正苦于以下问题:C++ Handle::SetInternalField方法的具体用法?C++ Handle::SetInternalField怎么用?C++ Handle::SetInternalField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Handle
的用法示例。
在下文中一共展示了Handle::SetInternalField方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
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);
}
示例2: New
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);
}
示例3:
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);
}
示例4:
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);
}
示例5:
void V8Templates::fillSkinOption(Handle<Object> v8Obj, SkinOption *obj)
{
HandleScope scope;
_ASSERT(!v8Obj.IsEmpty());
v8Obj->SetInternalField(0, External::New(obj));
}
示例6: NAN_GETTER
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);
}
示例7: WrapObject
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);
}
示例8: scope
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);
}
示例9: str
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;
}