// initialize a JS wrapper around this object void NodeFSEvents::Initialize(Handle<Object> target) { HandleScope scope; emit_sym = NODE_PSYMBOL("emit"); change_sym = NODE_PSYMBOL("fsevent"); Local<FunctionTemplate> t = FunctionTemplate::New(NodeFSEvents::New); constructor_template = Persistent<FunctionTemplate>::New(t); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->SetClassName(String::NewSymbol("FSEvents")); Local<Function> constructor = constructor_template->GetFunction(); constructor->Set(String::New("kFSEventStreamEventFlagNone"), Integer::New(0x00000000)); constructor->Set(String::New("kFSEventStreamEventFlagMustScanSubDirs"), Integer::New(0x00000001)); constructor->Set(String::New("kFSEventStreamEventFlagUserDropped"), Integer::New(0x00000002)); constructor->Set(String::New("kFSEventStreamEventFlagKernelDropped"), Integer::New(0x00000004)); constructor->Set(String::New("kFSEventStreamEventFlagEventIdsWrapped"), Integer::New(0x00000008)); constructor->Set(String::New("kFSEventStreamEventFlagHistoryDone"), Integer::New(0x00000010)); constructor->Set(String::New("kFSEventStreamEventFlagRootChanged"), Integer::New(0x00000020)); constructor->Set(String::New("kFSEventStreamEventFlagMount"), Integer::New(0x00000040)); constructor->Set(String::New("kFSEventStreamEventFlagUnmount"), Integer::New(0x00000080)); constructor->Set(String::New("kFSEventStreamEventFlagItemCreated"), Integer::New(0x00000100)); constructor->Set(String::New("kFSEventStreamEventFlagItemRemoved"), Integer::New(0x00000200)); constructor->Set(String::New("kFSEventStreamEventFlagItemInodeMetaMod"), Integer::New(0x00000400)); constructor->Set(String::New("kFSEventStreamEventFlagItemRenamed"), Integer::New(0x00000800)); constructor->Set(String::New("kFSEventStreamEventFlagItemModified"), Integer::New(0x00001000)); constructor->Set(String::New("kFSEventStreamEventFlagItemFinderInfoMod"), Integer::New(0x00002000)); constructor->Set(String::New("kFSEventStreamEventFlagItemChangeOwner"), Integer::New(0x00004000)); constructor->Set(String::New("kFSEventStreamEventFlagItemXattrMod"), Integer::New(0x00008000)); constructor->Set(String::New("kFSEventStreamEventFlagItemIsFile"), Integer::New(0x00010000)); constructor->Set(String::New("kFSEventStreamEventFlagItemIsDir"), Integer::New(0x00020000)); constructor->Set(String::New("kFSEventStreamEventFlagItemIsSymlink"), Integer::New(0x00040000)); target->Set(String::NewSymbol("FSEvents"), constructor); }
void ServiceRef::Initialize(Handle<Object> target) { Local<FunctionTemplate> t = FunctionTemplate::New(New); constructor_template = Persistent<FunctionTemplate>::New(t); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->SetClassName(String::NewSymbol("DNSServiceRef")); fd_symbol = NODE_PSYMBOL("fd"); initialized_symbol = NODE_PSYMBOL("initialized"); constructor_template->InstanceTemplate()->SetAccessor(fd_symbol, fd_getter); constructor_template->InstanceTemplate()->SetAccessor(initialized_symbol, initialized_getter); target->Set(String::NewSymbol("DNSServiceRef"), constructor_template->GetFunction()); }
/** * @details This is called from the module initialisation function * when the module is first loaded by Node. It should only be called * once per process. * * @param target The object representing the module. */ void Map::Init(Handle<Object> target) { HandleScope scope; Local<FunctionTemplate> template_ = FunctionTemplate::New(New); map_template = Persistent<FunctionTemplate>::New(template_); map_template->InstanceTemplate()->SetInternalFieldCount(1); map_template->SetClassName(String::NewSymbol("Map")); data_symbol = NODE_PSYMBOL("data"); headers_symbol = NODE_PSYMBOL("headers"); NODE_SET_PROTOTYPE_METHOD(map_template, "mapserv", MapservAsync); NODE_SET_METHOD(map_template, "FromFile", FromFileAsync); NODE_SET_METHOD(map_template, "FromString", FromStringAsync); target->Set(String::NewSymbol("Map"), map_template->GetFunction()); }
v8::Handle<v8::Value> BufferWrap::New(const v8::Arguments& args) { if (args.Length() == 1 && args[0]->IsExternal()) { v8::Local<v8::External> ext = v8::Local<v8::External>::Cast(args[0]); static_cast<BufferWrap*>(ext->Value())->Wrap(args.This()); return args.This(); } else if (args.Length() == 1 && args[0]->IsObject()) { auto obj = args[0]->ToObject(); if (node::Buffer::HasInstance(obj)) { osmium::memory::Buffer buffer(reinterpret_cast<unsigned char*>(node::Buffer::Data(obj)), node::Buffer::Length(obj)); BufferWrap* buffer_wrap = new BufferWrap(std::move(buffer)); buffer_wrap->Wrap(args.This()); // Store the node::Buffer in the new osmium::Buffer object // so the node::Buffer doesn't go away if it goes out of scope // outside this function. args.This()->Set(NODE_PSYMBOL("_data"), obj); return args.This(); } } return ThrowException(v8::Exception::TypeError(v8::String::New("osmium.Buffer takes a single argument, a node::Buffer"))); }
static void start(v8::Handle<v8::Object> target) { v8::HandleScope scope; module = v8::Persistent<v8::Object>::New(target); node::SetMethod(target, "apply", node_osmium::apply); node::SetMethod(target, "register_filter", node_osmium::Filter::register_filter); symbol_OSMEntity = NODE_PSYMBOL("OSMEntity"); symbol_OSMObject = NODE_PSYMBOL("OSMObject"); symbol_Node = NODE_PSYMBOL("Node"); symbol_node = NODE_PSYMBOL("node"); symbol_Way = NODE_PSYMBOL("Way"); symbol_way = NODE_PSYMBOL("way"); symbol_Relation = NODE_PSYMBOL("Relation"); symbol_relation = NODE_PSYMBOL("relation"); symbol_type = NODE_PSYMBOL("type"); symbol_ref = NODE_PSYMBOL("ref"); symbol_role = NODE_PSYMBOL("role"); symbol_Area = NODE_PSYMBOL("Area"); symbol_area = NODE_PSYMBOL("area"); symbol_Changeset = NODE_PSYMBOL("Changeset"); symbol_changeset = NODE_PSYMBOL("changeset"); symbol_Coordinates = NODE_PSYMBOL("Coordinates"); symbol_Box = NODE_PSYMBOL("Box"); symbol_generator = NODE_PSYMBOL("generator"); symbol_bounds = NODE_PSYMBOL("bounds"); symbol_Buffer = NODE_PSYMBOL("Buffer"); symbol_File = NODE_PSYMBOL("File"); symbol_Handler = NODE_PSYMBOL("Handler"); symbol_LocationHandler = NODE_PSYMBOL("LocationHandler"); symbol_MultipolygonCollector = NODE_PSYMBOL("MultipolygonCollector"); symbol_MultipolygonHandler = NODE_PSYMBOL("MultipolygonHandler"); symbol_BasicReader = NODE_PSYMBOL("BasicReader"); symbol_FlexReader = NODE_PSYMBOL("FlexReader"); node_osmium::OSMEntityWrap::Initialize(target); node_osmium::OSMObjectWrap::Initialize(target); node_osmium::OSMNodeWrap::Initialize(target); node_osmium::OSMWayWrap::Initialize(target); node_osmium::OSMRelationWrap::Initialize(target); node_osmium::OSMAreaWrap::Initialize(target); node_osmium::OSMChangesetWrap::Initialize(target); node_osmium::MultipolygonCollectorWrap::Initialize(target); node_osmium::MultipolygonHandlerWrap::Initialize(target); node_osmium::LocationHandlerWrap::Initialize(target); node_osmium::JSHandler::Initialize(target); node_osmium::FileWrap::Initialize(target); node_osmium::BasicReaderWrap::Initialize(target); node_osmium::FlexReaderWrap::Initialize(target); node_osmium::BufferWrap::Initialize(target); Filter::init_filters(); }
int Start(int argc, char *originalArgv[]) { TRACEIN; // ERZ mod, don't copy -psn_ arg, which Mac OS X generates for // double-clickable applications // now make a copy of the args and pretend main.js was requested on the command line bool needMainJs = (getScriptPassedInArgs(argc, (const char**)originalArgv) == 0); int i = 0; int j = 0; char* sMainJsStr = (char*) std::malloc(10); std::strcpy(sMainJsStr, "main.js"); char** argv = (char**)std::malloc(sizeof(char*)*(argc+2)); for (i = 0; i<argc; i++, j++) { argv[j] = originalArgv[i]; if (std::strncmp(originalArgv[i], "-psn_", 4) == 0) { j--; // overwrite the -psn arg } else if (strcmp(originalArgv[i], "--version") == 0 || strcmp(originalArgv[i], "-v") == 0) { printf("PDG v%s\nNode.js %s\n", PDG_VERSION, NODE_VERSION); exit(0); } else if (strcmp(originalArgv[i], "--help") == 0) { printf("Usage: pdg [options] [script.js] [arguments] \n" "\n" "If script is not specified, pdg will search for main.js \n" "\n" "Options:\n" " -v, --version print pdg's version\n" " --no-deprecation silence deprecation warnings\n" " --trace-deprecation show stack traces on deprecations\n" " --v8-options print v8 command line options\n" " --max-stack-size=val set max v8 stack size (bytes)\n" "\n" "Environment variables:\n" #ifdef _WIN32 "NODE_PATH ';'-separated list of directories\n" #else "NODE_PATH ':'-separated list of directories\n" #endif " prefixed to the module search path.\n" "NODE_DEBUG Set to \"module\" to debug module loading.\n" "NODE_DISABLE_COLORS Set to 1 to disable colors in the REPL\n" "\n" "PDG Documentation is at http://ezavada.com/pdg/\n" "Node.js Documentation can be found at http://nodejs.org/\n"); exit(0); } } argc -= (i-j); // adjust for argument(s) removed if (needMainJs) { argv[argc] = sMainJsStr; argc++; } argv[argc] = 0; // guard // uv_setup_args() won't like our non-contigous argv memory, so make a copy char **argv_clean = copy_argv(argc, argv); // Hack aroung with the argv pointer. Used for process.title = "blah". argv = uv_setup_args(argc, argv_clean); // Logic to duplicate argv as Init() modifies arguments // that are passed into it. char **argv_copy = copy_argv(argc, argv); TRACE("calling node::Init().."); // This needs to run *before* V8::Initialize() // Use copy here as to not modify the original argv: node::Init(argc, argv_copy); TRACE("calling v8::Initialize().."); v8::V8::Initialize(); { v8::Locker locker; v8::HandleScope handle_scope; // Create the one and only Context. v8::Persistent<v8::Context> context = v8::Context::New(); v8::Context::Scope context_scope(context); node::process_symbol = NODE_PSYMBOL("process"); node::domain_symbol = NODE_PSYMBOL("domain"); TRACE("calling node::SetupProcessObject().."); // Use original argv, as we're just copying values out of it. v8::Handle<v8::Object> process_l = node::SetupProcessObject(argc, argv); TRACE("calling v8_typed_array::AttachBindings().."); v8_typed_array::AttachBindings(context->Global()); // bypass the usual bootstrap and use ours instead pdg::setupThirdPartyMain(process_l); // Create all the objects, load modules, do everything. // so your next reading stop should be node::Load()! TRACE("calling node::Load().."); node::Load(process_l); // ERZ modification to standard node Start(), to support loading pdg modules TRACE("calling pdg::installIntoNodeApplication().."); pdg::installIntoNodeApplication(); // All our arguments are loaded. We've evaluated all of the scripts. We // might even have created TCP servers. Now we enter the main eventloop. If // there are no watchers on the loop (except for the ones that were // uv_unref'd) then this function exits. As long as there are active // watchers, it blocks. TRACE("calling uv_run().."); uv_run(uv_default_loop(), UV_RUN_DEFAULT); TRACE("calling node::EmitExit().."); node::EmitExit(process_l); TRACE("calling node::RunAtExit().."); node::RunAtExit(); #ifndef NDEBUG context.Dispose(); #endif } #ifndef NDEBUG // Clean up. Not strictly necessary. v8::V8::Dispose(); #endif // NDEBUG // Clean up the copy: free(argv_copy); TRACEOUT; return 0; }