Exemple #1
0
void prepare_import_results(Local<Value> returned_value, sass_context_wrapper* ctx_w) {
  NanScope();

  if (returned_value->IsArray()) {
    Handle<Array> array = Handle<Array>::Cast(returned_value);

    ctx_w->imports = sass_make_import_list(array->Length());

    for (size_t i = 0; i < array->Length(); ++i) {
      Local<Value> value = array->Get(i);

      if (!value->IsObject())
        continue;

      Local<Object> object = Local<Object>::Cast(value);
      char* path = create_string(object->Get(NanNew<String>("file")));
      char* contents = create_string(object->Get(NanNew<String>("contents")));

      ctx_w->imports[i] = sass_make_import_entry(path, (!contents || contents[0] == '\0') ? 0 : strdup(contents), 0);
    }
  }
  else if (returned_value->IsObject()) {
    ctx_w->imports = sass_make_import_list(1);
    Local<Object> object = Local<Object>::Cast(returned_value);
    char* path = create_string(object->Get(NanNew<String>("file")));
    char* contents = create_string(object->Get(NanNew<String>("contents")));

    ctx_w->imports[0] = sass_make_import_entry(path, (!contents || contents[0] == '\0') ? 0 : strdup(contents), 0);
  }
  else {
    ctx_w->imports = sass_make_import_list(1);
    ctx_w->imports[0] = sass_make_import_entry(ctx_w->file, 0, 0);
  }
}
Exemple #2
0
Handle<Value> ImgHash(const Arguments& args) {
	HandleScope scope;
	if (args.Length() < 1)
		return scope.Close(Undefined());
	if (args[0]->IsArray()){
		Handle<Array> arr = Local<Array>::Cast(args[0]);
		Handle<Array> output = Array::New(arr->Length());
		for (int i = 0; i < arr->Length(); i++){
			if (arr->Get(i)->IsString()){
				v8::String::Utf8Value str(arr->Get(i));
				char* file1 = *str;
				output->Set(i, hashImage(file1));
			}
			else
				output->Set(i, Undefined());
		}
		return scope.Close(output);
	}
	else if (args[0]->IsString()){
		v8::String::Utf8Value arg1(args[0]->ToString());
		char* file1 = *arg1;
		hash x;
		cv::Mat m1 = cv::imread(file1);
		if (!m1.data)
			return scope.Close(Undefined());
		imghash_algorithm(m1, x);

		Local<Object> obj = Object::New();
		hash2js(obj, x);
		return scope.Close(hashImage(file1));
	}
	return scope.Close(Undefined());
}
Exemple #3
0
geos::geom::Polygon* GeoJSONReader::getPolygon(Handle<Value> coords) {

    if (coords->IsArray()) {

        Handle<Array> array = Handle<Array>::Cast(coords);
        if (array->Length() == 0)
            throw "The number of the linear rings must be >= 1";


        geos::geom::LinearRing* shell = getLinearRing(array->Get(0));
        uint32_t length = array->Length();
        std::vector<geos::geom::Geometry*>* holes = new std::vector<geos::geom::Geometry*>();
        try {
            for (uint32_t i = 1; i < length; i++) {
                geos::geom::LinearRing* g = getLinearRing(array->Get(i));
                holes->push_back(g);
            }
        }
        catch (...) {
            delete shell;
            unsigned size = holes->size();
            for (unsigned int i = 0; i < size; i++)
                delete (*holes)[i];
            delete holes;
            throw;
        }


        return geometryFactory->createPolygon(shell, holes);
    }


    return geometryFactory->createPolygon();
}
Exemple #4
0
/*! Queues up an array to be sent to the sound card */
void Audio::AudioEngine::queueOutputBuffer( Handle<Array> result ) {
	// Reset our record of the number of cached output samples
	m_uNumCachedOutputSamples[m_uCurrentWriteBuffer] = 0;

	if( m_bInterleaved ) {
		for( int iSample=0; iSample<m_uSamplesPerBuffer*m_uOutputChannels; ++iSample )
			setSample( iSample, result->Get(iSample) );

		m_uNumCachedOutputSamples[m_uCurrentWriteBuffer] = result->Length()/m_uOutputChannels;

	} else {
		// Validate the structure of the output buffer array
		if( !result->Get(0)->IsArray() ) {
			NanThrowTypeError("Output buffer not properly setup, 0th channel is not an array");
			return;
		}

		Handle<Array> item;

		for( int iChannel=0; iChannel<m_uOutputChannels; ++iChannel ) {
			for( int iSample=0; iSample<m_uSamplesPerBuffer; ++iSample ) {

				item = Handle<Array>::Cast( result->Get(iChannel) );
				if( item->IsArray() ) {
					if( item->Length() > m_uNumCachedOutputSamples[m_uCurrentWriteBuffer] )
						m_uNumCachedOutputSamples[m_uCurrentWriteBuffer] = item->Length();

					setSample( iSample, item->Get(iSample) );
				}
			} // end for each sample
		} // end for each channel
	}
	m_uCurrentWriteBuffer = (m_uCurrentWriteBuffer + 1)%m_uNumBuffers;
} // end AudioEngine::queueOutputBuffer()
Exemple #5
0
int SerializePart(google::protobuf::Message *message, Handle<Object> subj) {
  Nan::HandleScope scope;
  // get a reflection
  const Reflection *r = message->GetReflection();
  const Descriptor *d = message->GetDescriptor();

  // build a list of required properties
  vector<string> required;
  for (int i = 0; i < d->field_count(); i++) {
    const FieldDescriptor *field = d->field(i);
    if (field->is_required())
      required.push_back(field->name());
  }

  // build a reflection
  // get properties of passed object
  Handle<Array> properties = subj->GetPropertyNames();
  uint32_t len = properties->Length();

  // check that all required properties are present
  for (uint32_t i = 0; i < required.size(); i++) {
    Handle<String> key = Nan::New<String>(required.at(i).c_str()).ToLocalChecked();
    if (!subj->Has(key))
      return -1;
  }

  for (uint32_t i = 0; i < len; i++) {
    Handle<Value> property = properties->Get(i);
    Handle<String> property_s = property->ToString();

    if (*property_s == NULL)
      continue;

    String::Utf8Value temp(property);
    std::string propertyName = std::string(*temp);

    const FieldDescriptor *field = d->FindFieldByName(propertyName);
    if (field == NULL) continue;

    Handle<Value> val = subj->Get(property);

    if (field->is_repeated()) {
      if (!val->IsArray())
        continue;

      Handle<Array> array = val.As<Array>();
      int len = array->Length();

      for (int i = 0; i < len; i++)
        SerializeField(message, r, field, array->Get(i));

    } else {
      SerializeField(message, r, field, val);
    }
  }

  return 0;
}
Exemple #6
0
//Accepts GL_UNSIGNED_SHORT and GL_FLOAT as types
//TODO(nico): deal with interleaved data
Handle<Value> GLESglBufferSubDataCallback(const Arguments& args) {
	if (args.Length() != 4)
		return v8::Undefined();

	unsigned int target  = args[0]->Uint32Value();
	unsigned int offset = args[1]->Uint32Value();
	unsigned int type  = args[3]->Uint32Value();

	void* ans;
	if(args[2]->IsArray()) {
		Handle<Array> data = Handle<Array>::Cast(args[2]);
		unsigned int len = data->Length();

		switch(type) {
			case GL_FLOAT:
			{
				GLfloat* arg1 = new  GLfloat[len];
				for (unsigned j = 0; j < data->Length(); j++) {
					Handle<Value> arg(data->Get(Integer::New(j)));
					arg1[j] = (GLfloat)arg->NumberValue();
				}
				ans = (void *)arg1;
			}
			break;

			case GL_UNSIGNED_SHORT:
			{
				GLushort* arg1 = new  GLushort[len];
				for (unsigned j = 0; j < data->Length(); j++) {
					Handle<Value> arg(data->Get(Integer::New(j)));
					arg1[j] = (GLushort)arg->Uint32Value();
				}
				ans = (void *)arg1;
			}
			break;

			default: return v8::Undefined();
		}

		glBufferSubData((GLenum)target,
			(GLintptr)offset,
			(GLsizeiptr)len,
			(const void*)ans);

		//should I delete[] ans?
	}

	Handle<Object> res(GlesFactory::self_);

	return res;
}
Exemple #7
0
geos::geom::MultiPolygon* GeoJSONReader::getMultiPolygon(Handle<Value> coords) {

    if (coords->IsArray()) {

        Handle<Array> array = Handle<Array>::Cast(coords);
        uint32_t length = array->Length();
        std::vector<geos::geom::Geometry*>* geoms = new std::vector<geos::geom::Geometry*>();
        try {
            for (uint32_t i = 0; i < length; i++) {
                geos::geom::Polygon* g = getPolygon(array->Get(i));
                geoms->push_back(g);
            }
        }
        catch (...) {
            unsigned size = geoms->size();
            for (unsigned int i = 0; i < size; i++)
                delete (*geoms)[i];
            delete geoms;
            throw;
        }


        return geometryFactory->createMultiPolygon(geoms);
    }


    return geometryFactory->createMultiPolygon();
}
Exemple #8
0
geos::geom::CoordinateSequence* GeoJSONReader::getCoordinates(Handle<Value> value) {

    if (!value->IsArray())
        throw "A coordinate sequence must be an instance of Array";


    Handle<Array> array = Handle<Array>::Cast(value);

    uint32_t length = array->Length();
    geos::geom::CoordinateSequence* sequence = coordinateSequenceFactory->create(length, 3);

    try {
        for (uint32_t i = 0; i < length; i++) {

            sequence->setAt(getCoordinate(array->Get(i)), (std::size_t)i);
        }
    }
    catch (...) {
        delete sequence;
        throw;
    }


    return sequence;
}
Exemple #9
0
Handle<Value> Dataset::setGeoTransform(const Arguments& args)
{
	Dataset *ds = ObjectWrap::Unwrap<Dataset>(args.This());
	if(!ds->this_) return NODE_THROW("Dataset object has already been destroyed");

	Handle<Array> transform;
	NODE_ARG_ARRAY(0, "transform", transform);

	if (transform->Length() != 6) {
		return NODE_THROW("Transform array must have 6 elements")
	}

	double buffer[6];
	for (int i = 0; i < 6; i++) {
		Local<Value> val = transform->Get(i);
		if (!val->IsNumber()) {
			return NODE_THROW("Transform array must only contain numbers");
		}
		buffer[i] = val->NumberValue();
	}

	CPLErr err = ds->this_->SetGeoTransform(buffer);
	if (err) return NODE_THROW_CPLERR(err);

	return Undefined();
}
/**
 * @function memcached.mget
 * 
 * ### Synopsis:
 * 
 * var o = memcache.get(handle, array_of_keys);
 * 
 * Get multiple values, identified by an array of keys, from memcached.
 * 
 * The returned object is a hash of returned values, indexed by the key.  
 * 
 * For each of these keys, the value is an object in the form described at the top of this page.
 * 
 * @param {object} handle - handle to memcached connection.
 * @param {array} keys - array of keys of data to get from memcached
 * @return {object} o - has of objects of the form described at top of the page, or false if an error occurred.
 */
