コード例 #1
0
static Handle<Value> NavigatorSet(Local<String> name, Local<Value> value, const AccessorInfo& info)
{
    Handle<Value> retval;
    std::string key = value_to_string(name);

    if (key != "javaEnabled") {
        Local<Object> self = info.This();
        Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
        void* ptr = wrap->Value();
        jsNavigator* el = static_cast<jsNavigator*>(ptr);
        // Convert the JavaScript string to a std::string.
        el->props[key] = Persistent<Value>::New(value);
        Handle<Value> retval = value;
    }
    return retval;
}
コード例 #2
0
ファイル: JSZCluster.cpp プロジェクト: paoloach/zdomus
    void JSZCluster::weakCallback(const v8::WeakCallbackData<v8::Object, JSZCluster> &data) {

        JSZCluster *This = data.GetParameter();
        Local<Object> value = data.GetValue();

        Local<External> wrap = Local<External>::Cast(value->GetInternalField(1));
        Cluster *cluster = (Cluster *) wrap->Value();

        NwkAddr nwkAddress = cluster->getNetworkAddress();
        EndpointID endpointId = cluster->getEndpoint();
        ClusterID clusterId = cluster->getId();

        Key key(nwkAddress, endpointId, clusterId);

        This->usedCluster.erase(key);
    }
