libraries/v8/runtime.cc
// Converts a Number to a Smi, if possible. Returns NaN if the number is not
// a small integer.
Converts a Number to a Smi, if possible. Returns NaN if the number is not
a small integer.
Converts a Number to a Smi if possible . Returns NaN if the number is not a small integer .
RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToSmi) {
  SealHandleScope shs(isolate);
  ASSERT(args.length() == 1);
  Object* obj = args[0];
  if (obj->IsSmi()) {
    return obj;
  }
  if (obj->IsHeapNumber()) {
    double value = HeapNumber::cast(obj)->value();
    int int_value = FastD2I(value);
    if (value == FastI2D(int_value) && Smi::IsValid(int_value)) {
      return Smi::FromInt(int_value);
    }
  }
  return isolate->heap()->nan_value();
}
RUNTIME_FUNCTION ( MaybeObject * , Runtime_NumberToSmi ) { SealHandleScope shs ( isolate ) ; ASSERT ( args . length ( ) == 1 ) ; Object * obj = args [ 0 ] ; if ( obj -> IsSmi ( ) ) { return obj ; } if ( obj -> IsHeapNumber ( ) ) { double value = HeapNumber :: cast ( obj ) -> value ( ) ; int int_value = FastD2I ( value ) ; if ( value == FastI2D ( int_value ) && Smi :: IsValid ( int_value ) ) { return Smi :: FromInt ( int_value ) ; } } return isolate -> heap ( ) -> nan_value ( ) ; }
Converts a Number to a Smi, if possible.
Converts a Number to a Smi if possible .