1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 /* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is [Open Source Virtual Machine.].
18 * The Initial Developer of the Original Code is
19 * Adobe System Incorporated.
20 * Portions created by the Initial Developer are Copyright (C) 2004-2006
21 * the Initial Developer. All Rights Reserved.
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
43 //pseudo-final - no user class can extend Function
44 [native(cls
="FunctionClass", gc
="exact", instance
="FunctionObject", methods
="auto", construct
="instance")]
45 dynamic public class Function
47 // Function.length = 1 per ES3
48 // E262 {ReadOnly, DontDelete, DontEnum }
49 public static const length
:int = 1
52 // JS {DontEnum,DontDelete}
53 public native function get prototype
()
54 public native function set prototype
(p
)
56 // E262 {DontEnum, DontDelete, ReadOnly}
57 public native function get length
():int
59 // called by native code to create empty functions used for
60 // prototype and no-arg constructor.
61 private static function emptyCtor
()
66 /* cn: Spidermonkey returns the actual source text of the function here. The ES3
67 // standard only says:
68 15.3.4.2 Function.prototype.toString ( )
69 An implementation-dependent representation of the function is returned. This
70 representation has the syntax of a FunctionDeclaration. Note in particular
71 that the use and placement of white space, line terminators, and semicolons
72 within the representation string is implementation-dependent.
73 The toString function is not generic; it throws a TypeError exception if its this value is not a Function object.
74 Therefore, it cannot be transferred to other kinds of objects for use as a method.
76 // We don't have the source text, so this impl follows the letter if not the intent
79 // Note: we only honor the compact ES3/4 spec, which means
80 // we don't support new Function(stringArg) where stringArg is the text of
81 // the function to be compiled at runtime. Returning the true text of the
82 // function in toString() seems to be a bookend to this feature to me, and
83 // thus shouldn't be in the compact specification either. */
85 prototype
.toLocaleString
=
86 prototype
.toString
= function():String
89 return "function Function() {}"
92 AS3 native function call
(thisArg
=void 0, ...args
)
93 prototype
.call
= function(thisArg
=void 0, ...args
)
96 return f
.AS3::apply
(thisArg
, args
)
99 AS3 native function apply
(thisArg
=void 0, argArray
=void 0)
100 prototype
.apply
= function(thisArg
=void 0, argArray
=void 0)
102 var f
:Function = this
103 return f
.AS3::apply
(thisArg
, argArray
)
106 _dontEnumPrototype
(prototype
);
111 [native(cls
="MethodClosureClass", gc
="exact", instance
="MethodClosure", methods
="auto", construct
="instance")]
112 final class MethodClosure
extends Function
114 override public function get prototype
()
119 override public function set prototype
(p
)
121 Error.throwError
( ReferenceError, 1074 /*kConstWriteError*/, "prototype", "MethodClosure" );