コード例 #3
0
ファイル: jsengine.cpp プロジェクト: Daniel15/vroomjs
static Handle<Value> managed_prop_set(Local<String> name, Local<Value> value, const AccessorInfo& info)
{
#ifdef DEBUG_TRACE_API
		std::cout << "managed_prop_set" << std::endl;
#endif
    HandleScope scope;
    
    Local<Object> self = info.Holder();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    ManagedRef* ref = (ManagedRef*)wrap->Value();
	if (ref == NULL) {
		Local<Value> result;
		return scope.Close(result);
	}
    return scope.Close(ref->SetPropertyValue(name, value));
}
コード例 #4
0
static void Set_FontState_strikeOut(Local<String> property, Local<Value> value, const AccessorInfo& info) 
{
	HandleScope scope;
	
	Local<Object> self = info.Holder();
	Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
	if (wrap.IsEmpty())
		return;

	FontState *tmp = (FontState *) wrap->Value();
	if (tmp == NULL)
		return;

	if (!value.IsEmpty() && value->IsBoolean())
		tmp->setStrikeOut(value->BooleanValue());
}
コード例 #5
0
static void Set_DialogState_height(Local<String> property, Local<Value> value, const AccessorInfo& info)
{
    HandleScope scope;

    Local<Object> self = info.Holder();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    if (wrap.IsEmpty())
        return;

    DialogState *tmp = (DialogState *) wrap->Value();
    if (tmp == NULL)
        return;

    if (!value.IsEmpty() && value->IsNumber())
        tmp->setHeight(value->Int32Value());
}
コード例 #6
0
ファイル: ogr_geometry.cpp プロジェクト: blairdgeo/node-ogr
Handle<Value> Geometry::New(const Arguments& args)
{
  HandleScope scope;

  if (!args.IsConstructCall())
    return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));

  if (args[0]->IsExternal()) {
    Local<External> ext = Local<External>::Cast(args[0]);
    void* ptr = ext->Value();
    Geometry *f = static_cast<Geometry *>(ptr);
    f->Wrap(args.This());
    return args.This();
  }

  return args.This();
}
コード例 #7
0
ファイル: dataset_bands.cpp プロジェクト: jarped/node-gdal
Handle<Value> DatasetBands::New(const Arguments& args)
{
	HandleScope scope;

	if (!args.IsConstructCall()) {
		return NODE_THROW("Cannot call constructor as function, you need to use 'new' keyword");
	}
	if (args[0]->IsExternal()) {
		Local<External> ext = Local<External>::Cast(args[0]);
		void* ptr = ext->Value();
		DatasetBands *f =  static_cast<DatasetBands *>(ptr);
		f->Wrap(args.This());
		return args.This();
	} else {
		return NODE_THROW("Cannot create DatasetBands directly");
	}
}
コード例 #8
0
Handle<Value> jsWindow::PlaceHolder(const Arguments& args)
{
    Local<Object> self = args.This();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    void* ptr = wrap->Value();
    jsWindow* el = static_cast<jsWindow*>(ptr);

    string ret;
    ret = value_to_string(args.Callee()->ToString());
    ret += " [Window; uuid=";
    ret += el->win_uuid;
    ret += "; name=";
    ret += value_to_string(el->props["name"]->ToString());
    ret += "]";
    LOG4CXX_DEBUG(iLogger::GetLogger(), _T("jsWindow::PlaceHolder - ") << ret);
    return String::New(ret.c_str());
}
コード例 #9
0
Handle<Value> lzmaCRC32(const Arguments& args) {
	HandleScope scope;
	Local<Integer> arg = Local<Integer>::Cast(args[1]);
	
	if (arg.IsEmpty() || args[1]->IsUndefined())
		arg = Integer::New(0);
	
	const uint8_t* data;
	size_t datalen;
	
	if (!readBufferFromObj(args[0], data, datalen)) {
		ThrowException(Exception::TypeError(String::New("CRC32 expects Buffer as input")));
		return scope.Close(Undefined());
	}
	
	return scope.Close(Integer::NewFromUnsigned(lzma_crc32(data, datalen, arg->Value())));
}
コード例 #10
0
Handle<Value> TiUITableView::_scrollToIndex(void* userContext, TiObject*, const Arguments& args)
{
    HandleScope handleScope;
    TiUITableView* obj = (TiUITableView*) userContext;
    NativeObject* no = obj->getNativeObject();
    if (args[0]->IsNumber())
    {
        Local<Integer> index = args[0]->ToInteger();
        no->scrollToIndex(index->Value());
    }
    else
    {
        TI_DEBUG(Ti::Msg::INTERNAL__args0_is_not_a_number);
    }

    return Undefined();
}
コード例 #11
0
ファイル: V8Script.cpp プロジェクト: Databean/ProgNet
void makeLine(const v8::FunctionCallbackInfo<v8::Value>& args) {
	if(args.Length() != 4) {
		args.GetReturnValue().Set(Boolean::New(Isolate::GetCurrent(), false));
		return;
	}
	Local<External> shapeManagerExternal = Local<External>::Cast(args.Callee()->Get(String::NewFromUtf8(Isolate::GetCurrent(), shapeManagerStr.c_str())));
	ShapeManager2d* shapeManager = static_cast<ShapeManager2d*>(shapeManagerExternal->Value());
	
	Point2d p1{args[0]->NumberValue(), args[1]->NumberValue()};
	Point2d p2{args[2]->NumberValue(), args[3]->NumberValue()};
	
	Local<Object> obj = initShape()->NewInstance();
	unsigned int shape = shapeManager->makeLine(p1, p2);
	obj->SetInternalField(0, shapeManagerExternal);
	obj->SetInternalField(1, Integer::NewFromUnsigned(Isolate::GetCurrent(), shape));
	
	args.GetReturnValue().Set(obj);
}
コード例 #12
0
Handle<Value> MemoryDatasource::New(const Arguments& args)
{
    HandleScope scope;

    if (!args.IsConstructCall())
        return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));

    if (args[0]->IsExternal())
    {
        //std::clog << "external!\n";
        Local<External> ext = Local<External>::Cast(args[0]);
        void* ptr = ext->Value();
        MemoryDatasource* d =  static_cast<MemoryDatasource*>(ptr);
        d->Wrap(args.This());
        return args.This();
    }
    if (args.Length() != 1){
        return ThrowException(Exception::TypeError(
                                  String::New("accepts only one argument, an object of key:value datasource options")));
    }

    if (!args[0]->IsObject())
        return ThrowException(Exception::TypeError(
                                  String::New("Must provide an object, eg {type: 'shape', file : 'world.shp'}")));

    Local<Object> options = args[0]->ToObject();

    mapnik::parameters params;
    Local<Array> names = options->GetPropertyNames();
    unsigned int i = 0;
    unsigned int a_length = names->Length();
    while (i < a_length) {
        Local<Value> name = names->Get(i)->ToString();
        Local<Value> value = options->Get(name);
        params[TOSTR(name)] = TOSTR(value);
        i++;
    }

    //memory_datasource cache;
    MemoryDatasource* d = new MemoryDatasource();
    d->Wrap(args.This());
    d->datasource_ = MAPNIK_MAKE_SHARED<mapnik::memory_datasource>();
    return args.This();
}
コード例 #13
0
static void Set_FontState_face(Local<String> property, Local<Value> value, const AccessorInfo& info) 
{
	HandleScope scope;
	
	Local<Object> self = info.Holder();
	Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
	if (wrap.IsEmpty())
		return;

	FontState *tmp = (FontState *) wrap->Value();
	if (tmp == NULL)
		return;

	if (!value.IsEmpty() && value->IsString())
	{
		String::Utf8Value utf8_value(value);
		tmp->setFace(Utf8ToTchar(*utf8_value));
	}
}
コード例 #14
0
ファイル: point.cpp プロジェクト: TheCodeInside/v8-example
void Point::Print( const FunctionCallbackInfo< Value >& args ) {
	// Enter a new scope
	HandleScope scope;

	// Ensure no parameters
	if ( args.Length() != 0 ) {
		Handle< Value > ex = Exception::SyntaxError( String::New( "Too many parameters." ) );
		ThrowException( ex );
	}
	else {
		// Get wrapped object
		Local< Object > self = args.Holder();
		Local< External > wrap = Local< External >::Cast( self->GetInternalField( 0 ) );

		// Print formatted object data
		Point* point = static_cast< Point* >( wrap->Value() );
		cout << "[x=" << point->pX << ",y=" << point->pY << "]" << endl;
	}
}
コード例 #15
0
Handle<Value> ImageView::New(const Arguments& args)
{
    HandleScope scope;
    if (!args.IsConstructCall())
        return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));

    if (args[0]->IsExternal())
    {
        //std::clog << "image view external!\n";
        Local<External> ext = Local<External>::Cast(args[0]);
        void* ptr = ext->Value();
        ImageView* im =  static_cast<ImageView*>(ptr);
        im->Wrap(args.This());
        return args.This();
    } else {
            return ThrowException(String::New("Cannot create this object from Javascript"));
    }
    return Undefined();
}
コード例 #16
0
ファイル: engine_v8.cpp プロジェクト: alanw/mongo
 Handle< Value > V8Scope::nativeCallback( const Arguments &args ) {
     Local< External > f = External::Cast( *args.Callee()->Get( v8::String::New( "_native_function" ) ) );
     NativeFunction function = ( NativeFunction )( f->Value() );
     BSONObjBuilder b;
     for( int i = 0; i < args.Length(); ++i ) {
         stringstream ss;
         ss << i;
         v8ToMongoElement( b, v8::String::New( "foo" ), ss.str(), args[ i ] );
     }
     BSONObj ret;
     try {
         ret = function( b.done() );
     } catch( const std::exception &e ) {
         return v8::ThrowException(v8::String::New(e.what()));
     } catch( ... ) {
         return v8::ThrowException(v8::String::New("unknown exception"));            
     }
     return mongoToV8Element( ret.firstElement() );
 }
