Exemple #1
0
/*
 * Prototype:
 * File.write(data_val)
 *
 * Docs:
 * TBW
 *
 * Example:
 * TBW
 */
static void
gum_v8_file_on_file_write (const FunctionCallbackInfo<Value> & info)
{
  GumFile * file = static_cast<GumFile *> (
      info.Holder ()->GetAlignedPointerFromInternalField (0));
  Isolate * isolate = info.GetIsolate ();

  gpointer data = NULL;
  gint data_length = 0;

  Local<Value> data_val = info[0];
  if (data_val->IsArrayBuffer ())
  {
    ArrayBuffer::Contents contents =
        Handle<ArrayBuffer>::Cast (data_val)->GetContents ();

    data = contents.Data ();
    data_length = (gint) contents.ByteLength ();
  }
  else if (!data_val->IsString ())
  {
    isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, 
        "File.write: argument must be a string or ArrayBuffer")));
    return;
  }

  if (gum_file_is_open (file))
  {
    if (data == NULL)
    {
      String::Utf8Value utf_val (data_val);
      fwrite (*utf_val, utf_val.length (), 1, file->handle);
    }
    else
    {
      fwrite (data, data_length, 1, file->handle);
    }
  }
  else
  {
    isolate->ThrowException (Exception::TypeError (String::NewFromUtf8 (isolate, 
        "File.write: file is closed")));
  }
}
Exemple #2
0
 NativeString(const Local<Value> &value)
 {
     if (value->IsUndefined()) {
         data = nullptr;
         length = 0;
     } else if (value->IsString()) {
         utf8Value = new (utf8ValueMemory) String::Utf8Value(value);
         data = (**utf8Value);
         length = utf8Value->length();
     } else if (node::Buffer::HasInstance(value)) {
         data = node::Buffer::Data(value);
         length = node::Buffer::Length(value);
     } else if (value->IsTypedArray()) {
         Local<ArrayBufferView> arrayBuffer = Local<ArrayBufferView>::Cast(value);
         ArrayBuffer::Contents contents = arrayBuffer->Buffer()->GetContents();
         length = contents.ByteLength();
         data = (char *) contents.Data();
     } else {
         static char empty[] = "";
         data = empty;
         length = 0;
     }
 }
bool CQueryParameter::TransformParameter( Isolate* isolate, Local< Value > value, sBindParameter** pOutParam )
{
	HandleScope scope( isolate );
	Local< Context > context = isolate->GetCurrentContext( );

	sBindParameter* pParameter = *pOutParam;

	if( value->IsNull( ) )
	{
		pParameter->SetNull( );
	}
	else if( value->IsString( ) )
	{
		pParameter->SetString( value.As<String>( ) );
	}
	else if( value->IsBoolean( ) )
	{
		pParameter->SetBool( value->BooleanValue( context ).FromJust( ) );
	}
	else if( value->IsInt32( ) )
	{
		pParameter->SetInt( value->Int32Value( context ).FromJust( ) );
	}
	else if( value->IsUint32( ) )
	{
		pParameter->SetUInt( value->Uint32Value( context ).FromJust( ) );
	}
	else if( value->IsNumber( ) )
	{
		double d = value->NumberValue( context ).FromJust( );
		if( _isnan( d ) || !_finite( d ) )
		{
			return false;
		}
		else if( d == floor( d ) &&
				 d >= std::numeric_limits<int64_t>::min( ) &&
				 d <= std::numeric_limits<int64_t>::max( )
				 )
		{
			pParameter->SetInt64( value->IntegerValue( context ).FromJust( ) );
		}
		else
		{
			pParameter->SetDouble( value->NumberValue( context ).FromJust( ) );
		}
	}
	else if( value->IsDate( ) )
	{
		Local<Date> dateObject = value.As<Date>( );

		pParameter->SetDate( dateObject->NumberValue( context ).FromJust( ) );
	}
	else if( value->IsObject( ) )
	{
		Local<Object> objValue = value.As<Object>( );

		if( node::Buffer::HasInstance( value ) )
		{
			pParameter->SetBuffer( isolate, objValue );
		}
		else
		{
			Local< String > strId = String::NewFromUtf8( isolate, "_objId", NewStringType::kNormal ).ToLocalChecked( );


			if( objValue->HasRealNamedProperty( context, strId ).FromJust( ) )
			{
				Local< Uint32 > numTypeId = objValue->Get( context, strId ).ToLocalChecked( ).As< Uint32 >( );

				uint32_t nType = numTypeId->Int32Value( context ).FromJust( );

				switch( nType )
				{
					case ID_INPUT_STREAM:
					{
						Local<Value> type = objValue->Get(
							context, String::NewFromUtf8( isolate, "type", NewStringType::kNormal ).ToLocalChecked( )
						).ToLocalChecked( );

						Local<Value> stream = objValue->Get(
							context, String::NewFromUtf8( isolate, "stream", NewStringType::kNormal ).ToLocalChecked( )
						).ToLocalChecked( );

						Local<Value> length = objValue->Get(
							context, String::NewFromUtf8( isolate, "length", NewStringType::kNormal ).ToLocalChecked( )
						).ToLocalChecked( );

						pParameter->SetStream( isolate, type->Uint32Value( context ).FromJust( ), stream, static_cast< SQLUINTEGER >( length->IntegerValue( context ).FromJust( ) ) );

						break;
					}
					case ID_NUMERIC_VALUE:
					{
						Local< Value > precision = objValue->Get(
							context, String::NewFromUtf8( isolate, "precision", NewStringType::kNormal ).ToLocalChecked( )
						).ToLocalChecked( );

						Local<Value> scale = objValue->Get(
							context, String::NewFromUtf8( isolate, "scale", NewStringType::kNormal ).ToLocalChecked( )
						).ToLocalChecked( );

						Local<Value> sign = objValue->Get(
							context, String::NewFromUtf8( isolate, "sign", NewStringType::kNormal ).ToLocalChecked( )
						).ToLocalChecked( );

						Local<Value> value = objValue->Get(
							context, String::NewFromUtf8( isolate, "value", NewStringType::kNormal ).ToLocalChecked( )
						).ToLocalChecked( );

						Local< Uint32 > numPrecision = precision.As<Uint32>( );
						Local< Uint32 > numScale = scale.As<Uint32>( );
						Local< Boolean > boolSign = sign.As<Boolean>( );
						Local< ArrayBuffer > arrBuffer = ( value.As<Uint8Array>( ) )->Buffer( );

						ArrayBuffer::Contents contents = arrBuffer->GetContents( );

						if( contents.ByteLength( ) > SQL_MAX_NUMERIC_LEN )
						{
							return false;
						}

						pParameter->SetNumeric( numPrecision->Uint32Value( context ).FromJust( ),
												numScale->Uint32Value( context ).FromJust( ),
												boolSign->BooleanValue( context ).FromJust( ),
												contents.Data( ),
												contents.ByteLength( )
						);


						break;
					}
					default:
					{
						return false;
					}
				}
			}
			else
			{
				return false;
			}
		}
	}
	else
	{
		return false;
	}

	return true;
}