JSVAL _memcached_mget (JSARGS args) {
    HandleScope scope;
    M* handle = HANDLE(args[0]);
    Handle<Array> aKeys = Handle<Array>::Cast(args[1]);
    int numKeys = aKeys->Length();
    char *keys[numKeys];
    size_t key_lengths[numKeys];
    for (int i = 0; i < numKeys; i++) {
        String::Utf8Value k(aKeys->Get(i));
        keys[i] = *k;
        key_lengths[i] = strlen(keys[i]);
    }
    R rc = memcached_mget(handle, keys, key_lengths, numKeys);
    if (rc != MEMCACHED_SUCCESS) {
        return String::New(memcached_strerror(handle, rc));
    }
    char return_key[MEMCACHED_MAX_KEY];
    size_t return_key_length;
    char *return_value;
    size_t return_value_length;
    uint32_t flags;
    JSOBJ result = Object::New();
    while ((return_value = memcached_fetch(handle, return_key, &return_key_length, &return_value_length, &flags, &rc))) {
        JSOBJ o = Object::New();
        o->Set(String::New("value"), String::New(return_value));
        o->Set(String::New("flags"), Integer::New(flags));
        o->Set(String::New("rc"), Integer::New(rc));
        free(return_value);
        result->Set(String::New(return_key), o);
    }
    return scope.Close(result);
}
Exemple #11
0
void league_table::read_league_table_file(Handle<Array> leagueDat)
{
    // The file doesn't have to exist (if it doesn't, a new table is
    // created). But if it exists, it must be in correct format
    //
    if (leagueDat->Length())
    {
        HandleScope scope;
        Handle<Array> tokens;
        for(int i=0, l=leagueDat->Length(); i<l; ++i)
        {
            tokens = Handle<Array>::Cast(leagueDat->Get(i));

            // The structure of a line must be:
            //
            // PLACE TEAMNAME+ PL W D L GF GA GD PTS
            //
            // TEAMNAME may be multiple tokens, so we count from the
            // end ! The first token is PLACE, the last 8 tokens are
            // as specified, and everything between the first and
            // the last 8 is the team name.
            //
            // Note: when the team name is restructured from the
            // tokens, each token is separated by one space
            //
            unsigned num_tokens = tokens->Length();

            if (num_tokens < 10)
                die("The following line in leaguedat has too few tokens%s");

            int points = tokens->Get(9)->IntegerValue();
            int goal_difference = tokens->Get(8)->IntegerValue();
            int goals_against = tokens->Get(7)->IntegerValue();
            int goals_for = tokens->Get(6)->IntegerValue();
            int lost = tokens->Get(5)->IntegerValue();
            int drawn = tokens->Get(4)->IntegerValue();
            int won = tokens->Get(3)->IntegerValue();
            int played = tokens->Get(2)->IntegerValue();
            char name[64];
            toAscii(tokens->Get(1)->ToString(), name);

            add_new_team(string(name), played, won, drawn, lost, goals_for, goals_against,
                         goal_difference, points);
        }
    }
}
Exemple #12
0
/*
 * call-seq:
 *   ary.push(value)  => value
 *   ary << value     => value
 *
 * Appends given value to referenced array.
 *
 */
