1
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3
* The contents of this file are subject to the Netscape Public
4
* License Version 1.1 (the "License"); you may not use this file
5
* except in compliance with the License. You may obtain a copy of
6
* the License at http://www.mozilla.org/NPL/
8
* Software distributed under the License is distributed on an "AS
9
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
* implied. See the License for the specific language governing
11
* rights and limitations under the License.
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
13
16
* The Original Code is Mozilla Communicator client code, released
16
* The Initial Developer of the Original Code is Netscape
17
* Communications Corporation. Portions created by Netscape are
18
* Copyright (C) 1998 Netscape Communications Corporation. All
19
* The Initial Developer of the Original Code is
20
* Netscape Communications Corporation.
21
* Portions created by the Initial Developer are Copyright (C) 1998
22
* the Initial Developer. All Rights Reserved.
23
* Alternatively, the contents of this file may be used under the
24
* terms of the GNU Public License (the "GPL"), in which case the
25
* provisions of the GPL are applicable instead of those above.
26
* If you wish to allow use of your version of this file only
27
* under the terms of the GPL and not to allow others to use your
28
* version of this file under the NPL, indicate your decision by
29
* deleting the provisions above and replace them with the notice
30
* and other provisions required by the GPL. If you do not delete
31
* the provisions above, a recipient may use your version of this
32
* file under either the NPL or the GPL.
26
* Alternatively, the contents of this file may be used under the terms of
27
* either of the GNU General Public License Version 2 or later (the "GPL"),
28
* or 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 ***** */
36
41
* JS function support.
254
262
(void) JS_GetReservedSlot(cx, argsobj, 0, &bmapval);
255
263
if (!JSVAL_IS_VOID(bmapval)) {
256
264
JS_SetReservedSlot(cx, argsobj, 0, JSVAL_VOID);
257
if (JS_MAX(fp->argc, fp->fun->nargs) > JSVAL_INT_BITS)
265
if (MAXARGS(fp) > JSVAL_INT_BITS)
258
266
JS_free(cx, JSVAL_TO_PRIVATE(bmapval));
398
397
JS_ASSERT(fp->argsobj);
401
399
if (JSVAL_IS_INT(id)) {
402
400
slot = JSVAL_TO_INT(id);
403
if (slot < JS_MAX(fp->argc, fp->fun->nargs) &&
404
!ArgWasDeleted(cx, fp, slot)) {
401
if (slot < MAXARGS(fp) && !ArgWasDeleted(cx, fp, slot)) {
405
402
/* XXX ECMA specs DontEnum, contrary to other array-like objects */
406
403
if (!js_DefineProperty(cx, obj, (jsid) id, fp->argv[slot],
407
404
args_getProperty, args_setProperty,
733
730
scope = OBJ_SCOPE(funobj);
734
731
for (sprop = SCOPE_LAST_PROP(scope); sprop; sprop = sprop->parent) {
735
732
getter = sprop->getter;
736
if (getter != js_GetArgument && getter != js_GetLocalVariable)
733
if (getter == js_GetArgument)
735
else if (getter == js_GetLocalVariable)
739
740
/* Trigger reflection in call_resolve by doing a lookup. */
740
741
if (!js_LookupProperty(cx, obj, sprop->id, &obj, &prop))
742
743
JS_ASSERT(obj && prop);
744
cprop = (JSScopeProperty *)prop;
745
LOCKED_OBJ_SET_SLOT(obj, cprop->slot, vec[sprop->shortid]);
743
746
OBJ_DROP_PROPERTY(cx, obj, prop);
1008
1013
return JS_FALSE;
1011
* ECMA says that constructor.prototype is DontEnum | DontDelete for
1016
* ECMA (15.3.5.2) says that constructor.prototype is DontDelete for
1012
1017
* user-defined functions, but DontEnum | ReadOnly | DontDelete for
1013
1018
* native "system" constructors such as Object or Function. So lazily
1014
1019
* set the former here in fun_resolve, but eagerly define the latter
1015
1020
* in JS_InitClass, with the right attributes.
1017
if (!js_SetClassPrototype(cx, obj, proto, JSPROP_PERMANENT)) {
1022
if (!js_SetClassPrototype(cx, obj, proto,
1023
JSPROP_ENUMERATE | JSPROP_PERMANENT)) {
1018
1024
cx->newborn[GCX_OBJECT] = NULL;
1019
1025
return JS_FALSE;
1148
1154
? JSXDR_FUNCONST
1149
1155
: JSXDR_FUNVAR;
1150
1156
userid = INT_TO_JSVAL(sprop->shortid);
1151
propname = ATOM_BYTES((JSAtom *)sprop->id);
1152
if (!JS_XDRUint32(xdr, &type) ||
1153
!JS_XDRUint32(xdr, (uint32 *)&userid) ||
1157
/* XXX lossy conversion, need new XDR version for ECMAv3 */
1158
propname = JS_GetStringBytes(ATOM_TO_STRING((JSAtom *)sprop->id));
1160
!JS_XDRUint32(xdr, &type) ||
1161
!JS_XDRUint32(xdr, &userid) ||
1154
1162
!JS_XDRCString(xdr, &propname)) {
1156
1164
JS_ARENA_RELEASE(&cx->tempPool, mark);
1666
1672
* are built for Function.prototype.call or .apply activations that invoke
1667
1673
* Function indirectly from a script.
1670
1675
JS_ASSERT(!fp->script && fp->fun && fp->fun->native == Function);
1681
* Load fp->script->* before calling js_PCToLineNumber, to avoid
1682
* a pessimal reload of fp->script.
1684
principals = fp->script->principals;
1685
filename = fp->script->filename;
1686
lineno = js_PCToLineNumber(fp->script, fp->pc);
1676
caller = JS_GetScriptedCaller(cx, fp);
1678
filename = caller->script->filename;
1679
lineno = js_PCToLineNumber(cx, caller->script, caller->pc);
1680
principals = JS_EvalFramePrincipals(cx, fp, caller);
1691
1687
n = argc ? argc - 1 : 0;
2011
js_ReportIsNotFunction(cx, vp, constructing);
2014
js_ReportIsNotFunction(cx, vp, flags);
2014
2017
return (JSFunction *) JS_GetPrivate(cx, obj);
2018
js_ReportIsNotFunction(JSContext *cx, jsval *vp, JSBool constructing)
2021
js_ReportIsNotFunction(JSContext *cx, jsval *vp, uintN flags)
2021
2024
JSString *fallback;
2031
2033
type = JS_TypeOfValue(cx, *vp);
2032
2034
fallback = ATOM_TO_STRING(cx->runtime->atomState.typeAtoms[type]);
2034
str = js_DecompileValueGenerator(cx, fp ? vp - fp->sp : JSDVG_IGNORE_STACK,
2035
str = js_DecompileValueGenerator(cx,
2036
(flags & JSV2F_SEARCH_STACK)
2037
? JSDVG_SEARCH_STACK
2040
: JSDVG_IGNORE_STACK,
2037
2044
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
2038
(uintN)(constructing ? JSMSG_NOT_CONSTRUCTOR
2039
: JSMSG_NOT_FUNCTION),
2045
(uintN)((flags & JSV2F_CONSTRUCT)
2046
? JSMSG_NOT_CONSTRUCTOR
2047
: JSMSG_NOT_FUNCTION),
2040
2048
JS_GetStringBytes(str));