当前位置: 首页>>代码示例>>C++>>正文


C++ Local::ToNumber方法代码示例

本文整理汇总了C++中Local::ToNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ Local::ToNumber方法的具体用法?C++ Local::ToNumber怎么用?C++ Local::ToNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Local的用法示例。


在下文中一共展示了Local::ToNumber方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setVectorY

void vectorTemplate::setVectorY(Local<String> property, Local<Value> value, const AccessorInfo &info){
	Local<External> data = Local<External>::Cast(info.Data());
	vector<double> *vect = reinterpret_cast<vector<double> *>(data->Value());
	if(value->IsNumber()){
		vect->y = value->ToNumber()->Value();
	}
}
开发者ID:boxyoman,项目名称:jsbots,代码行数:7,代码来源:vectorTemplate.cpp

示例2: execute

bool JSWrapper::execute( const char *scr, JSWrapperData *data, const char *fileName )
{
    HandleScope handle_scope( m_isolate );

    Local<String> source = String::NewFromUtf8( m_isolate, scr, NewStringType::kNormal ).ToLocalChecked();

    ScriptOrigin origin( v8::String::NewFromUtf8( m_isolate, fileName ? fileName : "Unknown" ) );
    MaybeLocal<Script> maybeScript = Script::Compile( m_context, source, &origin );

    bool success=false;

    if ( !maybeScript.IsEmpty() )
    {
        Local<Script> script = maybeScript.ToLocalChecked();        
        MaybeLocal<Value> maybeResult = script->Run(m_context);

        if ( !maybeResult.IsEmpty() )
        {
            Local<Value> result = maybeResult.ToLocalChecked();

            if ( data )
            {
                if ( result->IsNumber() )
                    data->setNumber( result->ToNumber()->Value() );
                else
                if ( result->IsString() )
                {
                    String::Utf8Value utf8( result );
                    data->setString( *utf8 );
                } else
                if ( result->IsBoolean() )
                    data->setBoolean( result->ToBoolean()->Value() );
                else                
                if ( result->IsObject() )
                    data->setObject( new JSWrapperObject( m_isolate, result->ToObject() ) );
                else
                if ( result->IsNull() )
                    data->setNull();
                else data->setUndefined();
            }

            success=true;
        } 
    }

    return success;
}
开发者ID:markusmoenig,项目名称:jsenginewrapper,代码行数:47,代码来源:jswrapper_v8.cpp

示例3: convertType

static Local<Value> convertType(TiAppPropertiesObject::PropertyType type, Local<Value> value) {
    switch (type) {
    case TiAppPropertiesObject::BoolProperty:
        return value->ToBoolean();
    case TiAppPropertiesObject::DoubleProperty:
    case TiAppPropertiesObject::IntProperty:
        return value->ToNumber();
    case TiAppPropertiesObject::ObjectProperty:
        return value->ToObject();
    case TiAppPropertiesObject::ListProperty:
        return value;
    case TiAppPropertiesObject::StringProperty:
        return value->ToString();
    default:
        return Local<Value>();
    }
}
开发者ID:adesugbaa,项目名称:titanium_mobile_blackberry,代码行数:17,代码来源:TiAppPropertiesObject.cpp

示例4: GetVectorParam

void ExecuteBaton::GetVectorParam(ExecuteBaton* baton, arrayParam_t* arrParam, Local<Array> arr) {
  // In case the array is empty just initialize the fields as we would need something in Connection::SetValuesOnStatement
  if (arr->Length() < 1) {
    arrParam->value = new int[0];
    arrParam->collectionLength = 0;
    arrParam->elementsSize = 0;
    arrParam->elementLength = new ub2[0];
    arrParam->elementsType = oracle::occi::OCCIINT;
    return;
  }
  
  // Next we create the array buffer that will be used later as the value for the param (in Connection::SetValuesOnStatement)
  // The array type will be derived from the type of the first element.
  Local<Value> val = arr->Get(0);

  // String array
  if (val->IsString()) {
    arrParam->elementsType = oracle::occi::OCCI_SQLT_STR;

    // Find the longest string, this is necessary in order to create a buffer later.
    int longestString = 0;
    for(unsigned int i = 0; i < arr->Length(); i++) {
    Local<Value> currVal = arr->Get(i);
    if (currVal->ToString()->Utf8Length() > longestString)
      longestString = currVal->ToString()->Utf8Length();
    }

    // Add 1 for '\0'
    ++longestString;

    // Create a long char* that will hold the entire array, it is important to create a FIXED SIZE array,
    // meaning all strings have the same allocated length.
    char* strArr = new char[arr->Length() * longestString];
    arrParam->elementLength = new ub2[arr->Length()];

    // loop thru the arr and copy the strings into the strArr
    int bytesWritten = 0;
    for(unsigned int i = 0; i < arr->Length(); i++) {
      Local<Value> currVal = arr->Get(i);
      if(!currVal->IsString()) {
        std::ostringstream message;
        message << "Input array has object with invalid type at index " << i << ", all object must be of type 'string' which is the type of the first element";
        baton->error = new std::string(message.str());
        return;
      }
            
      String::Utf8Value utfStr(currVal);
									
      // Copy this string onto the strArr (we put \0 in the beginning as this is what strcat expects).
      strArr[bytesWritten] = '\0';
      strncat(strArr + bytesWritten, *utfStr, longestString);
      bytesWritten += longestString;
									
      // Set the length of this element, add +1 for the '\0'
      arrParam->elementLength[i] = utfStr.length() + 1;
    }

    arrParam->value = strArr;
    arrParam->collectionLength = arr->Length();
    arrParam->elementsSize = longestString;
  }

  // Integer array.
  else if (val->IsNumber()) {
    arrParam->elementsType = oracle::occi::OCCI_SQLT_NUM;
	
    // Allocate memory for the numbers array, Number in Oracle is 21 bytes
    unsigned char* numArr = new unsigned char[arr->Length() * 21];
    arrParam->elementLength = new ub2[arr->Length()];

    for(unsigned int i = 0; i < arr->Length(); i++) {
      Local<Value> currVal = arr->Get(i);
      if(!currVal->IsNumber()) {
        std::ostringstream message;
        message << "Input array has object with invalid type at index " << i << ", all object must be of type 'number' which is the type of the first element";
        baton->error = new std::string(message.str());
        return;
	  }

      // JS numbers can exceed oracle numbers, make sure this is not the case.
      double d = currVal->ToNumber()->Value();
      if (d > 9.99999999999999999999999999999999999999*std::pow(double(10), double(125)) || d < -9.99999999999999999999999999999999999999*std::pow(double(10), double(125))) {
        std::ostringstream message;
        message << "Input array has number that is out of the range of Oracle numbers, check the number at index " << i;
        baton->error = new std::string(message.str());
        return;
      }
	  
      // Convert the JS number into Oracle Number and get its bytes representation
      oracle::occi::Number n = d;
      oracle::occi::Bytes b = n.toBytes();
      arrParam->elementLength[i] = b.length ();
      b.getBytes(&numArr[i*21], b.length());
    }

    arrParam->value = numArr;
    arrParam->collectionLength = arr->Length();
    arrParam->elementsSize = 21;
  }

//.........这里部分代码省略.........
开发者ID:Atlantis-Software,项目名称:node-oracle,代码行数:101,代码来源:executeBaton.cpp


注:本文中的Local::ToNumber方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。