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()); }
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()); }
// 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()); }
Local<FunctionTemplate> MetadataNode::GetConstructorFunctionTemplate(Isolate *isolate, MetadataTreeNode *treeNode, vector<MethodCallbackData*>& instanceMethodsCallbackData) { SET_PROFILER_FRAME(); Local<FunctionTemplate> ctorFuncTemplate; auto itFound = s_ctorFuncCache.find(treeNode); if (itFound != s_ctorFuncCache.end()) { auto& ctorCacheItem = itFound->second; instanceMethodsCallbackData = ctorCacheItem.instanceMethodCallbacks; ctorFuncTemplate = Local<FunctionTemplate>::New(isolate, *ctorCacheItem.ft); return ctorFuncTemplate; } auto node = GetOrCreateInternal(treeNode); auto ctorCallbackData = External::New(isolate, node); auto isInterface = s_metadataReader.IsNodeTypeInterface(treeNode->type); auto funcCallback = isInterface ? InterfaceConstructorCallback : ClassConstructorCallback; ctorFuncTemplate = FunctionTemplate::New(isolate, funcCallback, ctorCallbackData); ctorFuncTemplate->InstanceTemplate()->SetInternalFieldCount(static_cast<int>(ObjectManager::MetadataNodeKeys::END)); auto baseClass = s_metadataReader.GetBaseClassNode(treeNode); Local<Function> baseCtorFunc; vector<MethodCallbackData*> baseInstanceMethodsCallbackData; if ((baseClass != treeNode) && (baseClass != nullptr) && (baseClass->offsetValue > 0)) { auto baseFuncTemplate = GetConstructorFunctionTemplate(isolate, baseClass, baseInstanceMethodsCallbackData); if (!baseFuncTemplate.IsEmpty()) { ctorFuncTemplate->Inherit(baseFuncTemplate); baseCtorFunc = baseFuncTemplate->GetFunction(); } } auto prototypeTemplate = ctorFuncTemplate->PrototypeTemplate(); auto ctorFunc = node->SetMembers(isolate, ctorFuncTemplate, prototypeTemplate, instanceMethodsCallbackData, baseInstanceMethodsCallbackData, treeNode); if (!baseCtorFunc.IsEmpty()) { ctorFunc->SetPrototype(baseCtorFunc); } auto pft = new Persistent<FunctionTemplate>(isolate, ctorFuncTemplate); CtorCacheItem ctorCacheItem(pft, instanceMethodsCallbackData); s_ctorFuncCache.insert(make_pair(treeNode, ctorCacheItem)); SetInnnerTypes(isolate, ctorFunc, treeNode); SetTypeMetadata(isolate, ctorFunc, new TypeMetadata(s_metadataReader.ReadTypeName(treeNode))); return ctorFuncTemplate; }
void MultiPoint::Initialize(Local<Object> target) { Nan::HandleScope scope; Local<FunctionTemplate> lcons = Nan::New<FunctionTemplate>(MultiPoint::New); lcons->Inherit(Nan::New(GeometryCollection::constructor)); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("MultiPoint").ToLocalChecked()); Nan::SetPrototypeMethod(lcons, "toString", toString); target->Set(Nan::New("MultiPoint").ToLocalChecked(), lcons->GetFunction()); constructor.Reset(lcons); }
void DILexicalBlock::Init(Handle<Object> target) { Nan::HandleScope scope; Local<v8::FunctionTemplate> ctor = Nan::New<v8::FunctionTemplate>(New); constructor.Reset(ctor); ctor->Inherit (Nan::New<v8::FunctionTemplate>(DIScope::constructor)); ctor->InstanceTemplate()->SetInternalFieldCount(1); ctor->SetClassName(Nan::New("DILexicalBlock").ToLocalChecked()); Local<v8::Function> ctor_func = ctor->GetFunction(); constructor_func.Reset(ctor_func); target->Set(Nan::New("DILexicalBlock").ToLocalChecked(), ctor_func); }
void MultiLineString::Initialize(Handle<Object> target) { NanScope(); Local<FunctionTemplate> lcons = NanNew<FunctionTemplate>(MultiLineString::New); lcons->Inherit(NanNew(GeometryCollection::constructor)); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(NanNew("MultiLineString")); NODE_SET_PROTOTYPE_METHOD(lcons, "toString", toString); NODE_SET_PROTOTYPE_METHOD(lcons, "polygonize", polygonize); target->Set(NanNew("MultiLineString"), lcons->GetFunction()); NanAssignPersistent(constructor, lcons); }
void JsSprite::Init(Isolate * isolate, Handle<ObjectTemplate> exports) { // Prepare constructor template Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New); tpl->SetClassName(v8::String::NewFromUtf8(isolate, "Sprite")); tpl->InstanceTemplate()->SetInternalFieldCount(2); tpl->Inherit(v8_transformable::GetFunctionTemplate(isolate)); // Prototype Local<ObjectTemplate> proto = tpl->PrototypeTemplate(); // proto->SetInternalFieldCount(1); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "texture"), JS_GetTexture, JS_SetTexture); constructor.Reset(isolate, tpl); exports->Set(v8::String::NewFromUtf8(isolate, "Sprite"), PersistentToLocal(isolate, constructor)); }
Handle<FunctionTemplate> Proxy::inheritProxyTemplate( Handle<FunctionTemplate> superTemplate, jclass javaClass, Handle<String> className, Handle<Function> callback) { HandleScope scope; Local<Value> wrappedClass = External::Wrap(javaClass); Local<FunctionTemplate> inheritedTemplate = FunctionTemplate::New(proxyConstructor, callback); inheritedTemplate->Set(javaClassSymbol, wrappedClass, PropertyAttribute(DontDelete | DontEnum)); inheritedTemplate->InstanceTemplate()->SetInternalFieldCount(kInternalFieldCount); inheritedTemplate->SetClassName(className); inheritedTemplate->Inherit(superTemplate); return scope.Close(inheritedTemplate); }
Local<FunctionTemplate> Proxy::inheritProxyTemplate(Isolate* isolate, Local<FunctionTemplate> superTemplate, jclass javaClass, Local<String> className, Local<Function> callback) { EscapableHandleScope scope(isolate); Local<Value> wrappedClass = External::New(isolate, javaClass); Local<FunctionTemplate> inheritedTemplate = FunctionTemplate::New(isolate, proxyConstructor, callback); inheritedTemplate->Set(javaClassSymbol.Get(isolate), wrappedClass, static_cast<PropertyAttribute>(DontDelete | DontEnum)); inheritedTemplate->InstanceTemplate()->SetInternalFieldCount(kInternalFieldCount); inheritedTemplate->SetClassName(className); inheritedTemplate->Inherit(superTemplate); return scope.Escape(inheritedTemplate); }
void Polygon::Initialize(Handle<Object> target) { NanScope(); Local<FunctionTemplate> lcons = NanNew<FunctionTemplate>(Polygon::New); lcons->Inherit(NanNew(Geometry::constructor)); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(NanNew("Polygon")); NODE_SET_PROTOTYPE_METHOD(lcons, "toString", toString); NODE_SET_PROTOTYPE_METHOD(lcons, "getArea", getArea); ATTR(lcons, "rings", ringsGetter, READ_ONLY_SETTER); target->Set(NanNew("Polygon"), lcons->GetFunction()); NanAssignPersistent(constructor, lcons); }
void Instruction::Init(Handle<Object> target) { Nan::HandleScope scope; Local<v8::FunctionTemplate> ctor = Nan::New<v8::FunctionTemplate>(New); constructor.Reset(ctor); ctor->Inherit (Nan::New<v8::FunctionTemplate>(Value::constructor)); ctor->InstanceTemplate()->SetInternalFieldCount(1); ctor->SetClassName(Nan::New("Instruction").ToLocalChecked()); #if false Nan::SetPrototypeMethod (ctor, "setDebugLoc", Instruction::SetDebugLoc); #endif Local<v8::Function> ctor_func = ctor->GetFunction(); constructor_func.Reset(ctor_func); target->Set(Nan::New("Instruction").ToLocalChecked(), ctor_func); }
void LineString::Initialize(Local<Object> target) { Nan::HandleScope scope; Local<FunctionTemplate> lcons = Nan::New<FunctionTemplate>(LineString::New); lcons->Inherit(Nan::New(Geometry::constructor)); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("LineString").ToLocalChecked()); Nan::SetPrototypeMethod(lcons, "toString", toString); Nan::SetPrototypeMethod(lcons, "getLength", getLength); Nan::SetPrototypeMethod(lcons, "value", value); Nan::SetPrototypeMethod(lcons, "addSubLineString", addSubLineString); ATTR(lcons, "points", pointsGetter, READ_ONLY_SETTER); target->Set(Nan::New("LineString").ToLocalChecked(), lcons->GetFunction()); constructor.Reset(lcons); }
void AddonInitialize(v8::Handle<v8::Object> target) { using namespace v8; //HandleScope scope; static Termios termios; termios.no_canonical(); Terminfo::initialize(); keyinput_symbol = NODE_PSYMBOL("keyinput"); // javascript class Term Local<FunctionTemplate> t = FunctionTemplate::New(Term::New); t->InstanceTemplate()->SetInternalFieldCount(1); t->Inherit(node::EventEmitter::constructor_template); NODE_SET_PROTOTYPE_METHOD(t, "listen", Term::listen); NODE_SET_PROTOTYPE_METHOD(t, "tcmd", Term::tcmd); NODE_SET_PROTOTYPE_METHOD(t, "size", Term::size); target->Set(String::NewSymbol("Term"), t->GetFunction()); }
void Point::Initialize(Handle<Object> target) { NanScope(); Local<FunctionTemplate> lcons = NanNew<FunctionTemplate>(Point::New); lcons->Inherit(NanNew(Geometry::constructor)); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(NanNew("Point")); NODE_SET_PROTOTYPE_METHOD(lcons, "toString", toString); // properties ATTR(lcons, "x", xGetter, xSetter); ATTR(lcons, "y", yGetter, ySetter); ATTR(lcons, "z", zGetter, zSetter); target->Set(NanNew("Point"), lcons->GetFunction()); NanAssignPersistent(constructor, lcons); }
void APIModule::Initialize(Local<Object> target, Local<Context> context) { Isolate* isolate = context->GetIsolate(); HandleScope scope(isolate); Local<FunctionTemplate> constructor = FunctionTemplate::New(isolate); constructor->SetClassName(NEW_SYMBOL(isolate, "API")); constructorTemplate.Reset(isolate, constructor); // Hook methods to the API prototype, notice these aren't hooked to API // itself, instead we return a singleton of an API instance and export it // as Ti.API // Not sure why we then hook apiName as instance proprty, since // the difference is made moot by the singleton! SetProtoMethod(isolate, constructor, "debug", logDebug); SetProtoMethod(isolate, constructor, "info", logInfo); SetProtoMethod(isolate, constructor, "warn", logWarn); SetProtoMethod(isolate, constructor, "error", logError); SetProtoMethod(isolate, constructor, "trace", logTrace); SetProtoMethod(isolate, constructor, "notice", logNotice); SetProtoMethod(isolate, constructor, "critical", logCritical); SetProtoMethod(isolate, constructor, "fatal", logFatal); SetProtoMethod(isolate, constructor, "log", log); SetProtoMethod(isolate, constructor, "getApiName", APIModule::getApiName); // Add an "apiName" property to instances, which delegates to APIModule::getter_apiName // TODO Use a constant here? Local<ObjectTemplate> instanceTemplate = constructor->InstanceTemplate(); instanceTemplate->SetAccessor(NEW_SYMBOL(isolate, "apiName"), APIModule::getter_apiName); // Expose a method for terminating the application for the debugger. // Debugger will send an evaluation request calling this method // when it wants the application to terminate immediately. if (V8Runtime::debuggerEnabled) { SetProtoMethod(isolate, constructor, "terminate", terminate); SetProtoMethod(isolate, constructor, "debugBreak", debugBreak); } // Make API extend from KrollModule constructor->Inherit(KrollModule::getProxyTemplate(isolate)); // export an instance of API as "API" (basically make a static singleton) target->Set(NEW_SYMBOL(isolate, "API"), constructor->GetFunction(context).ToLocalChecked()->NewInstance(context).ToLocalChecked()); }
void FunctionType::Init(Handle<Object> target) { Nan::HandleScope scope; Local<v8::FunctionTemplate> ctor = Nan::New<v8::FunctionTemplate>(New); constructor.Reset(ctor); ctor->Inherit (Nan::New<v8::FunctionTemplate>(Type::constructor)); ctor->InstanceTemplate()->SetInternalFieldCount(1); ctor->SetClassName(Nan::New("FunctionType").ToLocalChecked()); Nan::SetMethod(ctor, "get", FunctionType::Get); Nan::SetPrototypeMethod(ctor, "getReturnType", FunctionType::GetReturnType); Nan::SetPrototypeMethod(ctor, "getParamType", FunctionType::GetParamType); Nan::SetPrototypeMethod(ctor, "dump", FunctionType::Dump); Nan::SetPrototypeMethod(ctor, "toString", FunctionType::ToString); Local<v8::Function> ctor_func = ctor->GetFunction(); constructor_func.Reset(ctor_func); target->Set(Nan::New("FunctionType").ToLocalChecked(), ctor_func); }