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