本文整理汇总了C++中Handle::NewInstance方法的典型用法代码示例。如果您正苦于以下问题:C++ Handle::NewInstance方法的具体用法?C++ Handle::NewInstance怎么用?C++ Handle::NewInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Handle
的用法示例。
在下文中一共展示了Handle::NewInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
Handle<Value> MSMap::GetLabelCache(const Arguments &args) {
HandleScope scope;
MSMap *map = ObjectWrap::Unwrap<MSMap>(args.This());
labelCacheObj *labelcache = &(map->this_->labelcache);
Handle<ObjectTemplate> objTempl = ObjectTemplate::New();
#if MS_VERSION_NUM < 60500
labelCacheSlotObj *cacheslot;
int numLabels = 0;
int k = 0;
size_t i = 0;
size_t j = 0;
for(i = 0; i < MS_MAX_LABEL_PRIORITY; ++i) {
cacheslot = &(labelcache->slots[i]);
for(size_t j = 0; j < cacheslot->numlabels; ++j) {
if (cacheslot->labels[j].status == MS_ON) {
numLabels ++;
}
}
}
Local<Array> labels = Array::New(numLabels);
for(i = 0; i < MS_MAX_LABEL_PRIORITY; ++i) {
cacheslot = &(labelcache->slots[i]);
Local<Array> labels = Array::New(cacheslot->numlabels);
for(j = 0; j < cacheslot->numlabels; ++j) {
Local<Object> label = objTempl->NewInstance();
label->Set(String::New("status"), Number::New(MS_ON));
label->Set(String::New("x"), Number::New(cacheslot->labels[j].point.x));
label->Set(String::New("y"), Number::New(cacheslot->labels[j].point.y));
label->Set(String::New("text"), String::New(cacheslot->labels[j].labels[0].annotext));
label->Set(String::New("layerindex"), Number::New(cacheslot->labels[j].layerindex));
label->Set(String::New("classindex"), Number::New(cacheslot->labels[j].classindex));
labels->Set(k++, label);
}
}
#else
Local<Array> labels = Array::New(labelcache->num_rendered_members);
int p = 0;
for (p=0; p<labelcache->num_rendered_members; p++) {
labelCacheMemberObj* curCachePtr = labelcache->rendered_text_symbols[p];
Local<Object> label = objTempl->NewInstance();
label->Set(String::New("status"), Number::New(MS_ON));
label->Set(String::New("x"), Number::New(curCachePtr->point.x));
label->Set(String::New("y"), Number::New(curCachePtr->point.y));
if ((curCachePtr->textsymbols[0]->annotext) == NULL) {
label->Set(String::New("text"), String::New(""));
} else {
label->Set(String::New("text"), String::New(curCachePtr->textsymbols[0]->annotext));
}
label->Set(String::New("layerindex"), Number::New(curCachePtr->layerindex));
label->Set(String::New("classindex"), Number::New(curCachePtr->classindex));
labels->Set(p, label);
}
#endif
// return an array of rendered labels
return scope.Close(labels);
}
示例2: NanEscapeScope
Handle<Value> TypedArray::New(GDALDataType type, unsigned int length) {
NanEscapableScope();
Handle<Value> val;
Handle<Function> constructor;
Local<Object> global = NanGetCurrentContext()->Global();
const char *name;
switch(type) {
case GDT_Byte: name = "Uint8Array"; break;
case GDT_Int16: name = "Int16Array"; break;
case GDT_UInt16: name = "Uint16Array"; break;
case GDT_Int32: name = "Int32Array"; break;
case GDT_UInt32: name = "Uint32Array"; break;
case GDT_Float32: name = "Float32Array"; break;
case GDT_Float64: name = "Float64Array"; break;
default:
NanThrowError("Unsupported array type");
return NanEscapeScope(NanUndefined());
}
// make ArrayBuffer
val = global->Get(NanNew("ArrayBuffer"));
if(val.IsEmpty() || !val->IsFunction()) {
NanThrowError("Error getting ArrayBuffer constructor");
return NanEscapeScope(NanUndefined());
}
constructor = val.As<Function>();
Local<Value> size = NanNew<Integer>(length * GDALGetDataTypeSize(type) / 8);
Local<Value> array_buffer = constructor->NewInstance(1, &size);
if(array_buffer.IsEmpty() || !array_buffer->IsObject()) {
NanThrowError("Error allocating ArrayBuffer");
return NanEscapeScope(NanUndefined());
}
// make TypedArray
val = global->Get(NanNew(name));
if(val.IsEmpty() || !val->IsFunction()) {
NanThrowError("Error getting typed array constructor");
return NanEscapeScope(NanUndefined());
}
constructor = val.As<Function>();
Local<Object> array = constructor->NewInstance(1, &array_buffer);
if(array.IsEmpty() || !array->IsObject()) {
NanThrowError("Error creating TypedArray");
return NanEscapeScope(NanUndefined());
}
return NanEscapeScope(array);
}
示例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: getObjectTemplateFromJsObject
Handle<Value> TiFilesystemObject::_getFile(void* userContext, TiObject* , const Arguments& args)
{
// Get the paths from the arguments
QString path = "";
for(int i = 0, len = args.Length(); i < len; i++) {
String::Utf8Value v8UtfString(Handle<String>::Cast(args[i]));
const char* cStr = *v8UtfString;
path.append(cStr).append("/");
}
// remove the last "/"
path.remove(path.length() - 1, 1);
// in case there is double slashesh, remove them
// Ti.Filesyste.getFile( Ti.Filestem.resourceDirectory, '/app.js')
// or
// Ti.Filesyste.getFile( Ti.Filestem.resourceDirectory, 'app.js')
path.replace("//", "/");
HandleScope handleScope;
// Get the Filesystem object
TiFilesystemObject* obj = (TiFilesystemObject*) userContext;
Handle<ObjectTemplate> global = getObjectTemplateFromJsObject(args.Holder());
Handle<Object> result = global->NewInstance();
// Create a File object
TiFilesystemFileObject* fileObject = new TiFilesystemFileObject(path);
fileObject->setNativeObjectFactory(obj->_objectFactory);
fileObject->setValue(result);
// Return it
setTiObjectToJsObject(result, fileObject);
return handleScope.Close(result);
}
示例5:
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);
}
示例6: handleScope
// Wraps 'this' in a Javascript object.
Handle<Object> JsContext::wrap() {
// Handle scope for temporary handles.
EscapableHandleScope handleScope(fGlobal->getIsolate());
// Fetch the template for creating JavaScript JsContext wrappers.
// It only has to be created once, which we do on demand.
if (gContextTemplate.IsEmpty()) {
Local<ObjectTemplate> localTemplate = ObjectTemplate::New();
// Add a field to store the pointer to a JsContext instance.
localTemplate->SetInternalFieldCount(1);
this->addAttributesAndMethods(localTemplate);
gContextTemplate.Reset(fGlobal->getIsolate(), localTemplate);
}
Handle<ObjectTemplate> templ =
Local<ObjectTemplate>::New(fGlobal->getIsolate(), gContextTemplate);
// Create an empty JsContext wrapper.
Local<Object> result = templ->NewInstance();
// Wrap the raw C++ pointer in an External so it can be referenced
// from within JavaScript.
Handle<External> contextPtr = External::New(fGlobal->getIsolate(), this);
// Store the context pointer in the JavaScript wrapper.
result->SetInternalField(0, contextPtr);
// Return the result through the current handle scope. Since each
// of these handles will go away when the handle scope is deleted
// we need to call Close to let one, the result, escape into the
// outer handle scope.
return handleScope.Escape(result);
}
示例7: PointConstructor
// Defines a Point() JS Object
void PointConstructor( const FunctionCallbackInfo<v8::Value>& args )
{
//Locker lock;
HandleScope scope;
Handle<ObjectTemplate> t = v8::ObjectTemplate::New();
//The JavaScript point object only has 1 C++ object
t->SetInternalFieldCount(1);
// Create x and y members with starting values of 0
//t->Set(String::New("x"), Number::New(0));
t->SetAccessor(String::New("x"),
(AccessorGetterCallback)GetPointX,
(AccessorSetterCallback)SetPointX);
//t->Set(String::New("y"), Number::New(0));
t->SetAccessor(String::New("y"),
(AccessorGetterCallback)GetPointY,
(AccessorSetterCallback)SetPointY);
// Create a mul(number) function that scales the point
t->Set(String::New("mul"), FunctionTemplate::New(MulCallback));
// for use in the if statement
Point *p = NULL;
Local<Object> obj;
// If Point(x, y) ctor was passed in values assign them
if(!args[0].IsEmpty() && args[0]->IsNumber() &&
!args[1].IsEmpty() && args[1]->IsNumber()) {
//t->Set(String::New("x"), args[0]);
//t->Set(String::New("y"), args[1]);
p = new Point(args[0]->Int32Value(), args[1]->Int32Value());
obj = t->NewInstance();
obj->SetInternalField(0, External::New(p));
} else {
/**
* Wrap a point object
*/
p = new Point(0, 0);
obj = t->NewInstance();
obj->SetInternalField(0, External::New(p));
}
// Return this newly created object
args.GetReturnValue().Set(obj);
}
示例8: BinaryTypes
Handle<Object> SorrowContext::SetupInternals(int argc, const char *argv[]) {
HandleScope scope;
Local<FunctionTemplate> internals_template = FunctionTemplate::New();
internals = Persistent<Object>::New(internals_template->GetFunction()->NewInstance());
Local<Object> global = Context::GetCurrent()->Global();
SET_METHOD(global, "quit", Quit)
SET_METHOD(global, "version", Version)
SET_METHOD(internals, "compile", CompileScript)
if (argc) {
Local<Array> lineArgs = Array::New(argc-1);
for (int i = 0; i +1 < argc; i++) {
lineArgs->Set(Integer::New(i), V8_STR(argv[i+1]));
}
internals->Set(V8_STR("args"), lineArgs);
} else {
internals->Set(V8_STR("args"), Array::New());
}
Handle<Object> libsObject = Object::New();
LoadNativeLibraries(libsObject);
internals->Set(V8_STR("stdlib"), libsObject);
Handle<ObjectTemplate> env = ObjectTemplate::New();
env->SetNamedPropertyHandler(EnvGetter);
internals->Set(V8_STR("env"), env->NewInstance());
internals->Set(V8_STR("global"), global);
binarytypes = new BinaryTypes(internals);
iostreams = new IOStreams(internals);
Filesystem::Initialize(internals);
Extensions::Initialize(internals);
TryCatch tryCatch;
Local<Value> func = ExecuteString(V8_STR(sorrow_native), V8_STR("sorrow.js"));
if (tryCatch.HasCaught()) {
ReportException(&tryCatch);
exit(10);
}
ASSERT_PIN(func->IsFunction(), "sorrow.js main function not found");
Local<Function> f = Local<Function>::Cast(func);
Local<Value> args[1] = { Local<Value>::New(internals) };
f->Call(global, 1, args);
if (tryCatch.HasCaught()) {
ReportException(&tryCatch);
exit(11);
}
return internals;
} // SetupInternals
示例9: convertPointToView
Handle<Value> TiUIBase::_convertPointToView(void* userContext, TiObject* caller, const Arguments& args)
{
HandleScope scope;
TiLogger::getInstance().log("Ti.UI.View convertPointToView() Not Supported in BB 10");
Handle<ObjectTemplate> o = ObjectTemplate::New();
o->Set(String::New("x"), Number::New(0));
o->Set(String::New("y"), Number::New(0));
return scope.Close(o->NewInstance());
}
示例10: Undefined
Handle<Value> MSMap::PropertyGetter (Local<String> property, const AccessorInfo& info) {
MSMap *map = ObjectWrap::Unwrap<MSMap>(info.This());
v8::String::AsciiValue n(property);
if (strcmp(*n, "width") == 0) {
RETURN_NUMBER(map->this_->width);
} else if (strcmp(*n, "height") == 0) {
RETURN_NUMBER(map->this_->height);
} else if (strcmp(*n, "status") == 0) {
RETURN_NUMBER(map->this_->status);
} else if (strcmp(*n, "maxsize") == 0) {
RETURN_NUMBER(map->this_->maxsize);
} else if (strcmp(*n, "cellsize") == 0) {
RETURN_NUMBER(map->this_->cellsize);
} else if (strcmp(*n, "units") == 0) {
RETURN_NUMBER(map->this_->units);
} else if (strcmp(*n, "scaledenom") == 0) {
RETURN_NUMBER(map->this_->scaledenom);
} else if (strcmp(*n, "resolution") == 0) {
RETURN_NUMBER(map->this_->resolution);
} else if (strcmp(*n, "defresolution") == 0) {
RETURN_NUMBER(map->this_->defresolution);
} else if (strcmp(*n, "imagetype") == 0) {
RETURN_STRING(map->this_->imagetype);
} else if (strcmp(*n, "mimetype") == 0) {
RETURN_STRING(map->this_->outputformat->mimetype);
} else if (strcmp(*n, "shapepath") == 0) {
RETURN_STRING(map->this_->shapepath);
} else if (strcmp(*n, "mappath") == 0) {
RETURN_STRING(map->this_->mappath);
} else if (strcmp(*n, "name") == 0) {
RETURN_STRING(map->this_->name);
} else if (strcmp(*n, "outputformat") == 0) {
HandleScope scope;
return scope.Close(MSOutputFormat::New(map->this_->outputformat));
} else if (strcmp(*n, "projection") == 0) {
HandleScope scope;
return scope.Close(MSProjection::New(&map->this_->projection));
} else if (strcmp(*n, "layers") == 0) {
HandleScope scope;
return scope.Close(MSLayers::New(map->this_));
} else if (strcmp(*n, "metadata") == 0) {
HandleScope scope;
#if MS_VERSION_NUM < 60400
Handle<ObjectTemplate> objTempl = ObjectTemplate::New();
Local<Object> result = objTempl->NewInstance();
return scope.Close(result);
#else
return scope.Close(MSHashTable::New(&(map->this_->web.metadata)));
#endif
} else if (strcmp(*n, "extent") == 0) {
HandleScope scope;
return scope.Close(MSRect::New(&map->this_->extent));
}
return Undefined();
}
示例11: Initialize
void Widget::Initialize(Handle<Object> target)
{
HandleScope scope;
Local<String> name = String::NewSymbol("Widget");
/* Create a new class */
Handle<ObjectTemplate> ObjectTpl = ObjectTemplate::New();
ObjectTpl->SetInternalFieldCount(1);
Local<Object> ClassObject = ObjectTpl->NewInstance();
target->Set(name, ClassObject);
/* Initializing Widget Class */
Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
tpl->InstanceTemplate()->SetInternalFieldCount(1);
/* Widgets */
Style::Initialize(ClassObject);
Bin::Initialize(ClassObject);
BoxLayout::Initialize(ClassObject);
Stack::Initialize(ClassObject);
Grid::Initialize(ClassObject);
Table::Initialize(ClassObject);
Adjustment::Initialize(ClassObject);
Scrollable::Initialize(ClassObject);
//Stylable::Initialize(ClassObject);
Button::Initialize(ClassObject);
Entry::Initialize(ClassObject);
Frame::Initialize(ClassObject);
Label::Initialize(ClassObject);
Dialog::Initialize(ClassObject);
ProgressBar::Initialize(ClassObject);
Slider::Initialize(ClassObject);
Toggle::Initialize(ClassObject);
Spinner::Initialize(ClassObject);
Image::Initialize(ClassObject);
Viewport::Initialize(ClassObject);
ScrollView::Initialize(ClassObject);
KineticScrollView::Initialize(ClassObject);
/* Constants */
JSDX_TOOLKIT_DEFINE_CONSTANT(ClassObject, "ORIENTATION_HORIZONTAL", JSDX_TOOLKIT_WIDGET_ORIENTATION_HORIZONTAL);
JSDX_TOOLKIT_DEFINE_CONSTANT(ClassObject, "ORIENTATION_VERTICAL", JSDX_TOOLKIT_WIDGET_ORIENTATION_VERTICAL);
JSDX_TOOLKIT_DEFINE_CONSTANT(ClassObject, "SCALE_MODE_NONE", MX_IMAGE_SCALE_NONE);
JSDX_TOOLKIT_DEFINE_CONSTANT(ClassObject, "SCALE_MODE_FIT", MX_IMAGE_SCALE_FIT);
JSDX_TOOLKIT_DEFINE_CONSTANT(ClassObject, "SCALE_MODE_CROP", MX_IMAGE_SCALE_CROP);
JSDX_TOOLKIT_DEFINE_CONSTANT(ClassObject, "KINETIC_SCROLL_VIEW_STATE_IDLE", MX_KINETIC_SCROLL_VIEW_STATE_IDLE);
JSDX_TOOLKIT_DEFINE_CONSTANT(ClassObject, "KINETIC_SCROLL_VIEW_STATE_PANNING", MX_KINETIC_SCROLL_VIEW_STATE_PANNING);
JSDX_TOOLKIT_DEFINE_CONSTANT(ClassObject, "KINETIC_SCROLL_VIEW_STATE_SCROLLING", MX_KINETIC_SCROLL_VIEW_STATE_SCROLLING);
JSDX_TOOLKIT_DEFINE_CONSTANT(ClassObject, "KINETIC_SCROLL_VIEW_STATE_CLAMPING", MX_KINETIC_SCROLL_VIEW_STATE_CLAMPING);
ClassObject->Set(name, tpl->GetFunction());
}
示例12: getObjectTemplateFromJsObject
Handle<Value> TiDatabase::_open(void* userContext, TiObject* /*caller*/, const Arguments& args)
{
HandleScope handleScope;
TiDatabase* obj = (TiDatabase*) userContext;
Handle<ObjectTemplate> global = getObjectTemplateFromJsObject(args.Holder());
Handle<Object> result = global->NewInstance();
TiDBObject* newDB = TiDBObject::createDB(obj->objectFactory_, args);
newDB->setValue(result);
setTiObjectToJsObject(result, newDB);
return handleScope.Close(result);
}
示例13: 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);
}
示例14: getTiObjectFromJsObject
/* Call back for V8 named properties. This is the entry point for accessing
* properties from js. We handle the properties we know and let V8 handle
* all other properties.
*/
Handle<Value> TiObject::_propGetter(Local<String> prop, const AccessorInfo& info)
{
HandleScope handleScope;
Handle<Object> result;
TiObject* obj = getTiObjectFromJsObject(info.Holder());
if (obj == NULL)
{
// Returns "empty". This will cause V8 to go back to default lookup.
return result;
}
Handle<ObjectTemplate> global = getObjectTemplateFromJsObject(info.Holder());
String::Utf8Value propName(prop);
const char* propString = (const char*)(*propName);
TiObject* propObject = obj->onLookupMember(propString);
if (propObject == NULL)
{
// TODO: Fix the following block of commented out code. Currently it breaks
// Titanium runtime.
/*
if(obj->canAddMembers())
{
// If we're allowed to add members, return an "empty" result
// so V8 will handle it. V8 will set the value internally so
// we can ignore non-Titanium objects.
return result;
}
*/
return Handle<Value>();
}
Handle<Value> ret = propObject->getValue();
if (!ret.IsEmpty())
{
return handleScope.Close(ret);
}
if ((propObject->hasMembers()) || (propObject->isFunction()))
{
result = global->NewInstance();
propObject->setValue(result);
setTiObjectToJsObject(result, propObject);
}
else
{
propObject->release();
return handleScope.Close(propObject->getValue());
}
propObject->release();
return handleScope.Close(result);
}
示例15: PrototypeMethodsInit
void Scrollable::PrototypeMethodsInit(Handle<FunctionTemplate> constructor_template)
{
HandleScope scope;
Local<String> name = String::NewSymbol("scroll");
/* Scrollable Object */
Handle<ObjectTemplate> ObjectTpl = ObjectTemplate::New();
ObjectTpl->SetInternalFieldCount(1);
Local<Object> ObjectInstance = ObjectTpl->NewInstance();
/* Methods */
NODE_SET_METHOD(ObjectInstance, "test", Scrollable::Test);
constructor_template->InstanceTemplate()->Set(name, ObjectInstance);
}