01 
02 /*
03  *  Descripter 1.0 - Java Script Engines
04  *  Copyright (C) 2010-2015  Jianjun Liu (J.J.Liu)
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.descripter.js.api.global;
21 
22 import org.descripter.js.api.Core;
23 import org.descripter.js.api.Function;
24 import org.descripter.js.api.Functor;
25 import org.descripter.js.api.Script;
26 
27 /**
28  * <p>Emulates the global Function function in JavaScript.</p>
29  * 
30  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.descripter.org" target="_blank">http://www.descripter.org</a>
31  * @since Descripter 1.0
32  */
33 public class Function_ extends Function<Core>
34 {
35     /**
36      * <p>Creates the singleton of the global {@link Function} object of this type.</p>
37      * @param core The {@link Core} global script context
38      * @since Descripter 1.0
39      */
40     public static final void create(Core core) {
41         if (core.get(core._Function) == null) {
42             core.put(core._Function, new Function_(core));
43         }
44     }
45 
46     private Function_(Core core) {
47         super(core);
48         put(core._constructor, null);
49         put(core._prototype  , core.object());
50     }
51 
52     /**
53      * <p>Allocates a new object with this {@link Function}.</p>
54      * @param script The script context that invoked this service
55      * @param args An array of the arguments passed by the invocation
56      * @return The newly allocated object
57      * @since Descripter 1.0
58      */
59     @Override
60     public <S extends Script<?>> Function<S> alloc(S script, Object ...args) {
61         Function<S> o = new Function<S>(script) {
62             @Override
63             public Functor<S> functor() {
64                 return null;
65             }
66         };
67         return o;
68     }
69 
70     /**
71      * <p>Gets the {@link Functor} of the {@link Function} object.</p>
72      * <p>This is a concrete implementation of the super abstract method.</p>
73      * @return The {@link Functor} of the {@link Function} object
74      * @since Descripter 1.0
75      */
76     @Override
77     protected Functor<Core> functor() {
78         return new Functor<Core>(this) {
79             @Override
80             public Object function() {
81                 return null;
82             }
83         };
84     }
85 }