01 /*
02  *  JScripter Emulation 1.0 - To Script Java
03  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
04  *  
05  *  This program is free software: you can redistribute it and/or modify
06  *  it under the terms of the GNU Affero General Public License as published by
07  *  the Free Software Foundation, either version 3 of the License, or
08  *  (at your option) any later version.
09  *  
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU Affero General Public License for more details.
14  *  
15  *  You should have received a copy of the GNU Affero General Public License
16  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.jscripter.emu.gc;
20 
21 import js.Js;
22 import js.ObjectLike;
23 import jsx.core.ObjectLikes;
24 
25 /**
26  * <p>
27  * An <tt>internal</tt> class for DOM-enabled depth-first-search garbage
28  * searchers emulating garbage collection based finalization in JavaScript.
29  * </p>
30  * <p>
31  * This class is only used internally by JS re-compiler implementations.
32  * </p>
33  * 
34  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a
35  *         href="http://www.jscripter.org"
36  *         target="_blank">http://www.jscripter.org</a>
37  * 
38  * @javascript This class is only loaded and resolved by re-compiler
39  *          implementations.
40  */
41 public final class DFSSearcher extends DFS {
42     /**
43      * <p>
44      * Internally constructs an object visitor of this type.
45      * </p>
46      * 
47      * @since 1.0
48      * @javascript Re-compilers must report error on end-users directly using this
49      *          constructor.
50      */
51     public DFSSearcher() {
52     }
53 
54     /**
55      * <p>
56      * Internally visits an object.
57      * </p>
58      * 
59      * @param o
60      *            An object to visit.
61      * @since 1.0
62      * @javascript Re-compilers must report error on end-users directly using this
63      *          method.
64      */
65     @Override
66     public void visit(ObjectLike o) {
67         if (Js.not(ObjectLikes.get(o, LIVES))) {
68             if (ObjectLikes.get(o, REFS) > ObjectLikes.get(o, COUNT)) {
69                 new DFSReviver().visit(o);
70             } else {
71                 ObjectLikes.dec(o, LIVES);
72                 traverse(o);
73             }
74         }
75     }
76 }