static VALUE rb_v8_array_push(VALUE self, VALUE value)
{
  HandleScope scope;
  Handle<Value> _value = to_v8(value);
  Handle<Array> ary = unwrap(self);
  ary->Set(ary->Length(), _value);  
  return to_ruby(_value);
}
Exemple #13
0
void CustomExternalStringResource::writeTo(Handle<String> str, MDB_val *val) {
    unsigned int l = str->Length() + 1;
    uint16_t *d = new uint16_t[l];
    str->Write(d);
    d[l - 1] = 0;

    val->mv_data = d;
    val->mv_size = l * sizeof(uint16_t);
}
   Handle<Value> DebugDrawManagerAddLines(const Arguments& args)
   {
      dtEntity::DebugDrawInterface* ddm = dtEntity::GetDebugDrawInterface();

      if(!ddm->IsEnabled() )
      {
         return Undefined();
      }

      if(args.Length() < 1 || !args[0]->IsArray())
      {
         return ThrowError("usage: addLines(Array(Vec3) lines,[Vec4 color, Int lineWidth, Number duration, bool useDepthTest])");
      }

      std::vector<dtEntity::Vec3f> lines;
      HandleScope scope;
      Handle<Array> arr = Handle<Array>::Cast(args[0]);
      
      unsigned int l = arr->Length();
      for(unsigned int i = 0; i < l; ++i)
      {
         lines.push_back(UnwrapVec3(arr->Get(i)));
      }
      
      dtEntity::Vec4f color(1,0,0,1);
      if(args.Length() > 1 && IsVec4(args[1]))
      {
         color = UnwrapVec4(args[1]);
      }

      int linewidth = 1;
      if(args.Length() > 2)
      {
         linewidth = args[2]->Int32Value();
         if(linewidth == 0) 
         {
            linewidth = 1;
         }
      }

      float duration = 0;
      if(args.Length() > 3)
      {
         duration = args[3]->NumberValue();
      }

      bool depth = true;
      if(args.Length() > 4)
      {
         depth = args[4]->BooleanValue();
      }

      ddm->AddLines(lines, color, linewidth, duration, depth);
      return Undefined();
   }
