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); }
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); }
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); }
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); }
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); }
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); }
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); }
// 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); }
// 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); }
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
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()); }
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(); }
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()); }
static Local<Value> ConstructError(const char *name, Handle<String> message) { // XXX: this probably isn't correct in all cases Handle<Context> ctx = Context::GetCurrent(); Handle<Object> global = ctx->Global(); Handle<Value> ctor = global->Get(String::New(name)); if (ctor.IsEmpty() || !ctor->IsFunction()) return Local<Value>(); Handle<Function> fn = ctor.As<Function>(); Handle<Value> args[] = { Handle<Value>(message) }; return Local<Value>::New(fn->NewInstance(1, args)); }
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); }
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); }
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); }
/* 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); }
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); }
Handle<Value> TiNetwork::_createHTTPClient(void* userContext, TiObject* /*caller*/, const Arguments& args) { HandleScope handleScope; TiNetwork* obj = (TiNetwork*) userContext; Handle<ObjectTemplate> global = getObjectTemplateFromJsObject(args.Holder()); Handle<Object> result = global->NewInstance(); TiHTTPClientObject* newHTTP = TiHTTPClientObject::createHTTPClient(obj->objectFactory_); newHTTP->setValue(result); if ((args.Length() > 0) && (args[0]->IsObject())) { Local<Object> settingsObj = Local<Object>::Cast(args[0]); newHTTP->setParametersFromObject(newHTTP, settingsObj); } setTiObjectToJsObject(result, newHTTP); return handleScope.Close(result); }
Handle<Value> TiTitaniumObject::_createBuffer(void* userContext, TiObject*, const Arguments& args) { HandleScope handleScope; TiTitaniumObject* obj = (TiTitaniumObject*) userContext; Handle<ObjectTemplate> global = getObjectTemplateFromJsObject(args.Holder()); Handle<Object> result = global->NewInstance(); TiBufferObject* newBuffer = TiBufferObject::createBuffer(obj->objectFactory_); newBuffer->setValue(result); if ((args.Length() > 0) && (args[0]->IsObject())) { Local<Object> settingsObj = Local<Object>::Cast(args[0]); newBuffer->setParametersFromObject(newBuffer, settingsObj); } setTiObjectToJsObject(result, newBuffer); return handleScope.Close(result); }
Handle<Value> TiUIObject::_createControlHelper(void* userContext, CREATEOBJECTCALLBACK createCallback, const Arguments& args) { HandleScope handleScope; TiUIObject* obj = (TiUIObject*) userContext; Handle<ObjectTemplate> global = getObjectTemplateFromJsObject(args.Holder()); Handle<Object> result; result = global->NewInstance(); TiProxy* newControl = (createCallback)(obj->objectFactory_); newControl->setValue(result); if ((args.Length() > 0) && (args[0]->IsObject())) { Local<Object> settingsObj = Local<Object>::Cast(args[0]); newControl->setParametersFromObject(newControl, settingsObj); } setTiObjectToJsObject(result, newControl); return handleScope.Close(result); }
Handle<Value> TiMedia::_createControlHelper(void* userContext, CREATEOBJECTCALLBACK createCallback, const Arguments& args) { HandleScope handleScope; TiMedia* obj = (TiMedia*) userContext; Handle<ObjectTemplate> global = getObjectTemplateFromJsObject(args.Holder()); Handle<Object> result; result = global->NewInstance(); TiProxy* newControl = (createCallback)(obj->objectFactory_); newControl->setAttachedObject(obj); newControl->setValue(result); newControl->makeWeak(); if (args.Length() > 0) { newControl->applyProperties(args[0]); } setTiObjectToJsObject(result, newControl); return handleScope.Close(result); }
//Used to make a new vector object Handle<Object> vectorTemplate::makeVectorObject(vector<double>* instVect){ HandleScope scope; //This is the prototype for the object Handle<Object> objProto = vectorObjTemp->NewInstance(); //This is the vector data that will be associated with this object Handle<External> data = External::New(reinterpret_cast<void *>(instVect)); Handle<ObjectTemplate> vectOjbTempInst = ObjectTemplate::New(); //Set up the setters vectOjbTempInst->SetAccessor(String::New("x"), getVectorX, setVectorX, data); vectOjbTempInst->SetAccessor(String::New("y"), getVectorY, setVectorY, data); Handle<Object> obj = vectOjbTempInst->NewInstance(); obj->SetPrototype(objProto); return scope.Close(obj); }
Handle<Object> SUIPictureBox::GetV8Obj() { Isolate* isolate = SPV8ScriptEngine::GetSingleton()->GetIsolate(); if (!v8Obj) { Local<Object> obj = Handle<Object>(); Handle<ObjectTemplate> handleTempl = SV8ScriptManager::GetSingleton()->GetPictureBoxTemplate(); obj = handleTempl->NewInstance(); if(!obj.IsEmpty()) { obj->SetInternalField(0, External::New(this)); v8Obj = new Persistent<Object>(isolate, obj); } } return Handle<Object>::New(isolate, *v8Obj); }
Handle<Value> TiProxy::createProxy(TiProxy *proxy, void* userContext, const Arguments& args) { TiProxy *module = static_cast<TiProxy*>(userContext); HandleScope handleScope; Handle<ObjectTemplate> global = getObjectTemplateFromJsObject(args.Holder()); Handle<Object> result = global->NewInstance(); proxy->setNativeObjectFactory(module->getNativeObjectFactory()); proxy->initializeTiObject(NULL); proxy->setValue(result); proxy->setAttachedObject(module); if ((args.Length() > 0) && (args[0]->IsObject())) { Local<Object> settingsObj = Local<Object>::Cast(args[0]); proxy->setParametersFromObject(proxy, settingsObj); } setTiObjectToJsObject(result, proxy); return handleScope.Close(result); }
JSBool FunctionTemplate::CallCallback(JSContext* cx, uintN argc, jsval* vp) { ApiExceptionBoundary boundary; HandleScope scope; Object fn(JSVAL_TO_OBJECT(JS_CALLEE(cx, vp))); PrivateData* pd = PrivateData::Get(cx, **fn.GetInternalField(0).As<Object>()); Handle<ObjectTemplate> instanceTemplate = pd->instanceTemplate.get(); InvocationCallback callback = pd->callback; Local<Value> data = pd->callbackData.get(); JSObject* thiz = NULL; bool isConstructing = JS_IsConstructing(cx, vp); if (isConstructing) { thiz = **instanceTemplate->NewInstance(); Handle<Value> proto = fn.Get(String::NewSymbol("prototype")); if (!proto.IsEmpty() && proto->IsObject()) { Handle<Object> o = proto->ToObject(); (void) JS_SetPrototype(cx, thiz, **o); } } else { thiz = JS_THIS_OBJECT(cx, vp); } Arguments args(cx, thiz, argc, vp, data); Handle<Value> ret; if (callback) { ret = callback(args); } if (ret.IsEmpty()) { ret = v8::Undefined(); } if (isConstructing) { JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(thiz)); } else { JS_SET_RVAL(cx, vp, ret->native()); } return boundary.noExceptionOccured(); }
Image *Image::CreateFromFile(const char *file) { ce::Image *baseImage = ce::Image::CreateFromFile(file); if(!baseImage) return 0; Image *image = new Image(); image->m_image = baseImage; Handle<ObjectTemplate> objectTemplate = ObjectTemplate::New(); objectTemplate->SetInternalFieldCount(1); HandleScope handleScope; Persistent<Object> instance = Persistent<Object>::New(objectTemplate->NewInstance()); instance->SetInternalField(0, External::New(image)); image->m_instance = instance; return image; }
Handle<Value> ContactsPersonProxy::_getImage(void* userContext) { ContactsPersonProxy *obj = (ContactsPersonProxy*) userContext; ContactPhoto photo = obj->getFullContact().primaryPhoto(); if(photo.isValid()) { TiBlobObject *blob = TiBlobObject::createBlob(obj->getNativeObjectFactory()); Handle<ObjectTemplate> templ = TiObject::getObjectTemplateFromJsObject(obj->getValue()); Local<Object> proxy = templ->NewInstance(); blob->setValue(proxy); TiObject::setTiObjectToJsObject(proxy, blob); QFile filePath(photo.largePhoto()); blob->setData(filePath.readAll(), ""); blob->release(); HandleScope scope; return scope.Close(proxy); } return False(); }
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); }