コード例 #17
0
Handle<Value> jsWindow::Open(const Arguments& args)
{
    Local<Object> self = args.This();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    void* ptr = wrap->Value();
    jsWindow* el = static_cast<jsWindow*>(ptr);

    Handle<Value> val;
    if (!el->is_closed()) {
        transport_url url;
        string nm = "";
        bool is_replace = false;
        jsWindow* new_win = NULL;
        if (args.Length() > 0) {
            url.assign_with_referer(value_to_string(args[0]), &el->location->url);
        } else {
            url.protocol = "about";
            url.host = "blank";
        }
        if (args.Length() > 1) {
            nm = value_to_string(args[1]);
        }
        // features (args[2]) argument not yet implemented
        if (args.Length() > 3) {
            is_replace = args[3]->BooleanValue();
        }
        if (nm != "") {
            new_win = el->browser->window_by_name(nm);
        }
        if (new_win == NULL) {
            new_win = new jsWindow(el->browser, el->browser->window, el);
            new_win->props["name"] = Persistent<Value>::New(String::New(nm.c_str()));
        }
        new_win->location->url = url;
        el->browser->register_window(new_win);
        val = v8_wrapper::wrap_object<jsWindow>(new_win);
        LOG4CXX_TRACE(iLogger::GetLogger(), _T("jsWindow::Open new window - uuid=") << new_win->win_uuid
                      << _T("; url=") << url.tostring());
    }
    return val;
}
コード例 #18
0
static Handle<Value> BrowserSet(Local<String> name, Local<Value> value, const AccessorInfo& info)
{
    Handle<Value> val;
    std::string key = value_to_string(name);

    LOG4CXX_TRACE(webEngine::iLogger::GetLogger(), _T("jsBrowserSet: property(")<< key <<_T(")"));
    Local<External> wrap = Local<External>::Cast(info.Data());
    void* ptr = wrap->Value();
    if (ptr != NULL) {
        jsBrowser* el = static_cast<jsBrowser*>(ptr);
        if (key == "v8_results") {
            string sval = value_to_string(value);
            el->append_results(sval);
        } else if (el->window->is_property(key)) {
            val = el->window->GetProperty(name, info);
        } else {
            el->props[key] = Persistent<Value>::New(value);
        }
    }
    return val;
}
コード例 #19
0
Handle<Value> jsBrowser::WinInterceptor( const Arguments& args )
{
    Handle<Value> retval;
    Local<Context> ctx = v8::Context::GetCurrent();
    Local<Object> exec = Local<Object>::Cast(ctx->Global()->Get(String::New("v8_context")));
    Local<External> wrap = Local<External>::Cast(exec->GetInternalField(0));
    void* ptr = wrap->Value();
    jsBrowser* el = static_cast<jsBrowser*>(ptr);

    string fname = value_to_string(args.Callee()->GetName()->ToString());

    Local<Object> _obj = Local<Object>::New(v8_wrapper::wrap_object<jsWindow>(el->window));
    Local<Function> _func = Local<Function>::Cast(_obj->Get(String::New(fname.c_str())));
    Handle<Value> *fargs = new Handle<Value>[args.Length()];
    for (int i = 0; i < args.Length(); ++i) {
        fargs[i] = args[i];
    }
    retval = _func->Call(_obj, args.Length(), fargs );

    return retval;
}
コード例 #20
0
static Handle<Value> NavigatorGet(Local<String> name, const AccessorInfo &info)
{
    HandleScope scope;

    Local<Object> self = info.This();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    v8_wrapper::tree_node* ptr = static_cast<v8_wrapper::tree_node*>(wrap->Value());
    jsNavigator* el = dynamic_cast<jsNavigator*>(ptr);
    // Convert the JavaScript string to a std::string.
    std::string key = value_to_string(name);

    // Look up the value if it exists using the standard STL idiom.
    std::map< std::string, Persistent<Value> >::iterator iter = el->props.find(key);

    // If the key is not present return an empty handle as signal.
    if (iter == el->props.end()) return Handle<Value>();

    // Otherwise fetch the value and wrap it in a JavaScript string.
    Local<Value> val = Local<Value>::New(iter->second);
    return scope.Close(val);
}
コード例 #21
0
Handle<Value> Image::New(const Arguments& args)
{
    HandleScope scope;
    if (!args.IsConstructCall())
        return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));

    if (args[0]->IsExternal())
    {
        //std::clog << "external!\n";
        Local<External> ext = Local<External>::Cast(args[0]);
        void* ptr = ext->Value();
        Image* im =  static_cast<Image*>(ptr);
        im->Wrap(args.This());
        return args.This();
    }

    try
    {
        if (args.Length() == 2)
        {
            if (!args[0]->IsNumber() || !args[1]->IsNumber())
                return ThrowException(Exception::Error(
                                          String::New("Image 'width' and 'height' must be a integers")));
            Image* im = new Image(args[0]->IntegerValue(),args[1]->IntegerValue());
            im->Wrap(args.This());
            return args.This();
        }
        else
        {
            return ThrowException(Exception::Error(
                                      String::New("please provide Image width and height")));
        }
    }
    catch (std::exception const& ex)
    {
        return ThrowException(Exception::Error(
                                  String::New(ex.what())));
    }
    return Undefined();
}
コード例 #22
0
Handle<Value> Geometry::New(const Arguments& args)
{
    HandleScope scope;
    //if (!args.IsConstructCall())
    //    return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));

    if (args[0]->IsExternal())
    {
        //std::clog << "external!\n";
        Local<External> ext = Local<External>::Cast(args[0]);
        void* ptr = ext->Value();
        Geometry* g =  static_cast<Geometry*>(ptr);
        g->Wrap(args.This());
        return args.This();
    }
    else
    {
        return ThrowException(Exception::Error(
                                  String::New("a mapnik.Geometry cannot be created directly - rather you should create mapnik.Path objects which can contain one or more geometries")));
    }
    return args.This();
}
コード例 #23
0
Handle<Value> MSOutputFormat::New(const Arguments &args) {
  HandleScope scope;
  MSOutputFormat *obj;
  
  if (!args.IsConstructCall()) {
    return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));
  }

  if (args[0]->IsExternal()) {
    Local<External> ext = Local<External>::Cast(args[0]);
    void* ptr = ext->Value();
    obj = static_cast<MSOutputFormat*>(ptr);
    obj->Wrap(args.This());
    return args.This();
  }
  
  REQ_STR_ARG(0, driver);
  REQ_STR_ARG(1, name);
  
  outputFormatObj *format = msCreateDefaultOutputFormat(NULL, *driver, *name);

  /* in the case of unsupported formats, msCreateDefaultOutputFormat
     should return NULL */
  if (!format) {
    msSetError(MS_MISCERR, "Unsupported format driver: %s",
               "outputFormatObj()", *driver);
    return args.This();
  }

  msInitializeRendererVTable(format);

  /* Else, continue */
  format->refcount++;
  format->inmapfile = MS_TRUE;
  
  obj = new MSOutputFormat(format);
  obj->Wrap(args.This());
  return args.This();
}
コード例 #24
0
static void SetLocationHref(Local<String> name, Local<Value> val, const AccessorInfo& info)
{
    Local<Object> self = info.This();
    Local<Value> x = self->GetInternalField(0);
    Local<External> wrap = Local<External>::Cast(x);
    void* ptr = wrap->Value();

    jsLocation* url = static_cast<jsLocation*>(ptr);
    std::string log_info = "Location changed from '";
    if(url->url.is_valid()) {
        log_info += url->url.tostring();
    } else {
        log_info += "undefined";
    }
    log_info += "' to \n\thref: ";
    url->url.assign_with_referer(value_to_string(val), &url->url);
    if(url->url.is_valid()) {
        log_info += url->url.tostring();
    } else {
        log_info += "undefined";
    }
    append_results(log_info);
}
コード例 #25
0
static Handle<Value> LocationReplace(const v8::Arguments& args)
{
    Local<Object> self = args.Holder();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    void* ptr = wrap->Value();

    jsLocation* url = static_cast<jsLocation*>(ptr);
    if (url->win != NULL && args.Length() > 0) {
        url->url.assign_with_referer(value_to_string(args[0]), &url->url);
        url->win->history->push_back(url->url.tostring());
        url->win->load(url->url.tostring());
    } else {
        std::string log_info = "Location changed from '";
        if(url->url.is_valid()) {
            log_info += url->url.tostring();
        } else {
            log_info += "undefined";
        }
        log_info += "' to \n\thref: ";
        if (args.Length() > 0) {
            url->url.assign_with_referer(value_to_string(args[0]), &url->url);
            if(url->url.is_valid()) {
                log_info += url->url.tostring();
            } else {
                log_info += "undefined";
            }
        } else {
            if(url->url.is_valid()) {
                log_info += url->url.tostring();
            } else {
                log_info += "undefined";
            }
        }
        append_results(log_info);
    }
    return Handle<Value>();
}
コード例 #26
0
ファイル: gdal_point.cpp プロジェクト: jarped/node-gdal
Handle<Value> Point::New(const Arguments& args)
{
	HandleScope scope;
	Point *f;
	OGRPoint *geom;
	double x = 0, y = 0, z = 0;

	if (!args.IsConstructCall()) {
		return NODE_THROW("Cannot call constructor as function, you need to use 'new' keyword");
	}

	if (args[0]->IsExternal()) {
		Local<External> ext = Local<External>::Cast(args[0]);
		void* ptr = ext->Value();
		f = static_cast<Point *>(ptr);

	} else {
		NODE_ARG_DOUBLE_OPT(0, "x", x);
		NODE_ARG_DOUBLE_OPT(1, "y", y);
		NODE_ARG_DOUBLE_OPT(2, "z", z);

		if (args.Length() == 1) {
			return NODE_THROW("Point constructor must be given 0, 2, or 3 arguments");
		}

		if (args.Length() == 3) {
			geom = new OGRPoint(x, y, z);
		} else {
			geom = new OGRPoint(x, y);
		}

		f = new Point(geom);
	}

	f->Wrap(args.This());
	return args.This();
}
コード例 #27
0
static Handle<Value> stop(const Arguments& args)
{
	HandleScope scope;

	if (args.Length() != 2) {
	    ThrowException(Exception::TypeError(String::New("Wrong number of arguments")));
	    return scope.Close(Undefined());
	}

	pthread_mutex_lock(&suscribe_mutex);
	if ( !isSuscribed )
	{
		loop = uv_default_loop();
		uv_async_init(loop, &status_change_notifier, after);
		isSuscribed = false;
	}
	pthread_mutex_unlock(&suscribe_mutex);

	Baton *baton = new Baton();
	baton->errorStatus = NO_ERROR;

//ESPECIFICO *********
	baton->errorStatus = 0;

	baton->afterCallBack = &afterStopImpl;
	Local<Integer> nodeTorrentId = args[0]->ToInteger();
	baton->torrentId = nodeTorrentId->Value();

	//CALLBACK
	baton->callback = Persistent<Function>::New(Local<Function>::Cast(args[1]));
//ESPECIFICO *********

	pthread_create(&status_change_thread, NULL, stopImpl, (void *)baton);

	return scope.Close(True());
}
コード例 #28
0
ファイル: MongoJS.cpp プロジェクト: tanfulai/mongo
DBClientConnection * getConnection( const Arguments& args ){
    Local<External> c = External::Cast( *(args.This()->Get( CONN_STRING )) );
    DBClientConnection * conn = (DBClientConnection*)(c->Value());
    assert( conn );
    return conn;
}
コード例 #29
0
ファイル: MongoJS.cpp プロジェクト: tanfulai/mongo
mongo::DBClientCursor * getCursor( const Arguments& args ){
    Local<External> c = External::Cast( *(args.This()->Get( String::New( "cursor" ) ) ) );
    mongo::DBClientCursor * cursor = (mongo::DBClientCursor*)(c->Value());
    return cursor;
}
コード例 #30
0
Handle<Value> JSDatasource::New(const Arguments& args)
{
    if (!args.IsConstructCall())
        return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));

    if (args[0]->IsExternal())
    {
        //std::clog << "external!\n";
        Local<External> ext = Local<External>::Cast(args[0]);
        void* ptr = ext->Value();
        JSDatasource* d =  static_cast<JSDatasource*>(ptr);
        d->Wrap(args.This());
        return args.This();
    }
    
    if (!args.Length() == 2){
        return ThrowException(Exception::TypeError(
          String::New("two argument required: an object of key:value datasource options and a callback function for features")));
    }

    if (!args[0]->IsObject())
        return ThrowException(Exception::TypeError(
          String::New("Must provide an object, eg {extent: '-180,-90,180,90'}")));

    Local<Object> options = args[0]->ToObject();

    // function callback
    if (!args[args.Length()-1]->IsFunction())
        return ThrowException(Exception::TypeError(
                  String::New("last argument must be a callback function")));

    // TODO - maybe validate in js?

    bool bind=true;
    if (options->Has(String::New("bind")))
    {
        Local<Value> bind_opt = options->Get(String::New("bind"));
        if (!bind_opt->IsBoolean())
          return ThrowException(Exception::TypeError(
            String::New("'bind' must be a Boolean")));

        bind = bind_opt->BooleanValue();
    }

    mapnik::parameters params;
    params["type"] = "js";
    Local<Array> names = options->GetPropertyNames();
    uint32_t i = 0;
    uint32_t a_length = names->Length();
    while (i < a_length) {
        Local<Value> name = names->Get(i)->ToString();
        Local<Value> value = options->Get(name);
        params[TOSTR(name)] = TOSTR(value);
        i++;
    }

    mapnik::datasource_ptr ds;
    try
    {

        ds = mapnik::datasource_ptr(new js_datasource(params,bind,args[args.Length()-1]));
        
    }
    catch (const std::exception & ex)
    {
        return ThrowException(Exception::Error(
          String::New(ex.what())));
    }
    catch (...)
    {
        return ThrowException(Exception::Error(
          String::New("unknown exception happened, please file bug")));
    }
    if (ds)
    {
        JSDatasource* d = new JSDatasource();
        d->Wrap(args.This());
        d->ds_ptr_ = ds;
        return args.This();
    }

    return Undefined();
}