libraries/v8/runtime.cc
// Push an object unto an array of objects if it is not already in the
// array.  Returns true if the element was pushed on the stack and
// false otherwise.
Push an object unto an array of objects if it is not already in the
array.  Returns true if the element was pushed on the stack and
false otherwise.
Push an object unto an array of objects if it is not already in the array . Returns true if the element was pushed on the stack and false otherwise .
RUNTIME_FUNCTION(MaybeObject*, Runtime_PushIfAbsent) {
  SealHandleScope shs(isolate);
  ASSERT(args.length() == 2);
  CONVERT_ARG_CHECKED(JSArray, array, 0);
  CONVERT_ARG_CHECKED(JSReceiver, element, 1);
  RUNTIME_ASSERT(array->HasFastSmiOrObjectElements());
  int length = Smi::cast(array->length())->value();
  FixedArray* elements = FixedArray::cast(array->elements());
  for (int i = 0; i < length; i++) {
    if (elements->get(i) == element) return isolate->heap()->false_value();
  }
  Object* obj;
  { MaybeObject* maybe_obj =
        array->SetFastElement(length, element, kNonStrictMode, true);
    if (!maybe_obj->ToObject(&obj)) return maybe_obj;
  }
  return isolate->heap()->true_value();
}
RUNTIME_FUNCTION ( MaybeObject * , Runtime_PushIfAbsent ) { SealHandleScope shs ( isolate ) ; ASSERT ( args . length ( ) == 2 ) ; CONVERT_ARG_CHECKED ( JSArray , array , 0 ) ; CONVERT_ARG_CHECKED ( JSReceiver , element , 1 ) ; RUNTIME_ASSERT ( array -> HasFastSmiOrObjectElements ( ) ) ; int length = Smi :: cast ( array -> length ( ) ) -> value ( ) ; FixedArray * elements = FixedArray :: cast ( array -> elements ( ) ) ; for ( int i = 0 ; i < length ; i ++ ) { if ( elements -> get ( i ) == element ) return isolate -> heap ( ) -> false_value ( ) ; } Object * obj ; { MaybeObject * maybe_obj = array -> SetFastElement ( length , element , kNonStrictMode , true ) ; if ( ! maybe_obj -> ToObject ( & obj ) ) return maybe_obj ; } return isolate -> heap ( ) -> true_value ( ) ; }
Push an object unto an array of objects if it is not already in the
array.
Push an object unto an array of objects if it is not already in the array .
// Strict not needed. Used for cycle detection in Array join implementation.