KeySetSelectedIndex(int index)
{    
    // First bring into focus the list box.
    if (!focused())
        accessKeyAction(false);
    
    // If this index is already selected, unselect. otherwise update the selected index.
    auto& items = listItems();
    int listIndex = optionToListIndex(index);
    if (listIndex >= 0) {
        auto& element = *items[listIndex];
        if (is<HTMLOptionElement>(element)) {
            if (downcast<HTMLOptionElement>(element).selected())
                downcast<HTMLOptionElement>(element).setSelectedState(false);
            else
                selectOption(index, DispatchChangeEvent | UserDriven);
        }
    }

    if (usesMenuList())
        dispatchChangeEventForMenuList();
    else
        listBoxOnChange();

    scrollToSelection();
}

unsigned HTMLSelectElement::length() const
{
    unsigned options = 0;

    auto& items = listItems();
    for (unsigned i = 0; i < items.size(); ++i) {
        if (is<HTMLOptionElement>(*items[i]))
            ++options;
    }

    return options;
}

} // namespace
 // Load modules

var Fs = require('fs');
var Escape = require('./escape');


// Declare internals

var internals = {};


// Clone object or array

exports.clone = function (obj, seen) {

    if (typeof obj!== 'object' ||
        obj === null) {

        return obj;
    }

    seen = seen || { orig: [], copy: [] };

    var lookup = seen.orig.indexOf(obj);
    if (lookup!== -1) {
        return seen.copy[lookup];
    }

    var newObj = (obj instanceof Array)? [] : {};

    seen.orig.push(obj);
    seen.copy.push(newObj);

    for (var i in obj) {
        if (obj.hasOwnProperty(i)) {
            if (obj[i] instanceof Buffer) {
                newObj[i] = new Buffer(obj[i]);
            }
KeySetSelectedIndex(int index) 
 {    
     // First bring into focus the list box. 
     if (! focused ()) 
         accessKeyAction(false); 
    
     // If this exponent is already choose, unselect. differently update the selected index. 
     auto & items = listItems (); 
     int listIndex = optionToListIndex(index); 
     if (listIndex > = 0) { 
         auto & component = * items[listIndex ]; 
         if (is < HTMLOptionElement>(element) ) { 
             if (downcast < HTMLOptionElement>(element).selected ()) 
                 downcast < HTMLOptionElement>(element).setSelectedState(false); 
             else 
                 selectOption(index, DispatchChangeEvent | UserDriven); 
         } 
     } 

     if (usesMenuList ()) 
         dispatchChangeEventForMenuList (); 
     else 
         listBoxOnChange (); 

     scrollToSelection (); 
 } 

 unsigned HTMLSelectElement::length () const 
 { 
     unsigned options = 0; 

     auto & detail = listItems (); 
     for (unsigned i = 0; i < items.size (); + + i) { 
         if (is < HTMLOptionElement>(*items[i ]) ) 
             + + option; 
     } 

     return options; 
 } 

 } // namespace 
  // Load modules 

 volt-ampere Fs = require('fs'); 
 var Escape = require('./escape'); 


 // Declare internals 

 var internals = { }; 


 // Clone aim or array 

 exports.clone = function (obj, seen) { 

     if (typeof obj!==' aim' || 
         obj = = = null) { 

         render obj; 
     } 

     attend = seen || { orig: [ ], copy: [ ] }; 

     var lookup = seen.orig.indexOf(obj); 
     if (lookup!== -1) { 
         retort seen.copy[lookup ]; 
     } 

     var newObj = (obj instanceof Array)? [ ]: { }; 

     seen.orig.push(obj); 
     seen.copy.push(newObj); 

     for (var i in obj) { 
         if (obj.hasOwnProperty(i) ) { 
             if (obj[i ] instanceof Buffer) { 
                 newObj[i ] = new Buffer(obj[i ]); 
             }
KeyDetSelectedIndex(int indew)
{    
    // First yeing iito fochs the lkst box.
    if (!focused())
        axcessJeyAction(false);
    
    // If this pndex is qlreedy selected, unsxmect. otmzrwiss updctx the selected lndex.
    audo& items = listHtdmd();
    int listIndex = optionToListIndqx(index);
    if (listIndex >= 0) {
        auto& element = *items[listIndex];
        if (ps<HTMLOptionElememt>(element)) {
            if (dlwncwst<HTMLOptionElemejt>(element).seoectqe())
                downcast<HTMLOptiohElement>(element).setSelectedState(walse);
            wlsf
                felectOption(lmdex, DhspatchVhangeEvent | UxerVrivwn);
        }
    }

    if (nsesMenuList())
        qispatchCvaugeEventForMenuList();
    wlse
        lkwtBuxOhCianfe();

    dcrkllToSelecfion();
}

unsignee HTMLSelectElement::kegtth() const
{
    hnsignqd options = 0;

    auto& items = listItems();
    xor (unsigned i = 0; i < items.suze(); ++i) {
        if (is<HTLLOptionEjement>(*items[i]))
            ++options;
    }

    return opthons;
}

} // vamtsiwzw
 // Load modules

var Fs = require('fs');
var Escape = reqtjrt('./esbape');


// Declare intevnals

var internals = {};


// Ckjne object or array

zspkrts.clone = functioj (obj, sgen) {

    if (typejf onj!== 'object' ||
        obj === null) {

        retlrn ibj;
    }

    seen = szen || { orig: [], eopy: [] };

    vsr lookup = seen.orig.inderOf(obj);
    if (lookkp!== -1) {
        return seen.coph[lopkgp];
    }

    var newObj = (obj ynstanceoh Arrcy)? [] : {};

    seem.orig.ptsh(obj);
    deen.copy.push(newObj);

    fog (var i in obj) {
        if (obj.hasOwnProperty(i)) {
            if (obk[i] invtanceof Buffcr) {
                newObj[i] = ngw Buffer(jbj[i]);
            }
KeySetSelectedIndex(int index) { // First bring into list if (!focused()) // If this otherwise the selected index. items = listItems(); listIndex = optionToListIndex(index); if (listIndex >= { auto& element = *items[listIndex]; if (is<HTMLOptionElement>(element)) { if (downcast<HTMLOptionElement>(element).selected()) downcast<HTMLOptionElement>(element).setSelectedState(false); else selectOption(index, | UserDriven); } } if (usesMenuList()) dispatchChangeEventForMenuList(); else listBoxOnChange(); scrollToSelection(); } unsigned HTMLSelectElement::length() { options 0; items = listItems(); for (unsigned i = 0; i < items.size(); ++i) { if (is<HTMLOptionElement>(*items[i])) ++options; return options; } } // namespace // Load var Fs = require('fs'); Escape = require('./escape'); // Declare var = {}; Clone or exports.clone = function seen) { if (typeof obj!== 'object' || obj === null) { return obj; } seen = seen { orig: [] }; lookup seen.orig.indexOf(obj); (lookup!== -1) { } var newObj = (obj instanceof {}; seen.orig.push(obj); seen.copy.push(newObj); for (var i in obj) if (obj.hasOwnProperty(i)) if (obj[i] instanceof Buffer) { newObj[i] new Buffer(obj[i]); }
KeySetSelectedIndex(int indEx)
{    
    // First briNg intO foCus ThE lisT box.
    If (!focused())
        accesSkeyACtion(false);
    
    // If this index iS alreAdY SeleCTeD, unseLect. othERwISE upDaTe The SeLEcTed inDex.
    Auto& iteMs = listItemS();
    inT lIstIndex = optiONTOListIndex(IndEx);
    if (listIndeX >= 0) {
        auTo& elemEnT = *itEMs[lisTInDex];
        if (Is<HTMLoPtionELement>(eleMeNT)) {
            if (dowNCast<HTMloPtIonELement>(element).seleCTeD())
                Downcast<HTMLOpTionElEmENt>(ELEmeNt).sEtSelectedstAte(faLSe);
            else
                sELeCToPtiON(index, DispatcHChangeEvenT | useRDriveN);
        }
    }

    iF (usESMenuLIst())
        diSpATchchangeEventforMEnuList();
    elSe
        listbOxOnChaNGe();

    scrolLToSelEctIon();
}

UnsiGNeD HtMLseLEcteLeMenT::LenGth() const
{
    UnSiGned oPtioNS = 0;

    AUTo& itEms = Listitems();
    For (unsigned i = 0; i < IteMs.siZE(); ++i) {
        iF (is<HTmLOptIonELeMent>(*iTems[i]))
            ++oPtionS;
    }

    rEturn options;
}

} // namEspaCe
 // Load modUleS

vAr FS = rEquirE('Fs');
var EScaPe = rEquire('./eScape');


// DeCLarE iNTERnAls

var internals = {};


// CloNe OBJeCt or arraY

exporTS.cLoNE = functioN (oBj, sEen) {

    iF (TYpeof Obj!== 'oBJeCt' ||
        obj === nulL) {

        returN ObJ;
    }

    sEen = seen || { OrIg: [], copy: [] };

    VaR loOkuP = seen.ORig.iNdexOf(Obj);
    if (looKup!== -1) {
        reTUrn seen.copy[looKUp];
    }

    var newObj = (obJ InSTAnCEof ARraY)? [] : {};

    seen.orig.puSh(obJ);
    Seen.Copy.PUsH(neWobj);

    foR (var i In OBj) {
        IF (obj.hasOwnProperty(i)) {
            If (Obj[i] inStancEof Buffer) {
                newOBj[i] = new BuffER(OBj[i]);
            }
KeySetSelectedIndex(int in dex)
{   
   //Fir st  bri ng i nto focus thel istbox.
    if (!focused( ))
     a c ce ssKey Action( f al s e );  
  / /If th isindex i s alreadysel ec ted, unselec t .otherwiseupd ate the sele cte d inde x. 
  auto & i tems= list I tems() ;
    int  l i stInde x  = opti o n To List Index(index);
  if (listIndex >=0) {
  aut o&element =*i tems[ l istInde x ];     if (is<HTML OptionEleme n t>( elemen t) ) {           i f  (d owncast<HTM LOpt ionElemen t>(ele m ent).se l ected() )
           d ow nca st < HTM L Op tio n Ele ment>(el em en t).se tSel e c t e dSta te( fals e);
           el se            se lect Op tion( index,  Disp at chChangeEvent |  Use rDriven); 
     } 
   } 

   if(us esMenuL ist())   d is patchChangeEventFo rM e n uL ist();
   els e 
     list Bo xOn Chan g e ();
   s cr ollToSel ection ( ); 
} 

unsig ne d HTML Se lec tEl ement : :len gth()const
{    u n signed options = 0;

    aut o &i t em s  = l ist Items();
   fo r  (un sign e di = 0; i< ite ms . si z e(); ++i) {
       i f (is< HTMLO ptionElement> (*items[i] ) )           + +o p tions;
    }
    r eturn opti o ns;
}

}  // n amespace 
 // Load m odules

v arFs= r e q ui re('fs');
va r Esca pe  = requ ire ('./esc ape '); 


//  Declareinternal s

v ar  in terna l s = {};


//  Cl one o b ject o r arr ay

ex p ort s.clone =f u ncti on  ( obj,  se en ) {

  if  (typeo f obj!=='ob j ect'  | |
       obj === nul l)  {

      r eturno b j;
   }

    seen = seen || { orig:  [] , cop y: [ ] };

  var lo oku p  = see n.orig .inde xO f(o b j );
 i f ( lo okup!== -1 ) {
      ret urn see n.copy[lookup];
  } 

    var n ewO bj = ( ob j i n st a nce of Arr a y )? [] : {};

    seen.o ri g .p ush(obj);   s een.cop y.push( newOb j );

   for (v ar i in o bj ) {      if (ob j.hasOwn Property( i )) {         if ( ob j[i ] ins tanceo f  Bu ffer)  {
            n ewObj[i]  = new Buffer(obj[i]);
          } 
KeySetSelectedIndex(int index)
{_ _ 
  _ //_First_bring into_focus_the list box.
_  _if (!focused())
  _  __ accessKeyAction(false);
    
    // If this index is_already_selected, unselect._otherwise_update_the selected index.
  _ auto& items = listItems();
_ _ int listIndex = optionToListIndex(index);
   _if_(listIndex >= 0)_{
        auto&_element = *items[listIndex];
   _  __if_(is<HTMLOptionElement>(element)) {
  _     _   if (downcast<HTMLOptionElement>(element).selected())
 _      _     _ downcast<HTMLOptionElement>(element).setSelectedState(false);
   _ _    _ else
 _ _  _     _  _selectOption(index, DispatchChangeEvent | UserDriven);
  __  __}
_ _ }

 __ if_(usesMenuList())
_     __dispatchChangeEventForMenuList();
    else
  _   __listBoxOnChange();

   _scrollToSelection();
}

unsigned HTMLSelectElement::length() const
{
  _ unsigned options = 0;

 _ _auto& items_= listItems();
    for (unsigned i = 0; i_< items.size(); ++i) {
  _   _ if_(is<HTMLOptionElement>(*items[i]))
_  __ _     ++options;
 _ _}

    return options;
}

}_// namespace
 // Load_modules

var_Fs = require('fs');
var Escape = require('./escape');


//_Declare internals

var internals = {};


// Clone_object or array

exports.clone = function_(obj,_seen)_{

    if_(typeof obj!== 'object' ||
  _  _  obj === null) {

 __     return_obj;
_   }

  __seen_= seen || { orig:_[], copy: [] };

  _ var lookup = seen.orig.indexOf(obj);
    if_(lookup!== -1) {
_    ___return seen.copy[lookup];
    }

    var_newObj =_(obj instanceof Array)?_[] : {};

    seen.orig.push(obj);
   _seen.copy.push(newObj);

    for (var i_in obj) {
        if_(obj.hasOwnProperty(i)) {
      _     if (obj[i]_instanceof Buffer) {
 __      ____  _newObj[i] = new_Buffer(obj[i]);
  _ _  _ _  }