Esempio n. 1
0
Local<Value> Geometry::New(OGRGeometry *geom, bool owned)
{
    Nan::EscapableHandleScope scope;

    if (!geom) {
        return scope.Escape(Nan::Null());
    }

    OGRwkbGeometryType type = getGeometryType_fixed(geom);
    type = wkbFlatten(type);

    switch (type) {
    case wkbPoint:
        return scope.Escape(Point::New(static_cast<OGRPoint*>(geom), owned));
    case wkbLineString:
        return scope.Escape(LineString::New(static_cast<OGRLineString*>(geom), owned));
    case wkbLinearRing:
        return scope.Escape(LinearRing::New(static_cast<OGRLinearRing*>(geom), owned));
    case wkbPolygon:
        return scope.Escape(Polygon::New(static_cast<OGRPolygon*>(geom), owned));
    case wkbGeometryCollection:
        return scope.Escape(GeometryCollection::New(static_cast<OGRGeometryCollection*>(geom), owned));
    case wkbMultiPoint:
        return scope.Escape(MultiPoint::New(static_cast<OGRMultiPoint*>(geom), owned));
    case wkbMultiLineString:
        return scope.Escape(MultiLineString::New(static_cast<OGRMultiLineString*>(geom), owned));
    case wkbMultiPolygon:
        return scope.Escape(MultiPolygon::New(static_cast<OGRMultiPolygon*>(geom), owned));
    default:
        Nan::ThrowError("Tried to create unsupported geometry type");
        return scope.Escape(Nan::Undefined());
    }
}
Esempio n. 2
0
Local<Value> LineString::New(OGRLineString *geom, bool owned)
{
	Nan::EscapableHandleScope scope;

	if (!geom) {
		return scope.Escape(Nan::Null());
	}

	//make a copy of geometry owned by a feature
	// + no need to track when a feature is destroyed
	// + no need to throw errors when a method trys to modify an owned read-only geometry
	// - is slower

	if (!owned) {
		geom = static_cast<OGRLineString*>(geom->clone());
	};

	LineString *wrapped = new LineString(geom);
	wrapped->owned_ = true;

	UPDATE_AMOUNT_OF_GEOMETRY_MEMORY(wrapped);

	Local<Value> ext = Nan::New<External>(wrapped);
	Local<Object> obj = Nan::New(LineString::constructor)->GetFunction()->NewInstance(1, &ext);

	return scope.Escape(obj);
}
Esempio n. 3
0
 Local<Value> next() {
     Nan::EscapableHandleScope scope;
     if (nextIt == items.end()) return scope.Escape(Nan::Undefined());
     Local<Array> obj = Nan::New<Array>();
     obj->Set(Nan::New(0), Nan::New(nextIt->first).ToLocalChecked());
     obj->Set(Nan::New(1), Nan::New(nextIt->second).ToLocalChecked());
     nextIt++;
     return scope.Escape(obj);
 }
