Ejemplo n.º 1
0
Handle<Value> js_haptics_vibrate(const Arguments &args) {
	Handle<Object> opts = Handle<Object>::Cast(args[0]);
	Handle<Value> milliseconds = opts->Get(STRING_CACHE_milliseconds);

	if ( milliseconds->IsUndefined() ) {
	
		Handle<Object> pattern = Handle<Array>::Cast( opts->Get(STRING_CACHE_pattern) );
		int repeat = opts->Get(STRING_CACHE_repeat)->Int32Value();

		int patternLen = pattern->Get(STRING_CACHE_length)->Int32Value();
		long long* patternArr = (long long*)malloc(sizeof(long long) * patternLen);
	
		for ( int i = 0; i < patternLen; i++ ) {	
			patternArr[i] = pattern->Get(Number::New(i))->IntegerValue();
		}
		
		haptics_vibrate(patternArr, repeat, patternLen);

		free(patternArr);
	
	} else {

		haptics_vibrate(milliseconds->IntegerValue());	
	
	}

	return Undefined();
}
void printV8Value(Handle<Value> value, bool force=false)
{
    Logging::Level level = force ? Logging::ERROR : Logging::INFO;

    if (!Logging::shouldShow(level)) return;

    HandleScope handleScope;

    if (value.IsEmpty())
        Logging::log(level, "Empty handle\r\n");
    else if (value->IsInt32())
        Logging::log(level, "INT: %d\r\n", value->IntegerValue());
    else if (value->IsNull())
        Logging::log(level, "NULL (null)\r\n");
    else if (value->IsUndefined())
        Logging::log(level, "VOID (undefined)\r\n");
    else if (value->IsBoolean())
        Logging::log(level, "BOOLEAN: %d\r\n", value->BooleanValue());
    else if (value->IsNumber())
        Logging::log(level, "NUMBER: %f\r\n", value->NumberValue());
    else if (value->IsString())
        Logging::log(level, "STRING: ?\r\n");
    else if (value->IsObject())
        Logging::log(level, "OBJECT (object)\r\n");
    else
        Logging::log(level, "Uncertain V8 value\n");
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
0
Handle<Object> XML::GetChild(const Arguments& args) {
	HandleScope scope;
	Shell *shell = Shell::Instance();
	Context::Scope context_scope(shell->globalContext);		
	Handle<Value> arg = args[0];
	int64_t index = arg->IntegerValue();
	XMLElement *childElement = (XMLElement *)getChild(index);
	Handle<Object> newObject = childElement->registerObject();
	return(scope.Close(newObject));
}
Ejemplo n.º 5
0
Handle<Value> LayerFields::reorder(const Arguments& args)
{
	HandleScope scope;

	Handle<Object> parent = args.This()->GetHiddenValue(String::NewSymbol("parent_"))->ToObject();
	Layer *layer = ObjectWrap::Unwrap<Layer>(parent);
	if (!layer->get()) {
		return NODE_THROW("Layer object already destroyed");
	}

	OGRFeatureDefn *def = layer->get()->GetLayerDefn();
	if (!def) {
		return NODE_THROW("Layer has no layer definition set");
	}

	Handle<Array> field_map = Array::New(0);
	NODE_ARG_ARRAY(0, "field map", field_map);

	int n = def->GetFieldCount();
	OGRErr err = 0;

	if ((int)field_map->Length() != n) {
		return NODE_THROW("Array length must match field count");
	}

	int *field_map_array = new int[n];

	for (int i = 0; i < n; i++) {
		Handle<Value> val = field_map->Get(i);
		if (!val->IsNumber()) {
			delete [] field_map_array;
			return NODE_THROW("Array must only contain integers");
		}

		int key = val->IntegerValue();
		if (key < 0 || key >= n) {
			delete [] field_map_array;
			return NODE_THROW("Values must be between 0 and field count - 1");
		}

		field_map_array[i] = key;
	}

	err = layer->get()->ReorderFields(field_map_array);

	delete [] field_map_array;

	if (err) {
		return NODE_THROW_OGRERR(err);
	}
	return Undefined();
}
Ejemplo n.º 6
0
int Conv::ToJavaString(JNIEnv *jniEnv, Handle<Value> val, jstring *jVal) {
  Handle<String> vString;
  Handle<Value> empty, vRes;
  jstring ob;
  char buf[64];
  switch(GetNaturalType(val)) {
    default: {
      if(val->IsObject()) {
        /* call ToString() in javascript */
        Handle<Object> oVal = val->ToObject();
        Handle<Value> vToString = oVal->Get(sToString);
        if(!vToString.IsEmpty() && vToString->IsFunction()) {
          Handle<Function> fToString = Handle<Function>::Cast(vToString);
          vRes = fToString->CallAsFunction(oVal, 0, &empty);
          if(!vRes.IsEmpty() && (vRes->IsString() || vRes->IsStringObject())) {
            return ToJavaString(jniEnv, vRes->ToString(), jVal);
          }
        }
      }
      return ErrorType;
    }
    case TYPE_UNDEFINED:
    case TYPE_NULL:
      *jVal = 0;
      return OK;
    case TYPE_BOOL:
      return ToJavaString(jniEnv, (val->BooleanValue() ? "true" : "false"), jVal);
    case TYPE_INT:
      sprintf(buf, "%d", val->Int32Value());
      return ToJavaString(jniEnv, buf, jVal);
    case TYPE_LONG:
      sprintf(buf, "%lld", val->IntegerValue());
      return ToJavaString(jniEnv, buf, jVal);
    case TYPE_DOUBLE:
      sprintf(buf, "%g", val->NumberValue());
      return ToJavaString(jniEnv, buf, jVal);
    case TYPE_STRING:
      return ToJavaString(jniEnv, val->ToString(), (jstring *)jVal);
  }
  if(ob) {
    *jVal = ob;
    return OK;
  }
  if(jniEnv->ExceptionCheck())
    jniEnv->ExceptionClear();
  return ErrorVM;
}
int NativeAbstractTextControlObject::setTextAlign(TiObject* obj)
{
    Handle<Value> value = obj->getValue();
    int alignment;

    if (!value->IsNumber()) {
        QString s = V8ValueToQString(value);
        if (s == "left") {
            alignment = Ti::UI::TEXT_ALIGNMENT_LEFT;
        } else if (s == "center") {
            alignment = Ti::UI::TEXT_ALIGNMENT_CENTER;
        } else if (s == "right") {
            alignment = Ti::UI::TEXT_ALIGNMENT_RIGHT;
        } else {
            return NATIVE_ERROR_INVALID_ARG;
        }
    } else {
        alignment = value->IntegerValue();
    }

    switch (alignment)
    {
    case Ti::UI::TEXT_ALIGNMENT_LEFT:
        textControl_->textStyle()->setTextAlign(bb::cascades::TextAlign::Left);
        break;
    case Ti::UI::TEXT_ALIGNMENT_CENTER:
        textControl_->textStyle()->setTextAlign(bb::cascades::TextAlign::Center);
        break;
    case Ti::UI::TEXT_ALIGNMENT_RIGHT:
        textControl_->textStyle()->setTextAlign(bb::cascades::TextAlign::Right);
        break;
    default:
        return NATIVE_ERROR_INVALID_ARG;
    }

    return NATIVE_ERROR_OK;
}
Ejemplo n.º 8
0
int Conv::ToJavaObject(JNIEnv *jniEnv, Handle<Value> val, int expectedType, jobject *jVal) {

  /* empty, null and undefined convert to null for any nullable type */
  if((expectedType >= TYPE__OB_START) && (val.IsEmpty() || val->IsNull() || val->IsUndefined())) {
    *jVal = 0;
    return OK;
  }

  if(isSequence(expectedType))
    return ToJavaSequence(jniEnv, val, getComponentType(expectedType), (jarray *)jVal);
  
  if(isArray(expectedType))
    return arrayConv->ToJavaArray(jniEnv, val, getComponentType(expectedType), jVal);
  
  if(isMap(expectedType))
    return ToJavaMap(jniEnv, val, getComponentType(expectedType), jVal);
  
  if(isInterface(expectedType))
    return ToJavaInterface(jniEnv, val, getClassId(expectedType), jVal);
  
  if(isDict(expectedType))
    return ToJavaDict(jniEnv, val, getClassId(expectedType), jVal);
  
  HandleScope scope;
  jobject ob;
  switch(expectedType) {
    default:
      return ErrorType;
    case TYPE_BOOL: {
      bool isVoid = val.IsEmpty() ? false : val->BooleanValue();
      ob = jniEnv->CallStaticObjectMethod(jni.anode.js.JSValue_Bool.class_, jni.anode.js.JSValue_Bool.ctor, isVoid);
      break;
    }
    case TYPE_BYTE:
    case TYPE_INT: {
      jint intValue = val.IsEmpty() ? 0 : val->Int32Value();
      ob = jniEnv->CallStaticObjectMethod(jni.anode.js.JSValue_Long.class_, jni.anode.js.JSValue_Long.ctor, (jlong)intValue);
      break;
    }
    case TYPE_LONG: {
      jlong longValue = val.IsEmpty() ? 0 : val->IntegerValue();
      ob = jniEnv->CallStaticObjectMethod(jni.anode.js.JSValue_Long.class_, jni.anode.js.JSValue_Long.ctor, longValue);
      break;
    }
    case TYPE_DOUBLE: {
      jdouble doubleValue = val.IsEmpty() ? 0 : val->NumberValue();
      ob = jniEnv->CallStaticObjectMethod(jni.anode.js.JSValue_Double.class_, jni.anode.js.JSValue_Double.ctor, doubleValue);
      break;
    }
    case TYPE_STRING:
      return ToJavaString(jniEnv, val, (jstring *)jVal);
    case TYPE_DATE:
      return ToJavaDate(jniEnv, val, jVal);
    case TYPE_OBJECT:
      return ToNaturalJavaObject(jniEnv, val, jVal);
    case TYPE_OBJECT|TYPE_BOOL: {
      bool isVoid = val->BooleanValue();
      ob = jniEnv->NewObject(jni.java.lang.Boolean.class_, jni.java.lang.Boolean.ctor, isVoid);
      break;
    }
    case TYPE_OBJECT|TYPE_BYTE: {
      jbyte byteValue = val->Int32Value();
      ob = jniEnv->NewObject(jni.java.lang.Byte.class_, jni.java.lang.Byte.ctor, byteValue);
      break;
    }
    case TYPE_OBJECT|TYPE_INT: {
      jint intValue = val->Int32Value();
      ob = jniEnv->NewObject(jni.java.lang.Integer.class_, jni.java.lang.Integer.ctor, intValue);
      break;
    }
    case TYPE_OBJECT|TYPE_LONG: {
      jlong longValue = val->IntegerValue();
      ob = jniEnv->NewObject(jni.java.lang.Long.class_, jni.java.lang.Long.ctor, longValue);
      break;
    }
    case TYPE_OBJECT|TYPE_DOUBLE: {
      jdouble doubleValue = val->NumberValue();
      ob = jniEnv->NewObject(jni.java.lang.Double.class_, jni.java.lang.Double.ctor, doubleValue);
      break;
    }
  }
  if(ob) {
    *jVal = ob;
    return OK;
  }
  if(jniEnv->ExceptionCheck())
    jniEnv->ExceptionClear();
  return ErrorVM;
}
Ejemplo n.º 9
0
int Conv::ToNaturalJavaObject(JNIEnv *jniEnv, Handle<Value> val, jobject *jVal) {
  HandleScope scope;
  jobject ob = 0;
  int result = 0;
  switch(GetNaturalType(val)) {
    default:
      return ErrorInvalid;
    case TYPE_UNDEFINED:
    case TYPE_NULL:
      *jVal = 0;
      return OK;
    case TYPE_BOOL:
      ob = jniEnv->NewObject(jni.java.lang.Boolean.class_, jni.java.lang.Boolean.ctor, val->BooleanValue());
      break;
    case TYPE_INT:
      ob = jniEnv->NewObject(jni.java.lang.Integer.class_, jni.java.lang.Integer.ctor, (jint)val->IntegerValue());
      break;
    case TYPE_LONG:
      ob = jniEnv->NewObject(jni.java.lang.Long.class_, jni.java.lang.Long.ctor, val->IntegerValue());
      break;
    case TYPE_DOUBLE:
      ob = jniEnv->NewObject(jni.java.lang.Double.class_, jni.java.lang.Double.ctor, val->NumberValue());
      break;
    case TYPE_STRING:
      return ToJavaString(jniEnv, val->ToString(), (jstring *)jVal);
      break;
    case TYPE_DATE:
      ob = jniEnv->NewObject(jni.java.util.Date.class_, jni.java.util.Date.ctor, val->NumberValue());
      break;
    case TYPE_FUNCTION: {
      Handle<Function> fVal = Handle<Function>::Cast(val->ToObject());
      result = UnwrapObject(jniEnv, fVal, sObjectHiddenKey, jVal);
      if(result == ErrorNotfound)
        result = WrapV8Object(jniEnv, fVal, jVal);
      break;
    }
    case TYPE_ARRAY: {
      Handle<Array> aVal = Handle<Array>::Cast(val->ToObject());
      result = UnwrapObject(jniEnv, aVal, arrayConv->getHiddenKey(), jVal);
      if(result == ErrorNotfound)
        result = arrayConv->WrapV8Array(jniEnv, aVal, jVal);
      break;
    }
    case TYPE_OBJECT: {
      Handle<Object> oVal = Handle<Object>::Cast(val->ToObject());
      result = UnwrapObject(jniEnv, oVal, sObjectHiddenKey, jVal);
      if(result == ErrorNotfound)
        result = WrapV8Object(jniEnv, oVal, jVal);
      break;
    }
  }
  if(jniEnv->ExceptionCheck()) {
    jniEnv->ExceptionClear();
    return ErrorVM;
  }
  if(ob) {
    *jVal = ob;
    return OK;
  }
  return result;
}
Ejemplo n.º 10
0
 size_t Get<size_t> (Handle<Value> value) {
   return value->IntegerValue();
 }