Пример #1
0
/**
 * @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);
}
Пример #2
0
void DBOperationHelper_NonVO(Handle<Object> spec, KeyOperation & op) {
  HandleScope scope;

  Local<Value> v;
  Local<Object> o;

  setKeysInOp(spec, op);
  
  v = spec->Get(HELPER_ROW_BUFFER);
  if(! v->IsNull()) {
    o = v->ToObject();
    op.row_buffer = V8BINDER_UNWRAP_BUFFER(o);
  }
  
  v = spec->Get(HELPER_ROW_RECORD);
  if(! v->IsNull()) {
    o = v->ToObject();
    const Record * record = unwrapPointer<const Record *>(o);
    op.row_record = record;

    v = spec->Get(HELPER_BLOBS);
    if(v->IsObject()) {
      if(op.opcode == 1) {
        createBlobReadHandles(v->ToObject(), record, op);
      } else {
        createBlobWriteHandles(v->ToObject(), record, op);
      }
    }
  }
  
  v = spec->Get(HELPER_LOCK_MODE);
  if(! v->IsNull()) {
    int intLockMode = v->Int32Value();
    op.lmode = static_cast<NdbOperation::LockMode>(intLockMode);
  }

  v = spec->Get(HELPER_COLUMN_MASK);
  if(! v->IsNull()) {
    Array *maskArray = Array::Cast(*v);
    for(unsigned int m = 0 ; m < maskArray->Length() ; m++) {
      Local<Value> colId = maskArray->Get(m);
      op.useColumn(colId->Int32Value());
    }
  }

  DEBUG_PRINT("Non-VO opcode: %d mask: %u", op.opcode, op.u.maskvalue);
}
Пример #3
0
static string get_env(Handle<Function> require) {
    HandleScope hs;
    Handle<Object> env = Handle<Object>::Cast(Context::GetCalling()->Global()->Get(String::New("_env")));
    if(env->IsUndefined()) return "/usr/lib/purple/js";
    String::Utf8Value cwd (env->Get(String::New("cwd")));
    cerr << "found cwd = " << *cwd << endl;
    return string(*cwd);
}
Пример #4
0
	//*]}//*
void loadComponent(cs::StringList& sl,LPCWSTR modeList,LPCWSTR component,Handle<Object>& glb,LPCWSTR checkName,LOADJSCOMPONENT loadc){
		if(strIsNull(modeList)||sl.IndexOf(component)!=-1){
			//检测此dll是否已经加载过了.
			Local<Value> vp = glb->Get(String::New((uint16_t*)checkName));
			if(vp->IsUndefined())
				loadc(glb);
		}
	}
Пример #5
0
void js2hash(Handle<Object> obj, hash& h){
	Handle<Array> hash1 = Handle<Array>::Cast(obj->Get(String::New("major_hash")));
	for (int i = 0; i < HASH1NUMBINS; i++)
		h.hist_major[i]= (float)hash1->Get(i)->ToNumber()->NumberValue();

	//Handle <Array> hash2 = Handle<Array>::Cast(obj->Get(String::New("minor_hash_which")));
	Handle <Array> hash3 = Handle<Array>::Cast(obj->Get(String::New("minor_hash")));
	for (int i = 0; i < NUMBINS; i++){
		//Handle<Array> a = Handle<Array>::Cast(hash2->Get(i));
		Handle<Array> b = Handle<Array>::Cast(hash3->Get(i));
		for (int j = 0; j < NUMMAX; j++){
			h.hist_minor[i][j] = std::pair<HASH2INTTYPE, HASH2INTBOXES>();
			//h.hist_minor[i][j].first = a->Get(j)->Uint32Value();
			h.hist_minor[i][j].second = b->Get(j)->Uint32Value();
		}
	}
}
Пример #6
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);
        }
    }
}
Пример #7
0
int ArrayConv::UserGetElement(JNIEnv *jniEnv, Handle<Object> val, unsigned int elementType, int idx, jobject *jVal) {
  HandleScope scope;
  TryCatch tryCatch;
  Handle<Value> vElement = val->Get(idx);
  if(vElement.IsEmpty()) return ErrorNotfound;
  if(tryCatch.HasCaught()) return ErrorJS;
  return conv->ToJavaObject(jniEnv, vElement, elementType, jVal);
}
Пример #8
0
static gboolean
gum_v8_flags_get (Handle<Object> flags,
                  const gchar * name,
                  GumV8Core * core)
{
  Local<String> key (String::NewFromUtf8 (core->isolate, name));
  return flags->Has (key) && flags->Get (key)->ToBoolean ()->BooleanValue ();
}
Пример #9
0
   Handle<Value> SCROpenWindow(const Arguments& args)
   {

      osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
      osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits(ds);

      traits->windowDecoration = true;
      traits->doubleBuffer = true;
      traits->sharedContext = 0;

      if(args.Length() > 1)
      {
         Handle<Object> traitsin = Handle<Object>::Cast(args[1]);
         if(traitsin->Has(String::New("x"))) traits->x = traitsin->Get(String::New("x"))->Int32Value();
         if(traitsin->Has(String::New("y"))) traits->y = traitsin->Get(String::New("y"))->Int32Value();
         if(traitsin->Has(String::New("width"))) traits->width = traitsin->Get(String::New("width"))->Int32Value();
         if(traitsin->Has(String::New("height"))) traits->height = traitsin->Get(String::New("height"))->Int32Value();
         if(traitsin->Has(String::New("windowDecoration"))) traits->windowDecoration = traitsin->Get(String::New("windowDecoration"))->BooleanValue();
         if(traitsin->Has(String::New("hostName"))) traits->hostName = ToStdString(traitsin->Get(String::New("hostName")));
         if(traitsin->Has(String::New("displayNum"))) traits->displayNum = traitsin->Get(String::New("displayNum"))->Int32Value();
         if(traitsin->Has(String::New("screenNum"))) traits->screenNum = traitsin->Get(String::New("screenNum"))->Int32Value();
         if(traitsin->Has(String::New("vsync"))) traits->vsync = traitsin->Get(String::New("vsync"))->BooleanValue();
      }

      
      unsigned int contextid;
      // TODO how to pass traits???
      //dtEntityOSG::OSGWindowInterface* wface = static_cast<dtEntityOSG::OSGWindowInterface*>(dtEntity::GetWindowInterface());
      //wface->SetTraits(traits);
      bool success = dtEntity::GetWindowInterface()->OpenWindow(ToStdString(args[0]), contextid);
      assert(success);
      return Uint32::New(contextid);
   }
Пример #10
0
   Handle<Value> SCRSetWindowGeometry(const Arguments& args)
   {
      if(args.Length() != 2)
      {
         return ThrowError("Usage: setWindowGeometry(contextId, array[x,y,w,h])");
      }
      unsigned int contextId = args[0]->Uint32Value();
      HandleScope scope;
      Handle<Array> arr = Handle<Array>::Cast(args[1]);
      int x = arr->Get(0)->Int32Value();
      int y = arr->Get(1)->Int32Value();
      int w = arr->Get(2)->Int32Value();
      int h = arr->Get(3)->Int32Value();

      dtEntity::GetWindowInterface()->SetWindowGeometry(contextId, x, y, w, h);

      return Undefined();
   }
Пример #11
0
void V8Templates::fillFieldState(Handle<Object> v8Obj, FieldState *obj)
{
	HandleScope scope;
	
	_ASSERT(!v8Obj.IsEmpty());

	v8Obj->SetInternalField(0, External::New(obj));
	fillBorderState(Handle<Object>::Cast(v8Obj->Get(String::New("bordersRaw"))), obj->getBorders());
}
Пример #12
0
void setKeysInOp(Handle<Object> spec, Operation & op) {
  HandleScope scope;

  Local<Value> v;
  Local<Object> o;

  v = spec->Get(HELPER_KEY_BUFFER);
  if(! v->IsNull()) {
    o = v->ToObject();
    op.key_buffer = V8BINDER_UNWRAP_BUFFER(o);
  }
  
  v = spec->Get(HELPER_KEY_RECORD);
  if(! v->IsNull()) {
    o = v->ToObject();
    op.key_record = unwrapPointer<const Record *>(o);
  }
}
Пример #13
0
int KeyOperation::createBlobWriteHandles(Handle<Object> blobsArray,
                                         const Record * rowRecord) {
  DEBUG_MARKER(UDEB_DEBUG);
  int ncreated = 0;
  int ncol = rowRecord->getNoOfColumns();
  for(int i = 0 ; i < ncol ; i++) {
    if(blobsArray->Get(i)->IsObject()) {
      Local<Object> blobValue = blobsArray->Get(i)->ToObject();
      assert(node::Buffer::HasInstance(blobValue));
      const NdbDictionary::Column * col = rowRecord->getColumn(i);
      assert( (col->getType() ==  NdbDictionary::Column::Blob) ||
              (col->getType() ==  NdbDictionary::Column::Text));
      ncreated++;
      setBlobHandler(new BlobWriteHandler(i, col->getColumnNo(), blobValue));
    }
  }
  return ncreated;
}
Пример #14
0
int ArrayConv::UserGetLength(JNIEnv *jniEnv, Handle<Object> val, int *length) {
  HandleScope scope;
  TryCatch tryCatch;
  Handle<Value> vLength = val->Get(sLength);
  if(vLength.IsEmpty()) return ErrorNotfound;
  if(tryCatch.HasCaught()) return ErrorJS;
  *length = (int)vLength->IntegerValue();
  return OK;
}
Пример #15
0
void Processor::initializeGlobalObject(Handle<Object> g) {
    g->Set(String::New("global"), g);
    Handle<Object> paths = Array::New();
    paths->Set(0, String::New("/usr/lib/purple/modules")); //TODO: move this to config
    Handle<Object>::Cast(g->Get(String::New("require")))->Set(String::New("paths"), paths);
    Handle<Object> env = Object::New();
    env->Set(String::New("cwd"), String::New(getCwd().c_str())); 
    g->Set(String::New("_env"), env);
}
Пример #16
0
bool
WeechatJsV8::functionExists(const char *function)
{
    Context::Scope context_scope(this->context);

    Handle<Object> global = this->context->Global();
    Handle<Value> value = global->Get(String::New(function));
    return value->IsFunction();
}
Пример #17
0
TaskOptions::TaskOptions(Handle<Object> source) :
    liveStreaming(NULL) {
  HandleScope scope;

  Local<Object> liveStreaming =
      Local<Object>::Cast(source->Get(String::New("liveStreaming")));
  if (!liveStreaming.IsEmpty() && liveStreaming->IsObject()) {
    this->liveStreaming = new LiveStreamingOptions(liveStreaming);
  }
}
void Ti::TiProxy::initWithObject(Handle<Object> obj)
{
	HandleScope scope;
	Local<Array> props = obj->GetPropertyNames();
	for(int i = 0, len = props->Length(); i < len; i++) {
		Local<String> key = props->Get(i)->ToString();
		Local<Value> val = obj->Get(key);
		_jsObject->Set(key, val);
	}
}
Пример #19
0
extern "C" void extractArray(Persistent<Context> context,
				       Handle<Array> array,
				       int length,
				       Handle<Value>* result) {
    HandleScope handle_scope;
    Context::Scope context_scope(context);
    for (int i = 0; i < length; i++) {
	result[i] = array->Get(i);
    }
}
Пример #20
0
void V8Util::reportException(TryCatch &tryCatch, bool showLine)
{
	HandleScope scope;
	Handle<Message> message = tryCatch.Message();

	if (nameSymbol.IsEmpty()) {
		nameSymbol = SYMBOL_LITERAL("name");
		messageSymbol = SYMBOL_LITERAL("message");
	}

	if (showLine) {
		Handle<Message> message = tryCatch.Message();
		if (!message.IsEmpty()) {
			String::Utf8Value filename(message->GetScriptResourceName());
			String::Utf8Value msg(message->Get());
			int linenum = message->GetLineNumber();
			LOGE(EXC_TAG, "Exception occurred at %s:%i: %s", *filename, linenum, *msg);
		}
	}

	Local<Value> stackTrace = tryCatch.StackTrace();
	String::Utf8Value trace(tryCatch.StackTrace());

	if (trace.length() > 0 && !stackTrace->IsUndefined()) {
		LOGD(EXC_TAG, *trace);
	} else {
		Local<Value> exception = tryCatch.Exception();
		if (exception->IsObject()) {
			Handle<Object> exceptionObj = exception->ToObject();
			Handle<Value> message = exceptionObj->Get(messageSymbol);
			Handle<Value> name = exceptionObj->Get(nameSymbol);

			if (!message->IsUndefined() && !name->IsUndefined()) {
				String::Utf8Value nameValue(name);
				String::Utf8Value messageValue(message);
				LOGE(EXC_TAG, "%s: %s", *nameValue, *messageValue);
			}
		} else {
			String::Utf8Value error(exception);
			LOGE(EXC_TAG, *error);
		}
	}
}
Пример #21
0
   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();
   }
Пример #22
0
static void logV8Exception(Handle<Message> msg, Handle<Value> data)
{
	HandleScope scope;

	// Log reason and location of the error.
	LOGD(TAG, *String::Utf8Value(msg->Get()));
	LOGD(TAG, "%s @ %d >>> %s",
		*String::Utf8Value(msg->GetScriptResourceName()),
		msg->GetLineNumber(),
		*String::Utf8Value(msg->GetSourceLine()));
}
Пример #23
0
void ScriptMatch::_calculateClassification(const ConstOsmMapPtr& map, Handle<Object> plugin)
{
  Context::Scope context_scope(_script->getContext());
  HandleScope handleScope;

  // removing these two lines causes a crash when checking for conflicts. WTF?
  Handle<Object> global = _script->getContext()->Global();
  global->Get(String::NewSymbol("plugin"));

  if (_plugin->Has(String::NewSymbol("isWholeGroup")))
  {
    Handle<Value> v = _script->call(_plugin, "isWholeGroup");
    _isWholeGroup = v->BooleanValue();
  }

  try
  {
    Handle<Value> v = _call(map, plugin);

    if (v.IsEmpty() || v->IsObject() == false)
    {
      throw IllegalArgumentException("Expected matchScore to return an associative array.");
    }

    QVariantMap vm = toCpp<QVariantMap>(v);
    // grab the match, miss, review results. If they aren't populated they get a value of 0.
    _p.setMatchP(_script->toNumber(v, "match", 0));
    _p.setMissP(_script->toNumber(v, "miss", 0));
    _p.setReviewP(_script->toNumber(v, "review", 0));

    _explainText = vm["explain"].toString();
    if (_explainText.isEmpty())
    {
      _explainText = _threshold->getTypeDetail(_p);
    }
    if (_threshold->getType(_p) == MatchType::Review)
    {
      if (_explainText.isEmpty())
      {
        throw IllegalArgumentException("If the match is a review an appropriate explanation must "
                                       "be provided (E.g. { 'review': 1, "
                                       "'explain': 'some reason' }.");
      }
    }
  }
  catch (NeedsReviewException& ex)
  {
    LOG_VAR(ex.getClassName());
    _p.setReview();
    _explainText = ex.getWhat();
  }

  _p.normalize();
}
Пример #24
0
int PDFDateDriver::GetIntValueFromDateFunction(Handle<Date> inDate, const char* inFunctionName)
{
    HandleScope scope;
    
    Handle<v8::Value> value = inDate->Get(String::New(inFunctionName));
    Handle<Function> func = Handle<Function>::Cast(value);
    Handle<Value> result;
    
    result = func->Call(inDate, 0, NULL);
    return result->ToNumber()->Int32Value();
}
Пример #25
0
static Local<Value> ConstructError(const char *name, Handle<String> message) {
  // XXX: this probably isn't correct in all cases
  Handle<Context> ctx = Context::GetCurrent();
  Handle<Object> global = ctx->Global();
  Handle<Value> ctor = global->Get(String::New(name));
  if (ctor.IsEmpty() || !ctor->IsFunction())
    return Local<Value>();
  Handle<Function> fn = ctor.As<Function>();
  Handle<Value> args[] = { Handle<Value>(message) };
  return Local<Value>::New(fn->NewInstance(1, args));
}
METHOD_RETURN_TYPE DocumentCopyingContextDriver::ReplaceSourceObjects(const ARGS_TYPE& args)
{
    // getting a dictionary mapping source to target object, translating to the C++ map...and on we go
	CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;

    DocumentCopyingContextDriver* copyingContextDriver = ObjectWrap::Unwrap<DocumentCopyingContextDriver>(args.This());
    
    if(!copyingContextDriver->CopyingContext)
    {
		THROW_EXCEPTION("copying context object not initialized, create using pdfWriter.createPDFCopyingContext or PDFWriter.createPDFCopyingContextForModifiedFile");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    if(args.Length() != 0 ||
       !args[0]->IsObject())
    {
 		THROW_EXCEPTION("Wrong arguments. provide 1 arugment, which is an object mapping source object ids to map to target object IDs");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    // create an object that will serve as the map
    ObjectIDTypeToObjectIDTypeMap resultMap;
    
    Handle<Object> anObject = args[0]->ToObject();
    
    Handle<Array> objectKeys = anObject->GetOwnPropertyNames();
    
    for(unsigned long i=0; i < objectKeys->Length(); ++i)
    {
        Handle<String> key  = objectKeys->Get(NEW_NUMBER(0))->ToString();
        Handle<Value> value = anObject->Get(key);
        
        resultMap.insert(ObjectIDTypeToObjectIDTypeMap::value_type(ObjectIDTypeObject(*String::Utf8Value(key)),value->ToNumber()->Uint32Value()));
        
    }
    
    copyingContextDriver->CopyingContext->ReplaceSourceObjects(resultMap);
    
    SET_FUNCTION_RETURN_VALUE(UNDEFINED);
}
Пример #27
0
geos::geom::Coordinate GeoJSONReader::getCoordinate(Handle<Value> value, bool acceptArrayOnly) {

    bool isArray = value->IsArray();

    if (acceptArrayOnly) {
        if (!isArray)
            throw "A coordinate must be an instance of Array";


    }
    else {
        if (
            !isArray
            && !value->IsNull()
            && !value->IsUndefined()
        )
            throw "A coordinate must be an instance of Array or null";


        if (!isArray)
            return geos::geom::Coordinate::getNull();
    }


    Handle<Array> array = Handle<Array>::Cast(value);
    uint32_t length = array->Length();
    if (length < 2)
        throw "A coordinate's length must be >= 2";


    geos::geom::Coordinate coord;

    coord.x = valueToDouble(array->Get(0));
    coord.y = valueToDouble(array->Get(1));
    if (length > 2) {
        coord.z = valueToDouble(array->Get(2));
    }
    precisionModel->makePrecise(&coord);

    return coord;
}
Пример #28
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.")));
        }
    }
}
Пример #29
0
std::string v8ScriptService::preCompileCode(const std::string &code, const boost::filesystem::path &filename) {
	HandleScope scope;

	std::string filenameString = filename.string();
	bool isCoffee = false;
	bool isLiterateCoffee = false;

	if (boost::regex_search(
		filenameString,
		regex(".*\\.coffee$")
	)) {
		isCoffee = true;
	}

	if (boost::regex_search(
		filenameString,
		regex(".*\\.litcoffee$")
	)) {
		isCoffee = true;
		isLiterateCoffee = true;
	}

	// Compile coffeescript to JS.
	if (isCoffee) {

		TryCatch exception;

		Handle<Object> CoffeeScript = Context::GetCurrent()->Global()->Get(String::New("CoffeeScript")).As<Object>();
		Handle<Function> compile = CoffeeScript->Get(String::New("compile")).As<Function>();

		Handle<Object> options = Object::New();
		options->Set(String::New("filename"), String::New(
			filenameString.c_str()
		));
		options->Set(String::New("literate"), Boolean::New(isLiterateCoffee));
		Handle<Value> args[] = {
			String::New(code.c_str()),
			options
		};

		Handle<Value> result = compile->Call(compile, 2, args);

		if (exception.HasCaught()) {
			throw script_precompilation_error(V8::stringifyException(exception, true));
		}

		return V8::stringToStdString(result->ToString());
	}
	else {

		return code;
	}
}
Пример #30
0
JNIEXPORT jobject JNICALL
Java_org_appcelerator_kroll_runtime_v8_V8Object_nativeGetProperty
	(JNIEnv *env, jobject object, jlong ptr, jstring name)
{
	ENTER_V8(V8Runtime::globalContext);
	titanium::JNIScope jniScope(env);

	Handle<Object> jsObject;
	if (ptr != 0) {
		jsObject = Persistent<Object>((Object *) ptr);
	} else {
		jsObject = TypeConverter::javaObjectToJsValue(env, object)->ToObject();
	}

	Handle<Object> properties = jsObject->Get(Proxy::propertiesSymbol)->ToObject();
	Handle<Value> jsName = TypeConverter::javaStringToJsString(env, name);

	Local<Value> jsValue = Local<Value>::New(jsObject->Get(jsName));
	bool isNew;
	return TypeConverter::jsValueToJavaObject(env, jsValue, &isNew);
}