本文整理汇总了C++中Handle::IsNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ Handle::IsNumber方法的具体用法?C++ Handle::IsNumber怎么用?C++ Handle::IsNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Handle
的用法示例。
在下文中一共展示了Handle::IsNumber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printV8Value
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");
}
示例2: Write
IOBasicTypes::LongBufferSizeType ObjectByteWriterWithPosition::Write(const IOBasicTypes::Byte* inBuffer,IOBasicTypes::LongBufferSizeType inBufferSize)
{
HandleScope handle;
Handle<Object> anArray = Array::New((int)inBufferSize);
for(int i=0;i<(int)inBufferSize;++i)
anArray->Set(Number::New(i),Number::New(inBuffer[i]));
Handle<Value> value = mObject->Get(String::New("write"));
if(value->IsUndefined() || !value->IsFunction())
{
ThrowException(Exception::TypeError(String::New("write is not a function, it should be you know...")));
return 0;
}
Handle<Function> func = Handle<Function>::Cast(value);
Handle<Value> args[1];
args[0] = anArray;
Handle<Value> result = func->Call(mObject, 1, args);
if(result.IsEmpty())
{
ThrowException(Exception::TypeError(String::New("wrong return value. it's empty. return the number of written characters")));
return 0;
}
else if(result->IsNumber())
{
return result->ToNumber()->Uint32Value();
}
else
{
ThrowException(Exception::TypeError(String::New("wrong return value. write should return the number of written characters")));
return 0;
}
}
示例3: UserException
int V8Scope::type( const char *field ){
V8_SIMPLE_HEADER
Handle<Value> v = get( field );
if ( v->IsNull() )
return jstNULL;
if ( v->IsUndefined() )
return Undefined;
if ( v->IsString() )
return String;
if ( v->IsFunction() )
return Code;
if ( v->IsArray() )
return Array;
if ( v->IsBoolean() )
return Bool;
if ( v->IsInt32() )
return NumberInt;
if ( v->IsNumber() )
return NumberDouble;
if ( v->IsExternal() ){
uassert( 10230 , "can't handle external yet" , 0 );
return -1;
}
if ( v->IsDate() )
return Date;
if ( v->IsObject() )
return Object;
throw UserException( 12509, (string)"don't know what this is: " + field );
}
示例4: getKeyHandle
Handle<Integer> V8Config::getIntegerParameter(Handle<Object> element,const char* key){
Handle<Value> handleValue = getKeyHandle(element,key);
assert(handleValue->IsNumber());
return handleValue->ToInteger();
}
示例5:
Handle<Value> BGJSView::startJS(const char* fnName, const char* configJson, Handle<Value> uiObj, long configId) {
HandleScope scope;
Handle<Value> config;
if (configJson) {
config = String::New(configJson);
} else {
config = v8::Undefined();
}
// bgjsgl->Set(String::New("log"), FunctionTemplate::New(BGJSGLModule::log));
Local<Object> objInstance = this->jsViewOT->NewInstance();
objInstance->SetInternalField(0, External::New(this));
// Local<Object> instance = bgjsglft->GetFunction()->NewInstance();
this->_jsObj = Persistent<Object>::New(objInstance);
Handle<Value> argv[4] = { uiObj, this->_jsObj, config, Number::New(configId) };
Handle<Value> res = this->_jsContext->callFunction(_jsContext->_context->Global(), fnName, 4,
argv);
if (res->IsNumber()) {
_contentObj = res->ToNumber()->Value();
#ifdef DEBUG
LOGD ("startJS return id %d", _contentObj);
#endif
} else {
LOGI ("Did not receive a return id from startJS");
}
return scope.Close(res);
}
示例6: GetNaturalType
int Conv::GetNaturalType(Handle<Value> val) {
if(val.IsEmpty()) return TYPE_INVALID;
if(val->IsUndefined()) return TYPE_UNDEFINED;
if(val->IsNull()) return TYPE_NULL;
if(val->IsBoolean() || val->IsBooleanObject()) return TYPE_BOOL;
if(val->IsInt32()) return TYPE_INT;
if(val->IsUint32()) return TYPE_LONG;
if(val->IsNumber() || val->IsNumberObject()) return TYPE_DOUBLE;
if(val->IsString() || val->IsStringObject()) return TYPE_STRING;
return GetNaturalType(Handle<Object>::Cast(val));
}
示例7:
void v8ConvertIn(const Handle<Value> & value, QuantLib::Date & date)
{
if (value->IsNumber())
{
const double val = value->NumberValue();
date = QuantLib::Date(val);
}
else
{
THROW_EXCEPTION("value is not a number");
}
}
示例8: NODE_THROW
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();
}
示例9: SerializeField
void SerializeField(google::protobuf::Message *message, const Reflection *r, const FieldDescriptor *field, Handle<Value> val) {
const EnumValueDescriptor *enumValue = NULL;
bool repeated = field->is_repeated();
switch (field->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
SET_VALUE(Int32, val->Int32Value());
break;
case FieldDescriptor::CPPTYPE_INT64:
SET_VALUE(Int64, val->NumberValue());
break;
case FieldDescriptor::CPPTYPE_UINT32:
SET_VALUE(UInt32, val->Uint32Value());
break;
case FieldDescriptor::CPPTYPE_UINT64:
SET_VALUE(UInt64, val->NumberValue());
break;
case FieldDescriptor::CPPTYPE_DOUBLE:
SET_VALUE(Double, val->NumberValue());
break;
case FieldDescriptor::CPPTYPE_FLOAT:
SET_VALUE(Float, val->NumberValue());
break;
case FieldDescriptor::CPPTYPE_BOOL:
SET_VALUE(Bool, val->BooleanValue());
break;
case FieldDescriptor::CPPTYPE_ENUM:
enumValue = val->IsNumber() ?
field->enum_type()->FindValueByNumber(val->Int32Value()) :
field->enum_type()->FindValueByName(*String::AsciiValue(val));
if (enumValue != NULL)
SET_VALUE(Enum, enumValue);
break;
case FieldDescriptor::CPPTYPE_MESSAGE:
if (val->IsObject()) {
Type* type = protobuf->GetType(field->message_type());
type->SerializePart(repeated ?
r->AddMessage(message, field) :
r->MutableMessage(message, field), val.As<Object>());
}
break;
case FieldDescriptor::CPPTYPE_STRING:
if (Buffer::HasInstance(val)) {
Local<Object> buf = val->ToObject();
SET_VALUE(String, std::string(Buffer::Data(buf), Buffer::Length(buf)));
} else {
String::Utf8Value utf8(val);
SET_VALUE(String, std::string(*utf8, utf8.length()));
}
break;
}
}
示例10: keyStr
Susi::Util::Any Susi::JS::Engine::convertFromJS(Handle<Value> jsVal){
if(jsVal->IsArray()){
Susi::Util::Any::Array result;
auto obj = jsVal->ToObject();
const Local<Array> props = obj->GetPropertyNames();
const uint32_t length = props->Length();
for (uint32_t i=0 ; i<length ; ++i){
const Local<Value> key = props->Get(i);
const Local<Value> value = obj->Get(key);
result.push_back(Susi::JS::Engine::convertFromJS(value));
}
return result;
}
if(jsVal->IsObject()){
Susi::Util::Any result = Susi::Util::Any::Object{};
auto obj = jsVal->ToObject();
const Local<Array> props = obj->GetPropertyNames();
const uint32_t length = props->Length();
for (uint32_t i=0 ; i<length ; ++i){
const Local<Value> key = props->Get(i);
const Local<Value> value = obj->Get(key);
String::Utf8Value keyStr(key);
result[std::string(*keyStr)] = Susi::JS::Engine::convertFromJS(value);
}
return result;
}
if(jsVal->IsString()){
String::Utf8Value val(jsVal);
Susi::Util::Any result{std::string(*val)};
return result;
}
if(jsVal->IsNumber()){
Susi::Util::Any result{jsVal->ToNumber()->Value()};
return result;
}
if(jsVal->IsBoolean()){
Susi::Util::Any result{jsVal->ToBoolean()->Value()};
return result;
}
if(jsVal->IsNativeError()){
String::Utf8Value val(jsVal);
Susi::Util::Any result{std::string(*val)};
return result;
}
if(jsVal->IsUndefined()){
Susi::Util::Any result;
return result;
}
return Susi::Util::Any{"type not known"};
}
示例11: setField
inline bool setField(OGRFeature* f, int field_index, Handle<Value> val){
if (val->IsInt32()) {
f->SetField(field_index, val->Int32Value());
} else if (val->IsNumber()) {
f->SetField(field_index, val->NumberValue());
} else if (val->IsString()) {
std::string str = *NanUtf8String(val);
f->SetField(field_index, str.c_str());
} else if(val->IsNull() || val->IsUndefined()) {
f->UnsetField(field_index);
} else {
return true;
}
return false;
}
示例12: v8_to_gvalue
void v8_to_gvalue(Handle<Value> v, GValue *gv, GParamSpec *spec) {
if(v->IsNumber()) {
g_value_init(gv, G_TYPE_FLOAT);
g_value_set_float(gv, v->NumberValue());
} else if(v->IsString()) {
String::Utf8Value value(v->ToString());
if(spec->value_type == GST_TYPE_CAPS) {
GstCaps* caps = gst_caps_from_string(*value);
g_value_init(gv, GST_TYPE_CAPS);
g_value_set_boxed(gv, caps);
} else {
g_value_init(gv, G_TYPE_STRING);
g_value_set_string(gv, *value);
}
} else if(v->IsBoolean()) {
g_value_init(gv, G_TYPE_BOOLEAN);
g_value_set_boolean(gv, v->BooleanValue());
}
return;
}
示例13: rr_v82rb
VALUE rr_v82rb(Handle<Value> value) {
if (value.IsEmpty()) {
return rr_v8_value_empty();
}
if (value->IsUndefined() || value->IsNull()) {
return Qnil;
}
if (value->IsExternal()) {
return rr_reflect_v8_external(value);
}
if (value->IsUint32()) {
return UINT2NUM(value->Uint32Value());
}
if (value->IsInt32()) {
return INT2FIX(value->Int32Value());
}
if (value->IsBoolean()) {
return value->BooleanValue() ? Qtrue : Qfalse;
}
if (value->IsNumber()) {
return rb_float_new(value->NumberValue());
}
if (value->IsString()) {
return rr_reflect_v8_string(value);
}
if (value->IsFunction()) {
return rr_reflect_v8_function(value);
}
if (value->IsArray()) {
return rr_reflect_v8_array(value);
}
if (value->IsDate()) {
return rr_reflect_v8_date(value);
}
if (value->IsObject()) {
return rr_reflect_v8_object(value);
}
return rr_wrap_v8_value(value);
}
示例14: setTextAlign
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;
}
开发者ID:richardmadison,项目名称:titanium_mobile_blackberry,代码行数:37,代码来源:NativeAbstractTextControlObject.cpp
示例15: setTimeout
static void setTimeout(getdns_context* context, Handle<Value> opt) {
if (opt->IsNumber()) {
uint32_t num = opt->Uint32Value();
getdns_context_set_timeout(context, num);
}
}