Exemple #15
0
void V8Util::objectExtend(Handle<Object> dest, Handle<Object> src)
{
	Handle<Array> names = src->GetOwnPropertyNames();
	int length = names->Length();

	for (int i = 0; i < length; ++i) {
		Handle<Value> name = names->Get(i);
		Handle<Value> value = src->Get(name);
		dest->Set(name, value);
	}
}
Handle<Value> TiUITabGroup::_getTabs(void* userContext)
{
	TiUITabGroup* obj = (TiUITabGroup*) userContext;
    Handle<Array> array = Array::New();

    for(int i = 0, len = obj->allTabs_.length(); i < len; i++) {
    	array->Set(array->Length(), obj->allTabs_.at(i));
    }

    return array;
}
Exemple #17
0
static void setUpstreams(getdns_context* context, Handle<Value> opt) {
    if (opt->IsArray()) {
        getdns_list* upstreams = getdns_list_create();
        Handle<Array> values = Handle<Array>::Cast(opt);
        for (uint32_t i = 0; i < values->Length(); ++i) {
            Local<Value> ipOrTuple = values->Get(i);
            getdns_dict* ipDict = NULL;
            if (ipOrTuple->IsArray()) {
                // two tuple - first is IP, 2nd is port
                Handle<Array> tuple = Handle<Array>::Cast(ipOrTuple);
                if (tuple->Length() > 0) {
                    String::AsciiValue asciiStr(tuple->Get(0)->ToString());
                    ipDict = getdns_util_create_ip(*asciiStr);
                    if (ipDict && tuple->Length() > 1 &&
                        tuple->Get(1)->IsNumber()) {
                        // port
                        uint32_t port = tuple->Get(1)->Uint32Value();
                        getdns_dict_set_int(ipDict, "port", port);
                    }
                }
            } else {
                String::AsciiValue asciiStr(ipOrTuple->ToString());
                ipDict = getdns_util_create_ip(*asciiStr);
            }
            if (ipDict) {
                size_t len = 0;
                getdns_list_get_length(upstreams, &len);
                getdns_list_set_dict(upstreams, len, ipDict);
                getdns_dict_destroy(ipDict);
            } else {
                Local<String> msg = String::Concat(String::New("Upstream value is invalid: "), ipOrTuple->ToString());
                ThrowException(Exception::TypeError(msg));
            }
        }
        getdns_return_t r = getdns_context_set_upstream_recursive_servers(context, upstreams);
        getdns_list_destroy(upstreams);
        if (r != GETDNS_RETURN_GOOD) {
            ThrowException(Exception::TypeError(String::New("Failed to set upstreams.")));
        }
    }
}
Exemple #18
0
Handle<Value> GLESglDrawElementsCallback(const Arguments& args) {
  if (args.Length() != 4)
    return v8::Undefined();

  HandleScope handle_scope;
  unsigned int mode  = args[0]->Uint32Value();
  int count = args[1]->IntegerValue();
  unsigned int type  = args[2]->Uint32Value();
  void* ans;

  if(args[3]->IsArray()) {
	  Handle<Array> data = Handle<Array>::Cast(args[3]);
	  switch(type) {
		  case GL_UNSIGNED_SHORT:
		  {
			  GLushort* arg1 = new  GLushort[data->Length()];
			  for (unsigned j = 0; j < data->Length(); j++) {
			      Handle<Value> arg(data->Get(Integer::New(j)));
			      arg1[j] = (GLushort)arg->Uint32Value();
			  }
			  ans = (void *)arg1;
		  }
		  break;

		  default: return v8::Undefined();
	  }
  } else {
	  ans = (void *)args[3]->IntegerValue();
  }

  glDrawElements((GLenum)mode,
		  (GLsizei)count,
		  (GLenum)type,
		  (const GLvoid*)ans);

  //should I delete[] ans?

  Handle<Object> res(GlesFactory::self_);
  return res;
}
Exemple #19
0
/* This function takes care of the penalties taken 
*/
void TakePenalty(Handle<Array> commentary, int nTeam, int nPenaltyNum)
{
    commentary->Set(commentary->Length(), String::New(the_commentary().rand_comment("PENALTY", PenaltyTaker[nTeam][nPenaltyNum].name).c_str()));

    /* checking if a goal was scored */
    if (randomp(8000 + PenaltyTaker[nTeam][nPenaltyNum].sh*100 - team[!nTeam].player[team[!nTeam].current_gk].st*100))
    {
    commentary->Set(commentary->Length(), String::New(the_commentary().rand_comment("GOAL").c_str()));

	PenScore[nTeam]++;
	sprintf(buf, "\n          ...  %s %d-%d %s...", team[0].name, PenScore[0], PenScore[1],  team[1].name);
    }
    else
    {
	int rnd = my_random(10);
	if (rnd < 5)
	    sprintf(buf, "%s", the_commentary().rand_comment("SAVE", team[!nTeam].player[team[!nTeam].current_gk].name).c_str());
	else
	    sprintf(buf, "%s", the_commentary().rand_comment("OFFTARGET", team[!nTeam].player[team[!nTeam].current_gk].name).c_str());
    }
    commentary->Set(commentary->Length(), String::New(buf));
}
QByteArray TiObject::getByteArrayFromValue(Handle<Value> value)
{
	if (value->IsArray()) {
		Handle<Array> array = Handle<Array>::Cast(value);
		int length = array->Length();
		QByteArray result = QByteArray(length, 0);
		char *data = result.data();
		for (int index = 0; index < length; ++index) {
			data[index] = Handle<Number>::Cast(array->Get(index))->Value();
		}
		return result;
	}
	return QByteArray();
}
/*
   DESCRIPTION
     Processing of Binds Array

   PARAMETERS:
     Handle Array, eBaton struct

   NOTES:
     Overloaded function
*/
void Connection::GetBinds (Handle<Array> binds, eBaton* executeBaton)
{
  HandleScope scope;

  for(unsigned int index = 0; index < binds->Length(); index++)
  {
    Bind* bind = new Bind;
    Local<Value> val__ = binds->Get(index);
    GetBindUnit(val__, bind, executeBaton);
    if(!executeBaton->error.empty()) goto exitGetBinds;
  }
  exitGetBinds:
  ;
}
Exemple #22
0
//Accepts GL_UNSIGNED_SHORT and GL_FLOAT as types
//TODO(nico): deal with interleaved data
Handle<Value> GLESglBufferDataCallback(const Arguments& args) {
	if (args.Length() != 4 || !args[1]->IsArray())
		return v8::Undefined();

	unsigned int target  = args[0]->Uint32Value();
	unsigned int type = args[2]->Uint32Value();
	unsigned int usage  = args[3]->Uint32Value();
	Handle<Array> data = Handle<Array>::Cast(args[1]);
	unsigned int len = data->Length();

	switch(type) {
		case GL_FLOAT: {
			GLfloat* arg1 = new GLfloat[len];
			
			for (unsigned j = 0; j < len; j++) {
				Handle<Value> arg(data->Get(Integer::New(j)));
				arg1[j] = (GLfloat)arg->NumberValue();
			}
			
			glBufferData((GLenum)target,
				(GLsizeiptr)(len * sizeof(*arg1)),
				(const void*)arg1,
				(GLenum)usage);
				
			delete[] arg1;
		}
		break;
		
		case GL_UNSIGNED_SHORT: {
			GLushort* arg1 = new GLushort[len];
			
			for (unsigned j = 0; j < len; j++) {
				Handle<Value> arg(data->Get(Integer::New(j)));
				arg1[j] = (GLushort)arg->Uint32Value();
			}
			
			glBufferData((GLenum)target,
				(GLsizeiptr)(len * sizeof(*arg1)),
				(const void*)arg1,
				(GLenum)usage);
				
			delete[] arg1;
		}
	}

	Handle<Object> res(GlesFactory::self_);

	return res;
}
Exemple #23
0
void
test_Length()
{
  HandleScope handle_scope;
  Persistent<Context> context = Context::New();
  Context::Scope context_scope(context);

  char TEST_STRING[] = "this is a test";
  int TEST_LENGTH = strlen(TEST_STRING);
  Handle<String> str = String::New(TEST_STRING);
  do_check_eq(str->Length(), TEST_LENGTH);

  // Now, make a string with an embedded NULL.
  TEST_STRING[8] = '\0';
  str = String::New(TEST_STRING, TEST_LENGTH);
  do_check_eq(str->Length(), TEST_LENGTH);

  // Finally, make sure that we end up calling strlen if no length is passed.
  str = String::New(TEST_STRING);

  int strlength = strlen(TEST_STRING);
  do_check_eq(str->Length(), strlength);
  context.Dispose();
}
Exemple #24
0
Handle<Value> Dataset::setGCPs(const Arguments& args)
{
	Dataset *ds = ObjectWrap::Unwrap<Dataset>(args.This());
	if(!ds->this_) return NODE_THROW("Dataset object has already been destroyed");

	Handle<Array> gcps;
	std::string projection("");
	NODE_ARG_ARRAY(0, "gcps", gcps);
	NODE_ARG_OPT_STR(1, "projection", projection);

	GDAL_GCP* list = new GDAL_GCP [gcps->Length()];
	GDAL_GCP* gcp = list;
	for (unsigned int i = 0; i < gcps->Length(); ++i) {
		Local<Value> val = gcps->Get(i);
		if (!val->IsObject()) {
			return NODE_THROW("list of GCPs must only contain objects");
		}
		Local<Object> obj = val->ToObject();

		NODE_STR_FROM_OBJ_OPT(obj, "pszId", gcp->pszId);
		NODE_STR_FROM_OBJ_OPT(obj, "pszInfo", gcp->pszInfo);
		NODE_DOUBLE_FROM_OBJ(obj, "dfGCPPixel", gcp->dfGCPPixel);
		NODE_DOUBLE_FROM_OBJ(obj, "dfGCPLine", gcp->dfGCPLine);
		NODE_DOUBLE_FROM_OBJ(obj, "dfGCPX", gcp->dfGCPX);
		NODE_DOUBLE_FROM_OBJ(obj, "dfGCPY", gcp->dfGCPY);
		NODE_DOUBLE_FROM_OBJ_OPT(obj, "dfGCPZ", gcp->dfGCPZ);
		gcp++;
	}

	if (list) delete [] list;

	CPLErr err = ds->this_->SetGCPs(gcps->Length(), list, projection.c_str());
	if(err) return NODE_THROW_CPLERR(err);

	return Undefined();
}
Exemple #25
0
int Conv::ToJavaString(JNIEnv *jniEnv, Handle<String> val, jstring *jVal) {
  int len = val->Length();
  jchar *buf = new jchar[len];
  if(!buf) return ErrorMem;
  val->Write(buf, 0, len, v8::String::NO_NULL_TERMINATION);
  jstring ob = jniEnv->NewString(buf, len);
  delete[] buf;
  if(ob) {
    *jVal = ob;
    return OK;
  }
  if(jniEnv->ExceptionCheck())
    jniEnv->ExceptionClear();
  return ErrorVM;
}
Exemple #26
0
void
test_AsciiValue_length()
{
  HandleScope handle_scope;
  Persistent<Context> context = Context::New();
  Context::Scope context_scope(context);

  char TEST_STRING[] = "toString";
  int TEST_LENGTH = strlen(TEST_STRING);
  Handle<String> str = String::New(TEST_STRING);
  do_check_eq(str->Length(), TEST_LENGTH);
  String::AsciiValue k(str);
  do_check_eq(k.length(), TEST_LENGTH);
  context.Dispose();
}
Exemple #27
0
Type* Protobuf::GetType(const Descriptor* descriptor) {
	TypeMap::iterator it = mTypeMap.find(descriptor);
	if (it != mTypeMap.end())
		return it->second;
	Type* result = mTypeMap[descriptor] = 
		new Type(this,
		factory.GetPrototype(descriptor)->New(),
		TypeTemplate->GetFunction()->NewInstance(),
		handles.size());
	handles.push_back(result);

    Handle<Array> types = handle_->GetInternalField(1).As<Array>();
    types->Set(types->Length(), result->handle_);
	return result;
}
Exemple #28
0
void
test_Utf8Value_length()
{
  HandleScope handle_scope;
  Persistent<Context> context = Context::New();
  Context::Scope context_scope(context);

  char TEST_STRING[] = "this is a UTF-8 test!  This is pi: π";
  int TEST_LENGTH = strlen(TEST_STRING);
  Handle<String> str = String::New(TEST_STRING);
  do_check_eq(str->Length(), TEST_LENGTH - 1);
  String::Utf8Value k(str);
  do_check_eq(k.length(), TEST_LENGTH);
  do_check_true(0 == strcmp(TEST_STRING, *k));
  context.Dispose();
}
Exemple #29
0
/* Returns a compiled javascript script. */
static Handle<Script> msV8CompileScript(Handle<String> source, Handle<String> script_name)
{
  TryCatch try_catch;

  if (source.IsEmpty() || source->Length() == 0) {
    msV8ReportException(NULL, "No source to compile");
    return Handle<Script>();
  }

  Handle<Script> script = Script::Compile(source, script_name);
  if (script.IsEmpty() && try_catch.HasCaught()) {
    msV8ReportException(&try_catch);
  }

  return script;
}
Exemple #30
0
void
test_PartialWriteAscii() {
  HandleScope handle_scope;
  Persistent<Context> context = Context::New();
  Context::Scope context_scope(context);

  char TEST_STRING[] = "toString";
  int TEST_LENGTH = strlen(TEST_STRING);
  Handle<String> str = String::New(TEST_STRING);
  do_check_eq(str->Length(), TEST_LENGTH);
  char buffer[] = "hag";
  int written = str->WriteAscii(buffer, 0, 1);
  do_check_eq(strlen(buffer), 3);
  do_check_eq(strcmp(buffer, "tag"), 0);
  context.Dispose();
}