Esempio n. 4
0
Local<Value> Geometry::getConstructor(OGRwkbGeometryType type) {
    Nan::EscapableHandleScope scope;

    type = wkbFlatten(type);
    switch (type) {
    case wkbPoint:
        return scope.Escape(Nan::New(Point::constructor)->GetFunction());
    case wkbLineString:
        return scope.Escape(Nan::New(LineString::constructor)->GetFunction());
    case wkbLinearRing:
        return scope.Escape(Nan::New(LinearRing::constructor)->GetFunction());
    case wkbPolygon:
        return scope.Escape(Nan::New(Polygon::constructor)->GetFunction());
    case wkbGeometryCollection:
        return scope.Escape(Nan::New(GeometryCollection::constructor)->GetFunction());
    case wkbMultiPoint:
        return scope.Escape(Nan::New(MultiPoint::constructor)->GetFunction());
    case wkbMultiLineString:
        return scope.Escape(Nan::New(MultiLineString::constructor)->GetFunction());
    case wkbMultiPolygon:
        return scope.Escape(Nan::New(MultiPolygon::constructor)->GetFunction());
    default:
        return scope.Escape(Nan::Null());
    }
}
/*
   DESCRIPTION
     Abstraction to all getter accessors of properties
*/
Local<Primitive> Pool::getPoolProperty(Pool* njsPool, unsigned int poolProperty)
{
  Nan::EscapableHandleScope scope;
  
  if(!njsPool->isValid_)
  {
    string msg = NJSMessages::getErrorMsg(errInvalidPool);
    NJS_SET_EXCEPTION(msg.c_str(), (int) msg.length());
    return scope.Escape ( Nan::Undefined() ) ;
  }
  else
  {
    return scope.Escape ( Nan::New<v8::Integer>(poolProperty) ) ;
  }
  return scope.Escape ( Nan::Undefined() ) ;
}
Esempio n. 6
0
 v8::Local<v8::Value> DebugLoc::Create(llvm::DebugLoc llvm_debugloc) {
   Nan::EscapableHandleScope scope;
   Local<Object> new_instance = Nan::NewInstance(Nan::New(DebugLoc::constructor_func)).ToLocalChecked();
   DebugLoc* new_debugloc = new DebugLoc(llvm_debugloc);
   new_debugloc->Wrap(new_instance);
   return scope.Escape(new_instance);
 }
Esempio n. 7
0
 v8::Local<v8::Value> DICompileUnit::Create(llvm::DICompileUnit* llvm_dicompileunit) {
   Nan::EscapableHandleScope scope;
   Local<Object> new_instance = Nan::NewInstance(Nan::New(DICompileUnit::constructor_func)).ToLocalChecked();
   DICompileUnit* new_dicompileunit = new DICompileUnit(llvm_dicompileunit);
   new_dicompileunit->Wrap(new_instance);
   return scope.Escape(new_instance);
 }
Esempio n. 8
0
 v8::Local<v8::Value> DILexicalBlock::Create(llvm::DILexicalBlock* llvm_dilexicalblock) {
   Nan::EscapableHandleScope scope;
   Local<Object> new_instance = Nan::NewInstance(Nan::New(DILexicalBlock::constructor_func)).ToLocalChecked();
   DILexicalBlock* new_dilexicalblock = new DILexicalBlock(llvm_dilexicalblock);
   new_dilexicalblock->Wrap(new_instance);
   return scope.Escape(new_instance);
 }
Esempio n. 9
0
 v8::Local<v8::Value> DIFile::Create(llvm::DIFile* llvm_difile) {
   Nan::EscapableHandleScope scope;
   Local<Object> new_instance = Nan::NewInstance(Nan::New(DIFile::constructor_func)).ToLocalChecked();
   DIFile* new_difile = new DIFile(llvm_difile);
   new_difile->Wrap(new_instance);
   return scope.Escape(new_instance);
 }
Esempio n. 10
0
 v8::Local<v8::Value> DISubprogram::Create(llvm::DISubprogram* llvm_disubprogram) {
   Nan::EscapableHandleScope scope;
   Local<Object> new_instance = Nan::NewInstance(Nan::New(DISubprogram::constructor_func)).ToLocalChecked();
   DISubprogram* new_disubprogram = new DISubprogram(llvm_disubprogram);
   new_disubprogram->Wrap(new_instance);
   return scope.Escape(new_instance);
 }
Esempio n. 11
0
v8::Local<v8::Value> MSOutputFormat::NewInstance(outputFormatObj *of_ptr) {
  Nan::EscapableHandleScope scope;
  MSOutputFormat* of = new MSOutputFormat();
  of->this_ = of_ptr;
  v8::Local<v8::Value> ext = Nan::New<v8::External>(of);
  return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
}
Esempio n. 12
0
 v8::Local<v8::Object> operator()(const point<T>& point) {
     Nan::EscapableHandleScope scope;
     v8::Local<v8::Array> result = Nan::New<v8::Array>(2);
     Nan::Set(result, 0, Nan::New(point.x));
     Nan::Set(result, 1, Nan::New(point.y));
     return scope.Escape(result);
 }
Esempio n. 13
0
// Unfortunately native modules don't get a reference
// to require.cache as this happens in Module._compile()
// and native modules aren't compiled, they are loaded
// directly by NativeModule.require() (in Module._load())
// So we need to get it from Module._cache instead (by
// executing require('module')._cache)
static Local<Object> getRequireCache(Handle<Object> module) {
	Nan::EscapableHandleScope scope;
	Handle<Value> args[] = { Nan::New<String>("module").ToLocalChecked() };
	Local<Value> m = module->Get(Nan::New<String>("require").ToLocalChecked())->ToObject()->CallAsFunction(Nan::GetCurrentContext()->Global(), 1, args);
	Local<Object> cache = m->ToObject()->Get(Nan::New<String>("_cache").ToLocalChecked())->ToObject();
	return scope.Escape(cache);
}
Esempio n. 14
0
v8::Local<v8::Value> Grid::_clearSync(Nan::NAN_METHOD_ARGS_TYPE info)
{
    Nan::EscapableHandleScope scope;
    Grid* g = Nan::ObjectWrap::Unwrap<Grid>(info.Holder());
    g->get()->clear();
    return scope.Escape(Nan::Undefined());
}
v8::Local<v8::Value> MemoryDatasource::NewInstance(mapnik::datasource_ptr ds_ptr) {
    Nan::EscapableHandleScope scope;
    MemoryDatasource* d = new MemoryDatasource();
    d->datasource_ = ds_ptr;
    v8::Local<v8::Value> ext = Nan::New<v8::External>(d);
    return scope.Escape( Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
}
Esempio n. 16
0
v8::Local<v8::Value> MSRect::NewInstance(rectObj *ptr) {
  Nan::EscapableHandleScope scope;
  MSRect* obj = new MSRect();
  obj->this_ = ptr;
  v8::Local<v8::Value> ext = Nan::New<v8::External>(obj);
  return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
}
Esempio n. 17
0
v8::Local<v8::Value> Feature::NewInstance(mapnik::feature_ptr f_ptr)
{
    Nan::EscapableHandleScope scope;
    Feature* f = new Feature(f_ptr);
    v8::Local<v8::Value> ext = Nan::New<v8::External>(f);
    return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
}
Esempio n. 18
0
v8::Local<v8::Value> Color::NewInstance(mapnik::color const& color) {
    Nan::EscapableHandleScope scope;
    Color* c = new Color();
    c->this_ = std::make_shared<mapnik::color>(color);
    v8::Local<v8::Value> ext = Nan::New<v8::External>(c);
    return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
}
Handle<Object> createBuffer(char *data, int length) {
	Nan::EscapableHandleScope scope;

	Local<Object> buffer = Nan::CopyBuffer(data, length).ToLocalChecked();

	return scope.Escape(buffer);
}
Esempio n. 20
0
Local<Object> ODBC::GetSQLError (SQLSMALLINT handleType, SQLHANDLE handle) {
    Nan::EscapableHandleScope scope;

    return scope.Escape(GetSQLError(
                            handleType,
                            handle,
                            (char *) "[node-odbc] SQL_ERROR"));
}
Esempio n. 21
0
 v8::Local<v8::Value> operator()(const std::vector<mbgl::Value>& array) {
     Nan::EscapableHandleScope scope;
     v8::Local<v8::Array> result = Nan::New<v8::Array>();
     for (unsigned int i = 0; i < array.size(); i++) {
         result->Set(i, toJS(array[i]));
     }
     return scope.Escape(result);
 }
Esempio n. 22
0
 v8::Local<v8::Object> operator()(const std::vector<E>& vector) {
     Nan::EscapableHandleScope scope;
     v8::Local<v8::Array> result = Nan::New<v8::Array>(vector.size());
     for (std::size_t i = 0; i < vector.size(); ++i) {
         Nan::Set(result, i, operator()(vector[i]));
     }
     return scope.Escape(result);
 }
Esempio n. 23
0
v8::Local<v8::Value> Featureset::NewInstance(mapnik::featureset_ptr fs_ptr)
{
    Nan::EscapableHandleScope scope;
    Featureset* fs = new Featureset();
    fs->this_ = fs_ptr;
    v8::Local<v8::Value> ext = Nan::New<v8::External>(fs);
    return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
}
v8::Local<v8::Function> Convert::getCallbackFunction(v8::Local<v8::Value> js)
{
    Nan::EscapableHandleScope scope;
    if (!js->IsFunction())
    {
        throw std::runtime_error("function");
    }
    return scope.Escape(js.As<v8::Function>());
}
Esempio n. 25
0
v8::Local<v8::Value> Color::NewInstance(mapnik::color const& color) {
    Nan::EscapableHandleScope scope;
    Color* c = new Color();
    c->this_ = std::make_shared<mapnik::color>(color);
    v8::Local<v8::Value> ext = Nan::New<v8::External>(c);
    Nan::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
    if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Color instance");
    return scope.Escape(maybe_local.ToLocalChecked());
}
Esempio n. 26
0
//
// Creates a new instance of Connection
//
// NOTE : This is not a Javascript Connection method
//
v8::Local<v8::Value> Connection::NewInstance(v8::Local<v8::Value> arg) {
  Nan::EscapableHandleScope scope;

  const unsigned argc = 1;
  v8::Local<v8::Value> argv[argc] = {arg};
  v8::Local<v8::Function> cons = Nan::New<v8::Function>(_constructor);
  v8::Local<v8::Object> instance = cons->NewInstance(argc, argv);

  return scope.Escape(instance);
}
Esempio n. 27
0
v8::Local<v8::Object> toJS(const Properties& properties) {
    Nan::EscapableHandleScope scope;

    v8::Local<v8::Object> result = Nan::New<v8::Object>();
    for (const auto& property : properties) {
        Nan::Set(result, Nan::New(property.first).ToLocalChecked(), toJS(property.second));
    }

    return scope.Escape(result);
}
Esempio n. 28
0
Local<Object> SelectResults::NewInstance(const SelectResultsPtr & selectResultsPtr) {
  Nan::EscapableHandleScope scope;
 const unsigned int argc = 0;
  Local<Value> argv[argc] = {};
  Local<Object> instance(Nan::New(SelectResults::constructor())->NewInstance(argc, argv));
  SelectResults * selectResults = new SelectResults(selectResultsPtr);
  selectResults->Wrap(instance);

  return scope.Escape(instance);
}
Esempio n. 29
0
v8::Local<v8::Value> Layer::NewInstance(mapnik::layer const& lay_ref) {
    Nan::EscapableHandleScope scope;
    Layer* l = new Layer();
    // copy new mapnik::layer into the shared_ptr
    l->layer_ = std::make_shared<mapnik::layer>(lay_ref);
    v8::Local<v8::Value> ext = Nan::New<v8::External>(l);
    Nan::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
    if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Layer instance");
    return scope.Escape(maybe_local.ToLocalChecked());
}
Esempio n. 30
0
v8::Local<v8::Value> Featureset::NewInstance(mapnik::featureset_ptr fsp)
{
    Nan::EscapableHandleScope scope;
    Featureset* fs = new Featureset();
    fs->this_ = fsp;
    v8::Local<v8::Value> ext = Nan::New<v8::External>(fs);
    Nan::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
    if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Featureset instance");
    return scope.Escape(maybe_local.ToLocalChecked());
}