Compare commits

..

38 Commits

Author SHA1 Message Date
dkl%redhat.com
8c591d53e2 Removed some remaining SelectVisible calls in favor of CanSeeBug
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@121533 18797224-902f-48f8-a5cc-f745e15eee43
2002-05-15 18:36:31 +00:00
dkl%redhat.com
c1aa983fd5 Update to HEAD 2002/05/13
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@121401 18797224-902f-48f8-a5cc-f745e15eee43
2002-05-13 21:56:49 +00:00
dkl%redhat.com
3551227412 forgot one
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@121393 18797224-902f-48f8-a5cc-f745e15eee43
2002-05-13 20:49:00 +00:00
dkl%redhat.com
d0cc91f285 Fixed some template inconsistencies with current 2.16 Stable Branch
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@121392 18797224-902f-48f8-a5cc-f745e15eee43
2002-05-13 20:46:50 +00:00
(no author)
65ff7d56b3 This commit was manufactured by cvs2svn to create branch
'Bugzilla_PgSQL_branch'.

git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@121370 18797224-902f-48f8-a5cc-f745e15eee43
2002-05-13 06:24:51 +00:00
dkl%redhat.com
800eccde9a Merge with HEAD 2002/04/26
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@119979 18797224-902f-48f8-a5cc-f745e15eee43
2002-04-26 18:59:37 +00:00
(no author)
5360e5b008 This commit was manufactured by cvs2svn to create branch
'Bugzilla_PgSQL_branch'.

git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@119975 18797224-902f-48f8-a5cc-f745e15eee43
2002-04-26 18:12:55 +00:00
dkl%redhat.com
da759055dd Sync to HEAD 2002/03/21
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@117156 18797224-902f-48f8-a5cc-f745e15eee43
2002-03-22 05:16:48 +00:00
(no author)
1f960bb1bd This commit was manufactured by cvs2svn to create branch
'Bugzilla_PgSQL_branch'.

git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@116669 18797224-902f-48f8-a5cc-f745e15eee43
2002-03-15 23:23:14 +00:00
dkl%redhat.com
e0f4b89db1 Update to HEAD 2002/02/26
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@115395 18797224-902f-48f8-a5cc-f745e15eee43
2002-02-27 01:11:14 +00:00
(no author)
025b6e8e46 This commit was manufactured by cvs2svn to create branch
'Bugzilla_PgSQL_branch'.

git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@115298 18797224-902f-48f8-a5cc-f745e15eee43
2002-02-24 09:28:23 +00:00
dkl%redhat.com
704f46aa53 Update to HEAD 2002/02/04
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@113607 18797224-902f-48f8-a5cc-f745e15eee43
2002-02-04 15:56:15 +00:00
(no author)
f26338df7e This commit was manufactured by cvs2svn to create branch
'Bugzilla_PgSQL_branch'.

git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@113575 18797224-902f-48f8-a5cc-f745e15eee43
2002-02-03 09:28:50 +00:00
dkl%redhat.com
58548c3f0d Update to HEAD 2002/01/30
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@113247 18797224-902f-48f8-a5cc-f745e15eee43
2002-01-30 23:00:13 +00:00
(no author)
9a6b4393ad This commit was manufactured by cvs2svn to create branch
'Bugzilla_PgSQL_branch'.

git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@113166 18797224-902f-48f8-a5cc-f745e15eee43
2002-01-29 23:26:38 +00:00
dkl%redhat.com
4316819604 Fix runtests.sh error on processmail
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@112507 18797224-902f-48f8-a5cc-f745e15eee43
2002-01-21 23:27:24 +00:00
dkl%redhat.com
9d93dfabb8 Fix botched earlier sync with HEAD
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@112499 18797224-902f-48f8-a5cc-f745e15eee43
2002-01-21 20:42:30 +00:00
dkl%redhat.com
d2ddb07675 Update to HEAD 01/18/2002
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@112473 18797224-902f-48f8-a5cc-f745e15eee43
2002-01-18 23:06:43 +00:00
dkl%redhat.com
66d426dc97 Lost the pgsetup.pl file somewhere along the line. Adding back properly.
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@111575 18797224-902f-48f8-a5cc-f745e15eee43
2002-01-08 16:13:05 +00:00
dkl%redhat.com
b7e91cb3b6 Changes to CanSeeBug to allow multiple checks in one call for buglist.cgi
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@111509 18797224-902f-48f8-a5cc-f745e15eee43
2002-01-07 23:20:15 +00:00
dkl%redhat.com
5ac0899827 Update to HEAD 2002-01-07
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@111508 18797224-902f-48f8-a5cc-f745e15eee43
2002-01-07 23:14:41 +00:00
dkl%redhat.com
4f49e57a3b Merge 3 with HEAD: 2001/12/26
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@111103 18797224-902f-48f8-a5cc-f745e15eee43
2001-12-27 07:26:12 +00:00
dkl%redhat.com
38c27be28f Merge 2 with HEAD: 2001/12/26
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@111102 18797224-902f-48f8-a5cc-f745e15eee43
2001-12-27 06:02:04 +00:00
dkl%redhat.com
d60d3d6121 Merge fix. This is frustrating.
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@111101 18797224-902f-48f8-a5cc-f745e15eee43
2001-12-27 05:29:04 +00:00
dkl%redhat.com
db0b87fb6c Merge with HEAD on 2001/12/26
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@111100 18797224-902f-48f8-a5cc-f745e15eee43
2001-12-27 05:09:43 +00:00
(no author)
6e2791a4b7 This commit was manufactured by cvs2svn to create branch
'Bugzilla_PgSQL_branch'.

git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@110404 18797224-902f-48f8-a5cc-f745e15eee43
2001-12-12 22:41:21 +00:00
dkl%redhat.com
14542c62c7 Update to HEAD 2001-12-03
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@109510 18797224-902f-48f8-a5cc-f745e15eee43
2001-12-03 04:06:19 +00:00
dkl%redhat.com
38ebcba576 Fixed error in AddFDef
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@108598 18797224-902f-48f8-a5cc-f745e15eee43
2001-11-20 18:40:38 +00:00
dkl%redhat.com
a5502157a9 Update to HEAD - November 18, 2001
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@108470 18797224-902f-48f8-a5cc-f745e15eee43
2001-11-19 05:57:30 +00:00
(no author)
ba69b37618 This commit was manufactured by cvs2svn to create branch
'Bugzilla_PgSQL_branch'.

git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@108456 18797224-902f-48f8-a5cc-f745e15eee43
2001-11-18 22:20:21 +00:00
dkl%redhat.com
22b863a5e9 Synced up with CVS HEAD and created Bugzilla_PgSQL_branch_sync tag
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@107700 18797224-902f-48f8-a5cc-f745e15eee43
2001-11-08 23:03:10 +00:00
dkl%redhat.com
3e54979994 Fixed conflict in Bug.pm, removal of tabs from lots of files.
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@107385 18797224-902f-48f8-a5cc-f745e15eee43
2001-11-06 01:21:11 +00:00
dkl%redhat.com
d73ca44c76 Add new cpan module dependencies
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@107356 18797224-902f-48f8-a5cc-f745e15eee43
2001-11-05 21:43:11 +00:00
dkl%redhat.com
a4fc52b12e Updates and bug fixes
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@107354 18797224-902f-48f8-a5cc-f745e15eee43
2001-11-05 21:10:15 +00:00
dkl%redhat.com
353baca797 New SQL utility functions. Changes in buglist.cgi to improve queries.
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@106967 18797224-902f-48f8-a5cc-f745e15eee43
2001-11-01 15:35:03 +00:00
dkl%redhat.com
4618ab6c36 Initial checkin of pgsetup.pl. Utility for setting up Bugzilla database in PostgreSQL.
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@106569 18797224-902f-48f8-a5cc-f745e15eee43
2001-10-29 20:15:50 +00:00
justdave%syndicomm.com
faaed9c15f initial commit of PgSQL megapatch v0.2
git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@106532 18797224-902f-48f8-a5cc-f745e15eee43
2001-10-29 07:49:05 +00:00
(no author)
675f64d0ae This commit was manufactured by cvs2svn to create branch
'Bugzilla_PgSQL_branch'.

git-svn-id: svn://10.0.0.236/branches/Bugzilla_PgSQL_branch@106501 18797224-902f-48f8-a5cc-f745e15eee43
2001-10-28 03:41:01 +00:00
383 changed files with 106012 additions and 98705 deletions

View File

@@ -1,381 +0,0 @@
# -*- Mode: makefile -*-
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Communicator client code, released
# March 31, 1998.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = js
LIBRARY_NAME = mozjs
LIB_IS_C_ONLY = 1
GRE_MODULE = 1
ifeq ($(OS_ARCH),WINNT)
LIBRARY_NAME = js$(MOZ_BITS)$(VERSION_NUMBER)
RESFILE = js$(MOZ_BITS)40.res
endif
PACKAGE_FILE = js.pkg
# JavaScript must be built shared, even for static builds, as it is used by
# other modules which are always built shared. Failure to do so results in
# the js code getting copied into xpinstall and jsd as well as mozilla-bin,
# and then the static data cells used for locking no longer work.
FORCE_SHARED_LIB = 1
CSRCS = \
jsapi.c \
jsarena.c \
jsarray.c \
jsatom.c \
jsbool.c \
jscntxt.c \
jsdate.c \
jsdbgapi.c \
jsdhash.c \
jsdtoa.c \
jsemit.c \
jsexn.c \
jsfun.c \
jsgc.c \
jshash.c \
jsinterp.c \
jslock.c \
jslog2.c \
jslong.c \
jsmath.c \
jsnum.c \
jsobj.c \
jsopcode.c \
jsparse.c \
jsprf.c \
jsregexp.c \
jsscan.c \
jsscope.c \
jsscript.c \
jsstr.c \
jsutil.c \
jsxdrapi.c \
jsxml.c \
prmjtime.c \
$(NULL)
EXPORTS = \
jsautocfg.h \
js.msg \
jsapi.h \
jsarray.h \
jsarena.h \
jsatom.h \
jsbit.h \
jsbool.h \
jsclist.h \
jscntxt.h \
jscompat.h \
jsconfig.h \
jsdate.h \
jsdbgapi.h \
jsdhash.h \
jsemit.h \
jsfun.h \
jsgc.h \
jshash.h \
jsinterp.h \
jslock.h \
jslong.h \
jsmath.h \
jsnum.h \
jsobj.h \
jsopcode.tbl \
jsopcode.h \
jsosdep.h \
jsotypes.h \
jsparse.h \
jsprf.h \
jsprvtd.h \
jspubtd.h \
jsregexp.h \
jsscan.h \
jsscope.h \
jsscript.h \
jsstddef.h \
jsstr.h \
jstypes.h \
jsutil.h \
jsxdrapi.h \
jsxml.h \
$(NULL)
ifeq ($(OS_ARCH),WINNT)
EXPORTS += jscpucfg.h
endif
FDLIBM_LIBRARY = fdlibm/$(LIB_PREFIX)fdm.$(LIB_SUFFIX)
JSMATH_PRELINK = jsmathtemp.o
JS_SAFE_ARENA = 1
DASH_R = -r
include $(topsrcdir)/config/config.mk
EXTRA_DSO_LDOPTS += $(NSPR_LIBS)
ifeq (,$(filter-out OS2 WINNT,$(OS_ARCH)))
SHARED_LIBRARY_LIBS += $(FDLIBM_LIBRARY)
endif
# When using gcc the assembly is inlined in the C-file (see jslock.c)
ifeq ($(OS_ARCH),SunOS)
ifneq ($(OS_TEST),i86pc)
ifndef GNU_CC
ASFILES = lock_$(OS_ARCH).s
endif
endif
endif
ifndef BUILD_OPT
MOCHAFILE = 1
endif
ifndef NSBUILDROOT
JSJAVA_STUBHEADERS = \
-I$(topsrcdir)/sun-java/include/_gen \
-I$(topsrcdir)/sun-java/netscape/javascript/_jri \
-I$(topsrcdir)/sun-java/netscape/security/_jri
else
JSJAVA_STUBHEADERS = -I$(JRI_GEN_DIR) -I$(JDK_GEN_DIR)
endif
JSJAVA_CFLAGS = \
-I$(topsrcdir)/sun-java/md-include \
-I$(topsrcdir)/sun-java/include \
$(JSJAVA_STUBHEADERS)
include $(topsrcdir)/config/rules.mk
DEFINES += -DEXPORT_JS_API
INCLUDES += -I$(srcdir)
# MSVC '-Gy' cc flag and '/OPT:REF' linker flag cause JS_GetArgument and
# JS_GetLocalVariable to be folded to the same address by the linker,
# leading to a crash on startup. See bug 151066. So, in optimized builds,
# add the /OPT:NOICF flag, which turns off 'identical COMDAT folding'.
#
# N.B.: 'identical COMDAT folding' that folds functions whose addresses
# are taken violates the ISO C and C++ standards.
ifndef MOZ_DEBUG
ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
LDFLAGS += /OPT:NOICF
endif
endif
GARBAGE += $(JSMATH_PRELINK) jscpucfg.o jsautocfg.h jsautocfg.tmp jscpucfg
ifneq (,$(CROSS_COMPILE)$(filter-out WINNT,$(OS_ARCH)))
TARGETS += jscpucfg$(HOST_BIN_SUFFIX)
endif
ifdef JS_SAFE_ARENA
DEFINES += -DJS_USE_SAFE_ARENA
endif
ifdef JS_THREADSAFE
DEFINES += -DJS_THREADSAFE
endif
ifdef JS_NO_THIN_LOCKS
DEFINES += -DJS_USE_ONLY_NSPR_LOCKS
endif
ifdef JS_VERSION
DEFINES += -DJS_VERSION=$(JS_VERSION)
endif
ifneq ($(findstring -L,$(NSPR_LIBS)),)
NSPR_STATIC_PATH = $(subst -L,,$(findstring -L,$(NSPR_LIBS)))
else
NSPR_STATIC_PATH = $(DIST)/lib
endif
LDFLAGS += $(pathsubst -l%,$(NSPR_STATIC_PATH)/%.a,$(NSPR_LIBS))
# BeOS and HP-UX do not require the extra linking of "-lm"
ifeq (,$(filter BeOS HP-UX WINNT OpenVMS,$(OS_ARCH)))
LDFLAGS += -lm
endif
# Prevent floating point errors caused by VC++ optimizations
ifeq ($(OS_ARCH)_$(GNU_CC),WINNT_)
ifeq (,$(filter-out 1200 1300 1310,$(_MSC_VER)))
CFLAGS += /Op
else
CFLAGS += /fp:precise
endif
endif # WINNT
ifeq ($(OS_ARCH),FreeBSD)
LDFLAGS += -pthread
endif
ifeq ($(OS_ARCH),IRIX)
ifdef USE_N32
DASH_R += -n32
endif
endif
ifeq ($(OS_ARCH),Linux)
LDFLAGS += -ldl
endif
ifeq ($(OS_ARCH),OSF1)
LDFLAGS += -lc_r
endif
ifeq ($(OS_ARCH),SunOS)
ifeq ($(TARGET_CPU),sparc)
ifdef JS_ULTRASPARC_OPTS
DEFINES += -DULTRA_SPARC
ifdef GNU_CC
CFLAGS += -Wa,-xarch=v8plus,-DULTRA_SPARC,-P,-L,-D_ASM,-D__STDC__=0
CXXFLAGS += -Wa,-xarch=v8plus,-DULTRA_SPARC,-P,-L,-D_ASM,-D__STDC__=0,-K,PIC
else
ASFLAGS += -xarch=v8plus -DULTRA_SPARC -P -L -D_ASM -D__STDC__=0 -K PIC
endif # GNU_CC
endif # JS_ULTRASPARC_OPTS
endif
ifeq ($(OS_RELEASE),4.1)
LDFLAGS += -ldl -lnsl
else
LDFLAGS += -lposix4 -ldl -lnsl -lsocket
endif
endif
ifeq ($(OS_ARCH),QNX)
ifneq ($(OS_TARGET),NTO)
# Don't use wildcard here, because we only want this resolved at link time.
OBJS += fdlibm/*.o
endif
endif
ifeq ($(OS_ARCH),IRIX)
ifndef GNU_CC
_COMPILE_CFLAGS = $(patsubst -O%,-O1,$(COMPILE_CFLAGS))
jsapi.o jsarena.o jsarray.o jsatom.o jsemit.o jsfun.o jsinterp.o jsregexp.o jsparse.o jsopcode.o jsscript.o: %.o: %.c Makefile.in
$(REPORT_BUILD)
@$(MAKE_DEPS_AUTO)
$(CC) -o $@ -c $(_COMPILE_CFLAGS) $<
endif
endif
# On OS/2 & win32 we are already linking against fdlibm, so don't bother
# creating jsmathtemp
ifeq (,$(filter OS2 WINNT OpenVMS,$(OS_ARCH)))
# special rule for jsmath.o since we want to incrementally link
# against fdlibm to pull in only what is needed
# Do this in a single step to avoid dependency problems
jsmath.o: jsmath.c $(FDLIBM_LIBRARY) Makefile.in
$(REPORT_BUILD)
@$(MAKE_DEPS_AUTO)
$(ELOG) $(CC) $(OUTOPTION)$(JSMATH_PRELINK) -c $(COMPILE_CFLAGS) $<
ifeq ($(OS_ARCH),QNX)
ifneq ($(OS_TARGET),NTO)
@cp $(JSMATH_PRELINK) $@
else
$(LD) $(DASH_R) -o $@ $(JSMATH_PRELINK) $(FDLIBM_LIBRARY)
endif
else
$(LD) $(DASH_R) -o $@ $(JSMATH_PRELINK) $(FDLIBM_LIBRARY)
endif
@$(RM) -f $(JSMATH_PRELINK)
else
# Create dependency so we build fdlibm
jsmath.o: $(FDLIBM_LIBRARY) Makefile.in
endif
# An AIX Optimization bug causes PR_dtoa() & JS_dtoa to produce wrong result.
# This suppresses optimization for this single compilation unit.
ifeq ($(OS_ARCH),AIX)
jsatom.o: jsatom.c Makefile.in
$(REPORT_BUILD)
@$(MAKE_DEPS_AUTO)
$(CC) -o $@ -c $(filter-out $(MOZ_OPTIMIZE_FLAGS), $(COMPILE_CFLAGS)) $<
jsdtoa.o: jsdtoa.c Makefile.in
$(REPORT_BUILD)
@$(MAKE_DEPS_AUTO)
$(CC) -o $@ -c $(filter-out $(MOZ_OPTIMIZE_FLAGS), $(COMPILE_CFLAGS)) $<
endif
$(FDLIBM_LIBRARY):
$(MAKE) -C $(@D) $(@F)
jsopcode.h jsopcode.c: jsopcode.tbl
ifeq (,$(CROSS_COMPILE)$(filter-out WINNT,$(OS_ARCH)))
jsautocfg.h:
touch $@
else
jsautocfg.h: jscpucfg$(HOST_BIN_SUFFIX)
@rm -f $@ jsautocfg.tmp
./jscpucfg > jsautocfg.tmp
mv jsautocfg.tmp $@
endif
# jscpucfg is a strange target
# Needs to be built with the host compiler but needs to include
# the mdcpucfg for the target so it needs the appropriate target defines
ifdef HOST_NSPR_MDCPUCFG
HOST_CC := $(HOST_CC) -DMDCPUCFG=$(TARGET_NSPR_MDCPUCFG)
endif
ifeq ($(OS_ARCH),QNX)
ifneq ($(OS_TARGET),NTO)
# QNX's compiler apparently can't build a binary directly from a source file.
jscpucfg.o: jscpucfg.c Makefile.in
$(HOST_CC) $(HOST_CFLAGS) -c $(DEFINES) $(NSPR_CFLAGS) -o $@ $<
jscpucfg: jscpucfg.o
$(HOST_CC) $(HOST_CFLAGS) $(DEFINES) -o $@ $<
endif
else
jscpucfg$(HOST_BIN_SUFFIX): jscpucfg.c Makefile.in
$(HOST_CC) $(HOST_CFLAGS) $(DEFINES) $(NSPR_CFLAGS) $(OUTOPTION)$@ $<
endif

View File

@@ -1,374 +0,0 @@
# -*- Mode: makefile -*-
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Communicator client code, released
# March 31, 1998.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Michael Ang <mang@subcarrier.org>
# Kevin Buhr <buhr@stat.wisc.edu>
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
#
# JSRef GNUmake makefile.
#
# Note: dependency rules are missing for some files (some
# .h, all .msg, etc.) Re-make clean if in doubt.
#
DEPTH = .
include config.mk
#NS_USE_NATIVE = 1
ifdef USE_MSVC
OTHER_LIBS += fdlibm/$(OBJDIR)/fdlibm.lib
else
OTHER_LIBS += -Lfdlibm/$(OBJDIR) -lfdm
endif
ifdef JS_THREADSAFE
DEFINES += -DJS_THREADSAFE
INCLUDES += -I../../dist/$(OBJDIR)/include
ifdef USE_MSVC
OTHER_LIBS += ../../dist/$(OBJDIR)/lib/libnspr${NSPR_LIBSUFFIX}.lib
else
OTHER_LIBS += -L../../dist/$(OBJDIR)/lib -lnspr${NSPR_LIBSUFFIX}
endif
endif
ifdef JS_NO_THIN_LOCKS
DEFINES += -DJS_USE_ONLY_NSPR_LOCKS
endif
ifdef JS_HAS_FILE_OBJECT
DEFINES += -DJS_HAS_FILE_OBJECT
endif
#
# XCFLAGS may be set in the environment or on the gmake command line
#
CFLAGS += $(OPTIMIZER) $(OS_CFLAGS) $(DEFINES) $(INCLUDES) $(XCFLAGS)
LDFLAGS = $(XLDFLAGS)
ifndef NO_LIBM
LDFLAGS += -lm
endif
# Prevent floating point errors caused by VC++ optimizations
ifeq ($(OS_ARCH),WINNT)
CFLAGS += /Op
endif # WINNT
#
# Ask perl what flags it was built with, so we can build js with similar flags
# and link properly. Viva gmake.
#
ifdef JS_PERLCONNECT
DEFINES += -DPERLCONNECT -D_GNU_SOURCE
PERLCFLAGS := $(shell perl -MExtUtils::Embed -e ccopts)
PERLLDFLAGS := $(shell perl -MExtUtils::Embed -e ldopts)
# perl erroneously reports compiler flag -rdynamic (interpreted by ld
# as -r) when it really meant -export-dynamic.
PERLLDFLAGS := $(subst -rdynamic,-export-dynamic,$(PERLLDFLAGS))
CFLAGS += $(PERLCFLAGS)
#LDFLAGS += $(PERLLDFLAGS) #PH removed this assgnment
INCLUDES += -I. #needed for perlconnect/jsperl.c
endif
#
# Server-related changes :
#
ifdef NES40
DEFINES += -DNES40
endif
#
# Line editing support.
# Define JS_READLINE or JS_EDITLINE to enable line editing in the
# js command-line interpreter.
#
ifdef JS_READLINE
# For those platforms with the readline library installed.
DEFINES += -DEDITLINE
PROG_LIBS += -lreadline -ltermcap
else
ifdef JS_EDITLINE
# Use the editline library, built locally.
PREDIRS += editline
DEFINES += -DEDITLINE
PROG_LIBS += editline/$(OBJDIR)/libedit.a
endif
endif
# For purify
PURE_CFLAGS = -DXP_UNIX $(OPTIMIZER) $(PURE_OS_CFLAGS) $(DEFINES) \
$(INCLUDES) $(XCFLAGS)
#
# JS file lists
#
JS_HFILES = \
jsarray.h \
jsatom.h \
jsbool.h \
jsconfig.h \
jscntxt.h \
jsdate.h \
jsemit.h \
jsexn.h \
jsfun.h \
jsgc.h \
jsinterp.h \
jslibmath.h \
jslock.h \
jsmath.h \
jsnum.h \
jsobj.h \
jsopcode.h \
jsparse.h \
jsarena.h \
jsclist.h \
jsdhash.h \
jsdtoa.h \
jshash.h \
jslong.h \
jsosdep.h \
jstypes.h \
jsprvtd.h \
jspubtd.h \
jsregexp.h \
jsscan.h \
jsscope.h \
jsscript.h \
jsstr.h \
jsxdrapi.h \
jsxml.h \
$(NULL)
API_HFILES = \
jsapi.h \
jsdbgapi.h \
$(NULL)
OTHER_HFILES = \
jsbit.h \
jscompat.h \
jscpucfg.h \
jsotypes.h \
jsstddef.h \
prmjtime.h \
resource.h \
jsopcode.tbl \
js.msg \
jsshell.msg \
$(NULL)
ifndef PREBUILT_CPUCFG
OTHER_HFILES += $(OBJDIR)/jsautocfg.h
endif
HFILES = $(JS_HFILES) $(API_HFILES) $(OTHER_HFILES)
JS_CFILES = \
jsapi.c \
jsarena.c \
jsarray.c \
jsatom.c \
jsbool.c \
jscntxt.c \
jsdate.c \
jsdbgapi.c \
jsdhash.c \
jsdtoa.c \
jsemit.c \
jsexn.c \
jsfun.c \
jsgc.c \
jshash.c \
jsinterp.c \
jslock.c \
jslog2.c \
jslong.c \
jsmath.c \
jsnum.c \
jsobj.c \
jsopcode.c \
jsparse.c \
jsprf.c \
jsregexp.c \
jsscan.c \
jsscope.c \
jsscript.c \
jsstr.c \
jsutil.c \
jsxdrapi.c \
jsxml.c \
prmjtime.c \
$(NULL)
PREDIRS += fdlibm
ifdef USE_MSVC
FDLIBM_LIBRARY = fdlibm/$(OBJDIR)/fdlibm.lib
else
FDLIBM_LIBRARY = fdlibm/$(OBJDIR)/libfdm.a
endif
JSMATH_PRELINK = $(OBJDIR)/jsmathtemp.o
# Flag for incremental linking
DASH_R = -r
ifeq ($(OS_ARCH),QNX)
ifneq ($(OS_TARGET),NTO)
# Don't use wildcard here, because we only want this resolved at link time.
OBJS += fdlibm/*.o
endif
endif
ifdef JS_LIVECONNECT
DIRS += liveconnect
endif
ifdef JS_PERLCONNECT
JS_CFILES += perlconnect/jsperl.c
endif
ifdef JS_HAS_FILE_OBJECT
JS_CFILES += jsfile.c
JS_HFILES += jsfile.h
endif
LIB_CFILES = $(JS_CFILES)
LIB_ASFILES := $(wildcard *_$(OS_ARCH).s)
PROG_CFILES = js.c
ifdef USE_MSVC
LIBRARY = $(OBJDIR)/js32.lib
SHARED_LIBRARY = $(OBJDIR)/js32.dll
PROGRAM = $(OBJDIR)/js.exe
else
LIBRARY = $(OBJDIR)/libjs.a
SHARED_LIBRARY = $(OBJDIR)/libjs.$(SO_SUFFIX)
PROGRAM = $(OBJDIR)/js
ifdef JS_PERLCONNECT
PROG_LIBS += $(PERLLDFLAGS)
endif
endif
include rules.mk
MOZ_DEPTH = ../..
include jsconfig.mk
nsinstall-target:
cd ../../config; $(MAKE) OBJDIR=$(OBJDIR) OBJDIR_NAME=$(OBJDIR)
ifdef USE_MSVC
$(PROGRAM): $(PROG_OBJS) $(LIBRARY) $(FDLIBM_LIBRARY)
link.exe -out:"$@" $(EXE_LINK_FLAGS) $^
else
$(PROGRAM): $(PROG_OBJS) $(LIBRARY) $(FDLIBM_LIBRARY)
$(CC) -o $@ $(CFLAGS) $(PROG_OBJS) $(LIBRARY) $(LDFLAGS) $(OTHER_LIBS) \
$(PROG_LIBS)
endif
$(PROGRAM).pure: $(PROG_OBJS) $(LIBRARY)
purify $(PUREFLAGS) \
$(CC) -o $@ $(PURE_OS_CFLAGS) $(PROG_OBJS) $(LIBRARY) $(LDFLAGS) \
$(OTHER_LIBS) $(PROG_LIBS)
ifndef PREBUILT_CPUCFG
$(HFILES) $(CFILES): $(OBJDIR)/jsautocfg.h
$(OBJDIR)/jsautocfg.h: $(OBJDIR)/jscpucfg
rm -f $@
$(OBJDIR)/jscpucfg > $@
$(OBJDIR)/jscpucfg: $(OBJDIR)/jscpucfg.o
$(CC) -o $@ $(OBJDIR)/jscpucfg.o
# Look in OBJDIR to find jsautocfg.h
INCLUDES += -I$(OBJDIR)
# Add to TARGETS for clobber rule
TARGETS += $(OBJDIR)/jsautocfg.h $(OBJDIR)/jscpucfg \
$(OBJDIR)/jscpucfg.o $(OBJDIR)/jsmathtemp.o
endif
# special rule for jsmath.o since we want to incrementally link
# against fdlibm to pull in only what is needed
$(OBJDIR)/jsmath.o: jsmath.c jsmath.h jslibmath.h $(FDLIBM_LIBRARY)
ifneq (,$(filter OS2 WINNT,$(OS_ARCH)))
$(CC) -Fo$(JSMATH_PRELINK) -c $(CFLAGS) $<
else
$(CC) -o $(JSMATH_PRELINK) -c $(CFLAGS) $<
endif
ifeq ($(OS_ARCH),QNX)
ifneq ($(OS_TARGET),NTO)
@cp $(JSMATH_PRELINK) $@
else
$(LD) $(DASH_R) -o $@ $(JSMATH_PRELINK) $(FDLIBM_LIBRARY)
endif
else
ifdef USE_MSVC
@echo Warning: to use $(LIBRARY) must also link against $(FDLIBM_LIBRARY)
@cp $(JSMATH_PRELINK) $@
endif
$(LD) $(DASH_R) -o $@ $(JSMATH_PRELINK) $(FDLIBM_LIBRARY)
endif
# Note: generated headers must be built before descending
# into fdlibm directory
$(FDLIBM_LIBRARY) :
$(MAKE) -C fdlibm -f Makefile.ref $(@F)
#
# Hardwire dependencies on jsopcode.tbl
#
jsopcode.h jsopcode.c: jsopcode.tbl
-include $(DEPENDENCIES)
TARNAME = jsref.tar
TARFILES = files `cat files`
SUFFIXES: .i
%.i: %.c
$(CC) -C -E $(CFLAGS) $< > $*.i

View File

@@ -1,826 +0,0 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
-
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- http://www.mozilla.org/MPL/
-
- Software distributed under the License is distributed on an "AS IS" basis,
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- for the specific language governing rights and limitations under the
- License.
-
- The Original Code is Mozilla Communicator client code, released
- March 31, 1998.
-
- The Initial Developer of the Original Code is
- Netscape Communications Corporation.
- Portions created by the Initial Developer are Copyright (C) 1998-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- either of the GNU General Public License Version 2 or later (the "GPL"),
- or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- in which case the provisions of the GPL or the LGPL are applicable instead
- of those above. If you wish to allow use of your version of this file only
- under the terms of either the GPL or the LGPL, and not to allow others to
- use your version of this file under the terms of the MPL, indicate your
- decision by deleting the provisions above and replace them with the notice
- and other provisions required by the GPL or the LGPL. If you do not delete
- the provisions above, a recipient may use your version of this file under
- the terms of any one of the MPL, the GPL or the LGPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.5 [en] (WinNT; I) [Netscape]">
<title>JavaScript Reference Implementation (JSRef) README</title>
</head>
<body>
<h2>
Table of Contents</h2>
<ul>
<li>
<a href="#Introduction">Introduction</a></li>
<li>
<a href="#Build">Build conventions (standalone JS engine and shell)</a></li>
<li>
<a href="#Debugging">Debugging notes</a></li>
<li>
<a href="#Conventions">Naming and coding conventions</a></li>
<li>
<a href="#JSAPI">Using the JS API</a></li>
<li>
<a href="#Design">Design walk-through</a></li>
<li>
<a href="#Resources">Additional Resources (links, API docs, and newsgroups)</a></li>
</ul>
<h2>
<a NAME="Introduction"></a>Introduction</h2>
This is the README file for the&nbsp;<span CLASS=LXRSHORTDESC>JavaScript
Reference (JSRef, now better known as SpiderMonkey) implementation.</span>
It consists of build conventions
and instructions, source code conventions, a design walk-through, and a
brief file-by-file description of the source.
<p><span CLASS=LXRLONGDESC>JSRef builds a library or DLL containing the
JavaScript runtime (compiler, interpreter, decompiler, garbage collector,
atom manager, standard classes). It then compiles a small "shell" program
and links that with the library to make an interpreter that can be used
interactively and with test .js files to run scripts.&nbsp; The code has
no dependencies on the rest of the Mozilla codebase.</span>
<p><i>Quick start tip</i>: skip to "Using the JS API" below, build the
js shell, and play with the object named "it" (start by setting 'it.noisy
= true').
<h2>
<a NAME="Build"></a>Build conventions (standalone JS engine and shell)
(OUT OF DATE!)</h2>
These build directions refer only to building the standalone JavaScript
engine and shell.&nbsp; To build within the browser, refer to the <a
href="http://www.mozilla.org/build/">build
directions</a> on the mozilla.org website.
<p>By default, all platforms build a version of the JS engine that is <i>not</i>
threadsafe.&nbsp; If you require thread-safety, you must also populate
the <tt>mozilla/dist</tt> directory with <a href="http://www.mozilla.org/projects/nspr/reference/html/"
>NSPR</a>
headers and libraries.&nbsp; (NSPR implements a portable threading library,
among other things.&nbsp; The source is downloadable via <a href="http://www.mozilla.org/cvs.html">CVS</a>
from <tt><a href="http://lxr.mozilla.org/mozilla/source/nsprpub">mozilla/nsprpub</a></tt>.)&nbsp;
Next, you must define <tt>JS_THREADSAFE</tt> when building the JS engine,
either on the command-line (gmake/nmake) or in a universal header file.
<h3>
Windows</h3>
<ul>
<li>
Use MSVC 4.2 or 5.0.</li>
<li>
For building from the IDE use <tt>js/src/js.mdp</tt>.&nbsp; (<tt>js.mdp</tt>
is an MSVC4.2 project file, but if you load it into MSVC5, it will be converted
to the newer project file format.)&nbsp; <font color="#CC0000">NOTE: makefile.win
is an nmake file used only for building the JS-engine in the Mozilla browser.&nbsp;
Don't attempt to use it to build the standalone JS-engine.</font></li>
<li>
If you prefer to build from the command-line, use '<tt>nmake -f js.mak</tt>'</li>
<li>
Executable shell <tt>js.exe</tt> and runtime library <tt>js32.dll</tt>
are created in either <tt>js/src/Debug</tt> or <tt>js/src/Release</tt>.</li>
</ul>
<h3>
Macintosh</h3>
<ul>
<li>
Use CodeWarrior 3.x</li>
<li>
Load the project file <tt>js:src:macbuild:JSRef.mcp </tt>and select "Make"
from the menu.</li>
</ul>
<h3>
Unix</h3>
<ul>
<li>
Use '<tt>gmake -f Makefile.ref</tt>' to build. To compile optimized code,
pass <tt>BUILD_OPT=1</tt> on the gmake command line or preset it in the
environment or <tt>Makefile.ref</tt>.&nbsp; <font color="#CC0000">NOTE:
Do not attempt to use Makefile to build the standalone JavaScript engine.&nbsp;
This file is used only for building the JS-engine in the Mozilla browser.</font></li>
<li>
<font color="#000000">Each platform on which JS is built must have a <tt>*.mk</tt>
configuration file in the <tt>js/src/config</tt> directory.&nbsp; The configuration
file specifies the compiler/linker to be used and allows for customization
of command-line options.&nbsp; To date, the build system has been tested
on Solaris, AIX, HP/UX, OSF, IRIX, x86 Linux and Windows NT.</font></li>
<li>
<font color="#000000">Most platforms will work with either the vendor compiler
</font>or
<a href="ftp://prep.ai.mit.edu/pub/gnu">gcc</a>.&nbsp;
(Except that HP builds only work using the native compiler.&nbsp; gcc won't
link correctly with shared libraries on that platform.&nbsp; If someone
knows a way to fix this, <a href="mailto:wynholds@netscape.com">let us
know</a>.)</li>
<li>
<font color="#000000">If you define <tt>JS_LIVECONNECT</tt>, gmake will
descend into the liveconnect directory and build
<a href="http://lxr.mozilla.org/mozilla/source/js/src/liveconnect/README.html">LiveConnect</a>
after building the JS engine.</font></li>
<li>
To build a binary drop (a zip'ed up file of headers, libraries, binaries),
check out <tt>mozilla/config</tt> and <tt>mozilla/nsprpub/config</tt>.&nbsp;
Use '<tt>gmake -f Makefile.ref nsinstall-target all export ship</tt>'</li>
</ul>
<h2>
<a NAME="Debugging"></a>Debugging notes</h2>
<ul>
<li>
To turn on GC instrumentation, define <tt>JS_GCMETER</tt>.</li>
<ul>
<li>
To turn on GC mark-phase debugging, useful to find leaked objects by their
address, and to dump the GC heap, define <tt>GC_MARK_DEBUG</tt>.
See the code in jsgc.c around the declaration and use of
<tt>js_LiveThingToFind</tt>.</li>
<li>
To turn on the arena package's instrumentation, define <tt>JS_ARENAMETER</tt>.</li>
<li>
To turn on the hash table package's metering, define <tt>JS_HASHMETER</tt>.</li>
</ul>
<h2>
<a NAME="Conventions"></a>Naming and coding conventions</h2>
<ul>
<li>
Public function names begin with <tt>JS_</tt> followed by capitalized "intercaps",
e.g. <tt>JS_NewObject</tt>.</li>
<li>
Extern but library-private function names use a <tt>js_</tt> prefix and
mixed case, e.g. <tt>js_SearchScope</tt>.</li>
<li>
Most static function names have unprefixed, mixed-case names: <tt>GetChar</tt>.</li>
<li>
But static native methods of JS objects have lowercase, underscore-separated
or intercaps names, e.g., <tt>str_indexOf</tt>.</li>
<li>
And library-private and static data use underscores, not intercaps (but
library-private data do use a <tt>js_</tt> prefix).</li>
<li>
Scalar type names are lowercase and js-prefixed: <tt>jsdouble</tt>.</li>
<li>
Aggregate type names are JS-prefixed and mixed-case: <tt>JSObject.</tt></li>
<li>
Macros are generally <tt>ALL_CAPS </tt>and underscored, to call out potential
side effects, multiple uses of a formal argument, etc.</li>
<li>
Four spaces of indentation per statement nesting level.</li>
<li>
Tabs are taken to be eight spaces, and an Emacs magic comment at the top
of each file tries to help. If you're using MSVC or similar, you'll want
to set tab width to 8, and help convert these files to be space-filled.
<font color="#CC0000">Do not add hard tabs to source files; do remove them
whenever possible.</font></li>
<li>
DLL entry points have their return type expanded within a <tt>JS_PUBLIC_API()</tt>
macro call, to get the right Windows secret type qualifiers in the right
places for all build variants.</li>
<li>
Callback functions that might be called from a DLL are similarly macroized
with <tt>JS_STATIC_DLL_CALLBACK</tt> (if the function otherwise would be
static to hide its name) or <tt>JS_DLL_CALLBACK</tt> (this macro takes
no type argument; it should be used after the return type and before the
function name).</li>
</ul>
<h2>
<a NAME="JSAPI"></a>Using the JS API</h2>
<h4>
Starting up</h4>
<pre><tt>&nbsp;&nbsp;&nbsp; /*
&nbsp;&nbsp;&nbsp;&nbsp; * Tune this to avoid wasting space for shallow stacks, while saving on
&nbsp;&nbsp;&nbsp;&nbsp; * malloc overhead/fragmentation for deep or highly-variable stacks.
&nbsp;&nbsp;&nbsp;&nbsp; */
&nbsp;&nbsp;&nbsp; #define STACK_CHUNK_SIZE&nbsp;&nbsp;&nbsp; 8192
&nbsp;&nbsp;&nbsp; JSRuntime *rt;
&nbsp;&nbsp;&nbsp; JSContext *cx;
&nbsp;&nbsp;&nbsp; /* You need a runtime and one or more contexts to do anything with JS. */
&nbsp;&nbsp;&nbsp; rt = JS_NewRuntime(0x400000L);
&nbsp;&nbsp;&nbsp; if (!rt)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fail("can't create JavaScript runtime");
&nbsp;&nbsp;&nbsp; cx = JS_NewContext(rt, STACK_CHUNK_SIZE);
&nbsp;&nbsp;&nbsp; if (!cx)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fail("can't create JavaScript context");
&nbsp;&nbsp;&nbsp; /*
&nbsp;&nbsp;&nbsp;&nbsp; * The context definitely wants a global object, in order to have standard
&nbsp;&nbsp;&nbsp;&nbsp; * classes and functions like Date and parseInt.&nbsp; See below for details on
&nbsp;&nbsp;&nbsp;&nbsp; * JS_NewObject.
&nbsp;&nbsp;&nbsp;&nbsp; */
&nbsp;&nbsp;&nbsp; JSObject *globalObj;
&nbsp;&nbsp;&nbsp; globalObj = JS_NewObject(cx, &amp;my_global_class, 0, 0);
&nbsp;&nbsp;&nbsp; JS_InitStandardClasses(cx, globalObj);</tt></pre>
<h4>
Defining objects and properties</h4>
<pre><tt>&nbsp;&nbsp;&nbsp; /* Statically initialize a class to make "one-off" objects. */
&nbsp;&nbsp;&nbsp; JSClass my_class = {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "MyClass",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* All of these can be replaced with the corresponding JS_*Stub
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function pointers. */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my_addProperty, my_delProperty, my_getProperty, my_setProperty,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my_enumerate,&nbsp;&nbsp; my_resolve,&nbsp;&nbsp;&nbsp;&nbsp; my_convert,&nbsp;&nbsp;&nbsp;&nbsp; my_finalize
&nbsp;&nbsp;&nbsp; };
&nbsp;&nbsp;&nbsp; JSObject *obj;
&nbsp;&nbsp;&nbsp; /*
&nbsp;&nbsp;&nbsp;&nbsp; * Define an object named in the global scope that can be enumerated by
&nbsp;&nbsp;&nbsp;&nbsp; * for/in loops.&nbsp; The parent object is passed as the second argument, as
&nbsp;&nbsp;&nbsp;&nbsp; * with all other API calls that take an object/name pair.&nbsp; The prototype
&nbsp;&nbsp;&nbsp;&nbsp; * passed in is null, so the default object prototype will be used.
&nbsp;&nbsp;&nbsp;&nbsp; */
&nbsp;&nbsp;&nbsp; obj = JS_DefineObject(cx, globalObj, "myObject", &amp;my_class, NULL,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JSPROP_ENUMERATE);
&nbsp;&nbsp;&nbsp; /*
&nbsp;&nbsp;&nbsp;&nbsp; * Define a bunch of properties with a JSPropertySpec array statically
&nbsp;&nbsp;&nbsp;&nbsp; * initialized and terminated with a null-name entry.&nbsp; Besides its name,
&nbsp;&nbsp;&nbsp;&nbsp; * each property has a "tiny" identifier (MY_COLOR, e.g.) that can be used
&nbsp;&nbsp;&nbsp;&nbsp; * in switch statements (in a common my_getProperty function, for example).
&nbsp;&nbsp;&nbsp;&nbsp; */
&nbsp;&nbsp;&nbsp; enum my_tinyid {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MY_COLOR, MY_HEIGHT, MY_WIDTH, MY_FUNNY, MY_ARRAY, MY_RDONLY
&nbsp;&nbsp;&nbsp; };
&nbsp;&nbsp;&nbsp; static JSPropertySpec my_props[] = {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {"color",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MY_COLOR,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JSPROP_ENUMERATE},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {"height",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MY_HEIGHT,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JSPROP_ENUMERATE},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {"width",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MY_WIDTH,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JSPROP_ENUMERATE},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {"funny",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MY_FUNNY,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JSPROP_ENUMERATE},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {"array",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MY_ARRAY,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JSPROP_ENUMERATE},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {"rdonly",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MY_RDONLY,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JSPROP_READONLY},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {0}
&nbsp;&nbsp;&nbsp; };
&nbsp;&nbsp;&nbsp; JS_DefineProperties(cx, obj, my_props);
&nbsp;&nbsp;&nbsp; /*
&nbsp;&nbsp;&nbsp;&nbsp; * Given the above definitions and call to JS_DefineProperties, obj will
&nbsp;&nbsp;&nbsp;&nbsp; * need this sort of "getter" method in its class (my_class, above).&nbsp; See
&nbsp;&nbsp;&nbsp;&nbsp; * the example for the "It" class in js.c.
&nbsp;&nbsp;&nbsp;&nbsp; */
&nbsp;&nbsp;&nbsp; static JSBool
&nbsp;&nbsp;&nbsp; my_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (JSVAL_IS_INT(id)) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch (JSVAL_TO_INT(id)) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case MY_COLOR:&nbsp; *vp = . . .; break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case MY_HEIGHT: *vp = . . .; break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case MY_WIDTH:&nbsp; *vp = . . .; break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case MY_FUNNY:&nbsp; *vp = . . .; break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case MY_ARRAY:&nbsp; *vp = . . .; break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case MY_RDONLY: *vp = . . .; break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return JS_TRUE;
&nbsp;&nbsp;&nbsp; }</tt></pre>
<h4>
Defining functions</h4>
<pre><tt>&nbsp;&nbsp;&nbsp; /* Define a bunch of native functions first: */
&nbsp;&nbsp;&nbsp; static JSBool
&nbsp;&nbsp;&nbsp; my_abs(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; jsdouble x, z;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!JS_ValueToNumber(cx, argv[0], &amp;x))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return JS_FALSE;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; z = (x &lt; 0) ? -x : x;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return JS_NewDoubleValue(cx, z, rval);
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; . . .
&nbsp;&nbsp;&nbsp; /*
&nbsp;&nbsp;&nbsp;&nbsp; * Use a JSFunctionSpec array terminated with a null name to define a
&nbsp;&nbsp;&nbsp;&nbsp; * bunch of native functions.
&nbsp;&nbsp;&nbsp;&nbsp; */
&nbsp;&nbsp;&nbsp; static JSFunctionSpec my_functions[] = {
&nbsp;&nbsp;&nbsp; /*&nbsp;&nbsp;&nbsp; name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; native&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nargs&nbsp;&nbsp;&nbsp; */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {"abs",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my_abs,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {"acos",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my_acos,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {"asin",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my_asin,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; . . .
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {0}
&nbsp;&nbsp;&nbsp; };
&nbsp;&nbsp;&nbsp; /*
&nbsp;&nbsp;&nbsp;&nbsp; * Pass a particular object to define methods for it alone.&nbsp; If you pass
&nbsp;&nbsp;&nbsp;&nbsp; * a prototype object, the methods will apply to all instances past and
&nbsp;&nbsp;&nbsp;&nbsp; * future of the prototype's class (see below for classes).
&nbsp;&nbsp;&nbsp;&nbsp; */
&nbsp;&nbsp;&nbsp; JS_DefineFunctions(cx, globalObj, my_functions);</tt></pre>
<h4>
Defining classes</h4>
<pre><tt>&nbsp;&nbsp;&nbsp; /*
&nbsp;&nbsp;&nbsp;&nbsp; * This pulls together the above API elements by defining a constructor
&nbsp;&nbsp;&nbsp;&nbsp; * function, a prototype object, and properties of the prototype and of
&nbsp;&nbsp;&nbsp;&nbsp; * the constructor, all with one API call.
&nbsp;&nbsp;&nbsp;&nbsp; *
&nbsp;&nbsp;&nbsp;&nbsp; * Initialize a class by defining its constructor function, prototype, and
&nbsp;&nbsp;&nbsp;&nbsp; * per-instance and per-class properties.&nbsp; The latter are called "static"
&nbsp;&nbsp;&nbsp;&nbsp; * below by analogy to Java.&nbsp; They are defined in the constructor object's
&nbsp;&nbsp;&nbsp;&nbsp; * scope, so that 'MyClass.myStaticProp' works along with 'new MyClass()'.
&nbsp;&nbsp;&nbsp;&nbsp; *
&nbsp;&nbsp;&nbsp;&nbsp; * JS_InitClass takes a lot of arguments, but you can pass null for any of
&nbsp;&nbsp;&nbsp;&nbsp; * the last four if there are no such properties or methods.
&nbsp;&nbsp;&nbsp;&nbsp; *
&nbsp;&nbsp;&nbsp;&nbsp; * Note that you do not need to call JS_InitClass to make a new instance of
&nbsp;&nbsp;&nbsp;&nbsp; * that class -- otherwise there would be a chicken-and-egg problem making
&nbsp;&nbsp;&nbsp;&nbsp; * the global object -- but you should call JS_InitClass if you require a
&nbsp;&nbsp;&nbsp;&nbsp; * constructor function for script authors to call via new, and/or a class
&nbsp;&nbsp;&nbsp;&nbsp; * prototype object ('MyClass.prototype') for authors to extend with new
&nbsp;&nbsp;&nbsp;&nbsp; * properties at run-time. In general, if you want to support multiple
&nbsp;&nbsp;&nbsp;&nbsp; * instances that share behavior, use JS_InitClass.
&nbsp;&nbsp;&nbsp;&nbsp; */
&nbsp;&nbsp;&nbsp; protoObj = JS_InitClass(cx, globalObj, NULL, &amp;my_class,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* native constructor function and min arg count */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MyClass, 0,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* prototype object properties and methods -- these
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; will be "inherited" by all instances through
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delegation up the instance's prototype link. */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my_props, my_methods,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* class constructor properties and methods */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my_static_props, my_static_methods);</tt></pre>
<h4>
Running scripts</h4>
<pre><tt>&nbsp;&nbsp;&nbsp; /* These should indicate source location for diagnostics. */
&nbsp;&nbsp;&nbsp; char *filename;
&nbsp;&nbsp;&nbsp; uintN lineno;
&nbsp;&nbsp;&nbsp; /*
&nbsp;&nbsp;&nbsp;&nbsp; * The return value comes back here -- if it could be a GC thing, you must
&nbsp;&nbsp;&nbsp;&nbsp; * add it to the GC's "root set" with JS_AddRoot(cx, &amp;thing) where thing
&nbsp;&nbsp;&nbsp;&nbsp; * is a JSString *, JSObject *, or jsdouble *, and remove the root before
&nbsp;&nbsp;&nbsp;&nbsp; * rval goes out of scope, or when rval is no longer needed.
&nbsp;&nbsp;&nbsp;&nbsp; */
&nbsp;&nbsp;&nbsp; jsval rval;
&nbsp;&nbsp;&nbsp; JSBool ok;
&nbsp;&nbsp;&nbsp; /*
&nbsp;&nbsp;&nbsp;&nbsp; * Some example source in a C string.&nbsp; Larger, non-null-terminated buffers
&nbsp;&nbsp;&nbsp;&nbsp; * can be used, if you pass the buffer length to JS_EvaluateScript.
&nbsp;&nbsp;&nbsp;&nbsp; */
&nbsp;&nbsp;&nbsp; char *source = "x * f(y)";
&nbsp;&nbsp;&nbsp; ok = JS_EvaluateScript(cx, globalObj, source, strlen(source),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; filename, lineno, &amp;rval);
&nbsp;&nbsp;&nbsp; if (ok) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Should get a number back from the example source. */
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; jsdouble d;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok = JS_ValueToNumber(cx, rval, &amp;d);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; . . .
&nbsp;&nbsp;&nbsp; }</tt></pre>
<h4>
Calling functions</h4>
<pre><tt>&nbsp;&nbsp;&nbsp; /* Call a global function named "foo" that takes no arguments. */
&nbsp;&nbsp;&nbsp; ok = JS_CallFunctionName(cx, globalObj, "foo", 0, 0, &amp;rval);
&nbsp;&nbsp;&nbsp; jsval argv[2];
&nbsp;&nbsp;&nbsp; /* Call a function in obj's scope named "method", passing two arguments. */
&nbsp;&nbsp;&nbsp; argv[0] = . . .;
&nbsp;&nbsp;&nbsp; argv[1] = . . .;
&nbsp;&nbsp;&nbsp; ok = JS_CallFunctionName(cx, obj, "method", 2, argv, &amp;rval);</tt></pre>
<h4>
Shutting down</h4>
<pre><tt>&nbsp;&nbsp;&nbsp; /* For each context you've created: */
&nbsp;&nbsp;&nbsp; JS_DestroyContext(cx);
&nbsp;&nbsp;&nbsp; /* For each runtime: */
&nbsp;&nbsp;&nbsp; JS_DestroyRuntime(rt);
&nbsp;&nbsp;&nbsp; /* And finally: */
&nbsp;&nbsp;&nbsp; JS_ShutDown();</tt></pre>
<h4>
Debugging API</h4>
See the<tt> trap, untrap, watch, unwatch, line2pc</tt>, and <tt>pc2line</tt>
commands in <tt>js.c</tt>. Also the (scant) comments in <i>jsdbgapi.h</i>.
<h2>
<a NAME="Design"></a>Design walk-through</h2>
This section must be brief for now -- it could easily turn into a book.
<h4>
JS "JavaScript Proper"</h4>
JS modules declare and implement the JavaScript compiler, interpreter,
decompiler, GC and atom manager, and standard classes.
<p>JavaScript uses untyped bytecode and runtime type tagging of data values.
The <tt>jsval</tt> type is a signed machine word that contains either a
signed integer value (if the low bit is set), or a type-tagged pointer
or boolean value (if the low bit is clear). Tagged pointers all refer to
8-byte-aligned things in the GC heap.
<p>Objects consist of a possibly shared structural description, called
the map or scope; and unshared property values in a vector, called the
slots. Object properties are associated with nonnegative integers stored
in <tt>jsval</tt>'s, or with atoms (unique string descriptors) if named
by an identifier or a non-integral index expression.
<p>Scripts contain bytecode, source annotations, and a pool of string,
number, and identifier literals. Functions are objects that extend scripts
or native functions with formal parameters, a literal syntax, and a distinct
primitive type ("function").
<p>The compiler consists of a recursive-descent parser and a random-logic
rather than table-driven lexical scanner. Semantic and lexical feedback
are used to disambiguate hard cases such as missing semicolons, assignable
expressions ("lvalues" in C parlance), etc. The parser generates bytecode
as it parses, using fixup lists for downward branches and code buffering
and rewriting for exceptional cases such as for loops. It attempts no error
recovery. The interpreter executes the bytecode of top-level scripts, and
calls itself indirectly to interpret function bodies (which are also scripts).
All state associated with an interpreter instance is passed through formal
parameters to the interpreter entry point; most implicit state is collected
in a type named JSContext. Therefore, all API and almost all other functions
in JSRef take a JSContext pointer as their first argument.
<p>The decompiler translates postfix bytecode into infix source by consulting
a separate byte-sized code, called source notes, to disambiguate bytecodes
that result from more than one grammatical production.
<p>The GC is a mark-and-sweep, non-conservative (exact) collector. It
can allocate only fixed-sized things -- the current size is two machine
words. It is used to hold JS object and string descriptors (but not property
lists or string bytes), and double-precision floating point numbers. It
runs automatically only when maxbytes (as passed to <tt>JS_NewRuntime()</tt>)
bytes of GC things have been allocated and another thing-allocation request
is made. JS API users should call <tt>JS_GC()</tt> or <tt>JS_MaybeGC()</tt>
between script executions or from the branch callback, as often as necessary.
<p>An important point about the GC's "exactness": you must add roots for
new objects created by your native methods if you store references to them
into a non-JS structure in the malloc heap or in static data. Also, if
you make a new object in a native method, but do not store it through the
<tt>rval</tt>
result parameter (see math_abs in the "Using the JS API" section above)
so that it is in a known root, the object is guaranteed to survive only
until another new object is created. Either lock the first new object when
making two in a row, or store it in a root you've added, or store it via
rval.
See the <a href="http://www.mozilla.org/js/spidermonkey/gctips.html">GC tips</a>
document for more.
<p>The atom manager consists of a hash table associating strings uniquely
with scanner/parser information such as keyword type, index in script or
function literal pool, etc. Atoms play three roles in JSRef: as literals
referred to by unaligned 16-bit immediate bytecode operands, as unique
string descriptors for efficient property name hashing, and as members
of the root GC set for exact GC.
<p>Native objects and methods for arrays, booleans, dates, functions, numbers,
and strings are implemented using the JS API and certain internal interfaces
used as "fast paths".
<p>In general, errors are signaled by false or unoverloaded-null return
values, and are reported using <tt>JS_ReportError()</tt> or one of its
variants by the lowest level in order to provide the most detail. Client
code can substitute its own error reporting function and suppress errors,
or reflect them into Java or some other runtime system as exceptions, GUI
dialogs, etc..
<h2>
File walk-through (OUT OF DATE!)</h2>
<h4>
jsapi.c, jsapi.h</h4>
The public API to be used by almost all client code.&nbsp; If your client
code can't make do with <tt>jsapi.h</tt>, and must reach into a friend
or private js* file, please let us know so we can extend <tt>jsapi.h</tt>
to include what you need in a fashion that we can support over the long
run.
<h4>
jspubtd.h, jsprvtd.h</h4>
These files exist to group struct and scalar typedefs so they can be used
everywhere without dragging in struct definitions from N different files.
The <tt>jspubtd.h</tt> file contains public typedefs, and is included by
<tt>jsapi.h</tt>.
The <tt>jsprvtd.h</tt> file contains private typedefs and is included by
various .h files that need type names, but not type sizes or declarations.
<h4>
jsdbgapi.c, jsdbgapi.h</h4>
The Debugging API, still very much under development. Provided so far:
<ul>
<li>
Traps, with which breakpoints, single-stepping, step over, step out, and
so on can be implemented. The debugger will have to consult jsopcode.def
on its own to figure out where to plant trap instructions to implement
functions like step out, but a future jsdbgapi.h will provide convenience
interfaces to do these things. At most one trap per bytecode can be set.
When a script (<tt>JSScript</tt>) is destroyed, all traps set in its bytecode
are cleared.</li>
<li>
Watchpoints, for intercepting set operations on properties and running
a debugger-supplied function that receives the old value and a pointer
to the new one, which it can use to modify the new value being set.</li>
<li>
Line number to PC and back mapping functions. The line-to-PC direction
"rounds" toward the next bytecode generated from a line greater than or
equal to the input line, and may return the PC of a for-loop update part,
if given the line number of the loop body's closing brace. Any line after
the last one in a script or function maps to a PC one byte beyond the last
bytecode in the script. An example, from perfect.js:</li>
<pre><tt>14&nbsp;&nbsp; function perfect(n)
15&nbsp;&nbsp; {
16&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print("The perfect numbers up to " +&nbsp; n + " are:");
17
18&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // We build sumOfDivisors[i] to hold a string expression for
19&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // the sum of the divisors of i, excluding i itself.
20&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var sumOfDivisors = new ExprArray(n+1,1);
21&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (var divisor = 2; divisor &lt;= n; divisor++) {
22&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (var j = divisor + divisor; j &lt;= n; j += divisor) {
23&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sumOfDivisors[j] += " + " + divisor;
24&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
25&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // At this point everything up to 'divisor' has its sumOfDivisors
26&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // expression calculated, so we can determine whether it's perfect
27&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // already by evaluating.
28&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (eval(sumOfDivisors[divisor]) == divisor) {
29&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print("" + divisor + " = " + sumOfDivisors[divisor]);
30&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
31&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
32&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delete sumOfDivisors;
33&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print("That's all.");
34&nbsp;&nbsp; }</tt></pre>
The line number to PC and back mappings can be tested using the js program
with the following script:
<pre><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; load("perfect.js")
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(perfect)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dis(perfect)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (var ln = 0; ln &lt;= 40; ln++) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var pc = line2pc(perfect,ln)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var ln2 = pc2line(perfect,pc)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print("\tline " + ln + " => pc " + pc + " => line " + ln2)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</tt></pre>
The result of the for loop over lines 0 to 40 inclusive is:
<pre><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 0 => pc 0 => line 16
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 1 => pc 0 => line 16
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 2 => pc 0 => line 16
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 3 => pc 0 => line 16
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 4 => pc 0 => line 16
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 5 => pc 0 => line 16
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 6 => pc 0 => line 16
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 7 => pc 0 => line 16
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 8 => pc 0 => line 16
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 9 => pc 0 => line 16
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 10 => pc 0 => line 16
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 11 => pc 0 => line 16
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 12 => pc 0 => line 16
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 13 => pc 0 => line 16
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 14 => pc 0 => line 16
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 15 => pc 0 => line 16
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 16 => pc 0 => line 16
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 17 => pc 19 => line 20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 18 => pc 19 => line 20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 19 => pc 19 => line 20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 20 => pc 19 => line 20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 21 => pc 36 => line 21
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 22 => pc 53 => line 22
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 23 => pc 74 => line 23
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 24 => pc 92 => line 22
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 25 => pc 106 => line 28
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 26 => pc 106 => line 28
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 27 => pc 106 => line 28
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 28 => pc 106 => line 28
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 29 => pc 127 => line 29
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 30 => pc 154 => line 21
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 31 => pc 154 => line 21
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 32 => pc 161 => line 32
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 33 => pc 172 => line 33
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 34 => pc 172 => line 33
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 35 => pc 172 => line 33
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 36 => pc 172 => line 33
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 37 => pc 172 => line 33
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 38 => pc 172 => line 33
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 39 => pc 172 => line 33
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line 40 => pc 172 => line 33</tt></pre>
</ul>
<h4>
jsconfig.h</h4>
Various configuration macros defined as 0 or 1 depending on how <tt>JS_VERSION</tt>
is defined (as 10 for JavaScript 1.0, 11 for JavaScript 1.1, etc.). Not
all macros are tested around related code yet. In particular, JS 1.0 support
is missing from JSRef. JS 1.2 support will appear in a future JSRef release.
<br>&nbsp;
<h4>
js.c</h4>
The "JS shell", a simple interpreter program that uses the JS API and more
than a few internal interfaces (some of these internal interfaces could
be replaced by <tt>jsapi.h</tt> calls). The js program built from this
source provides a test vehicle for evaluating scripts and calling functions,
trying out new debugger primitives, etc.
<h4>
jsarray.*, jsbool.*, jdsdate.*, jsfun.*, jsmath.*, jsnum.*, jsstr.*</h4>
These file pairs implement the standard classes and (where they exist)
their underlying primitive types. They have similar structure, generally
starting with class definitions and continuing with internal constructors,
finalizers, and helper functions.
<h4>
jsobj.*, jsscope.*</h4>
These two pairs declare and implement the JS object system. All of the
following happen here:
<ul>
<li>
creating objects by class and prototype, and finalizing objects;</li>
<li>
defining, looking up, getting, setting, and deleting properties;</li>
<li>
creating and destroying properties and binding names to them.</li>
</ul>
The details of a native object's map (scope) are mostly hidden in
<tt>jsscope.[ch]</tt>.
<h4>
jsatom.c, jsatom.h</h4>
The atom manager. Contains well-known string constants, their atoms, the
global atom hash table and related state, the js_Atomize() function that
turns a counted string of bytes into an atom, and literal pool (<tt>JSAtomMap</tt>)
methods.
<h4>
jsgc.c, jsgc.h</h4>
[TBD]
<h4>
jsinterp.*, jscntxt.*</h4>
The bytecode interpreter, and related functions such as Call and AllocStack,
live in <i>jsinterp.c</i>. The JSContext constructor and destructor are
factored out into <i>jscntxt.c</i> for minimal linking when the compiler
part of JS is split from the interpreter part into a separate program.
<h4>
jsemit.*, jsopcode.tbl, jsopcode.*, jsparse.*, jsscan.*, jsscript.*</h4>
Compiler and decompiler modules. The <i>jsopcode.tbl</i> file is a C preprocessor
source that defines almost everything there is to know about JS bytecodes.
See its major comment for how to use it. For now, a debugger will use it
and its dependents such as <i>jsopcode.h</i> directly, but over time we
intend to extend <i>jsdbgapi.h</i> to hide uninteresting details and provide
conveniences. The code generator is split across paragraphs of code in
<i>jsparse.c</i>,
and the utility methods called on <tt>JSCodeGenerator</tt> appear in <i>jsemit.c</i>.
Source notes generated by <i>jsparse.c</i> and
<i>jsemit.c</i> are used
in <i>jsscript.c</i> to map line number to program counter and back.
<h4>
jstypes.h, jslog2.c</h4>
Fundamental representation types and utility macros. This file alone among
all .h files in JSRef must be included first by .c files. It is not nested
in .h files, as other prerequisite .h files generally are, since it is
also a direct dependency of most .c files and would be over-included if
nested in addition to being directly included. The one "not-quite-a-macro
macro" is the <tt>JS_CeilingLog2()</tt> function in <i>jslog2.c</i>.
<h4>
jsarena.c, jsarena.h</h4>
Last-In-First-Out allocation macros that amortize malloc costs and allow
for en-masse freeing. See the paper mentioned in prarena.h's major comment.
<h4>
jsutil.c, jsutil.h</h4>
The <tt>JS_ASSERT</tt> macro is used throughout JSRef source as a proof
device to make invariants and preconditions clear to the reader, and to
hold the line during maintenance and evolution against regressions or violations
of assumptions that it would be too expensive to test unconditionally at
run-time. Certain assertions are followed by run-time tests that cope with
assertion failure, but only where I'm too smart or paranoid to believe
the assertion will never fail...
<h4>
jsclist.h</h4>
Doubly-linked circular list struct and macros.
<h4>
jscpucfg.c</h4>
This standalone program generates <i>jscpucfg.h</i>, a header file containing
bytes per word and other constants that depend on CPU architecture and
C compiler type model. It tries to discover most of these constants by
running its own experiments on the build host, so if you are cross-compiling,
beware.
<h4>
prdtoa.c, prdtoa.h</h4>
David Gay's portable double-precision floating point to string conversion
code, with Permission To Use notice included.
<h4>
prhash.c, prhash.h</h4>
Portable, extensible hash tables. These use multiplicative hash for strength
reduction over division hash, yet with very good key distribution over
power of two table sizes. Collisions resolve via chaining, so each entry
burns a malloc and can fragment the heap.
<h4>
prlong.c, prlong.h</h4>
64-bit integer emulation, and compatible macros that use C's long long
type where it exists (my last company mapped long long to a 128-bit type,
but no real architecture does 128-bit ints yet).
<h4>
jsosdep.h</h4>
Annoying OS dependencies rationalized into a few "feature-test" macros
such as <tt>JS_HAVE_LONG_LONG</tt>.
<h4>
jsprf.*</h4>
Portable, buffer-overrun-resistant sprintf and friends. For no good reason
save lack of time, the %e, %f, and %g formats cause your system's native
sprintf, rather than <tt>JS_dtoa()</tt>, to be used. This bug doesn't affect
JSRef, because it uses its own <tt>JS_dtoa()</tt> call in <i>jsnum.c</i>
to convert from double to string, but it's a bug that we'll fix later,
and one you should be aware of if you intend to use a <tt>JS_*printf()</tt>&nbsp;
function with your own floating type arguments - various vendor sprintf's
mishandle NaN, +/-Inf, and some even print normal floating values inaccurately.
<h4>
prmjtime.c, prmjtime.h</h4>
Time functions. These interfaces are named in a way that makes local vs.
universal time confusion likely. Caveat emptor, and we're working on it.
To make matters worse, Java (and therefore JavaScript) uses "local" time
numbers (offsets from the epoch) in its Date class.
<h2>
<a NAME="Resources"></a>Additional Resources (links, API docs, and newsgroups)</h2>
<ul>
<li><a href ="http://www.mozilla.org/js/">http://www.mozilla.org/js/</a>
<li><a href ="http://www.mozilla.org/js/spidermonkey/">http://www.mozilla.org/js/spidermonkey/</a>
<li><a href ="news://news.mozilla.org/netscape.public.mozilla.jseng">news://news.mozilla.org/netscape.public.mozilla.jseng</a>
</ul>
</body>
</html>

View File

@@ -1,12 +0,0 @@
mozilla/js/src/*
mozilla/js/src/config/*
mozilla/js/src/fdlibm/*
mozilla/js/src/liveconnect/*
mozilla/js/src/liveconnect/_jni/*
mozilla/js/src/liveconnect/classes/*
mozilla/js/src/liveconnect/classes/netscape/*
mozilla/js/src/liveconnect/classes/netscape/javascript/*
mozilla/js/src/liveconnect/config/*
mozilla/js/src/liveconnect/macbuild/*
mozilla/js/src/liveconnect/macbuild/JavaSession/*
mozilla/js/src/macbuild/*

View File

@@ -1,166 +0,0 @@
# -*- Mode: makefile -*-
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Communicator client code, released
# March 31, 1998.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998-1999
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
ifdef JS_DIST
DIST = $(JS_DIST)
else
DIST = $(DEPTH)/../../dist/$(OBJDIR)
endif
# Set os+release dependent make variables
OS_ARCH := $(subst /,_,$(shell uname -s | sed /\ /s//_/))
# Attempt to differentiate between SunOS 5.4 and x86 5.4
OS_CPUARCH := $(shell uname -m)
ifeq ($(OS_CPUARCH),i86pc)
OS_RELEASE := $(shell uname -r)_$(OS_CPUARCH)
else
ifeq ($(OS_ARCH),AIX)
OS_RELEASE := $(shell uname -v).$(shell uname -r)
else
OS_RELEASE := $(shell uname -r)
endif
endif
ifeq ($(OS_ARCH),IRIX64)
OS_ARCH := IRIX
endif
# Handle output from win32 unames other than Netscape's version
ifeq (,$(filter-out Windows_95 Windows_98 CYGWIN_95-4.0 CYGWIN_98-4.10, $(OS_ARCH)))
OS_ARCH := WIN95
endif
ifeq ($(OS_ARCH),WIN95)
OS_ARCH := WINNT
OS_RELEASE := 4.0
endif
ifeq ($(OS_ARCH), Windows_NT)
OS_ARCH := WINNT
OS_MINOR_RELEASE := $(shell uname -v)
ifeq ($(OS_MINOR_RELEASE),00)
OS_MINOR_RELEASE = 0
endif
OS_RELEASE := $(OS_RELEASE).$(OS_MINOR_RELEASE)
endif
ifeq (CYGWIN_NT,$(findstring CYGWIN_NT,$(OS_ARCH)))
OS_RELEASE := $(patsubst CYGWIN_NT-%,%,$(OS_ARCH))
OS_ARCH := WINNT
endif
ifeq ($(OS_ARCH), CYGWIN32_NT)
OS_ARCH := WINNT
endif
# Virtually all Linux versions are identical.
# Any distinctions are handled in linux.h
ifeq ($(OS_ARCH),Linux)
OS_CONFIG := Linux_All
else
ifeq ($(OS_ARCH),dgux)
OS_CONFIG := dgux
else
ifeq ($(OS_ARCH),Darwin)
OS_CONFIG := Darwin
else
OS_CONFIG := $(OS_ARCH)$(OS_OBJTYPE)$(OS_RELEASE)
endif
endif
endif
ASFLAGS =
DEFINES =
ifeq ($(OS_ARCH), WINNT)
INSTALL = nsinstall
CP = cp
else
INSTALL = $(DEPTH)/../../dist/$(OBJDIR)/bin/nsinstall
CP = cp
endif
ifdef BUILD_OPT
OPTIMIZER = -O
DEFINES += -UDEBUG -DNDEBUG -UDEBUG_$(shell whoami)
OBJDIR_TAG = _OPT
else
ifdef USE_MSVC
OPTIMIZER = -Zi
else
OPTIMIZER = -g
endif
DEFINES += -DDEBUG -DDEBUG_$(shell whoami)
OBJDIR_TAG = _DBG
endif
SO_SUFFIX = so
NS_USE_NATIVE = 1
# Java stuff
CLASSDIR = $(DEPTH)/liveconnect/classes
JAVA_CLASSES = $(patsubst %.java,%.class,$(JAVA_SRCS))
TARGETS += $(addprefix $(CLASSDIR)/$(OBJDIR)/$(JARPATH)/, $(JAVA_CLASSES))
JAVAC = $(JDK)/bin/javac
JAVAC_FLAGS = -classpath "$(CLASSPATH)" -d $(CLASSDIR)/$(OBJDIR)
ifeq ($(OS_ARCH), WINNT)
SEP = ;
else
SEP = :
endif
CLASSPATH = $(JDK)/lib/classes.zip$(SEP)$(CLASSDIR)/$(OBJDIR)
include $(DEPTH)/config/$(OS_CONFIG).mk
# Name of the binary code directories
ifdef BUILD_IDG
OBJDIR = $(OS_CONFIG)$(OBJDIR_TAG).OBJD
else
OBJDIR = $(OS_CONFIG)$(OBJDIR_TAG).OBJ
endif
VPATH = $(OBJDIR)
# Automatic make dependencies file
DEPENDENCIES = $(OBJDIR)/.md
LCJAR = js15lc30.jar
# Library name
LIBDIR := lib
ifeq ($(CPU_ARCH), x86_64)
LIBDIR := lib64
endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -1,279 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* This is the JavaScript error message file.
*
* The format for each JS error message is:
*
* MSG_DEF(<SYMBOLIC_NAME>, <ERROR_NUMBER>, <ARGUMENT_COUNT>, <EXCEPTION_NAME>,
* <FORMAT_STRING>)
*
* where ;
* <SYMBOLIC_NAME> is a legal C identifer that will be used in the
* JS engine source.
*
* <ERROR_NUMBER> is an unique integral value identifying this error.
*
* <ARGUMENT_COUNT> is an integer literal specifying the total number of
* replaceable arguments in the following format string.
*
* <EXCEPTION_NAME> is an exception index from the enum in jsexn.c;
* JSEXN_NONE for none. The given exception index will be raised by the
* engine when the corresponding error occurs.
*
* <FORMAT_STRING> is a string literal, optionally containing sequences
* {X} where X is an integer representing the argument number that will
* be replaced with a string value when the error is reported.
*
* e.g.
*
* MSG_DEF(JSMSG_NOT_A_SUBSPECIES, 73, JSEXN_NONE, 2,
* "{0} is not a member of the {1} family")
*
* can be used:
*
* JS_ReportErrorNumber(JSMSG_NOT_A_SUBSPECIES, "Rhino", "Monkey");
*
* to report:
*
* "Rhino is not a member of the Monkey family"
*
* Before adding a new MSG_DEF at the end, look for JSMSG_UNUSED<n> free
* index placeholders in the middle of the list.
*/
MSG_DEF(JSMSG_NOT_AN_ERROR, 0, 0, JSEXN_NONE, "<Error #0 is reserved>")
MSG_DEF(JSMSG_NOT_DEFINED, 1, 1, JSEXN_REFERENCEERR, "{0} is not defined")
MSG_DEF(JSMSG_NO_REG_EXPS, 2, 1, JSEXN_INTERNALERR, "sorry, regular expression are not supported")
MSG_DEF(JSMSG_MORE_ARGS_NEEDED, 3, 3, JSEXN_NONE, "{0} requires more than {1} argument{2}")
MSG_DEF(JSMSG_BAD_CHAR, 4, 1, JSEXN_NONE, "invalid format character {0}")
MSG_DEF(JSMSG_BAD_TYPE, 5, 1, JSEXN_NONE, "unknown type {0}")
MSG_DEF(JSMSG_CANT_LOCK, 6, 0, JSEXN_NONE, "can't lock memory")
MSG_DEF(JSMSG_CANT_UNLOCK, 7, 0, JSEXN_NONE, "can't unlock memory")
MSG_DEF(JSMSG_INCOMPATIBLE_PROTO, 8, 3, JSEXN_TYPEERR, "{0}.prototype.{1} called on incompatible {2}")
MSG_DEF(JSMSG_NO_CONSTRUCTOR, 9, 1, JSEXN_NONE, "{0} has no constructor")
MSG_DEF(JSMSG_CANT_ALIAS, 10, 3, JSEXN_NONE, "can't alias {0} to {1} in class {2}")
MSG_DEF(JSMSG_NOT_SCRIPTED_FUNCTION, 11, 1, JSEXN_TYPEERR, "{0} is not a scripted function")
MSG_DEF(JSMSG_BAD_SORT_ARG, 12, 0, JSEXN_TYPEERR, "invalid Array.prototype.sort argument")
MSG_DEF(JSMSG_BAD_ATOMIC_NUMBER, 13, 1, JSEXN_INTERNALERR, "internal error: no index for atom {0}")
MSG_DEF(JSMSG_TOO_MANY_LITERALS, 14, 0, JSEXN_INTERNALERR, "too many literals")
MSG_DEF(JSMSG_CANT_WATCH, 15, 1, JSEXN_NONE, "can't watch non-native objects of class {0}")
MSG_DEF(JSMSG_STACK_UNDERFLOW, 16, 2, JSEXN_INTERNALERR, "internal error compiling {0}: stack underflow at pc {1}")
MSG_DEF(JSMSG_NEED_DIET, 17, 1, JSEXN_INTERNALERR, "{0} too large")
MSG_DEF(JSMSG_TOO_MANY_LOCAL_ROOTS, 18, 0, JSEXN_ERR, "out of local root space")
MSG_DEF(JSMSG_READ_ONLY, 19, 1, JSEXN_ERR, "{0} is read-only")
MSG_DEF(JSMSG_BAD_FORMAL, 20, 0, JSEXN_SYNTAXERR, "malformed formal parameter")
MSG_DEF(JSMSG_SAME_FORMAL, 21, 1, JSEXN_NONE, "duplicate formal argument {0}")
MSG_DEF(JSMSG_NOT_FUNCTION, 22, 1, JSEXN_TYPEERR, "{0} is not a function")
MSG_DEF(JSMSG_NOT_CONSTRUCTOR, 23, 1, JSEXN_TYPEERR, "{0} is not a constructor")
MSG_DEF(JSMSG_STACK_OVERFLOW, 24, 1, JSEXN_INTERNALERR, "stack overflow in {0}")
MSG_DEF(JSMSG_NOT_EXPORTED, 25, 1, JSEXN_NONE, "{0} is not exported")
MSG_DEF(JSMSG_OVER_RECURSED, 26, 0, JSEXN_INTERNALERR, "too much recursion")
MSG_DEF(JSMSG_IN_NOT_OBJECT, 27, 1, JSEXN_TYPEERR, "invalid 'in' operand {0}")
MSG_DEF(JSMSG_BAD_NEW_RESULT, 28, 1, JSEXN_NONE, "invalid new expression result {0}")
MSG_DEF(JSMSG_BAD_SHARP_DEF, 29, 1, JSEXN_ERR, "invalid sharp variable definition #{0}=")
MSG_DEF(JSMSG_BAD_SHARP_USE, 30, 1, JSEXN_ERR, "invalid sharp variable use #{0}#")
MSG_DEF(JSMSG_BAD_INSTANCEOF_RHS, 31, 1, JSEXN_TYPEERR, "invalid 'instanceof' operand {0}")
MSG_DEF(JSMSG_BAD_BYTECODE, 32, 1, JSEXN_INTERNALERR, "unimplemented JavaScript bytecode {0}")
MSG_DEF(JSMSG_BAD_RADIX, 33, 1, JSEXN_ERR, "illegal radix {0}")
MSG_DEF(JSMSG_NAN, 34, 1, JSEXN_ERR, "{0} is not a number")
MSG_DEF(JSMSG_CANT_CONVERT, 35, 1, JSEXN_NONE, "can't convert {0} to an integer")
MSG_DEF(JSMSG_CYCLIC_VALUE, 36, 1, JSEXN_ERR, "cyclic {0} value")
MSG_DEF(JSMSG_PERMANENT, 37, 1, JSEXN_ERR, "{0} is permanent")
MSG_DEF(JSMSG_CANT_CONVERT_TO, 38, 2, JSEXN_TYPEERR, "can't convert {0} to {1}")
MSG_DEF(JSMSG_NO_PROPERTIES, 39, 1, JSEXN_TYPEERR, "{0} has no properties")
MSG_DEF(JSMSG_CANT_FIND_CLASS, 40, 1, JSEXN_NONE, "can't find class id {0}")
MSG_DEF(JSMSG_CANT_XDR_CLASS, 41, 1, JSEXN_NONE, "can't XDR class {0}")
MSG_DEF(JSMSG_BYTECODE_TOO_BIG, 42, 2, JSEXN_INTERNALERR, "bytecode {0} too large (limit {1})")
MSG_DEF(JSMSG_UNKNOWN_FORMAT, 43, 1, JSEXN_INTERNALERR, "unknown bytecode format {0}")
MSG_DEF(JSMSG_TOO_MANY_CON_ARGS, 44, 0, JSEXN_SYNTAXERR, "too many constructor arguments")
MSG_DEF(JSMSG_TOO_MANY_FUN_ARGS, 45, 0, JSEXN_SYNTAXERR, "too many function arguments")
MSG_DEF(JSMSG_BAD_QUANTIFIER, 46, 1, JSEXN_SYNTAXERR, "invalid quantifier {0}")
MSG_DEF(JSMSG_MIN_TOO_BIG, 47, 1, JSEXN_SYNTAXERR, "overlarge minimum {0}")
MSG_DEF(JSMSG_MAX_TOO_BIG, 48, 1, JSEXN_SYNTAXERR, "overlarge maximum {0}")
MSG_DEF(JSMSG_OUT_OF_ORDER, 49, 1, JSEXN_SYNTAXERR, "maximum {0} less than minimum")
MSG_DEF(JSMSG_ZERO_QUANTIFIER, 50, 1, JSEXN_SYNTAXERR, "zero quantifier {0}")
MSG_DEF(JSMSG_UNTERM_QUANTIFIER, 51, 1, JSEXN_SYNTAXERR, "unterminated quantifier {0}")
MSG_DEF(JSMSG_EMPTY_BEFORE_STAR, 52, 0, JSEXN_SYNTAXERR, "regular expression before * could be empty")
MSG_DEF(JSMSG_EMPTY_BEFORE_PLUS, 53, 0, JSEXN_SYNTAXERR, "regular expression before + could be empty")
MSG_DEF(JSMSG_MISSING_PAREN, 54, 0, JSEXN_SYNTAXERR, "unterminated parenthetical")
MSG_DEF(JSMSG_UNTERM_CLASS, 55, 1, JSEXN_SYNTAXERR, "unterminated character class {0}")
MSG_DEF(JSMSG_TRAILING_SLASH, 56, 0, JSEXN_SYNTAXERR, "trailing \\ in regular expression")
MSG_DEF(JSMSG_BAD_CLASS_RANGE, 57, 0, JSEXN_SYNTAXERR, "invalid range in character class")
MSG_DEF(JSMSG_BAD_FLAG, 58, 1, JSEXN_SYNTAXERR, "invalid regular expression flag {0}")
MSG_DEF(JSMSG_NO_INPUT, 59, 3, JSEXN_SYNTAXERR, "no input for /{0}/{1}{2}")
MSG_DEF(JSMSG_CANT_OPEN, 60, 2, JSEXN_NONE, "can't open {0}: {1}")
MSG_DEF(JSMSG_BAD_STRING_MASK, 61, 1, JSEXN_ERR, "invalid string escape mask {0}")
MSG_DEF(JSMSG_UNMATCHED_RIGHT_PAREN, 62, 0, JSEXN_SYNTAXERR, "unmatched ) in regular expression")
MSG_DEF(JSMSG_END_OF_DATA, 63, 0, JSEXN_NONE, "unexpected end of data")
MSG_DEF(JSMSG_SEEK_BEYOND_START, 64, 0, JSEXN_NONE, "illegal seek beyond start")
MSG_DEF(JSMSG_SEEK_BEYOND_END, 65, 0, JSEXN_NONE, "illegal seek beyond end")
MSG_DEF(JSMSG_END_SEEK, 66, 0, JSEXN_NONE, "illegal end-based seek")
MSG_DEF(JSMSG_WHITHER_WHENCE, 67, 1, JSEXN_NONE, "unknown seek whence: {0}")
MSG_DEF(JSMSG_BAD_SCRIPT_MAGIC, 68, 0, JSEXN_NONE, "bad script XDR magic number")
MSG_DEF(JSMSG_PAREN_BEFORE_FORMAL, 69, 0, JSEXN_SYNTAXERR, "missing ( before formal parameters")
MSG_DEF(JSMSG_MISSING_FORMAL, 70, 0, JSEXN_SYNTAXERR, "missing formal parameter")
MSG_DEF(JSMSG_PAREN_AFTER_FORMAL, 71, 0, JSEXN_SYNTAXERR, "missing ) after formal parameters")
MSG_DEF(JSMSG_CURLY_BEFORE_BODY, 72, 0, JSEXN_SYNTAXERR, "missing { before function body")
MSG_DEF(JSMSG_CURLY_AFTER_BODY, 73, 0, JSEXN_SYNTAXERR, "missing } after function body")
MSG_DEF(JSMSG_PAREN_BEFORE_COND, 74, 0, JSEXN_SYNTAXERR, "missing ( before condition")
MSG_DEF(JSMSG_PAREN_AFTER_COND, 75, 0, JSEXN_SYNTAXERR, "missing ) after condition")
MSG_DEF(JSMSG_NO_IMPORT_NAME, 76, 0, JSEXN_SYNTAXERR, "missing name in import statement")
MSG_DEF(JSMSG_NAME_AFTER_DOT, 77, 0, JSEXN_SYNTAXERR, "missing name after . operator")
MSG_DEF(JSMSG_BRACKET_IN_INDEX, 78, 0, JSEXN_SYNTAXERR, "missing ] in index expression")
MSG_DEF(JSMSG_NO_EXPORT_NAME, 79, 0, JSEXN_SYNTAXERR, "missing name in export statement")
MSG_DEF(JSMSG_PAREN_BEFORE_SWITCH, 80, 0, JSEXN_SYNTAXERR, "missing ( before switch expression")
MSG_DEF(JSMSG_PAREN_AFTER_SWITCH, 81, 0, JSEXN_SYNTAXERR, "missing ) after switch expression")
MSG_DEF(JSMSG_CURLY_BEFORE_SWITCH, 82, 0, JSEXN_SYNTAXERR, "missing { before switch body")
MSG_DEF(JSMSG_COLON_AFTER_CASE, 83, 0, JSEXN_SYNTAXERR, "missing : after case label")
MSG_DEF(JSMSG_WHILE_AFTER_DO, 84, 0, JSEXN_SYNTAXERR, "missing while after do-loop body")
MSG_DEF(JSMSG_PAREN_AFTER_FOR, 85, 0, JSEXN_SYNTAXERR, "missing ( after for")
MSG_DEF(JSMSG_SEMI_AFTER_FOR_INIT, 86, 0, JSEXN_SYNTAXERR, "missing ; after for-loop initializer")
MSG_DEF(JSMSG_SEMI_AFTER_FOR_COND, 87, 0, JSEXN_SYNTAXERR, "missing ; after for-loop condition")
MSG_DEF(JSMSG_PAREN_AFTER_FOR_CTRL, 88, 0, JSEXN_SYNTAXERR, "missing ) after for-loop control")
MSG_DEF(JSMSG_CURLY_BEFORE_TRY, 89, 0, JSEXN_SYNTAXERR, "missing { before try block")
MSG_DEF(JSMSG_CURLY_AFTER_TRY, 90, 0, JSEXN_SYNTAXERR, "missing } after try block")
MSG_DEF(JSMSG_PAREN_BEFORE_CATCH, 91, 0, JSEXN_SYNTAXERR, "missing ( before catch")
MSG_DEF(JSMSG_CATCH_IDENTIFIER, 92, 0, JSEXN_SYNTAXERR, "missing identifier in catch")
MSG_DEF(JSMSG_PAREN_AFTER_CATCH, 93, 0, JSEXN_SYNTAXERR, "missing ) after catch")
MSG_DEF(JSMSG_CURLY_BEFORE_CATCH, 94, 0, JSEXN_SYNTAXERR, "missing { before catch block")
MSG_DEF(JSMSG_CURLY_AFTER_CATCH, 95, 0, JSEXN_SYNTAXERR, "missing } after catch block")
MSG_DEF(JSMSG_CURLY_BEFORE_FINALLY, 96, 0, JSEXN_SYNTAXERR, "missing { before finally block")
MSG_DEF(JSMSG_CURLY_AFTER_FINALLY, 97, 0, JSEXN_SYNTAXERR, "missing } after finally block")
MSG_DEF(JSMSG_CATCH_OR_FINALLY, 98, 0, JSEXN_SYNTAXERR, "missing catch or finally after try")
MSG_DEF(JSMSG_PAREN_BEFORE_WITH, 99, 0, JSEXN_SYNTAXERR, "missing ( before with-statement object")
MSG_DEF(JSMSG_PAREN_AFTER_WITH, 100, 0, JSEXN_SYNTAXERR, "missing ) after with-statement object")
MSG_DEF(JSMSG_CURLY_IN_COMPOUND, 101, 0, JSEXN_SYNTAXERR, "missing } in compound statement")
MSG_DEF(JSMSG_NO_VARIABLE_NAME, 102, 0, JSEXN_SYNTAXERR, "missing variable name")
MSG_DEF(JSMSG_COLON_IN_COND, 103, 0, JSEXN_SYNTAXERR, "missing : in conditional expression")
MSG_DEF(JSMSG_PAREN_AFTER_ARGS, 104, 0, JSEXN_SYNTAXERR, "missing ) after argument list")
MSG_DEF(JSMSG_BRACKET_AFTER_LIST, 105, 0, JSEXN_SYNTAXERR, "missing ] after element list")
MSG_DEF(JSMSG_COLON_AFTER_ID, 106, 0, JSEXN_SYNTAXERR, "missing : after property id")
MSG_DEF(JSMSG_CURLY_AFTER_LIST, 107, 0, JSEXN_SYNTAXERR, "missing } after property list")
MSG_DEF(JSMSG_PAREN_IN_PAREN, 108, 0, JSEXN_SYNTAXERR, "missing ) in parenthetical")
MSG_DEF(JSMSG_SEMI_BEFORE_STMNT, 109, 0, JSEXN_SYNTAXERR, "missing ; before statement")
MSG_DEF(JSMSG_NO_RETURN_VALUE, 110, 1, JSEXN_TYPEERR, "function {0} does not always return a value")
MSG_DEF(JSMSG_DUPLICATE_FORMAL, 111, 1, JSEXN_TYPEERR, "duplicate formal argument {0}")
MSG_DEF(JSMSG_EQUAL_AS_ASSIGN, 112, 1, JSEXN_NONE, "test for equality (==) mistyped as assignment (=)?{0}")
MSG_DEF(JSMSG_BAD_IMPORT, 113, 0, JSEXN_SYNTAXERR, "invalid import expression")
MSG_DEF(JSMSG_TOO_MANY_DEFAULTS, 114, 0, JSEXN_SYNTAXERR, "more than one switch default")
MSG_DEF(JSMSG_TOO_MANY_CASES, 115, 0, JSEXN_INTERNALERR, "too many switch cases")
MSG_DEF(JSMSG_BAD_SWITCH, 116, 0, JSEXN_SYNTAXERR, "invalid switch statement")
MSG_DEF(JSMSG_BAD_FOR_LEFTSIDE, 117, 0, JSEXN_SYNTAXERR, "invalid for/in left-hand side")
MSG_DEF(JSMSG_CATCH_AFTER_GENERAL, 118, 0, JSEXN_SYNTAXERR, "catch after unconditional catch")
MSG_DEF(JSMSG_CATCH_WITHOUT_TRY, 119, 0, JSEXN_SYNTAXERR, "catch without try")
MSG_DEF(JSMSG_FINALLY_WITHOUT_TRY, 120, 0, JSEXN_SYNTAXERR, "finally without try")
MSG_DEF(JSMSG_LABEL_NOT_FOUND, 121, 0, JSEXN_SYNTAXERR, "label not found")
MSG_DEF(JSMSG_TOUGH_BREAK, 122, 0, JSEXN_SYNTAXERR, "invalid break")
MSG_DEF(JSMSG_BAD_CONTINUE, 123, 0, JSEXN_SYNTAXERR, "invalid continue")
MSG_DEF(JSMSG_BAD_RETURN, 124, 0, JSEXN_SYNTAXERR, "invalid return")
MSG_DEF(JSMSG_BAD_LABEL, 125, 0, JSEXN_SYNTAXERR, "invalid label")
MSG_DEF(JSMSG_DUPLICATE_LABEL, 126, 0, JSEXN_SYNTAXERR, "duplicate label")
MSG_DEF(JSMSG_VAR_HIDES_ARG, 127, 1, JSEXN_TYPEERR, "variable {0} hides argument")
MSG_DEF(JSMSG_BAD_VAR_INIT, 128, 0, JSEXN_SYNTAXERR, "invalid variable initialization")
MSG_DEF(JSMSG_BAD_LEFTSIDE_OF_ASS, 129, 0, JSEXN_SYNTAXERR, "invalid assignment left-hand side")
MSG_DEF(JSMSG_BAD_OPERAND, 130, 1, JSEXN_SYNTAXERR, "invalid {0} operand")
MSG_DEF(JSMSG_BAD_PROP_ID, 131, 0, JSEXN_SYNTAXERR, "invalid property id")
MSG_DEF(JSMSG_RESERVED_ID, 132, 1, JSEXN_SYNTAXERR, "{0} is a reserved identifier")
MSG_DEF(JSMSG_SYNTAX_ERROR, 133, 0, JSEXN_SYNTAXERR, "syntax error")
MSG_DEF(JSMSG_BAD_SHARP_VAR_DEF, 134, 0, JSEXN_SYNTAXERR, "invalid sharp variable definition")
MSG_DEF(JSMSG_BAD_PROTOTYPE, 135, 1, JSEXN_TYPEERR, "'prototype' property of {0} is not an object")
MSG_DEF(JSMSG_MISSING_EXPONENT, 136, 0, JSEXN_SYNTAXERR, "missing exponent")
MSG_DEF(JSMSG_OUT_OF_MEMORY, 137, 0, JSEXN_ERR, "out of memory")
MSG_DEF(JSMSG_UNTERMINATED_STRING, 138, 0, JSEXN_SYNTAXERR, "unterminated string literal")
MSG_DEF(JSMSG_TOO_MANY_PARENS, 139, 0, JSEXN_INTERNALERR, "too many parentheses in regular expression")
MSG_DEF(JSMSG_UNTERMINATED_COMMENT, 140, 0, JSEXN_SYNTAXERR, "unterminated comment")
MSG_DEF(JSMSG_UNTERMINATED_REGEXP, 141, 0, JSEXN_SYNTAXERR, "unterminated regular expression literal")
MSG_DEF(JSMSG_BAD_REGEXP_FLAG, 142, 0, JSEXN_SYNTAXERR, "invalid flag after regular expression")
MSG_DEF(JSMSG_SHARPVAR_TOO_BIG, 143, 0, JSEXN_SYNTAXERR, "overlarge sharp variable number")
MSG_DEF(JSMSG_ILLEGAL_CHARACTER, 144, 0, JSEXN_SYNTAXERR, "illegal character")
MSG_DEF(JSMSG_BAD_OCTAL, 145, 1, JSEXN_SYNTAXERR, "{0} is not a legal ECMA-262 octal constant")
MSG_DEF(JSMSG_BAD_INDIRECT_CALL, 146, 1, JSEXN_EVALERR, "function {0} must be called directly, and not by way of a function of another name")
MSG_DEF(JSMSG_UNCAUGHT_EXCEPTION, 147, 1, JSEXN_NONE, "uncaught exception: {0}")
MSG_DEF(JSMSG_INVALID_BACKREF, 148, 0, JSEXN_SYNTAXERR, "non-octal digit in an escape sequence that doesn't match a back-reference")
MSG_DEF(JSMSG_BAD_BACKREF, 149, 0, JSEXN_SYNTAXERR, "back-reference exceeds number of capturing parentheses")
MSG_DEF(JSMSG_PRECISION_RANGE, 150, 1, JSEXN_RANGEERR, "precision {0} out of range")
MSG_DEF(JSMSG_BAD_GETTER_OR_SETTER, 151, 1, JSEXN_SYNTAXERR, "invalid {0} usage")
MSG_DEF(JSMSG_BAD_ARRAY_LENGTH, 152, 0, JSEXN_RANGEERR, "invalid array length")
MSG_DEF(JSMSG_CANT_DESCRIBE_PROPS, 153, 1, JSEXN_NONE, "can't describe non-native properties of class {0}")
MSG_DEF(JSMSG_BAD_APPLY_ARGS, 154, 0, JSEXN_TYPEERR, "second argument to Function.prototype.apply must be an array")
MSG_DEF(JSMSG_REDECLARED_VAR, 155, 2, JSEXN_TYPEERR, "redeclaration of {0} {1}")
MSG_DEF(JSMSG_UNDECLARED_VAR, 156, 1, JSEXN_TYPEERR, "assignment to undeclared variable {0}")
MSG_DEF(JSMSG_ANON_NO_RETURN_VALUE, 157, 0, JSEXN_TYPEERR, "anonymous function does not always return a value")
MSG_DEF(JSMSG_DEPRECATED_USAGE, 158, 1, JSEXN_REFERENCEERR, "deprecated {0} usage")
MSG_DEF(JSMSG_BAD_URI, 159, 0, JSEXN_URIERR, "malformed URI sequence")
MSG_DEF(JSMSG_GETTER_ONLY, 160, 0, JSEXN_TYPEERR, "setting a property that has only a getter")
MSG_DEF(JSMSG_TRAILING_COMMA, 161, 0, JSEXN_SYNTAXERR, "trailing comma is not legal in ECMA-262 object initializers")
MSG_DEF(JSMSG_UNDEFINED_PROP, 162, 1, JSEXN_TYPEERR, "reference to undefined property {0}")
MSG_DEF(JSMSG_USELESS_EXPR, 163, 0, JSEXN_TYPEERR, "useless expression")
MSG_DEF(JSMSG_REDECLARED_PARAM, 164, 1, JSEXN_TYPEERR, "redeclaration of formal parameter {0}")
MSG_DEF(JSMSG_NEWREGEXP_FLAGGED, 165, 0, JSEXN_TYPEERR, "can't supply flags when constructing one RegExp from another")
MSG_DEF(JSMSG_RESERVED_SLOT_RANGE, 166, 0, JSEXN_RANGEERR, "reserved slot index out of range")
MSG_DEF(JSMSG_CANT_DECODE_PRINCIPALS, 167, 0, JSEXN_INTERNALERR, "can't decode JSPrincipals")
MSG_DEF(JSMSG_CANT_SEAL_OBJECT, 168, 1, JSEXN_ERR, "can't seal {0} objects")
MSG_DEF(JSMSG_CANT_UNSEAL_OBJECT, 169, 1, JSEXN_ERR, "can't unseal {0} objects")
MSG_DEF(JSMSG_BAD_XML_MARKUP, 170, 0, JSEXN_SYNTAXERR, "invalid XML markup")
MSG_DEF(JSMSG_BAD_XML_CHARACTER, 171, 0, JSEXN_SYNTAXERR, "illegal XML character")
MSG_DEF(JSMSG_BAD_DEFAULT_XML_NAMESPACE,172,0,JSEXN_SYNTAXERR, "invalid default XML namespace")
MSG_DEF(JSMSG_BAD_XML_NAME_SYNTAX, 173, 0, JSEXN_SYNTAXERR, "invalid XML name")
MSG_DEF(JSMSG_BRACKET_AFTER_ATTR_EXPR,174, 0, JSEXN_SYNTAXERR, "missing ] after attribute expression")
MSG_DEF(JSMSG_NAME_AFTER_DBLDOT, 175, 0, JSEXN_SYNTAXERR, "missing name after .. operator")
MSG_DEF(JSMSG_CURLY_IN_XML_EXPR, 176, 0, JSEXN_SYNTAXERR, "missing } in XML expression")
MSG_DEF(JSMSG_BAD_XML_NAMESPACE, 177, 1, JSEXN_TYPEERR, "invalid XML namespace {0}")
MSG_DEF(JSMSG_BAD_XML_ATTRIBUTE_NAME, 178, 1, JSEXN_TYPEERR, "invalid XML attribute name {0}")
MSG_DEF(JSMSG_BAD_XML_NAME, 179, 1, JSEXN_TYPEERR, "invalid XML name {0}")
MSG_DEF(JSMSG_BAD_XML_CONVERSION, 180, 1, JSEXN_TYPEERR, "can't convert {0} to XML")
MSG_DEF(JSMSG_BAD_XMLLIST_CONVERSION, 181, 1, JSEXN_TYPEERR, "can't convert {0} to XMLList")
MSG_DEF(JSMSG_IS_NOT_XML_OBJECT, 182, 1, JSEXN_TYPEERR, "{0} is not an XML object")
MSG_DEF(JSMSG_NO_ASSIGN_IN_XML_ATTR, 183, 0, JSEXN_SYNTAXERR, "missing = in XML attribute")
MSG_DEF(JSMSG_BAD_XML_ATTR_VALUE, 184, 0, JSEXN_SYNTAXERR, "invalid XML attribute value")
MSG_DEF(JSMSG_XML_TAG_NAME_MISMATCH, 185, 0, JSEXN_SYNTAXERR, "XML tag name mismatch")
MSG_DEF(JSMSG_BAD_XML_TAG_SYNTAX, 186, 0, JSEXN_SYNTAXERR, "invalid XML tag syntax")
MSG_DEF(JSMSG_BAD_XML_LIST_SYNTAX, 187, 0, JSEXN_SYNTAXERR, "invalid XML list syntax")
MSG_DEF(JSMSG_INCOMPATIBLE_METHOD, 188, 3, JSEXN_TYPEERR, "{0} {1} called on incompatible {2}")
MSG_DEF(JSMSG_CANT_SET_XML_ATTRS, 189, 0, JSEXN_INTERNALERR, "can't set XML property attributes")
MSG_DEF(JSMSG_END_OF_XML_SOURCE, 190, 0, JSEXN_SYNTAXERR, "unexpected end of XML source")
MSG_DEF(JSMSG_END_OF_XML_ENTITY, 191, 0, JSEXN_SYNTAXERR, "unexpected end of XML entity")
MSG_DEF(JSMSG_BAD_XML_QNAME, 192, 0, JSEXN_SYNTAXERR, "invalid XML qualified name")
MSG_DEF(JSMSG_BAD_FOR_EACH_LOOP, 193, 0, JSEXN_SYNTAXERR, "invalid for each loop")
MSG_DEF(JSMSG_BAD_XMLLIST_PUT, 194, 1, JSEXN_TYPEERR, "can't set property {0} in XMLList")
MSG_DEF(JSMSG_UNKNOWN_XML_ENTITY, 195, 1, JSEXN_TYPEERR, "unknown XML entity {0}")
MSG_DEF(JSMSG_BAD_XML_NCR, 196, 1, JSEXN_TYPEERR, "malformed XML character {0}")
MSG_DEF(JSMSG_UNDEFINED_XML_NAME, 197, 1, JSEXN_TYPEERR, "reference to undefined XML name {0}")

View File

@@ -1,2 +0,0 @@
[gecko xpi-bootstrap]
dist/bin/@SHARED_LIBRARY@

View File

@@ -1,79 +0,0 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winver.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,0,0,0
PRODUCTVERSION 4,0,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x10004L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904e4"
BEGIN
VALUE "CompanyName", "Netscape Communications Corporation\0"
VALUE "FileDescription", "Netscape 32-bit JavaScript Module\0"
VALUE "FileVersion", "4.0\0"
VALUE "InternalName", "JS3240\0"
VALUE "LegalCopyright", "Copyright Netscape Communications. 1994-96\0"
VALUE "LegalTrademarks", "Netscape, Mozilla\0"
VALUE "OriginalFilename", "js3240.dll\0"
VALUE "ProductName", "NETSCAPE\0"
VALUE "ProductVersion", "4.0\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1252
END
END
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""winver.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////

View File

@@ -1,654 +0,0 @@
; ***** BEGIN LICENSE BLOCK *****
; Version: MPL 1.1/GPL 2.0/LGPL 2.1
;
; The contents of this file are subject to the Mozilla Public License Version
; 1.1 (the "License"); you may not use this file except in compliance with
; the License. You may obtain a copy of the License at
; http://www.mozilla.org/MPL/
;
; Software distributed under the License is distributed on an "AS IS" basis,
; WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
; for the specific language governing rights and limitations under the
; License.
;
; The Original Code is Mozilla Communicator client code, released
; March 31, 1998.
;
; The Initial Developer of the Original Code is
; Netscape Communications Corporation.
; Portions created by the Initial Developer are Copyright (C) 1998
; the Initial Developer. All Rights Reserved.
;
; Contributor(s):
;
; Alternatively, the contents of this file may be used under the terms of
; either of the GNU General Public License Version 2 or later (the "GPL"),
; or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
; in which case the provisions of the GPL or the LGPL are applicable instead
; of those above. If you wish to allow use of your version of this file only
; under the terms of either the GPL or the LGPL, and not to allow others to
; use your version of this file under the terms of the MPL, indicate your
; decision by deleting the provisions above and replace them with the notice
; and other provisions required by the GPL or the LGPL. If you do not delete
; the provisions above, a recipient may use your version of this file under
; the terms of any one of the MPL, the GPL or the LGPL.
;
; ***** END LICENSE BLOCK *****
LIBRARY JS3240 INITINSTANCE TERMINSTANCE
PROTMODE
DESCRIPTION 'Netscape OS/2 JavaScript Library'
CODE LOADONCALL MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE NONSHARED
EXPORTS
;====================== win16 exports these at least... ===========
; JS_Init = JS_Init @2
; JS_Finish = JS_Finish @3
; JS_GetNaNValue
; JS_GetNegativeInfinityValue
; JS_GetPositiveInfinityValue
; JS_GetEmptyStringValue
; JS_ConvertValue
; JS_ValueToObject
; JS_ValueToFunction
; JS_ValueToString
; JS_ValueToNumber
; JS_ValueToBoolean
; JS_TypeOfValue
; JS_GetTypeName
; JS_Lock
; JS_Unlock
; JS_NewContext
; JS_DestroyContext
; JS_ContextIterator
; JS_GetGlobalObject
; JS_SetGlobalObject
; JS_InitStandardClasses
;; JS_GetStaticLink
; JS_malloc
; JS_realloc
; JS_free
; JS_strdup
; JS_NewDouble
; JS_NewDoubleValue
; JS_AddRoot
; JS_RemoveRoot
; JS_LockGCThing
; JS_UnlockGCThing
; JS_GC
; JS_PropertyStub
; JS_EnumerateStub
; JS_ResolveStub
; JS_ConvertStub
; JS_FinalizeStub
; JS_InitClass
; JS_GetClass
; JS_InstanceOf
; JS_GetPrivate
; JS_SetPrivate
; JS_GetInstancePrivate
; JS_GetPrototype
; JS_GetParent
; JS_SetParent
; JS_GetConstructor
; JS_NewObject
; JS_DefineObject
; JS_DefineConstDoubles
; JS_DefineProperties
; JS_DefineProperty
; JS_DefinePropertyWithTinyId
; JS_AliasProperty
; JS_LookupProperty
; JS_GetProperty
; JS_SetProperty
; JS_DeleteProperty
; JS_NewArrayObject
; JS_DefineElement
; JS_AliasElement
; JS_LookupElement
; JS_GetElement
; JS_SetElement
; JS_DeleteElement
; JS_ClearScope
; JS_NewFunction
; JS_GetFunctionObject
; JS_GetFunctionName
; JS_DefineFunctions
; JS_DefineFunction
; JS_CompileScript
; JS_DestroyScript
; JS_CompileFunction
; JS_DecompileScript
; JS_DecompileFunction
; JS_DecompileFunctionBody
; JS_ExecuteScript
; JS_EvaluateScript
; JS_CallFunction
; JS_CallFunctionName
; JS_CallFunctionValue
; JS_SetBranchCallback
; JS_IsRunning
; JS_IsConstructing
; JS_SetCallReturnValue2
; JS_NewString
; JS_NewStringCopyN
; JS_NewStringCopyZ
; JS_InternString
; JS_GetStringBytes
; JS_GetStringLength
; JS_CompareStrings
; JS_ReportError
; JS_ReportOutOfMemory
; JS_SetErrorReporter
; JS_NewRegExpObject
; JS_SetRegExpInput
; JS_ClearRegExpStatics
;=================================================
;00001:jsstr (OFFSET:0x00002e17, SIZE:0x0000ae17):
; - Public Definitions:
; js_EmptySubString
; js_CompareStrings
; js_HashString
; js_ValueToString
; js_StringToObject
; js_FinalizeString
; js_NewStringCopyZ
; js_NewString
; js_InitStringClass
; js_NewStringCopyN
; js_BoyerMooreHorspool
;
;
;00002:jsscript (OFFSET:0x0000dc2e, SIZE:0x00003abb):
; - Public Definitions:
; js_LineNumberToPC
; js_PCToLineNumber
; js_GetSrcNote
; js_DestroyScript
; js_NewScript
;
;
;00003:jsscope (OFFSET:0x000116e9, SIZE:0x00004f82):
; - Public Definitions:
; js_hash_scope_ops
; js_list_scope_ops
; js_DestroyProperty
; js_NewProperty
; js_IdToValue
; js_HashValue
; js_DestroyScope
; js_MutateScope
; js_DropScope
; js_HoldScope
; js_NewScope
; js_GetMutableScope
; js_HoldProperty
; js_DropProperty
;
;
;00004:jsscan (OFFSET:0x0001666b, SIZE:0x00008890):
; - Public Definitions:
; js_MatchToken
; js_FlushNewlines
; js_PeekTokenSameLine
; js_UngetToken
; js_GetToken
; js_PeekToken
; js_ReportCompileError
js_CloseTokenStream
js_NewBufferTokenStream
; js_NewTokenStream
; js_InitScanner
;
;
;00005:jsregexp (OFFSET:0x0001eefb, SIZE:0x0000eee4):
; - Public Definitions:
; js_RegExpClass
; reopsize
; js_NewRegExpObject
; js_InitRegExpClass
; js_FreeRegExpStatics
; js_InitRegExpStatics
; js_ExecuteRegExp
; js_NewRegExpOpt
; js_DestroyRegExp
; js_NewRegExp
;
;
;00006:jsparse (OFFSET:0x0002dddf, SIZE:0x00010b71):
; - Public Definitions:
; js_ParseFunctionBody
js_Parse
;
;
;00007:jsopcode (OFFSET:0x0003e950, SIZE:0x0000d362):
; - Public Definitions:
; js_EscapeMap
; js_NumCodeSpecs
; js_CodeSpec
; js_incop_str
; js_true_str
; js_false_str
; js_this_str
; js_null_str
; js_void_str
; js_typeof_str
; js_delete_str
; js_new_str
; js_ValueToSource
; js_DecompileScript
; js_DecompileCode
; js_DecompileFunction
; js_puts
; js_printf
; js_GetPrinterOutput
; js_DestroyPrinter
; js_NewPrinter
; js_EscapeString
; js_Disassemble1
; js_Disassemble
;
;00008:jsobj (OFFSET:0x0004bcb2, SIZE:0x000090a4):
; - Public Definitions:
; js_WithClass
; js_ObjectClass
; js_TryValueOf
; js_ValueToNonNullObject
; js_TryMethod
; js_ObjectToString
; js_SetClassPrototype
; js_DeleteProperty2
; js_DeleteProperty
; js_SetProperty
; js_GetProperty
; js_FindVariableScope
; js_FindVariable
; js_FindProperty
; js_LookupProperty
; js_DefineProperty
; js_FreeSlot
; js_AllocSlot
; js_FinalizeObject
; js_GetClassPrototype
; js_NewObject
; js_InitObjectClass
; js_ValueToObject
; js_obj_toString
; js_SetSlot
; js_GetSlot
;
;
;00009:jsnum (OFFSET:0x00054d56, SIZE:0x00004f29):
; - Public Definitions:
; js_ValueToInt32
; js_NumberToObject
; js_FinalizeDouble
; js_InitNumberClass
; js_NumberToString
; js_NewDoubleValue
; js_NewDouble
; js_ValueToNumber
;
;
;00010:jsmath (OFFSET:0x00059c7f, SIZE:0x000054b6):
; - Public Definitions:
; js_InitMathClass
;
;
;00011:jsjava (OFFSET:0x0005f135, SIZE:0x00022aad):
; - Public Definitions:
; js_Hooks
; MojaSrcLog
; finalizeTask
JSJ_FindCurrentJSContext
; JSJ_GetPrincipals
JSJ_IsSafeMethod
JSJ_InitContext
JSJ_Init
js_JSErrorToJException
js_JavaErrorReporter
js_RemoveReflection
js_ReflectJObjectToJSObject
js_convertJObjectToJSValue
js_convertJSValueToJObject
js_ReflectJSObjectToJObject
; js_ReflectJClassToJSObject
JSJ_ExitJS
JSJ_EnterJS
JSJ_CurrentContext
JSJ_IsEnabled
;added in GA code - DSR70297
JSJ_Finish
JSJ_IsCalledFromJava
js_GetJSPrincipalsFromJavaCaller
;
;
;00012:jsinterp (OFFSET:0x00081be2, SIZE:0x00012274):
; - Public Definitions:
; js_Call
; js_Interpret
; js_SetLocalVariable
; js_GetLocalVariable
; js_SetArgument
; js_GetArgument
; js_FlushPropertyCacheByProp
; js_FlushPropertyCache
;
;
;00013:jsgc (OFFSET:0x00093e56, SIZE:0x00004f8d):
; - Public Definitions:
; js_ForceGC
; js_UnlockGCThing
; js_LockGCThing
; js_GC
; js_AllocGCThing
; js_RemoveRoot
; js_AddRoot
; js_FinishGC
; js_InitGC
;
;
;00014:jsfun (OFFSET:0x00098de3, SIZE:0x0000977c):
; - Public Definitions:
; js_FunctionClass
; js_ClosureClass
; js_CallClass
; js_DefineFunction
; js_NewFunction
; js_InitCallAndClosureClasses
; js_InitFunctionClass
; js_ValueToFunction
; js_SetCallVariable
; js_GetCallVariable
; js_PutCallObject
; js_GetCallObject
;
;
;00015:jsemit (OFFSET:0x000a255f, SIZE:0x000077be):
; - Public Definitions:
; js_SrcNoteName
; js_SrcNoteArity
js_FinishTakingSrcNotes
; js_MoveSrcNotes
; js_GetSrcNoteOffset
; js_BumpSrcNoteDelta
; js_NewSrcNote3
; js_NewSrcNote2
; js_PopStatement
; js_EmitContinue
; js_EmitBreak
; js_SetSrcNoteOffset
; js_NewSrcNote
; js_PushStatement
; js_MoveCode
; js_SetJumpOffset
; js_Emit3
; js_Emit2
; js_Emit1
; js_UpdateDepth
; js_SrcNoteLength
; js_CancelLastOpcode
js_InitCodeGenerator
;
;
;00016:jsdbgapi (OFFSET:0x000a9d1d, SIZE:0x000057db):
; - Public Definitions:
; js_watchpoint_list
; js_trap_list
; JS_SetAnnotationInFrame
; JS_GetAnnotationFromFrame
; JS_GetJSPrincipalArrayFromFrame
; JS_NextJSFrame
; JS_InitJSFrameIterator
JS_LineNumberToPC
JS_PCToLineNumber
JS_ClearAllWatchPoints
JS_ClearWatchPoint
JS_SetWatchPoint
JS_HandleTrap
JS_ClearAllTraps
JS_ClearScriptTraps
JS_ClearTrap
JS_GetTrapOpcode
JS_SetTrap
;DSR070297 - added in GA code
JS_FrameIterator
JS_GetFrameAnnotation
JS_GetFramePrincipalArray
JS_GetFrameScript
JS_GetScriptFilename
JS_SetFrameAnnotation
JS_GetFramePC
JS_GetFunctionScript
;
;
;00017:jsdate (OFFSET:0x000af4f8, SIZE:0x00009a8e):
; - Public Definitions:
js_DateGetSeconds
js_DateGetMinutes
js_DateGetHours
js_DateGetDate
js_DateGetMonth
js_DateGetYear
js_NewDateObject
; js_InitDateClass
;
;
;00018:jscntxt (OFFSET:0x000b8f86, SIZE:0x00003732):
; - Public Definitions:
; js_InterpreterHooks
; js_ReportIsNotDefined
; js_ReportErrorAgain
; js_ReportErrorVA
; js_ContextIterator
; js_DestroyContext
; js_NewContext
; js_SetInterpreterHooks
;
;
;00019:jsbool (OFFSET:0x000bc6b8, SIZE:0x00003375):
; - Public Definitions:
; js_BooleanToString
; js_BooleanToObject
; js_InitBooleanClass
; js_ValueToBoolean
;
;
;00020:jsatom (OFFSET:0x000bfa2d, SIZE:0x000058d0):
; - Public Definitions:
; js_valueOf_str
; js_toString_str
; js_length_str
; js_eval_str
; js_constructor_str
; js_class_prototype_str
; js_assign_str
; js_anonymous_str
; js_Object_str
; js_Array_str
; js_type_str
; js_DropUnmappedAtoms
js_FreeAtomMap
js_InitAtomMap
; js_GetAtom
; js_DropAtom
; js_IndexAtom
; js_ValueToStringAtom
; js_AtomizeString
; js_AtomizeDouble
; js_AtomizeInt
; js_AtomizeBoolean
; js_AtomizeObject
; js_HoldAtom
; js_MarkAtomState
; js_FreeAtomState
; js_Atomize
; js_InitAtomState
;
;
;00021:jsarray (OFFSET:0x000c52fd, SIZE:0x00007c86):
; - Public Definitions:
; js_ArrayClass
; js_SetArrayLength
; js_GetArrayLength
; js_InitArrayClass
; js_NewArrayObject
; PR_qsort
;
;
;00022:jsapi (OFFSET:0x000ccf83, SIZE:0x0000de8c):
; - Public Definitions:
JS_ClearRegExpStatics
JS_SetRegExpInput
JS_NewRegExpObject
JS_SetErrorReporter
JS_CompareStrings
JS_GetStringLength
JS_GetStringBytes
JS_InternString
JS_NewStringCopyZ
JS_NewStringCopyN
JS_NewString
JS_IsRunning
JS_SetBranchCallback
JS_CallFunctionValue
JS_CallFunctionName
JS_CallFunction
JS_EvaluateScriptForPrincipals
JS_EvaluateScript
JS_ExecuteScript
JS_DecompileFunctionBody
JS_DecompileFunction
JS_DecompileScript
JS_CompileFunctionForPrincipals
JS_CompileFunction
JS_DestroyScript
JS_CompileScriptForPrincipals
JS_CompileScript
JS_DefineFunction
JS_GetFunctionName
JS_GetFunctionObject
JS_NewFunction
JS_ClearScope
JS_DeleteElement
JS_SetElement
JS_GetElement
JS_LookupElement
JS_AliasElement
JS_DefineElement
JS_SetArrayLength
JS_GetArrayLength
JS_NewArrayObject
JS_DeleteProperty
JS_SetProperty
JS_GetProperty
JS_LookupProperty
JS_AliasProperty
JS_DefinePropertyWithTinyId
JS_DefineProperty
JS_DefineConstDoubles
JS_DefineObject
JS_NewObject
JS_GetConstructor
JS_SetParent
JS_GetParent
JS_SetPrototype
JS_GetPrototype
JS_GetInstancePrivate
JS_SetPrivate
JS_GetPrivate
JS_InstanceOf
JS_GetClass
JS_DefineFunctions
JS_DefineProperties
JS_InitClass
JS_FinalizeStub
JS_ConvertStub
JS_ResolveStub
JS_EnumerateStub
JS_PropertyStub
JS_GC
JS_UnlockGCThing
JS_LockGCThing
JS_RemoveRoot
JS_AddRoot
JS_NewDoubleValue
JS_NewDouble
JS_strdup
JS_free
JS_realloc
JS_ReportOutOfMemory
JS_malloc
JS_GetScopeChain
JS_InitStandardClasses
JS_SetGlobalObject
JS_GetGlobalObject
JS_SetVersion
JS_GetVersion
JS_ContextIterator
JS_GetTaskState
JS_DestroyContext
JS_NewContext
JS_Unlock
JS_Lock
JS_Finish
JS_Init
JS_GetTypeName
JS_TypeOfValue
JS_ValueToBoolean
JS_ValueToInt32
JS_ValueToNumber
JS_ValueToString
JS_ValueToFunction
JS_ValueToObject
JS_ReportError
JS_ConvertValue
JS_GetEmptyStringValue
JS_GetPositiveInfinityValue
JS_GetNegativeInfinityValue
JS_GetNaNValue
;DSR062897 - added for GA code
JS_MaybeGC
JS_GetScriptPrincipals
JS_IsAssigning
JS_SetCharSetInfo
;brendan@mozilla.org, 2-Sept-2000
JS_SetCallReturnValue2
JS_SetGCCallback
JS_SetGCCallbackRT
JS_AddExternalStringFinalizer
JS_RemoveExternalStringFinalizer
JS_NewExternalString
;
;
;00023:prmjtime (OFFSET:0x000dae0f, SIZE:0x00008986):
; - Public Definitions:
PRMJ_FormatTimeUSEnglish
PRMJ_gmtime
PRMJ_FormatTime
PRMJ_mktime
PRMJ_ComputeTime
PRMJ_localtime
PRMJ_ExplodeTime
PRMJ_ToLocal
PRMJ_ToGMT
PRMJ_NowLocal
PRMJ_DSTOffset
PRMJ_NowS
PRMJ_NowMS
PRMJ_Now
PRMJ_ToExtendedTime
PRMJ_ToBaseTime
PRMJ_setDST
PRMJ_LocalGMTDifference

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,567 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* Lifetime-based fast allocation, inspired by much prior art, including
* "Fast Allocation and Deallocation of Memory Based on Object Lifetimes"
* David R. Hanson, Software -- Practice and Experience, Vol. 20(1).
*/
#include "jsstddef.h"
#include <stdlib.h>
#include <string.h>
#include "jstypes.h"
#include "jsbit.h"
#include "jsarena.h" /* Added by JSIFY */
#include "jsutil.h" /* Added by JSIFY */
#include "jslock.h"
static JSArena *arena_freelist;
#ifdef JS_THREADSAFE
static JSLock *arena_freelist_lock;
#endif
#ifdef JS_ARENAMETER
static JSArenaStats *arena_stats_list;
#define COUNT(pool,what) (pool)->stats.what++
#else
#define COUNT(pool,what) /* nothing */
#endif
#define JS_ARENA_DEFAULT_ALIGN sizeof(double)
JS_PUBLIC_API(void)
JS_InitArenaPool(JSArenaPool *pool, const char *name, size_t size, size_t align)
{
#ifdef JS_THREADSAFE
/* Must come through here once in primordial thread to init safely! */
if (!arena_freelist_lock) {
arena_freelist_lock = JS_NEW_LOCK();
JS_ASSERT(arena_freelist_lock);
}
#endif
if (align == 0)
align = JS_ARENA_DEFAULT_ALIGN;
pool->mask = JS_BITMASK(JS_CeilingLog2(align));
pool->first.next = NULL;
pool->first.base = pool->first.avail = pool->first.limit =
JS_ARENA_ALIGN(pool, &pool->first + 1);
pool->current = &pool->first;
pool->arenasize = size;
#ifdef JS_ARENAMETER
memset(&pool->stats, 0, sizeof pool->stats);
pool->stats.name = strdup(name);
pool->stats.next = arena_stats_list;
arena_stats_list = &pool->stats;
#endif
}
/*
* An allocation that consumes more than pool->arenasize also has a header
* pointing back to its previous arena's next member. This header is not
* included in [a->base, a->limit), so its space can't be wrongly claimed.
*
* As the header is a pointer, it must be well-aligned. If pool->mask is
* greater than or equal to POINTER_MASK, the header just preceding a->base
* for an oversized arena a is well-aligned, because a->base is well-aligned.
* However, we may need to add more space to pad the JSArena ** back-pointer
* so that it lies just behind a->base, because a might not be aligned such
* that (jsuword)(a + 1) is on a pointer boundary.
*
* By how much must we pad? Let M be the alignment modulus for pool and P
* the modulus for a pointer. Given M >= P, the greatest distance between a
* pointer aligned on an M boundary and one aligned on a P boundary is M-P.
* If M and P are powers of two, then M-P = (pool->mask - POINTER_MASK).
*
* How much extra padding might spill over unused into the remainder of the
* allocation, in the worst case (where M > P)?
*
* If we add M-P to the nominal back-pointer address and then round down to
* align on a P boundary, we will use at most M-P bytes of padding, and at
* least P (M > P => M >= 2P; M == 2P gives the least padding, P). So if we
* use P bytes of padding, then we will overallocate a by P+M-1 bytes, as we
* also add M-1 to the estimated size in case malloc returns an odd pointer.
* a->limit must include this overestimation to satisfy a->avail in [a->base,
* a->limit].
*
* Similarly, if pool->mask is less than POINTER_MASK, we must include enough
* space in the header size to align the back-pointer on a P boundary so that
* it can be found by subtracting P from a->base. This means a->base must be
* on a P boundary, even though subsequent allocations from a may be aligned
* on a lesser (M) boundary. Given powers of two M and P as above, the extra
* space needed when P > M is P-M or POINTER_MASK - pool->mask.
*
* The size of a header including padding is given by the HEADER_SIZE macro,
* below, for any pool (for any value of M).
*
* The mask to align a->base for any pool is (pool->mask | POINTER_MASK), or
* HEADER_BASE_MASK(pool).
*
* PTR_TO_HEADER computes the address of the back-pointer, given an oversized
* allocation at p. By definition, p must be a->base for the arena a that
* contains p. GET_HEADER and SET_HEADER operate on an oversized arena a, in
* the case of SET_HEADER with back-pointer ap.
*/
#define POINTER_MASK ((jsuword)(JS_ALIGN_OF_POINTER - 1))
#define HEADER_SIZE(pool) (sizeof(JSArena **) \
+ (((pool)->mask < POINTER_MASK) \
? POINTER_MASK - (pool)->mask \
: (pool)->mask - POINTER_MASK))
#define HEADER_BASE_MASK(pool) ((pool)->mask | POINTER_MASK)
#define PTR_TO_HEADER(pool,p) (JS_ASSERT(((jsuword)(p) \
& HEADER_BASE_MASK(pool)) \
== 0), \
(JSArena ***)(p) - 1)
#define GET_HEADER(pool,a) (*PTR_TO_HEADER(pool, (a)->base))
#define SET_HEADER(pool,a,ap) (*PTR_TO_HEADER(pool, (a)->base) = (ap))
JS_PUBLIC_API(void *)
JS_ArenaAllocate(JSArenaPool *pool, size_t nb)
{
JSArena **ap, **bp, *a, *b;
jsuword extra, hdrsz, gross, sz;
void *p;
/* Search pool from current forward till we find or make enough space. */
JS_ASSERT((nb & pool->mask) == 0);
for (a = pool->current; a->avail + nb > a->limit; pool->current = a) {
ap = &a->next;
if (!*ap) {
/* Not enough space in pool -- try to reclaim a free arena. */
extra = (nb > pool->arenasize) ? HEADER_SIZE(pool) : 0;
hdrsz = sizeof *a + extra + pool->mask;
gross = hdrsz + JS_MAX(nb, pool->arenasize);
bp = &arena_freelist;
JS_ACQUIRE_LOCK(arena_freelist_lock);
while ((b = *bp) != NULL) {
/*
* Insist on exact arenasize match if nb is not greater than
* arenasize. Otherwise take any arena big enough, but not by
* more than gross + arenasize.
*/
sz = JS_UPTRDIFF(b->limit, b);
if (extra
? sz >= gross && sz <= gross + pool->arenasize
: sz == gross) {
*bp = b->next;
JS_RELEASE_LOCK(arena_freelist_lock);
b->next = NULL;
COUNT(pool, nreclaims);
goto claim;
}
bp = &b->next;
}
/* Nothing big enough on the freelist, so we must malloc. */
JS_RELEASE_LOCK(arena_freelist_lock);
b = (JSArena *) malloc(gross);
if (!b)
return 0;
b->next = NULL;
b->limit = (jsuword)b + gross;
JS_COUNT_ARENA(pool,++);
COUNT(pool, nmallocs);
claim:
/* If oversized, store ap in the header, just before a->base. */
*ap = a = b;
JS_ASSERT(gross <= JS_UPTRDIFF(a->limit, a));
if (extra) {
a->base = a->avail =
((jsuword)a + hdrsz) & ~HEADER_BASE_MASK(pool);
SET_HEADER(pool, a, ap);
} else {
a->base = a->avail = JS_ARENA_ALIGN(pool, a + 1);
}
continue;
}
a = *ap; /* move to next arena */
}
p = (void *)a->avail;
a->avail += nb;
JS_ASSERT(a->base <= a->avail && a->avail <= a->limit);
return p;
}
JS_PUBLIC_API(void *)
JS_ArenaRealloc(JSArenaPool *pool, void *p, size_t size, size_t incr)
{
JSArena **ap, *a, *b;
jsuword boff, aoff, extra, hdrsz, gross;
/*
* Use the oversized-single-allocation header to avoid searching for ap.
* See JS_ArenaAllocate, the SET_HEADER call.
*/
if (size > pool->arenasize) {
ap = *PTR_TO_HEADER(pool, p);
a = *ap;
} else {
ap = &pool->first.next;
while ((a = *ap) != pool->current)
ap = &a->next;
}
JS_ASSERT(a->base == (jsuword)p);
boff = JS_UPTRDIFF(a->base, a);
aoff = size + incr;
JS_ASSERT(aoff > pool->arenasize);
extra = HEADER_SIZE(pool); /* oversized header holds ap */
hdrsz = sizeof *a + extra + pool->mask; /* header and alignment slop */
gross = hdrsz + aoff;
a = (JSArena *) realloc(a, gross);
if (!a)
return NULL;
#ifdef JS_ARENAMETER
pool->stats.nreallocs++;
#endif
if (a != *ap) {
/* Oops, realloc moved the allocation: update other pointers to a. */
if (pool->current == *ap)
pool->current = a;
b = a->next;
if (b && b->avail - b->base > pool->arenasize) {
JS_ASSERT(GET_HEADER(pool, b) == &(*ap)->next);
SET_HEADER(pool, b, &a->next);
}
/* Now update *ap, the next link of the arena before a. */
*ap = a;
}
a->base = ((jsuword)a + hdrsz) & ~HEADER_BASE_MASK(pool);
a->limit = (jsuword)a + gross;
a->avail = JS_ARENA_ALIGN(pool, a->base + aoff);
JS_ASSERT(a->base <= a->avail && a->avail <= a->limit);
/* Check whether realloc aligned differently, and copy if necessary. */
if (boff != JS_UPTRDIFF(a->base, a))
memmove((void *)a->base, (char *)a + boff, size);
/* Store ap in the oversized-load arena header. */
SET_HEADER(pool, a, ap);
return (void *)a->base;
}
JS_PUBLIC_API(void *)
JS_ArenaGrow(JSArenaPool *pool, void *p, size_t size, size_t incr)
{
void *newp;
/*
* If p points to an oversized allocation, it owns an entire arena, so we
* can simply realloc the arena.
*/
if (size > pool->arenasize)
return JS_ArenaRealloc(pool, p, size, incr);
JS_ARENA_ALLOCATE(newp, pool, size + incr);
if (newp)
memcpy(newp, p, size);
return newp;
}
/*
* Free tail arenas linked after head, which may not be the true list head.
* Reset pool->current to point to head in case it pointed at a tail arena.
*/
static void
FreeArenaList(JSArenaPool *pool, JSArena *head, JSBool reallyFree)
{
JSArena **ap, *a;
ap = &head->next;
a = *ap;
if (!a)
return;
#ifdef DEBUG
do {
JS_ASSERT(a->base <= a->avail && a->avail <= a->limit);
a->avail = a->base;
JS_CLEAR_UNUSED(a);
} while ((a = a->next) != NULL);
a = *ap;
#endif
if (reallyFree) {
do {
*ap = a->next;
JS_CLEAR_ARENA(a);
JS_COUNT_ARENA(pool,--);
free(a);
} while ((a = *ap) != NULL);
} else {
/* Insert the whole arena chain at the front of the freelist. */
do {
ap = &(*ap)->next;
} while (*ap);
JS_ACQUIRE_LOCK(arena_freelist_lock);
*ap = arena_freelist;
arena_freelist = a;
JS_RELEASE_LOCK(arena_freelist_lock);
head->next = NULL;
}
pool->current = head;
}
JS_PUBLIC_API(void)
JS_ArenaRelease(JSArenaPool *pool, char *mark)
{
JSArena *a;
for (a = &pool->first; a; a = a->next) {
JS_ASSERT(a->base <= a->avail && a->avail <= a->limit);
if (JS_UPTRDIFF(mark, a->base) <= JS_UPTRDIFF(a->avail, a->base)) {
a->avail = JS_ARENA_ALIGN(pool, mark);
JS_ASSERT(a->avail <= a->limit);
FreeArenaList(pool, a, JS_TRUE);
return;
}
}
}
JS_PUBLIC_API(void)
JS_ArenaFreeAllocation(JSArenaPool *pool, void *p, size_t size)
{
JSArena **ap, *a, *b;
jsuword q;
/*
* If the allocation is oversized, it consumes an entire arena, and it has
* a header just before the allocation pointing back to its predecessor's
* next member. Otherwise, we have to search pool for a.
*/
if (size > pool->arenasize) {
ap = *PTR_TO_HEADER(pool, p);
a = *ap;
} else {
q = (jsuword)p + size;
q = JS_ARENA_ALIGN(pool, q);
ap = &pool->first.next;
while ((a = *ap) != NULL) {
JS_ASSERT(a->base <= a->avail && a->avail <= a->limit);
if (a->avail == q) {
/*
* If a is consumed by the allocation at p, we can free it to
* the malloc heap.
*/
if (a->base == (jsuword)p)
break;
/*
* We can't free a, but we can "retract" its avail cursor --
* whether there are others after it in pool.
*/
a->avail = (jsuword)p;
return;
}
ap = &a->next;
}
}
/*
* At this point, a is doomed, so ensure that pool->current doesn't point
* at it. We must preserve LIFO order of mark/release cursors, so we use
* the oversized-allocation arena's back pointer (or if not oversized, we
* use the result of searching the entire pool) to compute the address of
* the arena that precedes a.
*/
if (pool->current == a)
pool->current = (JSArena *) ((char *)ap - offsetof(JSArena, next));
/*
* This is a non-LIFO deallocation, so take care to fix up a->next's back
* pointer in its header, if a->next is oversized.
*/
*ap = b = a->next;
if (b && b->avail - b->base > pool->arenasize) {
JS_ASSERT(GET_HEADER(pool, b) == &a->next);
SET_HEADER(pool, b, ap);
}
JS_CLEAR_ARENA(a);
JS_COUNT_ARENA(pool,--);
free(a);
}
JS_PUBLIC_API(void)
JS_FreeArenaPool(JSArenaPool *pool)
{
FreeArenaList(pool, &pool->first, JS_FALSE);
COUNT(pool, ndeallocs);
}
JS_PUBLIC_API(void)
JS_FinishArenaPool(JSArenaPool *pool)
{
FreeArenaList(pool, &pool->first, JS_TRUE);
#ifdef JS_ARENAMETER
{
JSArenaStats *stats, **statsp;
if (pool->stats.name)
free(pool->stats.name);
for (statsp = &arena_stats_list; (stats = *statsp) != 0;
statsp = &stats->next) {
if (stats == &pool->stats) {
*statsp = stats->next;
return;
}
}
}
#endif
}
JS_PUBLIC_API(void)
JS_ArenaFinish()
{
JSArena *a, *next;
JS_ACQUIRE_LOCK(arena_freelist_lock);
a = arena_freelist;
arena_freelist = NULL;
JS_RELEASE_LOCK(arena_freelist_lock);
for (; a; a = next) {
next = a->next;
free(a);
}
}
JS_PUBLIC_API(void)
JS_ArenaShutDown(void)
{
#ifdef JS_THREADSAFE
/* Must come through here once in the process's last thread! */
if (arena_freelist_lock) {
JS_DESTROY_LOCK(arena_freelist_lock);
arena_freelist_lock = NULL;
}
#endif
}
#ifdef JS_ARENAMETER
JS_PUBLIC_API(void)
JS_ArenaCountAllocation(JSArenaPool *pool, size_t nb)
{
pool->stats.nallocs++;
pool->stats.nbytes += nb;
if (nb > pool->stats.maxalloc)
pool->stats.maxalloc = nb;
pool->stats.variance += nb * nb;
}
JS_PUBLIC_API(void)
JS_ArenaCountInplaceGrowth(JSArenaPool *pool, size_t size, size_t incr)
{
pool->stats.ninplace++;
}
JS_PUBLIC_API(void)
JS_ArenaCountGrowth(JSArenaPool *pool, size_t size, size_t incr)
{
pool->stats.ngrows++;
pool->stats.nbytes += incr;
pool->stats.variance -= size * size;
size += incr;
if (size > pool->stats.maxalloc)
pool->stats.maxalloc = size;
pool->stats.variance += size * size;
}
JS_PUBLIC_API(void)
JS_ArenaCountRelease(JSArenaPool *pool, char *mark)
{
pool->stats.nreleases++;
}
JS_PUBLIC_API(void)
JS_ArenaCountRetract(JSArenaPool *pool, char *mark)
{
pool->stats.nfastrels++;
}
#include <math.h>
#include <stdio.h>
JS_PUBLIC_API(void)
JS_DumpArenaStats(FILE *fp)
{
JSArenaStats *stats;
uint32 nallocs, nbytes;
double mean, variance, sigma;
for (stats = arena_stats_list; stats; stats = stats->next) {
nallocs = stats->nallocs;
if (nallocs != 0) {
nbytes = stats->nbytes;
mean = (double)nbytes / nallocs;
variance = stats->variance * nallocs - nbytes * nbytes;
if (variance < 0 || nallocs == 1)
variance = 0;
else
variance /= nallocs * (nallocs - 1);
sigma = sqrt(variance);
} else {
mean = variance = sigma = 0;
}
fprintf(fp, "\n%s allocation statistics:\n", stats->name);
fprintf(fp, " number of arenas: %u\n", stats->narenas);
fprintf(fp, " number of allocations: %u\n", stats->nallocs);
fprintf(fp, " number of free arena reclaims: %u\n", stats->nreclaims);
fprintf(fp, " number of malloc calls: %u\n", stats->nmallocs);
fprintf(fp, " number of deallocations: %u\n", stats->ndeallocs);
fprintf(fp, " number of allocation growths: %u\n", stats->ngrows);
fprintf(fp, " number of in-place growths: %u\n", stats->ninplace);
fprintf(fp, " number of realloc'ing growths: %u\n", stats->nreallocs);
fprintf(fp, "number of released allocations: %u\n", stats->nreleases);
fprintf(fp, " number of fast releases: %u\n", stats->nfastrels);
fprintf(fp, " total bytes allocated: %u\n", stats->nbytes);
fprintf(fp, " mean allocation size: %g\n", mean);
fprintf(fp, " standard deviation: %g\n", sigma);
fprintf(fp, " maximum allocation size: %u\n", stats->maxalloc);
}
}
#endif /* JS_ARENAMETER */

View File

@@ -1,302 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsarena_h___
#define jsarena_h___
/*
* Lifetime-based fast allocation, inspired by much prior art, including
* "Fast Allocation and Deallocation of Memory Based on Object Lifetimes"
* David R. Hanson, Software -- Practice and Experience, Vol. 20(1).
*
* Also supports LIFO allocation (JS_ARENA_MARK/JS_ARENA_RELEASE).
*/
#include <stdlib.h>
#include "jstypes.h"
#include "jscompat.h"
JS_BEGIN_EXTERN_C
typedef struct JSArena JSArena;
typedef struct JSArenaPool JSArenaPool;
struct JSArena {
JSArena *next; /* next arena for this lifetime */
jsuword base; /* aligned base address, follows this header */
jsuword limit; /* one beyond last byte in arena */
jsuword avail; /* points to next available byte */
};
#ifdef JS_ARENAMETER
typedef struct JSArenaStats JSArenaStats;
struct JSArenaStats {
JSArenaStats *next; /* next in arenaStats list */
char *name; /* name for debugging */
uint32 narenas; /* number of arenas in pool */
uint32 nallocs; /* number of JS_ARENA_ALLOCATE() calls */
uint32 nreclaims; /* number of reclaims from freeArenas */
uint32 nmallocs; /* number of malloc() calls */
uint32 ndeallocs; /* number of lifetime deallocations */
uint32 ngrows; /* number of JS_ARENA_GROW() calls */
uint32 ninplace; /* number of in-place growths */
uint32 nreallocs; /* number of arena grow extending reallocs */
uint32 nreleases; /* number of JS_ARENA_RELEASE() calls */
uint32 nfastrels; /* number of "fast path" releases */
size_t nbytes; /* total bytes allocated */
size_t maxalloc; /* maximum allocation size in bytes */
double variance; /* size variance accumulator */
};
#endif
struct JSArenaPool {
JSArena first; /* first arena in pool list */
JSArena *current; /* arena from which to allocate space */
size_t arenasize; /* net exact size of a new arena */
jsuword mask; /* alignment mask (power-of-2 - 1) */
#ifdef JS_ARENAMETER
JSArenaStats stats;
#endif
};
/*
* If the including .c file uses only one power-of-2 alignment, it may define
* JS_ARENA_CONST_ALIGN_MASK to the alignment mask and save a few instructions
* per ALLOCATE and GROW.
*/
#ifdef JS_ARENA_CONST_ALIGN_MASK
#define JS_ARENA_ALIGN(pool, n) (((jsuword)(n) + JS_ARENA_CONST_ALIGN_MASK) \
& ~(jsuword)JS_ARENA_CONST_ALIGN_MASK)
#define JS_INIT_ARENA_POOL(pool, name, size) \
JS_InitArenaPool(pool, name, size, JS_ARENA_CONST_ALIGN_MASK + 1)
#else
#define JS_ARENA_ALIGN(pool, n) (((jsuword)(n) + (pool)->mask) & ~(pool)->mask)
#endif
#define JS_ARENA_ALLOCATE(p, pool, nb) \
JS_ARENA_ALLOCATE_CAST(p, void *, pool, nb)
#define JS_ARENA_ALLOCATE_TYPE(p, type, pool) \
JS_ARENA_ALLOCATE_CAST(p, type *, pool, sizeof(type))
#define JS_ARENA_ALLOCATE_CAST(p, type, pool, nb) \
JS_BEGIN_MACRO \
JSArena *_a = (pool)->current; \
size_t _nb = JS_ARENA_ALIGN(pool, nb); \
jsuword _p = _a->avail; \
jsuword _q = _p + _nb; \
JS_ASSERT(_q >= _p); \
if (_q > _a->limit) \
_p = (jsuword)JS_ArenaAllocate(pool, _nb); \
else \
_a->avail = _q; \
p = (type) _p; \
JS_ArenaCountAllocation(pool, nb); \
JS_END_MACRO
#define JS_ARENA_GROW(p, pool, size, incr) \
JS_ARENA_GROW_CAST(p, void *, pool, size, incr)
#define JS_ARENA_GROW_CAST(p, type, pool, size, incr) \
JS_BEGIN_MACRO \
JSArena *_a = (pool)->current; \
if (_a->avail == (jsuword)(p) + JS_ARENA_ALIGN(pool, size)) { \
size_t _nb = (size) + (incr); \
jsuword _q = (jsuword)(p) + JS_ARENA_ALIGN(pool, _nb); \
if (_q <= _a->limit) { \
_a->avail = _q; \
JS_ArenaCountInplaceGrowth(pool, size, incr); \
} else if ((jsuword)(p) == _a->base) { \
p = (type) JS_ArenaRealloc(pool, p, size, incr); \
} else { \
p = (type) JS_ArenaGrow(pool, p, size, incr); \
} \
} else { \
p = (type) JS_ArenaGrow(pool, p, size, incr); \
} \
JS_ArenaCountGrowth(pool, size, incr); \
JS_END_MACRO
#define JS_ARENA_MARK(pool) ((void *) (pool)->current->avail)
#define JS_UPTRDIFF(p,q) ((jsuword)(p) - (jsuword)(q))
#ifdef DEBUG
#define JS_FREE_PATTERN 0xDA
#define JS_CLEAR_UNUSED(a) (JS_ASSERT((a)->avail <= (a)->limit), \
memset((void*)(a)->avail, JS_FREE_PATTERN, \
(a)->limit - (a)->avail))
#define JS_CLEAR_ARENA(a) memset((void*)(a), JS_FREE_PATTERN, \
(a)->limit - (jsuword)(a))
#else
#define JS_CLEAR_UNUSED(a) /* nothing */
#define JS_CLEAR_ARENA(a) /* nothing */
#endif
#define JS_ARENA_RELEASE(pool, mark) \
JS_BEGIN_MACRO \
char *_m = (char *)(mark); \
JSArena *_a = (pool)->current; \
if (_a != &(pool)->first && \
JS_UPTRDIFF(_m, _a->base) <= JS_UPTRDIFF(_a->avail, _a->base)) { \
_a->avail = (jsuword)JS_ARENA_ALIGN(pool, _m); \
JS_ASSERT(_a->avail <= _a->limit); \
JS_CLEAR_UNUSED(_a); \
JS_ArenaCountRetract(pool, _m); \
} else { \
JS_ArenaRelease(pool, _m); \
} \
JS_ArenaCountRelease(pool, _m); \
JS_END_MACRO
#ifdef JS_ARENAMETER
#define JS_COUNT_ARENA(pool,op) ((pool)->stats.narenas op)
#else
#define JS_COUNT_ARENA(pool,op)
#endif
#define JS_ARENA_DESTROY(pool, a, pnext) \
JS_BEGIN_MACRO \
JS_COUNT_ARENA(pool,--); \
if ((pool)->current == (a)) (pool)->current = &(pool)->first; \
*(pnext) = (a)->next; \
JS_CLEAR_ARENA(a); \
free(a); \
(a) = NULL; \
JS_END_MACRO
/*
* Initialize an arena pool with the given name for debugging and metering,
* with a minimum size per arena of size bytes.
*/
extern JS_PUBLIC_API(void)
JS_InitArenaPool(JSArenaPool *pool, const char *name, size_t size,
size_t align);
/*
* Free the arenas in pool. The user may continue to allocate from pool
* after calling this function. There is no need to call JS_InitArenaPool()
* again unless JS_FinishArenaPool(pool) has been called.
*/
extern JS_PUBLIC_API(void)
JS_FreeArenaPool(JSArenaPool *pool);
/*
* Free the arenas in pool and finish using it altogether.
*/
extern JS_PUBLIC_API(void)
JS_FinishArenaPool(JSArenaPool *pool);
/*
* Finish using arenas, freeing all memory associated with them except for
* any locks needed for thread safety.
*/
extern JS_PUBLIC_API(void)
JS_ArenaFinish(void);
/*
* Free any locks or other memory needed for thread safety, just before
* shutting down. At that point, we must be called by a single thread.
*
* After shutting down, the next thread to call JS_InitArenaPool must not
* race with any other thread. Once a pool has been initialized, threads
* may safely call jsarena.c functions on thread-local pools. The upshot
* is that pools are per-thread, but the underlying global freelist is
* thread-safe, provided that both the first pool initialization and the
* shut-down call are single-threaded.
*/
extern JS_PUBLIC_API(void)
JS_ArenaShutDown(void);
/*
* Friend functions used by the JS_ARENA_*() macros.
*/
extern JS_PUBLIC_API(void *)
JS_ArenaAllocate(JSArenaPool *pool, size_t nb);
extern JS_PUBLIC_API(void *)
JS_ArenaRealloc(JSArenaPool *pool, void *p, size_t size, size_t incr);
extern JS_PUBLIC_API(void *)
JS_ArenaGrow(JSArenaPool *pool, void *p, size_t size, size_t incr);
extern JS_PUBLIC_API(void)
JS_ArenaRelease(JSArenaPool *pool, char *mark);
/*
* Function to be used directly when an allocation has likely grown to consume
* an entire JSArena, in which case the arena is returned to the malloc heap.
*/
extern JS_PUBLIC_API(void)
JS_ArenaFreeAllocation(JSArenaPool *pool, void *p, size_t size);
#ifdef JS_ARENAMETER
#include <stdio.h>
extern JS_PUBLIC_API(void)
JS_ArenaCountAllocation(JSArenaPool *pool, size_t nb);
extern JS_PUBLIC_API(void)
JS_ArenaCountInplaceGrowth(JSArenaPool *pool, size_t size, size_t incr);
extern JS_PUBLIC_API(void)
JS_ArenaCountGrowth(JSArenaPool *pool, size_t size, size_t incr);
extern JS_PUBLIC_API(void)
JS_ArenaCountRelease(JSArenaPool *pool, char *mark);
extern JS_PUBLIC_API(void)
JS_ArenaCountRetract(JSArenaPool *pool, char *mark);
extern JS_PUBLIC_API(void)
JS_DumpArenaStats(FILE *fp);
#else /* !JS_ARENAMETER */
#define JS_ArenaCountAllocation(ap, nb) /* nothing */
#define JS_ArenaCountInplaceGrowth(ap, size, incr) /* nothing */
#define JS_ArenaCountGrowth(ap, size, incr) /* nothing */
#define JS_ArenaCountRelease(ap, mark) /* nothing */
#define JS_ArenaCountRetract(ap, mark) /* nothing */
#endif /* !JS_ARENAMETER */
JS_END_EXTERN_C
#endif /* jsarena_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,80 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsarray_h___
#define jsarray_h___
/*
* JS Array interface.
*/
#include "jsprvtd.h"
#include "jspubtd.h"
JS_BEGIN_EXTERN_C
extern JSBool
js_IdIsIndex(jsval id, jsuint *indexp);
extern JSClass js_ArrayClass;
extern JSObject *
js_InitArrayClass(JSContext *cx, JSObject *obj);
extern JSObject *
js_NewArrayObject(JSContext *cx, jsuint length, jsval *vector);
extern JSBool
js_GetLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
extern JSBool
js_SetLengthProperty(JSContext *cx, JSObject *obj, jsuint length);
extern JSBool
js_HasLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
/*
* JS-specific heap sort function.
*/
typedef int (*JSComparator)(const void *a, const void *b, void *arg);
extern JSBool
js_HeapSort(void *vec, size_t nel, size_t elsize, JSComparator cmp, void *arg);
JS_END_EXTERN_C
#endif /* jsarray_h___ */

View File

@@ -1,951 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* JS atom table.
*/
#include "jsstddef.h"
#include <stdlib.h>
#include <string.h>
#include "jstypes.h"
#include "jsutil.h" /* Added by JSIFY */
#include "jshash.h" /* Added by JSIFY */
#include "jsprf.h"
#include "jsapi.h"
#include "jsatom.h"
#include "jscntxt.h"
#include "jsconfig.h"
#include "jsgc.h"
#include "jslock.h"
#include "jsnum.h"
#include "jsopcode.h"
#include "jsstr.h"
JS_FRIEND_API(const char *)
js_AtomToPrintableString(JSContext *cx, JSAtom *atom)
{
return js_ValueToPrintableString(cx, ATOM_KEY(atom));
}
extern const char js_Error_str[]; /* trivial, from jsexn.h */
/*
* Keep this in sync with jspubtd.h -- an assertion below will insist that
* its length match the JSType enum's JSTYPE_LIMIT limit value.
*/
const char *js_type_str[] = {
"undefined",
js_object_str,
"function",
"string",
"number",
"boolean",
"null",
"xml",
};
const char *js_boolean_str[] = {
js_false_str,
js_true_str
};
const char js_Arguments_str[] = "Arguments";
const char js_Array_str[] = "Array";
const char js_Boolean_str[] = "Boolean";
const char js_Call_str[] = "Call";
const char js_Date_str[] = "Date";
const char js_Function_str[] = "Function";
const char js_Math_str[] = "Math";
const char js_Number_str[] = "Number";
const char js_Object_str[] = "Object";
const char js_RegExp_str[] = "RegExp";
const char js_Script_str[] = "Script";
const char js_String_str[] = "String";
const char js_anonymous_str[] = "anonymous";
const char js_arguments_str[] = "arguments";
const char js_arity_str[] = "arity";
const char js_callee_str[] = "callee";
const char js_caller_str[] = "caller";
const char js_class_prototype_str[] = "prototype";
const char js_constructor_str[] = "constructor";
const char js_count_str[] = "__count__";
const char js_each_str[] = "each";
const char js_eval_str[] = "eval";
const char js_getter_str[] = "getter";
const char js_get_str[] = "get";
const char js_index_str[] = "index";
const char js_input_str[] = "input";
const char js_length_str[] = "length";
const char js_name_str[] = "name";
const char js_noSuchMethod_str[] = "__noSuchMethod__";
const char js_object_str[] = "object";
const char js_parent_str[] = "__parent__";
const char js_private_str[] = "private";
const char js_proto_str[] = "__proto__";
const char js_setter_str[] = "setter";
const char js_set_str[] = "set";
const char js_toSource_str[] = "toSource";
const char js_toString_str[] = "toString";
const char js_toLocaleString_str[] = "toLocaleString";
const char js_valueOf_str[] = "valueOf";
#if JS_HAS_XML_SUPPORT
const char js_etago_str[] = "</";
const char js_namespace_str[] = "namespace";
const char js_ptagc_str[] = "/>";
const char js_qualifier_str[] = "::";
const char js_space_str[] = " ";
const char js_stago_str[] = "<";
const char js_star_str[] = "*";
const char js_starQualifier_str[] = "*::";
const char js_tagc_str[] = ">";
const char js_xml_str[] = "xml";
#endif
#ifdef NARCISSUS
const char js_call_str[] = "__call__";
const char js_construct_str[] = "__construct__";
const char js_hasInstance_str[] = "__hasInstance__";
const char js_ExecutionContext_str[] = "ExecutionContext";
const char js_current_str[] = "current";
#endif
#define HASH_OBJECT(o) ((JSHashNumber)(o) >> JSVAL_TAGBITS)
#define HASH_INT(i) ((JSHashNumber)(i))
#define HASH_DOUBLE(dp) ((JSHashNumber)(JSDOUBLE_HI32(*dp) ^ JSDOUBLE_LO32(*dp)))
#define HASH_BOOLEAN(b) ((JSHashNumber)(b))
JS_STATIC_DLL_CALLBACK(JSHashNumber)
js_hash_atom_key(const void *key)
{
jsval v;
jsdouble *dp;
/* Order JSVAL_IS_* tests by likelihood of success. */
v = (jsval)key;
if (JSVAL_IS_STRING(v))
return js_HashString(JSVAL_TO_STRING(v));
if (JSVAL_IS_INT(v))
return HASH_INT(JSVAL_TO_INT(v));
if (JSVAL_IS_DOUBLE(v)) {
dp = JSVAL_TO_DOUBLE(v);
return HASH_DOUBLE(dp);
}
if (JSVAL_IS_OBJECT(v))
return HASH_OBJECT(JSVAL_TO_OBJECT(v));
if (JSVAL_IS_BOOLEAN(v))
return HASH_BOOLEAN(JSVAL_TO_BOOLEAN(v));
return (JSHashNumber)v;
}
JS_STATIC_DLL_CALLBACK(intN)
js_compare_atom_keys(const void *k1, const void *k2)
{
jsval v1, v2;
v1 = (jsval)k1, v2 = (jsval)k2;
if (JSVAL_IS_STRING(v1) && JSVAL_IS_STRING(v2))
return !js_CompareStrings(JSVAL_TO_STRING(v1), JSVAL_TO_STRING(v2));
if (JSVAL_IS_DOUBLE(v1) && JSVAL_IS_DOUBLE(v2)) {
double d1 = *JSVAL_TO_DOUBLE(v1);
double d2 = *JSVAL_TO_DOUBLE(v2);
if (JSDOUBLE_IS_NaN(d1))
return JSDOUBLE_IS_NaN(d2);
#if defined(XP_WIN)
/* XXX MSVC miscompiles such that (NaN == 0) */
if (JSDOUBLE_IS_NaN(d2))
return JS_FALSE;
#endif
return d1 == d2;
}
return v1 == v2;
}
JS_STATIC_DLL_CALLBACK(int)
js_compare_stub(const void *v1, const void *v2)
{
return 1;
}
/* These next two are exported to jsscript.c and used similarly there. */
void * JS_DLL_CALLBACK
js_alloc_table_space(void *priv, size_t size)
{
return malloc(size);
}
void JS_DLL_CALLBACK
js_free_table_space(void *priv, void *item)
{
free(item);
}
JS_STATIC_DLL_CALLBACK(JSHashEntry *)
js_alloc_atom(void *priv, const void *key)
{
JSAtomState *state = (JSAtomState *) priv;
JSAtom *atom;
atom = (JSAtom *) malloc(sizeof(JSAtom));
if (!atom)
return NULL;
#ifdef JS_THREADSAFE
state->tablegen++;
#endif
atom->entry.key = key;
atom->entry.value = NULL;
atom->flags = 0;
atom->number = state->number++;
return &atom->entry;
}
JS_STATIC_DLL_CALLBACK(void)
js_free_atom(void *priv, JSHashEntry *he, uintN flag)
{
if (flag != HT_FREE_ENTRY)
return;
#ifdef JS_THREADSAFE
((JSAtomState *)priv)->tablegen++;
#endif
free(he);
}
static JSHashAllocOps atom_alloc_ops = {
js_alloc_table_space, js_free_table_space,
js_alloc_atom, js_free_atom
};
#define JS_ATOM_HASH_SIZE 1024
JSBool
js_InitAtomState(JSContext *cx, JSAtomState *state)
{
state->table = JS_NewHashTable(JS_ATOM_HASH_SIZE, js_hash_atom_key,
js_compare_atom_keys, js_compare_stub,
&atom_alloc_ops, state);
if (!state->table) {
JS_ReportOutOfMemory(cx);
return JS_FALSE;
}
state->runtime = cx->runtime;
#ifdef JS_THREADSAFE
js_InitLock(&state->lock);
state->tablegen = 0;
#endif
if (!js_InitPinnedAtoms(cx, state)) {
js_FreeAtomState(cx, state);
return JS_FALSE;
}
return JS_TRUE;
}
JSBool
js_InitPinnedAtoms(JSContext *cx, JSAtomState *state)
{
uintN i;
#define FROB(lval,str) \
JS_BEGIN_MACRO \
if (!(state->lval = js_Atomize(cx, str, strlen(str), ATOM_PINNED))) \
return JS_FALSE; \
JS_END_MACRO
JS_ASSERT(sizeof js_type_str / sizeof js_type_str[0] == JSTYPE_LIMIT);
for (i = 0; i < JSTYPE_LIMIT; i++)
FROB(typeAtoms[i], js_type_str[i]);
FROB(booleanAtoms[0], js_false_str);
FROB(booleanAtoms[1], js_true_str);
FROB(nullAtom, js_null_str);
FROB(ArgumentsAtom, js_Arguments_str);
FROB(ArrayAtom, js_Array_str);
FROB(BooleanAtom, js_Boolean_str);
FROB(CallAtom, js_Call_str);
FROB(DateAtom, js_Date_str);
FROB(ErrorAtom, js_Error_str);
FROB(FunctionAtom, js_Function_str);
FROB(MathAtom, js_Math_str);
FROB(NumberAtom, js_Number_str);
FROB(ObjectAtom, js_Object_str);
FROB(RegExpAtom, js_RegExp_str);
FROB(ScriptAtom, js_Script_str);
FROB(StringAtom, js_String_str);
FROB(anonymousAtom, js_anonymous_str);
FROB(argumentsAtom, js_arguments_str);
FROB(arityAtom, js_arity_str);
FROB(calleeAtom, js_callee_str);
FROB(callerAtom, js_caller_str);
FROB(classPrototypeAtom, js_class_prototype_str);
FROB(constructorAtom, js_constructor_str);
FROB(countAtom, js_count_str);
FROB(eachAtom, js_each_str);
FROB(evalAtom, js_eval_str);
FROB(getAtom, js_get_str);
FROB(getterAtom, js_getter_str);
FROB(indexAtom, js_index_str);
FROB(inputAtom, js_input_str);
FROB(lengthAtom, js_length_str);
FROB(nameAtom, js_name_str);
FROB(noSuchMethodAtom, js_noSuchMethod_str);
FROB(parentAtom, js_parent_str);
FROB(protoAtom, js_proto_str);
FROB(setAtom, js_set_str);
FROB(setterAtom, js_setter_str);
FROB(toSourceAtom, js_toSource_str);
FROB(toStringAtom, js_toString_str);
FROB(toLocaleStringAtom, js_toLocaleString_str);
FROB(valueOfAtom, js_valueOf_str);
#if JS_HAS_XML_SUPPORT
FROB(etagoAtom, js_etago_str);
FROB(namespaceAtom, js_namespace_str);
FROB(ptagcAtom, js_ptagc_str);
FROB(qualifierAtom, js_qualifier_str);
FROB(spaceAtom, js_space_str);
FROB(stagoAtom, js_stago_str);
FROB(starAtom, js_star_str);
FROB(starQualifierAtom, js_starQualifier_str);
FROB(tagcAtom, js_tagc_str);
FROB(xmlAtom, js_xml_str);
#endif
#ifdef NARCISSUS
FROB(callAtom, js_call_str);
FROB(constructAtom, js_construct_str);
FROB(hasInstanceAtom, js_hasInstance_str);
FROB(ExecutionContextAtom, js_ExecutionContext_str);
FROB(currentAtom, js_current_str);
#endif
#undef FROB
memset(&state->lazy, 0, sizeof state->lazy);
return JS_TRUE;
}
/* NB: cx unused; js_FinishAtomState calls us with null cx. */
void
js_FreeAtomState(JSContext *cx, JSAtomState *state)
{
if (state->table)
JS_HashTableDestroy(state->table);
#ifdef JS_THREADSAFE
js_FinishLock(&state->lock);
#endif
memset(state, 0, sizeof *state);
}
typedef struct UninternArgs {
JSRuntime *rt;
jsatomid leaks;
} UninternArgs;
JS_STATIC_DLL_CALLBACK(intN)
js_atom_uninterner(JSHashEntry *he, intN i, void *arg)
{
JSAtom *atom;
UninternArgs *args;
atom = (JSAtom *)he;
args = (UninternArgs *)arg;
if (ATOM_IS_STRING(atom))
js_FinalizeStringRT(args->rt, ATOM_TO_STRING(atom));
else if (ATOM_IS_OBJECT(atom))
args->leaks++;
return HT_ENUMERATE_NEXT;
}
void
js_FinishAtomState(JSAtomState *state)
{
UninternArgs args;
if (!state->table)
return;
args.rt = state->runtime;
args.leaks = 0;
JS_HashTableEnumerateEntries(state->table, js_atom_uninterner, &args);
#ifdef DEBUG
if (args.leaks != 0) {
fprintf(stderr,
"JS engine warning: %lu atoms remain after destroying the JSRuntime.\n"
" These atoms may point to freed memory. Things reachable\n"
" through them have not been finalized.\n",
(unsigned long) args.leaks);
}
#endif
js_FreeAtomState(NULL, state);
}
typedef struct MarkArgs {
uintN gcflags;
JSGCThingMarker mark;
void *data;
} MarkArgs;
JS_STATIC_DLL_CALLBACK(intN)
js_atom_marker(JSHashEntry *he, intN i, void *arg)
{
JSAtom *atom;
MarkArgs *args;
jsval key;
atom = (JSAtom *)he;
args = (MarkArgs *)arg;
if ((atom->flags & (ATOM_PINNED | ATOM_INTERNED)) ||
(args->gcflags & GC_KEEP_ATOMS)) {
atom->flags |= ATOM_MARK;
key = ATOM_KEY(atom);
if (JSVAL_IS_GCTHING(key))
args->mark(JSVAL_TO_GCTHING(key), args->data);
}
return HT_ENUMERATE_NEXT;
}
void
js_MarkAtomState(JSAtomState *state, uintN gcflags, JSGCThingMarker mark,
void *data)
{
MarkArgs args;
if (!state->table)
return;
args.gcflags = gcflags;
args.mark = mark;
args.data = data;
JS_HashTableEnumerateEntries(state->table, js_atom_marker, &args);
}
JS_STATIC_DLL_CALLBACK(intN)
js_atom_sweeper(JSHashEntry *he, intN i, void *arg)
{
JSAtom *atom;
JSAtomState *state;
atom = (JSAtom *)he;
if (atom->flags & ATOM_MARK) {
atom->flags &= ~ATOM_MARK;
state = (JSAtomState *)arg;
state->liveAtoms++;
return HT_ENUMERATE_NEXT;
}
JS_ASSERT((atom->flags & (ATOM_PINNED | ATOM_INTERNED)) == 0);
atom->entry.key = NULL;
atom->flags = 0;
return HT_ENUMERATE_REMOVE;
}
void
js_SweepAtomState(JSAtomState *state)
{
state->liveAtoms = 0;
if (state->table)
JS_HashTableEnumerateEntries(state->table, js_atom_sweeper, state);
}
JS_STATIC_DLL_CALLBACK(intN)
js_atom_unpinner(JSHashEntry *he, intN i, void *arg)
{
JSAtom *atom;
atom = (JSAtom *)he;
atom->flags &= ~ATOM_PINNED;
return HT_ENUMERATE_NEXT;
}
void
js_UnpinPinnedAtoms(JSAtomState *state)
{
if (state->table)
JS_HashTableEnumerateEntries(state->table, js_atom_unpinner, NULL);
}
static JSAtom *
js_AtomizeHashedKey(JSContext *cx, jsval key, JSHashNumber keyHash, uintN flags)
{
JSAtomState *state;
JSHashTable *table;
JSHashEntry *he, **hep;
JSAtom *atom;
state = &cx->runtime->atomState;
JS_LOCK(&state->lock, cx);
table = state->table;
hep = JS_HashTableRawLookup(table, keyHash, (void *)key);
if ((he = *hep) == NULL) {
he = JS_HashTableRawAdd(table, hep, keyHash, (void *)key, NULL);
if (!he) {
JS_ReportOutOfMemory(cx);
atom = NULL;
goto out;
}
}
atom = (JSAtom *)he;
atom->flags |= flags;
cx->lastAtom = atom;
out:
JS_UNLOCK(&state->lock,cx);
return atom;
}
JSAtom *
js_AtomizeObject(JSContext *cx, JSObject *obj, uintN flags)
{
jsval key;
JSHashNumber keyHash;
/* XXX must be set in the following order or MSVC1.52 will crash */
keyHash = HASH_OBJECT(obj);
key = OBJECT_TO_JSVAL(obj);
return js_AtomizeHashedKey(cx, key, keyHash, flags);
}
JSAtom *
js_AtomizeBoolean(JSContext *cx, JSBool b, uintN flags)
{
jsval key;
JSHashNumber keyHash;
key = BOOLEAN_TO_JSVAL(b);
keyHash = HASH_BOOLEAN(b);
return js_AtomizeHashedKey(cx, key, keyHash, flags);
}
JSAtom *
js_AtomizeInt(JSContext *cx, jsint i, uintN flags)
{
jsval key;
JSHashNumber keyHash;
key = INT_TO_JSVAL(i);
keyHash = HASH_INT(i);
return js_AtomizeHashedKey(cx, key, keyHash, flags);
}
/* Worst-case alignment grain and aligning macro for 2x-sized buffer. */
#define ALIGNMENT(t) JS_MAX(JSVAL_ALIGN, sizeof(t))
#define ALIGN(b,t) ((t*) &(b)[ALIGNMENT(t) - (jsuword)(b) % ALIGNMENT(t)])
JSAtom *
js_AtomizeDouble(JSContext *cx, jsdouble d, uintN flags)
{
jsdouble *dp;
JSHashNumber keyHash;
jsval key;
JSAtomState *state;
JSHashTable *table;
JSHashEntry *he, **hep;
JSAtom *atom;
char buf[2 * ALIGNMENT(double)];
dp = ALIGN(buf, double);
*dp = d;
keyHash = HASH_DOUBLE(dp);
key = DOUBLE_TO_JSVAL(dp);
state = &cx->runtime->atomState;
JS_LOCK(&state->lock, cx);
table = state->table;
hep = JS_HashTableRawLookup(table, keyHash, (void *)key);
if ((he = *hep) == NULL) {
#ifdef JS_THREADSAFE
uint32 gen = state->tablegen;
#endif
JS_UNLOCK(&state->lock,cx);
if (!js_NewDoubleValue(cx, d, &key))
return NULL;
JS_LOCK(&state->lock, cx);
#ifdef JS_THREADSAFE
if (state->tablegen != gen) {
hep = JS_HashTableRawLookup(table, keyHash, (void *)key);
if ((he = *hep) != NULL) {
atom = (JSAtom *)he;
goto out;
}
}
#endif
he = JS_HashTableRawAdd(table, hep, keyHash, (void *)key, NULL);
if (!he) {
JS_ReportOutOfMemory(cx);
atom = NULL;
goto out;
}
}
atom = (JSAtom *)he;
atom->flags |= flags;
cx->lastAtom = atom;
out:
JS_UNLOCK(&state->lock,cx);
return atom;
}
JSAtom *
js_AtomizeString(JSContext *cx, JSString *str, uintN flags)
{
JSHashNumber keyHash;
jsval key;
JSAtomState *state;
JSHashTable *table;
JSHashEntry *he, **hep;
JSAtom *atom;
keyHash = js_HashString(str);
key = STRING_TO_JSVAL(str);
state = &cx->runtime->atomState;
JS_LOCK(&state->lock, cx);
table = state->table;
hep = JS_HashTableRawLookup(table, keyHash, (void *)key);
if ((he = *hep) == NULL) {
#ifdef JS_THREADSAFE
uint32 gen = state->tablegen;
JS_UNLOCK(&state->lock, cx);
#endif
if (flags & ATOM_TMPSTR) {
str = (flags & ATOM_NOCOPY)
? js_NewString(cx, str->chars, str->length, 0)
: js_NewStringCopyN(cx, str->chars, str->length, 0);
if (!str)
return NULL;
key = STRING_TO_JSVAL(str);
} else {
if (!JS_MakeStringImmutable(cx, str))
return NULL;
}
#ifdef JS_THREADSAFE
JS_LOCK(&state->lock, cx);
if (state->tablegen != gen) {
hep = JS_HashTableRawLookup(table, keyHash, (void *)key);
if ((he = *hep) != NULL) {
atom = (JSAtom *)he;
if (flags & ATOM_NOCOPY)
str->chars = NULL;
goto out;
}
}
#endif
he = JS_HashTableRawAdd(table, hep, keyHash, (void *)key, NULL);
if (!he) {
JS_ReportOutOfMemory(cx);
atom = NULL;
goto out;
}
}
atom = (JSAtom *)he;
atom->flags |= flags & (ATOM_PINNED | ATOM_INTERNED);
cx->lastAtom = atom;
out:
JS_UNLOCK(&state->lock,cx);
return atom;
}
JS_FRIEND_API(JSAtom *)
js_Atomize(JSContext *cx, const char *bytes, size_t length, uintN flags)
{
jschar *chars;
JSString *str;
JSAtom *atom;
char buf[2 * ALIGNMENT(JSString)];
/*
* Avoiding the malloc in js_InflateString on shorter strings saves us
* over 20,000 malloc calls on mozilla browser startup. This compares to
* only 131 calls where the string is longer than a 31 char (net) buffer.
* The vast majority of atomized strings are already in the hashtable. So
* js_AtomizeString rarely has to copy the temp string we make.
*/
#define ATOMIZE_BUF_MAX 32
jschar inflated[ATOMIZE_BUF_MAX];
if (length < ATOMIZE_BUF_MAX) {
js_InflateStringToBuffer(inflated, bytes, length);
chars = inflated;
} else {
chars = js_InflateString(cx, bytes, length);
if (!chars)
return NULL;
flags |= ATOM_NOCOPY;
}
str = ALIGN(buf, JSString);
str->chars = chars;
str->length = length;
atom = js_AtomizeString(cx, str, ATOM_TMPSTR | flags);
if (chars != inflated && (!atom || ATOM_TO_STRING(atom)->chars != chars))
JS_free(cx, chars);
return atom;
}
JS_FRIEND_API(JSAtom *)
js_AtomizeChars(JSContext *cx, const jschar *chars, size_t length, uintN flags)
{
JSString *str;
char buf[2 * ALIGNMENT(JSString)];
str = ALIGN(buf, JSString);
str->chars = (jschar *)chars;
str->length = length;
return js_AtomizeString(cx, str, ATOM_TMPSTR | flags);
}
JSAtom *
js_AtomizeValue(JSContext *cx, jsval value, uintN flags)
{
if (JSVAL_IS_STRING(value))
return js_AtomizeString(cx, JSVAL_TO_STRING(value), flags);
if (JSVAL_IS_INT(value))
return js_AtomizeInt(cx, JSVAL_TO_INT(value), flags);
if (JSVAL_IS_DOUBLE(value))
return js_AtomizeDouble(cx, *JSVAL_TO_DOUBLE(value), flags);
if (JSVAL_IS_OBJECT(value))
return js_AtomizeObject(cx, JSVAL_TO_OBJECT(value), flags);
if (JSVAL_IS_BOOLEAN(value))
return js_AtomizeBoolean(cx, JSVAL_TO_BOOLEAN(value), flags);
return js_AtomizeHashedKey(cx, value, (JSHashNumber)value, flags);
}
JSAtom *
js_ValueToStringAtom(JSContext *cx, jsval v)
{
JSString *str;
str = js_ValueToString(cx, v);
if (!str)
return NULL;
return js_AtomizeString(cx, str, 0);
}
JS_STATIC_DLL_CALLBACK(JSHashNumber)
js_hash_atom_ptr(const void *key)
{
const JSAtom *atom = key;
return atom->number;
}
JS_STATIC_DLL_CALLBACK(void *)
js_alloc_temp_space(void *priv, size_t size)
{
JSContext *cx = priv;
void *space;
JS_ARENA_ALLOCATE(space, &cx->tempPool, size);
if (!space)
JS_ReportOutOfMemory(cx);
return space;
}
JS_STATIC_DLL_CALLBACK(void)
js_free_temp_space(void *priv, void *item)
{
}
JS_STATIC_DLL_CALLBACK(JSHashEntry *)
js_alloc_temp_entry(void *priv, const void *key)
{
JSContext *cx = priv;
JSAtomListElement *ale;
JS_ARENA_ALLOCATE_TYPE(ale, JSAtomListElement, &cx->tempPool);
if (!ale) {
JS_ReportOutOfMemory(cx);
return NULL;
}
return &ale->entry;
}
JS_STATIC_DLL_CALLBACK(void)
js_free_temp_entry(void *priv, JSHashEntry *he, uintN flag)
{
}
static JSHashAllocOps temp_alloc_ops = {
js_alloc_temp_space, js_free_temp_space,
js_alloc_temp_entry, js_free_temp_entry
};
JSAtomListElement *
js_IndexAtom(JSContext *cx, JSAtom *atom, JSAtomList *al)
{
JSAtomListElement *ale, *ale2, *next;
JSHashEntry **hep;
ATOM_LIST_LOOKUP(ale, hep, al, atom);
if (!ale) {
if (al->count < 10) {
/* Few enough for linear search, no hash table needed. */
JS_ASSERT(!al->table);
ale = (JSAtomListElement *)js_alloc_temp_entry(cx, atom);
if (!ale)
return NULL;
ALE_SET_ATOM(ale, atom);
ALE_SET_NEXT(ale, al->list);
al->list = ale;
} else {
/* We want to hash. Have we already made a hash table? */
if (!al->table) {
/* No hash table yet, so hep had better be null! */
JS_ASSERT(!hep);
al->table = JS_NewHashTable(8, js_hash_atom_ptr,
JS_CompareValues, JS_CompareValues,
&temp_alloc_ops, cx);
if (!al->table)
return NULL;
/* Insert each ale on al->list into the new hash table. */
for (ale2 = al->list; ale2; ale2 = next) {
next = ALE_NEXT(ale2);
ale2->entry.keyHash = ALE_ATOM(ale2)->number;
hep = JS_HashTableRawLookup(al->table, ale2->entry.keyHash,
ale2->entry.key);
ALE_SET_NEXT(ale2, *hep);
*hep = &ale2->entry;
}
al->list = NULL;
/* Set hep for insertion of atom's ale, immediately below. */
hep = JS_HashTableRawLookup(al->table, atom->number, atom);
}
/* Finally, add an entry for atom into the hash bucket at hep. */
ale = (JSAtomListElement *)
JS_HashTableRawAdd(al->table, hep, atom->number, atom, NULL);
if (!ale)
return NULL;
}
ALE_SET_INDEX(ale, al->count++);
}
return ale;
}
JS_FRIEND_API(JSAtom *)
js_GetAtom(JSContext *cx, JSAtomMap *map, jsatomid i)
{
JSAtom *atom;
static JSAtom dummy;
JS_ASSERT(map->vector && i < map->length);
if (!map->vector || i >= map->length) {
char numBuf[12];
JS_snprintf(numBuf, sizeof numBuf, "%lu", (unsigned long)i);
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_BAD_ATOMIC_NUMBER, numBuf);
return &dummy;
}
atom = map->vector[i];
JS_ASSERT(atom);
return atom;
}
JS_STATIC_DLL_CALLBACK(intN)
js_map_atom(JSHashEntry *he, intN i, void *arg)
{
JSAtomListElement *ale = (JSAtomListElement *)he;
JSAtom **vector = arg;
vector[ALE_INDEX(ale)] = ALE_ATOM(ale);
return HT_ENUMERATE_NEXT;
}
#ifdef DEBUG
jsrefcount js_atom_map_count;
jsrefcount js_atom_map_hash_table_count;
#endif
JS_FRIEND_API(JSBool)
js_InitAtomMap(JSContext *cx, JSAtomMap *map, JSAtomList *al)
{
JSAtom **vector;
JSAtomListElement *ale;
uint32 count;
#ifdef DEBUG
JS_ATOMIC_INCREMENT(&js_atom_map_count);
#endif
ale = al->list;
if (!ale && !al->table) {
map->vector = NULL;
map->length = 0;
return JS_TRUE;
}
count = al->count;
if (count >= ATOM_INDEX_LIMIT) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
JSMSG_TOO_MANY_LITERALS);
return JS_FALSE;
}
vector = (JSAtom **) JS_malloc(cx, (size_t) count * sizeof *vector);
if (!vector)
return JS_FALSE;
if (al->table) {
#ifdef DEBUG
JS_ATOMIC_INCREMENT(&js_atom_map_hash_table_count);
#endif
JS_HashTableEnumerateEntries(al->table, js_map_atom, vector);
} else {
do {
vector[ALE_INDEX(ale)] = ALE_ATOM(ale);
} while ((ale = ALE_NEXT(ale)) != NULL);
}
ATOM_LIST_INIT(al);
map->vector = vector;
map->length = (jsatomid)count;
return JS_TRUE;
}
JS_FRIEND_API(void)
js_FreeAtomMap(JSContext *cx, JSAtomMap *map)
{
if (map->vector) {
JS_free(cx, map->vector);
map->vector = NULL;
}
map->length = 0;
}

View File

@@ -1,460 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsatom_h___
#define jsatom_h___
/*
* JS atom table.
*/
#include <stddef.h>
#include "jstypes.h"
#include "jshash.h" /* Added by JSIFY */
#include "jsapi.h"
#include "jsprvtd.h"
#include "jspubtd.h"
#ifdef JS_THREADSAFE
#include "jslock.h"
#endif
JS_BEGIN_EXTERN_C
#define ATOM_PINNED 0x01 /* atom is pinned against GC */
#define ATOM_INTERNED 0x02 /* pinned variant for JS_Intern* API */
#define ATOM_MARK 0x04 /* atom is reachable via GC */
#define ATOM_NOCOPY 0x40 /* don't copy atom string bytes */
#define ATOM_TMPSTR 0x80 /* internal, to avoid extra string */
struct JSAtom {
JSHashEntry entry; /* key is jsval, value keyword info */
uint32 flags; /* pinned, interned, and mark flags */
jsatomid number; /* atom serial number and hash code */
};
#define ATOM_KEY(atom) ((jsval)(atom)->entry.key)
#define ATOM_IS_OBJECT(atom) JSVAL_IS_OBJECT(ATOM_KEY(atom))
#define ATOM_TO_OBJECT(atom) JSVAL_TO_OBJECT(ATOM_KEY(atom))
#define ATOM_IS_INT(atom) JSVAL_IS_INT(ATOM_KEY(atom))
#define ATOM_TO_INT(atom) JSVAL_TO_INT(ATOM_KEY(atom))
#define ATOM_IS_DOUBLE(atom) JSVAL_IS_DOUBLE(ATOM_KEY(atom))
#define ATOM_TO_DOUBLE(atom) JSVAL_TO_DOUBLE(ATOM_KEY(atom))
#define ATOM_IS_STRING(atom) JSVAL_IS_STRING(ATOM_KEY(atom))
#define ATOM_TO_STRING(atom) JSVAL_TO_STRING(ATOM_KEY(atom))
#define ATOM_IS_BOOLEAN(atom) JSVAL_IS_BOOLEAN(ATOM_KEY(atom))
#define ATOM_TO_BOOLEAN(atom) JSVAL_TO_BOOLEAN(ATOM_KEY(atom))
/*
* Return a printable, lossless char[] representation of a string-type atom.
* The lifetime of the result extends at least until the next GC activation,
* longer if cx's string newborn root is not overwritten.
*/
extern JS_FRIEND_API(const char *)
js_AtomToPrintableString(JSContext *cx, JSAtom *atom);
#define ATOM_KEYWORD(atom) ((struct keyword *)(atom)->entry.value)
#define ATOM_SET_KEYWORD(atom,kw) ((atom)->entry.value = (kw))
struct JSAtomListElement {
JSHashEntry entry;
};
#define ALE_ATOM(ale) ((JSAtom *) (ale)->entry.key)
#define ALE_INDEX(ale) ((jsatomid) (ale)->entry.value)
#define ALE_JSOP(ale) ((JSOp) (ale)->entry.value)
#define ALE_VALUE(ale) ((jsval) (ale)->entry.value)
#define ALE_NEXT(ale) ((JSAtomListElement *) (ale)->entry.next)
#define ALE_SET_ATOM(ale,atom) ((ale)->entry.key = (const void *)(atom))
#define ALE_SET_INDEX(ale,index)((ale)->entry.value = (void *)(index))
#define ALE_SET_JSOP(ale,op) ((ale)->entry.value = (void *)(jsuword)(op))
#define ALE_SET_VALUE(ale,val) ((ale)->entry.value = (JSHashEntry *)(val))
#define ALE_SET_NEXT(ale,link) ((ale)->entry.next = (JSHashEntry *)(link))
struct JSAtomList {
JSAtomListElement *list; /* literals indexed for mapping */
JSHashTable *table; /* hash table if list gets too long */
jsuint count; /* count of indexed literals */
};
#define ATOM_LIST_INIT(al) ((al)->list = NULL, (al)->table = NULL, \
(al)->count = 0)
#define ATOM_LIST_SEARCH(_ale,_al,_atom) \
JS_BEGIN_MACRO \
JSHashEntry **_hep; \
ATOM_LIST_LOOKUP(_ale, _hep, _al, _atom); \
JS_END_MACRO
#define ATOM_LIST_LOOKUP(_ale,_hep,_al,_atom) \
JS_BEGIN_MACRO \
if ((_al)->table) { \
_hep = JS_HashTableRawLookup((_al)->table, _atom->number, _atom); \
_ale = *_hep ? (JSAtomListElement *) *_hep : NULL; \
} else { \
JSAtomListElement **_alep = &(_al)->list; \
_hep = NULL; \
while ((_ale = *_alep) != NULL) { \
if (ALE_ATOM(_ale) == (_atom)) { \
/* Hit, move atom's element to the front of the list. */ \
*_alep = ALE_NEXT(_ale); \
ALE_SET_NEXT(_ale, (_al)->list); \
(_al)->list = _ale; \
break; \
} \
_alep = (JSAtomListElement **)&_ale->entry.next; \
} \
} \
JS_END_MACRO
struct JSAtomMap {
JSAtom **vector; /* array of ptrs to indexed atoms */
jsatomid length; /* count of (to-be-)indexed atoms */
};
struct JSAtomState {
JSRuntime *runtime; /* runtime that owns us */
JSHashTable *table; /* hash table containing all atoms */
jsatomid number; /* one beyond greatest atom number */
jsatomid liveAtoms; /* number of live atoms after last GC */
/* Type names and value literals. */
JSAtom *typeAtoms[JSTYPE_LIMIT];
JSAtom *booleanAtoms[2];
JSAtom *nullAtom;
/* Various built-in or commonly-used atoms, pinned on first context. */
JSAtom *ArgumentsAtom;
JSAtom *ArrayAtom;
JSAtom *BooleanAtom;
JSAtom *CallAtom;
JSAtom *DateAtom;
JSAtom *ErrorAtom;
JSAtom *FunctionAtom;
JSAtom *MathAtom;
JSAtom *NumberAtom;
JSAtom *ObjectAtom;
JSAtom *RegExpAtom;
JSAtom *ScriptAtom;
JSAtom *StringAtom;
JSAtom *anonymousAtom;
JSAtom *argumentsAtom;
JSAtom *arityAtom;
JSAtom *calleeAtom;
JSAtom *callerAtom;
JSAtom *classPrototypeAtom;
JSAtom *constructorAtom;
JSAtom *countAtom;
JSAtom *etagoAtom;
JSAtom *eachAtom;
JSAtom *evalAtom;
JSAtom *getAtom;
JSAtom *getterAtom;
JSAtom *indexAtom;
JSAtom *inputAtom;
JSAtom *lengthAtom;
JSAtom *nameAtom;
JSAtom *namespaceAtom;
JSAtom *noSuchMethodAtom;
JSAtom *parentAtom;
JSAtom *protoAtom;
JSAtom *ptagcAtom;
JSAtom *qualifierAtom;
JSAtom *setAtom;
JSAtom *setterAtom;
JSAtom *spaceAtom;
JSAtom *stagoAtom;
JSAtom *starAtom;
JSAtom *starQualifierAtom;
JSAtom *tagcAtom;
JSAtom *toLocaleStringAtom;
JSAtom *toSourceAtom;
JSAtom *toStringAtom;
JSAtom *valueOfAtom;
JSAtom *xmlAtom;
/* Less frequently used atoms, pinned lazily by JS_ResolveStandardClass. */
struct {
JSAtom *AnyNameAtom;
JSAtom *AttributeNameAtom;
JSAtom *EvalErrorAtom;
JSAtom *InfinityAtom;
JSAtom *InternalErrorAtom;
JSAtom *NaNAtom;
JSAtom *NamespaceAtom;
JSAtom *QNameAtom;
JSAtom *RangeErrorAtom;
JSAtom *ReferenceErrorAtom;
JSAtom *SyntaxErrorAtom;
JSAtom *TypeErrorAtom;
JSAtom *URIErrorAtom;
JSAtom *XMLAtom;
JSAtom *XMLListAtom;
JSAtom *anynameAtom;
JSAtom *decodeURIAtom;
JSAtom *decodeURIComponentAtom;
JSAtom *defineGetterAtom;
JSAtom *defineSetterAtom;
JSAtom *encodeURIAtom;
JSAtom *encodeURIComponentAtom;
JSAtom *escapeAtom;
JSAtom *functionNamespaceAtom;
JSAtom *functionNamespaceURIAtom;
JSAtom *hasOwnPropertyAtom;
JSAtom *isFiniteAtom;
JSAtom *isNaNAtom;
JSAtom *isPrototypeOfAtom;
JSAtom *isXMLNameAtom;
JSAtom *lookupGetterAtom;
JSAtom *lookupSetterAtom;
JSAtom *parseFloatAtom;
JSAtom *parseIntAtom;
JSAtom *propertyIsEnumerableAtom;
JSAtom *unescapeAtom;
JSAtom *unevalAtom;
JSAtom *unwatchAtom;
JSAtom *watchAtom;
} lazy;
#ifdef JS_THREADSAFE
JSThinLock lock;
volatile uint32 tablegen;
#endif
#ifdef NARCISSUS
JSAtom *callAtom;
JSAtom *constructAtom;
JSAtom *hasInstanceAtom;
JSAtom *ExecutionContextAtom;
JSAtom *currentAtom;
#endif
};
/* Well-known predefined strings and their atoms. */
extern const char *js_type_str[];
extern const char *js_boolean_str[];
extern const char js_Arguments_str[];
extern const char js_Array_str[];
extern const char js_Boolean_str[];
extern const char js_Call_str[];
extern const char js_Date_str[];
extern const char js_Function_str[];
extern const char js_Math_str[];
extern const char js_Number_str[];
extern const char js_Object_str[];
extern const char js_RegExp_str[];
extern const char js_Script_str[];
extern const char js_String_str[];
extern const char js_anonymous_str[];
extern const char js_arguments_str[];
extern const char js_arity_str[];
extern const char js_callee_str[];
extern const char js_caller_str[];
extern const char js_class_prototype_str[];
extern const char js_constructor_str[];
extern const char js_count_str[];
extern const char js_etago_str[];
extern const char js_each_str[];
extern const char js_eval_str[];
extern const char js_getter_str[];
extern const char js_get_str[];
extern const char js_index_str[];
extern const char js_input_str[];
extern const char js_length_str[];
extern const char js_name_str[];
extern const char js_namespace_str[];
extern const char js_noSuchMethod_str[];
extern const char js_object_str[];
extern const char js_parent_str[];
extern const char js_private_str[];
extern const char js_proto_str[];
extern const char js_ptagc_str[];
extern const char js_qualifier_str[];
extern const char js_setter_str[];
extern const char js_set_str[];
extern const char js_space_str[];
extern const char js_stago_str[];
extern const char js_star_str[];
extern const char js_starQualifier_str[];
extern const char js_tagc_str[];
extern const char js_toSource_str[];
extern const char js_toString_str[];
extern const char js_toLocaleString_str[];
extern const char js_valueOf_str[];
extern const char js_xml_str[];
#ifdef NARCISSUS
extern const char js_call_str[];
extern const char js_construct_str[];
extern const char js_hasInstance_str[];
extern const char js_ExecutionContext_str[];
extern const char js_current_str[];
#endif
/*
* Initialize atom state. Return true on success, false with an out of
* memory error report on failure.
*/
extern JSBool
js_InitAtomState(JSContext *cx, JSAtomState *state);
/*
* Free and clear atom state (except for any interned string atoms).
*/
extern void
js_FreeAtomState(JSContext *cx, JSAtomState *state);
/*
* Interned strings are atoms that live until state's runtime is destroyed.
* This function frees all interned string atoms, and then frees and clears
* state's members (just as js_FreeAtomState does), unless there aren't any
* interned strings in state -- in which case state must be "free" already.
*
* NB: js_FreeAtomState is called for each "last" context being destroyed in
* a runtime, where there may yet be another context created in the runtime;
* whereas js_FinishAtomState is called from JS_DestroyRuntime, when we know
* that no more contexts will be created. Thus we minimize garbage during
* context-free episodes on a runtime, while preserving atoms created by the
* JS_Intern*String APIs for the life of the runtime.
*/
extern void
js_FinishAtomState(JSAtomState *state);
/*
* Atom garbage collection hooks.
*/
typedef void
(*JSGCThingMarker)(void *thing, void *data);
extern void
js_MarkAtomState(JSAtomState *state, uintN gcflags, JSGCThingMarker mark,
void *data);
extern void
js_SweepAtomState(JSAtomState *state);
extern JSBool
js_InitPinnedAtoms(JSContext *cx, JSAtomState *state);
extern void
js_UnpinPinnedAtoms(JSAtomState *state);
/*
* Find or create the atom for an object. If we create a new atom, give it the
* type indicated in flags. Return 0 on failure to allocate memory.
*/
extern JSAtom *
js_AtomizeObject(JSContext *cx, JSObject *obj, uintN flags);
/*
* Find or create the atom for a Boolean value. If we create a new atom, give
* it the type indicated in flags. Return 0 on failure to allocate memory.
*/
extern JSAtom *
js_AtomizeBoolean(JSContext *cx, JSBool b, uintN flags);
/*
* Find or create the atom for an integer value. If we create a new atom, give
* it the type indicated in flags. Return 0 on failure to allocate memory.
*/
extern JSAtom *
js_AtomizeInt(JSContext *cx, jsint i, uintN flags);
/*
* Find or create the atom for a double value. If we create a new atom, give
* it the type indicated in flags. Return 0 on failure to allocate memory.
*/
extern JSAtom *
js_AtomizeDouble(JSContext *cx, jsdouble d, uintN flags);
/*
* Find or create the atom for a string. If we create a new atom, give it the
* type indicated in flags. Return 0 on failure to allocate memory.
*/
extern JSAtom *
js_AtomizeString(JSContext *cx, JSString *str, uintN flags);
extern JS_FRIEND_API(JSAtom *)
js_Atomize(JSContext *cx, const char *bytes, size_t length, uintN flags);
extern JS_FRIEND_API(JSAtom *)
js_AtomizeChars(JSContext *cx, const jschar *chars, size_t length, uintN flags);
/*
* This variant handles all value tag types.
*/
extern JSAtom *
js_AtomizeValue(JSContext *cx, jsval value, uintN flags);
/*
* Convert v to an atomized string.
*/
extern JSAtom *
js_ValueToStringAtom(JSContext *cx, jsval v);
/*
* Assign atom an index and insert it on al.
*/
extern JSAtomListElement *
js_IndexAtom(JSContext *cx, JSAtom *atom, JSAtomList *al);
/*
* Get the atom with index i from map.
*/
extern JS_FRIEND_API(JSAtom *)
js_GetAtom(JSContext *cx, JSAtomMap *map, jsatomid i);
/*
* For all unmapped atoms recorded in al, add a mapping from the atom's index
* to its address. The GC must not run until all indexed atoms in atomLists
* have been mapped by scripts connected to live objects (Function and Script
* class objects have scripts as/in their private data -- the GC knows about
* these two classes).
*/
extern JS_FRIEND_API(JSBool)
js_InitAtomMap(JSContext *cx, JSAtomMap *map, JSAtomList *al);
/*
* Free map->vector and clear map.
*/
extern JS_FRIEND_API(void)
js_FreeAtomMap(JSContext *cx, JSAtomMap *map);
JS_END_EXTERN_C
#endif /* jsatom_h___ */

View File

@@ -1,113 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsbit_h___
#define jsbit_h___
#include "jstypes.h"
JS_BEGIN_EXTERN_C
/*
** A jsbitmap_t is a long integer that can be used for bitmaps
*/
typedef JSUword jsbitmap_t; /* NSPR name, a la Unix system types */
typedef jsbitmap_t jsbitmap; /* JS-style scalar typedef name */
#define JS_TEST_BIT(_map,_bit) \
((_map)[(_bit)>>JS_BITS_PER_WORD_LOG2] & (1L << ((_bit) & (JS_BITS_PER_WORD-1))))
#define JS_SET_BIT(_map,_bit) \
((_map)[(_bit)>>JS_BITS_PER_WORD_LOG2] |= (1L << ((_bit) & (JS_BITS_PER_WORD-1))))
#define JS_CLEAR_BIT(_map,_bit) \
((_map)[(_bit)>>JS_BITS_PER_WORD_LOG2] &= ~(1L << ((_bit) & (JS_BITS_PER_WORD-1))))
/*
** Compute the log of the least power of 2 greater than or equal to n
*/
extern JS_PUBLIC_API(JSIntn) JS_CeilingLog2(JSUint32 i);
/*
** Compute the log of the greatest power of 2 less than or equal to n
*/
extern JS_PUBLIC_API(JSIntn) JS_FloorLog2(JSUint32 i);
/*
** Macro version of JS_CeilingLog2: Compute the log of the least power of
** 2 greater than or equal to _n. The result is returned in _log2.
*/
#define JS_CEILING_LOG2(_log2,_n) \
JS_BEGIN_MACRO \
JSUint32 j_ = (JSUint32)(_n); \
(_log2) = 0; \
if ((j_) & ((j_)-1)) \
(_log2) += 1; \
if ((j_) >> 16) \
(_log2) += 16, (j_) >>= 16; \
if ((j_) >> 8) \
(_log2) += 8, (j_) >>= 8; \
if ((j_) >> 4) \
(_log2) += 4, (j_) >>= 4; \
if ((j_) >> 2) \
(_log2) += 2, (j_) >>= 2; \
if ((j_) >> 1) \
(_log2) += 1; \
JS_END_MACRO
/*
** Macro version of JS_FloorLog2: Compute the log of the greatest power of
** 2 less than or equal to _n. The result is returned in _log2.
**
** This is equivalent to finding the highest set bit in the word.
*/
#define JS_FLOOR_LOG2(_log2,_n) \
JS_BEGIN_MACRO \
JSUint32 j_ = (JSUint32)(_n); \
(_log2) = 0; \
if ((j_) >> 16) \
(_log2) += 16, (j_) >>= 16; \
if ((j_) >> 8) \
(_log2) += 8, (j_) >>= 8; \
if ((j_) >> 4) \
(_log2) += 4, (j_) >>= 4; \
if ((j_) >> 2) \
(_log2) += 2, (j_) >>= 2; \
if ((j_) >> 1) \
(_log2) += 1; \
JS_END_MACRO
JS_END_EXTERN_C
#endif /* jsbit_h___ */

View File

@@ -1,220 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* JS boolean implementation.
*/
#include "jsstddef.h"
#include "jstypes.h"
#include "jsutil.h" /* Added by JSIFY */
#include "jsapi.h"
#include "jsatom.h"
#include "jsbool.h"
#include "jscntxt.h"
#include "jsconfig.h"
#include "jsinterp.h"
#include "jslock.h"
#include "jsnum.h"
#include "jsobj.h"
#include "jsstr.h"
JSClass js_BooleanClass = {
"Boolean",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
JSCLASS_NO_OPTIONAL_MEMBERS
};
#if JS_HAS_TOSOURCE
#include "jsprf.h"
static JSBool
bool_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
{
jsval v;
char buf[32];
JSString *str;
if (!JS_InstanceOf(cx, obj, &js_BooleanClass, argv))
return JS_FALSE;
v = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
if (!JSVAL_IS_BOOLEAN(v))
return js_obj_toSource(cx, obj, argc, argv, rval);
JS_snprintf(buf, sizeof buf, "(new %s(%s))",
js_BooleanClass.name,
js_boolean_str[JSVAL_TO_BOOLEAN(v) ? 1 : 0]);
str = JS_NewStringCopyZ(cx, buf);
if (!str)
return JS_FALSE;
*rval = STRING_TO_JSVAL(str);
return JS_TRUE;
}
#endif
static JSBool
bool_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
{
jsval v;
JSAtom *atom;
JSString *str;
if (!JS_InstanceOf(cx, obj, &js_BooleanClass, argv))
return JS_FALSE;
v = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
if (!JSVAL_IS_BOOLEAN(v))
return js_obj_toString(cx, obj, argc, argv, rval);
atom = cx->runtime->atomState.booleanAtoms[JSVAL_TO_BOOLEAN(v) ? 1 : 0];
str = ATOM_TO_STRING(atom);
if (!str)
return JS_FALSE;
*rval = STRING_TO_JSVAL(str);
return JS_TRUE;
}
static JSBool
bool_valueOf(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if (!JS_InstanceOf(cx, obj, &js_BooleanClass, argv))
return JS_FALSE;
*rval = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
return JS_TRUE;
}
static JSFunctionSpec boolean_methods[] = {
#if JS_HAS_TOSOURCE
{js_toSource_str, bool_toSource, 0,0,0},
#endif
{js_toString_str, bool_toString, 0,0,0},
{js_valueOf_str, bool_valueOf, 0,0,0},
{0,0,0,0,0}
};
#ifdef XP_MAC
#undef Boolean
#define Boolean js_Boolean
#endif
static JSBool
Boolean(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
JSBool b;
jsval bval;
if (argc != 0) {
if (!js_ValueToBoolean(cx, argv[0], &b))
return JS_FALSE;
bval = BOOLEAN_TO_JSVAL(b);
} else {
bval = JSVAL_FALSE;
}
if (!(cx->fp->flags & JSFRAME_CONSTRUCTING)) {
*rval = bval;
return JS_TRUE;
}
OBJ_SET_SLOT(cx, obj, JSSLOT_PRIVATE, bval);
return JS_TRUE;
}
JSObject *
js_InitBooleanClass(JSContext *cx, JSObject *obj)
{
JSObject *proto;
proto = JS_InitClass(cx, obj, NULL, &js_BooleanClass, Boolean, 1,
NULL, boolean_methods, NULL, NULL);
if (!proto)
return NULL;
OBJ_SET_SLOT(cx, proto, JSSLOT_PRIVATE, JSVAL_FALSE);
return proto;
}
JSObject *
js_BooleanToObject(JSContext *cx, JSBool b)
{
JSObject *obj;
obj = js_NewObject(cx, &js_BooleanClass, NULL, NULL);
if (!obj)
return NULL;
OBJ_SET_SLOT(cx, obj, JSSLOT_PRIVATE, BOOLEAN_TO_JSVAL(b));
return obj;
}
JSString *
js_BooleanToString(JSContext *cx, JSBool b)
{
return ATOM_TO_STRING(cx->runtime->atomState.booleanAtoms[b ? 1 : 0]);
}
JSBool
js_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp)
{
JSBool b;
jsdouble d;
if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) {
b = JS_FALSE;
} else if (JSVAL_IS_OBJECT(v)) {
if (!JS_VERSION_IS_ECMA(cx)) {
if (!OBJ_DEFAULT_VALUE(cx, JSVAL_TO_OBJECT(v), JSTYPE_BOOLEAN, &v))
return JS_FALSE;
if (!JSVAL_IS_BOOLEAN(v))
v = JSVAL_TRUE; /* non-null object is true */
b = JSVAL_TO_BOOLEAN(v);
} else {
b = JS_TRUE;
}
} else if (JSVAL_IS_STRING(v)) {
b = JSSTRING_LENGTH(JSVAL_TO_STRING(v)) ? JS_TRUE : JS_FALSE;
} else if (JSVAL_IS_INT(v)) {
b = JSVAL_TO_INT(v) ? JS_TRUE : JS_FALSE;
} else if (JSVAL_IS_DOUBLE(v)) {
d = *JSVAL_TO_DOUBLE(v);
b = (!JSDOUBLE_IS_NaN(d) && d != 0) ? JS_TRUE : JS_FALSE;
} else {
JS_ASSERT(JSVAL_IS_BOOLEAN(v));
b = JSVAL_TO_BOOLEAN(v);
}
*bp = b;
return JS_TRUE;
}

View File

@@ -1,64 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsbool_h___
#define jsbool_h___
/*
* JS boolean interface.
*/
JS_BEGIN_EXTERN_C
extern JSClass js_BooleanClass;
extern JSObject *
js_InitBooleanClass(JSContext *cx, JSObject *obj);
extern JSObject *
js_BooleanToObject(JSContext *cx, JSBool b);
extern JSString *
js_BooleanToString(JSContext *cx, JSBool b);
extern JSBool
js_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp);
JS_END_EXTERN_C
#endif /* jsbool_h___ */

View File

@@ -1,139 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsclist_h___
#define jsclist_h___
#include "jstypes.h"
/*
** Circular linked list
*/
typedef struct JSCListStr {
struct JSCListStr *next;
struct JSCListStr *prev;
} JSCList;
/*
** Insert element "_e" into the list, before "_l".
*/
#define JS_INSERT_BEFORE(_e,_l) \
JS_BEGIN_MACRO \
(_e)->next = (_l); \
(_e)->prev = (_l)->prev; \
(_l)->prev->next = (_e); \
(_l)->prev = (_e); \
JS_END_MACRO
/*
** Insert element "_e" into the list, after "_l".
*/
#define JS_INSERT_AFTER(_e,_l) \
JS_BEGIN_MACRO \
(_e)->next = (_l)->next; \
(_e)->prev = (_l); \
(_l)->next->prev = (_e); \
(_l)->next = (_e); \
JS_END_MACRO
/*
** Return the element following element "_e"
*/
#define JS_NEXT_LINK(_e) \
((_e)->next)
/*
** Return the element preceding element "_e"
*/
#define JS_PREV_LINK(_e) \
((_e)->prev)
/*
** Append an element "_e" to the end of the list "_l"
*/
#define JS_APPEND_LINK(_e,_l) JS_INSERT_BEFORE(_e,_l)
/*
** Insert an element "_e" at the head of the list "_l"
*/
#define JS_INSERT_LINK(_e,_l) JS_INSERT_AFTER(_e,_l)
/* Return the head/tail of the list */
#define JS_LIST_HEAD(_l) (_l)->next
#define JS_LIST_TAIL(_l) (_l)->prev
/*
** Remove the element "_e" from it's circular list.
*/
#define JS_REMOVE_LINK(_e) \
JS_BEGIN_MACRO \
(_e)->prev->next = (_e)->next; \
(_e)->next->prev = (_e)->prev; \
JS_END_MACRO
/*
** Remove the element "_e" from it's circular list. Also initializes the
** linkage.
*/
#define JS_REMOVE_AND_INIT_LINK(_e) \
JS_BEGIN_MACRO \
(_e)->prev->next = (_e)->next; \
(_e)->next->prev = (_e)->prev; \
(_e)->next = (_e); \
(_e)->prev = (_e); \
JS_END_MACRO
/*
** Return non-zero if the given circular list "_l" is empty, zero if the
** circular list is not empty
*/
#define JS_CLIST_IS_EMPTY(_l) \
((_l)->next == (_l))
/*
** Initialize a circular list
*/
#define JS_INIT_CLIST(_l) \
JS_BEGIN_MACRO \
(_l)->next = (_l); \
(_l)->prev = (_l); \
JS_END_MACRO
#define JS_INIT_STATIC_CLIST(_l) \
{(_l), (_l)}
#endif /* jsclist_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,652 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jscntxt_h___
#define jscntxt_h___
/*
* JS execution context.
*/
#include "jsarena.h" /* Added by JSIFY */
#include "jsclist.h"
#include "jslong.h"
#include "jsatom.h"
#include "jsconfig.h"
#include "jsdhash.h"
#include "jsgc.h"
#include "jsinterp.h"
#include "jsobj.h"
#include "jsprvtd.h"
#include "jspubtd.h"
#include "jsregexp.h"
JS_BEGIN_EXTERN_C
typedef enum JSGCMode { JS_NO_GC, JS_MAYBE_GC, JS_FORCE_GC } JSGCMode;
typedef enum JSRuntimeState {
JSRTS_DOWN,
JSRTS_LAUNCHING,
JSRTS_UP,
JSRTS_LANDING
} JSRuntimeState;
typedef struct JSPropertyTreeEntry {
JSDHashEntryHdr hdr;
JSScopeProperty *child;
} JSPropertyTreeEntry;
struct JSRuntime {
/* Runtime state, synchronized by the stateChange/gcLock condvar/lock. */
JSRuntimeState state;
/* Garbage collector state, used by jsgc.c. */
JSArenaPool gcArenaPool[GC_NUM_FREELISTS];
JSGCThing *gcFreeList[GC_NUM_FREELISTS];
JSDHashTable gcRootsHash;
JSDHashTable *gcLocksHash;
jsrefcount gcKeepAtoms;
uint32 gcBytes;
uint32 gcLastBytes;
uint32 gcMaxBytes;
uint32 gcLevel;
uint32 gcNumber;
JSPackedBool gcPoke;
JSPackedBool gcRunning;
JSGCCallback gcCallback;
uint32 gcMallocBytes;
/*
* API compatibility requires keeping GCX_PRIVATE bytes separate from the
* original GC types' byte tally. Otherwise embeddings that configure a
* good limit for pre-GCX_PRIVATE versions of the engine will see memory
* over-pressure too often, possibly leading to failed last-ditch GCs.
*
* The new XML GC-thing types do add to gcBytes, and they're larger than
* the original GC-thing type size (8 bytes on most architectures). So a
* user who enables E4X may want to increase the maxbytes value passed to
* JS_NewRuntime. TODO: Note this in the API docs.
*/
uint32 gcPrivateBytes;
#if JS_HAS_XML_SUPPORT
/* Lists of JSXML private data structures to be finalized. */
JSXMLNamespace *gcDoomedNamespaces;
JSXMLQName *gcDoomedQNames;
JSXML *gcDoomedXML;
#endif
#ifdef JS_GCMETER
JSGCStats gcStats;
#endif
/* Literal table maintained by jsatom.c functions. */
JSAtomState atomState;
/* Random number generator state, used by jsmath.c. */
JSBool rngInitialized;
int64 rngMultiplier;
int64 rngAddend;
int64 rngMask;
int64 rngSeed;
jsdouble rngDscale;
/* Well-known numbers held for use by this runtime's contexts. */
jsdouble *jsNaN;
jsdouble *jsNegativeInfinity;
jsdouble *jsPositiveInfinity;
/* Empty string held for use by this runtime's contexts. */
JSString *emptyString;
/* List of active contexts sharing this runtime; protected by gcLock. */
JSCList contextList;
/* These are used for debugging -- see jsprvtd.h and jsdbgapi.h. */
JSTrapHandler interruptHandler;
void *interruptHandlerData;
JSNewScriptHook newScriptHook;
void *newScriptHookData;
JSDestroyScriptHook destroyScriptHook;
void *destroyScriptHookData;
JSTrapHandler debuggerHandler;
void *debuggerHandlerData;
JSSourceHandler sourceHandler;
void *sourceHandlerData;
JSInterpreterHook executeHook;
void *executeHookData;
JSInterpreterHook callHook;
void *callHookData;
JSObjectHook objectHook;
void *objectHookData;
JSTrapHandler throwHook;
void *throwHookData;
JSDebugErrorHook debugErrorHook;
void *debugErrorHookData;
/* More debugging state, see jsdbgapi.c. */
JSCList trapList;
JSCList watchPointList;
/* Weak links to properties, indexed by quickened get/set opcodes. */
/* XXX must come after JSCLists or MSVC alignment bug bites empty lists */
JSPropertyCache propertyCache;
/* Client opaque pointer */
void *data;
#ifdef JS_THREADSAFE
/* These combine to interlock the GC and new requests. */
PRLock *gcLock;
PRCondVar *gcDone;
PRCondVar *requestDone;
uint32 requestCount;
jsword gcThread;
/* Lock and owning thread pointer for JS_LOCK_RUNTIME. */
PRLock *rtLock;
#ifdef DEBUG
jsword rtLockOwner;
#endif
/* Used to synchronize down/up state change; protected by gcLock. */
PRCondVar *stateChange;
/* Used to serialize cycle checks when setting __proto__ or __parent__. */
PRLock *setSlotLock;
PRCondVar *setSlotDone;
JSBool setSlotBusy;
JSScope *setSlotScope; /* deadlock avoidance, see jslock.c */
/*
* State for sharing single-threaded scopes, once a second thread tries to
* lock a scope. The scopeSharingDone condvar is protected by rt->gcLock,
* to minimize number of locks taken in JS_EndRequest.
*
* The scopeSharingTodo linked list is likewise "global" per runtime, not
* one-list-per-context, to conserve space over all contexts, optimizing
* for the likely case that scopes become shared rarely, and among a very
* small set of threads (contexts).
*/
PRCondVar *scopeSharingDone;
JSScope *scopeSharingTodo;
/*
* Magic terminator for the rt->scopeSharingTodo linked list, threaded through
* scope->u.link. This hack allows us to test whether a scope is on the list
* by asking whether scope->u.link is non-null. We use a large, likely bogus
* pointer here to distinguish this value from any valid u.count (small int)
* value.
*/
#define NO_SCOPE_SHARING_TODO ((JSScope *) 0xfeedbeef)
#endif /* JS_THREADSAFE */
/*
* Check property accessibility for objects of arbitrary class. Used at
* present to check f.caller accessibility for any function object f.
*/
JSCheckAccessOp checkObjectAccess;
/* Security principals serialization support. */
JSPrincipalsTranscoder principalsTranscoder;
/* Shared scope property tree, and allocator for its nodes. */
JSDHashTable propertyTreeHash;
JSScopeProperty *propertyFreeList;
JSArenaPool propertyArenaPool;
/* Script filename table. */
struct JSHashTable *scriptFilenameTable;
#ifdef JS_THREADSAFE
PRLock *scriptFilenameTableLock;
#endif
/* Number localization, used by jsnum.c */
const char *thousandsSeparator;
const char *decimalSeparator;
const char *numGrouping;
#ifdef DEBUG
/* Function invocation metering. */
jsrefcount inlineCalls;
jsrefcount nativeCalls;
jsrefcount nonInlineCalls;
jsrefcount constructs;
/* Scope lock and property metering. */
jsrefcount claimAttempts;
jsrefcount claimedScopes;
jsrefcount deadContexts;
jsrefcount deadlocksAvoided;
jsrefcount liveScopes;
jsrefcount sharedScopes;
jsrefcount totalScopes;
jsrefcount badUndependStrings;
jsrefcount liveScopeProps;
jsrefcount totalScopeProps;
jsrefcount livePropTreeNodes;
jsrefcount duplicatePropTreeNodes;
jsrefcount totalPropTreeNodes;
jsrefcount propTreeKidsChunks;
jsrefcount middleDeleteFixups;
/* String instrumentation. */
jsrefcount liveStrings;
jsrefcount totalStrings;
jsrefcount liveDependentStrings;
jsrefcount totalDependentStrings;
double lengthSum;
double lengthSquaredSum;
double strdepLengthSum;
double strdepLengthSquaredSum;
#endif
};
#ifdef DEBUG
# define JS_RUNTIME_METER(rt, which) JS_ATOMIC_INCREMENT(&(rt)->which)
# define JS_RUNTIME_UNMETER(rt, which) JS_ATOMIC_DECREMENT(&(rt)->which)
#else
# define JS_RUNTIME_METER(rt, which) /* nothing */
# define JS_RUNTIME_UNMETER(rt, which) /* nothing */
#endif
#define JS_KEEP_ATOMS(rt) JS_ATOMIC_INCREMENT(&(rt)->gcKeepAtoms);
#define JS_UNKEEP_ATOMS(rt) JS_ATOMIC_DECREMENT(&(rt)->gcKeepAtoms);
#ifdef JS_ARGUMENT_FORMATTER_DEFINED
/*
* Linked list mapping format strings for JS_{Convert,Push}Arguments{,VA} to
* formatter functions. Elements are sorted in non-increasing format string
* length order.
*/
struct JSArgumentFormatMap {
const char *format;
size_t length;
JSArgumentFormatter formatter;
JSArgumentFormatMap *next;
};
#endif
struct JSStackHeader {
uintN nslots;
JSStackHeader *down;
};
#define JS_STACK_SEGMENT(sh) ((jsval *)(sh) + 2)
/*
* Key and entry types for the JSContext.resolvingTable hash table, typedef'd
* here because all consumers need to see these declarations (and not just the
* typedef names, as would be the case for an opaque pointer-to-typedef'd-type
* declaration), along with cx->resolvingTable.
*/
typedef struct JSResolvingKey {
JSObject *obj;
jsid id;
} JSResolvingKey;
typedef struct JSResolvingEntry {
JSDHashEntryHdr hdr;
JSResolvingKey key;
uint32 flags;
} JSResolvingEntry;
#define JSRESFLAG_LOOKUP 0x1 /* resolving id from lookup */
#define JSRESFLAG_WATCH 0x2 /* resolving id from watch */
typedef struct JSLocalRootChunk JSLocalRootChunk;
#define JSLRS_CHUNK_SHIFT 8
#define JSLRS_CHUNK_SIZE JS_BIT(JSLRS_CHUNK_SHIFT)
#define JSLRS_CHUNK_MASK JS_BITMASK(JSLRS_CHUNK_SHIFT)
struct JSLocalRootChunk {
jsval roots[JSLRS_CHUNK_SIZE];
JSLocalRootChunk *down;
};
typedef struct JSLocalRootStack {
uint32 scopeMark;
uint32 rootCount;
JSLocalRootChunk *topChunk;
JSLocalRootChunk firstChunk;
} JSLocalRootStack;
#define JSLRS_NULL_MARK ((uint16) -1)
struct JSContext {
JSCList links;
/* Interpreter activation count. */
uintN interpLevel;
/* Limit pointer for checking stack consumption during recursion. */
jsuword stackLimit;
/* Runtime version control identifier and equality operators. */
uint16 version;
jsbytecode jsop_eq;
jsbytecode jsop_ne;
/* Data shared by threads in an address space. */
JSRuntime *runtime;
/* Stack arena pool and frame pointer register. */
JSArenaPool stackPool;
JSStackFrame *fp;
/* Temporary arena pool used while compiling and decompiling. */
JSArenaPool tempPool;
/* Top-level object and pointer to top stack frame's scope chain. */
JSObject *globalObject;
/* Most recently created things by type, members of the GC's root set. */
JSGCThing *newborn[GCX_NTYPES];
/* Atom root for the last-looked-up atom on this context. */
JSAtom *lastAtom;
/* Regular expression class statics (XXX not shared globally). */
JSRegExpStatics regExpStatics;
/* State for object and array toSource conversion. */
JSSharpObjectMap sharpObjectMap;
/* Argument formatter support for JS_{Convert,Push}Arguments{,VA}. */
JSArgumentFormatMap *argumentFormatMap;
/* Last message string and trace file for debugging. */
char *lastMessage;
#ifdef DEBUG
void *tracefp;
#endif
/* Per-context optional user callbacks. */
JSBranchCallback branchCallback;
JSErrorReporter errorReporter;
/* Client opaque pointer */
void *data;
/* GC and thread-safe state. */
JSStackFrame *dormantFrameChain; /* dormant stack frame to scan */
#ifdef JS_THREADSAFE
jsword thread;
jsrefcount requestDepth;
JSScope *scopeToShare; /* weak reference, see jslock.c */
JSScope *lockedSealedScope; /* weak ref, for low-cost sealed
scope locking */
#endif
#if JS_HAS_LVALUE_RETURN
/*
* Secondary return value from native method called on the left-hand side
* of an assignment operator. The native should store the object in which
* to set a property in *rval, and return the property's id expressed as a
* jsval by calling JS_SetCallReturnValue2(cx, idval).
*/
jsval rval2;
JSPackedBool rval2set;
#endif
#if JS_HAS_XML_SUPPORT
/*
* Bit-set formed from binary exponentials of the XML_* tiny-ids defined
* for boolean settings in jsxml.c, plus an XSF_CACHE_VALID bit. Together
* these act as a cache of the boolean XML.ignore* and XML.prettyPrinting
* property values associated with this context's global object.
*/
uint8 xmlSettingFlags;
#endif
/*
* True if creating an exception object, to prevent runaway recursion.
* NB: creatingException packs with rval2set, #if JS_HAS_LVALUE_RETURN;
* with xmlSettingFlags, #if JS_HAS_XML_SUPPORT; and with throwing below.
*/
JSPackedBool creatingException;
/*
* Exception state -- the exception member is a GC root by definition.
* NB: throwing packs with creatingException and rval2set, above.
*/
JSPackedBool throwing; /* is there a pending exception? */
jsval exception; /* most-recently-thrown exception */
/* Per-context options. */
uint32 options; /* see jsapi.h for JSOPTION_* */
/* Locale specific callbacks for string conversion. */
JSLocaleCallbacks *localeCallbacks;
/*
* cx->resolvingTable is non-null and non-empty if we are initializing
* standard classes lazily, or if we are otherwise recursing indirectly
* from js_LookupProperty through a JSClass.resolve hook. It is used to
* limit runaway recursion (see jsapi.c and jsobj.c).
*/
JSDHashTable *resolvingTable;
/* PDL of stack headers describing stack slots not rooted by argv, etc. */
JSStackHeader *stackHeaders;
/* Optional hook to find principals for an object being accessed on cx. */
JSObjectPrincipalsFinder findObjectPrincipals;
/* Optional stack of scoped local GC roots. */
JSLocalRootStack *localRootStack;
};
/*
* Slightly more readable macros for testing per-context option settings (also
* to hide bitset implementation detail).
*
* JSOPTION_XML must be handled specially in order to propagate from compile-
* to run-time (from cx->options to script->version/cx->version). To do that,
* we copy JSOPTION_XML from cx->options into cx->version as JSVERSION_HAS_XML
* whenever options are set, and preserve this XML flag across version number
* changes done via the JS_SetVersion API.
*
* But when executing a script or scripted function, the interpreter changes
* cx->version, including the XML flag, to script->version. Thus JSOPTION_XML
* is a compile-time option that causes a run-time version change during each
* activation of the compiled script. That version change has the effect of
* changing JS_HAS_XML_OPTION, so that any compiling done via eval enables XML
* support. If an XML-enabled script or function calls a non-XML function,
* the flag bit will be cleared during the callee's activation.
*
* Note that JS_SetVersion API calls never pass JSVERSION_HAS_XML or'd into
* that API's version parameter.
*
* Note also that script->version must contain this XML option flag in order
* for XDR'ed scripts to serialize and deserialize with that option preserved
* for detection at run-time. We can't copy other compile-time options into
* script->version because that would break backward compatibility (certain
* other options, e.g. JSOPTION_VAROBJFIX, are analogous to JSOPTION_XML).
*/
#define JS_HAS_OPTION(cx,option) (((cx)->options & (option)) != 0)
#define JS_HAS_STRICT_OPTION(cx) JS_HAS_OPTION(cx, JSOPTION_STRICT)
#define JS_HAS_WERROR_OPTION(cx) JS_HAS_OPTION(cx, JSOPTION_WERROR)
#define JS_HAS_COMPILE_N_GO_OPTION(cx) JS_HAS_OPTION(cx, JSOPTION_COMPILE_N_GO)
#define JS_HAS_ATLINE_OPTION(cx) JS_HAS_OPTION(cx, JSOPTION_ATLINE)
#define JSVERSION_MASK 0x0FFF /* see JSVersion in jspubtd.h */
#define JSVERSION_HAS_XML 0x1000 /* flag induced by XML option */
#define JS_HAS_XML_OPTION(cx) ((cx)->version & JSVERSION_HAS_XML)
#define JS_HAS_NATIVE_BRANCH_CALLBACK_OPTION(cx) \
JS_HAS_OPTION(cx, JSOPTION_NATIVE_BRANCH_CALLBACK)
/*
* Wrappers for the JSVERSION_IS_* macros from jspubtd.h taking JSContext *cx
* and masking off the XML flag and any other high order bits.
*/
#define JS_VERSION_IS_ECMA(cx) \
JSVERSION_IS_ECMA((cx)->version & JSVERSION_MASK)
#define JS_VERSION_IS_1_2(cx) \
(((cx)->version & JSVERSION_MASK) == JSVERSION_1_2)
/*
* Common subroutine of JS_SetVersion and js_SetVersion, to update per-context
* data that depends on version.
*/
extern void
js_OnVersionChange(JSContext *cx);
/*
* Unlike the JS_SetVersion API, this function stores JSVERSION_HAS_XML and
* any future non-version-number flags induced by compiler options.
*/
extern void
js_SetVersion(JSContext *cx, JSVersion version);
/*
* Create and destroy functions for JSContext, which is manually allocated
* and exclusively owned.
*/
extern JSContext *
js_NewContext(JSRuntime *rt, size_t stackChunkSize);
extern void
js_DestroyContext(JSContext *cx, JSGCMode gcmode);
/*
* Return true if cx points to a context in rt->contextList, else return false.
* NB: the caller (see jslock.c:ClaimScope) must hold rt->gcLock.
*/
extern JSBool
js_ValidContextPointer(JSRuntime *rt, JSContext *cx);
/*
* If unlocked, acquire and release rt->gcLock around *iterp update; otherwise
* the caller must be holding rt->gcLock.
*/
extern JSContext *
js_ContextIterator(JSRuntime *rt, JSBool unlocked, JSContext **iterp);
/*
* JSClass.resolve and watchpoint recursion damping machinery.
*/
extern JSBool
js_StartResolving(JSContext *cx, JSResolvingKey *key, uint32 flag,
JSResolvingEntry **entryp);
extern void
js_StopResolving(JSContext *cx, JSResolvingKey *key, uint32 flag,
JSResolvingEntry *entry, uint32 generation);
/*
* Local root set management.
*/
extern JSBool
js_EnterLocalRootScope(JSContext *cx);
extern void
js_LeaveLocalRootScope(JSContext *cx);
extern void
js_ForgetLocalRoot(JSContext *cx, jsval v);
extern int
js_PushLocalRoot(JSContext *cx, JSLocalRootStack *lrs, jsval v);
extern void
js_MarkLocalRoots(JSContext *cx, JSLocalRootStack *lrs);
/*
* Report an exception, which is currently realized as a printf-style format
* string and its arguments.
*/
typedef enum JSErrNum {
#define MSG_DEF(name, number, count, exception, format) \
name = number,
#include "js.msg"
#undef MSG_DEF
JSErr_Limit
} JSErrNum;
extern const JSErrorFormatString *
js_GetErrorMessage(void *userRef, const char *locale, const uintN errorNumber);
#ifdef va_start
extern JSBool
js_ReportErrorVA(JSContext *cx, uintN flags, const char *format, va_list ap);
extern JSBool
js_ReportErrorNumberVA(JSContext *cx, uintN flags, JSErrorCallback callback,
void *userRef, const uintN errorNumber,
JSBool charArgs, va_list ap);
extern JSBool
js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
void *userRef, const uintN errorNumber,
char **message, JSErrorReport *reportp,
JSBool *warningp, JSBool charArgs, va_list ap);
#endif
extern void
js_ReportOutOfMemory(JSContext *cx, JSErrorCallback errorCallback);
/*
* Report an exception using a previously composed JSErrorReport.
* XXXbe remove from "friend" API
*/
extern JS_FRIEND_API(void)
js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *report);
extern void
js_ReportIsNotDefined(JSContext *cx, const char *name);
extern JSErrorFormatString js_ErrorFormatString[JSErr_Limit];
/*
* See JS_SetThreadStackLimit in jsapi.c, where we check that the stack grows
* in the expected direction. On Unix-y systems, JS_STACK_GROWTH_DIRECTION is
* computed on the build host by jscpucfg.c and written into jsautocfg.h. The
* macro is hardcoded in jscpucfg.h on Windows and Mac systems (for historical
* reasons pre-dating autoconf usage).
*/
#if JS_STACK_GROWTH_DIRECTION > 0
# define JS_CHECK_STACK_SIZE(cx, lval) ((jsuword)&(lval) < (cx)->stackLimit)
#else
# define JS_CHECK_STACK_SIZE(cx, lval) ((jsuword)&(lval) > (cx)->stackLimit)
#endif
JS_END_EXTERN_C
#endif /* jscntxt_h___ */

View File

@@ -1,57 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* -*- Mode: C; tab-width: 8 -*-
* Copyright © 1996-1999 Netscape Communications Corporation, All Rights Reserved.
*/
#ifndef jscompat_h___
#define jscompat_h___
/*
* Compatibility glue for various NSPR versions. We must always define int8,
* int16, jsword, and so on to minimize differences with js/ref, no matter what
* the NSPR typedef names may be.
*/
#include "jstypes.h"
#include "jslong.h"
typedef JSIntn intN;
typedef JSUintn uintN;
typedef JSUword jsuword;
typedef JSWord jsword;
typedef float float32;
#define allocPriv allocPool
#endif /* jscompat_h___ */

View File

@@ -1,496 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* JS configuration macros.
*/
#ifndef JS_VERSION
#define JS_VERSION 150
#endif
/*
* Compile-time JS version configuration. The JS version numbers lie on the
* number line like so:
*
* 1.0 1.1 1.2 1.3 1.4 ECMAv3 1.5
* ^ ^
* | |
* basis for ECMAv1 close to ECMAv2
*
* where ECMAv3 stands for ECMA-262 Edition 3. See the runtime version enum
* JSVersion in jspubtd.h. Code in the engine can therefore count on version
* <= JSVERSION_1_4 to mean "before the Third Edition of ECMA-262" and version
* > JSVERSION_1_4 to mean "at or after the Third Edition".
*
* In the unlikely event that SpiderMonkey ever implements JavaScript 2.0, or
* ECMA-262 Edition 4 (JS2 without certain extensions), the version number to
* use would be near 200, or greater.
*
* The JS_VERSION_ECMA_3 version is the minimal configuration conforming to
* the ECMA-262 Edition 3 specification. Use it for minimal embeddings, where
* you're sure you don't need any of the extensions disabled in this version.
* In order to facilitate testing, JS_HAS_OBJ_PROTO_PROP is defined as part of
* the JS_VERSION_ECMA_3_TEST version.
*/
#define JS_VERSION_ECMA_3 148
#define JS_VERSION_ECMA_3_TEST 149
#if JS_VERSION == JS_VERSION_ECMA_3 || \
JS_VERSION == JS_VERSION_ECMA_3_TEST
#define JS_BUG_NULL_INDEX_PROPS 0 /* o[0] defaults to null, not void */
#define JS_BUG_EMPTY_INDEX_ZERO 0 /* o[""] is equivalent to o[0] */
#define JS_BUG_EAGER_TOSTRING 0 /* o.toString() trumps o.valueOf() */
#define JS_BUG_VOID_TOSTRING 0 /* void 0 + 0 == "undefined0" */
#define JS_BUG_EVAL_THIS_FUN 0 /* eval('this') in function f is f */
#define JS_BUG_EVAL_THIS_SCOPE 0 /* Math.eval('sin(x)') vs. local x */
#define JS_BUG_FALLIBLE_EQOPS 0 /* fallible/intransitive equality ops */
#define JS_BUG_FALLIBLE_TONUM 0 /* fallible ValueToNumber primitive */
#define JS_BUG_WITH_CLOSURE 0 /* with(o)function f(){} sets o.f */
#define JS_HAS_PROP_DELETE 1 /* delete o.p removes p from o */
#define JS_HAS_CALL_OBJECT 1 /* fun.caller is stack frame obj */
#define JS_HAS_LABEL_STATEMENT 1 /* has break/continue to label: */
#define JS_HAS_DO_WHILE_LOOP 1 /* has do {...} while (b) */
#define JS_HAS_SWITCH_STATEMENT 1 /* has switch (v) {case c: ...} */
#define JS_HAS_SOME_PERL_FUN 1 /* has array.join/reverse/sort */
#define JS_HAS_MORE_PERL_FUN 1 /* has array.push, array.pop, etc */
#define JS_HAS_STR_HTML_HELPERS 0 /* has str.anchor, str.bold, etc. */
#define JS_HAS_PERL_SUBSTR 0 /* has str.substr */
#define JS_HAS_VALUEOF_HINT 1 /* valueOf(hint) where hint is typeof */
#define JS_HAS_LEXICAL_CLOSURE 1 /* nested functions, lexically closed */
#define JS_HAS_APPLY_FUNCTION 1 /* has fun.apply(obj, argArray) */
#define JS_HAS_CALL_FUNCTION 1 /* has fun.call(obj, arg1, ... argN) */
#if JS_VERSION == JS_VERSION_ECMA_3_TEST
#define JS_HAS_OBJ_PROTO_PROP 1 /* has o.__proto__ etc. */
#else
#define JS_HAS_OBJ_PROTO_PROP 0 /* has o.__proto__ etc. */
#endif
#define JS_HAS_REGEXPS 1 /* has perl r.e.s via RegExp, /pat/ */
#define JS_HAS_SEQUENCE_OPS 1 /* has array.slice, string.concat */
#define JS_HAS_INITIALIZERS 1 /* has var o = {'foo': 42, 'bar':3} */
#define JS_HAS_OBJ_WATCHPOINT 0 /* has o.watch and o.unwatch */
#define JS_HAS_EXPORT_IMPORT 0 /* has export fun; import obj.fun */
#define JS_HAS_EVAL_THIS_SCOPE 0 /* Math.eval is same as with (Math) */
#define JS_HAS_TRIPLE_EQOPS 1 /* has === and !== identity eqops */
#define JS_HAS_SHARP_VARS 0 /* has #n=, #n# for object literals */
#define JS_HAS_REPLACE_LAMBDA 1 /* has string.replace(re, lambda) */
#define JS_HAS_SCRIPT_OBJECT 0 /* has (new Script("x++")).exec() */
#define JS_HAS_XDR 0 /* has XDR API and internal support */
#define JS_HAS_XDR_FREEZE_THAW 0 /* has XDR freeze/thaw script methods */
#define JS_HAS_EXCEPTIONS 1 /* has exception handling */
#define JS_HAS_UNDEFINED 1 /* has global "undefined" property */
#define JS_HAS_TOSOURCE 0 /* has Object/Array toSource method */
#define JS_HAS_IN_OPERATOR 1 /* has in operator ('p' in {p:1}) */
#define JS_HAS_INSTANCEOF 1 /* has {p:1} instanceof Object */
#define JS_HAS_ARGS_OBJECT 1 /* has minimal ECMA arguments object */
#define JS_HAS_DEBUGGER_KEYWORD 0 /* has hook for debugger keyword */
#define JS_HAS_ERROR_EXCEPTIONS 1 /* has error object hierarchy */
#define JS_HAS_CATCH_GUARD 0 /* has exception handling catch guard */
#define JS_HAS_NEW_OBJ_METHODS 1 /* has Object.prototype query methods */
#define JS_HAS_SPARSE_ARRAYS 0 /* array methods preserve empty elems */
#define JS_HAS_DFLT_MSG_STRINGS 1 /* provides English error messages */
#define JS_HAS_NUMBER_FORMATS 1 /* numbers have formatting methods */
#define JS_HAS_GETTER_SETTER 0 /* has JS2 getter/setter functions */
#define JS_HAS_UNEVAL 0 /* has uneval() top-level function */
#define JS_HAS_CONST 0 /* has JS2 const as alternative var */
#define JS_HAS_FUN_EXPR_STMT 0 /* has function expression statement */
#define JS_HAS_LVALUE_RETURN 1 /* has o.item(i) = j; for native item */
#define JS_HAS_NO_SUCH_METHOD 0 /* has o.__noSuchMethod__ handler */
#define JS_HAS_XML_SUPPORT 0 /* has ECMAScript for XML support */
#elif JS_VERSION == 100
#define JS_BUG_NULL_INDEX_PROPS 1 /* o[0] defaults to null, not void */
#define JS_BUG_EMPTY_INDEX_ZERO 1 /* o[""] is equivalent to o[0] */
#define JS_BUG_EAGER_TOSTRING 1 /* o.toString() trumps o.valueOf() */
#define JS_BUG_VOID_TOSTRING 0 /* void 0 + 0 == "undefined0" */
#define JS_BUG_EVAL_THIS_FUN 0 /* eval('this') in function f is f */
#define JS_BUG_EVAL_THIS_SCOPE 0 /* Math.eval('sin(x)') vs. local x */
#define JS_BUG_FALLIBLE_EQOPS 1 /* fallible/intransitive equality ops */
#define JS_BUG_FALLIBLE_TONUM 1 /* fallible ValueToNumber primitive */
#define JS_BUG_WITH_CLOSURE 0 /* with(o)function f(){} sets o.f */
#define JS_HAS_PROP_DELETE 0 /* delete o.p removes p from o */
#define JS_HAS_CALL_OBJECT 0 /* fun.caller is stack frame obj */
#define JS_HAS_LABEL_STATEMENT 0 /* has break/continue to label: */
#define JS_HAS_DO_WHILE_LOOP 0 /* has do {...} while (b) */
#define JS_HAS_SWITCH_STATEMENT 0 /* has switch (v) {case c: ...} */
#define JS_HAS_SOME_PERL_FUN 0 /* has array.join/reverse/sort */
#define JS_HAS_MORE_PERL_FUN 0 /* has array.push, str.substr, etc */
#define JS_HAS_STR_HTML_HELPERS 1 /* has str.anchor, str.bold, etc. */
#define JS_HAS_PERL_SUBSTR 0 /* has str.substr */
#define JS_HAS_VALUEOF_HINT 0 /* valueOf(hint) where hint is typeof */
#define JS_HAS_LEXICAL_CLOSURE 0 /* nested functions, lexically closed */
#define JS_HAS_APPLY_FUNCTION 0 /* has fun.apply(obj, argArray) */
#define JS_HAS_CALL_FUNCTION 0 /* has fun.call(obj, arg1, ... argN) */
#define JS_HAS_OBJ_PROTO_PROP 0 /* has o.__proto__ etc. */
#define JS_HAS_REGEXPS 0 /* has perl r.e.s via RegExp, /pat/ */
#define JS_HAS_SEQUENCE_OPS 0 /* has array.slice, string.concat */
#define JS_HAS_INITIALIZERS 0 /* has var o = {'foo': 42, 'bar':3} */
#define JS_HAS_OBJ_WATCHPOINT 0 /* has o.watch and o.unwatch */
#define JS_HAS_EXPORT_IMPORT 0 /* has export fun; import obj.fun */
#define JS_HAS_EVAL_THIS_SCOPE 0 /* Math.eval is same as with (Math) */
#define JS_HAS_TRIPLE_EQOPS 0 /* has === and !== identity eqops */
#define JS_HAS_SHARP_VARS 0 /* has #n=, #n# for object literals */
#define JS_HAS_REPLACE_LAMBDA 0 /* has string.replace(re, lambda) */
#define JS_HAS_SCRIPT_OBJECT 0 /* has (new Script("x++")).exec() */
#define JS_HAS_XDR 0 /* has XDR API and internal support */
#define JS_HAS_XDR_FREEZE_THAW 0 /* has XDR freeze/thaw script methods */
#define JS_HAS_EXCEPTIONS 0 /* has exception handling */
#define JS_HAS_UNDEFINED 0 /* has global "undefined" property */
#define JS_HAS_TOSOURCE 0 /* has Object/Array toSource method */
#define JS_HAS_IN_OPERATOR 0 /* has in operator ('p' in {p:1}) */
#define JS_HAS_INSTANCEOF 0 /* has {p:1} instanceof Object */
#define JS_HAS_ARGS_OBJECT 0 /* has minimal ECMA arguments object */
#define JS_HAS_DEBUGGER_KEYWORD 0 /* has hook for debugger keyword */
#define JS_HAS_ERROR_EXCEPTIONS 0 /* has error object hierarchy */
#define JS_HAS_CATCH_GUARD 0 /* has exception handling catch guard */
#define JS_HAS_NEW_OBJ_METHODS 0 /* has Object.prototype query methods */
#define JS_HAS_SPARSE_ARRAYS 0 /* array methods preserve empty elems */
#define JS_HAS_DFLT_MSG_STRINGS 1 /* provides English error messages */
#define JS_HAS_NUMBER_FORMATS 0 /* numbers have formatting methods */
#define JS_HAS_GETTER_SETTER 0 /* has JS2 getter/setter functions */
#define JS_HAS_UNEVAL 0 /* has uneval() top-level function */
#define JS_HAS_CONST 0 /* has JS2 const as alternative var */
#define JS_HAS_FUN_EXPR_STMT 0 /* has function expression statement */
#define JS_HAS_LVALUE_RETURN 0 /* has o.item(i) = j; for native item */
#define JS_HAS_NO_SUCH_METHOD 0 /* has o.__noSuchMethod__ handler */
#define JS_HAS_XML_SUPPORT 0 /* has ECMAScript for XML support */
#elif JS_VERSION == 110
#define JS_BUG_NULL_INDEX_PROPS 1 /* o[0] defaults to null, not void */
#define JS_BUG_EMPTY_INDEX_ZERO 1 /* o[""] is equivalent to o[0] */
#define JS_BUG_EAGER_TOSTRING 1 /* o.toString() trumps o.valueOf() */
#define JS_BUG_VOID_TOSTRING 0 /* void 0 + 0 == "undefined0" */
#define JS_BUG_EVAL_THIS_FUN 1 /* eval('this') in function f is f */
#define JS_BUG_EVAL_THIS_SCOPE 1 /* Math.eval('sin(x)') vs. local x */
#define JS_BUG_FALLIBLE_EQOPS 1 /* fallible/intransitive equality ops */
#define JS_BUG_FALLIBLE_TONUM 1 /* fallible ValueToNumber primitive */
#define JS_BUG_WITH_CLOSURE 0 /* with(o)function f(){} sets o.f */
#define JS_HAS_PROP_DELETE 0 /* delete o.p removes p from o */
#define JS_HAS_CALL_OBJECT 0 /* fun.caller is stack frame obj */
#define JS_HAS_LABEL_STATEMENT 0 /* has break/continue to label: */
#define JS_HAS_DO_WHILE_LOOP 0 /* has do {...} while (b) */
#define JS_HAS_SWITCH_STATEMENT 0 /* has switch (v) {case c: ...} */
#define JS_HAS_SOME_PERL_FUN 1 /* has array.join/reverse/sort */
#define JS_HAS_MORE_PERL_FUN 0 /* has array.push, str.substr, etc */
#define JS_HAS_STR_HTML_HELPERS 1 /* has str.anchor, str.bold, etc. */
#define JS_HAS_PERL_SUBSTR 0 /* has str.substr */
#define JS_HAS_VALUEOF_HINT 0 /* valueOf(hint) where hint is typeof */
#define JS_HAS_LEXICAL_CLOSURE 0 /* nested functions, lexically closed */
#define JS_HAS_APPLY_FUNCTION 0 /* has apply(fun, arg1, ... argN) */
#define JS_HAS_CALL_FUNCTION 0 /* has fun.call(obj, arg1, ... argN) */
#define JS_HAS_OBJ_PROTO_PROP 0 /* has o.__proto__ etc. */
#define JS_HAS_REGEXPS 0 /* has perl r.e.s via RegExp, /pat/ */
#define JS_HAS_SEQUENCE_OPS 0 /* has array.slice, string.concat */
#define JS_HAS_INITIALIZERS 0 /* has var o = {'foo': 42, 'bar':3} */
#define JS_HAS_OBJ_WATCHPOINT 0 /* has o.watch and o.unwatch */
#define JS_HAS_EXPORT_IMPORT 0 /* has export fun; import obj.fun */
#define JS_HAS_EVAL_THIS_SCOPE 0 /* Math.eval is same as with (Math) */
#define JS_HAS_TRIPLE_EQOPS 0 /* has === and !== identity eqops */
#define JS_HAS_SHARP_VARS 0 /* has #n=, #n# for object literals */
#define JS_HAS_REPLACE_LAMBDA 0 /* has string.replace(re, lambda) */
#define JS_HAS_SCRIPT_OBJECT 0 /* has (new Script("x++")).exec() */
#define JS_HAS_XDR 0 /* has XDR API and internal support */
#define JS_HAS_XDR_FREEZE_THAW 0 /* has XDR freeze/thaw script methods */
#define JS_HAS_EXCEPTIONS 0 /* has exception handling */
#define JS_HAS_UNDEFINED 0 /* has global "undefined" property */
#define JS_HAS_TOSOURCE 0 /* has Object/Array toSource method */
#define JS_HAS_IN_OPERATOR 0 /* has in operator ('p' in {p:1}) */
#define JS_HAS_INSTANCEOF 0 /* has {p:1} instanceof Object */
#define JS_HAS_ARGS_OBJECT 0 /* has minimal ECMA arguments object */
#define JS_HAS_DEBUGGER_KEYWORD 0 /* has hook for debugger keyword */
#define JS_HAS_ERROR_EXCEPTIONS 0 /* has error object hierarchy */
#define JS_HAS_CATCH_GUARD 0 /* has exception handling catch guard */
#define JS_HAS_NEW_OBJ_METHODS 0 /* has Object.prototype query methods */
#define JS_HAS_SPARSE_ARRAYS 0 /* array methods preserve empty elems */
#define JS_HAS_DFLT_MSG_STRINGS 1 /* provides English error messages */
#define JS_HAS_NUMBER_FORMATS 0 /* numbers have formatting methods */
#define JS_HAS_GETTER_SETTER 0 /* has JS2 getter/setter functions */
#define JS_HAS_UNEVAL 0 /* has uneval() top-level function */
#define JS_HAS_CONST 0 /* has JS2 const as alternative var */
#define JS_HAS_FUN_EXPR_STMT 0 /* has function expression statement */
#define JS_HAS_LVALUE_RETURN 0 /* has o.item(i) = j; for native item */
#define JS_HAS_NO_SUCH_METHOD 0 /* has o.__noSuchMethod__ handler */
#define JS_HAS_XML_SUPPORT 0 /* has ECMAScript for XML support */
#elif JS_VERSION == 120
#define JS_BUG_NULL_INDEX_PROPS 0 /* o[0] defaults to null, not void */
#define JS_BUG_EMPTY_INDEX_ZERO 0 /* o[""] is equivalent to o[0] */
#define JS_BUG_EAGER_TOSTRING 0 /* o.toString() trumps o.valueOf() */
#define JS_BUG_VOID_TOSTRING 1 /* void 0 + 0 == "undefined0" */
#define JS_BUG_EVAL_THIS_FUN 0 /* eval('this') in function f is f */
#define JS_BUG_EVAL_THIS_SCOPE 0 /* Math.eval('sin(x)') vs. local x */
#define JS_BUG_FALLIBLE_EQOPS 0 /* fallible/intransitive equality ops */
#define JS_BUG_FALLIBLE_TONUM 0 /* fallible ValueToNumber primitive */
#define JS_BUG_WITH_CLOSURE 1 /* with(o)function f(){} sets o.f */
#define JS_HAS_PROP_DELETE 1 /* delete o.p removes p from o */
#define JS_HAS_CALL_OBJECT 1 /* fun.caller is stack frame obj */
#define JS_HAS_LABEL_STATEMENT 1 /* has break/continue to label: */
#define JS_HAS_DO_WHILE_LOOP 1 /* has do {...} while (b) */
#define JS_HAS_SWITCH_STATEMENT 1 /* has switch (v) {case c: ...} */
#define JS_HAS_SOME_PERL_FUN 1 /* has array.join/reverse/sort */
#define JS_HAS_MORE_PERL_FUN 1 /* has array.push, str.substr, etc */
#define JS_HAS_STR_HTML_HELPERS 1 /* has str.anchor, str.bold, etc. */
#define JS_HAS_PERL_SUBSTR 1 /* has str.substr */
#define JS_HAS_VALUEOF_HINT 1 /* valueOf(hint) where hint is typeof */
#define JS_HAS_LEXICAL_CLOSURE 1 /* nested functions, lexically closed */
#define JS_HAS_APPLY_FUNCTION 1 /* has apply(fun, arg1, ... argN) */
#define JS_HAS_CALL_FUNCTION 0 /* has fun.call(obj, arg1, ... argN) */
#define JS_HAS_OBJ_PROTO_PROP 1 /* has o.__proto__ etc. */
#define JS_HAS_REGEXPS 1 /* has perl r.e.s via RegExp, /pat/ */
#define JS_HAS_SEQUENCE_OPS 1 /* has array.slice, string.concat */
#define JS_HAS_INITIALIZERS 1 /* has var o = {'foo': 42, 'bar':3} */
#define JS_HAS_OBJ_WATCHPOINT 1 /* has o.watch and o.unwatch */
#define JS_HAS_EXPORT_IMPORT 1 /* has export fun; import obj.fun */
#define JS_HAS_EVAL_THIS_SCOPE 1 /* Math.eval is same as with (Math) */
#define JS_HAS_TRIPLE_EQOPS 0 /* has === and !== identity eqops */
#define JS_HAS_SHARP_VARS 0 /* has #n=, #n# for object literals */
#define JS_HAS_REPLACE_LAMBDA 0 /* has string.replace(re, lambda) */
#define JS_HAS_SCRIPT_OBJECT 0 /* has (new Script("x++")).exec() */
#define JS_HAS_XDR 0 /* has XDR API and internal support */
#define JS_HAS_XDR_FREEZE_THAW 0 /* has XDR freeze/thaw script methods */
#define JS_HAS_EXCEPTIONS 0 /* has exception handling */
#define JS_HAS_UNDEFINED 0 /* has global "undefined" property */
#define JS_HAS_TOSOURCE 0 /* has Object/Array toSource method */
#define JS_HAS_IN_OPERATOR 0 /* has in operator ('p' in {p:1}) */
#define JS_HAS_INSTANCEOF 0 /* has {p:1} instanceof Object */
#define JS_HAS_ARGS_OBJECT 0 /* has minimal ECMA arguments object */
#define JS_HAS_DEBUGGER_KEYWORD 0 /* has hook for debugger keyword */
#define JS_HAS_ERROR_EXCEPTIONS 0 /* has error object hierarchy */
#define JS_HAS_CATCH_GUARD 0 /* has exception handling catch guard */
#define JS_HAS_NEW_OBJ_METHODS 0 /* has Object.prototype query methods */
#define JS_HAS_SPARSE_ARRAYS 0 /* array methods preserve empty elems */
#define JS_HAS_DFLT_MSG_STRINGS 1 /* provides English error messages */
#define JS_HAS_NUMBER_FORMATS 0 /* numbers have formatting methods */
#define JS_HAS_GETTER_SETTER 0 /* has JS2 getter/setter functions */
#define JS_HAS_UNEVAL 0 /* has uneval() top-level function */
#define JS_HAS_CONST 0 /* has JS2 const as alternative var */
#define JS_HAS_FUN_EXPR_STMT 0 /* has function expression statement */
#define JS_HAS_LVALUE_RETURN 0 /* has o.item(i) = j; for native item */
#define JS_HAS_NO_SUCH_METHOD 0 /* has o.__noSuchMethod__ handler */
#define JS_HAS_XML_SUPPORT 0 /* has ECMAScript for XML support */
#elif JS_VERSION == 130
#define JS_BUG_NULL_INDEX_PROPS 0 /* o[0] defaults to null, not void */
#define JS_BUG_EMPTY_INDEX_ZERO 0 /* o[""] is equivalent to o[0] */
#define JS_BUG_EAGER_TOSTRING 0 /* o.toString() trumps o.valueOf() */
#define JS_BUG_VOID_TOSTRING 0 /* void 0 + 0 == "undefined0" */
#define JS_BUG_EVAL_THIS_FUN 0 /* eval('this') in function f is f */
#define JS_BUG_EVAL_THIS_SCOPE 0 /* Math.eval('sin(x)') vs. local x */
#define JS_BUG_FALLIBLE_EQOPS 0 /* fallible/intransitive equality ops */
#define JS_BUG_FALLIBLE_TONUM 0 /* fallible ValueToNumber primitive */
#define JS_BUG_WITH_CLOSURE 1 /* with(o)function f(){} sets o.f */
#define JS_HAS_PROP_DELETE 1 /* delete o.p removes p from o */
#define JS_HAS_CALL_OBJECT 1 /* fun.caller is stack frame obj */
#define JS_HAS_LABEL_STATEMENT 1 /* has break/continue to label: */
#define JS_HAS_DO_WHILE_LOOP 1 /* has do {...} while (b) */
#define JS_HAS_SWITCH_STATEMENT 1 /* has switch (v) {case c: ...} */
#define JS_HAS_SOME_PERL_FUN 1 /* has array.join/reverse/sort */
#define JS_HAS_MORE_PERL_FUN 1 /* has array.push, str.substr, etc */
#define JS_HAS_STR_HTML_HELPERS 1 /* has str.anchor, str.bold, etc. */
#define JS_HAS_PERL_SUBSTR 1 /* has str.substr */
#define JS_HAS_VALUEOF_HINT 1 /* valueOf(hint) where hint is typeof */
#define JS_HAS_LEXICAL_CLOSURE 1 /* nested functions, lexically closed */
#define JS_HAS_APPLY_FUNCTION 1 /* has apply(fun, arg1, ... argN) */
#define JS_HAS_CALL_FUNCTION 1 /* has fun.call(obj, arg1, ... argN) */
#define JS_HAS_OBJ_PROTO_PROP 1 /* has o.__proto__ etc. */
#define JS_HAS_REGEXPS 1 /* has perl r.e.s via RegExp, /pat/ */
#define JS_HAS_SEQUENCE_OPS 1 /* has array.slice, string.concat */
#define JS_HAS_INITIALIZERS 1 /* has var o = {'foo': 42, 'bar':3} */
#define JS_HAS_OBJ_WATCHPOINT 1 /* has o.watch and o.unwatch */
#define JS_HAS_EXPORT_IMPORT 1 /* has export fun; import obj.fun */
#define JS_HAS_EVAL_THIS_SCOPE 1 /* Math.eval is same as with (Math) */
#define JS_HAS_TRIPLE_EQOPS 1 /* has === and !== identity eqops */
#define JS_HAS_SHARP_VARS 1 /* has #n=, #n# for object literals */
#define JS_HAS_REPLACE_LAMBDA 1 /* has string.replace(re, lambda) */
#define JS_HAS_SCRIPT_OBJECT 1 /* has (new Script("x++")).exec() */
#define JS_HAS_XDR 1 /* has XDR API and internal support */
#define JS_HAS_XDR_FREEZE_THAW 0 /* has XDR freeze/thaw script methods */
#define JS_HAS_EXCEPTIONS 0 /* has exception handling */
#define JS_HAS_UNDEFINED 1 /* has global "undefined" property */
#define JS_HAS_TOSOURCE 1 /* has Object/Array toSource method */
#define JS_HAS_IN_OPERATOR 0 /* has in operator ('p' in {p:1}) */
#define JS_HAS_INSTANCEOF 0 /* has {p:1} instanceof Object */
#define JS_HAS_ARGS_OBJECT 1 /* has minimal ECMA arguments object */
#define JS_HAS_DEBUGGER_KEYWORD 1 /* has hook for debugger keyword */
#define JS_HAS_ERROR_EXCEPTIONS 0 /* has error object hierarchy */
#define JS_HAS_CATCH_GUARD 0 /* has exception handling catch guard */
#define JS_HAS_NEW_OBJ_METHODS 0 /* has Object.prototype query methods */
#define JS_HAS_SPARSE_ARRAYS 0 /* array methods preserve empty elems */
#define JS_HAS_DFLT_MSG_STRINGS 1 /* provides English error messages */
#define JS_HAS_NUMBER_FORMATS 0 /* numbers have formatting methods */
#define JS_HAS_GETTER_SETTER 0 /* has JS2 getter/setter functions */
#define JS_HAS_UNEVAL 0 /* has uneval() top-level function */
#define JS_HAS_CONST 0 /* has JS2 const as alternative var */
#define JS_HAS_FUN_EXPR_STMT 0 /* has function expression statement */
#define JS_HAS_LVALUE_RETURN 0 /* has o.item(i) = j; for native item */
#define JS_HAS_NO_SUCH_METHOD 0 /* has o.__noSuchMethod__ handler */
#define JS_HAS_XML_SUPPORT 0 /* has ECMAScript for XML support */
#elif JS_VERSION == 140
#define JS_BUG_NULL_INDEX_PROPS 0 /* o[0] defaults to null, not void */
#define JS_BUG_EMPTY_INDEX_ZERO 0 /* o[""] is equivalent to o[0] */
#define JS_BUG_EAGER_TOSTRING 0 /* o.toString() trumps o.valueOf() */
#define JS_BUG_VOID_TOSTRING 0 /* void 0 + 0 == "undefined0" */
#define JS_BUG_EVAL_THIS_FUN 0 /* eval('this') in function f is f */
#define JS_BUG_EVAL_THIS_SCOPE 0 /* Math.eval('sin(x)') vs. local x */
#define JS_BUG_FALLIBLE_EQOPS 0 /* fallible/intransitive equality ops */
#define JS_BUG_FALLIBLE_TONUM 0 /* fallible ValueToNumber primitive */
#define JS_BUG_WITH_CLOSURE 1 /* with(o)function f(){} sets o.f */
#define JS_HAS_PROP_DELETE 1 /* delete o.p removes p from o */
#define JS_HAS_CALL_OBJECT 1 /* fun.caller is stack frame obj */
#define JS_HAS_LABEL_STATEMENT 1 /* has break/continue to label: */
#define JS_HAS_DO_WHILE_LOOP 1 /* has do {...} while (b) */
#define JS_HAS_SWITCH_STATEMENT 1 /* has switch (v) {case c: ...} */
#define JS_HAS_SOME_PERL_FUN 1 /* has array.join/reverse/sort */
#define JS_HAS_MORE_PERL_FUN 1 /* has array.push, str.substr, etc */
#define JS_HAS_STR_HTML_HELPERS 1 /* has str.anchor, str.bold, etc. */
#define JS_HAS_PERL_SUBSTR 1 /* has str.substr */
#define JS_HAS_VALUEOF_HINT 1 /* valueOf(hint) where hint is typeof */
#define JS_HAS_LEXICAL_CLOSURE 1 /* nested functions, lexically closed */
#define JS_HAS_APPLY_FUNCTION 1 /* has apply(fun, arg1, ... argN) */
#define JS_HAS_CALL_FUNCTION 1 /* has fun.call(obj, arg1, ... argN) */
#define JS_HAS_OBJ_PROTO_PROP 1 /* has o.__proto__ etc. */
#define JS_HAS_REGEXPS 1 /* has perl r.e.s via RegExp, /pat/ */
#define JS_HAS_SEQUENCE_OPS 1 /* has array.slice, string.concat */
#define JS_HAS_INITIALIZERS 1 /* has var o = {'foo': 42, 'bar':3} */
#define JS_HAS_OBJ_WATCHPOINT 1 /* has o.watch and o.unwatch */
#define JS_HAS_EXPORT_IMPORT 1 /* has export fun; import obj.fun */
#define JS_HAS_EVAL_THIS_SCOPE 1 /* Math.eval is same as with (Math) */
#define JS_HAS_TRIPLE_EQOPS 1 /* has === and !== identity eqops */
#define JS_HAS_SHARP_VARS 1 /* has #n=, #n# for object literals */
#define JS_HAS_REPLACE_LAMBDA 1 /* has string.replace(re, lambda) */
#define JS_HAS_SCRIPT_OBJECT 1 /* has (new Script("x++")).exec() */
#define JS_HAS_XDR 1 /* has XDR API and internal support */
#define JS_HAS_XDR_FREEZE_THAW 0 /* has XDR freeze/thaw script methods */
#define JS_HAS_EXCEPTIONS 1 /* has exception handling */
#define JS_HAS_UNDEFINED 1 /* has global "undefined" property */
#define JS_HAS_TOSOURCE 1 /* has Object/Array toSource method */
#define JS_HAS_IN_OPERATOR 1 /* has in operator ('p' in {p:1}) */
#define JS_HAS_INSTANCEOF 1 /* has {p:1} instanceof Object */
#define JS_HAS_ARGS_OBJECT 1 /* has minimal ECMA arguments object */
#define JS_HAS_DEBUGGER_KEYWORD 1 /* has hook for debugger keyword */
#define JS_HAS_ERROR_EXCEPTIONS 0 /* rt errors reflected as exceptions */
#define JS_HAS_CATCH_GUARD 0 /* has exception handling catch guard */
#define JS_HAS_NEW_OBJ_METHODS 0 /* has Object.prototype query methods */
#define JS_HAS_SPARSE_ARRAYS 0 /* array methods preserve empty elems */
#define JS_HAS_DFLT_MSG_STRINGS 1 /* provides English error messages */
#define JS_HAS_NUMBER_FORMATS 0 /* numbers have formatting methods */
#define JS_HAS_GETTER_SETTER 0 /* has JS2 getter/setter functions */
#define JS_HAS_UNEVAL 0 /* has uneval() top-level function */
#define JS_HAS_CONST 0 /* has JS2 const as alternative var */
#define JS_HAS_FUN_EXPR_STMT 0 /* has function expression statement */
#define JS_HAS_LVALUE_RETURN 0 /* has o.item(i) = j; for native item */
#define JS_HAS_NO_SUCH_METHOD 0 /* has o.__noSuchMethod__ handler */
#define JS_HAS_XML_SUPPORT 0 /* has ECMAScript for XML support */
#elif JS_VERSION == 150
#define JS_BUG_NULL_INDEX_PROPS 0 /* o[0] defaults to null, not void */
#define JS_BUG_EMPTY_INDEX_ZERO 0 /* o[""] is equivalent to o[0] */
#define JS_BUG_EAGER_TOSTRING 0 /* o.toString() trumps o.valueOf() */
#define JS_BUG_VOID_TOSTRING 0 /* void 0 + 0 == "undefined0" */
#define JS_BUG_EVAL_THIS_FUN 0 /* eval('this') in function f is f */
#define JS_BUG_EVAL_THIS_SCOPE 0 /* Math.eval('sin(x)') vs. local x */
#define JS_BUG_FALLIBLE_EQOPS 0 /* fallible/intransitive equality ops */
#define JS_BUG_FALLIBLE_TONUM 0 /* fallible ValueToNumber primitive */
#define JS_BUG_WITH_CLOSURE 0 /* with(o)function f(){} sets o.f */
#define JS_HAS_PROP_DELETE 1 /* delete o.p removes p from o */
#define JS_HAS_CALL_OBJECT 1 /* fun.caller is stack frame obj */
#define JS_HAS_LABEL_STATEMENT 1 /* has break/continue to label: */
#define JS_HAS_DO_WHILE_LOOP 1 /* has do {...} while (b) */
#define JS_HAS_SWITCH_STATEMENT 1 /* has switch (v) {case c: ...} */
#define JS_HAS_SOME_PERL_FUN 1 /* has array.join/reverse/sort */
#define JS_HAS_MORE_PERL_FUN 1 /* has array.push, str.substr, etc */
#define JS_HAS_STR_HTML_HELPERS 1 /* has str.anchor, str.bold, etc. */
#define JS_HAS_PERL_SUBSTR 1 /* has str.substr */
#define JS_HAS_VALUEOF_HINT 1 /* valueOf(hint) where hint is typeof */
#define JS_HAS_LEXICAL_CLOSURE 1 /* nested functions, lexically closed */
#define JS_HAS_APPLY_FUNCTION 1 /* has apply(fun, arg1, ... argN) */
#define JS_HAS_CALL_FUNCTION 1 /* has fun.call(obj, arg1, ... argN) */
#define JS_HAS_OBJ_PROTO_PROP 1 /* has o.__proto__ etc. */
#define JS_HAS_REGEXPS 1 /* has perl r.e.s via RegExp, /pat/ */
#define JS_HAS_SEQUENCE_OPS 1 /* has array.slice, string.concat */
#define JS_HAS_INITIALIZERS 1 /* has var o = {'foo': 42, 'bar':3} */
#define JS_HAS_OBJ_WATCHPOINT 1 /* has o.watch and o.unwatch */
#define JS_HAS_EXPORT_IMPORT 1 /* has export fun; import obj.fun */
#define JS_HAS_EVAL_THIS_SCOPE 1 /* Math.eval is same as with (Math) */
#define JS_HAS_TRIPLE_EQOPS 1 /* has === and !== identity eqops */
#define JS_HAS_SHARP_VARS 1 /* has #n=, #n# for object literals */
#define JS_HAS_REPLACE_LAMBDA 1 /* has string.replace(re, lambda) */
#define JS_HAS_SCRIPT_OBJECT 1 /* has (new Script("x++")).exec() */
#define JS_HAS_XDR 1 /* has XDR API and internal support */
#define JS_HAS_XDR_FREEZE_THAW 0 /* has XDR freeze/thaw script methods */
#define JS_HAS_EXCEPTIONS 1 /* has exception handling */
#define JS_HAS_UNDEFINED 1 /* has global "undefined" property */
#define JS_HAS_TOSOURCE 1 /* has Object/Array toSource method */
#define JS_HAS_IN_OPERATOR 1 /* has in operator ('p' in {p:1}) */
#define JS_HAS_INSTANCEOF 1 /* has {p:1} instanceof Object */
#define JS_HAS_ARGS_OBJECT 1 /* has minimal ECMA arguments object */
#define JS_HAS_DEBUGGER_KEYWORD 1 /* has hook for debugger keyword */
#define JS_HAS_ERROR_EXCEPTIONS 1 /* rt errors reflected as exceptions */
#define JS_HAS_CATCH_GUARD 1 /* has exception handling catch guard */
#define JS_HAS_NEW_OBJ_METHODS 1 /* has Object.prototype query methods */
#define JS_HAS_SPARSE_ARRAYS 0 /* array methods preserve empty elems */
#define JS_HAS_DFLT_MSG_STRINGS 1 /* provides English error messages */
#define JS_HAS_NUMBER_FORMATS 1 /* numbers have formatting methods */
#define JS_HAS_GETTER_SETTER 1 /* has JS2 getter/setter functions */
#define JS_HAS_UNEVAL 1 /* has uneval() top-level function */
#define JS_HAS_CONST 1 /* has JS2 const as alternative var */
#define JS_HAS_FUN_EXPR_STMT 1 /* has function expression statement */
#define JS_HAS_LVALUE_RETURN 1 /* has o.item(i) = j; for native item */
#define JS_HAS_NO_SUCH_METHOD 1 /* has o.__noSuchMethod__ handler */
#define JS_HAS_XML_SUPPORT 1 /* has ECMAScript for XML support */
#else
#error "unknown JS_VERSION"
#endif

View File

@@ -1,181 +0,0 @@
# -*- Mode: makefile -*-
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Communicator client code, released
# March 31, 1998.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998-1999
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
ifndef OBJDIR
ifdef OBJDIR_NAME
OBJDIR = $(OBJDIR_NAME)
endif
endif
NSPR_VERSION = v4.0
NSPR_LIBSUFFIX = 4
NSPR_LOCAL = $(MOZ_DEPTH)/dist/$(OBJDIR)/nspr
NSPR_DIST = $(MOZ_DEPTH)/dist/$(OBJDIR)
NSPR_OBJDIR = $(OBJDIR)
ifeq ($(OS_ARCH), SunOS)
NSPR_OBJDIR := $(subst _sparc,,$(NSPR_OBJDIR))
endif
ifeq ($(OS_ARCH), Linux)
LINUX_REL := $(shell uname -r)
ifneq (,$(findstring 2.0,$(LINUX_REL)))
NSPR_OBJDIR := $(subst _All,2.0_x86_glibc_PTH,$(NSPR_OBJDIR))
else
NSPR_OBJDIR := $(subst _All,2.2_x86_glibc_PTH,$(NSPR_OBJDIR))
endif
endif
ifeq ($(OS_ARCH), AIX)
NSPR_OBJDIR := $(subst 4.1,4.2,$(NSPR_OBJDIR))
endif
ifeq ($(OS_CONFIG), IRIX6.2)
NSPR_OBJDIR := $(subst 6.2,6.2_n32_PTH,$(NSPR_OBJDIR))
endif
ifeq ($(OS_CONFIG), IRIX6.5)
NSPR_OBJDIR := $(subst 6.5,6.5_n32_PTH,$(NSPR_OBJDIR))
endif
ifeq ($(OS_ARCH), WINNT)
ifeq ($(OBJDIR), WIN32_D.OBJ)
NSPR_OBJDIR = WINNT4.0_DBG.OBJ
endif
ifeq ($(OBJDIR), WIN32_O.OBJ)
NSPR_OBJDIR = WINNT4.0_OPT.OBJ
endif
endif
NSPR_SHARED = /share/builds/components/nspr20/$(NSPR_VERSION)/$(NSPR_OBJDIR)
ifeq ($(OS_ARCH), WINNT)
NSPR_SHARED = nspr20/$(NSPR_VERSION)/$(NSPR_OBJDIR)
endif
NSPR_VERSIONFILE = $(NSPR_LOCAL)/Version
NSPR_CURVERSION := $(shell cat $(NSPR_VERSIONFILE))
get_nspr:
@echo "Grabbing NSPR component..."
ifeq ($(NSPR_VERSION), $(NSPR_CURVERSION))
@echo "No need, NSPR is up to date in this tree (ver=$(NSPR_VERSION))."
else
mkdir -p $(NSPR_LOCAL)
mkdir -p $(NSPR_DIST)
ifneq ($(OS_ARCH), WINNT)
cp $(NSPR_SHARED)/*.jar $(NSPR_LOCAL)
else
sh $(MOZ_DEPTH)/../reltools/compftp.sh $(NSPR_SHARED) $(NSPR_LOCAL) *.jar
endif
unzip -o $(NSPR_LOCAL)/mdbinary.jar -d $(NSPR_DIST)
mkdir -p $(NSPR_DIST)/include
unzip -o $(NSPR_LOCAL)/mdheader.jar -d $(NSPR_DIST)/include
rm -rf $(NSPR_DIST)/META-INF
rm -rf $(NSPR_DIST)/include/META-INF
echo $(NSPR_VERSION) > $(NSPR_VERSIONFILE)
endif
SHIP_DIST = $(MOZ_DEPTH)/dist/$(OBJDIR)
SHIP_DIR = $(SHIP_DIST)/SHIP
SHIP_LIBS = libjs.$(SO_SUFFIX) libjs.a
ifdef JS_LIVECONNECT
SHIP_LIBS += libjsj.$(SO_SUFFIX) libjsj.a
endif
ifeq ($(OS_ARCH), WINNT)
SHIP_LIBS = js32.dll js32.lib
ifdef JS_LIVECONNECT
SHIP_LIBS += jsj.dll jsj.lib
endif
endif
SHIP_LIBS += $(LCJAR)
SHIP_LIBS := $(addprefix $(SHIP_DIST)/lib/, $(SHIP_LIBS))
SHIP_INCS = js*.h prmjtime.h resource.h *.msg *.tbl
ifdef JS_LIVECONNECT
SHIP_INCS += netscape*.h nsC*.h nsI*.h
endif
SHIP_INCS := $(addprefix $(SHIP_DIST)/include/, $(SHIP_INCS))
SHIP_BINS = js
ifdef JS_LIVECONNECT
SHIP_BINS += lcshell
endif
ifeq ($(OS_ARCH), WINNT)
SHIP_BINS := $(addsuffix .exe, $(SHIP_BINS))
endif
SHIP_BINS := $(addprefix $(SHIP_DIST)/bin/, $(SHIP_BINS))
ifdef BUILD_OPT
JSREFJAR = jsref_opt.jar
else
ifdef BUILD_IDG
JSREFJAR = jsref_idg.jar
else
JSREFJAR = jsref_dbg.jar
endif
endif
ship:
mkdir -p $(SHIP_DIR)/$(LIBDIR)
mkdir -p $(SHIP_DIR)/include
mkdir -p $(SHIP_DIR)/bin
cp $(SHIP_LIBS) $(SHIP_DIR)/$(LIBDIR)
cp $(SHIP_INCS) $(SHIP_DIR)/include
cp $(SHIP_BINS) $(SHIP_DIR)/bin
cd $(SHIP_DIR); \
zip -r $(JSREFJAR) bin lib include
ifdef BUILD_SHIP
cp $(SHIP_DIR)/$(JSREFJAR) $(BUILD_SHIP)
endif
CWD = $(shell pwd)
shipSource: $(SHIP_DIR)/jsref_src.lst .FORCE
mkdir -p $(SHIP_DIR)
cd $(MOZ_DEPTH)/.. ; \
zip $(CWD)/$(SHIP_DIR)/jsref_src.jar -@ < $(CWD)/$(SHIP_DIR)/jsref_src.lst
ifdef BUILD_SHIP
cp $(SHIP_DIR)/jsref_src.jar $(BUILD_SHIP)
endif
JSREFSRCDIRS := $(shell cat $(DEPTH)/SpiderMonkey.rsp)
$(SHIP_DIR)/jsref_src.lst: .FORCE
mkdir -p $(SHIP_DIR)
rm -f $@
touch $@
for d in $(JSREFSRCDIRS); do \
cd $(MOZ_DEPTH)/..; \
ls -1 -d $$d | grep -v CVS | grep -v \.OBJ >> $(CWD)/$@; \
cd $(CWD); \
done
.FORCE:

View File

@@ -1,377 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* Generate CPU-specific bit-size and similar #defines.
*/
#include <stdio.h>
#include <stdlib.h>
#ifdef CROSS_COMPILE
#include <prtypes.h>
#define INT64 PRInt64
#else
#ifdef __MWERKS__
#define XP_MAC 1
#endif
/************************************************************************/
/* Generate cpucfg.h */
#ifdef XP_MAC
#include <Types.h>
#define INT64 UnsignedWide
#else
#if defined(XP_WIN) || defined(XP_OS2)
#ifdef WIN32
#if defined(__GNUC__)
#define INT64 long long
#else
#define INT64 _int64
#endif /* __GNUC__ */
#else
#define INT64 long
#endif
#else
#if defined(HPUX) || defined(__QNX__) || defined(_SCO_DS) || defined(UNIXWARE)
#define INT64 long
#else
#define INT64 long long
#endif
#endif
#endif
#endif /* CROSS_COMPILE */
typedef void *prword;
struct align_short {
char c;
short a;
};
struct align_int {
char c;
int a;
};
struct align_long {
char c;
long a;
};
struct align_int64 {
char c;
INT64 a;
};
struct align_fakelonglong {
char c;
struct {
long hi, lo;
} a;
};
struct align_float {
char c;
float a;
};
struct align_double {
char c;
double a;
};
struct align_pointer {
char c;
void *a;
};
struct align_prword {
char c;
prword a;
};
#define ALIGN_OF(type) \
(((char*)&(((struct align_##type *)0)->a)) - ((char*)0))
unsigned int bpb;
static int Log2(unsigned int n)
{
int log2 = 0;
if (n & (n-1))
log2++;
if (n >> 16)
log2 += 16, n >>= 16;
if (n >> 8)
log2 += 8, n >>= 8;
if (n >> 4)
log2 += 4, n >>= 4;
if (n >> 2)
log2 += 2, n >>= 2;
if (n >> 1)
log2++;
return log2;
}
/*
* Conceivably this could actually be used, but there is lots of code out
* there with ands and shifts in it that assumes a byte is exactly 8 bits,
* so forget about porting THIS code to all those non 8 bit byte machines.
*/
static void BitsPerByte(void)
{
bpb = 8;
}
static int StackGrowthDirection(int *dummy1addr)
{
int dummy2;
return (&dummy2 < dummy1addr) ? -1 : 1;
}
int main(int argc, char **argv)
{
int sizeof_char, sizeof_short, sizeof_int, sizeof_int64, sizeof_long,
sizeof_float, sizeof_double, sizeof_word, sizeof_dword;
int bits_per_int64_log2, align_of_short, align_of_int, align_of_long,
align_of_int64, align_of_float, align_of_double, align_of_pointer,
align_of_word;
int dummy1;
BitsPerByte();
printf("#ifndef js_cpucfg___\n");
printf("#define js_cpucfg___\n\n");
printf("/* AUTOMATICALLY GENERATED - DO NOT EDIT */\n\n");
#ifdef CROSS_COMPILE
#if defined(IS_LITTLE_ENDIAN)
printf("#define IS_LITTLE_ENDIAN 1\n");
printf("#undef IS_BIG_ENDIAN\n\n");
#elif defined(IS_BIG_ENDIAN)
printf("#undef IS_LITTLE_ENDIAN\n");
printf("#define IS_BIG_ENDIAN 1\n\n");
#else
#error "Endianess not defined."
#endif
sizeof_char = PR_BYTES_PER_BYTE;
sizeof_short = PR_BYTES_PER_SHORT;
sizeof_int = PR_BYTES_PER_INT;
sizeof_int64 = PR_BYTES_PER_INT64;
sizeof_long = PR_BYTES_PER_LONG;
sizeof_float = PR_BYTES_PER_FLOAT;
sizeof_double = PR_BYTES_PER_DOUBLE;
sizeof_word = PR_BYTES_PER_WORD;
sizeof_dword = PR_BYTES_PER_DWORD;
bits_per_int64_log2 = PR_BITS_PER_INT64_LOG2;
align_of_short = PR_ALIGN_OF_SHORT;
align_of_int = PR_ALIGN_OF_INT;
align_of_long = PR_ALIGN_OF_LONG;
align_of_int64 = PR_ALIGN_OF_INT64;
align_of_float = PR_ALIGN_OF_FLOAT;
align_of_double = PR_ALIGN_OF_DOUBLE;
align_of_pointer = PR_ALIGN_OF_POINTER;
align_of_word = PR_ALIGN_OF_WORD;
#else /* !CROSS_COMPILE */
/*
* We don't handle PDP-endian or similar orders: if a short is big-endian,
* so must int and long be big-endian for us to generate the IS_BIG_ENDIAN
* #define and the IS_LITTLE_ENDIAN #undef.
*/
{
int big_endian = 0, little_endian = 0, ntests = 0;
if (sizeof(short) == 2) {
/* force |volatile| here to get rid of any compiler optimisations
* (var in register etc.) which may be appiled to |auto| vars -
* even those in |union|s...
* (|static| is used to get the same functionality for compilers
* which do not honor |volatile|...).
*/
volatile static union {
short i;
char c[2];
} u;
u.i = 0x0102;
big_endian += (u.c[0] == 0x01 && u.c[1] == 0x02);
little_endian += (u.c[0] == 0x02 && u.c[1] == 0x01);
ntests++;
}
if (sizeof(int) == 4) {
/* force |volatile| here ... */
volatile static union {
int i;
char c[4];
} u;
u.i = 0x01020304;
big_endian += (u.c[0] == 0x01 && u.c[1] == 0x02 &&
u.c[2] == 0x03 && u.c[3] == 0x04);
little_endian += (u.c[0] == 0x04 && u.c[1] == 0x03 &&
u.c[2] == 0x02 && u.c[3] == 0x01);
ntests++;
}
if (sizeof(long) == 8) {
/* force |volatile| here ... */
volatile static union {
long i;
char c[8];
} u;
/*
* Write this as portably as possible: avoid 0x0102030405060708L
* and <<= 32.
*/
u.i = 0x01020304;
u.i <<= 16, u.i <<= 16;
u.i |= 0x05060708;
big_endian += (u.c[0] == 0x01 && u.c[1] == 0x02 &&
u.c[2] == 0x03 && u.c[3] == 0x04 &&
u.c[4] == 0x05 && u.c[5] == 0x06 &&
u.c[6] == 0x07 && u.c[7] == 0x08);
little_endian += (u.c[0] == 0x08 && u.c[1] == 0x07 &&
u.c[2] == 0x06 && u.c[3] == 0x05 &&
u.c[4] == 0x04 && u.c[5] == 0x03 &&
u.c[6] == 0x02 && u.c[7] == 0x01);
ntests++;
}
if (big_endian && big_endian == ntests) {
printf("#undef IS_LITTLE_ENDIAN\n");
printf("#define IS_BIG_ENDIAN 1\n\n");
} else if (little_endian && little_endian == ntests) {
printf("#define IS_LITTLE_ENDIAN 1\n");
printf("#undef IS_BIG_ENDIAN\n\n");
} else {
fprintf(stderr, "%s: unknown byte order"
"(big_endian=%d, little_endian=%d, ntests=%d)!\n",
argv[0], big_endian, little_endian, ntests);
return EXIT_FAILURE;
}
}
sizeof_char = sizeof(char);
sizeof_short = sizeof(short);
sizeof_int = sizeof(int);
sizeof_int64 = 8;
sizeof_long = sizeof(long);
sizeof_float = sizeof(float);
sizeof_double = sizeof(double);
sizeof_word = sizeof(prword);
sizeof_dword = 8;
bits_per_int64_log2 = 6;
align_of_short = ALIGN_OF(short);
align_of_int = ALIGN_OF(int);
align_of_long = ALIGN_OF(long);
if (sizeof(INT64) < 8) {
/* this machine doesn't actually support int64's */
align_of_int64 = ALIGN_OF(fakelonglong);
} else {
align_of_int64 = ALIGN_OF(int64);
}
align_of_float = ALIGN_OF(float);
align_of_double = ALIGN_OF(double);
align_of_pointer = ALIGN_OF(pointer);
align_of_word = ALIGN_OF(prword);
#endif /* CROSS_COMPILE */
printf("#define JS_BYTES_PER_BYTE %dL\n", sizeof_char);
printf("#define JS_BYTES_PER_SHORT %dL\n", sizeof_short);
printf("#define JS_BYTES_PER_INT %dL\n", sizeof_int);
printf("#define JS_BYTES_PER_INT64 %dL\n", sizeof_int64);
printf("#define JS_BYTES_PER_LONG %dL\n", sizeof_long);
printf("#define JS_BYTES_PER_FLOAT %dL\n", sizeof_float);
printf("#define JS_BYTES_PER_DOUBLE %dL\n", sizeof_double);
printf("#define JS_BYTES_PER_WORD %dL\n", sizeof_word);
printf("#define JS_BYTES_PER_DWORD %dL\n", sizeof_dword);
printf("\n");
printf("#define JS_BITS_PER_BYTE %dL\n", bpb);
printf("#define JS_BITS_PER_SHORT %dL\n", bpb * sizeof_short);
printf("#define JS_BITS_PER_INT %dL\n", bpb * sizeof_int);
printf("#define JS_BITS_PER_INT64 %dL\n", bpb * sizeof_int64);
printf("#define JS_BITS_PER_LONG %dL\n", bpb * sizeof_long);
printf("#define JS_BITS_PER_FLOAT %dL\n", bpb * sizeof_float);
printf("#define JS_BITS_PER_DOUBLE %dL\n", bpb * sizeof_double);
printf("#define JS_BITS_PER_WORD %dL\n", bpb * sizeof_word);
printf("\n");
printf("#define JS_BITS_PER_BYTE_LOG2 %dL\n", Log2(bpb));
printf("#define JS_BITS_PER_SHORT_LOG2 %dL\n", Log2(bpb * sizeof_short));
printf("#define JS_BITS_PER_INT_LOG2 %dL\n", Log2(bpb * sizeof_int));
printf("#define JS_BITS_PER_INT64_LOG2 %dL\n", bits_per_int64_log2);
printf("#define JS_BITS_PER_LONG_LOG2 %dL\n", Log2(bpb * sizeof_long));
printf("#define JS_BITS_PER_FLOAT_LOG2 %dL\n", Log2(bpb * sizeof_float));
printf("#define JS_BITS_PER_DOUBLE_LOG2 %dL\n", Log2(bpb * sizeof_double));
printf("#define JS_BITS_PER_WORD_LOG2 %dL\n", Log2(bpb * sizeof_word));
printf("\n");
printf("#define JS_ALIGN_OF_SHORT %dL\n", align_of_short);
printf("#define JS_ALIGN_OF_INT %dL\n", align_of_int);
printf("#define JS_ALIGN_OF_LONG %dL\n", align_of_long);
printf("#define JS_ALIGN_OF_INT64 %dL\n", align_of_int64);
printf("#define JS_ALIGN_OF_FLOAT %dL\n", align_of_float);
printf("#define JS_ALIGN_OF_DOUBLE %dL\n", align_of_double);
printf("#define JS_ALIGN_OF_POINTER %dL\n", align_of_pointer);
printf("#define JS_ALIGN_OF_WORD %dL\n", align_of_word);
printf("\n");
printf("#define JS_BYTES_PER_WORD_LOG2 %dL\n", Log2(sizeof_word));
printf("#define JS_BYTES_PER_DWORD_LOG2 %dL\n", Log2(sizeof_dword));
printf("#define JS_WORDS_PER_DWORD_LOG2 %dL\n", Log2(sizeof_dword/sizeof_word));
printf("\n");
printf("#define JS_STACK_GROWTH_DIRECTION (%d)\n", StackGrowthDirection(&dummy1));
printf("\n");
printf("#endif /* js_cpucfg___ */\n");
return EXIT_SUCCESS;
}

View File

@@ -1,204 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef js_cpucfg___
#define js_cpucfg___
#include "jsosdep.h"
#ifdef XP_MAC
#undef IS_LITTLE_ENDIAN
#define IS_BIG_ENDIAN 1
#define JS_BYTES_PER_BYTE 1L
#define JS_BYTES_PER_SHORT 2L
#define JS_BYTES_PER_INT 4L
#define JS_BYTES_PER_INT64 8L
#define JS_BYTES_PER_LONG 4L
#define JS_BYTES_PER_FLOAT 4L
#define JS_BYTES_PER_DOUBLE 8L
#define JS_BYTES_PER_WORD 4L
#define JS_BYTES_PER_DWORD 8L
#define JS_BITS_PER_BYTE 8L
#define JS_BITS_PER_SHORT 16L
#define JS_BITS_PER_INT 32L
#define JS_BITS_PER_INT64 64L
#define JS_BITS_PER_LONG 32L
#define JS_BITS_PER_FLOAT 32L
#define JS_BITS_PER_DOUBLE 64L
#define JS_BITS_PER_WORD 32L
#define JS_BITS_PER_BYTE_LOG2 3L
#define JS_BITS_PER_SHORT_LOG2 4L
#define JS_BITS_PER_INT_LOG2 5L
#define JS_BITS_PER_INT64_LOG2 6L
#define JS_BITS_PER_LONG_LOG2 5L
#define JS_BITS_PER_FLOAT_LOG2 5L
#define JS_BITS_PER_DOUBLE_LOG2 6L
#define JS_BITS_PER_WORD_LOG2 5L
#define JS_ALIGN_OF_SHORT 2L
#define JS_ALIGN_OF_INT 4L
#define JS_ALIGN_OF_LONG 4L
#define JS_ALIGN_OF_INT64 2L
#define JS_ALIGN_OF_FLOAT 4L
#define JS_ALIGN_OF_DOUBLE 4L
#define JS_ALIGN_OF_POINTER 4L
#define JS_ALIGN_OF_WORD 4L
#define JS_BYTES_PER_WORD_LOG2 2L
#define JS_BYTES_PER_DWORD_LOG2 3L
#define PR_WORDS_PER_DWORD_LOG2 1L
#elif defined(XP_WIN) || defined(XP_OS2)
#ifdef __WATCOMC__
#define HAVE_VA_LIST_AS_ARRAY
#endif
#if defined( _WIN32) || defined(XP_OS2)
#define IS_LITTLE_ENDIAN 1
#undef IS_BIG_ENDIAN
#define JS_BYTES_PER_BYTE 1L
#define JS_BYTES_PER_SHORT 2L
#define JS_BYTES_PER_INT 4L
#define JS_BYTES_PER_INT64 8L
#define JS_BYTES_PER_LONG 4L
#define JS_BYTES_PER_FLOAT 4L
#define JS_BYTES_PER_DOUBLE 8L
#define JS_BYTES_PER_WORD 4L
#define JS_BYTES_PER_DWORD 8L
#define JS_BITS_PER_BYTE 8L
#define JS_BITS_PER_SHORT 16L
#define JS_BITS_PER_INT 32L
#define JS_BITS_PER_INT64 64L
#define JS_BITS_PER_LONG 32L
#define JS_BITS_PER_FLOAT 32L
#define JS_BITS_PER_DOUBLE 64L
#define JS_BITS_PER_WORD 32L
#define JS_BITS_PER_BYTE_LOG2 3L
#define JS_BITS_PER_SHORT_LOG2 4L
#define JS_BITS_PER_INT_LOG2 5L
#define JS_BITS_PER_INT64_LOG2 6L
#define JS_BITS_PER_LONG_LOG2 5L
#define JS_BITS_PER_FLOAT_LOG2 5L
#define JS_BITS_PER_DOUBLE_LOG2 6L
#define JS_BITS_PER_WORD_LOG2 5L
#define JS_ALIGN_OF_SHORT 2L
#define JS_ALIGN_OF_INT 4L
#define JS_ALIGN_OF_LONG 4L
#define JS_ALIGN_OF_INT64 8L
#define JS_ALIGN_OF_FLOAT 4L
#define JS_ALIGN_OF_DOUBLE 4L
#define JS_ALIGN_OF_POINTER 4L
#define JS_ALIGN_OF_WORD 4L
#define JS_BYTES_PER_WORD_LOG2 2L
#define JS_BYTES_PER_DWORD_LOG2 3L
#define PR_WORDS_PER_DWORD_LOG2 1L
#endif /* _WIN32 || XP_OS2 */
#if defined(_WINDOWS) && !defined(_WIN32) /* WIN16 */
#define IS_LITTLE_ENDIAN 1
#undef IS_BIG_ENDIAN
#define JS_BYTES_PER_BYTE 1L
#define JS_BYTES_PER_SHORT 2L
#define JS_BYTES_PER_INT 2L
#define JS_BYTES_PER_INT64 8L
#define JS_BYTES_PER_LONG 4L
#define JS_BYTES_PER_FLOAT 4L
#define JS_BYTES_PER_DOUBLE 8L
#define JS_BYTES_PER_WORD 4L
#define JS_BYTES_PER_DWORD 8L
#define JS_BITS_PER_BYTE 8L
#define JS_BITS_PER_SHORT 16L
#define JS_BITS_PER_INT 16L
#define JS_BITS_PER_INT64 64L
#define JS_BITS_PER_LONG 32L
#define JS_BITS_PER_FLOAT 32L
#define JS_BITS_PER_DOUBLE 64L
#define JS_BITS_PER_WORD 32L
#define JS_BITS_PER_BYTE_LOG2 3L
#define JS_BITS_PER_SHORT_LOG2 4L
#define JS_BITS_PER_INT_LOG2 4L
#define JS_BITS_PER_INT64_LOG2 6L
#define JS_BITS_PER_LONG_LOG2 5L
#define JS_BITS_PER_FLOAT_LOG2 5L
#define JS_BITS_PER_DOUBLE_LOG2 6L
#define JS_BITS_PER_WORD_LOG2 5L
#define JS_ALIGN_OF_SHORT 2L
#define JS_ALIGN_OF_INT 2L
#define JS_ALIGN_OF_LONG 2L
#define JS_ALIGN_OF_INT64 2L
#define JS_ALIGN_OF_FLOAT 2L
#define JS_ALIGN_OF_DOUBLE 2L
#define JS_ALIGN_OF_POINTER 2L
#define JS_ALIGN_OF_WORD 2L
#define JS_BYTES_PER_WORD_LOG2 2L
#define JS_BYTES_PER_DWORD_LOG2 3L
#define PR_WORDS_PER_DWORD_LOG2 1L
#endif /* defined(_WINDOWS) && !defined(_WIN32) */
#elif defined(XP_UNIX) || defined(XP_BEOS)
#error "This file is supposed to be auto-generated on UNIX platforms, but the"
#error "static version for Mac and Windows platforms is being used."
#error "Something's probably wrong with paths/headers/dependencies/Makefiles."
#else
#error "Must define one of XP_BEOS, XP_MAC, XP_OS2, XP_WIN, or XP_UNIX"
#endif
#ifndef JS_STACK_GROWTH_DIRECTION
#define JS_STACK_GROWTH_DIRECTION (-1)
#endif
#endif /* js_cpucfg___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,118 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* JS Date class interface.
*/
#ifndef jsdate_h___
#define jsdate_h___
JS_BEGIN_EXTERN_C
extern JSObject *
js_InitDateClass(JSContext *cx, JSObject *obj);
/*
* These functions provide a C interface to the date/time object
*/
/*
* Construct a new Date Object from a time value given in milliseconds UTC
* since the epoch.
*/
extern JS_FRIEND_API(JSObject*)
js_NewDateObjectMsec(JSContext* cx, jsdouble msec_time);
/*
* Construct a new Date Object from an exploded local time value.
*/
extern JS_FRIEND_API(JSObject*)
js_NewDateObject(JSContext* cx, int year, int mon, int mday,
int hour, int min, int sec);
/*
* Detect whether the internal date value is NaN. (Because failure is
* out-of-band for js_DateGet*)
*/
extern JS_FRIEND_API(JSBool)
js_DateIsValid(JSContext *cx, JSObject* obj);
extern JS_FRIEND_API(int)
js_DateGetYear(JSContext *cx, JSObject* obj);
extern JS_FRIEND_API(int)
js_DateGetMonth(JSContext *cx, JSObject* obj);
extern JS_FRIEND_API(int)
js_DateGetDate(JSContext *cx, JSObject* obj);
extern JS_FRIEND_API(int)
js_DateGetHours(JSContext *cx, JSObject* obj);
extern JS_FRIEND_API(int)
js_DateGetMinutes(JSContext *cx, JSObject* obj);
extern JS_FRIEND_API(int)
js_DateGetSeconds(JSContext *cx, JSObject* obj);
extern JS_FRIEND_API(void)
js_DateSetYear(JSContext *cx, JSObject *obj, int year);
extern JS_FRIEND_API(void)
js_DateSetMonth(JSContext *cx, JSObject *obj, int year);
extern JS_FRIEND_API(void)
js_DateSetDate(JSContext *cx, JSObject *obj, int date);
extern JS_FRIEND_API(void)
js_DateSetHours(JSContext *cx, JSObject *obj, int hours);
extern JS_FRIEND_API(void)
js_DateSetMinutes(JSContext *cx, JSObject *obj, int minutes);
extern JS_FRIEND_API(void)
js_DateSetSeconds(JSContext *cx, JSObject *obj, int seconds);
extern JS_FRIEND_API(jsdouble)
js_DateGetMsecSinceEpoch(JSContext *cx, JSObject *obj);
JS_END_EXTERN_C
#endif /* jsdate_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,345 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsdbgapi_h___
#define jsdbgapi_h___
/*
* JS debugger API.
*/
#include "jsapi.h"
#include "jsopcode.h"
#include "jsprvtd.h"
JS_BEGIN_EXTERN_C
extern void
js_PatchOpcode(JSContext *cx, JSScript *script, jsbytecode *pc, JSOp op);
extern JS_PUBLIC_API(JSBool)
JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
JSTrapHandler handler, void *closure);
extern JS_PUBLIC_API(JSOp)
JS_GetTrapOpcode(JSContext *cx, JSScript *script, jsbytecode *pc);
extern JS_PUBLIC_API(void)
JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
JSTrapHandler *handlerp, void **closurep);
extern JS_PUBLIC_API(void)
JS_ClearScriptTraps(JSContext *cx, JSScript *script);
extern JS_PUBLIC_API(void)
JS_ClearAllTraps(JSContext *cx);
extern JS_PUBLIC_API(JSTrapStatus)
JS_HandleTrap(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval);
extern JS_PUBLIC_API(JSBool)
JS_SetInterrupt(JSRuntime *rt, JSTrapHandler handler, void *closure);
extern JS_PUBLIC_API(JSBool)
JS_ClearInterrupt(JSRuntime *rt, JSTrapHandler *handlerp, void **closurep);
/************************************************************************/
extern JS_PUBLIC_API(JSBool)
JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsval id,
JSWatchPointHandler handler, void *closure);
extern JS_PUBLIC_API(JSBool)
JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsval id,
JSWatchPointHandler *handlerp, void **closurep);
extern JS_PUBLIC_API(JSBool)
JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj);
extern JS_PUBLIC_API(JSBool)
JS_ClearAllWatchPoints(JSContext *cx);
#ifdef JS_HAS_OBJ_WATCHPOINT
/*
* Hide these non-API function prototypes by testing whether the internal
* header file "jsconfig.h" has been included.
*/
extern void
js_MarkWatchPoints(JSRuntime *rt);
extern JSScopeProperty *
js_FindWatchPoint(JSRuntime *rt, JSScope *scope, jsid id);
extern JSPropertyOp
js_GetWatchedSetter(JSRuntime *rt, JSScope *scope,
const JSScopeProperty *sprop);
extern JSBool JS_DLL_CALLBACK
js_watch_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
extern JSBool JS_DLL_CALLBACK
js_watch_set_wrapper(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval);
extern JSPropertyOp
js_WrapWatchedSetter(JSContext *cx, jsid id, uintN attrs, JSPropertyOp setter);
#endif /* JS_HAS_OBJ_WATCHPOINT */
/************************************************************************/
extern JS_PUBLIC_API(uintN)
JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc);
extern JS_PUBLIC_API(jsbytecode *)
JS_LineNumberToPC(JSContext *cx, JSScript *script, uintN lineno);
extern JS_PUBLIC_API(JSScript *)
JS_GetFunctionScript(JSContext *cx, JSFunction *fun);
extern JS_PUBLIC_API(JSPrincipals *)
JS_GetScriptPrincipals(JSContext *cx, JSScript *script);
/*
* Stack Frame Iterator
*
* Used to iterate through the JS stack frames to extract
* information from the frames.
*/
extern JS_PUBLIC_API(JSStackFrame *)
JS_FrameIterator(JSContext *cx, JSStackFrame **iteratorp);
extern JS_PUBLIC_API(JSScript *)
JS_GetFrameScript(JSContext *cx, JSStackFrame *fp);
extern JS_PUBLIC_API(jsbytecode *)
JS_GetFramePC(JSContext *cx, JSStackFrame *fp);
/*
* Get the closest scripted frame below fp. If fp is null, start from cx->fp.
*/
extern JS_PUBLIC_API(JSStackFrame *)
JS_GetScriptedCaller(JSContext *cx, JSStackFrame *fp);
/*
* Return a weak reference to fp's principals. A null return does not denote
* an error, it means there are no principals.
*/
extern JS_PUBLIC_API(JSPrincipals *)
JS_StackFramePrincipals(JSContext *cx, JSStackFrame *fp);
/*
* Like JS_StackFramePrincipals(cx, caller), but if cx->findObjectPrincipals
* is non-null, return the object principals for fp's callee function object
* (fp->argv[-2]), which is eval, Function, or a similar eval-like method.
* The caller parameter should be the result of JS_GetScriptedCaller(cx, fp).
*
* All eval-like methods must use JS_EvalFramePrincipals to acquire a weak
* reference to the correct principals for the eval call to be secure, given
* an embedding that calls JS_SetObjectPrincipalsFinder (see jsapi.h).
*/
extern JS_PUBLIC_API(JSPrincipals *)
JS_EvalFramePrincipals(JSContext *cx, JSStackFrame *fp, JSStackFrame *caller);
extern JS_PUBLIC_API(void *)
JS_GetFrameAnnotation(JSContext *cx, JSStackFrame *fp);
extern JS_PUBLIC_API(void)
JS_SetFrameAnnotation(JSContext *cx, JSStackFrame *fp, void *annotation);
extern JS_PUBLIC_API(void *)
JS_GetFramePrincipalArray(JSContext *cx, JSStackFrame *fp);
extern JS_PUBLIC_API(JSBool)
JS_IsNativeFrame(JSContext *cx, JSStackFrame *fp);
/* this is deprecated, use JS_GetFrameScopeChain instead */
extern JS_PUBLIC_API(JSObject *)
JS_GetFrameObject(JSContext *cx, JSStackFrame *fp);
extern JS_PUBLIC_API(JSObject *)
JS_GetFrameScopeChain(JSContext *cx, JSStackFrame *fp);
extern JS_PUBLIC_API(JSObject *)
JS_GetFrameCallObject(JSContext *cx, JSStackFrame *fp);
extern JS_PUBLIC_API(JSObject *)
JS_GetFrameThis(JSContext *cx, JSStackFrame *fp);
extern JS_PUBLIC_API(JSFunction *)
JS_GetFrameFunction(JSContext *cx, JSStackFrame *fp);
extern JS_PUBLIC_API(JSObject *)
JS_GetFrameFunctionObject(JSContext *cx, JSStackFrame *fp);
/* XXXrginda Initially published with typo */
#define JS_IsContructorFrame JS_IsConstructorFrame
extern JS_PUBLIC_API(JSBool)
JS_IsConstructorFrame(JSContext *cx, JSStackFrame *fp);
extern JS_PUBLIC_API(JSBool)
JS_IsDebuggerFrame(JSContext *cx, JSStackFrame *fp);
extern JS_PUBLIC_API(jsval)
JS_GetFrameReturnValue(JSContext *cx, JSStackFrame *fp);
extern JS_PUBLIC_API(void)
JS_SetFrameReturnValue(JSContext *cx, JSStackFrame *fp, jsval rval);
/************************************************************************/
extern JS_PUBLIC_API(const char *)
JS_GetScriptFilename(JSContext *cx, JSScript *script);
extern JS_PUBLIC_API(uintN)
JS_GetScriptBaseLineNumber(JSContext *cx, JSScript *script);
extern JS_PUBLIC_API(uintN)
JS_GetScriptLineExtent(JSContext *cx, JSScript *script);
extern JS_PUBLIC_API(JSVersion)
JS_GetScriptVersion(JSContext *cx, JSScript *script);
/************************************************************************/
/*
* Hook setters for script creation and destruction, see jsprvtd.h for the
* typedefs. These macros provide binary compatibility and newer, shorter
* synonyms.
*/
#define JS_SetNewScriptHook JS_SetNewScriptHookProc
#define JS_SetDestroyScriptHook JS_SetDestroyScriptHookProc
extern JS_PUBLIC_API(void)
JS_SetNewScriptHook(JSRuntime *rt, JSNewScriptHook hook, void *callerdata);
extern JS_PUBLIC_API(void)
JS_SetDestroyScriptHook(JSRuntime *rt, JSDestroyScriptHook hook,
void *callerdata);
/************************************************************************/
extern JS_PUBLIC_API(JSBool)
JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fp,
const jschar *bytes, uintN length,
const char *filename, uintN lineno,
jsval *rval);
extern JS_PUBLIC_API(JSBool)
JS_EvaluateInStackFrame(JSContext *cx, JSStackFrame *fp,
const char *bytes, uintN length,
const char *filename, uintN lineno,
jsval *rval);
/************************************************************************/
typedef struct JSPropertyDesc {
jsval id; /* primary id, a string or int */
jsval value; /* property value */
uint8 flags; /* flags, see below */
uint8 spare; /* unused */
uint16 slot; /* argument/variable slot */
jsval alias; /* alias id if JSPD_ALIAS flag */
} JSPropertyDesc;
#define JSPD_ENUMERATE 0x01 /* visible to for/in loop */
#define JSPD_READONLY 0x02 /* assignment is error */
#define JSPD_PERMANENT 0x04 /* property cannot be deleted */
#define JSPD_ALIAS 0x08 /* property has an alias id */
#define JSPD_ARGUMENT 0x10 /* argument to function */
#define JSPD_VARIABLE 0x20 /* local variable in function */
#define JSPD_EXCEPTION 0x40 /* exception occurred fetching the property, */
/* value is exception */
#define JSPD_ERROR 0x80 /* native getter returned JS_FALSE without */
/* throwing an exception */
typedef struct JSPropertyDescArray {
uint32 length; /* number of elements in array */
JSPropertyDesc *array; /* alloc'd by Get, freed by Put */
} JSPropertyDescArray;
extern JS_PUBLIC_API(JSScopeProperty *)
JS_PropertyIterator(JSObject *obj, JSScopeProperty **iteratorp);
extern JS_PUBLIC_API(JSBool)
JS_GetPropertyDesc(JSContext *cx, JSObject *obj, JSScopeProperty *sprop,
JSPropertyDesc *pd);
extern JS_PUBLIC_API(JSBool)
JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda);
extern JS_PUBLIC_API(void)
JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda);
/************************************************************************/
extern JS_PUBLIC_API(JSBool)
JS_SetDebuggerHandler(JSRuntime *rt, JSTrapHandler handler, void *closure);
extern JS_PUBLIC_API(JSBool)
JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure);
extern JS_PUBLIC_API(JSBool)
JS_SetExecuteHook(JSRuntime *rt, JSInterpreterHook hook, void *closure);
extern JS_PUBLIC_API(JSBool)
JS_SetCallHook(JSRuntime *rt, JSInterpreterHook hook, void *closure);
extern JS_PUBLIC_API(JSBool)
JS_SetObjectHook(JSRuntime *rt, JSObjectHook hook, void *closure);
extern JS_PUBLIC_API(JSBool)
JS_SetThrowHook(JSRuntime *rt, JSTrapHandler hook, void *closure);
extern JS_PUBLIC_API(JSBool)
JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure);
/************************************************************************/
extern JS_PUBLIC_API(size_t)
JS_GetObjectTotalSize(JSContext *cx, JSObject *obj);
extern JS_PUBLIC_API(size_t)
JS_GetFunctionTotalSize(JSContext *cx, JSFunction *fun);
extern JS_PUBLIC_API(size_t)
JS_GetScriptTotalSize(JSContext *cx, JSScript *script);
JS_END_EXTERN_C
#endif /* jsdbgapi_h___ */

View File

@@ -1,763 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla JavaScript code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999-2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brendan Eich <brendan@mozilla.org> (Original Author)
* Chris Waterson <waterson@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* Double hashing implementation.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "jsbit.h"
#include "jsdhash.h"
#include "jsutil.h" /* for JS_ASSERT */
#ifdef JS_DHASHMETER
# if defined MOZILLA_CLIENT && defined DEBUG_XXXbrendan
# include "nsTraceMalloc.h"
# endif
# define METER(x) x
#else
# define METER(x) /* nothing */
#endif
JS_PUBLIC_API(void *)
JS_DHashAllocTable(JSDHashTable *table, uint32 nbytes)
{
return malloc(nbytes);
}
JS_PUBLIC_API(void)
JS_DHashFreeTable(JSDHashTable *table, void *ptr)
{
free(ptr);
}
JS_PUBLIC_API(JSDHashNumber)
JS_DHashStringKey(JSDHashTable *table, const void *key)
{
JSDHashNumber h;
const unsigned char *s;
h = 0;
for (s = key; *s != '\0'; s++)
h = (h >> (JS_DHASH_BITS - 4)) ^ (h << 4) ^ *s;
return h;
}
JS_PUBLIC_API(const void *)
JS_DHashGetKeyStub(JSDHashTable *table, JSDHashEntryHdr *entry)
{
JSDHashEntryStub *stub = (JSDHashEntryStub *)entry;
return stub->key;
}
JS_PUBLIC_API(JSDHashNumber)
JS_DHashVoidPtrKeyStub(JSDHashTable *table, const void *key)
{
return (JSDHashNumber)key >> 2;
}
JS_PUBLIC_API(JSBool)
JS_DHashMatchEntryStub(JSDHashTable *table,
const JSDHashEntryHdr *entry,
const void *key)
{
const JSDHashEntryStub *stub = (const JSDHashEntryStub *)entry;
return stub->key == key;
}
JS_PUBLIC_API(JSBool)
JS_DHashMatchStringKey(JSDHashTable *table,
const JSDHashEntryHdr *entry,
const void *key)
{
const JSDHashEntryStub *stub = (const JSDHashEntryStub *)entry;
/* XXX tolerate null keys on account of sloppy Mozilla callers. */
return stub->key == key ||
(stub->key && key && strcmp(stub->key, key) == 0);
}
JS_PUBLIC_API(void)
JS_DHashMoveEntryStub(JSDHashTable *table,
const JSDHashEntryHdr *from,
JSDHashEntryHdr *to)
{
memcpy(to, from, table->entrySize);
}
JS_PUBLIC_API(void)
JS_DHashClearEntryStub(JSDHashTable *table, JSDHashEntryHdr *entry)
{
memset(entry, 0, table->entrySize);
}
JS_PUBLIC_API(void)
JS_DHashFreeStringKey(JSDHashTable *table, JSDHashEntryHdr *entry)
{
const JSDHashEntryStub *stub = (const JSDHashEntryStub *)entry;
free((void *) stub->key);
memset(entry, 0, table->entrySize);
}
JS_PUBLIC_API(void)
JS_DHashFinalizeStub(JSDHashTable *table)
{
}
static const JSDHashTableOps stub_ops = {
JS_DHashAllocTable,
JS_DHashFreeTable,
JS_DHashGetKeyStub,
JS_DHashVoidPtrKeyStub,
JS_DHashMatchEntryStub,
JS_DHashMoveEntryStub,
JS_DHashClearEntryStub,
JS_DHashFinalizeStub,
NULL
};
JS_PUBLIC_API(const JSDHashTableOps *)
JS_DHashGetStubOps(void)
{
return &stub_ops;
}
JS_PUBLIC_API(JSDHashTable *)
JS_NewDHashTable(const JSDHashTableOps *ops, void *data, uint32 entrySize,
uint32 capacity)
{
JSDHashTable *table;
table = (JSDHashTable *) malloc(sizeof *table);
if (!table)
return NULL;
if (!JS_DHashTableInit(table, ops, data, entrySize, capacity)) {
free(table);
return NULL;
}
return table;
}
JS_PUBLIC_API(void)
JS_DHashTableDestroy(JSDHashTable *table)
{
JS_DHashTableFinish(table);
free(table);
}
JS_PUBLIC_API(JSBool)
JS_DHashTableInit(JSDHashTable *table, const JSDHashTableOps *ops, void *data,
uint32 entrySize, uint32 capacity)
{
int log2;
uint32 nbytes;
#ifdef DEBUG
if (entrySize > 10 * sizeof(void *)) {
fprintf(stderr,
"jsdhash: for the table at address %p, the given entrySize"
" of %lu %s favors chaining over double hashing.\n",
(void *)table,
(unsigned long) entrySize,
(entrySize > 16 * sizeof(void*)) ? "definitely" : "probably");
}
#endif
table->ops = ops;
table->data = data;
if (capacity < JS_DHASH_MIN_SIZE)
capacity = JS_DHASH_MIN_SIZE;
log2 = JS_CeilingLog2(capacity);
capacity = JS_BIT(log2);
if (capacity >= JS_DHASH_SIZE_LIMIT)
return JS_FALSE;
table->hashShift = JS_DHASH_BITS - log2;
table->maxAlphaFrac = 0xC0; /* .75 */
table->minAlphaFrac = 0x40; /* .25 */
table->entrySize = entrySize;
table->entryCount = table->removedCount = 0;
table->generation = 0;
nbytes = capacity * entrySize;
table->entryStore = ops->allocTable(table, nbytes);
if (!table->entryStore)
return JS_FALSE;
memset(table->entryStore, 0, nbytes);
METER(memset(&table->stats, 0, sizeof table->stats));
return JS_TRUE;
}
/*
* Compute max and min load numbers (entry counts) from table params.
*/
#define MAX_LOAD(table, size) (((table)->maxAlphaFrac * (size)) >> 8)
#define MIN_LOAD(table, size) (((table)->minAlphaFrac * (size)) >> 8)
JS_PUBLIC_API(void)
JS_DHashTableSetAlphaBounds(JSDHashTable *table,
float maxAlpha,
float minAlpha)
{
uint32 size;
/*
* Reject obviously insane bounds, rather than trying to guess what the
* buggy caller intended.
*/
JS_ASSERT(0.5 <= maxAlpha && maxAlpha < 1 && 0 <= minAlpha);
if (maxAlpha < 0.5 || 1 <= maxAlpha || minAlpha < 0)
return;
/*
* Ensure that at least one entry will always be free. If maxAlpha at
* minimum size leaves no entries free, reduce maxAlpha based on minimum
* size and the precision limit of maxAlphaFrac's fixed point format.
*/
JS_ASSERT(JS_DHASH_MIN_SIZE - (maxAlpha * JS_DHASH_MIN_SIZE) >= 1);
if (JS_DHASH_MIN_SIZE - (maxAlpha * JS_DHASH_MIN_SIZE) < 1) {
maxAlpha = (float)
(JS_DHASH_MIN_SIZE - JS_MAX(JS_DHASH_MIN_SIZE / 256, 1))
/ JS_DHASH_MIN_SIZE;
}
/*
* Ensure that minAlpha is strictly less than half maxAlpha. Take care
* not to truncate an entry's worth of alpha when storing in minAlphaFrac
* (8-bit fixed point format).
*/
JS_ASSERT(minAlpha < maxAlpha / 2);
if (minAlpha >= maxAlpha / 2) {
size = JS_DHASH_TABLE_SIZE(table);
minAlpha = (size * maxAlpha - JS_MAX(size / 256, 1)) / (2 * size);
}
table->maxAlphaFrac = (uint8)(maxAlpha * 256);
table->minAlphaFrac = (uint8)(minAlpha * 256);
}
/*
* Double hashing needs the second hash code to be relatively prime to table
* size, so we simply make hash2 odd.
*/
#define HASH1(hash0, shift) ((hash0) >> (shift))
#define HASH2(hash0,log2,shift) ((((hash0) << (log2)) >> (shift)) | 1)
/*
* Reserve keyHash 0 for free entries and 1 for removed-entry sentinels. Note
* that a removed-entry sentinel need be stored only if the removed entry had
* a colliding entry added after it. Therefore we can use 1 as the collision
* flag in addition to the removed-entry sentinel value. Multiplicative hash
* uses the high order bits of keyHash, so this least-significant reservation
* should not hurt the hash function's effectiveness much.
*
* If you change any of these magic numbers, also update JS_DHASH_ENTRY_IS_LIVE
* in jsdhash.h. It used to be private to jsdhash.c, but then became public to
* assist iterator writers who inspect table->entryStore directly.
*/
#define COLLISION_FLAG ((JSDHashNumber) 1)
#define MARK_ENTRY_FREE(entry) ((entry)->keyHash = 0)
#define MARK_ENTRY_REMOVED(entry) ((entry)->keyHash = 1)
#define ENTRY_IS_REMOVED(entry) ((entry)->keyHash == 1)
#define ENTRY_IS_LIVE(entry) JS_DHASH_ENTRY_IS_LIVE(entry)
#define ENSURE_LIVE_KEYHASH(hash0) if (hash0 < 2) hash0 -= 2; else (void)0
/* Match an entry's keyHash against an unstored one computed from a key. */
#define MATCH_ENTRY_KEYHASH(entry,hash0) \
(((entry)->keyHash & ~COLLISION_FLAG) == (hash0))
/* Compute the address of the indexed entry in table. */
#define ADDRESS_ENTRY(table, index) \
((JSDHashEntryHdr *)((table)->entryStore + (index) * (table)->entrySize))
JS_PUBLIC_API(void)
JS_DHashTableFinish(JSDHashTable *table)
{
char *entryAddr, *entryLimit;
uint32 entrySize;
JSDHashEntryHdr *entry;
#ifdef DEBUG_XXXbrendan
static FILE *dumpfp = NULL;
if (!dumpfp) dumpfp = fopen("/tmp/jsdhash.bigdump", "w");
if (dumpfp) {
#ifdef MOZILLA_CLIENT
NS_TraceStack(1, dumpfp);
#endif
JS_DHashTableDumpMeter(table, NULL, dumpfp);
fputc('\n', dumpfp);
}
#endif
/* Call finalize before clearing entries, so it can enumerate them. */
table->ops->finalize(table);
/* Clear any remaining live entries. */
entryAddr = table->entryStore;
entrySize = table->entrySize;
entryLimit = entryAddr + JS_DHASH_TABLE_SIZE(table) * entrySize;
while (entryAddr < entryLimit) {
entry = (JSDHashEntryHdr *)entryAddr;
if (ENTRY_IS_LIVE(entry)) {
METER(table->stats.removeEnums++);
table->ops->clearEntry(table, entry);
}
entryAddr += entrySize;
}
/* Free entry storage last. */
table->ops->freeTable(table, table->entryStore);
}
static JSDHashEntryHdr * JS_DHASH_FASTCALL
SearchTable(JSDHashTable *table, const void *key, JSDHashNumber keyHash,
JSDHashOperator op)
{
JSDHashNumber hash1, hash2;
int hashShift, sizeLog2;
JSDHashEntryHdr *entry, *firstRemoved;
JSDHashMatchEntry matchEntry;
uint32 sizeMask;
METER(table->stats.searches++);
JS_ASSERT(!(keyHash & COLLISION_FLAG));
/* Compute the primary hash address. */
hashShift = table->hashShift;
hash1 = HASH1(keyHash, hashShift);
entry = ADDRESS_ENTRY(table, hash1);
/* Miss: return space for a new entry. */
if (JS_DHASH_ENTRY_IS_FREE(entry)) {
METER(table->stats.misses++);
return entry;
}
/* Hit: return entry. */
matchEntry = table->ops->matchEntry;
if (MATCH_ENTRY_KEYHASH(entry, keyHash) && matchEntry(table, entry, key)) {
METER(table->stats.hits++);
return entry;
}
/* Collision: double hash. */
sizeLog2 = JS_DHASH_BITS - table->hashShift;
hash2 = HASH2(keyHash, sizeLog2, hashShift);
sizeMask = JS_BITMASK(sizeLog2);
/* Save the first removed entry pointer so JS_DHASH_ADD can recycle it. */
if (ENTRY_IS_REMOVED(entry)) {
firstRemoved = entry;
} else {
firstRemoved = NULL;
if (op == JS_DHASH_ADD)
entry->keyHash |= COLLISION_FLAG;
}
for (;;) {
METER(table->stats.steps++);
hash1 -= hash2;
hash1 &= sizeMask;
entry = ADDRESS_ENTRY(table, hash1);
if (JS_DHASH_ENTRY_IS_FREE(entry)) {
METER(table->stats.misses++);
return (firstRemoved && op == JS_DHASH_ADD) ? firstRemoved : entry;
}
if (MATCH_ENTRY_KEYHASH(entry, keyHash) &&
matchEntry(table, entry, key)) {
METER(table->stats.hits++);
return entry;
}
if (ENTRY_IS_REMOVED(entry)) {
if (!firstRemoved)
firstRemoved = entry;
} else {
if (op == JS_DHASH_ADD)
entry->keyHash |= COLLISION_FLAG;
}
}
/* NOTREACHED */
return NULL;
}
static JSBool
ChangeTable(JSDHashTable *table, int deltaLog2)
{
int oldLog2, newLog2;
uint32 oldCapacity, newCapacity;
char *newEntryStore, *oldEntryStore, *oldEntryAddr;
uint32 entrySize, i, nbytes;
JSDHashEntryHdr *oldEntry, *newEntry;
JSDHashGetKey getKey;
JSDHashMoveEntry moveEntry;
/* Look, but don't touch, until we succeed in getting new entry store. */
oldLog2 = JS_DHASH_BITS - table->hashShift;
newLog2 = oldLog2 + deltaLog2;
oldCapacity = JS_BIT(oldLog2);
newCapacity = JS_BIT(newLog2);
if (newCapacity >= JS_DHASH_SIZE_LIMIT)
return JS_FALSE;
entrySize = table->entrySize;
nbytes = newCapacity * entrySize;
newEntryStore = table->ops->allocTable(table, nbytes);
if (!newEntryStore)
return JS_FALSE;
/* We can't fail from here on, so update table parameters. */
table->hashShift = JS_DHASH_BITS - newLog2;
table->removedCount = 0;
table->generation++;
/* Assign the new entry store to table. */
memset(newEntryStore, 0, nbytes);
oldEntryAddr = oldEntryStore = table->entryStore;
table->entryStore = newEntryStore;
getKey = table->ops->getKey;
moveEntry = table->ops->moveEntry;
/* Copy only live entries, leaving removed ones behind. */
for (i = 0; i < oldCapacity; i++) {
oldEntry = (JSDHashEntryHdr *)oldEntryAddr;
if (ENTRY_IS_LIVE(oldEntry)) {
oldEntry->keyHash &= ~COLLISION_FLAG;
newEntry = SearchTable(table, getKey(table, oldEntry),
oldEntry->keyHash, JS_DHASH_ADD);
JS_ASSERT(JS_DHASH_ENTRY_IS_FREE(newEntry));
moveEntry(table, oldEntry, newEntry);
newEntry->keyHash = oldEntry->keyHash;
}
oldEntryAddr += entrySize;
}
table->ops->freeTable(table, oldEntryStore);
return JS_TRUE;
}
JS_PUBLIC_API(JSDHashEntryHdr *) JS_DHASH_FASTCALL
JS_DHashTableOperate(JSDHashTable *table, const void *key, JSDHashOperator op)
{
JSDHashNumber keyHash;
JSDHashEntryHdr *entry;
uint32 size;
int deltaLog2;
keyHash = table->ops->hashKey(table, key);
keyHash *= JS_DHASH_GOLDEN_RATIO;
/* Avoid 0 and 1 hash codes, they indicate free and removed entries. */
ENSURE_LIVE_KEYHASH(keyHash);
keyHash &= ~COLLISION_FLAG;
switch (op) {
case JS_DHASH_LOOKUP:
METER(table->stats.lookups++);
entry = SearchTable(table, key, keyHash, op);
break;
case JS_DHASH_ADD:
/*
* If alpha is >= .75, grow or compress the table. If key is already
* in the table, we may grow once more than necessary, but only if we
* are on the edge of being overloaded.
*/
size = JS_DHASH_TABLE_SIZE(table);
if (table->entryCount + table->removedCount >= MAX_LOAD(table, size)) {
/* Compress if a quarter or more of all entries are removed. */
if (table->removedCount >= size >> 2) {
METER(table->stats.compresses++);
deltaLog2 = 0;
} else {
METER(table->stats.grows++);
deltaLog2 = 1;
}
/*
* Grow or compress table, returning null if ChangeTable fails and
* falling through might claim the last free entry.
*/
if (!ChangeTable(table, deltaLog2) &&
table->entryCount + table->removedCount == size - 1) {
METER(table->stats.addFailures++);
return NULL;
}
}
/*
* Look for entry after possibly growing, so we don't have to add it,
* then skip it while growing the table and re-add it after.
*/
entry = SearchTable(table, key, keyHash, op);
if (!ENTRY_IS_LIVE(entry)) {
/* Initialize the entry, indicating that it's no longer free. */
METER(table->stats.addMisses++);
if (ENTRY_IS_REMOVED(entry)) {
METER(table->stats.addOverRemoved++);
table->removedCount--;
keyHash |= COLLISION_FLAG;
}
if (table->ops->initEntry &&
!table->ops->initEntry(table, entry, key)) {
/* We haven't claimed entry yet; fail with null return. */
memset(entry + 1, 0, table->entrySize - sizeof *entry);
return NULL;
}
entry->keyHash = keyHash;
table->entryCount++;
}
METER(else table->stats.addHits++);
break;
case JS_DHASH_REMOVE:
entry = SearchTable(table, key, keyHash, op);
if (ENTRY_IS_LIVE(entry)) {
/* Clear this entry and mark it as "removed". */
METER(table->stats.removeHits++);
JS_DHashTableRawRemove(table, entry);
/* Shrink if alpha is <= .25 and table isn't too small already. */
size = JS_DHASH_TABLE_SIZE(table);
if (size > JS_DHASH_MIN_SIZE &&
table->entryCount <= MIN_LOAD(table, size)) {
METER(table->stats.shrinks++);
(void) ChangeTable(table, -1);
}
}
METER(else table->stats.removeMisses++);
entry = NULL;
break;
default:
JS_ASSERT(0);
entry = NULL;
}
return entry;
}
JS_PUBLIC_API(void)
JS_DHashTableRawRemove(JSDHashTable *table, JSDHashEntryHdr *entry)
{
JSDHashNumber keyHash; /* load first in case clearEntry goofs it */
JS_ASSERT(JS_DHASH_ENTRY_IS_LIVE(entry));
keyHash = entry->keyHash;
table->ops->clearEntry(table, entry);
if (keyHash & COLLISION_FLAG) {
MARK_ENTRY_REMOVED(entry);
table->removedCount++;
} else {
METER(table->stats.removeFrees++);
MARK_ENTRY_FREE(entry);
}
table->entryCount--;
}
JS_PUBLIC_API(uint32)
JS_DHashTableEnumerate(JSDHashTable *table, JSDHashEnumerator etor, void *arg)
{
char *entryAddr, *entryLimit;
uint32 i, capacity, entrySize;
JSBool didRemove;
JSDHashEntryHdr *entry;
JSDHashOperator op;
entryAddr = table->entryStore;
entrySize = table->entrySize;
capacity = JS_DHASH_TABLE_SIZE(table);
entryLimit = entryAddr + capacity * entrySize;
i = 0;
didRemove = JS_FALSE;
while (entryAddr < entryLimit) {
entry = (JSDHashEntryHdr *)entryAddr;
if (ENTRY_IS_LIVE(entry)) {
op = etor(table, entry, i++, arg);
if (op & JS_DHASH_REMOVE) {
METER(table->stats.removeEnums++);
JS_DHashTableRawRemove(table, entry);
didRemove = JS_TRUE;
}
if (op & JS_DHASH_STOP)
break;
}
entryAddr += entrySize;
}
/*
* Shrink or compress if a quarter or more of all entries are removed, or
* if the table is underloaded according to the configured minimum alpha,
* and is not minimal-size already. Do this only if we removed above, so
* non-removing enumerations can count on stable table->entryStore until
* the next non-lookup-Operate or removing-Enumerate.
*/
if (didRemove &&
(table->removedCount >= capacity >> 2 ||
(capacity > JS_DHASH_MIN_SIZE &&
table->entryCount <= MIN_LOAD(table, capacity)))) {
METER(table->stats.enumShrinks++);
capacity = table->entryCount;
capacity += capacity >> 1;
if (capacity < JS_DHASH_MIN_SIZE)
capacity = JS_DHASH_MIN_SIZE;
(void) ChangeTable(table,
JS_CeilingLog2(capacity)
- (JS_DHASH_BITS - table->hashShift));
}
return i;
}
#ifdef JS_DHASHMETER
#include <math.h>
JS_PUBLIC_API(void)
JS_DHashTableDumpMeter(JSDHashTable *table, JSDHashEnumerator dump, FILE *fp)
{
char *entryAddr;
uint32 entrySize, entryCount;
int hashShift, sizeLog2;
uint32 i, tableSize, sizeMask, chainLen, maxChainLen, chainCount;
JSDHashNumber hash1, hash2, saveHash1, maxChainHash1, maxChainHash2;
double sqsum, mean, variance, sigma;
JSDHashEntryHdr *entry, *probe;
entryAddr = table->entryStore;
entrySize = table->entrySize;
hashShift = table->hashShift;
sizeLog2 = JS_DHASH_BITS - hashShift;
tableSize = JS_DHASH_TABLE_SIZE(table);
sizeMask = JS_BITMASK(sizeLog2);
chainCount = maxChainLen = 0;
hash2 = 0;
sqsum = 0;
for (i = 0; i < tableSize; i++) {
entry = (JSDHashEntryHdr *)entryAddr;
entryAddr += entrySize;
if (!ENTRY_IS_LIVE(entry))
continue;
hash1 = HASH1(entry->keyHash & ~COLLISION_FLAG, hashShift);
saveHash1 = hash1;
probe = ADDRESS_ENTRY(table, hash1);
chainLen = 1;
if (probe == entry) {
/* Start of a (possibly unit-length) chain. */
chainCount++;
} else {
hash2 = HASH2(entry->keyHash & ~COLLISION_FLAG, sizeLog2,
hashShift);
do {
chainLen++;
hash1 -= hash2;
hash1 &= sizeMask;
probe = ADDRESS_ENTRY(table, hash1);
} while (probe != entry);
}
sqsum += chainLen * chainLen;
if (chainLen > maxChainLen) {
maxChainLen = chainLen;
maxChainHash1 = saveHash1;
maxChainHash2 = hash2;
}
}
entryCount = table->entryCount;
if (entryCount && chainCount) {
mean = (double)entryCount / chainCount;
variance = chainCount * sqsum - entryCount * entryCount;
if (variance < 0 || chainCount == 1)
variance = 0;
else
variance /= chainCount * (chainCount - 1);
sigma = sqrt(variance);
} else {
mean = sigma = 0;
}
fprintf(fp, "Double hashing statistics:\n");
fprintf(fp, " table size (in entries): %u\n", tableSize);
fprintf(fp, " number of entries: %u\n", table->entryCount);
fprintf(fp, " number of removed entries: %u\n", table->removedCount);
fprintf(fp, " number of searches: %u\n", table->stats.searches);
fprintf(fp, " number of hits: %u\n", table->stats.hits);
fprintf(fp, " number of misses: %u\n", table->stats.misses);
fprintf(fp, " mean steps per search: %g\n", table->stats.searches ?
(double)table->stats.steps
/ table->stats.searches :
0.);
fprintf(fp, " mean hash chain length: %g\n", mean);
fprintf(fp, " standard deviation: %g\n", sigma);
fprintf(fp, " maximum hash chain length: %u\n", maxChainLen);
fprintf(fp, " number of lookups: %u\n", table->stats.lookups);
fprintf(fp, " adds that made a new entry: %u\n", table->stats.addMisses);
fprintf(fp, "adds that recycled removeds: %u\n", table->stats.addOverRemoved);
fprintf(fp, " adds that found an entry: %u\n", table->stats.addHits);
fprintf(fp, " add failures: %u\n", table->stats.addFailures);
fprintf(fp, " useful removes: %u\n", table->stats.removeHits);
fprintf(fp, " useless removes: %u\n", table->stats.removeMisses);
fprintf(fp, "removes that freed an entry: %u\n", table->stats.removeFrees);
fprintf(fp, " removes while enumerating: %u\n", table->stats.removeEnums);
fprintf(fp, " number of grows: %u\n", table->stats.grows);
fprintf(fp, " number of shrinks: %u\n", table->stats.shrinks);
fprintf(fp, " number of compresses: %u\n", table->stats.compresses);
fprintf(fp, "number of enumerate shrinks: %u\n", table->stats.enumShrinks);
if (dump && maxChainLen && hash2) {
fputs("Maximum hash chain:\n", fp);
hash1 = maxChainHash1;
hash2 = maxChainHash2;
entry = ADDRESS_ENTRY(table, hash1);
i = 0;
do {
if (dump(table, entry, i++, fp) != JS_DHASH_NEXT)
break;
hash1 -= hash2;
hash1 &= sizeMask;
entry = ADDRESS_ENTRY(table, hash1);
} while (JS_DHASH_ENTRY_IS_BUSY(entry));
}
}
#endif /* JS_DHASHMETER */

View File

@@ -1,579 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla JavaScript code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999-2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brendan Eich <brendan@mozilla.org> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsdhash_h___
#define jsdhash_h___
/*
* Double hashing, a la Knuth 6.
*/
#include "jstypes.h"
JS_BEGIN_EXTERN_C
#if defined(__GNUC__) && defined(__i386__) && (__GNUC__ >= 3) && !defined(XP_OS2)
#define JS_DHASH_FASTCALL __attribute__ ((regparm (3),stdcall))
#else
#define JS_DHASH_FASTCALL
#endif
#ifdef DEBUG_XXXbrendan
#define JS_DHASHMETER 1
#endif
/* Table size limit, do not equal or exceed (see min&maxAlphaFrac, below). */
#undef JS_DHASH_SIZE_LIMIT
#define JS_DHASH_SIZE_LIMIT JS_BIT(24)
/* Minimum table size, or gross entry count (net is at most .75 loaded). */
#ifndef JS_DHASH_MIN_SIZE
#define JS_DHASH_MIN_SIZE 16
#elif (JS_DHASH_MIN_SIZE & (JS_DHASH_MIN_SIZE - 1)) != 0
#error "JS_DHASH_MIN_SIZE must be a power of two!"
#endif
/*
* Multiplicative hash uses an unsigned 32 bit integer and the golden ratio,
* expressed as a fixed-point 32-bit fraction.
*/
#define JS_DHASH_BITS 32
#define JS_DHASH_GOLDEN_RATIO 0x9E3779B9U
/* Primitive and forward-struct typedefs. */
typedef uint32 JSDHashNumber;
typedef struct JSDHashEntryHdr JSDHashEntryHdr;
typedef struct JSDHashEntryStub JSDHashEntryStub;
typedef struct JSDHashTable JSDHashTable;
typedef struct JSDHashTableOps JSDHashTableOps;
/*
* Table entry header structure.
*
* In order to allow in-line allocation of key and value, we do not declare
* either here. Instead, the API uses const void *key as a formal parameter,
* and asks each entry for its key when necessary via a getKey callback, used
* when growing or shrinking the table. Other callback types are defined
* below and grouped into the JSDHashTableOps structure, for single static
* initialization per hash table sub-type.
*
* Each hash table sub-type should nest the JSDHashEntryHdr structure at the
* front of its particular entry type. The keyHash member contains the result
* of multiplying the hash code returned from the hashKey callback (see below)
* by JS_DHASH_GOLDEN_RATIO, then constraining the result to avoid the magic 0
* and 1 values. The stored keyHash value is table size invariant, and it is
* maintained automatically by JS_DHashTableOperate -- users should never set
* it, and its only uses should be via the entry macros below.
*
* The JS_DHASH_ENTRY_IS_LIVE macro tests whether entry is neither free nor
* removed. An entry may be either busy or free; if busy, it may be live or
* removed. Consumers of this API should not access members of entries that
* are not live.
*
* However, use JS_DHASH_ENTRY_IS_BUSY for faster liveness testing of entries
* returned by JS_DHashTableOperate, as JS_DHashTableOperate never returns a
* non-live, busy (i.e., removed) entry pointer to its caller. See below for
* more details on JS_DHashTableOperate's calling rules.
*/
struct JSDHashEntryHdr {
JSDHashNumber keyHash; /* every entry must begin like this */
};
#define JS_DHASH_ENTRY_IS_FREE(entry) ((entry)->keyHash == 0)
#define JS_DHASH_ENTRY_IS_BUSY(entry) (!JS_DHASH_ENTRY_IS_FREE(entry))
#define JS_DHASH_ENTRY_IS_LIVE(entry) ((entry)->keyHash >= 2)
/*
* A JSDHashTable is currently 8 words (without the JS_DHASHMETER overhead)
* on most architectures, and may be allocated on the stack or within another
* structure or class (see below for the Init and Finish functions to use).
*
* To decide whether to use double hashing vs. chaining, we need to develop a
* trade-off relation, as follows:
*
* Let alpha be the load factor, esize the entry size in words, count the
* entry count, and pow2 the power-of-two table size in entries.
*
* (JSDHashTable overhead) > (JSHashTable overhead)
* (unused table entry space) > (malloc and .next overhead per entry) +
* (buckets overhead)
* (1 - alpha) * esize * pow2 > 2 * count + pow2
*
* Notice that alpha is by definition (count / pow2):
*
* (1 - alpha) * esize * pow2 > 2 * alpha * pow2 + pow2
* (1 - alpha) * esize > 2 * alpha + 1
*
* esize > (1 + 2 * alpha) / (1 - alpha)
*
* This assumes both tables must keep keyHash, key, and value for each entry,
* where key and value point to separately allocated strings or structures.
* If key and value can be combined into one pointer, then the trade-off is:
*
* esize > (1 + 3 * alpha) / (1 - alpha)
*
* If the entry value can be a subtype of JSDHashEntryHdr, rather than a type
* that must be allocated separately and referenced by an entry.value pointer
* member, and provided key's allocation can be fused with its entry's, then
* k (the words wasted per entry with chaining) is 4.
*
* To see these curves, feed gnuplot input like so:
*
* gnuplot> f(x,k) = (1 + k * x) / (1 - x)
* gnuplot> plot [0:.75] f(x,2), f(x,3), f(x,4)
*
* For k of 2 and a well-loaded table (alpha > .5), esize must be more than 4
* words for chaining to be more space-efficient than double hashing.
*
* Solving for alpha helps us decide when to shrink an underloaded table:
*
* esize > (1 + k * alpha) / (1 - alpha)
* esize - alpha * esize > 1 + k * alpha
* esize - 1 > (k + esize) * alpha
* (esize - 1) / (k + esize) > alpha
*
* alpha < (esize - 1) / (esize + k)
*
* Therefore double hashing should keep alpha >= (esize - 1) / (esize + k),
* assuming esize is not too large (in which case, chaining should probably be
* used for any alpha). For esize=2 and k=3, we want alpha >= .2; for esize=3
* and k=2, we want alpha >= .4. For k=4, esize could be 6, and alpha >= .5
* would still obtain. See the JS_DHASH_MIN_ALPHA macro further below.
*
* The current implementation uses a configurable lower bound on alpha, which
* defaults to .25, when deciding to shrink the table (while still respecting
* JS_DHASH_MIN_SIZE).
*
* Note a qualitative difference between chaining and double hashing: under
* chaining, entry addresses are stable across table shrinks and grows. With
* double hashing, you can't safely hold an entry pointer and use it after an
* ADD or REMOVE operation, unless you sample table->generation before adding
* or removing, and compare the sample after, dereferencing the entry pointer
* only if table->generation has not changed.
*
* The moral of this story: there is no one-size-fits-all hash table scheme,
* but for small table entry size, and assuming entry address stability is not
* required, double hashing wins.
*/
struct JSDHashTable {
const JSDHashTableOps *ops; /* virtual operations, see below */
void *data; /* ops- and instance-specific data */
int16 hashShift; /* multiplicative hash shift */
uint8 maxAlphaFrac; /* 8-bit fixed point max alpha */
uint8 minAlphaFrac; /* 8-bit fixed point min alpha */
uint32 entrySize; /* number of bytes in an entry */
uint32 entryCount; /* number of entries in table */
uint32 removedCount; /* removed entry sentinels in table */
uint32 generation; /* entry storage generation number */
char *entryStore; /* entry storage */
#ifdef JS_DHASHMETER
struct JSDHashStats {
uint32 searches; /* total number of table searches */
uint32 steps; /* hash chain links traversed */
uint32 hits; /* searches that found key */
uint32 misses; /* searches that didn't find key */
uint32 lookups; /* number of JS_DHASH_LOOKUPs */
uint32 addMisses; /* adds that miss, and do work */
uint32 addOverRemoved; /* adds that recycled a removed entry */
uint32 addHits; /* adds that hit an existing entry */
uint32 addFailures; /* out-of-memory during add growth */
uint32 removeHits; /* removes that hit, and do work */
uint32 removeMisses; /* useless removes that miss */
uint32 removeFrees; /* removes that freed entry directly */
uint32 removeEnums; /* removes done by Enumerate */
uint32 grows; /* table expansions */
uint32 shrinks; /* table contractions */
uint32 compresses; /* table compressions */
uint32 enumShrinks; /* contractions after Enumerate */
} stats;
#endif
};
/*
* Size in entries (gross, not net of free and removed sentinels) for table.
* We store hashShift rather than sizeLog2 to optimize the collision-free case
* in SearchTable.
*/
#define JS_DHASH_TABLE_SIZE(table) JS_BIT(JS_DHASH_BITS - (table)->hashShift)
/*
* Table space at entryStore is allocated and freed using these callbacks.
* The allocator should return null on error only (not if called with nbytes
* equal to 0; but note that jsdhash.c code will never call with 0 nbytes).
*/
typedef void *
(* JS_DLL_CALLBACK JSDHashAllocTable)(JSDHashTable *table, uint32 nbytes);
typedef void
(* JS_DLL_CALLBACK JSDHashFreeTable) (JSDHashTable *table, void *ptr);
/*
* When a table grows or shrinks, each entry is queried for its key using this
* callback. NB: in that event, entry is not in table any longer; it's in the
* old entryStore vector, which is due to be freed once all entries have been
* moved via moveEntry callbacks.
*/
typedef const void *
(* JS_DLL_CALLBACK JSDHashGetKey) (JSDHashTable *table,
JSDHashEntryHdr *entry);
/*
* Compute the hash code for a given key to be looked up, added, or removed
* from table. A hash code may have any JSDHashNumber value.
*/
typedef JSDHashNumber
(* JS_DLL_CALLBACK JSDHashHashKey) (JSDHashTable *table, const void *key);
/*
* Compare the key identifying entry in table with the provided key parameter.
* Return JS_TRUE if keys match, JS_FALSE otherwise.
*/
typedef JSBool
(* JS_DLL_CALLBACK JSDHashMatchEntry)(JSDHashTable *table,
const JSDHashEntryHdr *entry,
const void *key);
/*
* Copy the data starting at from to the new entry storage at to. Do not add
* reference counts for any strong references in the entry, however, as this
* is a "move" operation: the old entry storage at from will be freed without
* any reference-decrementing callback shortly.
*/
typedef void
(* JS_DLL_CALLBACK JSDHashMoveEntry)(JSDHashTable *table,
const JSDHashEntryHdr *from,
JSDHashEntryHdr *to);
/*
* Clear the entry and drop any strong references it holds. This callback is
* invoked during a JS_DHASH_REMOVE operation (see below for operation codes),
* but only if the given key is found in the table.
*/
typedef void
(* JS_DLL_CALLBACK JSDHashClearEntry)(JSDHashTable *table,
JSDHashEntryHdr *entry);
/*
* Called when a table (whether allocated dynamically by itself, or nested in
* a larger structure, or allocated on the stack) is finished. This callback
* allows table->ops-specific code to finalize table->data.
*/
typedef void
(* JS_DLL_CALLBACK JSDHashFinalize) (JSDHashTable *table);
/*
* Initialize a new entry, apart from keyHash. This function is called when
* JS_DHashTableOperate's JS_DHASH_ADD case finds no existing entry for the
* given key, and must add a new one. At that point, entry->keyHash is not
* set yet, to avoid claiming the last free entry in a severely overloaded
* table.
*/
typedef JSBool
(* JS_DLL_CALLBACK JSDHashInitEntry)(JSDHashTable *table,
JSDHashEntryHdr *entry,
const void *key);
/*
* Finally, the "vtable" structure for JSDHashTable. The first eight hooks
* must be provided by implementations; they're called unconditionally by the
* generic jsdhash.c code. Hooks after these may be null.
*
* Summary of allocation-related hook usage with C++ placement new emphasis:
* allocTable Allocate raw bytes with malloc, no ctors run.
* freeTable Free raw bytes with free, no dtors run.
* initEntry Call placement new using default key-based ctor.
* Return JS_TRUE on success, JS_FALSE on error.
* moveEntry Call placement new using copy ctor, run dtor on old
* entry storage.
* clearEntry Run dtor on entry.
* finalize Stub unless table->data was initialized and needs to
* be finalized.
*
* Note the reason why initEntry is optional: the default hooks (stubs) clear
* entry storage: On successful JS_DHashTableOperate(tbl, key, JS_DHASH_ADD),
* the returned entry pointer addresses an entry struct whose keyHash member
* has been set non-zero, but all other entry members are still clear (null).
* JS_DHASH_ADD callers can test such members to see whether the entry was
* newly created by the JS_DHASH_ADD call that just succeeded. If placement
* new or similar initialization is required, define an initEntry hook. Of
* course, the clearEntry hook must zero or null appropriately.
*
* XXX assumes 0 is null for pointer types.
*/
struct JSDHashTableOps {
/* Mandatory hooks. All implementations must provide these. */
JSDHashAllocTable allocTable;
JSDHashFreeTable freeTable;
JSDHashGetKey getKey;
JSDHashHashKey hashKey;
JSDHashMatchEntry matchEntry;
JSDHashMoveEntry moveEntry;
JSDHashClearEntry clearEntry;
JSDHashFinalize finalize;
/* Optional hooks start here. If null, these are not called. */
JSDHashInitEntry initEntry;
};
/*
* Default implementations for the above ops.
*/
extern JS_PUBLIC_API(void *)
JS_DHashAllocTable(JSDHashTable *table, uint32 nbytes);
extern JS_PUBLIC_API(void)
JS_DHashFreeTable(JSDHashTable *table, void *ptr);
extern JS_PUBLIC_API(JSDHashNumber)
JS_DHashStringKey(JSDHashTable *table, const void *key);
/* A minimal entry contains a keyHash header and a void key pointer. */
struct JSDHashEntryStub {
JSDHashEntryHdr hdr;
const void *key;
};
extern JS_PUBLIC_API(const void *)
JS_DHashGetKeyStub(JSDHashTable *table, JSDHashEntryHdr *entry);
extern JS_PUBLIC_API(JSDHashNumber)
JS_DHashVoidPtrKeyStub(JSDHashTable *table, const void *key);
extern JS_PUBLIC_API(JSBool)
JS_DHashMatchEntryStub(JSDHashTable *table,
const JSDHashEntryHdr *entry,
const void *key);
extern JS_PUBLIC_API(JSBool)
JS_DHashMatchStringKey(JSDHashTable *table,
const JSDHashEntryHdr *entry,
const void *key);
extern JS_PUBLIC_API(void)
JS_DHashMoveEntryStub(JSDHashTable *table,
const JSDHashEntryHdr *from,
JSDHashEntryHdr *to);
extern JS_PUBLIC_API(void)
JS_DHashClearEntryStub(JSDHashTable *table, JSDHashEntryHdr *entry);
extern JS_PUBLIC_API(void)
JS_DHashFreeStringKey(JSDHashTable *table, JSDHashEntryHdr *entry);
extern JS_PUBLIC_API(void)
JS_DHashFinalizeStub(JSDHashTable *table);
/*
* If you use JSDHashEntryStub or a subclass of it as your entry struct, and
* if your entries move via memcpy and clear via memset(0), you can use these
* stub operations.
*/
extern JS_PUBLIC_API(const JSDHashTableOps *)
JS_DHashGetStubOps(void);
/*
* Dynamically allocate a new JSDHashTable using malloc, initialize it using
* JS_DHashTableInit, and return its address. Return null on malloc failure.
* Note that the entry storage at table->entryStore will be allocated using
* the ops->allocTable callback.
*/
extern JS_PUBLIC_API(JSDHashTable *)
JS_NewDHashTable(const JSDHashTableOps *ops, void *data, uint32 entrySize,
uint32 capacity);
/*
* Finalize table's data, free its entry storage (via table->ops->freeTable),
* and return the memory starting at table to the malloc heap.
*/
extern JS_PUBLIC_API(void)
JS_DHashTableDestroy(JSDHashTable *table);
/*
* Initialize table with ops, data, entrySize, and capacity. Capacity is a
* guess for the smallest table size at which the table will usually be less
* than 75% loaded (the table will grow or shrink as needed; capacity serves
* only to avoid inevitable early growth from JS_DHASH_MIN_SIZE).
*/
extern JS_PUBLIC_API(JSBool)
JS_DHashTableInit(JSDHashTable *table, const JSDHashTableOps *ops, void *data,
uint32 entrySize, uint32 capacity);
/*
* Set maximum and minimum alpha for table. The defaults are 0.75 and .25.
* maxAlpha must be in [0.5, 0.9375] for the default JS_DHASH_MIN_SIZE; or if
* MinSize=JS_DHASH_MIN_SIZE <= 256, in [0.5, (float)(MinSize-1)/MinSize]; or
* else in [0.5, 255.0/256]. minAlpha must be in [0, maxAlpha / 2), so that
* we don't shrink on the very next remove after growing a table upon adding
* an entry that brings entryCount past maxAlpha * tableSize.
*/
JS_PUBLIC_API(void)
JS_DHashTableSetAlphaBounds(JSDHashTable *table,
float maxAlpha,
float minAlpha);
/*
* Call this macro with k, the number of pointer-sized words wasted per entry
* under chaining, to compute the minimum alpha at which double hashing still
* beats chaining.
*/
#define JS_DHASH_MIN_ALPHA(table, k) \
((float)((table)->entrySize / sizeof(void *) - 1) \
/ ((table)->entrySize / sizeof(void *) + (k)))
/*
* Finalize table's data, free its entry storage using table->ops->freeTable,
* and leave its members unchanged from their last live values (which leaves
* pointers dangling). If you want to burn cycles clearing table, it's up to
* your code to call memset.
*/
extern JS_PUBLIC_API(void)
JS_DHashTableFinish(JSDHashTable *table);
/*
* To consolidate keyHash computation and table grow/shrink code, we use a
* single entry point for lookup, add, and remove operations. The operation
* codes are declared here, along with codes returned by JSDHashEnumerator
* functions, which control JS_DHashTableEnumerate's behavior.
*/
typedef enum JSDHashOperator {
JS_DHASH_LOOKUP = 0, /* lookup entry */
JS_DHASH_ADD = 1, /* add entry */
JS_DHASH_REMOVE = 2, /* remove entry, or enumerator says remove */
JS_DHASH_NEXT = 0, /* enumerator says continue */
JS_DHASH_STOP = 1 /* enumerator says stop */
} JSDHashOperator;
/*
* To lookup a key in table, call:
*
* entry = JS_DHashTableOperate(table, key, JS_DHASH_LOOKUP);
*
* If JS_DHASH_ENTRY_IS_BUSY(entry) is true, key was found and it identifies
* entry. If JS_DHASH_ENTRY_IS_FREE(entry) is true, key was not found.
*
* To add an entry identified by key to table, call:
*
* entry = JS_DHashTableOperate(table, key, JS_DHASH_ADD);
*
* If entry is null upon return, then either the table is severely overloaded,
* and memory can't be allocated for entry storage via table->ops->allocTable;
* Or if table->ops->initEntry is non-null, the table->ops->initEntry op may
* have returned false.
*
* Otherwise, entry->keyHash has been set so that JS_DHASH_ENTRY_IS_BUSY(entry)
* is true, and it is up to the caller to initialize the key and value parts
* of the entry sub-type, if they have not been set already (i.e. if entry was
* not already in the table, and if the optional initEntry hook was not used).
*
* To remove an entry identified by key from table, call:
*
* (void) JS_DHashTableOperate(table, key, JS_DHASH_REMOVE);
*
* If key's entry is found, it is cleared (via table->ops->clearEntry) and
* the entry is marked so that JS_DHASH_ENTRY_IS_FREE(entry). This operation
* returns null unconditionally; you should ignore its return value.
*/
extern JS_PUBLIC_API(JSDHashEntryHdr *) JS_DHASH_FASTCALL
JS_DHashTableOperate(JSDHashTable *table, const void *key, JSDHashOperator op);
/*
* Remove an entry already accessed via LOOKUP or ADD.
*
* NB: this is a "raw" or low-level routine, intended to be used only where
* the inefficiency of a full JS_DHashTableOperate (which rehashes in order
* to find the entry given its key) is not tolerable. This function does not
* shrink the table if it is underloaded. It does not update stats #ifdef
* JS_DHASHMETER, either.
*/
extern JS_PUBLIC_API(void)
JS_DHashTableRawRemove(JSDHashTable *table, JSDHashEntryHdr *entry);
/*
* Enumerate entries in table using etor:
*
* count = JS_DHashTableEnumerate(table, etor, arg);
*
* JS_DHashTableEnumerate calls etor like so:
*
* op = etor(table, entry, number, arg);
*
* where number is a zero-based ordinal assigned to live entries according to
* their order in table->entryStore.
*
* The return value, op, is treated as a set of flags. If op is JS_DHASH_NEXT,
* then continue enumerating. If op contains JS_DHASH_REMOVE, then clear (via
* table->ops->clearEntry) and free entry. Then we check whether op contains
* JS_DHASH_STOP; if so, stop enumerating and return the number of live entries
* that were enumerated so far. Return the total number of live entries when
* enumeration completes normally.
*
* If etor calls JS_DHashTableOperate on table with op != JS_DHASH_LOOKUP, it
* must return JS_DHASH_STOP; otherwise undefined behavior results.
*
* If any enumerator returns JS_DHASH_REMOVE, table->entryStore may be shrunk
* or compressed after enumeration, but before JS_DHashTableEnumerate returns.
* Such an enumerator therefore can't safely set aside entry pointers, but an
* enumerator that never returns JS_DHASH_REMOVE can set pointers to entries
* aside, e.g., to avoid copying live entries into an array of the entry type.
* Copying entry pointers is cheaper, and safe so long as the caller of such a
* "stable" Enumerate doesn't use the set-aside pointers after any call either
* to PL_DHashTableOperate, or to an "unstable" form of Enumerate, which might
* grow or shrink entryStore.
*
* If your enumerator wants to remove certain entries, but set aside pointers
* to other entries that it retains, it can use JS_DHashTableRawRemove on the
* entries to be removed, returning JS_DHASH_NEXT to skip them. Likewise, if
* you want to remove entries, but for some reason you do not want entryStore
* to be shrunk or compressed, you can call JS_DHashTableRawRemove safely on
* the entry being enumerated, rather than returning JS_DHASH_REMOVE.
*/
typedef JSDHashOperator
(* JS_DLL_CALLBACK JSDHashEnumerator)(JSDHashTable *table, JSDHashEntryHdr *hdr,
uint32 number, void *arg);
extern JS_PUBLIC_API(uint32)
JS_DHashTableEnumerate(JSDHashTable *table, JSDHashEnumerator etor, void *arg);
#ifdef JS_DHASHMETER
#include <stdio.h>
extern JS_PUBLIC_API(void)
JS_DHashTableDumpMeter(JSDHashTable *table, JSDHashEnumerator dump, FILE *fp);
#endif
JS_END_EXTERN_C
#endif /* jsdhash_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,130 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsdtoa_h___
#define jsdtoa_h___
/*
* Public interface to portable double-precision floating point to string
* and back conversion package.
*/
#include "jscompat.h"
JS_BEGIN_EXTERN_C
/*
* JS_strtod() returns as a double-precision floating-point number
* the value represented by the character string pointed to by
* s00. The string is scanned up to the first unrecognized
* character.
* If the value of se is not (char **)NULL, a pointer to
* the character terminating the scan is returned in the location pointed
* to by se. If no number can be formed, se is set to s00r, and
* zero is returned.
*
* *err is set to zero on success; it's set to JS_DTOA_ERANGE on range
* errors and JS_DTOA_ENOMEM on memory failure.
*/
#define JS_DTOA_ERANGE 1
#define JS_DTOA_ENOMEM 2
JS_FRIEND_API(double)
JS_strtod(const char *s00, char **se, int *err);
/*
* Modes for converting floating-point numbers to strings.
*
* Some of the modes can round-trip; this means that if the number is converted to
* a string using one of these mode and then converted back to a number, the result
* will be identical to the original number (except that, due to ECMA, -0 will get converted
* to +0). These round-trip modes return the minimum number of significand digits that
* permit the round trip.
*
* Some of the modes take an integer parameter <precision>.
*/
/* NB: Keep this in sync with number_constants[]. */
typedef enum JSDToStrMode {
DTOSTR_STANDARD, /* Either fixed or exponential format; round-trip */
DTOSTR_STANDARD_EXPONENTIAL, /* Always exponential format; round-trip */
DTOSTR_FIXED, /* Round to <precision> digits after the decimal point; exponential if number is large */
DTOSTR_EXPONENTIAL, /* Always exponential format; <precision> significant digits */
DTOSTR_PRECISION /* Either fixed or exponential format; <precision> significant digits */
} JSDToStrMode;
/* Maximum number of characters (including trailing null) that a DTOSTR_STANDARD or DTOSTR_STANDARD_EXPONENTIAL
* conversion can produce. This maximum is reached for a number like -0.0000012345678901234567. */
#define DTOSTR_STANDARD_BUFFER_SIZE 26
/* Maximum number of characters (including trailing null) that one of the other conversions
* can produce. This maximum is reached for TO_FIXED, which can generate up to 21 digits before the decimal point. */
#define DTOSTR_VARIABLE_BUFFER_SIZE(precision) ((precision)+24 > DTOSTR_STANDARD_BUFFER_SIZE ? (precision)+24 : DTOSTR_STANDARD_BUFFER_SIZE)
/*
* Convert dval according to the given mode and return a pointer to the resulting ASCII string.
* The result is held somewhere in buffer, but not necessarily at the beginning. The size of
* buffer is given in bufferSize, and must be at least as large as given by the above macros.
*
* Return NULL if out of memory.
*/
JS_FRIEND_API(char *)
JS_dtostr(char *buffer, size_t bufferSize, JSDToStrMode mode, int precision, double dval);
/*
* Convert d to a string in the given base. The integral part of d will be printed exactly
* in that base, regardless of how large it is, because there is no exponential notation for non-base-ten
* numbers. The fractional part will be rounded to as few digits as possible while still preserving
* the round-trip property (analogous to that of printing decimal numbers). In other words, if one were
* to read the resulting string in via a hypothetical base-number-reading routine that rounds to the nearest
* IEEE double (and to an even significand if there are two equally near doubles), then the result would
* equal d (except for -0.0, which converts to "0", and NaN, which is not equal to itself).
*
* Return NULL if out of memory. If the result is not NULL, it must be released via free().
*/
JS_FRIEND_API(char *)
JS_dtobasestr(int base, double d);
/*
* Clean up any persistent RAM allocated during the execution of DtoA
* routines, and remove any locks that might have been created.
*/
extern void js_FinishDtoa(void);
JS_END_EXTERN_C
#endif /* jsdtoa_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,575 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsemit_h___
#define jsemit_h___
/*
* JS bytecode generation.
*/
#include "jsstddef.h"
#include "jstypes.h"
#include "jsatom.h"
#include "jsopcode.h"
#include "jsprvtd.h"
#include "jspubtd.h"
JS_BEGIN_EXTERN_C
/*
* NB: If you add non-loop STMT_* enumerators, do so before STMT_DO_LOOP or
* you will break the STMT_IS_LOOP macro, just below this enum.
*/
typedef enum JSStmtType {
STMT_BLOCK = 0, /* compound statement: { s1[;... sN] } */
STMT_LABEL = 1, /* labeled statement: L: s */
STMT_IF = 2, /* if (then) statement */
STMT_ELSE = 3, /* else clause of if statement */
STMT_SWITCH = 4, /* switch statement */
STMT_WITH = 5, /* with statement */
STMT_TRY = 6, /* try statement */
STMT_CATCH = 7, /* catch block */
STMT_FINALLY = 8, /* finally statement */
STMT_SUBROUTINE = 9, /* gosub-target subroutine body */
STMT_DO_LOOP = 10, /* do/while loop statement */
STMT_FOR_LOOP = 11, /* for loop statement */
STMT_FOR_IN_LOOP = 12, /* for/in loop statement */
STMT_WHILE_LOOP = 13 /* while loop statement */
} JSStmtType;
#define STMT_IS_LOOP(stmt) ((stmt)->type >= STMT_DO_LOOP)
typedef struct JSStmtInfo JSStmtInfo;
struct JSStmtInfo {
JSStmtType type; /* statement type */
ptrdiff_t update; /* loop update offset (top if none) */
ptrdiff_t breaks; /* offset of last break in loop */
ptrdiff_t continues; /* offset of last continue in loop */
ptrdiff_t gosub; /* offset of last GOSUB for this finally */
ptrdiff_t catchJump; /* offset of last end-of-catch jump */
JSAtom *label; /* name of LABEL or CATCH var */
JSStmtInfo *down; /* info for enclosing statement */
};
#define SET_STATEMENT_TOP(stmt, top) \
((stmt)->update = (top), (stmt)->breaks = \
(stmt)->continues = (stmt)->catchJump = (stmt)->gosub = (-1))
struct JSTreeContext { /* tree context for semantic checks */
uint16 flags; /* statement state flags, see below */
uint16 numGlobalVars; /* max. no. of global variables/regexps */
uint32 tryCount; /* total count of try statements parsed */
uint32 globalUses; /* optimizable global var uses in total */
uint32 loopyGlobalUses;/* optimizable global var uses in loops */
JSStmtInfo *topStmt; /* top of statement info stack */
JSAtomList decls; /* function, const, and var declarations */
JSParseNode *nodeList; /* list of recyclable parse-node structs */
};
#define TCF_COMPILING 0x01 /* generating bytecode; this tc is a cg */
#define TCF_IN_FUNCTION 0x02 /* parsing inside function body */
#define TCF_RETURN_EXPR 0x04 /* function has 'return expr;' */
#define TCF_RETURN_VOID 0x08 /* function has 'return;' */
#define TCF_IN_FOR_INIT 0x10 /* parsing init expr of for; exclude 'in' */
#define TCF_FUN_CLOSURE_VS_VAR 0x20 /* function and var with same name */
#define TCF_FUN_USES_NONLOCALS 0x40 /* function refers to non-local names */
#define TCF_FUN_HEAVYWEIGHT 0x80 /* function needs Call object per call */
#define TCF_FUN_FLAGS 0xE0 /* flags to propagate from FunctionBody */
#define TCF_HAS_DEFXMLNS 0x100 /* default xml namespace = ...; parsed */
#define TREE_CONTEXT_INIT(tc) \
((tc)->flags = (tc)->numGlobalVars = 0, \
(tc)->tryCount = (tc)->globalUses = (tc)->loopyGlobalUses = 0, \
(tc)->topStmt = NULL, ATOM_LIST_INIT(&(tc)->decls), \
(tc)->nodeList = NULL)
#define TREE_CONTEXT_FINISH(tc) \
((void)0)
/*
* Span-dependent instructions are jumps whose span (from the jump bytecode to
* the jump target) may require 2 or 4 bytes of immediate operand.
*/
typedef struct JSSpanDep JSSpanDep;
typedef struct JSJumpTarget JSJumpTarget;
struct JSSpanDep {
ptrdiff_t top; /* offset of first bytecode in an opcode */
ptrdiff_t offset; /* offset - 1 within opcode of jump operand */
ptrdiff_t before; /* original offset - 1 of jump operand */
JSJumpTarget *target; /* tagged target pointer or backpatch delta */
};
/*
* Jump targets are stored in an AVL tree, for O(log(n)) lookup with targets
* sorted by offset from left to right, so that targets after a span-dependent
* instruction whose jump offset operand must be extended can be found quickly
* and adjusted upward (toward higher offsets).
*/
struct JSJumpTarget {
ptrdiff_t offset; /* offset of span-dependent jump target */
int balance; /* AVL tree balance number */
JSJumpTarget *kids[2]; /* left and right AVL tree child pointers */
};
#define JT_LEFT 0
#define JT_RIGHT 1
#define JT_OTHER_DIR(dir) (1 - (dir))
#define JT_IMBALANCE(dir) (((dir) << 1) - 1)
#define JT_DIR(imbalance) (((imbalance) + 1) >> 1)
/*
* Backpatch deltas are encoded in JSSpanDep.target if JT_TAG_BIT is clear,
* so we can maintain backpatch chains when using span dependency records to
* hold jump offsets that overflow 16 bits.
*/
#define JT_TAG_BIT ((jsword) 1)
#define JT_UNTAG_SHIFT 1
#define JT_SET_TAG(jt) ((JSJumpTarget *)((jsword)(jt) | JT_TAG_BIT))
#define JT_CLR_TAG(jt) ((JSJumpTarget *)((jsword)(jt) & ~JT_TAG_BIT))
#define JT_HAS_TAG(jt) ((jsword)(jt) & JT_TAG_BIT)
#define BITS_PER_PTRDIFF (sizeof(ptrdiff_t) * JS_BITS_PER_BYTE)
#define BITS_PER_BPDELTA (BITS_PER_PTRDIFF - 1 - JT_UNTAG_SHIFT)
#define BPDELTA_MAX (((ptrdiff_t)1 << BITS_PER_BPDELTA) - 1)
#define BPDELTA_TO_JT(bp) ((JSJumpTarget *)((bp) << JT_UNTAG_SHIFT))
#define JT_TO_BPDELTA(jt) ((ptrdiff_t)((jsword)(jt) >> JT_UNTAG_SHIFT))
#define SD_SET_TARGET(sd,jt) ((sd)->target = JT_SET_TAG(jt))
#define SD_SET_BPDELTA(sd,bp) ((sd)->target = BPDELTA_TO_JT(bp))
#define SD_GET_BPDELTA(sd) (JS_ASSERT(!JT_HAS_TAG((sd)->target)), \
JT_TO_BPDELTA((sd)->target))
#define SD_TARGET_OFFSET(sd) (JS_ASSERT(JT_HAS_TAG((sd)->target)), \
JT_CLR_TAG((sd)->target)->offset)
struct JSCodeGenerator {
JSTreeContext treeContext; /* base state: statement info stack, etc. */
JSArenaPool *codePool; /* pointer to thread code arena pool */
JSArenaPool *notePool; /* pointer to thread srcnote arena pool */
void *codeMark; /* low watermark in cg->codePool */
void *noteMark; /* low watermark in cg->notePool */
void *tempMark; /* low watermark in cx->tempPool */
struct {
jsbytecode *base; /* base of JS bytecode vector */
jsbytecode *limit; /* one byte beyond end of bytecode */
jsbytecode *next; /* pointer to next free bytecode */
jssrcnote *notes; /* source notes, see below */
uintN noteCount; /* number of source notes so far */
uintN noteMask; /* growth increment for notes */
ptrdiff_t lastNoteOffset; /* code offset for last source note */
uintN currentLine; /* line number for tree-based srcnote gen */
} prolog, main, *current;
const char *filename; /* null or weak link to source filename */
uintN firstLine; /* first line, for js_NewScriptFromCG */
JSPrincipals *principals; /* principals for constant folding eval */
JSAtomList atomList; /* literals indexed for mapping */
intN stackDepth; /* current stack depth in script frame */
uintN maxStackDepth; /* maximum stack depth so far */
JSTryNote *tryBase; /* first exception handling note */
JSTryNote *tryNext; /* next available note */
size_t tryNoteSpace; /* # of bytes allocated at tryBase */
JSSpanDep *spanDeps; /* span dependent instruction records */
JSJumpTarget *jumpTargets; /* AVL tree of jump target offsets */
JSJumpTarget *jtFreeList; /* JT_LEFT-linked list of free structs */
uintN numSpanDeps; /* number of span dependencies */
uintN numJumpTargets; /* number of jump targets */
uintN emitLevel; /* js_EmitTree recursion level */
JSAtomList constList; /* compile time constants */
JSCodeGenerator *parent; /* Enclosing function or global context */
};
#define CG_BASE(cg) ((cg)->current->base)
#define CG_LIMIT(cg) ((cg)->current->limit)
#define CG_NEXT(cg) ((cg)->current->next)
#define CG_CODE(cg,offset) (CG_BASE(cg) + (offset))
#define CG_OFFSET(cg) PTRDIFF(CG_NEXT(cg), CG_BASE(cg), jsbytecode)
#define CG_NOTES(cg) ((cg)->current->notes)
#define CG_NOTE_COUNT(cg) ((cg)->current->noteCount)
#define CG_NOTE_MASK(cg) ((cg)->current->noteMask)
#define CG_LAST_NOTE_OFFSET(cg) ((cg)->current->lastNoteOffset)
#define CG_CURRENT_LINE(cg) ((cg)->current->currentLine)
#define CG_PROLOG_BASE(cg) ((cg)->prolog.base)
#define CG_PROLOG_LIMIT(cg) ((cg)->prolog.limit)
#define CG_PROLOG_NEXT(cg) ((cg)->prolog.next)
#define CG_PROLOG_CODE(cg,poff) (CG_PROLOG_BASE(cg) + (poff))
#define CG_PROLOG_OFFSET(cg) PTRDIFF(CG_PROLOG_NEXT(cg), CG_PROLOG_BASE(cg),\
jsbytecode)
#define CG_SWITCH_TO_MAIN(cg) ((cg)->current = &(cg)->main)
#define CG_SWITCH_TO_PROLOG(cg) ((cg)->current = &(cg)->prolog)
/*
* Initialize cg to allocate bytecode space from codePool, source note space
* from notePool, and all other arena-allocated temporaries from cx->tempPool.
* Return true on success. Report an error and return false if the initial
* code segment can't be allocated.
*/
extern JS_FRIEND_API(JSBool)
js_InitCodeGenerator(JSContext *cx, JSCodeGenerator *cg,
JSArenaPool *codePool, JSArenaPool *notePool,
const char *filename, uintN lineno,
JSPrincipals *principals);
/*
* Release cg->codePool, cg->notePool, and cx->tempPool to marks set by
* js_InitCodeGenerator. Note that cgs are magic: they own the arena pool
* "tops-of-stack" space above their codeMark, noteMark, and tempMark points.
* This means you cannot alloc from tempPool and save the pointer beyond the
* next JS_FinishCodeGenerator.
*/
extern JS_FRIEND_API(void)
js_FinishCodeGenerator(JSContext *cx, JSCodeGenerator *cg);
/*
* Emit one bytecode.
*/
extern ptrdiff_t
js_Emit1(JSContext *cx, JSCodeGenerator *cg, JSOp op);
/*
* Emit two bytecodes, an opcode (op) with a byte of immediate operand (op1).
*/
extern ptrdiff_t
js_Emit2(JSContext *cx, JSCodeGenerator *cg, JSOp op, jsbytecode op1);
/*
* Emit three bytecodes, an opcode with two bytes of immediate operands.
*/
extern ptrdiff_t
js_Emit3(JSContext *cx, JSCodeGenerator *cg, JSOp op, jsbytecode op1,
jsbytecode op2);
/*
* Emit (1 + extra) bytecodes, for N bytes of op and its immediate operand.
*/
extern ptrdiff_t
js_EmitN(JSContext *cx, JSCodeGenerator *cg, JSOp op, size_t extra);
/*
* Unsafe macro to call js_SetJumpOffset and return false if it does.
*/
#define CHECK_AND_SET_JUMP_OFFSET(cx,cg,pc,off) \
JS_BEGIN_MACRO \
if (!js_SetJumpOffset(cx, cg, pc, off)) \
return JS_FALSE; \
JS_END_MACRO
#define CHECK_AND_SET_JUMP_OFFSET_AT(cx,cg,off) \
CHECK_AND_SET_JUMP_OFFSET(cx, cg, CG_CODE(cg,off), CG_OFFSET(cg) - (off))
extern JSBool
js_SetJumpOffset(JSContext *cx, JSCodeGenerator *cg, jsbytecode *pc,
ptrdiff_t off);
/* Test whether we're in a with statement. */
extern JSBool
js_InWithStatement(JSTreeContext *tc);
/* Test whether we're in a catch block with exception named by atom. */
extern JSBool
js_InCatchBlock(JSTreeContext *tc, JSAtom *atom);
/*
* Push the C-stack-allocated struct at stmt onto the stmtInfo stack.
*/
extern void
js_PushStatement(JSTreeContext *tc, JSStmtInfo *stmt, JSStmtType type,
ptrdiff_t top);
/*
* Pop tc->topStmt. If the top JSStmtInfo struct is not stack-allocated, it
* is up to the caller to free it.
*/
extern void
js_PopStatement(JSTreeContext *tc);
/*
* Like js_PopStatement(&cg->treeContext), also patch breaks and continues.
* May fail if a jump offset overflows.
*/
extern JSBool
js_PopStatementCG(JSContext *cx, JSCodeGenerator *cg);
/*
* Define and lookup a primitive jsval associated with the const named by atom.
* js_DefineCompileTimeConstant analyzes the constant-folded initializer at pn
* and saves the const's value in cg->constList, if it can be used at compile
* time. It returns true unless an error occurred.
*
* If the initializer's value could not be saved, js_LookupCompileTimeConstant
* calls will return the undefined value. js_LookupCompileTimeConstant tries
* to find a const value memorized for atom, returning true with *vp set to a
* value other than undefined if the constant was found, true with *vp set to
* JSVAL_VOID if not found, and false on error.
*/
extern JSBool
js_DefineCompileTimeConstant(JSContext *cx, JSCodeGenerator *cg, JSAtom *atom,
JSParseNode *pn);
extern JSBool
js_LookupCompileTimeConstant(JSContext *cx, JSCodeGenerator *cg, JSAtom *atom,
jsval *vp);
/*
* Emit code into cg for the tree rooted at pn.
*/
extern JSBool
js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn);
/*
* Emit code into cg for the tree rooted at body, then create a persistent
* script for fun from cg.
*/
extern JSBool
js_EmitFunctionBody(JSContext *cx, JSCodeGenerator *cg, JSParseNode *body,
JSFunction *fun);
/*
* Source notes generated along with bytecode for decompiling and debugging.
* A source note is a uint8 with 5 bits of type and 3 of offset from the pc of
* the previous note. If 3 bits of offset aren't enough, extended delta notes
* (SRC_XDELTA) consisting of 2 set high order bits followed by 6 offset bits
* are emitted before the next note. Some notes have operand offsets encoded
* immediately after them, in note bytes or byte-triples.
*
* Source Note Extended Delta
* +7-6-5-4-3+2-1-0+ +7-6-5+4-3-2-1-0+
* |note-type|delta| |1 1| ext-delta |
* +---------+-----+ +---+-----------+
*
* At most one "gettable" note (i.e., a note of type other than SRC_NEWLINE,
* SRC_SETLINE, and SRC_XDELTA) applies to a given bytecode.
*
* NB: the js_SrcNoteSpec array in jsemit.c is indexed by this enum, so its
* initializers need to match the order here.
*/
typedef enum JSSrcNoteType {
SRC_NULL = 0, /* terminates a note vector */
SRC_IF = 1, /* JSOP_IFEQ bytecode is from an if-then */
SRC_IF_ELSE = 2, /* JSOP_IFEQ bytecode is from an if-then-else */
SRC_WHILE = 3, /* JSOP_IFEQ is from a while loop */
SRC_FOR = 4, /* JSOP_NOP or JSOP_POP in for loop head */
SRC_CONTINUE = 5, /* JSOP_GOTO is a continue, not a break;
also used on JSOP_ENDINIT if extra comma
at end of array literal: [1,2,,] */
SRC_VAR = 6, /* JSOP_NAME/SETNAME/FORNAME in a var decl */
SRC_PCDELTA = 7, /* offset from comma-operator to next POP,
or from CONDSWITCH to first CASE opcode */
SRC_ASSIGNOP = 8, /* += or another assign-op follows */
SRC_COND = 9, /* JSOP_IFEQ is from conditional ?: operator */
SRC_RESERVED0 = 10, /* reserved for future use */
SRC_HIDDEN = 11, /* opcode shouldn't be decompiled */
SRC_PCBASE = 12, /* offset of first obj.prop.subprop bytecode */
SRC_LABEL = 13, /* JSOP_NOP for label: with atomid immediate */
SRC_LABELBRACE = 14, /* JSOP_NOP for label: {...} begin brace */
SRC_ENDBRACE = 15, /* JSOP_NOP for label: {...} end brace */
SRC_BREAK2LABEL = 16, /* JSOP_GOTO for 'break label' with atomid */
SRC_CONT2LABEL = 17, /* JSOP_GOTO for 'continue label' with atomid */
SRC_SWITCH = 18, /* JSOP_*SWITCH with offset to end of switch,
2nd off to first JSOP_CASE if condswitch */
SRC_FUNCDEF = 19, /* JSOP_NOP for function f() with atomid */
SRC_CATCH = 20, /* catch block has guard */
SRC_CONST = 21, /* JSOP_SETCONST in a const decl */
SRC_NEWLINE = 22, /* bytecode follows a source newline */
SRC_SETLINE = 23, /* a file-absolute source line number note */
SRC_XDELTA = 24 /* 24-31 are for extended delta notes */
} JSSrcNoteType;
#define SN_TYPE_BITS 5
#define SN_DELTA_BITS 3
#define SN_XDELTA_BITS 6
#define SN_TYPE_MASK (JS_BITMASK(SN_TYPE_BITS) << SN_DELTA_BITS)
#define SN_DELTA_MASK ((ptrdiff_t)JS_BITMASK(SN_DELTA_BITS))
#define SN_XDELTA_MASK ((ptrdiff_t)JS_BITMASK(SN_XDELTA_BITS))
#define SN_MAKE_NOTE(sn,t,d) (*(sn) = (jssrcnote) \
(((t) << SN_DELTA_BITS) \
| ((d) & SN_DELTA_MASK)))
#define SN_MAKE_XDELTA(sn,d) (*(sn) = (jssrcnote) \
((SRC_XDELTA << SN_DELTA_BITS) \
| ((d) & SN_XDELTA_MASK)))
#define SN_IS_XDELTA(sn) ((*(sn) >> SN_DELTA_BITS) >= SRC_XDELTA)
#define SN_TYPE(sn) (SN_IS_XDELTA(sn) ? SRC_XDELTA \
: *(sn) >> SN_DELTA_BITS)
#define SN_SET_TYPE(sn,type) SN_MAKE_NOTE(sn, type, SN_DELTA(sn))
#define SN_IS_GETTABLE(sn) (SN_TYPE(sn) < SRC_NEWLINE)
#define SN_DELTA(sn) ((ptrdiff_t)(SN_IS_XDELTA(sn) \
? *(sn) & SN_XDELTA_MASK \
: *(sn) & SN_DELTA_MASK))
#define SN_SET_DELTA(sn,delta) (SN_IS_XDELTA(sn) \
? SN_MAKE_XDELTA(sn, delta) \
: SN_MAKE_NOTE(sn, SN_TYPE(sn), delta))
#define SN_DELTA_LIMIT ((ptrdiff_t)JS_BIT(SN_DELTA_BITS))
#define SN_XDELTA_LIMIT ((ptrdiff_t)JS_BIT(SN_XDELTA_BITS))
/*
* Offset fields follow certain notes and are frequency-encoded: an offset in
* [0,0x7f] consumes one byte, an offset in [0x80,0x7fffff] takes three, and
* the high bit of the first byte is set.
*/
#define SN_3BYTE_OFFSET_FLAG 0x80
#define SN_3BYTE_OFFSET_MASK 0x7f
typedef struct JSSrcNoteSpec {
const char *name; /* name for disassembly/debugging output */
uint8 arity; /* number of offset operands */
uint8 offsetBias; /* bias of offset(s) from annotated pc */
int8 isSpanDep; /* 1 or -1 if offsets could span extended ops,
0 otherwise; sign tells span direction */
} JSSrcNoteSpec;
extern JS_FRIEND_DATA(JSSrcNoteSpec) js_SrcNoteSpec[];
extern JS_FRIEND_API(uintN) js_SrcNoteLength(jssrcnote *sn);
#define SN_LENGTH(sn) ((js_SrcNoteSpec[SN_TYPE(sn)].arity == 0) ? 1 \
: js_SrcNoteLength(sn))
#define SN_NEXT(sn) ((sn) + SN_LENGTH(sn))
/* A source note array is terminated by an all-zero element. */
#define SN_MAKE_TERMINATOR(sn) (*(sn) = SRC_NULL)
#define SN_IS_TERMINATOR(sn) (*(sn) == SRC_NULL)
/*
* Append a new source note of the given type (and therefore size) to cg's
* notes dynamic array, updating cg->noteCount. Return the new note's index
* within the array pointed at by cg->current->notes. Return -1 if out of
* memory.
*/
extern intN
js_NewSrcNote(JSContext *cx, JSCodeGenerator *cg, JSSrcNoteType type);
extern intN
js_NewSrcNote2(JSContext *cx, JSCodeGenerator *cg, JSSrcNoteType type,
ptrdiff_t offset);
extern intN
js_NewSrcNote3(JSContext *cx, JSCodeGenerator *cg, JSSrcNoteType type,
ptrdiff_t offset1, ptrdiff_t offset2);
/*
* NB: this function can add at most one extra extended delta note.
*/
extern jssrcnote *
js_AddToSrcNoteDelta(JSContext *cx, JSCodeGenerator *cg, jssrcnote *sn,
ptrdiff_t delta);
/*
* Get and set the offset operand identified by which (0 for the first, etc.).
*/
extern JS_FRIEND_API(ptrdiff_t)
js_GetSrcNoteOffset(jssrcnote *sn, uintN which);
extern JSBool
js_SetSrcNoteOffset(JSContext *cx, JSCodeGenerator *cg, uintN index,
uintN which, ptrdiff_t offset);
/*
* Finish taking source notes in cx's notePool, copying final notes to the new
* stable store allocated by the caller and passed in via notes. Return false
* on malloc failure, which means this function reported an error.
*
* To compute the number of jssrcnotes to allocate and pass in via notes, use
* the CG_COUNT_FINAL_SRCNOTES macro. This macro knows a lot about details of
* js_FinishTakingSrcNotes, SO DON'T CHANGE jsemit.c's js_FinishTakingSrcNotes
* FUNCTION WITHOUT CHECKING WHETHER THIS MACRO NEEDS CORRESPONDING CHANGES!
*/
#define CG_COUNT_FINAL_SRCNOTES(cg, cnt) \
JS_BEGIN_MACRO \
ptrdiff_t diff_ = CG_PROLOG_OFFSET(cg) - (cg)->prolog.lastNoteOffset; \
cnt = (cg)->prolog.noteCount + (cg)->main.noteCount + 1; \
if ((cg)->prolog.noteCount && \
(cg)->prolog.currentLine != (cg)->firstLine) { \
if (diff_ > SN_DELTA_MASK) \
cnt += JS_HOWMANY(diff_ - SN_DELTA_MASK, SN_XDELTA_MASK); \
cnt += 2 + (((cg)->firstLine > SN_3BYTE_OFFSET_MASK) << 1); \
} else if (diff_ > 0) { \
if (cg->main.noteCount) { \
jssrcnote *sn_ = (cg)->main.notes; \
diff_ -= SN_IS_XDELTA(sn_) \
? SN_XDELTA_MASK - (*sn_ & SN_XDELTA_MASK) \
: SN_DELTA_MASK - (*sn_ & SN_DELTA_MASK); \
} \
if (diff_ > 0) \
cnt += JS_HOWMANY(diff_, SN_XDELTA_MASK); \
} \
JS_END_MACRO
extern JSBool
js_FinishTakingSrcNotes(JSContext *cx, JSCodeGenerator *cg, jssrcnote *notes);
/*
* Allocate cg->treeContext.tryCount notes (plus one for the end sentinel)
* from cx->tempPool and set up cg->tryBase/tryNext for exactly tryCount
* js_NewTryNote calls. The storage is freed by js_FinishCodeGenerator.
*/
extern JSBool
js_AllocTryNotes(JSContext *cx, JSCodeGenerator *cg);
/*
* Grab the next trynote slot in cg, filling it in appropriately.
*/
extern JSTryNote *
js_NewTryNote(JSContext *cx, JSCodeGenerator *cg, ptrdiff_t start,
ptrdiff_t end, ptrdiff_t catchStart);
/*
* Finish generating exception information into the space at notes. As with
* js_FinishTakingSrcNotes, the caller must use CG_COUNT_FINAL_TRYNOTES(cg) to
* preallocate enough space in a JSTryNote[] to pass as the notes parameter of
* js_FinishTakingTryNotes.
*/
#define CG_COUNT_FINAL_TRYNOTES(cg, cnt) \
JS_BEGIN_MACRO \
cnt = ((cg)->tryNext > (cg)->tryBase) \
? PTRDIFF(cg->tryNext, cg->tryBase, JSTryNote) + 1 \
: 0; \
JS_END_MACRO
extern void
js_FinishTakingTryNotes(JSContext *cx, JSCodeGenerator *cg, JSTryNote *notes);
JS_END_EXTERN_C
#endif /* jsemit_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,102 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* JS runtime exception classes.
*/
#ifndef jsexn_h___
#define jsexn_h___
JS_BEGIN_EXTERN_C
/*
* Initialize the exception constructor/prototype hierarchy.
*/
extern JSObject *
js_InitExceptionClasses(JSContext *cx, JSObject *obj);
/*
* String constants naming the exception classes.
*/
extern const char js_Error_str[];
extern const char js_InternalError_str[];
extern const char js_EvalError_str[];
extern const char js_RangeError_str[];
extern const char js_ReferenceError_str[];
extern const char js_SyntaxError_str[];
extern const char js_TypeError_str[];
extern const char js_URIError_str[];
/*
* Given a JSErrorReport, check to see if there is an exception associated with
* the error number. If there is, then create an appropriate exception object,
* set it as the pending exception, and set the JSREPORT_EXCEPTION flag on the
* error report. Exception-aware host error reporters should probably ignore
* error reports so flagged. Returns JS_TRUE if an associated exception is
* found and set, JS_FALSE otherwise..
*/
extern JSBool
js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp);
/*
* Called if a JS API call to js_Execute or js_InternalCall fails; calls the
* error reporter with the error report associated with any uncaught exception
* that has been raised. Returns true if there was an exception pending, and
* the error reporter was actually called.
*
* The JSErrorReport * that the error reporter is called with is currently
* associated with a JavaScript object, and is not guaranteed to persist after
* the object is collected. Any persistent uses of the JSErrorReport contents
* should make their own copy.
*
* The flags field of the JSErrorReport will have the JSREPORT_EXCEPTION flag
* set; embeddings that want to silently propagate JavaScript exceptions to
* other contexts may want to use an error reporter that ignores errors with
* this flag.
*/
extern JSBool
js_ReportUncaughtException(JSContext *cx);
extern JSErrorReport *
js_ErrorFromException(JSContext *cx, jsval exn);
JS_END_EXTERN_C
#endif /* jsexn_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,50 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef _jsfile_h__
#define _jsfile_h__
#if JS_HAS_FILE_OBJECT
extern JS_PUBLIC_API(JSObject*)
js_InitFileClass(JSContext *cx, JSObject* obj, JSBool initStandardStreams);
extern JS_PUBLIC_API(JSObject*)
js_NewFileObject(JSContext *cx, char *bytes);
#endif /* JS_HAS_FILE_OBJECT */
#endif /* _jsfile_h__ */

View File

@@ -1,89 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
Error messages for jsfile.c. See js.msg for format specification.
*/
MSG_DEF(JSFILEMSG_NOT_AN_ERROR, 0, 0, JSEXN_NONE, "<Error #0 is reserved>")
MSG_DEF(JSFILEMSG_FILE_CONSTRUCTOR_UNDEFINED_ERROR, 1, 0, JSEXN_NONE, "File constructor is undefined")
MSG_DEF(JSFILEMSG_FILE_CURRENTDIR_UNDEFINED_ERROR, 2, 0, JSEXN_NONE, "File.currentDir is undefined")
MSG_DEF(JSFILEMSG_FIRST_ARGUMENT_OPEN_NOT_STRING_ERROR, 3, 1, JSEXN_NONE, "The first argument {0} to file.open must be a string")
MSG_DEF(JSFILEMSG_SECOND_ARGUMENT_OPEN_NOT_STRING_ERROR, 4, 0, JSEXN_NONE, "The second argument to file.open must be a string")
MSG_DEF(JSFILEMSG_CANNOT_COPY_FILE_OPEN_FOR_WRITING_ERROR, 5, 1, JSEXN_NONE, "Cannot copy file {0} open for writing")
MSG_DEF(JSFILEMSG_CANNOT_ACCESS_FILE_INFO_ERROR, 6, 1, JSEXN_NONE, "Cannot access file information for {0}")
MSG_DEF(JSFILEMSG_COPY_READ_ERROR, 7, 1, JSEXN_NONE, "An error occured while attempting to read a file {0} to copy")
MSG_DEF(JSFILEMSG_COPY_WRITE_ERROR, 8, 1, JSEXN_NONE, "An error occured while attempting to copy into file {0}")
MSG_DEF(JSFILEMSG_EXPECTS_ONE_ARG_ERROR, 9, 0, JSEXN_NONE, "Operation {0} expects one argument, not {1}")
MSG_DEF(JSFILEMSG_CANNOT_FLUSH_CLOSE_FILE_ERROR, 10, 1, JSEXN_NONE, "Cannot flush closed file {0}")
MSG_DEF(JSFILEMSG_CANNOT_OPEN_WRITING_ERROR, 11, 1, JSEXN_NONE, "Cannot open file {0} for writing")
MSG_DEF(JSFILEMSG_WRITEALL_EXPECTS_ONE_ARG_ERROR, 12, 0, JSEXN_NONE, "writeAll expects one argument")
MSG_DEF(JSFILEMSG_FIRST_ARGUMENT_WRITEALL_NOT_ARRAY_ERROR, 13, 0, JSEXN_NONE, "writeAll expects an array as an argument")
MSG_DEF(JSFILEMSG_CANNOT_OPEN_FILE_ERROR, 15, 1, JSEXN_NONE, "Cannot open file {0}")
MSG_DEF(JSFILEMSG_FIRST_ARGUMENT_CONSTRUCTOR_NOT_STRING_ERROR, 16, 1, JSEXN_NONE, "The argument to the File constructor {0} must be a string")
MSG_DEF(JSFILEMSG_BIDIRECTIONAL_PIPE_NOT_SUPPORTED, 17, 0, JSEXN_NONE, "Bidirectional pipes are not supported")
MSG_DEF(JSFILEMSG_OPEN_MODE_NOT_SUPPORTED_WITH_PIPES, 18, 2, JSEXN_NONE, "The opening mode you have chosen {0} is not supported by the pipe you are trying to open: {1}")
MSG_DEF(JSFILEMSG_OPEN_FAILED, 19, 1, JSEXN_NONE, "open on file {0} failed")
MSG_DEF(JSFILEMSG_CLOSE_FAILED, 20, 1, JSEXN_NONE, "close on file {0} failed")
MSG_DEF(JSFILEMSG_PCLOSE_FAILED, 21, 1, JSEXN_NONE, "pclose on file {0} failed")
MSG_DEF(JSFILEMSG_REMOVE_FAILED, 22, 1, JSEXN_NONE, "remove on file {0} failed")
MSG_DEF(JSFILEMSG_CANNOT_ACCESS_FILE_STATUS, 23, 1, JSEXN_NONE, "Cannot access file status for {0}")
MSG_DEF(JSFILEMSG_RENAME_FAILED, 24, 2, JSEXN_NONE, "Cannot rename {0} to {1}")
MSG_DEF(JSFILEMSG_WRITE_FAILED, 25, 1, JSEXN_NONE, "Write failed on file {0}")
MSG_DEF(JSFILEMSG_READ_FAILED, 26, 1, JSEXN_NONE, "Read failed on file {0}")
MSG_DEF(JSFILEMSG_SKIP_FAILED, 27, 1, JSEXN_NONE, "Skip failed on file {0}")
MSG_DEF(JSFILEMSG_FIRST_ARGUMENT_MUST_BE_A_FUNCTION_OR_REGEX, 28, 1, JSEXN_NONE, "The first argument to file.list must be a function or a regex")
MSG_DEF(JSFILEMSG_CANNOT_DO_LIST_ON_A_FILE, 29, 1, JSEXN_NONE, "{0} must be a directory, cannot do list")
MSG_DEF(JSFILEMSG_NATIVE_OPERATION_IS_NOT_SUPPORTED, 30, 2, JSEXN_NONE, "Native operation {0} is not supported on {1}")
MSG_DEF(JSFILEMSG_CANNOT_SET_PRIVATE_FILE, 31, 1, JSEXN_NONE, "Cannot set private data for file {0}")
MSG_DEF(JSFILEMSG_FIRST_ARGUMENT_MUST_BE_A_NUMBER, 32, 2, JSEXN_NONE, "First argument to {0} must be a number, not {1}")
MSG_DEF(JSFILEMSG_CANNOT_WRITE, 33, 1, JSEXN_NONE, "Cannot write to {0}, file mode is different")
MSG_DEF(JSFILEMSG_CANNOT_READ, 34, 1, JSEXN_NONE, "Cannot read from {0}, file mode is different")
MSG_DEF(JSFILEMSG_CANNOT_FLUSH, 35, 1, JSEXN_NONE, "Flush failed on {0}")
MSG_DEF(JSFILEMSG_OP_FAILED, 36, 1, JSEXN_NONE, "File operation {0} failed")
MSG_DEF(JSFILEMSG_FILE_MUST_BE_OPEN, 37, 1, JSEXN_NONE, "File must be open for {0}")
MSG_DEF(JSFILEMSG_FILE_MUST_BE_CLOSED, 38, 1, JSEXN_NONE, "File must be closed for {0}")
MSG_DEF(JSFILEMSG_NO_RANDOM_ACCESS, 39, 1, JSEXN_NONE, "File {0} doesn't allow random access")
MSG_DEF(JSFILEMSG_OBJECT_CREATION_FAILED, 40, 1, JSEXN_NONE, "Couldn't create {0}")
MSG_DEF(JSFILEMSG_CANNOT_OPEN_DIR, 41, 1, JSEXN_NONE, "Couldn't open directory {0}")
MSG_DEF(JSFILEMSG_CANNOT_REPORT_POSITION, 42, 1, JSEXN_NONE, "Couldn't report position for {0}")
MSG_DEF(JSFILEMSG_CANNOT_SET_POSITION, 43, 1, JSEXN_NONE, "Couldn't set position for {0}")
MSG_DEF(JSFILEMSG_INIT_FAILED, 44, 0, JSEXN_NONE, "File class initialization failed")

File diff suppressed because it is too large Load Diff

View File

@@ -1,158 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsfun_h___
#define jsfun_h___
/*
* JS function definitions.
*/
#include "jsprvtd.h"
#include "jspubtd.h"
JS_BEGIN_EXTERN_C
struct JSFunction {
jsrefcount nrefs; /* number of referencing objects */
JSObject *object; /* back-pointer to GC'ed object header */
union {
JSNative native; /* native method pointer or null */
JSScript *script; /* interpreted bytecode descriptor or null */
} u;
uint16 nargs; /* minimum number of actual arguments */
uint16 extra; /* number of arg slots for local GC roots */
uint16 nvars; /* number of local variables */
uint8 flags; /* bound method and other flags, see jsapi.h */
JSPackedBool interpreted; /* use u.script if true, u.native if false */
uint16 nregexps; /* number of regular expressions literals */
uint16 spare; /* reserved for future use */
JSAtom *atom; /* name for diagnostics and decompiling */
JSClass *clasp; /* if non-null, constructor for this class */
};
#define FUN_NATIVE(fun) ((fun)->interpreted ? NULL : (fun)->u.native)
#define FUN_SCRIPT(fun) ((fun)->interpreted ? (fun)->u.script : NULL)
extern JSClass js_ArgumentsClass;
extern JSClass js_CallClass;
/* JS_FRIEND_DATA so that JSVAL_IS_FUNCTION is callable from outside */
extern JS_FRIEND_DATA(JSClass) js_FunctionClass;
/*
* NB: jsapi.h and jsobj.h must be included before any call to this macro.
*/
#define JSVAL_IS_FUNCTION(cx, v) \
(!JSVAL_IS_PRIMITIVE(v) && \
OBJ_GET_CLASS(cx, JSVAL_TO_OBJECT(v)) == &js_FunctionClass)
extern JSBool
js_fun_toString(JSContext *cx, JSObject *obj, uint32 indent,
uintN argc, jsval *argv, jsval *rval);
extern JSBool
js_IsIdentifier(JSString *str);
extern JSObject *
js_InitFunctionClass(JSContext *cx, JSObject *obj);
extern JSObject *
js_InitArgumentsClass(JSContext *cx, JSObject *obj);
extern JSObject *
js_InitCallClass(JSContext *cx, JSObject *obj);
extern JSFunction *
js_NewFunction(JSContext *cx, JSObject *funobj, JSNative native, uintN nargs,
uintN flags, JSObject *parent, JSAtom *atom);
extern JSObject *
js_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent);
extern JSBool
js_LinkFunctionObject(JSContext *cx, JSFunction *fun, JSObject *object);
extern JSFunction *
js_DefineFunction(JSContext *cx, JSObject *obj, JSAtom *atom, JSNative native,
uintN nargs, uintN flags);
/*
* Flags for js_ValueToFunction and js_ReportIsNotFunction. We depend on the
* fact that JSINVOKE_CONSTRUCT (aka JSFRAME_CONSTRUCTING) is 1, and test that
* with #if/#error in jsfun.c.
*/
#define JSV2F_CONSTRUCT JSINVOKE_CONSTRUCT
#define JSV2F_SEARCH_STACK 2
extern JSFunction *
js_ValueToFunction(JSContext *cx, jsval *vp, uintN flags);
extern void
js_ReportIsNotFunction(JSContext *cx, jsval *vp, uintN flags);
extern JSObject *
js_GetCallObject(JSContext *cx, JSStackFrame *fp, JSObject *parent);
extern JSBool
js_PutCallObject(JSContext *cx, JSStackFrame *fp);
extern JSBool
js_GetCallVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
extern JSBool
js_SetCallVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
extern JSBool
js_GetArgsValue(JSContext *cx, JSStackFrame *fp, jsval *vp);
extern JSBool
js_GetArgsProperty(JSContext *cx, JSStackFrame *fp, jsid id,
JSObject **objp, jsval *vp);
extern JSObject *
js_GetArgsObject(JSContext *cx, JSStackFrame *fp);
extern JSBool
js_PutArgsObject(JSContext *cx, JSStackFrame *fp);
extern JSBool
js_XDRFunction(JSXDRState *xdr, JSObject **objp);
JS_END_EXTERN_C
#endif /* jsfun_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,263 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsgc_h___
#define jsgc_h___
/*
* JS Garbage Collector.
*/
#include "jsprvtd.h"
#include "jspubtd.h"
#include "jsdhash.h"
JS_BEGIN_EXTERN_C
/* GC thing type indexes. */
#define GCX_OBJECT 0 /* JSObject */
#define GCX_STRING 1 /* JSString */
#define GCX_DOUBLE 2 /* jsdouble */
#define GCX_MUTABLE_STRING 3 /* JSString that's mutable --
single-threaded only! */
#define GCX_PRIVATE 4 /* private (unscanned) data */
#define GCX_NAMESPACE 5 /* JSXMLNamespace */
#define GCX_QNAME 6 /* JSXMLQName */
#define GCX_XML 7 /* JSXML */
#define GCX_EXTERNAL_STRING 8 /* JSString w/ external chars */
#define GCX_NTYPES_LOG2 4 /* type index bits */
#define GCX_NTYPES JS_BIT(GCX_NTYPES_LOG2)
/* GC flag definitions, must fit in 8 bits (type index goes in the low bits). */
#define GCF_TYPEMASK JS_BITMASK(GCX_NTYPES_LOG2)
#define GCF_MARK JS_BIT(GCX_NTYPES_LOG2)
#define GCF_FINAL JS_BIT(GCX_NTYPES_LOG2 + 1)
#define GCF_LOCKSHIFT (GCX_NTYPES_LOG2 + 2) /* lock bit shift and mask */
#define GCF_LOCKMASK (JS_BITMASK(8 - GCF_LOCKSHIFT) << GCF_LOCKSHIFT)
#define GCF_LOCK JS_BIT(GCF_LOCKSHIFT) /* lock request bit in API */
/* Pseudo-flag that modifies GCX_STRING to make GCX_MUTABLE_STRING. */
#define GCF_MUTABLE 2
#if (GCX_STRING | GCF_MUTABLE) != GCX_MUTABLE_STRING
# error "mutable string type index botch!"
#endif
extern uint8 *
js_GetGCThingFlags(void *thing);
/* These are compatible with JSDHashEntryStub. */
struct JSGCRootHashEntry {
JSDHashEntryHdr hdr;
void *root;
const char *name;
};
struct JSGCLockHashEntry {
JSDHashEntryHdr hdr;
const JSGCThing *thing;
uint32 count;
};
#if 1
/*
* Since we're forcing a GC from JS_GC anyway, don't bother wasting cycles
* loading oldval. XXX remove implied force, fix jsinterp.c's "second arg
* ignored", etc.
*/
#define GC_POKE(cx, oldval) ((cx)->runtime->gcPoke = JS_TRUE)
#else
#define GC_POKE(cx, oldval) ((cx)->runtime->gcPoke = JSVAL_IS_GCTHING(oldval))
#endif
extern intN
js_ChangeExternalStringFinalizer(JSStringFinalizeOp oldop,
JSStringFinalizeOp newop);
extern JSBool
js_InitGC(JSRuntime *rt, uint32 maxbytes);
extern void
js_FinishGC(JSRuntime *rt);
extern JSBool
js_AddRoot(JSContext *cx, void *rp, const char *name);
extern JSBool
js_AddRootRT(JSRuntime *rt, void *rp, const char *name);
extern JSBool
js_RemoveRoot(JSRuntime *rt, void *rp);
/*
* The private JSGCThing struct, which describes a gcFreeList element.
*/
struct JSGCThing {
JSGCThing *next;
uint8 *flagp;
};
#define GC_NBYTES_MAX (10 * sizeof(JSGCThing))
#define GC_NUM_FREELISTS (GC_NBYTES_MAX / sizeof(JSGCThing))
#define GC_FREELIST_NBYTES(i) (((i) + 1) * sizeof(JSGCThing))
#define GC_FREELIST_INDEX(n) (((n) / sizeof(JSGCThing)) - 1)
extern void *
js_NewGCThing(JSContext *cx, uintN flags, size_t nbytes);
extern JSBool
js_LockGCThing(JSContext *cx, void *thing);
extern JSBool
js_LockGCThingRT(JSRuntime *rt, void *thing);
extern JSBool
js_UnlockGCThingRT(JSRuntime *rt, void *thing);
extern JSBool
js_IsAboutToBeFinalized(JSContext *cx, void *thing);
extern void
js_MarkAtom(JSContext *cx, JSAtom *atom, void *arg);
/* We avoid a large number of unnecessary calls by doing the flag check first */
#define GC_MARK_ATOM(cx, atom, arg) \
JS_BEGIN_MACRO \
if (!((atom)->flags & ATOM_MARK)) \
js_MarkAtom(cx, atom, arg); \
JS_END_MACRO
extern void
js_MarkGCThing(JSContext *cx, void *thing, void *arg);
#ifdef GC_MARK_DEBUG
typedef struct GCMarkNode GCMarkNode;
struct GCMarkNode {
void *thing;
const char *name;
GCMarkNode *next;
GCMarkNode *prev;
};
#define GC_MARK(cx_, thing_, name_, prev_) \
JS_BEGIN_MACRO \
GCMarkNode node_; \
node_.thing = thing_; \
node_.name = name_; \
node_.next = NULL; \
node_.prev = prev_; \
if (prev_) ((GCMarkNode *)(prev_))->next = &node_; \
js_MarkGCThing(cx_, thing_, &node_); \
JS_END_MACRO
#else /* !GC_MARK_DEBUG */
#define GC_MARK(cx, thing, name, prev) js_MarkGCThing(cx, thing, NULL)
#endif /* !GC_MARK_DEBUG */
/*
* Flags to modify how a GC marks and sweeps:
* GC_KEEP_ATOMS Don't sweep unmarked atoms, they may be in use by the
* compiler, or by an API function that calls js_Atomize,
* when the GC is called from js_NewGCThing, due to a
* malloc failure or the runtime GC-thing limit.
* GC_LAST_CONTEXT Called from js_DestroyContext for last JSContext in a
* JSRuntime, when it is imperative that rt->gcPoke gets
* cleared early in js_GC, if it is set.
* GC_ALREADY_LOCKED rt->gcLock is already held on entry to js_GC, and kept
* on return to its caller.
*/
#define GC_KEEP_ATOMS 0x1
#define GC_LAST_CONTEXT 0x2
#define GC_ALREADY_LOCKED 0x4
extern void
js_ForceGC(JSContext *cx, uintN gcflags);
extern void
js_GC(JSContext *cx, uintN gcflags);
#ifdef DEBUG_brendan
#define JS_GCMETER 1
#endif
#ifdef JS_GCMETER
typedef struct JSGCStats {
uint32 alloc; /* number of allocation attempts */
uint32 freelen[GC_NUM_FREELISTS];
/* gcFreeList lengths */
uint32 recycle[GC_NUM_FREELISTS];
/* number of things recycled through gcFreeList */
uint32 retry; /* allocation attempt retries after running the GC */
uint32 retryhalt; /* allocation retries halted by the branch callback */
uint32 fail; /* allocation failures */
uint32 finalfail; /* finalizer calls allocator failures */
uint32 lockborn; /* things born locked */
uint32 lock; /* valid lock calls */
uint32 unlock; /* valid unlock calls */
uint32 stuck; /* stuck reference counts seen by lock calls */
uint32 unstuck; /* unlock calls that saw a stuck lock count */
uint32 depth; /* mark tail recursion depth */
uint32 maxdepth; /* maximum mark tail recursion depth */
uint32 cdepth; /* mark recursion depth of C functions */
uint32 maxcdepth; /* maximum mark recursion depth of C functions */
uint32 dswmark; /* mark C stack overflows => Deutsch-Schorr-Waite */
uint32 dswdepth; /* DSW mark depth */
uint32 maxdswdepth;/* maximum DSW mark depth */
uint32 dswup; /* DSW moves up the mark spanning tree */
uint32 dswupstep; /* steps in obj->slots to find DSW-reversed pointer */
uint32 maxlevel; /* maximum GC nesting (indirect recursion) level */
uint32 poke; /* number of potentially useful GC calls */
uint32 nopoke; /* useless GC calls where js_PokeGC was not set */
uint32 afree; /* thing arenas freed so far */
uint32 stackseg; /* total extraordinary stack segments scanned */
uint32 segslots; /* total stack segment jsval slots scanned */
} JSGCStats;
extern void
js_DumpGCStats(JSRuntime *rt, FILE *fp);
#endif /* JS_GCMETER */
JS_END_EXTERN_C
#endif /* jsgc_h___ */

View File

@@ -1,471 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* PR hash table package.
*/
#include "jsstddef.h"
#include <stdlib.h>
#include <string.h>
#include "jstypes.h"
#include "jsbit.h"
#include "jsutil.h" /* Added by JSIFY */
#include "jshash.h" /* Added by JSIFY */
/* Compute the number of buckets in ht */
#define NBUCKETS(ht) JS_BIT(JS_HASH_BITS - (ht)->shift)
/* The smallest table has 16 buckets */
#define MINBUCKETSLOG2 4
#define MINBUCKETS JS_BIT(MINBUCKETSLOG2)
/* Compute the maximum entries given n buckets that we will tolerate, ~90% */
#define OVERLOADED(n) ((n) - ((n) >> 3))
/* Compute the number of entries below which we shrink the table by half */
#define UNDERLOADED(n) (((n) > MINBUCKETS) ? ((n) >> 2) : 0)
/*
** Stubs for default hash allocator ops.
*/
static void *
DefaultAllocTable(void *pool, size_t size)
{
return malloc(size);
}
static void
DefaultFreeTable(void *pool, void *item)
{
free(item);
}
static JSHashEntry *
DefaultAllocEntry(void *pool, const void *key)
{
return (JSHashEntry*) malloc(sizeof(JSHashEntry));
}
static void
DefaultFreeEntry(void *pool, JSHashEntry *he, uintN flag)
{
if (flag == HT_FREE_ENTRY)
free(he);
}
static JSHashAllocOps defaultHashAllocOps = {
DefaultAllocTable, DefaultFreeTable,
DefaultAllocEntry, DefaultFreeEntry
};
JS_PUBLIC_API(JSHashTable *)
JS_NewHashTable(uint32 n, JSHashFunction keyHash,
JSHashComparator keyCompare, JSHashComparator valueCompare,
JSHashAllocOps *allocOps, void *allocPriv)
{
JSHashTable *ht;
size_t nb;
if (n <= MINBUCKETS) {
n = MINBUCKETSLOG2;
} else {
n = JS_CeilingLog2(n);
if ((int32)n < 0)
return NULL;
}
if (!allocOps) allocOps = &defaultHashAllocOps;
ht = (JSHashTable*) allocOps->allocTable(allocPriv, sizeof *ht);
if (!ht)
return NULL;
memset(ht, 0, sizeof *ht);
ht->shift = JS_HASH_BITS - n;
n = JS_BIT(n);
nb = n * sizeof(JSHashEntry *);
ht->buckets = (JSHashEntry**) allocOps->allocTable(allocPriv, nb);
if (!ht->buckets) {
allocOps->freeTable(allocPriv, ht);
return NULL;
}
memset(ht->buckets, 0, nb);
ht->keyHash = keyHash;
ht->keyCompare = keyCompare;
ht->valueCompare = valueCompare;
ht->allocOps = allocOps;
ht->allocPriv = allocPriv;
return ht;
}
JS_PUBLIC_API(void)
JS_HashTableDestroy(JSHashTable *ht)
{
uint32 i, n;
JSHashEntry *he, **hep;
JSHashAllocOps *allocOps = ht->allocOps;
void *allocPriv = ht->allocPriv;
n = NBUCKETS(ht);
for (i = 0; i < n; i++) {
hep = &ht->buckets[i];
while ((he = *hep) != NULL) {
*hep = he->next;
allocOps->freeEntry(allocPriv, he, HT_FREE_ENTRY);
}
}
#ifdef DEBUG
memset(ht->buckets, 0xDB, n * sizeof ht->buckets[0]);
#endif
allocOps->freeTable(allocPriv, ht->buckets);
#ifdef DEBUG
memset(ht, 0xDB, sizeof *ht);
#endif
allocOps->freeTable(allocPriv, ht);
}
/*
** Multiplicative hash, from Knuth 6.4.
*/
JS_PUBLIC_API(JSHashEntry **)
JS_HashTableRawLookup(JSHashTable *ht, JSHashNumber keyHash, const void *key)
{
JSHashEntry *he, **hep, **hep0;
JSHashNumber h;
#ifdef HASHMETER
ht->nlookups++;
#endif
h = keyHash * JS_GOLDEN_RATIO;
h >>= ht->shift;
hep = hep0 = &ht->buckets[h];
while ((he = *hep) != NULL) {
if (he->keyHash == keyHash && ht->keyCompare(key, he->key)) {
/* Move to front of chain if not already there */
if (hep != hep0) {
*hep = he->next;
he->next = *hep0;
*hep0 = he;
}
return hep0;
}
hep = &he->next;
#ifdef HASHMETER
ht->nsteps++;
#endif
}
return hep;
}
JS_PUBLIC_API(JSHashEntry *)
JS_HashTableRawAdd(JSHashTable *ht, JSHashEntry **hep,
JSHashNumber keyHash, const void *key, void *value)
{
uint32 i, n;
JSHashEntry *he, *next, **oldbuckets;
size_t nb;
/* Grow the table if it is overloaded */
n = NBUCKETS(ht);
if (ht->nentries >= OVERLOADED(n)) {
oldbuckets = ht->buckets;
nb = 2 * n * sizeof(JSHashEntry *);
ht->buckets = (JSHashEntry**)
ht->allocOps->allocTable(ht->allocPriv, nb);
if (!ht->buckets) {
ht->buckets = oldbuckets;
return NULL;
}
memset(ht->buckets, 0, nb);
#ifdef HASHMETER
ht->ngrows++;
#endif
ht->shift--;
for (i = 0; i < n; i++) {
for (he = oldbuckets[i]; he; he = next) {
next = he->next;
hep = JS_HashTableRawLookup(ht, he->keyHash, he->key);
JS_ASSERT(*hep == NULL);
he->next = NULL;
*hep = he;
}
}
#ifdef DEBUG
memset(oldbuckets, 0xDB, n * sizeof oldbuckets[0]);
#endif
ht->allocOps->freeTable(ht->allocPriv, oldbuckets);
hep = JS_HashTableRawLookup(ht, keyHash, key);
}
/* Make a new key value entry */
he = ht->allocOps->allocEntry(ht->allocPriv, key);
if (!he)
return NULL;
he->keyHash = keyHash;
he->key = key;
he->value = value;
he->next = *hep;
*hep = he;
ht->nentries++;
return he;
}
JS_PUBLIC_API(JSHashEntry *)
JS_HashTableAdd(JSHashTable *ht, const void *key, void *value)
{
JSHashNumber keyHash;
JSHashEntry *he, **hep;
keyHash = ht->keyHash(key);
hep = JS_HashTableRawLookup(ht, keyHash, key);
if ((he = *hep) != NULL) {
/* Hit; see if values match */
if (ht->valueCompare(he->value, value)) {
/* key,value pair is already present in table */
return he;
}
if (he->value)
ht->allocOps->freeEntry(ht->allocPriv, he, HT_FREE_VALUE);
he->value = value;
return he;
}
return JS_HashTableRawAdd(ht, hep, keyHash, key, value);
}
JS_PUBLIC_API(void)
JS_HashTableRawRemove(JSHashTable *ht, JSHashEntry **hep, JSHashEntry *he)
{
uint32 i, n;
JSHashEntry *next, **oldbuckets;
size_t nb;
*hep = he->next;
ht->allocOps->freeEntry(ht->allocPriv, he, HT_FREE_ENTRY);
/* Shrink table if it's underloaded */
n = NBUCKETS(ht);
if (--ht->nentries < UNDERLOADED(n)) {
oldbuckets = ht->buckets;
nb = n * sizeof(JSHashEntry*) / 2;
ht->buckets = (JSHashEntry**)
ht->allocOps->allocTable(ht->allocPriv, nb);
if (!ht->buckets) {
ht->buckets = oldbuckets;
return;
}
memset(ht->buckets, 0, nb);
#ifdef HASHMETER
ht->nshrinks++;
#endif
ht->shift++;
for (i = 0; i < n; i++) {
for (he = oldbuckets[i]; he; he = next) {
next = he->next;
hep = JS_HashTableRawLookup(ht, he->keyHash, he->key);
JS_ASSERT(*hep == NULL);
he->next = NULL;
*hep = he;
}
}
#ifdef DEBUG
memset(oldbuckets, 0xDB, n * sizeof oldbuckets[0]);
#endif
ht->allocOps->freeTable(ht->allocPriv, oldbuckets);
}
}
JS_PUBLIC_API(JSBool)
JS_HashTableRemove(JSHashTable *ht, const void *key)
{
JSHashNumber keyHash;
JSHashEntry *he, **hep;
keyHash = ht->keyHash(key);
hep = JS_HashTableRawLookup(ht, keyHash, key);
if ((he = *hep) == NULL)
return JS_FALSE;
/* Hit; remove element */
JS_HashTableRawRemove(ht, hep, he);
return JS_TRUE;
}
JS_PUBLIC_API(void *)
JS_HashTableLookup(JSHashTable *ht, const void *key)
{
JSHashNumber keyHash;
JSHashEntry *he, **hep;
keyHash = ht->keyHash(key);
hep = JS_HashTableRawLookup(ht, keyHash, key);
if ((he = *hep) != NULL) {
return he->value;
}
return NULL;
}
/*
** Iterate over the entries in the hash table calling func for each
** entry found. Stop if "f" says to (return value & JS_ENUMERATE_STOP).
** Return a count of the number of elements scanned.
*/
JS_PUBLIC_API(int)
JS_HashTableEnumerateEntries(JSHashTable *ht, JSHashEnumerator f, void *arg)
{
JSHashEntry *he, **hep;
uint32 i, nbuckets;
int rv, n = 0;
JSHashEntry *todo = NULL;
nbuckets = NBUCKETS(ht);
for (i = 0; i < nbuckets; i++) {
hep = &ht->buckets[i];
while ((he = *hep) != NULL) {
rv = f(he, n, arg);
n++;
if (rv & (HT_ENUMERATE_REMOVE | HT_ENUMERATE_UNHASH)) {
*hep = he->next;
if (rv & HT_ENUMERATE_REMOVE) {
he->next = todo;
todo = he;
}
} else {
hep = &he->next;
}
if (rv & HT_ENUMERATE_STOP) {
goto out;
}
}
}
out:
hep = &todo;
while ((he = *hep) != NULL) {
JS_HashTableRawRemove(ht, hep, he);
}
return n;
}
#ifdef HASHMETER
#include <math.h>
#include <stdio.h>
JS_PUBLIC_API(void)
JS_HashTableDumpMeter(JSHashTable *ht, JSHashEnumerator dump, FILE *fp)
{
double sqsum, mean, variance, sigma;
uint32 nchains, nbuckets, nentries;
uint32 i, n, maxChain, maxChainLen;
JSHashEntry *he;
sqsum = 0;
nchains = 0;
maxChainLen = 0;
nbuckets = NBUCKETS(ht);
for (i = 0; i < nbuckets; i++) {
he = ht->buckets[i];
if (!he)
continue;
nchains++;
for (n = 0; he; he = he->next)
n++;
sqsum += n * n;
if (n > maxChainLen) {
maxChainLen = n;
maxChain = i;
}
}
nentries = ht->nentries;
mean = (double)nentries / nchains;
variance = nchains * sqsum - nentries * nentries;
if (variance < 0 || nchains == 1)
variance = 0;
else
variance /= nchains * (nchains - 1);
sigma = sqrt(variance);
fprintf(fp, "\nHash table statistics:\n");
fprintf(fp, " number of lookups: %u\n", ht->nlookups);
fprintf(fp, " number of entries: %u\n", ht->nentries);
fprintf(fp, " number of grows: %u\n", ht->ngrows);
fprintf(fp, " number of shrinks: %u\n", ht->nshrinks);
fprintf(fp, " mean steps per hash: %g\n", (double)ht->nsteps
/ ht->nlookups);
fprintf(fp, "mean hash chain length: %g\n", mean);
fprintf(fp, " standard deviation: %g\n", sigma);
fprintf(fp, " max hash chain length: %u\n", maxChainLen);
fprintf(fp, " max hash chain: [%u]\n", maxChain);
for (he = ht->buckets[maxChain], i = 0; he; he = he->next, i++)
if (dump(he, i, fp) != HT_ENUMERATE_NEXT)
break;
}
#endif /* HASHMETER */
JS_PUBLIC_API(int)
JS_HashTableDump(JSHashTable *ht, JSHashEnumerator dump, FILE *fp)
{
int count;
count = JS_HashTableEnumerateEntries(ht, dump, fp);
#ifdef HASHMETER
JS_HashTableDumpMeter(ht, dump, fp);
#endif
return count;
}
JS_PUBLIC_API(JSHashNumber)
JS_HashString(const void *key)
{
JSHashNumber h;
const unsigned char *s;
h = 0;
for (s = (const unsigned char *)key; *s; s++)
h = (h >> (JS_HASH_BITS - 4)) ^ (h << 4) ^ *s;
return h;
}
JS_PUBLIC_API(int)
JS_CompareValues(const void *v1, const void *v2)
{
return v1 == v2;
}

View File

@@ -1,152 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jshash_h___
#define jshash_h___
/*
* API to portable hash table code.
*/
#include <stddef.h>
#include <stdio.h>
#include "jstypes.h"
#include "jscompat.h"
JS_BEGIN_EXTERN_C
typedef uint32 JSHashNumber;
typedef struct JSHashEntry JSHashEntry;
typedef struct JSHashTable JSHashTable;
#define JS_HASH_BITS 32
#define JS_GOLDEN_RATIO 0x9E3779B9U
typedef JSHashNumber (* JS_DLL_CALLBACK JSHashFunction)(const void *key);
typedef intN (* JS_DLL_CALLBACK JSHashComparator)(const void *v1, const void *v2);
typedef intN (* JS_DLL_CALLBACK JSHashEnumerator)(JSHashEntry *he, intN i, void *arg);
/* Flag bits in JSHashEnumerator's return value */
#define HT_ENUMERATE_NEXT 0 /* continue enumerating entries */
#define HT_ENUMERATE_STOP 1 /* stop enumerating entries */
#define HT_ENUMERATE_REMOVE 2 /* remove and free the current entry */
#define HT_ENUMERATE_UNHASH 4 /* just unhash the current entry */
typedef struct JSHashAllocOps {
void * (*allocTable)(void *pool, size_t size);
void (*freeTable)(void *pool, void *item);
JSHashEntry * (*allocEntry)(void *pool, const void *key);
void (*freeEntry)(void *pool, JSHashEntry *he, uintN flag);
} JSHashAllocOps;
#define HT_FREE_VALUE 0 /* just free the entry's value */
#define HT_FREE_ENTRY 1 /* free value and entire entry */
struct JSHashEntry {
JSHashEntry *next; /* hash chain linkage */
JSHashNumber keyHash; /* key hash function result */
const void *key; /* ptr to opaque key */
void *value; /* ptr to opaque value */
};
struct JSHashTable {
JSHashEntry **buckets; /* vector of hash buckets */
uint32 nentries; /* number of entries in table */
uint32 shift; /* multiplicative hash shift */
JSHashFunction keyHash; /* key hash function */
JSHashComparator keyCompare; /* key comparison function */
JSHashComparator valueCompare; /* value comparison function */
JSHashAllocOps *allocOps; /* allocation operations */
void *allocPriv; /* allocation private data */
#ifdef HASHMETER
uint32 nlookups; /* total number of lookups */
uint32 nsteps; /* number of hash chains traversed */
uint32 ngrows; /* number of table expansions */
uint32 nshrinks; /* number of table contractions */
#endif
};
/*
* Create a new hash table.
* If allocOps is null, use default allocator ops built on top of malloc().
*/
extern JS_PUBLIC_API(JSHashTable *)
JS_NewHashTable(uint32 n, JSHashFunction keyHash,
JSHashComparator keyCompare, JSHashComparator valueCompare,
JSHashAllocOps *allocOps, void *allocPriv);
extern JS_PUBLIC_API(void)
JS_HashTableDestroy(JSHashTable *ht);
/* Low level access methods */
extern JS_PUBLIC_API(JSHashEntry **)
JS_HashTableRawLookup(JSHashTable *ht, JSHashNumber keyHash, const void *key);
extern JS_PUBLIC_API(JSHashEntry *)
JS_HashTableRawAdd(JSHashTable *ht, JSHashEntry **hep, JSHashNumber keyHash,
const void *key, void *value);
extern JS_PUBLIC_API(void)
JS_HashTableRawRemove(JSHashTable *ht, JSHashEntry **hep, JSHashEntry *he);
/* Higher level access methods */
extern JS_PUBLIC_API(JSHashEntry *)
JS_HashTableAdd(JSHashTable *ht, const void *key, void *value);
extern JS_PUBLIC_API(JSBool)
JS_HashTableRemove(JSHashTable *ht, const void *key);
extern JS_PUBLIC_API(intN)
JS_HashTableEnumerateEntries(JSHashTable *ht, JSHashEnumerator f, void *arg);
extern JS_PUBLIC_API(void *)
JS_HashTableLookup(JSHashTable *ht, const void *key);
extern JS_PUBLIC_API(intN)
JS_HashTableDump(JSHashTable *ht, JSHashEnumerator dump, FILE *fp);
/* General-purpose C string hash function. */
extern JS_PUBLIC_API(JSHashNumber)
JS_HashString(const void *key);
/* Stub function just returns v1 == v2 */
extern JS_PUBLIC_API(intN)
JS_CompareValues(const void *v1, const void *v2);
JS_END_EXTERN_C
#endif /* jshash_h___ */

View File

@@ -1,485 +0,0 @@
#!/usr/local/bin/perl
# This script modifies C code to use the hijacked NSPR routines that are
# now baked into the JavaScript engine rather than using the NSPR
# routines that they were based on, i.e. types like PRArenaPool are changed
# to JSArenaPool.
#
# This script was used in 9/98 to facilitate the incorporation of some NSPR
# code into the JS engine so as to minimize dependency on NSPR.
#
# Command-line: jsify.pl [options] [filename]*
#
# Options:
# -r Reverse direction of transformation, i.e. JS ==> NSPR2
# -outdir Directory in which to place output files
# NSPR2 symbols that will be modified to JS symbols, e.g.
# PRArena <==> JSArena
@NSPR_symbols = (
"PRArena",
"PRArenaPool",
"PRArenaStats",
"PR_ARENAMETER",
"PR_ARENA_",
"PR_ARENA_ALIGN",
"PR_ARENA_ALLOCATE",
"PR_ARENA_CONST_ALIGN_MASK",
"PR_ARENA_DEFAULT_ALIGN",
"PR_ARENA_DESTROY",
"PR_ARENA_GROW",
"PR_ARENA_MARK",
"PR_ARENA_RELEASE",
"PR_smprintf",
"PR_smprintf_free",
"PR_snprintf",
"PR_sprintf_append",
"PR_sscanf",
"PR_sxprintf",
"PR_vsmprintf",
"PR_vsnprintf",
"PR_vsprintf_append",
"PR_vsxprintf",
"PRCList",
"PRCListStr",
"PRCLists",
"PRDestroyEventProc",
"PREvent",
"PREventFunProc",
"PREventQueue",
"PRHandleEventProc",
"PR_PostEvent",
"PR_PostSynchronousEvent",
"PR_ProcessPendingEvents",
"PR_CreateEventQueue",
"PR_DequeueEvent",
"PR_DestroyEvent",
"PR_DestroyEventQueue",
"PR_EventAvailable",
"PR_EventLoop",
"PR_GetEvent",
"PR_GetEventOwner",
"PR_GetEventQueueMonitor",
"PR_GetEventQueueSelectFD",
"PR_GetMainEventQueue",
"PR_HandleEvent",
"PR_InitEvent",
"PR_ENTER_EVENT_QUEUE_MONITOR",
"PR_EXIT_EVENT_QUEUE_MONITOR",
"PR_MapEvents",
"PR_RevokeEvents",
"PR_cnvtf",
"PR_dtoa",
"PR_strtod",
"PRFileDesc",
"PR_HASH_BITS",
"PR_GOLDEN_RATIO",
"PRHashAllocOps",
"PRHashComparator",
"PRHashEntry",
"PRHashEnumerator",
"PRHashFunction",
"PRHashNumber",
"PRHashTable",
"PR_HashString",
"PR_HashTableAdd",
"PR_HashTableDestroy",
"PR_HashTableDump",
"PR_HashTableEnumerateEntries",
"PR_HashTableLookup",
"PR_HashTableRawAdd",
"PR_HashTableRawLookup",
"PR_HashTableRawRemove",
"PR_HashTableRemove",
"PRBool",
"PRFloat64",
"PRInt16",
"PRInt32",
"PRInt64",
"PRInt8",
"PRIntn",
"PRUint16",
"PRUint32",
"PRUint64",
"PRUint8",
"PRUintn",
"PRPtrDiff",
"PRPtrdiff",
"PRUptrdiff",
"PRUword",
"PRWord",
"PRPackedBool",
"PRSize",
"PRStatus",
"pruword",
"prword",
"prword_t",
"PR_ALIGN_OF_DOUBLE",
"PR_ALIGN_OF_FLOAT",
"PR_ALIGN_OF_INT",
"PR_ALIGN_OF_INT64",
"PR_ALIGN_OF_LONG",
"PR_ALIGN_OF_POINTER",
"PR_ALIGN_OF_SHORT",
"PR_ALIGN_OF_WORD",
"PR_BITS_PER_BYTE",
"PR_BITS_PER_BYTE_LOG2",
"PR_BITS_PER_DOUBLE",
"PR_BITS_PER_DOUBLE_LOG2",
"PR_BITS_PER_FLOAT",
"PR_BITS_PER_FLOAT_LOG2",
"PR_BITS_PER_INT",
"PR_BITS_PER_INT64",
"PR_BITS_PER_INT64_LOG2",
"PR_BITS_PER_INT_LOG2",
"PR_BITS_PER_LONG",
"PR_BITS_PER_LONG_LOG2",
"PR_BITS_PER_SHORT",
"PR_BITS_PER_SHORT_LOG2",
"PR_BITS_PER_WORD",
"PR_BITS_PER_WORD_LOG2",
"PR_BYTES_PER_BYTE",
"PR_BYTES_PER_DOUBLE",
"PR_BYTES_PER_DWORD",
"PR_BYTES_PER_DWORD_LOG2",
"PR_BYTES_PER_FLOAT",
"PR_BYTES_PER_INT",
"PR_BYTES_PER_INT64",
"PR_BYTES_PER_LONG",
"PR_BYTES_PER_SHORT",
"PR_BYTES_PER_WORD",
"PR_BYTES_PER_WORD_LOG2",
"PRSegment",
"PRSegmentAccess",
"PRStuffFunc",
"PRThread",
"PR_APPEND_LINK",
"PR_ASSERT",
"PR_ATOMIC_DWORD_LOAD",
"PR_ATOMIC_DWORD_STORE",
"PR_Abort",
"PR_ArenaAllocate",
"PR_ArenaCountAllocation",
"PR_ArenaCountGrowth",
"PR_ArenaCountInplaceGrowth",
"PR_ArenaCountRelease",
"PR_ArenaCountRetract",
"PR_ArenaFinish",
"PR_ArenaGrow",
"PR_ArenaRelease",
"PR_CompactArenaPool",
"PR_DumpArenaStats",
"PR_FinishArenaPool",
"PR_FreeArenaPool",
"PR_InitArenaPool",
"PR_Assert",
"PR_AttachThread",
"PR_BEGIN_EXTERN_C",
"PR_BEGIN_MACRO",
"PR_BIT",
"PR_BITMASK",
"PR_BUFFER_OVERFLOW_ERROR",
"PR_CALLBACK",
"PR_CALLBACK_DECL",
"PR_CALLOC",
"PR_CEILING_LOG2",
"PR_CLEAR_ARENA",
"PR_CLEAR_BIT",
"PR_CLEAR_UNUSED",
"PR_CLIST_IS_EMPTY",
"PR_COUNT_ARENA",
"PR_CURRENT_THREAD",
"PR_GetSegmentAccess",
"PR_GetSegmentSize",
"PR_GetSegmentVaddr",
"PR_GrowSegment",
"PR_DestroySegment",
"PR_MapSegment",
"PR_NewSegment",
"PR_Segment",
"PR_Seg",
"PR_SEGMENT_NONE",
"PR_SEGMENT_RDONLY",
"PR_SEGMENT_RDWR",
"PR_Calloc",
"PR_CeilingLog2",
"PR_CompareStrings",
"PR_CompareValues",
"PR_DELETE",
"PR_END_EXTERN_C",
"PR_END_MACRO",
"PR_ENUMERATE_STOP",
"PR_FAILURE",
"PR_FALSE",
"PR_FLOOR_LOG2",
"PR_FREEIF",
"PR_FREE_PATTERN",
"PR_FloorLog2",
"PR_FormatTime",
"PR_Free",
"PR_GetEnv",
"PR_GetError",
"PR_INIT_ARENA_POOL",
"PR_INIT_CLIST",
"PR_INIT_STATIC_CLIST",
"PR_INLINE",
"PR_INSERT_AFTER",
"PR_INSERT_BEFORE",
"PR_INSERT_LINK",
"PR_INT32",
"PR_INTERVAL_NO_TIMEOUT",
"PR_INTERVAL_NO_WAIT",
"PR_Init",
"PR_LIST_HEAD",
"PR_LIST_TAIL",
"PR_LOG",
"PR_LOGGING",
"PR_LOG_ALWAYS",
"PR_LOG_BEGIN",
"PR_LOG_DEBUG",
"PR_LOG_DEFINE",
"PR_LOG_END",
"PR_LOG_ERROR",
"PR_LOG_MAX",
"PR_LOG_MIN",
"PR_LOG_NONE",
"PR_LOG_NOTICE",
"PR_LOG_TEST",
"PR_LOG_WARN",
"PR_LOG_WARNING",
"PR_LogFlush",
"PR_LogPrint",
"PR_MALLOC",
"PR_MAX",
"PR_MD_calloc",
"PR_MD_free",
"PR_MD_malloc",
"PR_MD_realloc",
"PR_MIN",
"PR_Malloc",
"PR_NEW",
"PR_NEWZAP",
"PR_NEXT_LINK",
"PR_NOT_REACHED",
"PR_NewCondVar",
"PR_NewHashTable",
"PR_NewLogModule",
"PR_PREV_LINK",
"PR_PUBLIC_API",
"PR_PUBLIC_DATA",
"PR_RANGE_ERROR",
"PR_REALLOC",
"PR_REMOVE_AND_INIT_LINK",
"PR_REMOVE_LINK",
"PR_ROUNDUP",
"PR_Realloc",
"PR_SET_BIT",
"PR_STATIC_CALLBACK",
"PR_SUCCESS",
"PR_SetError",
"PR_SetLogBuffering",
"PR_SetLogFile",
"PR_TEST_BIT",
"PR_TRUE",
"PR_UINT32",
"PR_UPTRDIFF",
"prarena_h___",
"prbit_h___",
"prclist_h___",
"prdtoa_h___",
"prlog_h___",
"prlong_h___",
"prmacos_h___",
"prmem_h___",
"prprf_h___",
"prtypes_h___",
"prarena",
"prbit",
"prbitmap_t",
"prclist",
"prcpucfg",
"prdtoa",
"prhash",
"plhash",
"prlong",
"prmacos",
"prmem",
"prosdep",
"protypes",
"prprf",
"prtypes"
);
while ($ARGV[0] =~ /^-/) {
if ($ARGV[0] eq "-r") {
shift;
$reverse_conversion = 1;
} elsif ($ARGV[0] eq "-outdir") {
shift;
$outdir = shift;
}
}
# Given an NSPR symbol compute the JS equivalent or
# vice-versa
sub subst {
local ($replacement);
local ($sym) = @_;
$replacement = substr($sym,0,2) eq "pr" ? "js" : "JS";
$replacement .= substr($sym, 2);
return $replacement;
}
# Build the regular expression that will convert between the NSPR
# types and the JS types
if ($reverse_conversion) {
die "Not implemented yet";
} else {
foreach $sym (@NSPR_symbols) {
$regexp .= $sym . "|"
}
# Get rid of the last "!"
chop $regexp;
# Replace PR* with JS* and replace pr* with js*
$regexp = 's/(^|\\W)(' . $regexp . ')/$1 . &subst($2)/eg';
# print $regexp;
}
# Pre-compile a little subroutine to perform the regexp substitution
# between NSPR types and JS types
eval('sub convert_from_NSPR {($line) = @_; $line =~ ' . $regexp . ';}');
sub convert_mallocs {
($line) = @_;
$line =~ s/PR_MALLOC/malloc/g;
$line =~ s/PR_REALLOC/realloc/g;
$line =~ s/PR_FREE/free/g;
return $line;
}
sub convert_includes {
($line) = @_;
if ($line !~ /include/) {
return $line;
}
if ($line =~ /prlog\.h/) {
$line = '#include "jsutil.h"'. " /* Added by JSIFY */\n";
} elsif ($line =~ /plhash\.h/) {
$line = '#include "jshash.h"'. " /* Added by JSIFY */\n";
} elsif ($line =~ /plarena\.h/) {
$line = '#include "jsarena.h"'. " /* Added by JSIFY */\n";
} elsif ($line =~ /prmem\.h/) {
$line = "";
} elsif ($line =~ /jsmsg\.def/) {
$line = '#include "js.msg"' . "\n";
} elsif ($line =~ /shellmsg\.def/) {
$line = '#include "jsshell.msg"' . "\n";
} elsif ($line =~ /jsopcode\.def/) {
$line = '#include "jsopcode.tbl"' . "\n";
}
return $line;
}
sub convert_declarations {
($line) = @_;
$line =~ s/PR_EXTERN/JS_EXTERN_API/g;
$line =~ s/PR_IMPLEMENT_DATA/JS_EXPORT_DATA/g;
$line =~ s/PR_IMPLEMENT/JS_EXPORT_API/g;
$line =~ s/PR_CALLBACK/JS_DLL_CALLBACK/g;
$line =~ s/PR_STATIC_CALLBACK/JS_STATIC_DLL_CALLBACK/g;
$line =~ s/PR_IMPORT/JS_IMPORT/g;
$line =~ s/PR_PUBLIC_API/JS_EXPORT_API/g;
$line =~ s/PR_PUBLIC_DATA/JS_EXPORT_DATA/g;
return $line;
}
sub convert_long_long_macros {
($line) = @_;
$line =~ s/\b(LL_)/JSLL_/g;
return $line;
}
sub convert_asserts {
($line) = @_;
$line =~ s/\bPR_ASSERT/JS_ASSERT/g;
return $line;
}
while ($#ARGV >= 0) {
$infile = shift;
# Change filename, e.g. prtime.h to jsprtime.h, except for legacy
# files that start with 'prmj', like prmjtime.h.
$outfile = $infile;
if ($infile !~ /^prmj/) {
$outfile =~ s/^pr/js/;
$outfile =~ s/^pl/js/;
}
if ($outdir) {
$outfile = $outdir . '/' . $outfile;
}
if ($infile eq $outfile) {
die "Error: refuse to overwrite $outfile, use -outdir option."
}
die "Can't open $infile" if !open(INFILE, "<$infile");
die "Can't open $outfile for writing" if !open(OUTFILE, ">$outfile");
while (<INFILE>) {
$line = $_;
#Get rid of #include "prlog.h"
&convert_includes($line);
# Rename PR_EXTERN, PR_IMPORT, etc.
&convert_declarations($line);
# Convert from PR_MALLOC to malloc, etc.
&convert_mallocs($line);
# Convert from PR_ASSERT to JS_ASSERT
# &convert_asserts($line);
# Convert from, e.g. PRArena to JSPRArena
&convert_from_NSPR($line);
# Change LL_* macros to JSLL_*
&convert_long_long_macros($line);
print OUTFILE $line;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,304 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsinterp_h___
#define jsinterp_h___
/*
* JS interpreter interface.
*/
#include "jsprvtd.h"
#include "jspubtd.h"
JS_BEGIN_EXTERN_C
/*
* JS stack frame, allocated on the C stack.
*/
struct JSStackFrame {
JSObject *callobj; /* lazily created Call object */
JSObject *argsobj; /* lazily created arguments object */
JSObject *varobj; /* variables object, where vars go */
JSScript *script; /* script being interpreted */
JSFunction *fun; /* function being called or null */
JSObject *thisp; /* "this" pointer if in method */
uintN argc; /* actual argument count */
jsval *argv; /* base of argument stack slots */
jsval rval; /* function return value */
uintN nvars; /* local variable count */
jsval *vars; /* base of variable stack slots */
JSStackFrame *down; /* previous frame */
void *annotation; /* used by Java security */
JSObject *scopeChain; /* scope chain */
jsbytecode *pc; /* program counter */
jsval *sp; /* stack pointer */
jsval *spbase; /* operand stack base */
uintN sharpDepth; /* array/object initializer depth */
JSObject *sharpArray; /* scope for #n= initializer vars */
uint32 flags; /* frame flags -- see below */
JSStackFrame *dormantNext; /* next dormant frame chain */
JSObject *xmlNamespace; /* null or default xml namespace in E4X */
};
typedef struct JSInlineFrame {
JSStackFrame frame; /* base struct */
void *mark; /* mark before inline frame */
void *hookData; /* debugger call hook data */
JSVersion callerVersion; /* dynamic version of calling script */
} JSInlineFrame;
/* JS stack frame flags. */
#define JSFRAME_CONSTRUCTING 0x01 /* frame is for a constructor invocation */
#define JSFRAME_INTERNAL 0x02 /* internal call, not invoked by a script */
#define JSFRAME_SKIP_CALLER 0x04 /* skip one link when evaluating f.caller
for this invocation of f */
#define JSFRAME_ASSIGNING 0x08 /* a complex (not simplex JOF_ASSIGNING) op
is currently assigning to a property */
#define JSFRAME_DEBUGGER 0x10 /* frame for JS_EvaluateInStackFrame */
#define JSFRAME_EVAL 0x20 /* frame for obj_eval */
#define JSFRAME_SPECIAL 0x30 /* special evaluation frame flags */
#define JSFRAME_COMPILING 0x40 /* frame is being used by compiler */
#define JSFRAME_COMPILE_N_GO 0x80 /* compiler-and-go mode, can optimize name
references based on scope chain */
#define JSFRAME_OVERRIDE_SHIFT 24 /* override bit-set params; see jsfun.c */
#define JSFRAME_OVERRIDE_BITS 8
/*
* Property cache for quickened get/set property opcodes.
*/
#define PROPERTY_CACHE_LOG2 10
#define PROPERTY_CACHE_SIZE JS_BIT(PROPERTY_CACHE_LOG2)
#define PROPERTY_CACHE_MASK JS_BITMASK(PROPERTY_CACHE_LOG2)
#define PROPERTY_CACHE_HASH(obj, id) \
((((jsuword)(obj) >> JSVAL_TAGBITS) ^ (jsuword)(id)) & PROPERTY_CACHE_MASK)
#ifdef JS_THREADSAFE
#if HAVE_ATOMIC_DWORD_ACCESS
#define PCE_LOAD(cache, pce, entry) JS_ATOMIC_DWORD_LOAD(pce, entry)
#define PCE_STORE(cache, pce, entry) JS_ATOMIC_DWORD_STORE(pce, entry)
#else /* !HAVE_ATOMIC_DWORD_ACCESS */
#define JS_PROPERTY_CACHE_METERING 1
#define PCE_LOAD(cache, pce, entry) \
JS_BEGIN_MACRO \
uint32 prefills_; \
uint32 fills_ = (cache)->fills; \
do { \
/* Load until cache->fills is stable (see FILL macro below). */ \
prefills_ = fills_; \
(entry) = *(pce); \
} while ((fills_ = (cache)->fills) != prefills_); \
JS_END_MACRO
#define PCE_STORE(cache, pce, entry) \
JS_BEGIN_MACRO \
do { \
/* Store until no racing collider stores half or all of pce. */ \
*(pce) = (entry); \
} while (PCE_OBJECT(*pce) != PCE_OBJECT(entry) || \
PCE_PROPERTY(*pce) != PCE_PROPERTY(entry)); \
JS_END_MACRO
#endif /* !HAVE_ATOMIC_DWORD_ACCESS */
#else /* !JS_THREADSAFE */
#define PCE_LOAD(cache, pce, entry) ((entry) = *(pce))
#define PCE_STORE(cache, pce, entry) (*(pce) = (entry))
#endif /* !JS_THREADSAFE */
typedef union JSPropertyCacheEntry {
struct {
JSObject *object; /* weak link to object */
JSScopeProperty *property; /* weak link to property */
} s;
#ifdef HAVE_ATOMIC_DWORD_ACCESS
prdword align;
#endif
} JSPropertyCacheEntry;
/* These may be called in lvalue or rvalue position. */
#define PCE_OBJECT(entry) ((entry).s.object)
#define PCE_PROPERTY(entry) ((entry).s.property)
typedef struct JSPropertyCache {
JSPropertyCacheEntry table[PROPERTY_CACHE_SIZE];
JSBool empty;
JSBool disabled;
#ifdef JS_PROPERTY_CACHE_METERING
uint32 fills;
uint32 recycles;
uint32 tests;
uint32 misses;
uint32 flushes;
# define PCMETER(x) x
#else
# define PCMETER(x) /* nothing */
#endif
} JSPropertyCache;
#define PROPERTY_CACHE_FILL(cache, obj, id, sprop) \
JS_BEGIN_MACRO \
JSPropertyCache *cache_ = (cache); \
if (!cache_->disabled) { \
uintN hashIndex_ = (uintN) PROPERTY_CACHE_HASH(obj, id); \
JSPropertyCacheEntry *pce_ = &cache_->table[hashIndex_]; \
JSPropertyCacheEntry entry_; \
JSScopeProperty *pce_sprop_; \
PCE_LOAD(cache_, pce_, entry_); \
pce_sprop_ = PCE_PROPERTY(entry_); \
PCMETER(if (pce_sprop_ && pce_sprop_ != sprop) \
cache_->recycles++); \
PCE_OBJECT(entry_) = obj; \
PCE_PROPERTY(entry_) = sprop; \
cache_->empty = JS_FALSE; \
PCMETER(cache_->fills++); \
PCE_STORE(cache_, pce_, entry_); \
} \
JS_END_MACRO
#define PROPERTY_CACHE_TEST(cache, obj, id, sprop) \
JS_BEGIN_MACRO \
uintN hashIndex_ = (uintN) PROPERTY_CACHE_HASH(obj, id); \
JSPropertyCache *cache_ = (cache); \
JSPropertyCacheEntry *pce_ = &cache_->table[hashIndex_]; \
JSPropertyCacheEntry entry_; \
JSScopeProperty *pce_sprop_; \
PCE_LOAD(cache_, pce_, entry_); \
pce_sprop_ = PCE_PROPERTY(entry_); \
PCMETER(cache_->tests++); \
if (pce_sprop_ && \
PCE_OBJECT(entry_) == obj && \
pce_sprop_->id == id) { \
sprop = pce_sprop_; \
} else { \
PCMETER(cache_->misses++); \
sprop = NULL; \
} \
JS_END_MACRO
extern void
js_FlushPropertyCache(JSContext *cx);
extern void
js_DisablePropertyCache(JSContext *cx);
extern void
js_EnablePropertyCache(JSContext *cx);
extern JS_FRIEND_API(jsval *)
js_AllocStack(JSContext *cx, uintN nslots, void **markp);
extern JS_FRIEND_API(void)
js_FreeStack(JSContext *cx, void *mark);
extern JSBool
js_GetArgument(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
extern JSBool
js_SetArgument(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
extern JSBool
js_GetLocalVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
extern JSBool
js_SetLocalVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
#ifdef DUMP_CALL_TABLE
# define JSOPTION_LOGCALL_TOSOURCE JS_BIT(15)
extern JSHashTable *js_CallTable;
extern size_t js_LogCallToSourceLimit;
extern void js_DumpCallTable(JSContext *cx);
#endif
/*
* NB: js_Invoke requires that cx is currently running JS (i.e., that cx->fp
* is non-null), and that the callee, |this| parameter, and actual arguments
* are already pushed on the stack under cx->fp->sp.
*/
extern JS_FRIEND_API(JSBool)
js_Invoke(JSContext *cx, uintN argc, uintN flags);
/*
* Consolidated js_Invoke flags simply rename the low JSFRAME_* flags.
*/
#define JSINVOKE_CONSTRUCT JSFRAME_CONSTRUCTING
#define JSINVOKE_INTERNAL JSFRAME_INTERNAL
#define JSINVOKE_SKIP_CALLER JSFRAME_SKIP_CALLER
/*
* "Internal" calls may come from C or C++ code using a JSContext on which no
* JS is running (!cx->fp), so they may need to push a dummy JSStackFrame.
*/
#define js_InternalCall(cx,obj,fval,argc,argv,rval) \
js_InternalInvoke(cx, obj, fval, 0, argc, argv, rval)
#define js_InternalConstruct(cx,obj,fval,argc,argv,rval) \
js_InternalInvoke(cx, obj, fval, JSINVOKE_CONSTRUCT, argc, argv, rval)
extern JSBool
js_InternalInvoke(JSContext *cx, JSObject *obj, jsval fval, uintN flags,
uintN argc, jsval *argv, jsval *rval);
extern JSBool
js_InternalGetOrSet(JSContext *cx, JSObject *obj, jsid id, jsval fval,
JSAccessMode mode, uintN argc, jsval *argv, jsval *rval);
extern JSBool
js_Execute(JSContext *cx, JSObject *chain, JSScript *script,
JSStackFrame *down, uintN flags, jsval *result);
extern JSBool
js_CheckRedeclaration(JSContext *cx, JSObject *obj, jsid id, uintN attrs,
JSObject **objp, JSProperty **propp);
extern JSBool
js_Interpret(JSContext *cx, jsbytecode *pc, jsval *result);
JS_END_EXTERN_C
#endif /* jsinterp_h___ */

View File

@@ -1,290 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* IBM Corp.
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* By default all math calls go to fdlibm. The defines for each platform
* remap the math calls to native routines.
*/
#ifndef _LIBMATH_H
#define _LIBMATH_H
#include <math.h>
#include "jsconfig.h"
/*
* Define which platforms on which to use fdlibm. Not used
* by default since there can be problems with endian-ness and such.
*/
#if defined(_WIN32) && !defined(__MWERKS__)
#define JS_USE_FDLIBM_MATH 1
#elif defined(SUNOS4)
#define JS_USE_FDLIBM_MATH 1
#elif defined(IRIX)
#define JS_USE_FDLIBM_MATH 1
#elif defined(SOLARIS)
#define JS_USE_FDLIBM_MATH 1
#elif defined(HPUX)
#define JS_USE_FDLIBM_MATH 1
#elif defined(linux)
#define JS_USE_FDLIBM_MATH 1
#elif defined(OSF1)
/* Want to use some fdlibm functions but fdlibm broken on OSF1/alpha. */
#define JS_USE_FDLIBM_MATH 0
#elif defined(AIX)
#define JS_USE_FDLIBM_MATH 1
#else
#define JS_USE_FDLIBM_MATH 0
#endif
#if !JS_USE_FDLIBM_MATH
/*
* Use system provided math routines.
*/
#define fd_acos acos
#define fd_asin asin
#define fd_atan atan
#define fd_atan2 atan2
#define fd_ceil ceil
#define fd_copysign copysign
#define fd_cos cos
#define fd_exp exp
#define fd_fabs fabs
#define fd_floor floor
#define fd_fmod fmod
#define fd_log log
#define fd_pow pow
#define fd_sin sin
#define fd_sqrt sqrt
#define fd_tan tan
#else
/*
* Use math routines in fdlibm.
*/
#undef __P
#ifdef __STDC__
#define __P(p) p
#else
#define __P(p) ()
#endif
#if defined _WIN32 || defined SUNOS4
#define fd_acos acos
#define fd_asin asin
#define fd_atan atan
#define fd_cos cos
#define fd_sin sin
#define fd_tan tan
#define fd_exp exp
#define fd_log log
#define fd_sqrt sqrt
#define fd_ceil ceil
#define fd_fabs fabs
#define fd_floor floor
#define fd_fmod fmod
extern double fd_atan2 __P((double, double));
extern double fd_copysign __P((double, double));
extern double fd_pow __P((double, double));
#elif defined IRIX
#define fd_acos acos
#define fd_asin asin
#define fd_atan atan
#define fd_exp exp
#define fd_log log
#define fd_log10 log10
#define fd_sqrt sqrt
#define fd_fabs fabs
#define fd_floor floor
#define fd_fmod fmod
extern double fd_cos __P((double));
extern double fd_sin __P((double));
extern double fd_tan __P((double));
extern double fd_atan2 __P((double, double));
extern double fd_pow __P((double, double));
extern double fd_ceil __P((double));
extern double fd_copysign __P((double, double));
#elif defined SOLARIS
#define fd_atan atan
#define fd_cos cos
#define fd_sin sin
#define fd_tan tan
#define fd_exp exp
#define fd_sqrt sqrt
#define fd_ceil ceil
#define fd_fabs fabs
#define fd_floor floor
#define fd_fmod fmod
extern double fd_acos __P((double));
extern double fd_asin __P((double));
extern double fd_log __P((double));
extern double fd_atan2 __P((double, double));
extern double fd_pow __P((double, double));
extern double fd_copysign __P((double, double));
#elif defined HPUX
#define fd_cos cos
#define fd_sin sin
#define fd_exp exp
#define fd_sqrt sqrt
#define fd_fabs fabs
#define fd_floor floor
#define fd_fmod fmod
extern double fd_ceil __P((double));
extern double fd_acos __P((double));
extern double fd_log __P((double));
extern double fd_atan2 __P((double, double));
extern double fd_tan __P((double));
extern double fd_pow __P((double, double));
extern double fd_asin __P((double));
extern double fd_atan __P((double));
extern double fd_copysign __P((double, double));
#elif defined(linux)
#define fd_atan atan
#define fd_atan2 atan2
#define fd_ceil ceil
#define fd_cos cos
#define fd_fabs fabs
#define fd_floor floor
#define fd_fmod fmod
#define fd_sin sin
#define fd_sqrt sqrt
#define fd_tan tan
#define fd_copysign copysign
extern double fd_asin __P((double));
extern double fd_acos __P((double));
extern double fd_exp __P((double));
extern double fd_log __P((double));
extern double fd_pow __P((double, double));
#elif defined(OSF1)
#define fd_acos acos
#define fd_asin asin
#define fd_atan atan
#define fd_copysign copysign
#define fd_cos cos
#define fd_exp exp
#define fd_fabs fabs
#define fd_fmod fmod
#define fd_sin sin
#define fd_sqrt sqrt
#define fd_tan tan
extern double fd_atan2 __P((double, double));
extern double fd_ceil __P((double));
extern double fd_floor __P((double));
extern double fd_log __P((double));
extern double fd_pow __P((double, double));
#elif defined(AIX)
#define fd_acos acos
#define fd_asin asin
#define fd_atan2 atan2
#define fd_copysign copysign
#define fd_cos cos
#define fd_exp exp
#define fd_fabs fabs
#define fd_floor floor
#define fd_fmod fmod
#define fd_log log
#define fd_sin sin
#define fd_sqrt sqrt
extern double fd_atan __P((double));
extern double fd_ceil __P((double));
extern double fd_pow __P((double,double));
extern double fd_tan __P((double));
#else /* other platform.. generic paranoid slow fdlibm */
extern double fd_acos __P((double));
extern double fd_asin __P((double));
extern double fd_atan __P((double));
extern double fd_cos __P((double));
extern double fd_sin __P((double));
extern double fd_tan __P((double));
extern double fd_exp __P((double));
extern double fd_log __P((double));
extern double fd_sqrt __P((double));
extern double fd_ceil __P((double));
extern double fd_fabs __P((double));
extern double fd_floor __P((double));
extern double fd_fmod __P((double, double));
extern double fd_atan2 __P((double, double));
extern double fd_pow __P((double, double));
extern double fd_copysign __P((double, double));
#endif
#endif /* JS_USE_FDLIBM_MATH */
#endif /* _LIBMATH_H */

File diff suppressed because it is too large Load Diff

View File

@@ -1,261 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jslock_h__
#define jslock_h__
#ifdef JS_THREADSAFE
#include "jstypes.h"
#include "pratom.h"
#include "prlock.h"
#include "prcvar.h"
#include "jsprvtd.h" /* for JSScope, etc. */
#include "jspubtd.h" /* for JSRuntime, etc. */
#define Thin_GetWait(W) ((jsword)(W) & 0x1)
#define Thin_SetWait(W) ((jsword)(W) | 0x1)
#define Thin_RemoveWait(W) ((jsword)(W) & ~0x1)
typedef struct JSFatLock JSFatLock;
struct JSFatLock {
int susp;
PRLock *slock;
PRCondVar *svar;
JSFatLock *next;
JSFatLock **prevp;
};
typedef struct JSThinLock {
jsword owner;
JSFatLock *fat;
} JSThinLock;
typedef PRLock JSLock;
typedef struct JSFatLockTable {
JSFatLock *free;
JSFatLock *taken;
} JSFatLockTable;
/*
* Atomic increment and decrement for a reference counter, given jsrefcount *p.
* NB: jsrefcount is int32, aka PRInt32, so that pratom.h functions work.
*/
#define JS_ATOMIC_INCREMENT(p) PR_AtomicIncrement((PRInt32 *)(p))
#define JS_ATOMIC_DECREMENT(p) PR_AtomicDecrement((PRInt32 *)(p))
#define JS_ATOMIC_ADD(p,v) PR_AtomicAdd((PRInt32 *)(p), (PRInt32)(v))
#define CurrentThreadId() (jsword)PR_GetCurrentThread()
#define JS_CurrentThreadId() js_CurrentThreadId()
#define JS_NEW_LOCK() PR_NewLock()
#define JS_DESTROY_LOCK(l) PR_DestroyLock(l)
#define JS_ACQUIRE_LOCK(l) PR_Lock(l)
#define JS_RELEASE_LOCK(l) PR_Unlock(l)
#define JS_LOCK0(P,M) js_Lock(P,M)
#define JS_UNLOCK0(P,M) js_Unlock(P,M)
#define JS_NEW_CONDVAR(l) PR_NewCondVar(l)
#define JS_DESTROY_CONDVAR(cv) PR_DestroyCondVar(cv)
#define JS_WAIT_CONDVAR(cv,to) PR_WaitCondVar(cv,to)
#define JS_NO_TIMEOUT PR_INTERVAL_NO_TIMEOUT
#define JS_NOTIFY_CONDVAR(cv) PR_NotifyCondVar(cv)
#define JS_NOTIFY_ALL_CONDVAR(cv) PR_NotifyAllCondVar(cv)
/*
* Include jsscope.h so JS_LOCK_OBJ macro callers don't have to include it.
* Since there is a JSThinLock member in JSScope, we can't nest this include
* much earlier (see JSThinLock's typedef, above). Yes, that means there is
* an #include cycle between jslock.h and jsscope.h: moderate-sized XXX here,
* to be fixed by moving JS_LOCK_SCOPE to jsscope.h, JS_LOCK_OBJ to jsobj.h,
* and so on.
*/
#include "jsscope.h"
#define JS_LOCK_RUNTIME(rt) js_LockRuntime(rt)
#define JS_UNLOCK_RUNTIME(rt) js_UnlockRuntime(rt)
/*
* NB: The JS_LOCK_OBJ and JS_UNLOCK_OBJ macros work *only* on native objects
* (objects for which OBJ_IS_NATIVE returns true). All uses of these macros in
* the engine are predicated on OBJ_IS_NATIVE or equivalent checks. These uses
* are for optimizations above the JSObjectOps layer, under which object locks
* normally hide.
*/
#define JS_LOCK_OBJ(cx,obj) ((OBJ_SCOPE(obj)->ownercx == (cx)) \
? (void)0 \
: (js_LockObj(cx, obj)))
#define JS_UNLOCK_OBJ(cx,obj) ((OBJ_SCOPE(obj)->ownercx == (cx)) \
? (void)0 : js_UnlockObj(cx, obj))
#define JS_LOCK_SCOPE(cx,scope) ((scope)->ownercx == (cx) ? (void)0 \
: js_LockScope(cx, scope))
#define JS_UNLOCK_SCOPE(cx,scope) ((scope)->ownercx == (cx) ? (void)0 \
: js_UnlockScope(cx, scope))
#define JS_TRANSFER_SCOPE_LOCK(cx, scope, newscope) \
js_TransferScopeLock(cx, scope, newscope)
extern jsword js_CurrentThreadId();
extern void js_LockRuntime(JSRuntime *rt);
extern void js_UnlockRuntime(JSRuntime *rt);
extern void js_LockObj(JSContext *cx, JSObject *obj);
extern void js_UnlockObj(JSContext *cx, JSObject *obj);
extern void js_LockScope(JSContext *cx, JSScope *scope);
extern void js_UnlockScope(JSContext *cx, JSScope *scope);
extern int js_SetupLocks(int,int);
extern void js_CleanupLocks();
extern void js_InitContextForLocking(JSContext *);
extern void js_TransferScopeLock(JSContext *, JSScope *, JSScope *);
extern JS_FRIEND_API(jsval)
js_GetSlotThreadSafe(JSContext *, JSObject *, uint32);
extern void js_SetSlotThreadSafe(JSContext *, JSObject *, uint32, jsval);
extern void js_InitLock(JSThinLock *);
extern void js_FinishLock(JSThinLock *);
extern void js_FinishSharingScope(JSRuntime *rt, JSScope *scope);
#ifdef DEBUG
#define JS_IS_RUNTIME_LOCKED(rt) js_IsRuntimeLocked(rt)
#define JS_IS_OBJ_LOCKED(cx,obj) js_IsObjLocked(cx,obj)
#define JS_IS_SCOPE_LOCKED(cx,scope) js_IsScopeLocked(cx,scope)
extern JSBool js_IsRuntimeLocked(JSRuntime *rt);
extern JSBool js_IsObjLocked(JSContext *cx, JSObject *obj);
extern JSBool js_IsScopeLocked(JSContext *cx, JSScope *scope);
#else
#define JS_IS_RUNTIME_LOCKED(rt) 0
#define JS_IS_OBJ_LOCKED(cx,obj) 1
#define JS_IS_SCOPE_LOCKED(cx,scope) 1
#endif /* DEBUG */
#define JS_LOCK_OBJ_VOID(cx, obj, e) \
JS_BEGIN_MACRO \
JS_LOCK_OBJ(cx, obj); \
e; \
JS_UNLOCK_OBJ(cx, obj); \
JS_END_MACRO
#define JS_LOCK_VOID(cx, e) \
JS_BEGIN_MACRO \
JSRuntime *_rt = (cx)->runtime; \
JS_LOCK_RUNTIME_VOID(_rt, e); \
JS_END_MACRO
#if defined(JS_USE_ONLY_NSPR_LOCKS) || \
!( (defined(_WIN32) && defined(_M_IX86)) || \
(defined(__GNUC__) && defined(__i386__)) || \
(defined(SOLARIS) && defined(sparc) && defined(ULTRA_SPARC)) || \
defined(AIX) )
#define NSPR_LOCK 1
#undef JS_LOCK0
#undef JS_UNLOCK0
#define JS_LOCK0(P,M) (JS_ACQUIRE_LOCK(((JSLock*)(P)->fat)), (P)->owner = (M))
#define JS_UNLOCK0(P,M) ((P)->owner = 0, JS_RELEASE_LOCK(((JSLock*)(P)->fat)))
#else /* arch-tests */
#undef NSPR_LOCK
extern JS_INLINE void js_Lock(JSThinLock *tl, jsword me);
extern JS_INLINE void js_Unlock(JSThinLock *tl, jsword me);
#endif /* arch-tests */
#else /* !JS_THREADSAFE */
#define JS_ATOMIC_INCREMENT(p) (++*(p))
#define JS_ATOMIC_DECREMENT(p) (--*(p))
#define JS_ATOMIC_ADD(p,v) (*(p) += (v))
#define JS_CurrentThreadId() 0
#define JS_NEW_LOCK() NULL
#define JS_DESTROY_LOCK(l) ((void)0)
#define JS_ACQUIRE_LOCK(l) ((void)0)
#define JS_RELEASE_LOCK(l) ((void)0)
#define JS_LOCK0(P,M) ((void)0)
#define JS_UNLOCK0(P,M) ((void)0)
#define JS_NEW_CONDVAR(l) NULL
#define JS_DESTROY_CONDVAR(cv) ((void)0)
#define JS_WAIT_CONDVAR(cv,to) ((void)0)
#define JS_NOTIFY_CONDVAR(cv) ((void)0)
#define JS_NOTIFY_ALL_CONDVAR(cv) ((void)0)
#define JS_LOCK_RUNTIME(rt) ((void)0)
#define JS_UNLOCK_RUNTIME(rt) ((void)0)
#define JS_LOCK_OBJ(cx,obj) ((void)0)
#define JS_UNLOCK_OBJ(cx,obj) ((void)0)
#define JS_LOCK_OBJ_VOID(cx,obj,e) (e)
#define JS_LOCK_SCOPE(cx,scope) ((void)0)
#define JS_UNLOCK_SCOPE(cx,scope) ((void)0)
#define JS_TRANSFER_SCOPE_LOCK(c,o,n) ((void)0)
#define JS_IS_RUNTIME_LOCKED(rt) 1
#define JS_IS_OBJ_LOCKED(cx,obj) 1
#define JS_IS_SCOPE_LOCKED(cx,scope) 1
#define JS_LOCK_VOID(cx, e) JS_LOCK_RUNTIME_VOID((cx)->runtime, e)
#endif /* !JS_THREADSAFE */
#define JS_LOCK_RUNTIME_VOID(rt,e) \
JS_BEGIN_MACRO \
JS_LOCK_RUNTIME(rt); \
e; \
JS_UNLOCK_RUNTIME(rt); \
JS_END_MACRO
#define JS_LOCK_GC(rt) JS_ACQUIRE_LOCK((rt)->gcLock)
#define JS_UNLOCK_GC(rt) JS_RELEASE_LOCK((rt)->gcLock)
#define JS_LOCK_GC_VOID(rt,e) (JS_LOCK_GC(rt), (e), JS_UNLOCK_GC(rt))
#define JS_AWAIT_GC_DONE(rt) JS_WAIT_CONDVAR((rt)->gcDone, JS_NO_TIMEOUT)
#define JS_NOTIFY_GC_DONE(rt) JS_NOTIFY_ALL_CONDVAR((rt)->gcDone)
#define JS_AWAIT_REQUEST_DONE(rt) JS_WAIT_CONDVAR((rt)->requestDone, \
JS_NO_TIMEOUT)
#define JS_NOTIFY_REQUEST_DONE(rt) JS_NOTIFY_CONDVAR((rt)->requestDone)
#define JS_LOCK(P,CX) JS_LOCK0(P,(CX)->thread)
#define JS_UNLOCK(P,CX) JS_UNLOCK0(P,(CX)->thread)
#endif /* jslock_h___ */

View File

@@ -1,60 +0,0 @@
; -*- Mode: asm; tab-width: 8; c-basic-offset: 4 -*-
; ***** BEGIN LICENSE BLOCK *****
; Version: MPL 1.1/GPL 2.0/LGPL 2.1
;
; The contents of this file are subject to the Mozilla Public License Version
; 1.1 (the "License"); you may not use this file except in compliance with
; the License. You may obtain a copy of the License at
; http://www.mozilla.org/MPL/
;
; Software distributed under the License is distributed on an "AS IS" basis,
; WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
; for the specific language governing rights and limitations under the
; License.
;
; The Original Code is an OS/2 implementation of js_CompareAndSwap in assembly.
;
; The Initial Developer of the Original Code is
; IBM Corporation.
; Portions created by the Initial Developer are Copyright (C) 2001
; the Initial Developer. All Rights Reserved.
;
; Contributor(s):
;
; Alternatively, the contents of this file may be used under the terms of
; either the GNU General Public License Version 2 or later (the "GPL"), or
; the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
; in which case the provisions of the GPL or the LGPL are applicable instead
; of those above. If you wish to allow use of your version of this file only
; under the terms of either the GPL or the LGPL, and not to allow others to
; use your version of this file under the terms of the MPL, indicate your
; decision by deleting the provisions above and replace them with the notice
; and other provisions required by the GPL or the LGPL. If you do not delete
; the provisions above, a recipient may use your version of this file under
; the terms of any one of the MPL, the GPL or the LGPL.
;
; ***** END LICENSE BLOCK *****
.486P
.MODEL FLAT, OPTLINK
.STACK
.CODE
;;;---------------------------------------------------------------------
;;; int _Optlink js_CompareAndSwap(jsword *w, jsword ov, jsword nv)
;;;---------------------------------------------------------------------
js_CompareAndSwap PROC OPTLINK EXPORT
push ebx
mov ebx, eax
mov eax, edx
mov edx, ebx
lock cmpxchg [ebx], ecx
sete al
and eax, 1h
pop ebx
ret
js_CompareAndSwap endp
END

View File

@@ -1,83 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "jsstddef.h"
#include "jsbit.h"
/*
** Compute the log of the least power of 2 greater than or equal to n
*/
JS_PUBLIC_API(JSIntn) JS_CeilingLog2(JSUint32 n)
{
JSIntn log2 = 0;
if (n & (n-1))
log2++;
if (n >> 16)
log2 += 16, n >>= 16;
if (n >> 8)
log2 += 8, n >>= 8;
if (n >> 4)
log2 += 4, n >>= 4;
if (n >> 2)
log2 += 2, n >>= 2;
if (n >> 1)
log2++;
return log2;
}
/*
** Compute the log of the greatest power of 2 less than or equal to n.
** This really just finds the highest set bit in the word.
*/
JS_PUBLIC_API(JSIntn) JS_FloorLog2(JSUint32 n)
{
JSIntn log2 = 0;
if (n >> 16)
log2 += 16, n >>= 16;
if (n >> 8)
log2 += 8, n >>= 8;
if (n >> 4)
log2 += 4, n >>= 4;
if (n >> 2)
log2 += 2, n >>= 2;
if (n >> 1)
log2++;
return log2;
}

View File

@@ -1,281 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "jsstddef.h"
#include "jstypes.h"
#include "jslong.h"
static JSInt64 ll_zero = JSLL_INIT( 0x00000000,0x00000000 );
static JSInt64 ll_maxint = JSLL_INIT( 0x7fffffff, 0xffffffff );
static JSInt64 ll_minint = JSLL_INIT( 0x80000000, 0x00000000 );
#ifdef HAVE_WATCOM_BUG_2
JSInt64 __pascal __loadds __export
JSLL_Zero(void) { return ll_zero; }
JSInt64 __pascal __loadds __export
JSLL_MaxInt(void) { return ll_maxint; }
JSInt64 __pascal __loadds __export
JSLL_MinInt(void) { return ll_minint; }
#else
JS_PUBLIC_API(JSInt64) JSLL_Zero(void) { return ll_zero; }
JS_PUBLIC_API(JSInt64) JSLL_MaxInt(void) { return ll_maxint; }
JS_PUBLIC_API(JSInt64) JSLL_MinInt(void) { return ll_minint; }
#endif
#ifndef JS_HAVE_LONG_LONG
/*
** Divide 64-bit a by 32-bit b, which must be normalized so its high bit is 1.
*/
static void norm_udivmod32(JSUint32 *qp, JSUint32 *rp, JSUint64 a, JSUint32 b)
{
JSUint32 d1, d0, q1, q0;
JSUint32 r1, r0, m;
d1 = jshi16(b);
d0 = jslo16(b);
r1 = a.hi % d1;
q1 = a.hi / d1;
m = q1 * d0;
r1 = (r1 << 16) | jshi16(a.lo);
if (r1 < m) {
q1--, r1 += b;
if (r1 >= b /* i.e., we didn't get a carry when adding to r1 */
&& r1 < m) {
q1--, r1 += b;
}
}
r1 -= m;
r0 = r1 % d1;
q0 = r1 / d1;
m = q0 * d0;
r0 = (r0 << 16) | jslo16(a.lo);
if (r0 < m) {
q0--, r0 += b;
if (r0 >= b
&& r0 < m) {
q0--, r0 += b;
}
}
*qp = (q1 << 16) | q0;
*rp = r0 - m;
}
static JSUint32 CountLeadingZeros(JSUint32 a)
{
JSUint32 t;
JSUint32 r = 32;
if ((t = a >> 16) != 0)
r -= 16, a = t;
if ((t = a >> 8) != 0)
r -= 8, a = t;
if ((t = a >> 4) != 0)
r -= 4, a = t;
if ((t = a >> 2) != 0)
r -= 2, a = t;
if ((t = a >> 1) != 0)
r -= 1, a = t;
if (a & 1)
r--;
return r;
}
JS_PUBLIC_API(void) jsll_udivmod(JSUint64 *qp, JSUint64 *rp, JSUint64 a, JSUint64 b)
{
JSUint32 n0, n1, n2;
JSUint32 q0, q1;
JSUint32 rsh, lsh;
n0 = a.lo;
n1 = a.hi;
if (b.hi == 0) {
if (b.lo > n1) {
/* (0 q0) = (n1 n0) / (0 D0) */
lsh = CountLeadingZeros(b.lo);
if (lsh) {
/*
* Normalize, i.e. make the most significant bit of the
* denominator be set.
*/
b.lo = b.lo << lsh;
n1 = (n1 << lsh) | (n0 >> (32 - lsh));
n0 = n0 << lsh;
}
a.lo = n0, a.hi = n1;
norm_udivmod32(&q0, &n0, a, b.lo);
q1 = 0;
/* remainder is in n0 >> lsh */
} else {
/* (q1 q0) = (n1 n0) / (0 d0) */
if (b.lo == 0) /* user wants to divide by zero! */
b.lo = 1 / b.lo; /* so go ahead and crash */
lsh = CountLeadingZeros(b.lo);
if (lsh == 0) {
/*
* From (n1 >= b.lo)
* && (the most significant bit of b.lo is set),
* conclude that
* (the most significant bit of n1 is set)
* && (the leading quotient digit q1 = 1).
*
* This special case is necessary, not an optimization
* (Shifts counts of 32 are undefined).
*/
n1 -= b.lo;
q1 = 1;
} else {
/*
* Normalize.
*/
rsh = 32 - lsh;
b.lo = b.lo << lsh;
n2 = n1 >> rsh;
n1 = (n1 << lsh) | (n0 >> rsh);
n0 = n0 << lsh;
a.lo = n1, a.hi = n2;
norm_udivmod32(&q1, &n1, a, b.lo);
}
/* n1 != b.lo... */
a.lo = n0, a.hi = n1;
norm_udivmod32(&q0, &n0, a, b.lo);
/* remainder in n0 >> lsh */
}
if (rp) {
rp->lo = n0 >> lsh;
rp->hi = 0;
}
} else {
if (b.hi > n1) {
/* (0 0) = (n1 n0) / (D1 d0) */
q0 = 0;
q1 = 0;
/* remainder in (n1 n0) */
if (rp) {
rp->lo = n0;
rp->hi = n1;
}
} else {
/* (0 q0) = (n1 n0) / (d1 d0) */
lsh = CountLeadingZeros(b.hi);
if (lsh == 0) {
/*
* From (n1 >= b.hi)
* && (the most significant bit of b.hi is set),
* conclude that
* (the most significant bit of n1 is set)
* && (the quotient digit q0 = 0 or 1).
*
* This special case is necessary, not an optimization.
*/
/*
* The condition on the next line takes advantage of that
* n1 >= b.hi (true due to control flow).
*/
if (n1 > b.hi || n0 >= b.lo) {
q0 = 1;
a.lo = n0, a.hi = n1;
JSLL_SUB(a, a, b);
} else {
q0 = 0;
}
q1 = 0;
if (rp) {
rp->lo = n0;
rp->hi = n1;
}
} else {
JSInt64 m;
/*
* Normalize.
*/
rsh = 32 - lsh;
b.hi = (b.hi << lsh) | (b.lo >> rsh);
b.lo = b.lo << lsh;
n2 = n1 >> rsh;
n1 = (n1 << lsh) | (n0 >> rsh);
n0 = n0 << lsh;
a.lo = n1, a.hi = n2;
norm_udivmod32(&q0, &n1, a, b.hi);
JSLL_MUL32(m, q0, b.lo);
if ((m.hi > n1) || ((m.hi == n1) && (m.lo > n0))) {
q0--;
JSLL_SUB(m, m, b);
}
q1 = 0;
/* Remainder is ((n1 n0) - (m1 m0)) >> lsh */
if (rp) {
a.lo = n0, a.hi = n1;
JSLL_SUB(a, a, m);
rp->lo = (a.hi << rsh) | (a.lo >> lsh);
rp->hi = a.hi >> lsh;
}
}
}
}
if (qp) {
qp->lo = q0;
qp->hi = q1;
}
}
#endif /* !JS_HAVE_LONG_LONG */

View File

@@ -1,437 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
** File: jslong.h
** Description: Portable access to 64 bit numerics
**
** Long-long (64-bit signed integer type) support. Some C compilers
** don't support 64 bit integers yet, so we use these macros to
** support both machines that do and don't.
**/
#ifndef jslong_h___
#define jslong_h___
#include "jstypes.h"
JS_BEGIN_EXTERN_C
/***********************************************************************
** DEFINES: JSLL_MaxInt
** JSLL_MinInt
** JSLL_Zero
** DESCRIPTION:
** Various interesting constants and static variable
** initializer
***********************************************************************/
#ifdef HAVE_WATCOM_BUG_2
JSInt64 __pascal __loadds __export
JSLL_MaxInt(void);
JSInt64 __pascal __loadds __export
JSLL_MinInt(void);
JSInt64 __pascal __loadds __export
JSLL_Zero(void);
#else
extern JS_PUBLIC_API(JSInt64) JSLL_MaxInt(void);
extern JS_PUBLIC_API(JSInt64) JSLL_MinInt(void);
extern JS_PUBLIC_API(JSInt64) JSLL_Zero(void);
#endif
#define JSLL_MAXINT JSLL_MaxInt()
#define JSLL_MININT JSLL_MinInt()
#define JSLL_ZERO JSLL_Zero()
#ifdef JS_HAVE_LONG_LONG
#if JS_BYTES_PER_LONG == 8
#define JSLL_INIT(hi, lo) ((hi ## L << 32) + lo ## L)
#elif (defined(WIN32) || defined(WIN16)) && !defined(__GNUC__)
#define JSLL_INIT(hi, lo) ((hi ## i64 << 32) + lo ## i64)
#else
#define JSLL_INIT(hi, lo) ((hi ## LL << 32) + lo ## LL)
#endif
/***********************************************************************
** MACROS: JSLL_*
** DESCRIPTION:
** The following macros define portable access to the 64 bit
** math facilities.
**
***********************************************************************/
/***********************************************************************
** MACROS: JSLL_<relational operators>
**
** JSLL_IS_ZERO Test for zero
** JSLL_EQ Test for equality
** JSLL_NE Test for inequality
** JSLL_GE_ZERO Test for zero or positive
** JSLL_CMP Compare two values
***********************************************************************/
#define JSLL_IS_ZERO(a) ((a) == 0)
#define JSLL_EQ(a, b) ((a) == (b))
#define JSLL_NE(a, b) ((a) != (b))
#define JSLL_GE_ZERO(a) ((a) >= 0)
#define JSLL_CMP(a, op, b) ((JSInt64)(a) op (JSInt64)(b))
#define JSLL_UCMP(a, op, b) ((JSUint64)(a) op (JSUint64)(b))
/***********************************************************************
** MACROS: JSLL_<logical operators>
**
** JSLL_AND Logical and
** JSLL_OR Logical or
** JSLL_XOR Logical exclusion
** JSLL_OR2 A disgusting deviation
** JSLL_NOT Negation (one's compliment)
***********************************************************************/
#define JSLL_AND(r, a, b) ((r) = (a) & (b))
#define JSLL_OR(r, a, b) ((r) = (a) | (b))
#define JSLL_XOR(r, a, b) ((r) = (a) ^ (b))
#define JSLL_OR2(r, a) ((r) = (r) | (a))
#define JSLL_NOT(r, a) ((r) = ~(a))
/***********************************************************************
** MACROS: JSLL_<mathematical operators>
**
** JSLL_NEG Negation (two's compliment)
** JSLL_ADD Summation (two's compliment)
** JSLL_SUB Difference (two's compliment)
***********************************************************************/
#define JSLL_NEG(r, a) ((r) = -(a))
#define JSLL_ADD(r, a, b) ((r) = (a) + (b))
#define JSLL_SUB(r, a, b) ((r) = (a) - (b))
/***********************************************************************
** MACROS: JSLL_<mathematical operators>
**
** JSLL_MUL Product (two's compliment)
** JSLL_DIV Quotient (two's compliment)
** JSLL_MOD Modulus (two's compliment)
***********************************************************************/
#define JSLL_MUL(r, a, b) ((r) = (a) * (b))
#define JSLL_DIV(r, a, b) ((r) = (a) / (b))
#define JSLL_MOD(r, a, b) ((r) = (a) % (b))
/***********************************************************************
** MACROS: JSLL_<shifting operators>
**
** JSLL_SHL Shift left [0..64] bits
** JSLL_SHR Shift right [0..64] bits with sign extension
** JSLL_USHR Unsigned shift right [0..64] bits
** JSLL_ISHL Signed shift left [0..64] bits
***********************************************************************/
#define JSLL_SHL(r, a, b) ((r) = (JSInt64)(a) << (b))
#define JSLL_SHR(r, a, b) ((r) = (JSInt64)(a) >> (b))
#define JSLL_USHR(r, a, b) ((r) = (JSUint64)(a) >> (b))
#define JSLL_ISHL(r, a, b) ((r) = (JSInt64)(a) << (b))
/***********************************************************************
** MACROS: JSLL_<conversion operators>
**
** JSLL_L2I Convert to signed 32 bit
** JSLL_L2UI Convert to unsigned 32 bit
** JSLL_L2F Convert to floating point
** JSLL_L2D Convert to floating point
** JSLL_I2L Convert signed to 64 bit
** JSLL_UI2L Convert unsigned to 64 bit
** JSLL_F2L Convert float to 64 bit
** JSLL_D2L Convert float to 64 bit
***********************************************************************/
#define JSLL_L2I(i, l) ((i) = (JSInt32)(l))
#define JSLL_L2UI(ui, l) ((ui) = (JSUint32)(l))
#define JSLL_L2F(f, l) ((f) = (JSFloat64)(l))
#define JSLL_L2D(d, l) ((d) = (JSFloat64)(l))
#define JSLL_I2L(l, i) ((l) = (JSInt64)(i))
#define JSLL_UI2L(l, ui) ((l) = (JSInt64)(ui))
#define JSLL_F2L(l, f) ((l) = (JSInt64)(f))
#define JSLL_D2L(l, d) ((l) = (JSInt64)(d))
/***********************************************************************
** MACROS: JSLL_UDIVMOD
** DESCRIPTION:
** Produce both a quotient and a remainder given an unsigned
** INPUTS: JSUint64 a: The dividend of the operation
** JSUint64 b: The quotient of the operation
** OUTPUTS: JSUint64 *qp: pointer to quotient
** JSUint64 *rp: pointer to remainder
***********************************************************************/
#define JSLL_UDIVMOD(qp, rp, a, b) \
(*(qp) = ((JSUint64)(a) / (b)), \
*(rp) = ((JSUint64)(a) % (b)))
#else /* !JS_HAVE_LONG_LONG */
#ifdef IS_LITTLE_ENDIAN
#define JSLL_INIT(hi, lo) {JS_INT32(lo), JS_INT32(hi)}
#else
#define JSLL_INIT(hi, lo) {JS_INT32(hi), JS_INT32(lo)}
#endif
#define JSLL_IS_ZERO(a) (((a).hi == 0) && ((a).lo == 0))
#define JSLL_EQ(a, b) (((a).hi == (b).hi) && ((a).lo == (b).lo))
#define JSLL_NE(a, b) (((a).hi != (b).hi) || ((a).lo != (b).lo))
#define JSLL_GE_ZERO(a) (((a).hi >> 31) == 0)
#ifdef DEBUG
#define JSLL_CMP(a, op, b) (JS_ASSERT((#op)[1] != '='), JSLL_REAL_CMP(a, op, b))
#define JSLL_UCMP(a, op, b) (JS_ASSERT((#op)[1] != '='), JSLL_REAL_UCMP(a, op, b))
#else
#define JSLL_CMP(a, op, b) JSLL_REAL_CMP(a, op, b)
#define JSLL_UCMP(a, op, b) JSLL_REAL_UCMP(a, op, b)
#endif
#define JSLL_REAL_CMP(a,op,b) (((JSInt32)(a).hi op (JSInt32)(b).hi) || \
(((a).hi == (b).hi) && ((a).lo op (b).lo)))
#define JSLL_REAL_UCMP(a,op,b) (((a).hi op (b).hi) || \
(((a).hi == (b).hi) && ((a).lo op (b).lo)))
#define JSLL_AND(r, a, b) ((r).lo = (a).lo & (b).lo, \
(r).hi = (a).hi & (b).hi)
#define JSLL_OR(r, a, b) ((r).lo = (a).lo | (b).lo, \
(r).hi = (a).hi | (b).hi)
#define JSLL_XOR(r, a, b) ((r).lo = (a).lo ^ (b).lo, \
(r).hi = (a).hi ^ (b).hi)
#define JSLL_OR2(r, a) ((r).lo = (r).lo | (a).lo, \
(r).hi = (r).hi | (a).hi)
#define JSLL_NOT(r, a) ((r).lo = ~(a).lo, \
(r).hi = ~(a).hi)
#define JSLL_NEG(r, a) ((r).lo = -(JSInt32)(a).lo, \
(r).hi = -(JSInt32)(a).hi - ((r).lo != 0))
#define JSLL_ADD(r, a, b) { \
JSInt64 _a, _b; \
_a = a; _b = b; \
(r).lo = _a.lo + _b.lo; \
(r).hi = _a.hi + _b.hi + ((r).lo < _b.lo); \
}
#define JSLL_SUB(r, a, b) { \
JSInt64 _a, _b; \
_a = a; _b = b; \
(r).lo = _a.lo - _b.lo; \
(r).hi = _a.hi - _b.hi - (_a.lo < _b.lo); \
}
#define JSLL_MUL(r, a, b) { \
JSInt64 _a, _b; \
_a = a; _b = b; \
JSLL_MUL32(r, _a.lo, _b.lo); \
(r).hi += _a.hi * _b.lo + _a.lo * _b.hi; \
}
#define jslo16(a) ((a) & JS_BITMASK(16))
#define jshi16(a) ((a) >> 16)
#define JSLL_MUL32(r, a, b) { \
JSUint32 _a1, _a0, _b1, _b0, _y0, _y1, _y2, _y3; \
_a1 = jshi16(a), _a0 = jslo16(a); \
_b1 = jshi16(b), _b0 = jslo16(b); \
_y0 = _a0 * _b0; \
_y1 = _a0 * _b1; \
_y2 = _a1 * _b0; \
_y3 = _a1 * _b1; \
_y1 += jshi16(_y0); /* can't carry */ \
_y1 += _y2; /* might carry */ \
if (_y1 < _y2) \
_y3 += (JSUint32)(JS_BIT(16)); /* propagate */ \
(r).lo = (jslo16(_y1) << 16) + jslo16(_y0); \
(r).hi = _y3 + jshi16(_y1); \
}
#define JSLL_UDIVMOD(qp, rp, a, b) jsll_udivmod(qp, rp, a, b)
extern JS_PUBLIC_API(void) jsll_udivmod(JSUint64 *qp, JSUint64 *rp, JSUint64 a, JSUint64 b);
#define JSLL_DIV(r, a, b) { \
JSInt64 _a, _b; \
JSUint32 _negative = (JSInt32)(a).hi < 0; \
if (_negative) { \
JSLL_NEG(_a, a); \
} else { \
_a = a; \
} \
if ((JSInt32)(b).hi < 0) { \
_negative ^= 1; \
JSLL_NEG(_b, b); \
} else { \
_b = b; \
} \
JSLL_UDIVMOD(&(r), 0, _a, _b); \
if (_negative) \
JSLL_NEG(r, r); \
}
#define JSLL_MOD(r, a, b) { \
JSInt64 _a, _b; \
JSUint32 _negative = (JSInt32)(a).hi < 0; \
if (_negative) { \
JSLL_NEG(_a, a); \
} else { \
_a = a; \
} \
if ((JSInt32)(b).hi < 0) { \
JSLL_NEG(_b, b); \
} else { \
_b = b; \
} \
JSLL_UDIVMOD(0, &(r), _a, _b); \
if (_negative) \
JSLL_NEG(r, r); \
}
#define JSLL_SHL(r, a, b) { \
if (b) { \
JSInt64 _a; \
_a = a; \
if ((b) < 32) { \
(r).lo = _a.lo << ((b) & 31); \
(r).hi = (_a.hi << ((b) & 31)) | (_a.lo >> (32 - (b))); \
} else { \
(r).lo = 0; \
(r).hi = _a.lo << ((b) & 31); \
} \
} else { \
(r) = (a); \
} \
}
/* a is an JSInt32, b is JSInt32, r is JSInt64 */
#define JSLL_ISHL(r, a, b) { \
if (b) { \
JSInt64 _a; \
_a.lo = (a); \
_a.hi = 0; \
if ((b) < 32) { \
(r).lo = (a) << ((b) & 31); \
(r).hi = ((a) >> (32 - (b))); \
} else { \
(r).lo = 0; \
(r).hi = (a) << ((b) & 31); \
} \
} else { \
(r).lo = (a); \
(r).hi = 0; \
} \
}
#define JSLL_SHR(r, a, b) { \
if (b) { \
JSInt64 _a; \
_a = a; \
if ((b) < 32) { \
(r).lo = (_a.hi << (32 - (b))) | (_a.lo >> ((b) & 31)); \
(r).hi = (JSInt32)_a.hi >> ((b) & 31); \
} else { \
(r).lo = (JSInt32)_a.hi >> ((b) & 31); \
(r).hi = (JSInt32)_a.hi >> 31; \
} \
} else { \
(r) = (a); \
} \
}
#define JSLL_USHR(r, a, b) { \
if (b) { \
JSInt64 _a; \
_a = a; \
if ((b) < 32) { \
(r).lo = (_a.hi << (32 - (b))) | (_a.lo >> ((b) & 31)); \
(r).hi = _a.hi >> ((b) & 31); \
} else { \
(r).lo = _a.hi >> ((b) & 31); \
(r).hi = 0; \
} \
} else { \
(r) = (a); \
} \
}
#define JSLL_L2I(i, l) ((i) = (l).lo)
#define JSLL_L2UI(ui, l) ((ui) = (l).lo)
#define JSLL_L2F(f, l) { double _d; JSLL_L2D(_d, l); (f) = (JSFloat64)_d; }
#define JSLL_L2D(d, l) { \
int _negative; \
JSInt64 _absval; \
\
_negative = (l).hi >> 31; \
if (_negative) { \
JSLL_NEG(_absval, l); \
} else { \
_absval = l; \
} \
(d) = (double)_absval.hi * 4.294967296e9 + _absval.lo; \
if (_negative) \
(d) = -(d); \
}
#define JSLL_I2L(l, i) { JSInt32 _i = (i) >> 31; (l).lo = (i); (l).hi = _i; }
#define JSLL_UI2L(l, ui) ((l).lo = (ui), (l).hi = 0)
#define JSLL_F2L(l, f) { double _d = (double)f; JSLL_D2L(l, _d); }
#define JSLL_D2L(l, d) { \
int _negative; \
double _absval, _d_hi; \
JSInt64 _lo_d; \
\
_negative = ((d) < 0); \
_absval = _negative ? -(d) : (d); \
\
(l).hi = _absval / 4.294967296e9; \
(l).lo = 0; \
JSLL_L2D(_d_hi, l); \
_absval -= _d_hi; \
_lo_d.hi = 0; \
if (_absval < 0) { \
_lo_d.lo = -_absval; \
JSLL_SUB(l, l, _lo_d); \
} else { \
_lo_d.lo = _absval; \
JSLL_ADD(l, l, _lo_d); \
} \
\
if (_negative) \
JSLL_NEG(l, l); \
}
#endif /* !JS_HAVE_LONG_LONG */
JS_END_EXTERN_C
#endif /* jslong_h___ */

View File

@@ -1,477 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* JS math package.
*/
#include "jsstddef.h"
#include "jslibmath.h"
#include <stdlib.h>
#include "jstypes.h"
#include "jslong.h"
#include "prmjtime.h"
#include "jsapi.h"
#include "jsatom.h"
#include "jscntxt.h"
#include "jsconfig.h"
#include "jslock.h"
#include "jsmath.h"
#include "jsnum.h"
#include "jsobj.h"
#ifndef M_E
#define M_E 2.7182818284590452354
#endif
#ifndef M_LOG2E
#define M_LOG2E 1.4426950408889634074
#endif
#ifndef M_LOG10E
#define M_LOG10E 0.43429448190325182765
#endif
#ifndef M_LN2
#define M_LN2 0.69314718055994530942
#endif
#ifndef M_LN10
#define M_LN10 2.30258509299404568402
#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_SQRT2
#define M_SQRT2 1.41421356237309504880
#endif
#ifndef M_SQRT1_2
#define M_SQRT1_2 0.70710678118654752440
#endif
static JSConstDoubleSpec math_constants[] = {
{M_E, "E", 0, {0,0,0}},
{M_LOG2E, "LOG2E", 0, {0,0,0}},
{M_LOG10E, "LOG10E", 0, {0,0,0}},
{M_LN2, "LN2", 0, {0,0,0}},
{M_LN10, "LN10", 0, {0,0,0}},
{M_PI, "PI", 0, {0,0,0}},
{M_SQRT2, "SQRT2", 0, {0,0,0}},
{M_SQRT1_2, "SQRT1_2", 0, {0,0,0}},
{0,0,0,{0,0,0}}
};
static JSClass math_class = {
"Math",
0,
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
JSCLASS_NO_OPTIONAL_MEMBERS
};
static JSBool
math_abs(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, z;
if (!js_ValueToNumber(cx, argv[0], &x))
return JS_FALSE;
z = fd_fabs(x);
return js_NewNumberValue(cx, z, rval);
}
static JSBool
math_acos(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, z;
if (!js_ValueToNumber(cx, argv[0], &x))
return JS_FALSE;
z = fd_acos(x);
return js_NewNumberValue(cx, z, rval);
}
static JSBool
math_asin(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, z;
if (!js_ValueToNumber(cx, argv[0], &x))
return JS_FALSE;
#ifdef XP_MAC
if (x == 0)
return js_NewNumberValue(cx, x, rval);
#endif
z = fd_asin(x);
return js_NewNumberValue(cx, z, rval);
}
static JSBool
math_atan(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, z;
if (!js_ValueToNumber(cx, argv[0], &x))
return JS_FALSE;
#ifdef XP_MAC
if (x == 0)
return js_NewNumberValue(cx, x, rval);
#endif
z = fd_atan(x);
return js_NewNumberValue(cx, z, rval);
}
static JSBool
math_atan2(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, y, z;
if (!js_ValueToNumber(cx, argv[0], &x))
return JS_FALSE;
if (!js_ValueToNumber(cx, argv[1], &y))
return JS_FALSE;
z = fd_atan2(x, y);
return js_NewNumberValue(cx, z, rval);
}
static JSBool
math_ceil(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, z;
if (!js_ValueToNumber(cx, argv[0], &x))
return JS_FALSE;
z = fd_ceil(x);
return js_NewNumberValue(cx, z, rval);
}
static JSBool
math_cos(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, z;
if (!js_ValueToNumber(cx, argv[0], &x))
return JS_FALSE;
z = fd_cos(x);
return js_NewNumberValue(cx, z, rval);
}
static JSBool
math_exp(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, z;
if (!js_ValueToNumber(cx, argv[0], &x))
return JS_FALSE;
#ifdef _WIN32
if (!JSDOUBLE_IS_NaN(x)) {
if (x == *cx->runtime->jsPositiveInfinity) {
*rval = DOUBLE_TO_JSVAL(cx->runtime->jsPositiveInfinity);
return JS_TRUE;
}
if (x == *cx->runtime->jsNegativeInfinity) {
*rval = JSVAL_ZERO;
return JS_TRUE;
}
}
#endif
z = fd_exp(x);
return js_NewNumberValue(cx, z, rval);
}
static JSBool
math_floor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, z;
if (!js_ValueToNumber(cx, argv[0], &x))
return JS_FALSE;
z = fd_floor(x);
return js_NewNumberValue(cx, z, rval);
}
static JSBool
math_log(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, z;
if (!js_ValueToNumber(cx, argv[0], &x))
return JS_FALSE;
z = fd_log(x);
return js_NewNumberValue(cx, z, rval);
}
static JSBool
math_max(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, z = *cx->runtime->jsNegativeInfinity;
uintN i;
if (argc == 0) {
*rval = DOUBLE_TO_JSVAL(cx->runtime->jsNegativeInfinity);
return JS_TRUE;
}
for (i = 0; i < argc; i++) {
if (!js_ValueToNumber(cx, argv[i], &x))
return JS_FALSE;
if (JSDOUBLE_IS_NaN(x)) {
*rval = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
return JS_TRUE;
}
if ((x==0)&&(x==z)&&(fd_copysign(1.0,z)==-1))
z = x;
else
z = (x > z) ? x : z;
}
return js_NewNumberValue(cx, z, rval);
}
static JSBool
math_min(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, z = *cx->runtime->jsPositiveInfinity;
uintN i;
if (argc == 0) {
*rval = DOUBLE_TO_JSVAL(cx->runtime->jsPositiveInfinity);
return JS_TRUE;
}
for (i = 0; i < argc; i++) {
if (!js_ValueToNumber(cx, argv[i], &x))
return JS_FALSE;
if (JSDOUBLE_IS_NaN(x)) {
*rval = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
return JS_TRUE;
}
if ((x==0)&&(x==z)&&(fd_copysign(1.0,x)==-1))
z = x;
else
z = (x < z) ? x : z;
}
return js_NewNumberValue(cx, z, rval);
}
static JSBool
math_pow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, y, z;
if (!js_ValueToNumber(cx, argv[0], &x))
return JS_FALSE;
if (!js_ValueToNumber(cx, argv[1], &y))
return JS_FALSE;
z = fd_pow(x, y);
return js_NewNumberValue(cx, z, rval);
}
/*
* Math.random() support, lifted from java.util.Random.java.
*/
static void
random_setSeed(JSRuntime *rt, int64 seed)
{
int64 tmp;
JSLL_I2L(tmp, 1000);
JSLL_DIV(seed, seed, tmp);
JSLL_XOR(tmp, seed, rt->rngMultiplier);
JSLL_AND(rt->rngSeed, tmp, rt->rngMask);
}
static void
random_init(JSRuntime *rt)
{
int64 tmp, tmp2;
/* Do at most once. */
if (rt->rngInitialized)
return;
rt->rngInitialized = JS_TRUE;
/* rt->rngMultiplier = 0x5DEECE66DL */
JSLL_ISHL(tmp, 0x5, 32);
JSLL_UI2L(tmp2, 0xDEECE66DL);
JSLL_OR(rt->rngMultiplier, tmp, tmp2);
/* rt->rngAddend = 0xBL */
JSLL_I2L(rt->rngAddend, 0xBL);
/* rt->rngMask = (1L << 48) - 1 */
JSLL_I2L(tmp, 1);
JSLL_SHL(tmp2, tmp, 48);
JSLL_SUB(rt->rngMask, tmp2, tmp);
/* rt->rngDscale = (jsdouble)(1L << 53) */
JSLL_SHL(tmp2, tmp, 53);
JSLL_L2D(rt->rngDscale, tmp2);
/* Finally, set the seed from current time. */
random_setSeed(rt, PRMJ_Now());
}
static uint32
random_next(JSRuntime *rt, int bits)
{
int64 nextseed, tmp;
uint32 retval;
JSLL_MUL(nextseed, rt->rngSeed, rt->rngMultiplier);
JSLL_ADD(nextseed, nextseed, rt->rngAddend);
JSLL_AND(nextseed, nextseed, rt->rngMask);
rt->rngSeed = nextseed;
JSLL_USHR(tmp, nextseed, 48 - bits);
JSLL_L2I(retval, tmp);
return retval;
}
static jsdouble
random_nextDouble(JSRuntime *rt)
{
int64 tmp, tmp2;
jsdouble d;
JSLL_ISHL(tmp, random_next(rt, 26), 27);
JSLL_UI2L(tmp2, random_next(rt, 27));
JSLL_ADD(tmp, tmp, tmp2);
JSLL_L2D(d, tmp);
return d / rt->rngDscale;
}
static JSBool
math_random(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
JSRuntime *rt;
jsdouble z;
rt = cx->runtime;
JS_LOCK_RUNTIME(rt);
random_init(rt);
z = random_nextDouble(rt);
JS_UNLOCK_RUNTIME(rt);
return js_NewNumberValue(cx, z, rval);
}
static JSBool
math_round(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, z;
if (!js_ValueToNumber(cx, argv[0], &x))
return JS_FALSE;
z = fd_copysign(fd_floor(x + 0.5), x);
return js_NewNumberValue(cx, z, rval);
}
static JSBool
math_sin(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, z;
if (!js_ValueToNumber(cx, argv[0], &x))
return JS_FALSE;
z = fd_sin(x);
return js_NewNumberValue(cx, z, rval);
}
static JSBool
math_sqrt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, z;
if (!js_ValueToNumber(cx, argv[0], &x))
return JS_FALSE;
z = fd_sqrt(x);
return js_NewNumberValue(cx, z, rval);
}
static JSBool
math_tan(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, z;
if (!js_ValueToNumber(cx, argv[0], &x))
return JS_FALSE;
z = fd_tan(x);
return js_NewNumberValue(cx, z, rval);
}
#if JS_HAS_TOSOURCE
static JSBool
math_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
{
*rval = ATOM_KEY(cx->runtime->atomState.MathAtom);
return JS_TRUE;
}
#endif
static JSFunctionSpec math_static_methods[] = {
#if JS_HAS_TOSOURCE
{js_toSource_str, math_toSource, 0, 0, 0},
#endif
{"abs", math_abs, 1, 0, 0},
{"acos", math_acos, 1, 0, 0},
{"asin", math_asin, 1, 0, 0},
{"atan", math_atan, 1, 0, 0},
{"atan2", math_atan2, 2, 0, 0},
{"ceil", math_ceil, 1, 0, 0},
{"cos", math_cos, 1, 0, 0},
{"exp", math_exp, 1, 0, 0},
{"floor", math_floor, 1, 0, 0},
{"log", math_log, 1, 0, 0},
{"max", math_max, 2, 0, 0},
{"min", math_min, 2, 0, 0},
{"pow", math_pow, 2, 0, 0},
{"random", math_random, 0, 0, 0},
{"round", math_round, 1, 0, 0},
{"sin", math_sin, 1, 0, 0},
{"sqrt", math_sqrt, 1, 0, 0},
{"tan", math_tan, 1, 0, 0},
{0,0,0,0,0}
};
JSObject *
js_InitMathClass(JSContext *cx, JSObject *obj)
{
JSObject *Math;
Math = JS_DefineObject(cx, obj, "Math", &math_class, NULL, 0);
if (!Math)
return NULL;
if (!JS_DefineFunctions(cx, Math, math_static_methods))
return NULL;
if (!JS_DefineConstDoubles(cx, Math, math_constants))
return NULL;
return Math;
}

View File

@@ -1,55 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* -*- Mode: C; tab-width: 8 -*-
* Copyright (C) 1998-1999 Netscape Communications Corporation, All Rights Reserved.
*/
#ifndef jsmath_h___
#define jsmath_h___
/*
* JS math functions.
*/
JS_BEGIN_EXTERN_C
extern JSObject *
js_InitMathClass(JSContext *cx, JSObject *obj);
JS_END_EXTERN_C
#endif /* jsmath_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,268 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsnum_h___
#define jsnum_h___
/*
* JS number (IEEE double) interface.
*
* JS numbers are optimistically stored in the top 31 bits of 32-bit integers,
* but floating point literals, results that overflow 31 bits, and division and
* modulus operands and results require a 64-bit IEEE double. These are GC'ed
* and pointed to by 32-bit jsvals on the stack and in object properties.
*
* When a JS number is treated as an object (followed by . or []), the runtime
* wraps it with a JSObject whose valueOf method returns the unwrapped number.
*/
JS_BEGIN_EXTERN_C
/*
* Stefan Hanske <sh990154@mail.uni-greifswald.de> reports:
* ARM is a little endian architecture but 64 bit double words are stored
* differently: the 32 bit words are in little endian byte order, the two words
* are stored in big endian`s way.
*/
#if defined(__arm) || defined(__arm32__) || defined(__arm26__) || defined(__arm__)
#define CPU_IS_ARM
#endif
typedef union jsdpun {
struct {
#if defined(IS_LITTLE_ENDIAN) && !defined(CPU_IS_ARM)
uint32 lo, hi;
#else
uint32 hi, lo;
#endif
} s;
jsdouble d;
} jsdpun;
#if (__GNUC__ == 2 && __GNUC_MINOR__ > 95) || __GNUC__ > 2
/*
* This version of the macros is safe for the alias optimizations that gcc
* does, but uses gcc-specific extensions.
*/
#define JSDOUBLE_HI32(x) (__extension__ ({ jsdpun u; u.d = (x); u.s.hi; }))
#define JSDOUBLE_LO32(x) (__extension__ ({ jsdpun u; u.d = (x); u.s.lo; }))
#define JSDOUBLE_SET_HI32(x, y) \
(__extension__ ({ jsdpun u; u.d = (x); u.s.hi = (y); (x) = u.d; }))
#define JSDOUBLE_SET_LO32(x, y) \
(__extension__ ({ jsdpun u; u.d = (x); u.s.lo = (y); (x) = u.d; }))
#else /* not or old GNUC */
/*
* We don't know of any non-gcc compilers that perform alias optimization,
* so this code should work.
*/
#if defined(IS_LITTLE_ENDIAN) && !defined(CPU_IS_ARM)
#define JSDOUBLE_HI32(x) (((uint32 *)&(x))[1])
#define JSDOUBLE_LO32(x) (((uint32 *)&(x))[0])
#else
#define JSDOUBLE_HI32(x) (((uint32 *)&(x))[0])
#define JSDOUBLE_LO32(x) (((uint32 *)&(x))[1])
#endif
#define JSDOUBLE_SET_HI32(x, y) (JSDOUBLE_HI32(x)=(y))
#define JSDOUBLE_SET_LO32(x, y) (JSDOUBLE_LO32(x)=(y))
#endif /* not or old GNUC */
#define JSDOUBLE_HI32_SIGNBIT 0x80000000
#define JSDOUBLE_HI32_EXPMASK 0x7ff00000
#define JSDOUBLE_HI32_MANTMASK 0x000fffff
#define JSDOUBLE_IS_NaN(x) \
((JSDOUBLE_HI32(x) & JSDOUBLE_HI32_EXPMASK) == JSDOUBLE_HI32_EXPMASK && \
(JSDOUBLE_LO32(x) || (JSDOUBLE_HI32(x) & JSDOUBLE_HI32_MANTMASK)))
#define JSDOUBLE_IS_INFINITE(x) \
((JSDOUBLE_HI32(x) & ~JSDOUBLE_HI32_SIGNBIT) == JSDOUBLE_HI32_EXPMASK && \
!JSDOUBLE_LO32(x))
#define JSDOUBLE_IS_FINITE(x) \
((JSDOUBLE_HI32(x) & JSDOUBLE_HI32_EXPMASK) != JSDOUBLE_HI32_EXPMASK)
#define JSDOUBLE_IS_NEGZERO(d) (JSDOUBLE_HI32(d) == JSDOUBLE_HI32_SIGNBIT && \
JSDOUBLE_LO32(d) == 0)
/*
* JSDOUBLE_IS_INT first checks that d is neither NaN nor infinite, to avoid
* raising SIGFPE on platforms such as Alpha Linux, then (only if the cast is
* safe) leaves i as (jsint)d. This also avoid anomalous NaN floating point
* comparisons under MSVC.
*/
#define JSDOUBLE_IS_INT(d, i) (JSDOUBLE_IS_FINITE(d) \
&& !JSDOUBLE_IS_NEGZERO(d) \
&& ((d) == (i = (jsint)(d))))
#if defined(XP_WIN)
#define JSDOUBLE_COMPARE(LVAL, OP, RVAL, IFNAN) \
((JSDOUBLE_IS_NaN(LVAL) || JSDOUBLE_IS_NaN(RVAL)) \
? (IFNAN) \
: (LVAL) OP (RVAL))
#else
#define JSDOUBLE_COMPARE(LVAL, OP, RVAL, IFNAN) ((LVAL) OP (RVAL))
#endif
/* Initialize number constants and runtime state for the first context. */
extern JSBool
js_InitRuntimeNumberState(JSContext *cx);
extern void
js_FinishRuntimeNumberState(JSContext *cx);
/* Initialize the Number class, returning its prototype object. */
extern JSClass js_NumberClass;
extern JSObject *
js_InitNumberClass(JSContext *cx, JSObject *obj);
/*
* String constants for global function names, used in jsapi.c and jsnum.c.
*/
extern const char js_Infinity_str[];
extern const char js_NaN_str[];
extern const char js_isNaN_str[];
extern const char js_isFinite_str[];
extern const char js_parseFloat_str[];
extern const char js_parseInt_str[];
/* GC-allocate a new JS number. */
extern jsdouble *
js_NewDouble(JSContext *cx, jsdouble d, uintN gcflag);
extern void
js_FinalizeDouble(JSContext *cx, jsdouble *dp);
extern JSBool
js_NewDoubleValue(JSContext *cx, jsdouble d, jsval *rval);
extern JSBool
js_NewNumberValue(JSContext *cx, jsdouble d, jsval *rval);
/* Construct a Number instance that wraps around d. */
extern JSObject *
js_NumberToObject(JSContext *cx, jsdouble d);
/* Convert a number to a GC'ed string. */
extern JSString *
js_NumberToString(JSContext *cx, jsdouble d);
/*
* Convert a value to a number, returning false after reporting any error,
* otherwise returning true with *dp set.
*/
extern JSBool
js_ValueToNumber(JSContext *cx, jsval v, jsdouble *dp);
/*
* Convert a value or a double to an int32, according to the ECMA rules
* for ToInt32.
*/
extern JSBool
js_ValueToECMAInt32(JSContext *cx, jsval v, int32 *ip);
extern JSBool
js_DoubleToECMAInt32(JSContext *cx, jsdouble d, int32 *ip);
/*
* Convert a value or a double to a uint32, according to the ECMA rules
* for ToUint32.
*/
extern JSBool
js_ValueToECMAUint32(JSContext *cx, jsval v, uint32 *ip);
extern JSBool
js_DoubleToECMAUint32(JSContext *cx, jsdouble d, uint32 *ip);
/*
* Convert a value to a number, then to an int32 if it fits by rounding to
* nearest; but failing with an error report if the double is out of range
* or unordered.
*/
extern JSBool
js_ValueToInt32(JSContext *cx, jsval v, int32 *ip);
/*
* Convert a value to a number, then to a uint16 according to the ECMA rules
* for ToUint16.
*/
extern JSBool
js_ValueToUint16(JSContext *cx, jsval v, uint16 *ip);
/*
* Convert a jsdouble to an integral number, stored in a jsdouble.
* If d is NaN, return 0. If d is an infinity, return it without conversion.
*/
extern jsdouble
js_DoubleToInteger(jsdouble d);
/*
* Similar to strtod except that it replaces overflows with infinities of the
* correct sign, and underflows with zeros of the correct sign. Guaranteed to
* return the closest double number to the given input in dp.
*
* Also allows inputs of the form [+|-]Infinity, which produce an infinity of
* the appropriate sign. The case of the "Infinity" string must match exactly.
* If the string does not contain a number, set *ep to s and return 0.0 in dp.
* Return false if out of memory.
*/
extern JSBool
js_strtod(JSContext *cx, const jschar *s, const jschar **ep, jsdouble *dp);
/*
* Similar to strtol except that it handles integers of arbitrary size.
* Guaranteed to return the closest double number to the given input when radix
* is 10 or a power of 2. Callers may see round-off errors for very large
* numbers of a different radix than 10 or a power of 2.
*
* If the string does not contain a number, set *ep to s and return 0.0 in dp.
* Return false if out of memory.
*/
extern JSBool
js_strtointeger(JSContext *cx, const jschar *s, const jschar **ep, jsint radix, jsdouble *dp);
JS_END_EXTERN_C
#endif /* jsnum_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,464 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsobj_h___
#define jsobj_h___
/*
* JS object definitions.
*
* A JS object consists of a possibly-shared object descriptor containing
* ordered property names, called the map; and a dense vector of property
* values, called slots. The map/slot pointer pair is GC'ed, while the map
* is reference counted and the slot vector is malloc'ed.
*/
#include "jshash.h" /* Added by JSIFY */
#include "jsprvtd.h"
#include "jspubtd.h"
JS_BEGIN_EXTERN_C
struct JSObjectMap {
jsrefcount nrefs; /* count of all referencing objects */
JSObjectOps *ops; /* high level object operation vtable */
uint32 nslots; /* length of obj->slots vector */
uint32 freeslot; /* index of next free obj->slots element */
};
/* Shorthand macros for frequently-made calls. */
#define OBJ_LOOKUP_PROPERTY(cx,obj,id,objp,propp) \
(obj)->map->ops->lookupProperty(cx,obj,id,objp,propp)
#define OBJ_DEFINE_PROPERTY(cx,obj,id,value,getter,setter,attrs,propp) \
(obj)->map->ops->defineProperty(cx,obj,id,value,getter,setter,attrs,propp)
#define OBJ_GET_PROPERTY(cx,obj,id,vp) \
(obj)->map->ops->getProperty(cx,obj,id,vp)
#define OBJ_SET_PROPERTY(cx,obj,id,vp) \
(obj)->map->ops->setProperty(cx,obj,id,vp)
#define OBJ_GET_ATTRIBUTES(cx,obj,id,prop,attrsp) \
(obj)->map->ops->getAttributes(cx,obj,id,prop,attrsp)
#define OBJ_SET_ATTRIBUTES(cx,obj,id,prop,attrsp) \
(obj)->map->ops->setAttributes(cx,obj,id,prop,attrsp)
#define OBJ_DELETE_PROPERTY(cx,obj,id,rval) \
(obj)->map->ops->deleteProperty(cx,obj,id,rval)
#define OBJ_DEFAULT_VALUE(cx,obj,hint,vp) \
(obj)->map->ops->defaultValue(cx,obj,hint,vp)
#define OBJ_ENUMERATE(cx,obj,enum_op,statep,idp) \
(obj)->map->ops->enumerate(cx,obj,enum_op,statep,idp)
#define OBJ_CHECK_ACCESS(cx,obj,id,mode,vp,attrsp) \
(obj)->map->ops->checkAccess(cx,obj,id,mode,vp,attrsp)
/* These four are time-optimized to avoid stub calls. */
#define OBJ_THIS_OBJECT(cx,obj) \
((obj)->map->ops->thisObject \
? (obj)->map->ops->thisObject(cx,obj) \
: (obj))
#define OBJ_DROP_PROPERTY(cx,obj,prop) \
((obj)->map->ops->dropProperty \
? (obj)->map->ops->dropProperty(cx,obj,prop) \
: (void)0)
#define OBJ_GET_REQUIRED_SLOT(cx,obj,slot) \
((obj)->map->ops->getRequiredSlot \
? (obj)->map->ops->getRequiredSlot(cx, obj, slot) \
: JSVAL_VOID)
#define OBJ_SET_REQUIRED_SLOT(cx,obj,slot,v) \
((obj)->map->ops->setRequiredSlot \
? (obj)->map->ops->setRequiredSlot(cx, obj, slot, v) \
: JS_TRUE)
/*
* In the original JS engine design, obj->slots pointed to a vector of length
* JS_INITIAL_NSLOTS words if obj->map was shared with a prototype object,
* else of length obj->map->nslots. With the advent of JS_GetReservedSlot,
* JS_SetReservedSlot, and JSCLASS_HAS_RESERVED_SLOTS (see jsapi.h), the size
* of the minimum length slots vector in the case where map is shared cannot
* be constant. This length starts at JS_INITIAL_NSLOTS, but may advance to
* include all the reserved slots.
*
* Therefore slots must be self-describing. Rather than tag its low order bit
* (a bit is all we need) to distinguish initial length from reserved length,
* we do "the BSTR thing": over-allocate slots by one jsval, and store the
* *net* length (counting usable slots, which have non-negative obj->slots[]
* indices) in obj->slots[-1]. All code that sets obj->slots must be aware of
* this hack -- you have been warned, and jsobj.c has been updated!
*/
struct JSObject {
JSObjectMap *map;
jsval *slots;
};
#define JSSLOT_PROTO 0
#define JSSLOT_PARENT 1
#define JSSLOT_CLASS 2
#define JSSLOT_PRIVATE 3
#define JSSLOT_START(clasp) (((clasp)->flags & JSCLASS_HAS_PRIVATE) \
? JSSLOT_PRIVATE + 1 \
: JSSLOT_CLASS + 1)
#define JSSLOT_FREE(clasp) (JSSLOT_START(clasp) \
+ JSCLASS_RESERVED_SLOTS(clasp))
#define JS_INITIAL_NSLOTS 5
#ifdef DEBUG
#define MAP_CHECK_SLOT(map,slot) \
JS_ASSERT((uint32)slot < JS_MIN((map)->freeslot, (map)->nslots))
#define OBJ_CHECK_SLOT(obj,slot) \
MAP_CHECK_SLOT((obj)->map, slot)
#else
#define OBJ_CHECK_SLOT(obj,slot) ((void)0)
#endif
/* Fast macros for accessing obj->slots while obj is locked (if thread-safe). */
#define LOCKED_OBJ_GET_SLOT(obj,slot) \
(OBJ_CHECK_SLOT(obj, slot), (obj)->slots[slot])
#define LOCKED_OBJ_SET_SLOT(obj,slot,value) \
(OBJ_CHECK_SLOT(obj, slot), (obj)->slots[slot] = (value))
#define LOCKED_OBJ_GET_PROTO(obj) \
JSVAL_TO_OBJECT(LOCKED_OBJ_GET_SLOT(obj, JSSLOT_PROTO))
#define LOCKED_OBJ_GET_CLASS(obj) \
((JSClass *)JSVAL_TO_PRIVATE(LOCKED_OBJ_GET_SLOT(obj, JSSLOT_CLASS)))
#ifdef JS_THREADSAFE
/* Thread-safe functions and wrapper macros for accessing obj->slots. */
#define OBJ_GET_SLOT(cx,obj,slot) \
(OBJ_CHECK_SLOT(obj, slot), \
(OBJ_IS_NATIVE(obj) && OBJ_SCOPE(obj)->ownercx == cx) \
? LOCKED_OBJ_GET_SLOT(obj, slot) \
: js_GetSlotThreadSafe(cx, obj, slot))
#define OBJ_SET_SLOT(cx,obj,slot,value) \
(OBJ_CHECK_SLOT(obj, slot), \
(OBJ_IS_NATIVE(obj) && OBJ_SCOPE(obj)->ownercx == cx) \
? (void) LOCKED_OBJ_SET_SLOT(obj, slot, value) \
: js_SetSlotThreadSafe(cx, obj, slot, value))
/*
* If thread-safe, define an OBJ_GET_SLOT wrapper that bypasses, for a native
* object, the lock-free "fast path" test of (OBJ_SCOPE(obj)->ownercx == cx),
* to avoid needlessly switching from lock-free to lock-full scope when doing
* GC on a different context from the last one to own the scope. The caller
* in this case is probably a JSClass.mark function, e.g., fun_mark, or maybe
* a finalizer.
*
* The GC runs only when all threads except the one on which the GC is active
* are suspended at GC-safe points, so there is no hazard in directly accessing
* obj->slots[slot] from the GC's thread, once rt->gcRunning has been set. See
* jsgc.c for details.
*/
#define THREAD_IS_RUNNING_GC(rt, thread) \
((rt)->gcRunning && (rt)->gcThread == (thread))
#define CX_THREAD_IS_RUNNING_GC(cx) \
THREAD_IS_RUNNING_GC((cx)->runtime, (cx)->thread)
#define GC_AWARE_GET_SLOT(cx, obj, slot) \
((OBJ_IS_NATIVE(obj) && CX_THREAD_IS_RUNNING_GC(cx)) \
? (obj)->slots[slot] \
: OBJ_GET_SLOT(cx, obj, slot))
#else /* !JS_THREADSAFE */
#define OBJ_GET_SLOT(cx,obj,slot) LOCKED_OBJ_GET_SLOT(obj,slot)
#define OBJ_SET_SLOT(cx,obj,slot,value) LOCKED_OBJ_SET_SLOT(obj,slot,value)
#define GC_AWARE_GET_SLOT(cx,obj,slot) LOCKED_OBJ_GET_SLOT(obj,slot)
#endif /* !JS_THREADSAFE */
/* Thread-safe proto, parent, and class access macros. */
#define OBJ_GET_PROTO(cx,obj) \
JSVAL_TO_OBJECT(OBJ_GET_SLOT(cx, obj, JSSLOT_PROTO))
#define OBJ_SET_PROTO(cx,obj,proto) \
OBJ_SET_SLOT(cx, obj, JSSLOT_PROTO, OBJECT_TO_JSVAL(proto))
#define OBJ_GET_PARENT(cx,obj) \
JSVAL_TO_OBJECT(OBJ_GET_SLOT(cx, obj, JSSLOT_PARENT))
#define OBJ_SET_PARENT(cx,obj,parent) \
OBJ_SET_SLOT(cx, obj, JSSLOT_PARENT, OBJECT_TO_JSVAL(parent))
#define OBJ_GET_CLASS(cx,obj) \
((JSClass *)JSVAL_TO_PRIVATE(OBJ_GET_SLOT(cx, obj, JSSLOT_CLASS)))
/* Test whether a map or object is native. */
#define MAP_IS_NATIVE(map) \
((map)->ops == &js_ObjectOps || \
((map)->ops && (map)->ops->newObjectMap == js_ObjectOps.newObjectMap))
#define OBJ_IS_NATIVE(obj) MAP_IS_NATIVE((obj)->map)
extern JS_FRIEND_DATA(JSObjectOps) js_ObjectOps;
extern JS_FRIEND_DATA(JSObjectOps) js_WithObjectOps;
extern JSClass js_ObjectClass;
extern JSClass js_WithClass;
struct JSSharpObjectMap {
jsrefcount depth;
jsatomid sharpgen;
JSHashTable *table;
};
#define SHARP_BIT ((jsatomid) 1)
#define BUSY_BIT ((jsatomid) 2)
#define SHARP_ID_SHIFT 2
#define IS_SHARP(he) ((jsatomid)(he)->value & SHARP_BIT)
#define MAKE_SHARP(he) ((he)->value = (void*)((jsatomid)(he)->value|SHARP_BIT))
#define IS_BUSY(he) ((jsatomid)(he)->value & BUSY_BIT)
#define MAKE_BUSY(he) ((he)->value = (void*)((jsatomid)(he)->value|BUSY_BIT))
#define CLEAR_BUSY(he) ((he)->value = (void*)((jsatomid)(he)->value&~BUSY_BIT))
extern JSHashEntry *
js_EnterSharpObject(JSContext *cx, JSObject *obj, JSIdArray **idap,
jschar **sp);
extern void
js_LeaveSharpObject(JSContext *cx, JSIdArray **idap);
extern JSBool
js_obj_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval);
extern JSBool
js_obj_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval);
extern JSBool
js_HasOwnPropertyHelper(JSContext *cx, JSObject *obj, JSLookupPropOp lookup,
uintN argc, jsval *argv, jsval *rval);
extern JSObject *
js_InitObjectClass(JSContext *cx, JSObject *obj);
/* Select Object.prototype method names shared between jsapi.c and jsobj.c. */
extern const char js_watch_str[];
extern const char js_unwatch_str[];
extern const char js_hasOwnProperty_str[];
extern const char js_isPrototypeOf_str[];
extern const char js_propertyIsEnumerable_str[];
extern const char js_defineGetter_str[];
extern const char js_defineSetter_str[];
extern const char js_lookupGetter_str[];
extern const char js_lookupSetter_str[];
extern void
js_InitObjectMap(JSObjectMap *map, jsrefcount nrefs, JSObjectOps *ops,
JSClass *clasp);
extern JSObjectMap *
js_NewObjectMap(JSContext *cx, jsrefcount nrefs, JSObjectOps *ops,
JSClass *clasp, JSObject *obj);
extern void
js_DestroyObjectMap(JSContext *cx, JSObjectMap *map);
extern JSObjectMap *
js_HoldObjectMap(JSContext *cx, JSObjectMap *map);
extern JSObjectMap *
js_DropObjectMap(JSContext *cx, JSObjectMap *map, JSObject *obj);
extern JSObject *
js_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent);
extern JSBool
js_FindConstructor(JSContext *cx, JSObject *start, const char *name, jsval *vp);
extern JSObject *
js_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto,
JSObject *parent, uintN argc, jsval *argv);
extern void
js_FinalizeObject(JSContext *cx, JSObject *obj);
extern JSBool
js_AllocSlot(JSContext *cx, JSObject *obj, uint32 *slotp);
extern void
js_FreeSlot(JSContext *cx, JSObject *obj, uint32 slot);
/*
* Find or create a property named by id in obj's scope, with the given getter
* and setter, slot, attributes, and other members.
*/
extern JSScopeProperty *
js_AddNativeProperty(JSContext *cx, JSObject *obj, jsid id,
JSPropertyOp getter, JSPropertyOp setter, uint32 slot,
uintN attrs, uintN flags, intN shortid);
/*
* Change sprop to have the given attrs, getter, and setter in scope, morphing
* it into a potentially new JSScopeProperty. Return a pointer to the changed
* or identical property.
*/
extern JSScopeProperty *
js_ChangeNativePropertyAttrs(JSContext *cx, JSObject *obj,
JSScopeProperty *sprop, uintN attrs, uintN mask,
JSPropertyOp getter, JSPropertyOp setter);
/*
* On error, return false. On success, if propp is non-null, return true with
* obj locked and with a held property in *propp; if propp is null, return true
* but release obj's lock first. Therefore all callers who pass non-null propp
* result parameters must later call OBJ_DROP_PROPERTY(cx, obj, *propp) both to
* drop the held property, and to release the lock on obj.
*/
extern JSBool
js_DefineProperty(JSContext *cx, JSObject *obj, jsid id, jsval value,
JSPropertyOp getter, JSPropertyOp setter, uintN attrs,
JSProperty **propp);
extern JSBool
js_DefineNativeProperty(JSContext *cx, JSObject *obj, jsid id, jsval value,
JSPropertyOp getter, JSPropertyOp setter, uintN attrs,
uintN flags, intN shortid, JSProperty **propp);
/*
* Unlike js_DefineProperty, propp must be non-null. On success, and if id was
* found, return true with *objp non-null and locked, and with a held property
* stored in *propp. If successful but id was not found, return true with both
* *objp and *propp null. Therefore all callers who receive a non-null *propp
* must later call OBJ_DROP_PROPERTY(cx, *objp, *propp).
*/
extern JS_FRIEND_API(JSBool)
js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
JSProperty **propp);
/*
* Specialized subroutine that allows caller to preset JSRESOLVE_* flags.
*/
extern JSBool
js_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, jsid id, uintN flags,
JSObject **objp, JSProperty **propp);
extern JS_FRIEND_API(JSBool)
js_FindProperty(JSContext *cx, jsid id, JSObject **objp, JSObject **pobjp,
JSProperty **propp);
extern JSObject *
js_FindIdentifierBase(JSContext *cx, jsid id);
extern JSObject *
js_FindVariableScope(JSContext *cx, JSFunction **funp);
extern JSBool
js_GetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
extern JSBool
js_SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
extern JSBool
js_GetAttributes(JSContext *cx, JSObject *obj, jsid id, JSProperty *prop,
uintN *attrsp);
extern JSBool
js_SetAttributes(JSContext *cx, JSObject *obj, jsid id, JSProperty *prop,
uintN *attrsp);
extern JSBool
js_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, jsval *rval);
extern JSBool
js_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp);
extern JSIdArray *
js_NewIdArray(JSContext *cx, jsint length);
extern JSIdArray *
js_GrowIdArray(JSContext *cx, JSIdArray *ida, jsint length);
extern JSBool
js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
jsval *statep, jsid *idp);
extern JSBool
js_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
jsval *vp, uintN *attrsp);
extern JSBool
js_Call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
extern JSBool
js_Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval);
extern JSBool
js_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);
extern JSBool
js_SetProtoOrParent(JSContext *cx, JSObject *obj, uint32 slot, JSObject *pobj);
extern JSBool
js_IsDelegate(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);
extern JSBool
js_GetClassPrototype(JSContext *cx, const char *name, JSObject **protop);
extern JSBool
js_SetClassPrototype(JSContext *cx, JSObject *ctor, JSObject *proto,
uintN attrs);
extern JSBool
js_ValueToObject(JSContext *cx, jsval v, JSObject **objp);
extern JSObject *
js_ValueToNonNullObject(JSContext *cx, jsval v);
extern JSBool
js_TryValueOf(JSContext *cx, JSObject *obj, JSType type, jsval *rval);
extern JSBool
js_TryMethod(JSContext *cx, JSObject *obj, JSAtom *atom,
uintN argc, jsval *argv, jsval *rval);
extern JSBool
js_XDRObject(JSXDRState *xdr, JSObject **objp);
extern uint32
js_Mark(JSContext *cx, JSObject *obj, void *arg);
extern void
js_Clear(JSContext *cx, JSObject *obj);
extern jsval
js_GetRequiredSlot(JSContext *cx, JSObject *obj, uint32 slot);
extern JSBool
js_SetRequiredSlot(JSContext *cx, JSObject *obj, uint32 slot, jsval v);
JS_END_EXTERN_C
#endif /* jsobj_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,278 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsopcode_h___
#define jsopcode_h___
/*
* JS bytecode definitions.
*/
#include <stddef.h>
#include "jsprvtd.h"
#include "jspubtd.h"
JS_BEGIN_EXTERN_C
/*
* JS operation bytecodes.
*/
typedef enum JSOp {
#define OPDEF(op,val,name,token,length,nuses,ndefs,prec,format) \
op = val,
#include "jsopcode.tbl"
#undef OPDEF
JSOP_LIMIT
} JSOp;
/*
* JS bytecode formats.
*/
#define JOF_BYTE 0 /* single bytecode, no immediates */
#define JOF_JUMP 1 /* signed 16-bit jump offset immediate */
#define JOF_CONST 2 /* unsigned 16-bit constant pool index */
#define JOF_UINT16 3 /* unsigned 16-bit immediate operand */
#define JOF_TABLESWITCH 4 /* table switch */
#define JOF_LOOKUPSWITCH 5 /* lookup switch */
#define JOF_QARG 6 /* quickened get/set function argument ops */
#define JOF_QVAR 7 /* quickened get/set local variable ops */
#define JOF_INDEXCONST 8 /* arg or var index + constant pool index */
#define JOF_JUMPX 9 /* signed 32-bit jump offset immediate */
#define JOF_TABLESWITCHX 10 /* extended (32-bit offset) table switch */
#define JOF_LOOKUPSWITCHX 11 /* extended (32-bit offset) lookup switch */
#define JOF_CONST2 12 /* 2 unsigned 16-bit constant pool indexes */
#define JOF_TYPEMASK 0x000f /* mask for above immediate types */
#define JOF_NAME 0x0010 /* name operation */
#define JOF_PROP 0x0020 /* obj.prop operation */
#define JOF_ELEM 0x0030 /* obj[index] operation */
#define JOF_MODEMASK 0x0030 /* mask for above addressing modes */
#define JOF_SET 0x0040 /* set (i.e., assignment) operation */
#define JOF_DEL 0x0080 /* delete operation */
#define JOF_DEC 0x0100 /* decrement (--, not ++) opcode */
#define JOF_INC 0x0200 /* increment (++, not --) opcode */
#define JOF_INCDEC 0x0300 /* increment or decrement opcode */
#define JOF_POST 0x0400 /* postorder increment or decrement */
#define JOF_IMPORT 0x0800 /* import property op */
#define JOF_FOR 0x1000 /* for-in property op */
#define JOF_ASSIGNING JOF_SET /* hint for JSClass.resolve, used for ops
that do simplex assignment */
#define JOF_DETECTING 0x2000 /* object detection flag for JSNewResolveOp */
#define JOF_BACKPATCH 0x4000 /* backpatch placeholder during codegen */
#define JOF_LEFTASSOC 0x8000 /* left-associative operator */
#define JOF_DECLARING 0x10000 /* var, const, or function declaration op */
#define JOF_XMLNAME 0x20000 /* XML name: *, a::b, @a, @a::b, etc. */
#define JOF_TYPE_IS_EXTENDED_JUMP(t) \
((unsigned)((t) - JOF_JUMPX) <= (unsigned)(JOF_LOOKUPSWITCHX - JOF_JUMPX))
/*
* Immediate operand getters, setters, and bounds.
*/
/* Short (2-byte signed offset) relative jump macros. */
#define JUMP_OFFSET_LEN 2
#define JUMP_OFFSET_HI(off) ((jsbytecode)((off) >> 8))
#define JUMP_OFFSET_LO(off) ((jsbytecode)(off))
#define GET_JUMP_OFFSET(pc) ((int16)(((pc)[1] << 8) | (pc)[2]))
#define SET_JUMP_OFFSET(pc,off) ((pc)[1] = JUMP_OFFSET_HI(off), \
(pc)[2] = JUMP_OFFSET_LO(off))
#define JUMP_OFFSET_MIN ((int16)0x8000)
#define JUMP_OFFSET_MAX ((int16)0x7fff)
/*
* When a short jump won't hold a relative offset, its 2-byte immediate offset
* operand is an unsigned index of a span-dependency record, maintained until
* code generation finishes -- after which some (but we hope not nearly all)
* span-dependent jumps must be extended (see OptimizeSpanDeps in jsemit.c).
*
* If the span-dependency record index overflows SPANDEP_INDEX_MAX, the jump
* offset will contain SPANDEP_INDEX_HUGE, indicating that the record must be
* found (via binary search) by its "before span-dependency optimization" pc
* offset (from script main entry point).
*/
#define GET_SPANDEP_INDEX(pc) ((uint16)(((pc)[1] << 8) | (pc)[2]))
#define SET_SPANDEP_INDEX(pc,i) ((pc)[1] = JUMP_OFFSET_HI(i), \
(pc)[2] = JUMP_OFFSET_LO(i))
#define SPANDEP_INDEX_MAX ((uint16)0xfffe)
#define SPANDEP_INDEX_HUGE ((uint16)0xffff)
/* Ultimately, if short jumps won't do, emit long (4-byte signed) offsets. */
#define JUMPX_OFFSET_LEN 4
#define JUMPX_OFFSET_B3(off) ((jsbytecode)((off) >> 24))
#define JUMPX_OFFSET_B2(off) ((jsbytecode)((off) >> 16))
#define JUMPX_OFFSET_B1(off) ((jsbytecode)((off) >> 8))
#define JUMPX_OFFSET_B0(off) ((jsbytecode)(off))
#define GET_JUMPX_OFFSET(pc) ((int32)(((pc)[1] << 24) | ((pc)[2] << 16) \
| ((pc)[3] << 8) | (pc)[4]))
#define SET_JUMPX_OFFSET(pc,off)((pc)[1] = JUMPX_OFFSET_B3(off), \
(pc)[2] = JUMPX_OFFSET_B2(off), \
(pc)[3] = JUMPX_OFFSET_B1(off), \
(pc)[4] = JUMPX_OFFSET_B0(off))
#define JUMPX_OFFSET_MIN ((int32)0x80000000)
#define JUMPX_OFFSET_MAX ((int32)0x7fffffff)
/* A literal is indexed by a per-script atom map. */
#define ATOM_INDEX_LEN 2
#define ATOM_INDEX_HI(index) ((jsbytecode)((index) >> 8))
#define ATOM_INDEX_LO(index) ((jsbytecode)(index))
#define GET_ATOM_INDEX(pc) ((jsatomid)(((pc)[1] << 8) | (pc)[2]))
#define SET_ATOM_INDEX(pc,index)((pc)[1] = ATOM_INDEX_HI(index), \
(pc)[2] = ATOM_INDEX_LO(index))
#define GET_ATOM(cx,script,pc) js_GetAtom((cx), &(script)->atomMap, \
GET_ATOM_INDEX(pc))
#define ATOM_INDEX_LIMIT_LOG2 16
#define ATOM_INDEX_LIMIT ((uint32)1 << ATOM_INDEX_LIMIT_LOG2)
/* Actual argument count operand format helpers. */
#define ARGC_HI(argc) ((jsbytecode)((argc) >> 8))
#define ARGC_LO(argc) ((jsbytecode)(argc))
#define GET_ARGC(pc) ((uintN)(((pc)[1] << 8) | (pc)[2]))
#define ARGC_LIMIT ((uint32)1 << 16)
/* Synonyms for quick JOF_QARG and JOF_QVAR bytecodes. */
#define GET_ARGNO(pc) GET_ARGC(pc)
#define SET_ARGNO(pc,argno) SET_JUMP_OFFSET(pc,argno)
#define ARGNO_LEN JUMP_OFFSET_LEN
#define GET_VARNO(pc) GET_ARGC(pc)
#define SET_VARNO(pc,varno) SET_JUMP_OFFSET(pc,varno)
#define VARNO_LEN JUMP_OFFSET_LEN
struct JSCodeSpec {
const char *name; /* JS bytecode name */
const char *token; /* JS source literal or null */
int8 length; /* length including opcode byte */
int8 nuses; /* arity, -1 if variadic */
int8 ndefs; /* number of stack results */
uint8 prec; /* operator precedence */
uint32 format; /* immediate operand format */
};
extern const char js_const_str[];
extern const char js_var_str[];
extern const char js_function_str[];
extern const char js_in_str[];
extern const char js_instanceof_str[];
extern const char js_new_str[];
extern const char js_delete_str[];
extern const char js_typeof_str[];
extern const char js_void_str[];
extern const char js_null_str[];
extern const char js_this_str[];
extern const char js_false_str[];
extern const char js_true_str[];
extern const char js_default_str[];
extern const JSCodeSpec js_CodeSpec[];
extern uintN js_NumCodeSpecs;
extern const jschar js_EscapeMap[];
/*
* Return a GC'ed string containing the chars in str, with any non-printing
* chars or quotes (' or " as specified by the quote argument) escaped, and
* with the quote character at the beginning and end of the result string.
*/
extern JSString *
js_QuoteString(JSContext *cx, JSString *str, jschar quote);
/*
* JSPrinter operations, for printf style message formatting. The return
* value from js_GetPrinterOutput() is the printer's cumulative output, in
* a GC'ed string.
*/
extern JSPrinter *
js_NewPrinter(JSContext *cx, const char *name, uintN indent, JSBool pretty);
extern void
js_DestroyPrinter(JSPrinter *jp);
extern JSString *
js_GetPrinterOutput(JSPrinter *jp);
extern int
js_printf(JSPrinter *jp, const char *format, ...);
extern JSBool
js_puts(JSPrinter *jp, const char *s);
#ifdef DEBUG
/*
* Disassemblers, for debugging only.
*/
#include <stdio.h>
extern JS_FRIEND_API(void)
js_Disassemble(JSContext *cx, JSScript *script, JSBool lines, FILE *fp);
extern JS_FRIEND_API(uintN)
js_Disassemble1(JSContext *cx, JSScript *script, jsbytecode *pc, uintN loc,
JSBool lines, FILE *fp);
#endif /* DEBUG */
/*
* Decompilers, for script, function, and expression pretty-printing.
*/
extern JSBool
js_DecompileCode(JSPrinter *jp, JSScript *script, jsbytecode *pc, uintN len);
extern JSBool
js_DecompileScript(JSPrinter *jp, JSScript *script);
extern JSBool
js_DecompileFunctionBody(JSPrinter *jp, JSFunction *fun);
extern JSBool
js_DecompileFunction(JSPrinter *jp, JSFunction *fun);
/*
* Find the source expression that resulted in v, and return a new string
* containing it. Fall back on v's string conversion (fallback) if we can't
* find the bytecode that generated and pushed v on the operand stack.
*
* Search the current stack frame if spindex is JSDVG_SEARCH_STACK. Don't
* look for v on the stack if spindex is JSDVG_IGNORE_STACK. Otherwise,
* spindex is the negative index of v, measured from cx->fp->sp, or from a
* lower frame's sp if cx->fp is native.
*/
extern JSString *
js_DecompileValueGenerator(JSContext *cx, intN spindex, jsval v,
JSString *fallback);
#define JSDVG_IGNORE_STACK 0
#define JSDVG_SEARCH_STACK 1
JS_END_EXTERN_C
#endif /* jsopcode_h___ */

View File

@@ -1,373 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* JavaScript operation bytecodes. If you need to allocate a bytecode, look
* for a name of the form JSOP_UNUSED* and claim it. Otherwise, always add at
* the end of the table.
*
* Includers must define an OPDEF macro of the following form:
*
* #define OPDEF(op,val,name,image,length,nuses,ndefs,prec,format) ...
*
* Selected arguments can be expanded in initializers. The op argument is
* expanded followed by comma in the JSOp enum (jsopcode.h), e.g. The value
* field must be dense for now, because jsopcode.c uses an OPDEF() expansion
* inside the js_CodeSpec[] initializer.
*
* Field Description
* op Bytecode name, which is the JSOp enumerator name
* value Bytecode value, which is the JSOp enumerator value
* name C string containing name for disassembler
* image C string containing "image" for pretty-printer, null if ugly
* length Number of bytes including any immediate operands
* nuses Number of stack slots consumed by bytecode, -1 if variadic
* ndefs Number of stack slots produced by bytecode
* prec Operator precedence, zero if not an operator
* format Bytecode plus immediate operand encoding format
*
* This file is best viewed with 116 columns:
01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
*/
/* legend: op val name image len use def prec format */
/* Longstanding JavaScript bytecodes. */
OPDEF(JSOP_NOP, 0, "nop", NULL, 1, 0, 0, 0, JOF_BYTE)
OPDEF(JSOP_PUSH, 1, "push", NULL, 1, 0, 1, 0, JOF_BYTE)
OPDEF(JSOP_POPV, 2, "popv", NULL, 1, 1, 0, 0, JOF_BYTE)
OPDEF(JSOP_ENTERWITH, 3, "enterwith", NULL, 1, 1, 1, 0, JOF_BYTE)
OPDEF(JSOP_LEAVEWITH, 4, "leavewith", NULL, 1, 1, 0, 0, JOF_BYTE)
OPDEF(JSOP_RETURN, 5, "return", NULL, 1, 1, 0, 0, JOF_BYTE)
OPDEF(JSOP_GOTO, 6, "goto", NULL, 3, 0, 0, 0, JOF_JUMP)
OPDEF(JSOP_IFEQ, 7, "ifeq", NULL, 3, 1, 0, 0, JOF_JUMP|JOF_DETECTING)
OPDEF(JSOP_IFNE, 8, "ifne", NULL, 3, 1, 0, 0, JOF_JUMP)
/* Get the arguments object for the current, lightweight function activation. */
OPDEF(JSOP_ARGUMENTS, 9, js_arguments_str, js_arguments_str, 1, 0, 1, 12, JOF_BYTE)
/* ECMA-compliant for-in loop with argument or local variable loop control. */
OPDEF(JSOP_FORARG, 10, "forarg", NULL, 3, 0, 1, 0, JOF_QARG|JOF_NAME|JOF_FOR)
OPDEF(JSOP_FORVAR, 11, "forvar", NULL, 3, 0, 1, 0, JOF_QVAR|JOF_NAME|JOF_FOR)
/* More longstanding bytecodes. */
OPDEF(JSOP_DUP, 12, "dup", NULL, 1, 1, 2, 0, JOF_BYTE)
OPDEF(JSOP_DUP2, 13, "dup2", NULL, 1, 2, 4, 0, JOF_BYTE)
OPDEF(JSOP_SETCONST, 14, "setconst", NULL, 3, 1, 1, 1, JOF_CONST|JOF_NAME|JOF_SET|JOF_ASSIGNING)
OPDEF(JSOP_BITOR, 15, "bitor", "|", 1, 2, 1, 2, JOF_BYTE|JOF_LEFTASSOC)
OPDEF(JSOP_BITXOR, 16, "bitxor", "^", 1, 2, 1, 3, JOF_BYTE|JOF_LEFTASSOC)
OPDEF(JSOP_BITAND, 17, "bitand", "&", 1, 2, 1, 4, JOF_BYTE|JOF_LEFTASSOC)
OPDEF(JSOP_EQ, 18, "eq", "==", 1, 2, 1, 5, JOF_BYTE|JOF_LEFTASSOC|JOF_DETECTING)
OPDEF(JSOP_NE, 19, "ne", "!=", 1, 2, 1, 5, JOF_BYTE|JOF_LEFTASSOC|JOF_DETECTING)
OPDEF(JSOP_LT, 20, "lt", "<", 1, 2, 1, 6, JOF_BYTE|JOF_LEFTASSOC)
OPDEF(JSOP_LE, 21, "le", "<=", 1, 2, 1, 6, JOF_BYTE|JOF_LEFTASSOC)
OPDEF(JSOP_GT, 22, "gt", ">", 1, 2, 1, 6, JOF_BYTE|JOF_LEFTASSOC)
OPDEF(JSOP_GE, 23, "ge", ">=", 1, 2, 1, 6, JOF_BYTE|JOF_LEFTASSOC)
OPDEF(JSOP_LSH, 24, "lsh", "<<", 1, 2, 1, 7, JOF_BYTE|JOF_LEFTASSOC)
OPDEF(JSOP_RSH, 25, "rsh", ">>", 1, 2, 1, 7, JOF_BYTE|JOF_LEFTASSOC)
OPDEF(JSOP_URSH, 26, "ursh", ">>>", 1, 2, 1, 7, JOF_BYTE|JOF_LEFTASSOC)
OPDEF(JSOP_ADD, 27, "add", "+", 1, 2, 1, 8, JOF_BYTE|JOF_LEFTASSOC)
OPDEF(JSOP_SUB, 28, "sub", "-", 1, 2, 1, 8, JOF_BYTE|JOF_LEFTASSOC)
OPDEF(JSOP_MUL, 29, "mul", "*", 1, 2, 1, 9, JOF_BYTE|JOF_LEFTASSOC)
OPDEF(JSOP_DIV, 30, "div", "/", 1, 2, 1, 9, JOF_BYTE|JOF_LEFTASSOC)
OPDEF(JSOP_MOD, 31, "mod", "%", 1, 2, 1, 9, JOF_BYTE|JOF_LEFTASSOC)
OPDEF(JSOP_NOT, 32, "not", "!", 1, 1, 1, 10, JOF_BYTE|JOF_DETECTING)
OPDEF(JSOP_BITNOT, 33, "bitnot", "~", 1, 1, 1, 10, JOF_BYTE)
OPDEF(JSOP_NEG, 34, "neg", "-", 1, 1, 1, 10, JOF_BYTE)
OPDEF(JSOP_NEW, 35, js_new_str, NULL, 3, -1, 1, 10, JOF_UINT16)
OPDEF(JSOP_DELNAME, 36, "delname", NULL, 3, 0, 1, 10, JOF_CONST|JOF_NAME|JOF_DEL)
OPDEF(JSOP_DELPROP, 37, "delprop", NULL, 3, 1, 1, 10, JOF_CONST|JOF_PROP|JOF_DEL)
OPDEF(JSOP_DELELEM, 38, "delelem", NULL, 1, 2, 1, 10, JOF_BYTE |JOF_ELEM|JOF_DEL)
OPDEF(JSOP_TYPEOF, 39, js_typeof_str,NULL, 1, 1, 1, 10, JOF_BYTE|JOF_DETECTING)
OPDEF(JSOP_VOID, 40, js_void_str, NULL, 1, 1, 1, 10, JOF_BYTE)
OPDEF(JSOP_INCNAME, 41, "incname", NULL, 3, 0, 1, 10, JOF_CONST|JOF_NAME|JOF_INC)
OPDEF(JSOP_INCPROP, 42, "incprop", NULL, 3, 1, 1, 10, JOF_CONST|JOF_PROP|JOF_INC)
OPDEF(JSOP_INCELEM, 43, "incelem", NULL, 1, 2, 1, 10, JOF_BYTE |JOF_ELEM|JOF_INC)
OPDEF(JSOP_DECNAME, 44, "decname", NULL, 3, 0, 1, 10, JOF_CONST|JOF_NAME|JOF_DEC)
OPDEF(JSOP_DECPROP, 45, "decprop", NULL, 3, 1, 1, 10, JOF_CONST|JOF_PROP|JOF_DEC)
OPDEF(JSOP_DECELEM, 46, "decelem", NULL, 1, 2, 1, 10, JOF_BYTE |JOF_ELEM|JOF_DEC)
OPDEF(JSOP_NAMEINC, 47, "nameinc", NULL, 3, 0, 1, 10, JOF_CONST|JOF_NAME|JOF_INC|JOF_POST)
OPDEF(JSOP_PROPINC, 48, "propinc", NULL, 3, 1, 1, 10, JOF_CONST|JOF_PROP|JOF_INC|JOF_POST)
OPDEF(JSOP_ELEMINC, 49, "eleminc", NULL, 1, 2, 1, 10, JOF_BYTE |JOF_ELEM|JOF_INC|JOF_POST)
OPDEF(JSOP_NAMEDEC, 50, "namedec", NULL, 3, 0, 1, 10, JOF_CONST|JOF_NAME|JOF_DEC|JOF_POST)
OPDEF(JSOP_PROPDEC, 51, "propdec", NULL, 3, 1, 1, 10, JOF_CONST|JOF_PROP|JOF_DEC|JOF_POST)
OPDEF(JSOP_ELEMDEC, 52, "elemdec", NULL, 1, 2, 1, 10, JOF_BYTE |JOF_ELEM|JOF_DEC|JOF_POST)
OPDEF(JSOP_GETPROP, 53, "getprop", NULL, 3, 1, 1, 11, JOF_CONST|JOF_PROP)
OPDEF(JSOP_SETPROP, 54, "setprop", NULL, 3, 2, 1, 1, JOF_CONST|JOF_PROP|JOF_SET|JOF_ASSIGNING|JOF_DETECTING)
OPDEF(JSOP_GETELEM, 55, "getelem", NULL, 1, 2, 1, 11, JOF_BYTE |JOF_ELEM|JOF_LEFTASSOC)
OPDEF(JSOP_SETELEM, 56, "setelem", NULL, 1, 3, 1, 1, JOF_BYTE |JOF_ELEM|JOF_SET|JOF_ASSIGNING|JOF_DETECTING)
OPDEF(JSOP_PUSHOBJ, 57, "pushobj", NULL, 1, 0, 1, 0, JOF_BYTE)
OPDEF(JSOP_CALL, 58, "call", NULL, 3, -1, 1, 11, JOF_UINT16)
OPDEF(JSOP_NAME, 59, "name", NULL, 3, 0, 1, 12, JOF_CONST|JOF_NAME)
OPDEF(JSOP_NUMBER, 60, "number", NULL, 3, 0, 1, 12, JOF_CONST)
OPDEF(JSOP_STRING, 61, "string", NULL, 3, 0, 1, 12, JOF_CONST)
OPDEF(JSOP_ZERO, 62, "zero", "0", 1, 0, 1, 12, JOF_BYTE)
OPDEF(JSOP_ONE, 63, "one", "1", 1, 0, 1, 12, JOF_BYTE)
OPDEF(JSOP_NULL, 64, js_null_str, js_null_str, 1, 0, 1, 12, JOF_BYTE)
OPDEF(JSOP_THIS, 65, js_this_str, js_this_str, 1, 0, 1, 12, JOF_BYTE)
OPDEF(JSOP_FALSE, 66, js_false_str, js_false_str, 1, 0, 1, 12, JOF_BYTE)
OPDEF(JSOP_TRUE, 67, js_true_str, js_true_str, 1, 0, 1, 12, JOF_BYTE)
OPDEF(JSOP_OR, 68, "or", NULL, 3, 1, 0, 0, JOF_JUMP|JOF_DETECTING)
OPDEF(JSOP_AND, 69, "and", NULL, 3, 1, 0, 0, JOF_JUMP|JOF_DETECTING)
/* The switch bytecodes have variable length. */
OPDEF(JSOP_TABLESWITCH, 70, "tableswitch", NULL, -1, 1, 0, 0, JOF_TABLESWITCH)
OPDEF(JSOP_LOOKUPSWITCH, 71, "lookupswitch", NULL, -1, 1, 0, 0, JOF_LOOKUPSWITCH)
/* New, infallible/transitive identity ops. */
OPDEF(JSOP_NEW_EQ, 72, "eq", NULL, 1, 2, 1, 5, JOF_BYTE|JOF_DETECTING)
OPDEF(JSOP_NEW_NE, 73, "ne", NULL, 1, 2, 1, 5, JOF_BYTE|JOF_DETECTING)
/* Lexical closure constructor. */
OPDEF(JSOP_CLOSURE, 74, "closure", NULL, 3, 0, 0, 0, JOF_CONST)
/* Export and import ops. */
OPDEF(JSOP_EXPORTALL, 75, "exportall", NULL, 1, 0, 0, 0, JOF_BYTE)
OPDEF(JSOP_EXPORTNAME,76, "exportname", NULL, 3, 0, 0, 0, JOF_CONST|JOF_NAME)
OPDEF(JSOP_IMPORTALL, 77, "importall", NULL, 1, 1, 0, 0, JOF_BYTE)
OPDEF(JSOP_IMPORTPROP,78, "importprop", NULL, 3, 1, 0, 0, JOF_CONST|JOF_PROP|JOF_IMPORT)
OPDEF(JSOP_IMPORTELEM,79, "importelem", NULL, 1, 2, 0, 0, JOF_BYTE |JOF_ELEM|JOF_IMPORT)
/* Push object literal. */
OPDEF(JSOP_OBJECT, 80, "object", NULL, 3, 0, 1, 12, JOF_CONST)
/* Pop value and discard it. */
OPDEF(JSOP_POP, 81, "pop", NULL, 1, 1, 0, 0, JOF_BYTE)
/* Convert value to number, for unary +. */
OPDEF(JSOP_POS, 82, "pos", "+", 1, 1, 1, 10, JOF_BYTE)
/* Trap into debugger for breakpoint, etc. */
OPDEF(JSOP_TRAP, 83, "trap", NULL, 1, 0, 0, 0, JOF_BYTE)
/* Fast get/set ops for function arguments and local variables. */
OPDEF(JSOP_GETARG, 84, "getarg", NULL, 3, 0, 1, 12, JOF_QARG |JOF_NAME)
OPDEF(JSOP_SETARG, 85, "setarg", NULL, 3, 1, 1, 1, JOF_QARG |JOF_NAME|JOF_SET|JOF_ASSIGNING)
OPDEF(JSOP_GETVAR, 86, "getvar", NULL, 3, 0, 1, 12, JOF_QVAR |JOF_NAME)
OPDEF(JSOP_SETVAR, 87, "setvar", NULL, 3, 1, 1, 1, JOF_QVAR |JOF_NAME|JOF_SET|JOF_ASSIGNING|JOF_DETECTING)
/* Push unsigned 16-bit int constant. */
OPDEF(JSOP_UINT16, 88, "uint16", NULL, 3, 0, 1, 12, JOF_UINT16)
/* Object and array literal support. */
OPDEF(JSOP_NEWINIT, 89, "newinit", NULL, 1, 2, 1, 10, JOF_BYTE)
OPDEF(JSOP_ENDINIT, 90, "endinit", NULL, 1, 0, 0, 0, JOF_BYTE)
OPDEF(JSOP_INITPROP, 91, "initprop", NULL, 3, 1, 0, 0, JOF_CONST|JOF_PROP|JOF_DETECTING)
OPDEF(JSOP_INITELEM, 92, "initelem", NULL, 1, 2, 0, 0, JOF_BYTE |JOF_ELEM|JOF_DETECTING)
OPDEF(JSOP_DEFSHARP, 93, "defsharp", NULL, 3, 0, 0, 0, JOF_UINT16)
OPDEF(JSOP_USESHARP, 94, "usesharp", NULL, 3, 0, 1, 0, JOF_UINT16)
/* Fast inc/dec ops for args and local vars. */
OPDEF(JSOP_INCARG, 95, "incarg", NULL, 3, 0, 1, 10, JOF_QARG |JOF_NAME|JOF_INC)
OPDEF(JSOP_INCVAR, 96, "incvar", NULL, 3, 0, 1, 10, JOF_QVAR |JOF_NAME|JOF_INC)
OPDEF(JSOP_DECARG, 97, "decarg", NULL, 3, 0, 1, 10, JOF_QARG |JOF_NAME|JOF_DEC)
OPDEF(JSOP_DECVAR, 98, "decvar", NULL, 3, 0, 1, 10, JOF_QVAR |JOF_NAME|JOF_DEC)
OPDEF(JSOP_ARGINC, 99, "arginc", NULL, 3, 0, 1, 10, JOF_QARG |JOF_NAME|JOF_INC|JOF_POST)
OPDEF(JSOP_VARINC, 100,"varinc", NULL, 3, 0, 1, 10, JOF_QVAR |JOF_NAME|JOF_INC|JOF_POST)
OPDEF(JSOP_ARGDEC, 101,"argdec", NULL, 3, 0, 1, 10, JOF_QARG |JOF_NAME|JOF_DEC|JOF_POST)
OPDEF(JSOP_VARDEC, 102,"vardec", NULL, 3, 0, 1, 10, JOF_QVAR |JOF_NAME|JOF_DEC|JOF_POST)
/* ECMA-compliant for/in ops. */
OPDEF(JSOP_TOOBJECT, 103,"toobject", NULL, 1, 1, 1, 0, JOF_BYTE)
OPDEF(JSOP_FORNAME, 104,"forname", NULL, 3, 0, 1, 0, JOF_CONST|JOF_NAME|JOF_FOR)
OPDEF(JSOP_FORPROP, 105,"forprop", NULL, 3, 1, 1, 0, JOF_CONST|JOF_PROP|JOF_FOR)
OPDEF(JSOP_FORELEM, 106,"forelem", NULL, 1, 2, 4, 0, JOF_BYTE |JOF_ELEM|JOF_FOR)
OPDEF(JSOP_POP2, 107,"pop2", NULL, 1, 2, 0, 0, JOF_BYTE)
/* ECMA-compliant assignment ops. */
OPDEF(JSOP_BINDNAME, 108,"bindname", NULL, 3, 0, 1, 0, JOF_CONST|JOF_NAME|JOF_SET|JOF_ASSIGNING)
OPDEF(JSOP_SETNAME, 109,"setname", NULL, 3, 2, 1, 1, JOF_CONST|JOF_NAME|JOF_SET|JOF_ASSIGNING|JOF_DETECTING)
/* Exception handling ops. */
OPDEF(JSOP_THROW, 110,"throw", NULL, 1, 1, 0, 0, JOF_BYTE)
/* 'in' and 'instanceof' ops. */
OPDEF(JSOP_IN, 111,js_in_str, js_in_str, 1, 2, 1, 6, JOF_BYTE|JOF_LEFTASSOC)
OPDEF(JSOP_INSTANCEOF,112,js_instanceof_str,js_instanceof_str,1,2,1,6,JOF_BYTE|JOF_LEFTASSOC)
/* debugger op */
OPDEF(JSOP_DEBUGGER, 113,"debugger", NULL, 1, 0, 0, 0, JOF_BYTE)
/* gosub/retsub for finally handling */
OPDEF(JSOP_GOSUB, 114,"gosub", NULL, 3, 0, 1, 0, JOF_JUMP)
OPDEF(JSOP_RETSUB, 115,"retsub", NULL, 1, 1, 0, 0, JOF_BYTE)
/* More exception handling ops. */
OPDEF(JSOP_EXCEPTION, 116,"exception", NULL, 1, 0, 1, 0, JOF_BYTE)
OPDEF(JSOP_SETSP, 117,"setsp", NULL, 3, 0, 0, 0, JOF_UINT16)
/*
* ECMA-compliant switch statement ops.
* CONDSWITCH is a decompilable NOP; CASE is ===, POP, jump if true, re-push
* lval if false; and DEFAULT is POP lval and GOTO.
*/
OPDEF(JSOP_CONDSWITCH,118,"condswitch", NULL, 1, 0, 0, 0, JOF_BYTE)
OPDEF(JSOP_CASE, 119,"case", NULL, 3, 1, 0, 0, JOF_JUMP)
OPDEF(JSOP_DEFAULT, 120,"default", NULL, 3, 1, 0, 0, JOF_JUMP)
/*
* ECMA-compliant call to eval op
*/
OPDEF(JSOP_EVAL, 121,"eval", NULL, 3, -1, 1, 11, JOF_UINT16)
/*
* ECMA-compliant helper for 'for (x[i] in o)' loops.
*/
OPDEF(JSOP_ENUMELEM, 122,"enumelem", NULL, 1, 3, 0, 1, JOF_BYTE |JOF_SET|JOF_ASSIGNING)
/*
* Getter and setter prefix bytecodes. These modify the next bytecode, either
* an assignment or a property initializer code, which then defines a property
* getter or setter.
*/
OPDEF(JSOP_GETTER, 123,js_getter_str,NULL, 1, 0, 0, 0, JOF_BYTE)
OPDEF(JSOP_SETTER, 124,js_setter_str,NULL, 1, 0, 0, 0, JOF_BYTE)
/*
* Prolog bytecodes for defining function, var, and const names.
*/
OPDEF(JSOP_DEFFUN, 125,"deffun", NULL, 3, 0, 0, 0, JOF_CONST|JOF_DECLARING)
OPDEF(JSOP_DEFCONST, 126,"defconst", NULL, 3, 0, 0, 0, JOF_CONST|JOF_NAME|JOF_DECLARING)
OPDEF(JSOP_DEFVAR, 127,"defvar", NULL, 3, 0, 0, 0, JOF_CONST|JOF_NAME|JOF_DECLARING)
/* Auto-clone (if needed due to re-parenting) and push an anonymous function. */
OPDEF(JSOP_ANONFUNOBJ, 128, "anonfunobj", NULL, 3, 0, 1, 12, JOF_CONST)
/* ECMA ed. 3 named function expression. */
OPDEF(JSOP_NAMEDFUNOBJ, 129, "namedfunobj", NULL, 3, 0, 1, 12, JOF_CONST)
/* Like JSOP_INITPROP, but specialized to make a DontDelete property for ECMA ed. 3 catch variables. */
OPDEF(JSOP_INITCATCHVAR,130, "initcatchvar",NULL, 3, 1, 0, 0, JOF_CONST|JOF_PROP)
/* ECMA-mandated parenthesization opcode, which nulls the reference base register, obj; see jsinterp.c. */
OPDEF(JSOP_GROUP, 131, "group", NULL, 1, 0, 0, 0, JOF_BYTE)
/* Host object extension: given 'o.item(i) = j', the left-hand side compiles JSOP_SETCALL, rather than JSOP_CALL. */
OPDEF(JSOP_SETCALL, 132, "setcall", NULL, 3, -1, 2, 11, JOF_UINT16|JOF_SET|JOF_ASSIGNING)
/*
* Exception handling no-ops, for more economical byte-coding than SRC_TRYFIN
* srcnote-annotated JSOP_NOPs.
*/
OPDEF(JSOP_TRY, 133,"try", NULL, 1, 0, 0, 0, JOF_BYTE)
OPDEF(JSOP_FINALLY, 134,"finally", NULL, 1, 0, 0, 0, JOF_BYTE)
/*
* Swap the top two stack elements.
* N.B. JSOP_SWAP doesn't swap the corresponding pc stack generating pcs, as
* they're not needed for the current use of preserving the top-of-stack return
* value when popping scopes while returning from catch blocks.
*/
OPDEF(JSOP_SWAP, 135,"swap", NULL, 1, 2, 2, 0, JOF_BYTE)
/*
* Bytecodes that avoid making an arguments object in most cases:
* JSOP_ARGSUB gets arguments[i] from fp->argv, iff i is in [0, fp->argc-1].
* JSOP_ARGCNT returns fp->argc.
*/
OPDEF(JSOP_ARGSUB, 136,"argsub", NULL, 3, 0, 1, 12, JOF_QARG |JOF_NAME)
OPDEF(JSOP_ARGCNT, 137,"argcnt", NULL, 1, 0, 1, 12, JOF_BYTE)
/*
* Define a local function object as a local variable.
* The local variable's slot number is the first immediate two-byte operand.
* The function object's atom index is the second immediate operand.
*/
OPDEF(JSOP_DEFLOCALFUN, 138,"deflocalfun",NULL, 5, 0, 0, 0, JOF_INDEXCONST|JOF_DECLARING)
/* Extended jumps. */
OPDEF(JSOP_GOTOX, 139,"gotox", NULL, 5, 0, 0, 0, JOF_JUMPX)
OPDEF(JSOP_IFEQX, 140,"ifeqx", NULL, 5, 1, 0, 0, JOF_JUMPX|JOF_DETECTING)
OPDEF(JSOP_IFNEX, 141,"ifnex", NULL, 5, 1, 0, 0, JOF_JUMPX)
OPDEF(JSOP_ORX, 142,"orx", NULL, 5, 1, 0, 0, JOF_JUMPX|JOF_DETECTING)
OPDEF(JSOP_ANDX, 143,"andx", NULL, 5, 1, 0, 0, JOF_JUMPX|JOF_DETECTING)
OPDEF(JSOP_GOSUBX, 144,"gosubx", NULL, 5, 0, 1, 0, JOF_JUMPX)
OPDEF(JSOP_CASEX, 145,"casex", NULL, 5, 1, 0, 0, JOF_JUMPX)
OPDEF(JSOP_DEFAULTX, 146,"defaultx", NULL, 5, 1, 0, 0, JOF_JUMPX)
OPDEF(JSOP_TABLESWITCHX, 147,"tableswitchx",NULL, -1, 1, 0, 0, JOF_TABLESWITCHX)
OPDEF(JSOP_LOOKUPSWITCHX, 148,"lookupswitchx",NULL, -1, 1, 0, 0, JOF_LOOKUPSWITCHX)
/* Placeholders for a real jump opcode set during backpatch chain fixup. */
OPDEF(JSOP_BACKPATCH, 149,"backpatch",NULL, 3, 0, 0, 0, JOF_JUMP|JOF_BACKPATCH)
OPDEF(JSOP_BACKPATCH_POP, 150,"backpatch_pop",NULL, 3, 1, 0, 0, JOF_JUMP|JOF_BACKPATCH)
OPDEF(JSOP_BACKPATCH_PUSH,151,"backpatch_push",NULL, 3, 0, 1, 0, JOF_JUMP|JOF_BACKPATCH)
/* Set and get return value pseudo-register in stack frame. */
OPDEF(JSOP_SETRVAL, 152,"setrval", NULL, 1, 1, 0, 0, JOF_BYTE)
OPDEF(JSOP_RETRVAL, 153,"retrval", NULL, 1, 0, 0, 0, JOF_BYTE)
/* Optimized global variable ops (we don't bother doing a JSOP_FORGVAR op). */
OPDEF(JSOP_GETGVAR, 154,"getgvar", NULL, 3, 0, 1, 12, JOF_CONST|JOF_NAME)
OPDEF(JSOP_SETGVAR, 155,"setgvar", NULL, 3, 1, 1, 1, JOF_CONST|JOF_NAME|JOF_SET|JOF_ASSIGNING|JOF_DETECTING)
OPDEF(JSOP_INCGVAR, 156,"incgvar", NULL, 3, 0, 1, 10, JOF_CONST|JOF_NAME|JOF_INC)
OPDEF(JSOP_DECGVAR, 157,"decgvar", NULL, 3, 0, 1, 10, JOF_CONST|JOF_NAME|JOF_DEC)
OPDEF(JSOP_GVARINC, 158,"gvarinc", NULL, 3, 0, 1, 10, JOF_CONST|JOF_NAME|JOF_INC|JOF_POST)
OPDEF(JSOP_GVARDEC, 159,"gvardec", NULL, 3, 0, 1, 10, JOF_CONST|JOF_NAME|JOF_DEC|JOF_POST)
/* Regular expression literal requiring special "fork on exec" handling. */
OPDEF(JSOP_REGEXP, 160,"regexp", NULL, 3, 0, 1, 12, JOF_CONST)
/* XML (ECMA-357, a.k.a. "E4X") support. */
OPDEF(JSOP_DEFXMLNS, 161,"defxmlns", NULL, 1, 1, 0, 0, JOF_BYTE)
OPDEF(JSOP_ANYNAME, 162,"anyname", NULL, 1, 0, 1, 12, JOF_BYTE|JOF_XMLNAME)
OPDEF(JSOP_QNAMEPART, 163,"qnamepart", NULL, 3, 0, 1, 12, JOF_CONST|JOF_XMLNAME)
OPDEF(JSOP_QNAMECONST, 164,"qnameconst", NULL, 3, 1, 1, 12, JOF_CONST|JOF_XMLNAME)
OPDEF(JSOP_QNAME, 165,"qname", NULL, 1, 2, 1, 12, JOF_BYTE|JOF_XMLNAME)
OPDEF(JSOP_TOATTRNAME, 166,"toattrname", NULL, 1, 1, 1, 12, JOF_BYTE|JOF_XMLNAME)
OPDEF(JSOP_TOATTRVAL, 167,"toattrval", NULL, 1, 1, 1, 12, JOF_BYTE)
OPDEF(JSOP_ADDATTRNAME, 168,"addattrname",NULL, 1, 2, 1, 8, JOF_BYTE)
OPDEF(JSOP_ADDATTRVAL, 169,"addattrval", NULL, 1, 2, 1, 8, JOF_BYTE)
OPDEF(JSOP_BINDXMLNAME, 170,"bindxmlname",NULL, 1, 1, 2, 0, JOF_BYTE|JOF_XMLNAME|JOF_SET|JOF_ASSIGNING)
OPDEF(JSOP_SETXMLNAME, 171,"setxmlname", NULL, 1, 3, 1, 1, JOF_BYTE|JOF_XMLNAME|JOF_SET|JOF_ASSIGNING|JOF_DETECTING)
OPDEF(JSOP_XMLNAME, 172,"xmlname", NULL, 1, 1, 1, 12, JOF_BYTE|JOF_XMLNAME)
OPDEF(JSOP_DESCENDANTS, 173,"descendants",NULL, 1, 2, 1, 11, JOF_BYTE)
OPDEF(JSOP_FILTER, 174,"filter", NULL, 3, 1, 1, 11, JOF_JUMP)
OPDEF(JSOP_ENDFILTER, 175,"endfilter", NULL, 1, 1, 0, 0, JOF_BYTE)
OPDEF(JSOP_TOXML, 176,"toxml", NULL, 1, 1, 1, 12, JOF_BYTE)
OPDEF(JSOP_TOXMLLIST, 177,"toxmllist", NULL, 1, 1, 1, 12, JOF_BYTE)
OPDEF(JSOP_XMLTAGEXPR, 178,"xmltagexpr", NULL, 1, 1, 1, 12, JOF_BYTE)
OPDEF(JSOP_XMLELTEXPR, 179,"xmleltexpr", NULL, 1, 1, 1, 12, JOF_BYTE)
OPDEF(JSOP_XMLOBJECT, 180,"xmlobject", NULL, 3, 0, 1, 12, JOF_CONST)
OPDEF(JSOP_XMLCDATA, 181,"xmlcdata", NULL, 3, 0, 1, 12, JOF_CONST)
OPDEF(JSOP_XMLCOMMENT, 182,"xmlcomment", NULL, 3, 0, 1, 12, JOF_CONST)
OPDEF(JSOP_XMLPI, 183,"xmlpi", NULL, 5, 0, 1, 12, JOF_CONST2)
OPDEF(JSOP_GETMETHOD, 184,"getmethod", NULL, 3, 1, 1, 11, JOF_CONST|JOF_PROP)
OPDEF(JSOP_GETFUNNS, 185,"getfunns", NULL, 1, 0, 1, 12, JOF_BYTE)
OPDEF(JSOP_FOREACH, 186,"foreach", NULL, 1, 0, 0, 0, JOF_BYTE)
OPDEF(JSOP_DELDESC, 187,"deldesc", NULL, 1, 2, 1, 10, JOF_BYTE |JOF_ELEM|JOF_DEL)

View File

@@ -1,127 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsosdep_h___
#define jsosdep_h___
/*
* OS (and machine, and compiler XXX) dependent information.
*/
#if defined(XP_WIN) || defined(XP_OS2)
#if defined(_WIN32) || defined (XP_OS2)
#define JS_HAVE_LONG_LONG
#else
#undef JS_HAVE_LONG_LONG
#endif
#endif /* XP_WIN || XP_OS2 */
#ifdef XP_MAC
#define JS_HAVE_LONG_LONG
JS_BEGIN_EXTERN_C
#include <stddef.h>
extern void* reallocSmaller(void* block, size_t newSize);
extern char* strdup(const char* str);
JS_END_EXTERN_C
#endif /* XP_MAC */
#ifdef XP_BEOS
#define JS_HAVE_LONG_LONG
#endif
#ifdef XP_UNIX
/*
* Get OS specific header information.
*/
#if defined(AIXV3) || defined(AIX)
#define JS_HAVE_LONG_LONG
#elif defined(BSDI)
#define JS_HAVE_LONG_LONG
#elif defined(HPUX)
#define JS_HAVE_LONG_LONG
#elif defined(IRIX)
#define JS_HAVE_LONG_LONG
#elif defined(linux)
#define JS_HAVE_LONG_LONG
#elif defined(OSF1)
#define JS_HAVE_LONG_LONG
#elif defined(_SCO_DS)
#undef JS_HAVE_LONG_LONG
#elif defined(SOLARIS)
#define JS_HAVE_LONG_LONG
#elif defined(FREEBSD)
#define JS_HAVE_LONG_LONG
#elif defined(SUNOS4)
#undef JS_HAVE_LONG_LONG
/*
** Missing function prototypes
*/
extern void *sbrk(int);
#elif defined(UNIXWARE)
#undef JS_HAVE_LONG_LONG
#elif defined(VMS) && defined(__ALPHA)
#define JS_HAVE_LONG_LONG
#endif
#endif /* XP_UNIX */
#endif /* jsosdep_h___ */

View File

@@ -1,211 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* This section typedefs the old 'native' types to the new PR<type>s.
* These definitions are scheduled to be eliminated at the earliest
* possible time. The NSPR API is implemented and documented using
* the new definitions.
*/
/*
* Note that we test for PROTYPES_H, not JSOTYPES_H. This is to avoid
* double-definitions of scalar types such as uint32, if NSPR's
* protypes.h is also included.
*/
#ifndef PROTYPES_H
#define PROTYPES_H
#ifdef XP_BEOS
/* BeOS defines most int types in SupportDefs.h (int8, uint8, int16,
* uint16, int32, uint32, int64, uint64), so in the interest of
* not conflicting with other definitions elsewhere we have to skip the
* #ifdef jungle below, duplicate some definitions, and do our stuff.
*/
#include <SupportDefs.h>
typedef JSUintn uintn;
#ifndef _XP_Core_
typedef JSIntn intn;
#endif
#else
/* SVR4 typedef of uint is commonly found on UNIX machines. */
#ifdef XP_UNIX
#include <sys/types.h>
#else
typedef JSUintn uint;
#endif
typedef JSUintn uintn;
typedef JSUint64 uint64;
#if !defined(XP_MAC) && !defined(_WIN32) && !defined(XP_OS2)
typedef JSUint32 uint32;
#else
typedef unsigned long uint32;
#endif
typedef JSUint16 uint16;
typedef JSUint8 uint8;
#ifndef _XP_Core_
typedef JSIntn intn;
#endif
/*
* On AIX 4.3, sys/inttypes.h (which is included by sys/types.h, a very
* common header file) defines the types int8, int16, int32, and int64.
* So we don't define these four types here to avoid conflicts in case
* the code also includes sys/types.h.
*/
#if defined(AIX) && defined(HAVE_SYS_INTTYPES_H)
#include <sys/inttypes.h>
#else
typedef JSInt64 int64;
/* /usr/include/model.h on HP-UX defines int8, int16, and int32 */
#ifdef HPUX
#include <model.h>
#else
#if !defined(XP_MAC) && !defined(_WIN32) && !defined(XP_OS2)
typedef JSInt32 int32;
#else
typedef long int32;
#endif
typedef JSInt16 int16;
typedef JSInt8 int8;
#endif /* HPUX */
#endif /* AIX && HAVE_SYS_INTTYPES_H */
#endif /* XP_BEOS */
typedef JSFloat64 float64;
/* Re: jsbit.h */
#define TEST_BIT JS_TEST_BIT
#define SET_BIT JS_SET_BIT
#define CLEAR_BIT JS_CLEAR_BIT
/* Re: prarena.h->plarena.h */
#define PRArena PLArena
#define PRArenaPool PLArenaPool
#define PRArenaStats PLArenaStats
#define PR_ARENA_ALIGN PL_ARENA_ALIGN
#define PR_INIT_ARENA_POOL PL_INIT_ARENA_POOL
#define PR_ARENA_ALLOCATE PL_ARENA_ALLOCATE
#define PR_ARENA_GROW PL_ARENA_GROW
#define PR_ARENA_MARK PL_ARENA_MARK
#define PR_CLEAR_UNUSED PL_CLEAR_UNUSED
#define PR_CLEAR_ARENA PL_CLEAR_ARENA
#define PR_ARENA_RELEASE PL_ARENA_RELEASE
#define PR_COUNT_ARENA PL_COUNT_ARENA
#define PR_ARENA_DESTROY PL_ARENA_DESTROY
#define PR_InitArenaPool PL_InitArenaPool
#define PR_FreeArenaPool PL_FreeArenaPool
#define PR_FinishArenaPool PL_FinishArenaPool
#define PR_CompactArenaPool PL_CompactArenaPool
#define PR_ArenaFinish PL_ArenaFinish
#define PR_ArenaAllocate PL_ArenaAllocate
#define PR_ArenaGrow PL_ArenaGrow
#define PR_ArenaRelease PL_ArenaRelease
#define PR_ArenaCountAllocation PL_ArenaCountAllocation
#define PR_ArenaCountInplaceGrowth PL_ArenaCountInplaceGrowth
#define PR_ArenaCountGrowth PL_ArenaCountGrowth
#define PR_ArenaCountRelease PL_ArenaCountRelease
#define PR_ArenaCountRetract PL_ArenaCountRetract
/* Re: prevent.h->plevent.h */
#define PREvent PLEvent
#define PREventQueue PLEventQueue
#define PR_CreateEventQueue PL_CreateEventQueue
#define PR_DestroyEventQueue PL_DestroyEventQueue
#define PR_GetEventQueueMonitor PL_GetEventQueueMonitor
#define PR_ENTER_EVENT_QUEUE_MONITOR PL_ENTER_EVENT_QUEUE_MONITOR
#define PR_EXIT_EVENT_QUEUE_MONITOR PL_EXIT_EVENT_QUEUE_MONITOR
#define PR_PostEvent PL_PostEvent
#define PR_PostSynchronousEvent PL_PostSynchronousEvent
#define PR_GetEvent PL_GetEvent
#define PR_EventAvailable PL_EventAvailable
#define PREventFunProc PLEventFunProc
#define PR_MapEvents PL_MapEvents
#define PR_RevokeEvents PL_RevokeEvents
#define PR_ProcessPendingEvents PL_ProcessPendingEvents
#define PR_WaitForEvent PL_WaitForEvent
#define PR_EventLoop PL_EventLoop
#define PR_GetEventQueueSelectFD PL_GetEventQueueSelectFD
#define PRHandleEventProc PLHandleEventProc
#define PRDestroyEventProc PLDestroyEventProc
#define PR_InitEvent PL_InitEvent
#define PR_GetEventOwner PL_GetEventOwner
#define PR_HandleEvent PL_HandleEvent
#define PR_DestroyEvent PL_DestroyEvent
#define PR_DequeueEvent PL_DequeueEvent
#define PR_GetMainEventQueue PL_GetMainEventQueue
/* Re: prhash.h->plhash.h */
#define PRHashEntry PLHashEntry
#define PRHashTable PLHashTable
#define PRHashNumber PLHashNumber
#define PRHashFunction PLHashFunction
#define PRHashComparator PLHashComparator
#define PRHashEnumerator PLHashEnumerator
#define PRHashAllocOps PLHashAllocOps
#define PR_NewHashTable PL_NewHashTable
#define PR_HashTableDestroy PL_HashTableDestroy
#define PR_HashTableRawLookup PL_HashTableRawLookup
#define PR_HashTableRawAdd PL_HashTableRawAdd
#define PR_HashTableRawRemove PL_HashTableRawRemove
#define PR_HashTableAdd PL_HashTableAdd
#define PR_HashTableRemove PL_HashTableRemove
#define PR_HashTableEnumerateEntries PL_HashTableEnumerateEntries
#define PR_HashTableLookup PL_HashTableLookup
#define PR_HashTableDump PL_HashTableDump
#define PR_HashString PL_HashString
#define PR_CompareStrings PL_CompareStrings
#define PR_CompareValues PL_CompareValues
#ifdef XP_MAC
#ifndef TRUE /* Mac standard is lower case true */
#define TRUE 1
#endif
#ifndef FALSE /* Mac standard is lower case false */
#define FALSE 0
#endif
#endif
#endif /* !defined(PROTYPES_H) */

File diff suppressed because it is too large Load Diff

View File

@@ -1,414 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsparse_h___
#define jsparse_h___
/*
* JS parser definitions.
*/
#include "jsconfig.h"
#include "jsprvtd.h"
#include "jspubtd.h"
#include "jsscan.h"
JS_BEGIN_EXTERN_C
/*
* Parsing builds a tree of nodes that directs code generation. This tree is
* not a concrete syntax tree in all respects (for example, || and && are left
* associative, but (A && B && C) translates into the right-associated tree
* <A && <B && C>> so that code generation can emit a left-associative branch
* around <B && C> when A is false). Nodes are labeled by token type, with a
* JSOp secondary label when needed:
*
* Label Variant Members
* ----- ------- -------
* <Definitions>
* TOK_FUNCTION func pn_funAtom: atom holding function object containing
* arg and var properties. We create the function
* object at parse (not emit) time to specialize arg
* and var bytecodes early.
* pn_body: TOK_LC node for function body statements
* pn_flags: TCF_FUN_* flags (see jsemit.h) collected
* while parsing the function's body
* pn_tryCount: of try statements in function
*
* <Statements>
* TOK_LC list pn_head: list of pn_count statements
* TOK_EXPORT list pn_head: list of pn_count TOK_NAMEs or one TOK_STAR
* (which is not a multiply node)
* TOK_IMPORT list pn_head: list of pn_count sub-trees of the form
* a.b.*, a[b].*, a.*, a.b, or a[b] -- but never a.
* Each member is expressed with TOK_DOT or TOK_LB.
* Each sub-tree's root node has a pn_op in the set
* JSOP_IMPORT{ALL,PROP,ELEM}
* TOK_IF ternary pn_kid1: cond, pn_kid2: then, pn_kid3: else or null
* TOK_SWITCH binary pn_left: discriminant
* pn_right: list of TOK_CASE nodes, with at most one
* TOK_DEFAULT node
* TOK_CASE, binary pn_left: case expr or null if TOK_DEFAULT
* TOK_DEFAULT pn_right: TOK_LC node for this case's statements
* pn_val: constant value if lookup or table switch
* TOK_WHILE binary pn_left: cond, pn_right: body
* TOK_DO binary pn_left: body, pn_right: cond
* TOK_FOR binary pn_left: either
* for/in loop: a binary TOK_IN node with
* pn_left: TOK_VAR or TOK_NAME to left of 'in'
* if TOK_VAR, its pn_extra may have PNX_POPVAR
* and PNX_FORINVAR bits set
* pn_right: object expr to right of 'in'
* for(;;) loop: a ternary TOK_RESERVED node with
* pn_kid1: init expr before first ';'
* pn_kid2: cond expr before second ';'
* pn_kid3: update expr after second ';'
* any kid may be null
* pn_right: body
* TOK_THROW unary pn_op: JSOP_THROW, pn_kid: exception
* TOK_TRY ternary pn_kid1: try block
* pn_kid2: catch blocks or null
* pn_kid3: finally block or null
* TOK_CATCH ternary pn_kid1: PN_NAME node for catch var (with pn_expr
* null or the catch guard expression)
* pn_kid2: more catch blocks or null
* pn_kid3: catch block statements
* TOK_BREAK name pn_atom: label or null
* TOK_CONTINUE name pn_atom: label or null
* TOK_WITH binary pn_left: head expr, pn_right: body
* TOK_VAR list pn_head: list of pn_count TOK_NAME nodes
* each name node has
* pn_atom: variable name
* pn_expr: initializer or null
* TOK_RETURN unary pn_kid: return expr or null
* TOK_SEMI unary pn_kid: expr or null statement
* TOK_COLON name pn_atom: label, pn_expr: labeled statement
*
* <Expressions>
* All left-associated binary trees of the same type are optimized into lists
* to avoid recursion when processing expression chains.
* TOK_COMMA list pn_head: list of pn_count comma-separated exprs
* TOK_ASSIGN binary pn_left: lvalue, pn_right: rvalue
* pn_op: JSOP_ADD for +=, etc.
* TOK_HOOK ternary pn_kid1: cond, pn_kid2: then, pn_kid3: else
* TOK_OR binary pn_left: first in || chain, pn_right: rest of chain
* TOK_AND binary pn_left: first in && chain, pn_right: rest of chain
* TOK_BITOR binary pn_left: left-assoc | expr, pn_right: ^ expr
* TOK_BITXOR binary pn_left: left-assoc ^ expr, pn_right: & expr
* TOK_BITAND binary pn_left: left-assoc & expr, pn_right: EQ expr
* TOK_EQOP binary pn_left: left-assoc EQ expr, pn_right: REL expr
* pn_op: JSOP_EQ, JSOP_NE, JSOP_NEW_EQ, JSOP_NEW_NE
* TOK_RELOP binary pn_left: left-assoc REL expr, pn_right: SH expr
* pn_op: JSOP_LT, JSOP_LE, JSOP_GT, JSOP_GE
* TOK_SHOP binary pn_left: left-assoc SH expr, pn_right: ADD expr
* pn_op: JSOP_LSH, JSOP_RSH, JSOP_URSH
* TOK_PLUS, binary pn_left: left-assoc ADD expr, pn_right: MUL expr
* pn_extra: if a left-associated binary TOK_PLUS
* tree has been flattened into a list (see above
* under <Expressions>), pn_extra will contain
* PNX_STRCAT if at least one list element is a
* string literal (TOK_STRING); if such a list has
* any non-string, non-number term, pn_extra will
* contain PNX_CANTFOLD.
* pn_
* TOK_MINUS pn_op: JSOP_ADD, JSOP_SUB
* TOK_STAR, binary pn_left: left-assoc MUL expr, pn_right: UNARY expr
* TOK_DIVOP pn_op: JSOP_MUL, JSOP_DIV, JSOP_MOD
* TOK_UNARYOP unary pn_kid: UNARY expr, pn_op: JSOP_NEG, JSOP_POS,
* JSOP_NOT, JSOP_BITNOT, JSOP_TYPEOF, JSOP_VOID
* TOK_INC, unary pn_kid: MEMBER expr
* TOK_DEC
* TOK_NEW list pn_head: list of ctor, arg1, arg2, ... argN
* pn_count: 1 + N (where N is number of args)
* ctor is a MEMBER expr
* TOK_DELETE unary pn_kid: MEMBER expr
* TOK_DOT, name pn_expr: MEMBER expr to left of .
* TOK_DBLDOT pn_atom: name to right of .
* TOK_LB binary pn_left: MEMBER expr to left of [
* pn_right: expr between [ and ]
* TOK_LP list pn_head: list of call, arg1, arg2, ... argN
* pn_count: 1 + N (where N is number of args)
* call is a MEMBER expr naming a callable object
* TOK_RB list pn_head: list of pn_count array element exprs
* [,,] holes are represented by TOK_COMMA nodes
* #n=[...] produces TOK_DEFSHARP at head of list
* pn_extra: PN_ENDCOMMA if extra comma at end
* TOK_RC list pn_head: list of pn_count TOK_COLON nodes where
* each has pn_left: property id, pn_right: value
* #n={...} produces TOK_DEFSHARP at head of list
* TOK_DEFSHARP unary pn_num: jsint value of n in #n=
* pn_kid: null for #n=[...] and #n={...}, primary
* if #n=primary for function, paren, name, object
* literal expressions
* TOK_USESHARP nullary pn_num: jsint value of n in #n#
* TOK_RP unary pn_kid: parenthesized expression
* TOK_NAME, name pn_atom: name, string, or object atom
* TOK_STRING, pn_op: JSOP_NAME, JSOP_STRING, or JSOP_OBJECT, or
* JSOP_REGEXP
* TOK_OBJECT If JSOP_NAME, pn_op may be JSOP_*ARG or JSOP_*VAR
* with pn_slot >= 0 and pn_attrs telling const-ness
* TOK_NUMBER dval pn_dval: double value of numeric literal
* TOK_PRIMARY nullary pn_op: JSOp bytecode
* TOK_ANYNAME nullary pn_op: JSOP_ANYNAME
* pn_atom: cx->runtime->atomState.starAtom
* TOK_AT unary pn_op: JSOP_TOATTRNAME; pn_kid attribute id/expr
* TOK_DBLCOLON binary pn_op: JSOP_QNAME
* pn_left: TOK_ANYNAME or TOK_NAME node
* pn_right: TOK_STRING "*" node, or expr within []
* name pn_op: JSOP_QNAMECONST
* pn_expr: TOK_ANYNAME or TOK_NAME left operand
* pn_atom: name on right of ::
* TOK_XMLELEM list XML element node
* pn_head: start tag, content1, ... contentN, end tag
* pn_count: 2 + N where N is number of content nodes
* N may be > x.length() if {expr} embedded
* TOK_XMLLIST list XML list node
* pn_head: content1, ... contentN
* TOK_XMLSTAGO, list XML start, end, and point tag contents
* TOK_XMLETAGC, pn_head: tag name or {expr}, ... XML attrs ...
* TOK_XMLPTAGO
* TOK_XMLNAME nullary pn_atom: XML name, with no {expr} embedded
* TOK_XMLNAME list pn_head: tag name or {expr}, ... name or {expr}
* TOK_XMLATTR, nullary pn_atom: attribute value string; pn_op: JSOP_STRING
* TOK_XMLCDATA,
* TOK_XMLCOMMENT
* TOK_XMLPI nullary pn_atom: XML processing instruction target
* pn_atom2: XML PI content, or null if no content
* TOK_XMLTEXT nullary pn_atom: marked-up text, or null if empty string
* TOK_LC unary {expr} in XML tag or content; pn_kid is expr
*
* So an XML tag with no {expr} and three attributes is a list with the form:
*
* (tagname attrname1 attrvalue1 attrname2 attrvalue2 attrname2 attrvalue3)
*
* An XML tag with embedded expressions like so:
*
* <name1{expr1} name2{expr2}name3={expr3}>
*
* would have the form:
*
* ((name1 {expr1}) (name2 {expr2} name3) {expr3})
*
* where () bracket a list with elements separated by spaces, and {expr} is a
* TOK_LC unary node with expr as its kid.
*
* Thus, the attribute name/value pairs occupy successive odd and even list
* locations, where pn_head is the TOK_XMLNAME node at list location 0. The
* parser builds the same sort of structures for elements:
*
* <a x={x}>Hi there!<b y={y}>How are you?</b><answer>{x + y}</answer></a>
*
* translates to:
*
* ((a x {x}) 'Hi there!' ((b y {y}) 'How are you?') ((answer) {x + y}))
*/
typedef enum JSParseNodeArity {
PN_FUNC = -3,
PN_LIST = -2,
PN_TERNARY = 3,
PN_BINARY = 2,
PN_UNARY = 1,
PN_NAME = -1,
PN_NULLARY = 0
} JSParseNodeArity;
struct JSParseNode {
uint16 pn_type;
uint8 pn_op;
int8 pn_arity;
JSTokenPos pn_pos;
ptrdiff_t pn_offset; /* first generated bytecode offset */
union {
struct { /* TOK_FUNCTION node */
JSAtom *funAtom; /* atomized function object */
JSParseNode *body; /* TOK_LC list of statements */
uint32 flags; /* accumulated tree context flags */
uint32 tryCount; /* count of try statements in body */
} func;
struct { /* list of next-linked nodes */
JSParseNode *head; /* first node in list */
JSParseNode **tail; /* ptr to ptr to last node in list */
uint32 count; /* number of nodes in list */
uint32 extra; /* extra comma flag for [1,2,,] */
} list;
struct { /* ternary: if, for(;;), ?: */
JSParseNode *kid1; /* condition, discriminant, etc. */
JSParseNode *kid2; /* then-part, case list, etc. */
JSParseNode *kid3; /* else-part, default case, etc. */
} ternary;
struct { /* two kids if binary */
JSParseNode *left;
JSParseNode *right;
jsval val; /* switch case value */
} binary;
struct { /* one kid if unary */
JSParseNode *kid;
jsint num; /* -1 or sharp variable number */
} unary;
struct { /* name, labeled statement, etc. */
JSAtom *atom; /* name or label atom, null if slot */
JSParseNode *expr; /* object or initializer */
jsint slot; /* -1 or arg or local var slot */
uintN attrs; /* attributes if local var or const */
} name;
struct {
JSAtom *atom; /* first atom in pair */
JSAtom *atom2; /* second atom in pair or null */
} apair;
jsdouble dval; /* aligned numeric literal value */
} pn_u;
JSParseNode *pn_next; /* to align dval and pn_u on RISCs */
#if JS_HAS_XML_SUPPORT
JSTokenStream *pn_ts; /* token stream for XML error reports */
#endif
};
#define pn_funAtom pn_u.func.funAtom
#define pn_body pn_u.func.body
#define pn_flags pn_u.func.flags
#define pn_tryCount pn_u.func.tryCount
#define pn_head pn_u.list.head
#define pn_tail pn_u.list.tail
#define pn_count pn_u.list.count
#define pn_extra pn_u.list.extra
#define pn_kid1 pn_u.ternary.kid1
#define pn_kid2 pn_u.ternary.kid2
#define pn_kid3 pn_u.ternary.kid3
#define pn_left pn_u.binary.left
#define pn_right pn_u.binary.right
#define pn_val pn_u.binary.val
#define pn_kid pn_u.unary.kid
#define pn_num pn_u.unary.num
#define pn_atom pn_u.name.atom
#define pn_expr pn_u.name.expr
#define pn_slot pn_u.name.slot
#define pn_attrs pn_u.name.attrs
#define pn_dval pn_u.dval
#define pn_atom2 pn_u.apair.atom2
/* PN_LIST pn_extra flags. */
#define PNX_STRCAT 0x01 /* TOK_PLUS list has string term */
#define PNX_CANTFOLD 0x02 /* TOK_PLUS list has unfoldable term */
#define PNX_POPVAR 0x04 /* TOK_VAR last result needs popping */
#define PNX_FORINVAR 0x08 /* TOK_VAR is left kid of TOK_IN node,
which is left kid of TOK_FOR */
#define PNX_ENDCOMMA 0x10 /* array literal has comma at end */
#define PNX_XMLROOT 0x20 /* top-most node in XML literal tree */
/*
* Move pn2 into pn, preserving pn->pn_pos and pn->pn_offset and handing off
* any kids in pn2->pn_u, by clearing pn2.
*/
#define PN_MOVE_NODE(pn, pn2) \
JS_BEGIN_MACRO \
(pn)->pn_type = (pn2)->pn_type; \
(pn)->pn_op = (pn2)->pn_op; \
(pn)->pn_arity = (pn2)->pn_arity; \
(pn)->pn_u = (pn2)->pn_u; \
PN_CLEAR_NODE(pn2); \
JS_END_MACRO
#define PN_CLEAR_NODE(pn) \
JS_BEGIN_MACRO \
(pn)->pn_type = TOK_EOF; \
(pn)->pn_op = JSOP_NOP; \
(pn)->pn_arity = PN_NULLARY; \
JS_END_MACRO
/* True if pn is a parsenode representing a literal constant. */
#define PN_IS_CONSTANT(pn) \
((pn)->pn_type == TOK_NUMBER || \
(pn)->pn_type == TOK_STRING || \
((pn)->pn_type == TOK_PRIMARY && (pn)->pn_op != JSOP_THIS))
/*
* Compute a pointer to the last JSParseNode element in a singly-linked list.
* NB: list must be non-empty for correct PN_LAST usage!
*/
#define PN_LAST(list) \
((JSParseNode *)((char *)(list)->pn_tail - offsetof(JSParseNode, pn_next)))
#define PN_INIT_LIST(list) \
JS_BEGIN_MACRO \
(list)->pn_head = NULL; \
(list)->pn_tail = &(list)->pn_head; \
(list)->pn_count = (list)->pn_extra = 0; \
JS_END_MACRO
#define PN_INIT_LIST_1(list, pn) \
JS_BEGIN_MACRO \
(list)->pn_head = (pn); \
(list)->pn_tail = &(pn)->pn_next; \
(list)->pn_count = 1; \
(list)->pn_extra = 0; \
JS_END_MACRO
#define PN_APPEND(list, pn) \
JS_BEGIN_MACRO \
*(list)->pn_tail = (pn); \
(list)->pn_tail = &(pn)->pn_next; \
(list)->pn_count++; \
JS_END_MACRO
/*
* Parse a top-level JS script.
*
* The caller must prevent the GC from running while this function is active,
* because atoms and function newborns are not rooted yet.
*/
extern JS_FRIEND_API(JSParseNode *)
js_ParseTokenStream(JSContext *cx, JSObject *chain, JSTokenStream *ts);
extern JS_FRIEND_API(JSBool)
js_CompileTokenStream(JSContext *cx, JSObject *chain, JSTokenStream *ts,
JSCodeGenerator *cg);
extern JSBool
js_CompileFunctionBody(JSContext *cx, JSTokenStream *ts, JSFunction *fun);
extern JSBool
js_FoldConstants(JSContext *cx, JSParseNode *pn, JSTreeContext *tc);
#if JS_HAS_XML_SUPPORT
JS_FRIEND_API(JSParseNode *)
js_ParseXMLTokenStream(JSContext *cx, JSObject *chain, JSTokenStream *ts,
JSBool allowList);
#endif
JS_END_EXTERN_C
#endif /* jsparse_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,148 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsprf_h___
#define jsprf_h___
/*
** API for PR printf like routines. Supports the following formats
** %d - decimal
** %u - unsigned decimal
** %x - unsigned hex
** %X - unsigned uppercase hex
** %o - unsigned octal
** %hd, %hu, %hx, %hX, %ho - 16-bit versions of above
** %ld, %lu, %lx, %lX, %lo - 32-bit versions of above
** %lld, %llu, %llx, %llX, %llo - 64 bit versions of above
** %s - string
** %c - character
** %p - pointer (deals with machine dependent pointer size)
** %f - float
** %g - float
*/
#include "jstypes.h"
#include <stdio.h>
#include <stdarg.h>
JS_BEGIN_EXTERN_C
/*
** sprintf into a fixed size buffer. Guarantees that a NUL is at the end
** of the buffer. Returns the length of the written output, NOT including
** the NUL, or (JSUint32)-1 if an error occurs.
*/
extern JS_PUBLIC_API(JSUint32) JS_snprintf(char *out, JSUint32 outlen, const char *fmt, ...);
/*
** sprintf into a malloc'd buffer. Return a pointer to the malloc'd
** buffer on success, NULL on failure. Call "JS_smprintf_free" to release
** the memory returned.
*/
extern JS_PUBLIC_API(char*) JS_smprintf(const char *fmt, ...);
/*
** Free the memory allocated, for the caller, by JS_smprintf
*/
extern JS_PUBLIC_API(void) JS_smprintf_free(char *mem);
/*
** "append" sprintf into a malloc'd buffer. "last" is the last value of
** the malloc'd buffer. sprintf will append data to the end of last,
** growing it as necessary using realloc. If last is NULL, JS_sprintf_append
** will allocate the initial string. The return value is the new value of
** last for subsequent calls, or NULL if there is a malloc failure.
*/
extern JS_PUBLIC_API(char*) JS_sprintf_append(char *last, const char *fmt, ...);
/*
** sprintf into a function. The function "f" is called with a string to
** place into the output. "arg" is an opaque pointer used by the stuff
** function to hold any state needed to do the storage of the output
** data. The return value is a count of the number of characters fed to
** the stuff function, or (JSUint32)-1 if an error occurs.
*/
typedef JSIntn (*JSStuffFunc)(void *arg, const char *s, JSUint32 slen);
extern JS_PUBLIC_API(JSUint32) JS_sxprintf(JSStuffFunc f, void *arg, const char *fmt, ...);
/*
** va_list forms of the above.
*/
extern JS_PUBLIC_API(JSUint32) JS_vsnprintf(char *out, JSUint32 outlen, const char *fmt, va_list ap);
extern JS_PUBLIC_API(char*) JS_vsmprintf(const char *fmt, va_list ap);
extern JS_PUBLIC_API(char*) JS_vsprintf_append(char *last, const char *fmt, va_list ap);
extern JS_PUBLIC_API(JSUint32) JS_vsxprintf(JSStuffFunc f, void *arg, const char *fmt, va_list ap);
/*
***************************************************************************
** FUNCTION: JS_sscanf
** DESCRIPTION:
** JS_sscanf() scans the input character string, performs data
** conversions, and stores the converted values in the data objects
** pointed to by its arguments according to the format control
** string.
**
** JS_sscanf() behaves the same way as the sscanf() function in the
** Standard C Library (stdio.h), with the following exceptions:
** - JS_sscanf() handles the NSPR integer and floating point types,
** such as JSInt16, JSInt32, JSInt64, and JSFloat64, whereas
** sscanf() handles the standard C types like short, int, long,
** and double.
** - JS_sscanf() has no multibyte character support, while sscanf()
** does.
** INPUTS:
** const char *buf
** a character string holding the input to scan
** const char *fmt
** the format control string for the conversions
** ...
** variable number of arguments, each of them is a pointer to
** a data object in which the converted value will be stored
** OUTPUTS: none
** RETURNS: JSInt32
** The number of values converted and stored.
** RESTRICTIONS:
** Multibyte characters in 'buf' or 'fmt' are not allowed.
***************************************************************************
*/
extern JS_PUBLIC_API(JSInt32) JS_sscanf(const char *buf, const char *fmt, ...);
JS_END_EXTERN_C
#endif /* jsprf_h___ */

View File

@@ -1,203 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsprvtd_h___
#define jsprvtd_h___
/*
* JS private typename definitions.
*
* This header is included only in other .h files, for convenience and for
* simplicity of type naming. The alternative for structures is to use tags,
* which are named the same as their typedef names (legal in C/C++, and less
* noisy than suffixing the typedef name with "Struct" or "Str"). Instead,
* all .h files that include this file may use the same typedef name, whether
* declaring a pointer to struct type, or defining a member of struct type.
*
* A few fundamental scalar types are defined here too. Neither the scalar
* nor the struct typedefs should change much, therefore the nearly-global
* make dependency induced by this file should not prove painful.
*/
#include "jspubtd.h"
/* Internal identifier (jsid) macros. */
#define JSID_ATOM 0x0
#define JSID_INT 0x1
#define JSID_OBJECT 0x2
#define JSID_TAGMASK 0x3
#define JSID_TAG(id) ((id) & JSID_TAGMASK)
#define JSID_SETTAG(id,t) ((id) | (t))
#define JSID_CLRTAG(id) ((id) & ~(jsid)JSID_TAGMASK)
#define JSID_IS_ATOM(id) (JSID_TAG(id) == JSID_ATOM)
#define JSID_TO_ATOM(id) ((JSAtom *)(id))
#define ATOM_TO_JSID(atom) ((jsid)(atom))
#define ATOM_JSID_TO_JSVAL(id) ATOM_KEY(JSID_TO_ATOM(id))
#define JSID_IS_INT(id) ((id) & JSID_INT)
#define JSID_TO_INT(id) ((jsint)(id) >> 1)
#define INT_TO_JSID(i) (((jsint)(i) << 1) | JSID_INT)
#define INT_JSID_TO_JSVAL(id) (id)
#define INT_JSVAL_TO_JSID(v) (v)
#define JSID_IS_OBJECT(id) (JSID_TAG(id) == JSID_OBJECT)
#define JSID_TO_OBJECT(id) ((JSObject *) JSID_CLRTAG(id))
#define OBJECT_TO_JSID(obj) ((jsid)(obj) | JSID_OBJECT)
#define OBJECT_JSID_TO_JSVAL(id) OBJECT_TO_JSVAL(JSID_CLRTAG(id))
#define OBJECT_JSVAL_TO_JSID(v) OBJECT_TO_JSID(JSVAL_TO_OBJECT(v))
/* Scalar typedefs. */
typedef uint8 jsbytecode;
typedef uint8 jssrcnote;
typedef uint32 jsatomid;
/* Struct typedefs. */
typedef struct JSArgumentFormatMap JSArgumentFormatMap;
typedef struct JSCodeGenerator JSCodeGenerator;
typedef struct JSDependentString JSDependentString;
typedef struct JSGCLockHashEntry JSGCLockHashEntry;
typedef struct JSGCRootHashEntry JSGCRootHashEntry;
typedef struct JSGCThing JSGCThing;
typedef struct JSParseNode JSParseNode;
typedef struct JSSharpObjectMap JSSharpObjectMap;
typedef struct JSToken JSToken;
typedef struct JSTokenPos JSTokenPos;
typedef struct JSTokenPtr JSTokenPtr;
typedef struct JSTokenStream JSTokenStream;
typedef struct JSTreeContext JSTreeContext;
typedef struct JSTryNote JSTryNote;
/* Friend "Advanced API" typedefs. */
typedef struct JSAtom JSAtom;
typedef struct JSAtomList JSAtomList;
typedef struct JSAtomListElement JSAtomListElement;
typedef struct JSAtomMap JSAtomMap;
typedef struct JSAtomState JSAtomState;
typedef struct JSCodeSpec JSCodeSpec;
typedef struct JSPrinter JSPrinter;
typedef struct JSRegExp JSRegExp;
typedef struct JSRegExpStatics JSRegExpStatics;
typedef struct JSScope JSScope;
typedef struct JSScopeOps JSScopeOps;
typedef struct JSScopeProperty JSScopeProperty;
typedef struct JSStackFrame JSStackFrame;
typedef struct JSStackHeader JSStackHeader;
typedef struct JSStringBuffer JSStringBuffer;
typedef struct JSSubString JSSubString;
typedef struct JSXML JSXML;
typedef struct JSXMLNamespace JSXMLNamespace;
typedef struct JSXMLQName JSXMLQName;
typedef struct JSXMLArray JSXMLArray;
typedef struct JSXMLArrayCursor JSXMLArrayCursor;
/* "Friend" types used by jscntxt.h and jsdbgapi.h. */
typedef enum JSTrapStatus {
JSTRAP_ERROR,
JSTRAP_CONTINUE,
JSTRAP_RETURN,
JSTRAP_THROW,
JSTRAP_LIMIT
} JSTrapStatus;
typedef JSTrapStatus
(* JS_DLL_CALLBACK JSTrapHandler)(JSContext *cx, JSScript *script,
jsbytecode *pc, jsval *rval, void *closure);
typedef JSBool
(* JS_DLL_CALLBACK JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsval id,
jsval old, jsval *newp, void *closure);
/* called just after script creation */
typedef void
(* JS_DLL_CALLBACK JSNewScriptHook)(JSContext *cx,
const char *filename, /* URL of script */
uintN lineno, /* first line */
JSScript *script,
JSFunction *fun,
void *callerdata);
/* called just before script destruction */
typedef void
(* JS_DLL_CALLBACK JSDestroyScriptHook)(JSContext *cx,
JSScript *script,
void *callerdata);
typedef void
(* JS_DLL_CALLBACK JSSourceHandler)(const char *filename, uintN lineno,
jschar *str, size_t length,
void **listenerTSData, void *closure);
/*
* This hook captures high level script execution and function calls (JS or
* native). It is used by JS_SetExecuteHook to hook top level scripts and by
* JS_SetCallHook to hook function calls. It will get called twice per script
* or function call: just before execution begins and just after it finishes.
* In both cases the 'current' frame is that of the executing code.
*
* The 'before' param is JS_TRUE for the hook invocation before the execution
* and JS_FALSE for the invocation after the code has run.
*
* The 'ok' param is significant only on the post execution invocation to
* signify whether or not the code completed 'normally'.
*
* The 'closure' param is as passed to JS_SetExecuteHook or JS_SetCallHook
* for the 'before'invocation, but is whatever value is returned from that
* invocation for the 'after' invocation. Thus, the hook implementor *could*
* allocate a stucture in the 'before' invocation and return a pointer to that
* structure. The pointer would then be handed to the hook for the 'after'
* invocation. Alternately, the 'before' could just return the same value as
* in 'closure' to cause the 'after' invocation to be called with the same
* 'closure' value as the 'before'.
*
* Returning NULL in the 'before' hook will cause the 'after' hook *not* to
* be called.
*/
typedef void *
(* JS_DLL_CALLBACK JSInterpreterHook)(JSContext *cx, JSStackFrame *fp, JSBool before,
JSBool *ok, void *closure);
typedef void
(* JS_DLL_CALLBACK JSObjectHook)(JSContext *cx, JSObject *obj, JSBool isNew,
void *closure);
typedef JSBool
(* JS_DLL_CALLBACK JSDebugErrorHook)(JSContext *cx, const char *message,
JSErrorReport *report, void *closure);
#endif /* jsprvtd_h___ */

View File

@@ -1,604 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jspubtd_h___
#define jspubtd_h___
/*
* JS public API typedefs.
*/
#include "jstypes.h"
#include "jscompat.h"
JS_BEGIN_EXTERN_C
/* Scalar typedefs. */
typedef uint16 jschar;
typedef int32 jsint;
typedef uint32 jsuint;
typedef float64 jsdouble;
typedef jsword jsval;
typedef jsword jsid;
typedef int32 jsrefcount; /* PRInt32 if JS_THREADSAFE, see jslock.h */
/*
* Run-time version enumeration. See jsconfig.h for compile-time counterparts
* to these values that may be selected by the JS_VERSION macro, and tested by
* #if expressions.
*/
typedef enum JSVersion {
JSVERSION_1_0 = 100,
JSVERSION_1_1 = 110,
JSVERSION_1_2 = 120,
JSVERSION_1_3 = 130,
JSVERSION_1_4 = 140,
JSVERSION_ECMA_3 = 148,
JSVERSION_1_5 = 150,
JSVERSION_DEFAULT = 0,
JSVERSION_UNKNOWN = -1
} JSVersion;
#define JSVERSION_IS_ECMA(version) \
((version) == JSVERSION_DEFAULT || (version) >= JSVERSION_1_3)
/* Result of typeof operator enumeration. */
typedef enum JSType {
JSTYPE_VOID, /* undefined */
JSTYPE_OBJECT, /* object */
JSTYPE_FUNCTION, /* function */
JSTYPE_STRING, /* string */
JSTYPE_NUMBER, /* number */
JSTYPE_BOOLEAN, /* boolean */
JSTYPE_NULL, /* null */
JSTYPE_XML, /* xml object */
JSTYPE_LIMIT
} JSType;
/* JSObjectOps.checkAccess mode enumeration. */
typedef enum JSAccessMode {
JSACC_PROTO = 0, /* XXXbe redundant w.r.t. id */
JSACC_PARENT = 1, /* XXXbe redundant w.r.t. id */
JSACC_IMPORT = 2, /* import foo.bar */
JSACC_WATCH = 3, /* a watchpoint on object foo for id 'bar' */
JSACC_READ = 4, /* a "get" of foo.bar */
JSACC_WRITE = 8, /* a "set" of foo.bar = baz */
JSACC_LIMIT
} JSAccessMode;
#define JSACC_TYPEMASK (JSACC_WRITE - 1)
/*
* This enum type is used to control the behavior of a JSObject property
* iterator function that has type JSNewEnumerate.
*/
typedef enum JSIterateOp {
JSENUMERATE_INIT, /* Create new iterator state */
JSENUMERATE_NEXT, /* Iterate once */
JSENUMERATE_DESTROY /* Destroy iterator state */
} JSIterateOp;
/* Struct typedefs. */
typedef struct JSClass JSClass;
typedef struct JSExtendedClass JSExtendedClass;
typedef struct JSConstDoubleSpec JSConstDoubleSpec;
typedef struct JSContext JSContext;
typedef struct JSErrorReport JSErrorReport;
typedef struct JSFunction JSFunction;
typedef struct JSFunctionSpec JSFunctionSpec;
typedef struct JSIdArray JSIdArray;
typedef struct JSProperty JSProperty;
typedef struct JSPropertySpec JSPropertySpec;
typedef struct JSObject JSObject;
typedef struct JSObjectMap JSObjectMap;
typedef struct JSObjectOps JSObjectOps;
typedef struct JSXMLObjectOps JSXMLObjectOps;
typedef struct JSRuntime JSRuntime;
typedef struct JSRuntime JSTaskState; /* XXX deprecated name */
typedef struct JSScript JSScript;
typedef struct JSString JSString;
typedef struct JSXDRState JSXDRState;
typedef struct JSExceptionState JSExceptionState;
typedef struct JSLocaleCallbacks JSLocaleCallbacks;
/* JSClass (and JSObjectOps where appropriate) function pointer typedefs. */
/*
* Add, delete, get or set a property named by id in obj. Note the jsval id
* type -- id may be a string (Unicode property identifier) or an int (element
* index). The *vp out parameter, on success, is the new property value after
* an add, get, or set. After a successful delete, *vp is JSVAL_FALSE iff
* obj[id] can't be deleted (because it's permanent).
*/
typedef JSBool
(* JS_DLL_CALLBACK JSPropertyOp)(JSContext *cx, JSObject *obj, jsval id,
jsval *vp);
/*
* This function type is used for callbacks that enumerate the properties of
* a JSObject. The behavior depends on the value of enum_op:
*
* JSENUMERATE_INIT
* A new, opaque iterator state should be allocated and stored in *statep.
* (You can use PRIVATE_TO_JSVAL() to tag the pointer to be stored).
*
* The number of properties that will be enumerated should be returned as
* an integer jsval in *idp, if idp is non-null, and provided the number of
* enumerable properties is known. If idp is non-null and the number of
* enumerable properties can't be computed in advance, *idp should be set
* to JSVAL_ZERO.
*
* JSENUMERATE_NEXT
* A previously allocated opaque iterator state is passed in via statep.
* Return the next jsid in the iteration using *idp. The opaque iterator
* state pointed at by statep is destroyed and *statep is set to JSVAL_NULL
* if there are no properties left to enumerate.
*
* JSENUMERATE_DESTROY
* Destroy the opaque iterator state previously allocated in *statep by a
* call to this function when enum_op was JSENUMERATE_INIT.
*
* The return value is used to indicate success, with a value of JS_FALSE
* indicating failure.
*/
typedef JSBool
(* JS_DLL_CALLBACK JSNewEnumerateOp)(JSContext *cx, JSObject *obj,
JSIterateOp enum_op,
jsval *statep, jsid *idp);
/*
* The old-style JSClass.enumerate op should define all lazy properties not
* yet reflected in obj.
*/
typedef JSBool
(* JS_DLL_CALLBACK JSEnumerateOp)(JSContext *cx, JSObject *obj);
/*
* Resolve a lazy property named by id in obj by defining it directly in obj.
* Lazy properties are those reflected from some peer native property space
* (e.g., the DOM attributes for a given node reflected as obj) on demand.
*
* JS looks for a property in an object, and if not found, tries to resolve
* the given id. If resolve succeeds, the engine looks again in case resolve
* defined obj[id]. If no such property exists directly in obj, the process
* is repeated with obj's prototype, etc.
*
* NB: JSNewResolveOp provides a cheaper way to resolve lazy properties.
*/
typedef JSBool
(* JS_DLL_CALLBACK JSResolveOp)(JSContext *cx, JSObject *obj, jsval id);
/*
* Like JSResolveOp, but flags provide contextual information as follows:
*
* JSRESOLVE_QUALIFIED a qualified property id: obj.id or obj[id], not id
* JSRESOLVE_ASSIGNING obj[id] is on the left-hand side of an assignment
*
* The *objp out parameter, on success, should be null to indicate that id
* was not resolved; and non-null, referring to obj or one of its prototypes,
* if id was resolved.
*
* This hook instead of JSResolveOp is called via the JSClass.resolve member
* if JSCLASS_NEW_RESOLVE is set in JSClass.flags.
*
* Setting JSCLASS_NEW_RESOLVE and JSCLASS_NEW_RESOLVE_GETS_START further
* extends this hook by passing in the starting object on the prototype chain
* via *objp. Thus a resolve hook implementation may define the property id
* being resolved in the object in which the id was first sought, rather than
* in a prototype object whose class led to the resolve hook being called.
*
* When using JSCLASS_NEW_RESOLVE_GETS_START, the resolve hook must therefore
* null *objp to signify "not resolved". With only JSCLASS_NEW_RESOLVE and no
* JSCLASS_NEW_RESOLVE_GETS_START, the hook can assume *objp is null on entry.
* This is not good practice, but enough existing hook implementations count
* on it that we can't break compatibility by passing the starting object in
* *objp without a new JSClass flag.
*/
typedef JSBool
(* JS_DLL_CALLBACK JSNewResolveOp)(JSContext *cx, JSObject *obj, jsval id,
uintN flags, JSObject **objp);
/*
* Convert obj to the given type, returning true with the resulting value in
* *vp on success, and returning false on error or exception.
*/
typedef JSBool
(* JS_DLL_CALLBACK JSConvertOp)(JSContext *cx, JSObject *obj, JSType type,
jsval *vp);
/*
* Finalize obj, which the garbage collector has determined to be unreachable
* from other live objects or from GC roots. Obviously, finalizers must never
* store a reference to obj.
*/
typedef void
(* JS_DLL_CALLBACK JSFinalizeOp)(JSContext *cx, JSObject *obj);
/*
* Used by JS_AddExternalStringFinalizer and JS_RemoveExternalStringFinalizer
* to extend and reduce the set of string types finalized by the GC.
*/
typedef void
(* JS_DLL_CALLBACK JSStringFinalizeOp)(JSContext *cx, JSString *str);
/*
* The signature for JSClass.getObjectOps, used by JS_NewObject's internals
* to discover the set of high-level object operations to use for new objects
* of the given class. All native objects have a JSClass, which is stored as
* a private (int-tagged) pointer in obj->slots[JSSLOT_CLASS]. In contrast,
* all native and host objects have a JSObjectMap at obj->map, which may be
* shared among a number of objects, and which contains the JSObjectOps *ops
* pointer used to dispatch object operations from API calls.
*
* Thus JSClass (which pre-dates JSObjectOps in the API) provides a low-level
* interface to class-specific code and data, while JSObjectOps allows for a
* higher level of operation, which does not use the object's class except to
* find the class's JSObjectOps struct, by calling clasp->getObjectOps, and to
* finalize the object.
*
* If this seems backwards, that's because it is! API compatibility requires
* a JSClass *clasp parameter to JS_NewObject, etc. Most host objects do not
* need to implement the larger JSObjectOps, and can share the common JSScope
* code and data used by the native (js_ObjectOps, see jsobj.c) ops.
*
* Further extension to preserve API compatibility: if this function returns
* a pointer to JSXMLObjectOps.base, not to JSObjectOps, then the engine calls
* extended hooks needed for E4X.
*/
typedef JSObjectOps *
(* JS_DLL_CALLBACK JSGetObjectOps)(JSContext *cx, JSClass *clasp);
/*
* JSClass.checkAccess type: check whether obj[id] may be accessed per mode,
* returning false on error/exception, true on success with obj[id]'s last-got
* value in *vp, and its attributes in *attrsp. As for JSPropertyOp above, id
* is either a string or an int jsval.
*
* See JSCheckAccessIdOp, below, for the JSObjectOps counterpart, which takes
* a jsid (a tagged int or aligned, unique identifier pointer) rather than a
* jsval. The native js_ObjectOps.checkAccess simply forwards to the object's
* clasp->checkAccess, so that both JSClass and JSObjectOps implementors may
* specialize access checks.
*/
typedef JSBool
(* JS_DLL_CALLBACK JSCheckAccessOp)(JSContext *cx, JSObject *obj, jsval id,
JSAccessMode mode, jsval *vp);
/*
* Encode or decode an object, given an XDR state record representing external
* data. See jsxdrapi.h.
*/
typedef JSBool
(* JS_DLL_CALLBACK JSXDRObjectOp)(JSXDRState *xdr, JSObject **objp);
/*
* Check whether v is an instance of obj. Return false on error or exception,
* true on success with JS_TRUE in *bp if v is an instance of obj, JS_FALSE in
* *bp otherwise.
*/
typedef JSBool
(* JS_DLL_CALLBACK JSHasInstanceOp)(JSContext *cx, JSObject *obj, jsval v,
JSBool *bp);
/*
* Function type for JSClass.mark and JSObjectOps.mark, called from the GC to
* scan live GC-things reachable from obj's private data structure. For each
* such thing, a mark implementation must call
*
* JS_MarkGCThing(cx, thing, name, arg);
*
* The trailing name and arg parameters are used for GC_MARK_DEBUG-mode heap
* dumping and ref-path tracing. The mark function should pass a (typically
* literal) string naming the private data member for name, and it must pass
* the opaque arg parameter through from its caller.
*
* For the JSObjectOps.mark hook, the return value is the number of slots at
* obj->slots to scan. For JSClass.mark, the return value is ignored.
*
* NB: JSMarkOp implementations cannot allocate new GC-things (JS_NewObject
* called from a mark function will fail silently, e.g.).
*/
typedef uint32
(* JS_DLL_CALLBACK JSMarkOp)(JSContext *cx, JSObject *obj, void *arg);
/*
* The optional JSClass.reserveSlots hook allows a class to make computed
* per-instance object slots reservations, in addition to or instead of using
* JSCLASS_HAS_RESERVED_SLOTS(n) in the JSClass.flags initializer to reserve
* a constant-per-class number of slots. Implementations of this hook should
* return the number of slots to reserve, not including any reserved by using
* JSCLASS_HAS_RESERVED_SLOTS(n) in JSClass.flags.
*
* NB: called with obj locked by the JSObjectOps-specific mutual exclusion
* mechanism appropriate for obj, so don't nest other operations that might
* also lock obj.
*/
typedef uint32
(* JS_DLL_CALLBACK JSReserveSlotsOp)(JSContext *cx, JSObject *obj);
/* JSObjectOps function pointer typedefs. */
/*
* Create a new subclass of JSObjectMap (see jsobj.h), with the nrefs and ops
* members initialized from the same-named parameters, and with the nslots and
* freeslot members initialized according to ops and clasp. Return null on
* error, non-null on success.
*
* JSObjectMaps are reference-counted by generic code in the engine. Usually,
* the nrefs parameter to JSObjectOps.newObjectMap will be 1, to count the ref
* returned to the caller on success. After a successful construction, some
* number of js_HoldObjectMap and js_DropObjectMap calls ensue. When nrefs
* reaches 0 due to a js_DropObjectMap call, JSObjectOps.destroyObjectMap will
* be called to dispose of the map.
*/
typedef JSObjectMap *
(* JS_DLL_CALLBACK JSNewObjectMapOp)(JSContext *cx, jsrefcount nrefs,
JSObjectOps *ops, JSClass *clasp,
JSObject *obj);
/*
* Generic type for an infallible JSObjectMap operation, used currently by
* JSObjectOps.destroyObjectMap.
*/
typedef void
(* JS_DLL_CALLBACK JSObjectMapOp)(JSContext *cx, JSObjectMap *map);
/*
* Look for id in obj and its prototype chain, returning false on error or
* exception, true on success. On success, return null in *propp if id was
* not found. If id was found, return the first object searching from obj
* along its prototype chain in which id names a direct property in *objp, and
* return a non-null, opaque property pointer in *propp.
*
* If JSLookupPropOp succeeds and returns with *propp non-null, that pointer
* may be passed as the prop parameter to a JSAttributesOp, as a short-cut
* that bypasses id re-lookup. In any case, a non-null *propp result after a
* successful lookup must be dropped via JSObjectOps.dropProperty.
*
* NB: successful return with non-null *propp means the implementation may
* have locked *objp and added a reference count associated with *propp, so
* callers should not risk deadlock by nesting or interleaving other lookups
* or any obj-bearing ops before dropping *propp.
*/
typedef JSBool
(* JS_DLL_CALLBACK JSLookupPropOp)(JSContext *cx, JSObject *obj, jsid id,
JSObject **objp, JSProperty **propp);
/*
* Define obj[id], a direct property of obj named id, having the given initial
* value, with the specified getter, setter, and attributes. If the propp out
* param is non-null, *propp on successful return contains an opaque property
* pointer usable as a speedup hint with JSAttributesOp. But note that propp
* may be null, indicating that the caller is not interested in recovering an
* opaque pointer to the newly-defined property.
*
* If propp is non-null and JSDefinePropOp succeeds, its caller must be sure
* to drop *propp using JSObjectOps.dropProperty in short order, just as with
* JSLookupPropOp.
*/
typedef JSBool
(* JS_DLL_CALLBACK JSDefinePropOp)(JSContext *cx, JSObject *obj,
jsid id, jsval value,
JSPropertyOp getter, JSPropertyOp setter,
uintN attrs, JSProperty **propp);
/*
* Get, set, or delete obj[id], returning false on error or exception, true
* on success. If getting or setting, the new value is returned in *vp on
* success. If deleting without error, *vp will be JSVAL_FALSE if obj[id] is
* permanent, and JSVAL_TRUE if id named a direct property of obj that was in
* fact deleted, or if id names no direct property of obj (id could name a
* prototype property, or no property in obj or its prototype chain).
*/
typedef JSBool
(* JS_DLL_CALLBACK JSPropertyIdOp)(JSContext *cx, JSObject *obj, jsid id,
jsval *vp);
/*
* Get or set attributes of the property obj[id]. Return false on error or
* exception, true with current attributes in *attrsp. If prop is non-null,
* it must come from the *propp out parameter of a prior JSDefinePropOp or
* JSLookupPropOp call.
*/
typedef JSBool
(* JS_DLL_CALLBACK JSAttributesOp)(JSContext *cx, JSObject *obj, jsid id,
JSProperty *prop, uintN *attrsp);
/*
* JSObjectOps.checkAccess type: check whether obj[id] may be accessed per
* mode, returning false on error/exception, true on success with obj[id]'s
* last-got value in *vp, and its attributes in *attrsp.
*/
typedef JSBool
(* JS_DLL_CALLBACK JSCheckAccessIdOp)(JSContext *cx, JSObject *obj, jsid id,
JSAccessMode mode, jsval *vp,
uintN *attrsp);
/*
* A generic type for functions mapping an object to another object, or null
* if an error or exception was thrown on cx. Used by JSObjectOps.thisObject
* at present.
*/
typedef JSObject *
(* JS_DLL_CALLBACK JSObjectOp)(JSContext *cx, JSObject *obj);
/*
* A generic type for functions taking a context, object, and property, with
* no return value. Used by JSObjectOps.dropProperty currently (see above,
* JSDefinePropOp and JSLookupPropOp, for the object-locking protocol in which
* dropProperty participates).
*/
typedef void
(* JS_DLL_CALLBACK JSPropertyRefOp)(JSContext *cx, JSObject *obj,
JSProperty *prop);
/*
* Function type for JSObjectOps.setProto and JSObjectOps.setParent. These
* hooks must check for cycles without deadlocking, and otherwise take special
* steps. See jsobj.c, js_SetProtoOrParent, for an example.
*/
typedef JSBool
(* JS_DLL_CALLBACK JSSetObjectSlotOp)(JSContext *cx, JSObject *obj,
uint32 slot, JSObject *pobj);
/*
* Get and set a required slot, one that should already have been allocated.
* These operations are infallible, so required slots must be pre-allocated,
* or implementations must suppress out-of-memory errors. The native ops
* (js_ObjectOps, see jsobj.c) access slots reserved by including a call to
* the JSCLASS_HAS_RESERVED_SLOTS(n) macro in the JSClass.flags initializer.
*
* NB: the slot parameter is a zero-based index into obj->slots[], unlike the
* index parameter to the JS_GetReservedSlot and JS_SetReservedSlot API entry
* points, which is a zero-based index into the JSCLASS_RESERVED_SLOTS(clasp)
* reserved slots that come after the initial well-known slots: proto, parent,
* class, and optionally, the private data slot.
*/
typedef jsval
(* JS_DLL_CALLBACK JSGetRequiredSlotOp)(JSContext *cx, JSObject *obj,
uint32 slot);
typedef JSBool
(* JS_DLL_CALLBACK JSSetRequiredSlotOp)(JSContext *cx, JSObject *obj,
uint32 slot, jsval v);
typedef JSObject *
(* JS_DLL_CALLBACK JSGetMethodOp)(JSContext *cx, JSObject *obj, jsid id,
jsval *vp);
typedef JSBool
(* JS_DLL_CALLBACK JSEnumerateValuesOp)(JSContext *cx, JSObject *obj,
JSIterateOp enum_op,
jsval *statep, jsid *idp, jsval *vp);
typedef JSBool
(* JS_DLL_CALLBACK JSEqualityOp)(JSContext *cx, JSObject *obj, jsval v,
JSBool *bp);
typedef JSBool
(* JS_DLL_CALLBACK JSConcatenateOp)(JSContext *cx, JSObject *obj, jsval v,
jsval *vp);
/* Typedef for native functions called by the JS VM. */
typedef JSBool
(* JS_DLL_CALLBACK JSNative)(JSContext *cx, JSObject *obj, uintN argc,
jsval *argv, jsval *rval);
/* Callbacks and their arguments. */
typedef enum JSGCStatus {
JSGC_BEGIN,
JSGC_END,
JSGC_MARK_END,
JSGC_FINALIZE_END
} JSGCStatus;
typedef JSBool
(* JS_DLL_CALLBACK JSGCCallback)(JSContext *cx, JSGCStatus status);
typedef JSBool
(* JS_DLL_CALLBACK JSBranchCallback)(JSContext *cx, JSScript *script);
typedef void
(* JS_DLL_CALLBACK JSErrorReporter)(JSContext *cx, const char *message,
JSErrorReport *report);
typedef struct JSErrorFormatString {
const char *format;
uintN argCount;
} JSErrorFormatString;
typedef const JSErrorFormatString *
(* JS_DLL_CALLBACK JSErrorCallback)(void *userRef, const char *locale,
const uintN errorNumber);
#ifdef va_start
#define JS_ARGUMENT_FORMATTER_DEFINED 1
typedef JSBool
(* JS_DLL_CALLBACK JSArgumentFormatter)(JSContext *cx, const char *format,
JSBool fromJS, jsval **vpp,
va_list *app);
#endif
typedef JSBool
(* JS_DLL_CALLBACK JSLocaleToUpperCase)(JSContext *cx, JSString *src,
jsval *rval);
typedef JSBool
(* JS_DLL_CALLBACK JSLocaleToLowerCase)(JSContext *cx, JSString *src,
jsval *rval);
typedef JSBool
(* JS_DLL_CALLBACK JSLocaleCompare)(JSContext *cx,
JSString *src1, JSString *src2,
jsval *rval);
typedef JSBool
(* JS_DLL_CALLBACK JSLocaleToUnicode)(JSContext *cx, char *src, jsval *rval);
/*
* Security protocol types.
*/
typedef struct JSPrincipals JSPrincipals;
/*
* XDR-encode or -decode a principals instance, based on whether xdr->mode is
* JSXDR_ENCODE, in which case *principalsp should be encoded; or JSXDR_DECODE,
* in which case implementations must return a held (via JSPRINCIPALS_HOLD),
* non-null *principalsp out parameter. Return true on success, false on any
* error, which the implementation must have reported.
*/
typedef JSBool
(* JS_DLL_CALLBACK JSPrincipalsTranscoder)(JSXDRState *xdr,
JSPrincipals **principalsp);
/*
* Return a weak reference to the principals associated with obj, possibly via
* the immutable parent chain leading from obj to a top-level container (e.g.,
* a window object in the DOM level 0). If there are no principals associated
* with obj, return null. Therefore null does not mean an error was reported;
* in no event should an error be reported or an exception be thrown by this
* callback's implementation.
*/
typedef JSPrincipals *
(* JS_DLL_CALLBACK JSObjectPrincipalsFinder)(JSContext *cx, JSObject *obj);
JS_END_EXTERN_C
#endif /* jspubtd_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,180 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsregexp_h___
#define jsregexp_h___
/*
* JS regular expression interface.
*/
#include <stddef.h>
#include "jspubtd.h"
#include "jsstr.h"
#ifdef JS_THREADSAFE
#include "jsdhash.h"
#endif
struct JSRegExpStatics {
JSString *input; /* input string to match (perl $_, GC root) */
JSBool multiline; /* whether input contains newlines (perl $*) */
uint16 parenCount; /* number of valid elements in parens[] */
uint16 moreLength; /* number of allocated elements in moreParens */
JSSubString parens[9]; /* last set of parens matched (perl $1, $2) */
JSSubString *moreParens; /* null or realloc'd vector for $10, etc. */
JSSubString lastMatch; /* last string matched (perl $&) */
JSSubString lastParen; /* last paren matched (perl $+) */
JSSubString leftContext; /* input to left of last match (perl $`) */
JSSubString rightContext; /* input to right of last match (perl $') */
};
/*
* This struct holds a bitmap representation of a class from a regexp.
* There's a list of these referenced by the classList field in the JSRegExp
* struct below. The initial state has startIndex set to the offset in the
* original regexp source of the beginning of the class contents. The first
* use of the class converts the source representation into a bitmap.
*
*/
typedef struct RECharSet {
JSPackedBool converted;
JSPackedBool sense;
uint16 length;
union {
uint8 *bits;
struct {
uint16 startIndex;
uint16 length;
} src;
} u;
} RECharSet;
/*
* This macro is safe because moreParens is guaranteed to be allocated and big
* enough to hold parenCount, or else be null when parenCount is 0.
*/
#define REGEXP_PAREN_SUBSTRING(res, num) \
(((jsuint)(num) < (jsuint)(res)->parenCount) \
? ((jsuint)(num) < 9) \
? &(res)->parens[num] \
: &(res)->moreParens[(num) - 9] \
: &js_EmptySubString)
typedef struct RENode RENode;
struct JSRegExp {
jsrefcount nrefs; /* reference count */
uint16 flags; /* flags, see jsapi.h's JSREG_* defines */
uint16 cloneIndex; /* index in fp->vars or funobj->slots of
cloned regexp object */
uint16 parenCount; /* number of parenthesized submatches */
uint16 classCount; /* count [...] bitmaps */
RECharSet *classList; /* list of [...] bitmaps */
JSString *source; /* locked source string, sans // */
jsbytecode program[1]; /* regular expression bytecode */
};
extern JSRegExp *
js_NewRegExp(JSContext *cx, JSTokenStream *ts,
JSString *str, uintN flags, JSBool flat);
extern JSRegExp *
js_NewRegExpOpt(JSContext *cx, JSTokenStream *ts,
JSString *str, JSString *opt, JSBool flat);
extern void
js_DestroyRegExp(JSContext *cx, JSRegExp *re);
/*
* Execute re on input str at *indexp, returning null in *rval on mismatch.
* On match, return true if test is true, otherwise return an array object.
* Update *indexp and cx->regExpStatics always on match.
*/
extern JSBool
js_ExecuteRegExp(JSContext *cx, JSRegExp *re, JSString *str, size_t *indexp,
JSBool test, jsval *rval);
/*
* These two add and remove GC roots, respectively, so their calls must be
* well-ordered.
*/
extern JSBool
js_InitRegExpStatics(JSContext *cx, JSRegExpStatics *res);
extern void
js_FreeRegExpStatics(JSContext *cx, JSRegExpStatics *res);
#define JSVAL_IS_REGEXP(cx, v) \
(JSVAL_IS_OBJECT(v) && JSVAL_TO_OBJECT(v) && \
OBJ_GET_CLASS(cx, JSVAL_TO_OBJECT(v)) == &js_RegExpClass)
extern JSClass js_RegExpClass;
extern JSObject *
js_InitRegExpClass(JSContext *cx, JSObject *obj);
/*
* Export js_regexp_toString to the decompiler.
*/
extern JSBool
js_regexp_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval);
/*
* Create, serialize/deserialize, or clone a RegExp object.
*/
extern JSObject *
js_NewRegExpObject(JSContext *cx, JSTokenStream *ts,
jschar *chars, size_t length, uintN flags);
extern JSBool
js_XDRRegExp(JSXDRState *xdr, JSObject **objp);
extern JSObject *
js_CloneRegExpObject(JSContext *cx, JSObject *obj, JSObject *parent);
/*
* Get and set the per-object (clone or clone-parent) lastIndex slot.
*/
extern JSBool
js_GetLastIndex(JSContext *cx, JSObject *obj, jsdouble *lastIndex);
extern JSBool
js_SetLastIndex(JSContext *cx, JSObject *obj, jsdouble lastIndex);
#endif /* jsregexp_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,335 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsscan_h___
#define jsscan_h___
/*
* JS lexical scanner interface.
*/
#include <stddef.h>
#include <stdio.h>
#include "jsopcode.h"
#include "jsprvtd.h"
#include "jspubtd.h"
JS_BEGIN_EXTERN_C
typedef enum JSTokenType {
TOK_ERROR = -1, /* well-known as the only code < EOF */
TOK_EOF = 0, /* end of file */
TOK_EOL = 1, /* end of line */
TOK_SEMI = 2, /* semicolon */
TOK_COMMA = 3, /* comma operator */
TOK_ASSIGN = 4, /* assignment ops (= += -= etc.) */
TOK_HOOK = 5, TOK_COLON = 6, /* conditional (?:) */
TOK_OR = 7, /* logical or (||) */
TOK_AND = 8, /* logical and (&&) */
TOK_BITOR = 9, /* bitwise-or (|) */
TOK_BITXOR = 10, /* bitwise-xor (^) */
TOK_BITAND = 11, /* bitwise-and (&) */
TOK_EQOP = 12, /* equality ops (== !=) */
TOK_RELOP = 13, /* relational ops (< <= > >=) */
TOK_SHOP = 14, /* shift ops (<< >> >>>) */
TOK_PLUS = 15, /* plus */
TOK_MINUS = 16, /* minus */
TOK_STAR = 17, TOK_DIVOP = 18, /* multiply/divide ops (* / %) */
TOK_UNARYOP = 19, /* unary prefix operator */
TOK_INC = 20, TOK_DEC = 21, /* increment/decrement (++ --) */
TOK_DOT = 22, /* member operator (.) */
TOK_LB = 23, TOK_RB = 24, /* left and right brackets */
TOK_LC = 25, TOK_RC = 26, /* left and right curlies (braces) */
TOK_LP = 27, TOK_RP = 28, /* left and right parentheses */
TOK_NAME = 29, /* identifier */
TOK_NUMBER = 30, /* numeric constant */
TOK_STRING = 31, /* string constant */
TOK_OBJECT = 32, /* RegExp or other object constant */
TOK_PRIMARY = 33, /* true, false, null, this, super */
TOK_FUNCTION = 34, /* function keyword */
TOK_EXPORT = 35, /* export keyword */
TOK_IMPORT = 36, /* import keyword */
TOK_IF = 37, /* if keyword */
TOK_ELSE = 38, /* else keyword */
TOK_SWITCH = 39, /* switch keyword */
TOK_CASE = 40, /* case keyword */
TOK_DEFAULT = 41, /* default keyword */
TOK_WHILE = 42, /* while keyword */
TOK_DO = 43, /* do keyword */
TOK_FOR = 44, /* for keyword */
TOK_BREAK = 45, /* break keyword */
TOK_CONTINUE = 46, /* continue keyword */
TOK_IN = 47, /* in keyword */
TOK_VAR = 48, /* var keyword */
TOK_WITH = 49, /* with keyword */
TOK_RETURN = 50, /* return keyword */
TOK_NEW = 51, /* new keyword */
TOK_DELETE = 52, /* delete keyword */
TOK_DEFSHARP = 53, /* #n= for object/array initializers */
TOK_USESHARP = 54, /* #n# for object/array initializers */
TOK_TRY = 55, /* try keyword */
TOK_CATCH = 56, /* catch keyword */
TOK_FINALLY = 57, /* finally keyword */
TOK_THROW = 58, /* throw keyword */
TOK_INSTANCEOF = 59, /* instanceof keyword */
TOK_DEBUGGER = 60, /* debugger keyword */
TOK_XMLSTAGO = 61, /* XML start tag open (<) */
TOK_XMLETAGO = 62, /* XML end tag open (</) */
TOK_XMLPTAGC = 63, /* XML point tag close (/>) */
TOK_XMLTAGC = 64, /* XML start or end tag close (>) */
TOK_XMLNAME = 65, /* XML start-tag non-final fragment */
TOK_XMLATTR = 66, /* XML quoted attribute value */
TOK_XMLSPACE = 67, /* XML whitespace */
TOK_XMLTEXT = 68, /* XML text */
TOK_XMLCOMMENT = 69, /* XML comment */
TOK_XMLCDATA = 70, /* XML CDATA section */
TOK_XMLPI = 71, /* XML processing instruction */
TOK_AT = 72, /* XML attribute op (@) */
TOK_DBLCOLON = 73, /* namespace qualified name op (::) */
TOK_ANYNAME = 74, /* XML AnyName singleton (*) */
TOK_DBLDOT = 75, /* XML descendant op (..) */
TOK_FILTER = 76, /* XML filtering predicate op (.()) */
TOK_XMLELEM = 77, /* XML element node type (no token) */
TOK_XMLLIST = 78, /* XML list node type (no token) */
TOK_RESERVED, /* reserved keywords */
TOK_LIMIT /* domain size */
} JSTokenType;
#define IS_PRIMARY_TOKEN(tt) \
((uintN)((tt) - TOK_NAME) <= (uintN)(TOK_PRIMARY - TOK_NAME))
#define TOKEN_TYPE_IS_XML(tt) \
(tt == TOK_AT || tt == TOK_DBLCOLON || tt == TOK_ANYNAME)
struct JSStringBuffer {
jschar *base;
jschar *limit; /* length limit for quick bounds check */
jschar *ptr; /* slot for next non-NUL char to store */
void *data;
JSBool (*grow)(JSStringBuffer *sb, size_t newlength);
void (*free)(JSStringBuffer *sb);
};
#define STRING_BUFFER_ERROR_BASE ((jschar *) 1)
#define STRING_BUFFER_OK(sb) ((sb)->base != STRING_BUFFER_ERROR_BASE)
#define STRING_BUFFER_OFFSET(sb) ((sb)->ptr -(sb)->base)
extern void
js_InitStringBuffer(JSStringBuffer *sb);
extern void
js_FinishStringBuffer(JSStringBuffer *sb);
extern void
js_AppendChar(JSStringBuffer *sb, jschar c);
extern void
js_RepeatChar(JSStringBuffer *sb, jschar c, uintN count);
extern void
js_AppendCString(JSStringBuffer *sb, const char *asciiz);
extern void
js_AppendJSString(JSStringBuffer *sb, JSString *str);
struct JSTokenPtr {
uint16 index; /* index of char in physical line */
uint16 lineno; /* physical line number */
};
struct JSTokenPos {
JSTokenPtr begin; /* first character and line of token */
JSTokenPtr end; /* index 1 past last char, last line */
};
struct JSToken {
JSTokenType type; /* char value or above enumerator */
JSTokenPos pos; /* token position in file */
jschar *ptr; /* beginning of token in line buffer */
union {
struct { /* non-numeric literal */
JSOp op; /* operator, for minimal parser */
JSAtom *atom; /* atom table entry */
} s;
struct { /* atom pair, for XML PIs */
JSAtom *atom2; /* auxiliary atom table entry */
JSAtom *atom; /* main atom table entry */
} p;
jsdouble dval; /* floating point number */
} u;
};
#define t_op u.s.op
#define t_atom u.s.atom
#define t_atom2 u.p.atom2
#define t_dval u.dval
typedef struct JSTokenBuf {
jschar *base; /* base of line or stream buffer */
jschar *limit; /* limit for quick bounds check */
jschar *ptr; /* next char to get, or slot to use */
} JSTokenBuf;
#define JS_LINE_LIMIT 256 /* logical line buffer size limit --
physical line length is unlimited */
#define NTOKENS 4 /* 1 current + 2 lookahead, rounded */
#define NTOKENS_MASK (NTOKENS-1) /* to power of 2 to avoid divmod by 3 */
struct JSTokenStream {
JSToken tokens[NTOKENS];/* circular token buffer */
uintN cursor; /* index of last parsed token */
uintN lookahead; /* count of lookahead tokens */
uintN lineno; /* current line number */
uintN ungetpos; /* next free char slot in ungetbuf */
jschar ungetbuf[6]; /* at most 6, for \uXXXX lookahead */
uintN flags; /* flags -- see below */
ptrdiff_t linelen; /* physical linebuf segment length */
ptrdiff_t linepos; /* linebuf offset in physical line */
JSTokenBuf linebuf; /* line buffer for diagnostics */
JSTokenBuf userbuf; /* user input buffer if !file */
JSStringBuffer tokenbuf; /* current token string buffer */
const char *filename; /* input filename or null */
FILE *file; /* stdio stream if reading from file */
JSPrincipals *principals; /* principals associated with source */
JSSourceHandler listener; /* callback for source; eg debugger */
void *listenerData; /* listener 'this' data */
void *listenerTSData;/* listener data for this TokenStream */
jschar *saveEOL; /* save next end of line in userbuf, to
optimize for very long lines */
};
#define CURRENT_TOKEN(ts) ((ts)->tokens[(ts)->cursor])
#define ON_CURRENT_LINE(ts,pos) ((uint16)(ts)->lineno == (pos).end.lineno)
/* JSTokenStream flags */
#define TSF_ERROR 0x01 /* fatal error while compiling */
#define TSF_EOF 0x02 /* hit end of file */
#define TSF_NEWLINES 0x04 /* tokenize newlines */
#define TSF_OPERAND 0x08 /* looking for operand, not operator */
#define TSF_NLFLAG 0x20 /* last linebuf ended with \n */
#define TSF_CRFLAG 0x40 /* linebuf would have ended with \r */
#define TSF_DIRTYLINE 0x80 /* non-whitespace since start of line */
#define TSF_OWNFILENAME 0x100 /* ts->filename is malloc'd */
#define TSF_XMLTAGMODE 0x200 /* scanning within an XML tag in E4X */
#define TSF_XMLTEXTMODE 0x400 /* scanning XMLText terminal from E4X */
#define TSF_XMLONLYMODE 0x800 /* don't scan {expr} within text/tag */
/* Flag indicating unexpected end of input, i.e. TOK_EOF not at top-level. */
#define TSF_UNEXPECTED_EOF 0x1000
/* Unicode separators that are treated as line terminators, in addition to \n, \r */
#define LINE_SEPARATOR 0x2028
#define PARA_SEPARATOR 0x2029
/*
* Create a new token stream, either from an input buffer or from a file.
* Return null on file-open or memory-allocation failure.
*
* NB: All of js_New{,Buffer,File}TokenStream() return a pointer to transient
* memory in the current context's temp pool. This memory is deallocated via
* JS_ARENA_RELEASE() after parsing is finished.
*/
extern JSTokenStream *
js_NewTokenStream(JSContext *cx, const jschar *base, size_t length,
const char *filename, uintN lineno, JSPrincipals *principals);
extern JS_FRIEND_API(JSTokenStream *)
js_NewBufferTokenStream(JSContext *cx, const jschar *base, size_t length);
extern JS_FRIEND_API(JSTokenStream *)
js_NewFileTokenStream(JSContext *cx, const char *filename, FILE *defaultfp);
extern JS_FRIEND_API(JSBool)
js_CloseTokenStream(JSContext *cx, JSTokenStream *ts);
/*
* Initialize the scanner, installing JS keywords into cx's global scope.
*/
extern JSBool
js_InitScanner(JSContext *cx);
/*
* Friend-exported API entry point to call a mapping function on each reserved
* identifier in the scanner's keyword table.
*/
extern JS_FRIEND_API(void)
js_MapKeywords(void (*mapfun)(const char *));
/*
* Report a compile-time error by its number, using ts or cg to show context.
* Return true for a warning, false for an error.
*/
extern JSBool
js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags,
uintN errorNumber, ...);
/* Steal some JSREPORT_* bits (see jsapi.h) to tell handle's type. */
#define JSREPORT_HANDLE 0x300
#define JSREPORT_TS 0x000
#define JSREPORT_CG 0x100
#define JSREPORT_PN 0x200
/*
* Look ahead one token and return its type.
*/
extern JSTokenType
js_PeekToken(JSContext *cx, JSTokenStream *ts);
extern JSTokenType
js_PeekTokenSameLine(JSContext *cx, JSTokenStream *ts);
/*
* Get the next token from ts.
*/
extern JSTokenType
js_GetToken(JSContext *cx, JSTokenStream *ts);
/*
* Push back the last scanned token onto ts.
*/
extern void
js_UngetToken(JSTokenStream *ts);
/*
* Get the next token from ts if its type is tt.
*/
extern JSBool
js_MatchToken(JSContext *cx, JSTokenStream *ts, JSTokenType tt);
JS_END_EXTERN_C
#endif /* jsscan_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,392 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsscope_h___
#define jsscope_h___
/*
* JS symbol tables.
*/
#include "jstypes.h"
#include "jsobj.h"
#include "jsprvtd.h"
#include "jspubtd.h"
#ifdef JS_THREADSAFE
# include "jslock.h"
#endif
/*
* Given P independent, non-unique properties each of size S words mapped by
* all scopes in a runtime, construct a property tree of N nodes each of size
* S+L words (L for tree linkage). A nominal L value is 2 for leftmost-child
* and right-sibling links. We hope that the N < P by enough that the space
* overhead of L, and the overhead of scope entries pointing at property tree
* nodes, is worth it.
*
* The tree construction goes as follows. If any empty scope in the runtime
* has a property X added to it, find or create a node under the tree root
* labeled X, and set scope->lastProp to point at that node. If any non-empty
* scope whose most recently added property is labeled Y has another property
* labeled Z added, find or create a node for Z under the node that was added
* for Y, and set scope->lastProp to point at that node.
*
* A property is labeled by its members' values: id, getter, setter, slot,
* attributes, tiny or short id, and a field telling for..in order. Note that
* labels are not unique in the tree, but they are unique among a node's kids
* (barring rare and benign multi-threaded race condition outcomes, see below)
* and along any ancestor line from the tree root to a given leaf node (except
* for the hard case of duplicate formal parameters to a function).
*
* Thus the root of the tree represents all empty scopes, and the first ply
* of the tree represents all scopes containing one property, etc. Each node
* in the tree can stand for any number of scopes having the same ordered set
* of properties, where that node was the last added to the scope. (We need
* not store the root of the tree as a node, and do not -- all we need are
* links to its kids.)
*
* Sidebar on for..in loop order: ECMA requires no particular order, but this
* implementation has promised and delivered property definition order, and
* compatibility is king. We could use an order number per property, which
* would require a sort in js_Enumerate, and an entry order generation number
* per scope. An order number beats a list, which should be doubly-linked for
* O(1) delete. An even better scheme is to use a parent link in the property
* tree, so that the ancestor line can be iterated from scope->lastProp when
* filling in a JSIdArray from back to front. This parent link also helps the
* GC to sweep properties iteratively.
*
* What if a property Y is deleted from a scope? If Y is the last property in
* the scope, we simply adjust the scope's lastProp member after we remove the
* scope's hash-table entry pointing at that property node. The parent link
* mentioned in the for..in sidebar above makes this adjustment O(1). But if
* Y comes between X and Z in the scope, then we might have to "fork" the tree
* at X, leaving X->Y->Z in case other scopes have those properties added in
* that order; and to finish the fork, we'd add a node labeled Z with the path
* X->Z, if it doesn't exist. This could lead to lots of extra nodes, and to
* O(n^2) growth when deleting lots of properties.
*
* Rather, for O(1) growth all around, we should share the path X->Y->Z among
* scopes having those three properties added in that order, and among scopes
* having only X->Z where Y was deleted. All such scopes have a lastProp that
* points to the Z child of Y. But a scope in which Y was deleted does not
* have a table entry for Y, and when iterating that scope by traversing the
* ancestor line from Z, we will have to test for a table entry for each node,
* skipping nodes that lack entries.
*
* What if we add Y again? X->Y->Z->Y is wrong and we'll enumerate Y twice.
* Therefore we must fork in such a case, if not earlier. Because delete is
* "bursty", we should not fork eagerly. Delaying a fork till we are at risk
* of adding Y after it was deleted already requires a flag in the JSScope, to
* wit, SCOPE_MIDDLE_DELETE.
*
* What about thread safety? If the property tree operations done by requests
* are find-node and insert-node, then the only hazard is duplicate insertion.
* This is harmless except for minor bloat. When all requests have ended or
* been suspended, the GC is free to sweep the tree after marking all nodes
* reachable from scopes, performing remove-node operations as needed. Note
* also that the stable storage of the property nodes during active requests
* permits the property cache (see jsinterp.h) to dereference JSScopeProperty
* weak references safely.
*
* Is the property tree worth it compared to property storage in each table's
* entries? To decide, we must find the relation <> between the words used
* with a property tree and the words required without a tree.
*
* Model all scopes as one super-scope of capacity T entries (T a power of 2).
* Let alpha be the load factor of this double hash-table. With the property
* tree, each entry in the table is a word-sized pointer to a node that can be
* shared by many scopes. But all such pointers are overhead compared to the
* situation without the property tree, where the table stores property nodes
* directly, as entries each of size S words. With the property tree, we need
* L=2 extra words per node for siblings and kids pointers. Without the tree,
* (1-alpha)*S*T words are wasted on free or removed sentinel-entries required
* by double hashing.
*
* Therefore,
*
* (property tree) <> (no property tree)
* N*(S+L) + T <> S*T
* N*(S+L) + T <> P*S + (1-alpha)*S*T
* N*(S+L) + alpha*T + (1-alpha)*T <> P*S + (1-alpha)*S*T
*
* Note that P is alpha*T by definition, so
*
* N*(S+L) + P + (1-alpha)*T <> P*S + (1-alpha)*S*T
* N*(S+L) <> P*S - P + (1-alpha)*S*T - (1-alpha)*T
* N*(S+L) <> (P + (1-alpha)*T) * (S-1)
* N*(S+L) <> (P + (1-alpha)*P/alpha) * (S-1)
* N*(S+L) <> P * (1/alpha) * (S-1)
*
* Let N = P*beta for a compression ratio beta, beta <= 1:
*
* P*beta*(S+L) <> P * (1/alpha) * (S-1)
* beta*(S+L) <> (S-1)/alpha
* beta <> (S-1)/((S+L)*alpha)
*
* For S = 6 (32-bit architectures) and L = 2, the property tree wins iff
*
* beta < 5/(8*alpha)
*
* We ensure that alpha <= .75, so the property tree wins if beta < .83_. An
* average beta from recent Mozilla browser startups was around .6.
*
* Can we reduce L? Observe that the property tree degenerates into a list of
* lists if at most one property Y follows X in all scopes. In or near such a
* case, we waste a word on the right-sibling link outside of the root ply of
* the tree. Note also that the root ply tends to be large, so O(n^2) growth
* searching it is likely, indicating the need for hashing (but with increased
* thread safety costs).
*
* If only K out of N nodes in the property tree have more than one child, we
* could eliminate the sibling link and overlay a children list or hash-table
* pointer on the leftmost-child link (which would then be either null or an
* only-child link; the overlay could be tagged in the low bit of the pointer,
* or flagged elsewhere in the property tree node, although such a flag must
* not be considered when comparing node labels during tree search).
*
* For such a system, L = 1 + (K * averageChildrenTableSize) / N instead of 2.
* If K << N, L approaches 1 and the property tree wins if beta < .95.
*
* We observe that fan-out below the root ply of the property tree appears to
* have extremely low degree (see the MeterPropertyTree code that histograms
* child-counts in jsscope.c), so instead of a hash-table we use a linked list
* of child node pointer arrays ("kid chunks"). The details are isolated in
* jsscope.c; others must treat JSScopeProperty.kids as opaque. We leave it
* strongly typed for debug-ability of the common (null or one-kid) cases.
*
* One final twist (can you stand it?): the mean number of entries per scope
* in Mozilla is < 5, with a large standard deviation (~8). Instead of always
* allocating scope->table, we leave it null while initializing all the other
* scope members as if it were non-null and minimal-length. Until a property
* is added that crosses the threshold of 6 or more entries for hashing, or
* until a "middle delete" occurs, we use linear search from scope->lastProp
* to find a given id, and save on the space overhead of a hash table.
*/
struct JSScope {
JSObjectMap map; /* base class state */
JSObject *object; /* object that owns this scope */
uint8 flags; /* flags, see below */
int8 hashShift; /* multiplicative hash shift */
uint16 dswIndex; /* Deutsch-Schorr-Waite scaled index */
uint32 entryCount; /* number of entries in table */
uint32 removedCount; /* removed entry sentinels in table */
JSScopeProperty **table; /* table of ptrs to shared tree nodes */
JSScopeProperty *lastProp; /* pointer to last property added */
#ifdef JS_THREADSAFE
JSContext *ownercx; /* creating context, NULL if shared */
JSThinLock lock; /* binary semaphore protecting scope */
union { /* union lockful and lock-free state: */
jsrefcount count; /* lock entry count for reentrancy */
JSScope *link; /* next link in rt->scopeSharingTodo */
} u;
#ifdef DEBUG
const char *file[4]; /* file where lock was (re-)taken */
unsigned int line[4]; /* line where lock was (re-)taken */
#endif
#endif
};
#define OBJ_SCOPE(obj) ((JSScope *)(obj)->map)
/* By definition, hashShift = JS_DHASH_BITS - log2(capacity). */
#define SCOPE_CAPACITY(scope) JS_BIT(JS_DHASH_BITS-(scope)->hashShift)
/* Scope flags and some macros to hide them from other files than jsscope.c. */
#define SCOPE_MIDDLE_DELETE 0x0001
#define SCOPE_SEALED 0x0002
#define SCOPE_HAD_MIDDLE_DELETE(scope) ((scope)->flags & SCOPE_MIDDLE_DELETE)
#define SCOPE_SET_MIDDLE_DELETE(scope) ((scope)->flags |= SCOPE_MIDDLE_DELETE)
#define SCOPE_CLR_MIDDLE_DELETE(scope) ((scope)->flags &= ~SCOPE_MIDDLE_DELETE)
#define SCOPE_IS_SEALED(scope) ((scope)->flags & SCOPE_SEALED)
#define SCOPE_SET_SEALED(scope) ((scope)->flags |= SCOPE_SEALED)
#if 0
/*
* Don't define this, it can't be done safely because JS_LOCK_OBJ will avoid
* taking the lock if the object owns its scope and the scope is sealed.
*/
#define SCOPE_CLR_SEALED(scope) ((scope)->flags &= ~SCOPE_SEALED)
#endif
/*
* A little information hiding for scope->lastProp, in case it ever becomes
* a tagged pointer again.
*/
#define SCOPE_LAST_PROP(scope) ((scope)->lastProp)
#define SCOPE_REMOVE_LAST_PROP(scope) ((scope)->lastProp = \
(scope)->lastProp->parent)
struct JSScopeProperty {
jsid id; /* int-tagged jsval/untagged JSAtom* */
JSPropertyOp getter; /* getter and setter hooks or objects */
JSPropertyOp setter;
uint32 slot; /* index in obj->slots vector */
uint8 attrs; /* attributes, see jsapi.h JSPROP_* */
uint8 flags; /* flags, see below for defines */
int16 shortid; /* tinyid, or local arg/var index */
JSScopeProperty *parent; /* parent node, reverse for..in order */
JSScopeProperty *kids; /* null, single child, or a tagged ptr
to many-kids data structure */
};
/* JSScopeProperty pointer tag bit indicating a collision. */
#define SPROP_COLLISION ((jsuword)1)
#define SPROP_REMOVED ((JSScopeProperty *) SPROP_COLLISION)
/* Macros to get and set sprop pointer values and collision flags. */
#define SPROP_IS_FREE(sprop) ((sprop) == NULL)
#define SPROP_IS_REMOVED(sprop) ((sprop) == SPROP_REMOVED)
#define SPROP_IS_LIVE(sprop) ((sprop) > SPROP_REMOVED)
#define SPROP_FLAG_COLLISION(spp,sprop) (*(spp) = (JSScopeProperty *) \
((jsuword)(sprop) | SPROP_COLLISION))
#define SPROP_HAD_COLLISION(sprop) ((jsuword)(sprop) & SPROP_COLLISION)
#define SPROP_FETCH(spp) SPROP_CLEAR_COLLISION(*(spp))
#define SPROP_CLEAR_COLLISION(sprop) \
((JSScopeProperty *) ((jsuword)(sprop) & ~SPROP_COLLISION))
#define SPROP_STORE_PRESERVING_COLLISION(spp, sprop) \
(*(spp) = (JSScopeProperty *) ((jsuword)(sprop) \
| SPROP_HAD_COLLISION(*(spp))))
/* Bits stored in sprop->flags. */
#define SPROP_MARK 0x01
#define SPROP_IS_DUPLICATE 0x02
#define SPROP_IS_ALIAS 0x04
#define SPROP_HAS_SHORTID 0x08
/*
* If SPROP_HAS_SHORTID is set in sprop->flags, we use sprop->shortid rather
* than id when calling sprop's getter or setter.
*/
#define SPROP_USERID(sprop) \
(((sprop)->flags & SPROP_HAS_SHORTID) ? INT_TO_JSVAL((sprop)->shortid) \
: ID_TO_VALUE((sprop)->id))
#define SPROP_INVALID_SLOT 0xffffffff
#define SPROP_HAS_VALID_SLOT(sprop, scope) \
((sprop)->slot < (scope)->map.freeslot)
#define SPROP_HAS_STUB_GETTER(sprop) (!(sprop)->getter)
#define SPROP_HAS_STUB_SETTER(sprop) (!(sprop)->setter)
#define SPROP_CALL_GETTER(cx,sprop,getter,obj,obj2,vp) \
(!(getter) || \
(getter)(cx, OBJ_THIS_OBJECT(cx,obj), SPROP_USERID(sprop), vp))
#define SPROP_CALL_SETTER(cx,sprop,setter,obj,obj2,vp) \
(!(setter) || \
(setter)(cx, OBJ_THIS_OBJECT(cx,obj), SPROP_USERID(sprop), vp))
#define SPROP_GET(cx,sprop,obj,obj2,vp) \
(((sprop)->attrs & JSPROP_GETTER) \
? js_InternalGetOrSet(cx, obj, (sprop)->id, \
OBJECT_TO_JSVAL((sprop)->getter), JSACC_READ, \
0, 0, vp) \
: SPROP_CALL_GETTER(cx, sprop, (sprop)->getter, obj, obj2, vp))
#define SPROP_SET(cx,sprop,obj,obj2,vp) \
(((sprop)->attrs & JSPROP_SETTER) \
? js_InternalGetOrSet(cx, obj, (sprop)->id, \
OBJECT_TO_JSVAL((sprop)->setter), JSACC_WRITE, \
1, vp, vp) \
: ((sprop)->attrs & JSPROP_GETTER) \
? (JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, \
JSMSG_GETTER_ONLY, NULL), JS_FALSE) \
: SPROP_CALL_SETTER(cx, sprop, (sprop)->setter, obj, obj2, vp))
/* Macro for common expression to test for shared permanent attributes. */
#define SPROP_IS_SHARED_PERMANENT(sprop) \
((~(sprop)->attrs & (JSPROP_SHARED | JSPROP_PERMANENT)) == 0)
extern JSScope *
js_GetMutableScope(JSContext *cx, JSObject *obj);
extern JSScope *
js_NewScope(JSContext *cx, jsrefcount nrefs, JSObjectOps *ops, JSClass *clasp,
JSObject *obj);
extern void
js_DestroyScope(JSContext *cx, JSScope *scope);
#define ID_TO_VALUE(id) (JSID_IS_ATOM(id) ? ATOM_JSID_TO_JSVAL(id) : \
JSID_IS_OBJECT(id) ? OBJECT_JSID_TO_JSVAL(id) : \
(jsval)(id))
#define HASH_ID(id) (JSID_IS_ATOM(id) ? JSID_TO_ATOM(id)->number : \
JSID_IS_OBJECT(id) ? (jsatomid) JSID_CLRTAG(id) : \
(jsatomid) JSID_TO_INT(id))
extern JS_FRIEND_API(JSScopeProperty **)
js_SearchScope(JSScope *scope, jsid id, JSBool adding);
#define SCOPE_GET_PROPERTY(scope, id) \
SPROP_FETCH(js_SearchScope(scope, id, JS_FALSE))
#define SCOPE_HAS_PROPERTY(scope, sprop) \
(SCOPE_GET_PROPERTY(scope, (sprop)->id) == (sprop))
extern JSScopeProperty *
js_AddScopeProperty(JSContext *cx, JSScope *scope, jsid id,
JSPropertyOp getter, JSPropertyOp setter, uint32 slot,
uintN attrs, uintN flags, intN shortid);
extern JSScopeProperty *
js_ChangeScopePropertyAttrs(JSContext *cx, JSScope *scope,
JSScopeProperty *sprop, uintN attrs, uintN mask,
JSPropertyOp getter, JSPropertyOp setter);
extern JSBool
js_RemoveScopeProperty(JSContext *cx, JSScope *scope, jsid id);
extern void
js_ClearScope(JSContext *cx, JSScope *scope);
#define MARK_SCOPE_PROPERTY(sprop) ((sprop)->flags |= SPROP_MARK)
extern void
js_SweepScopeProperties(JSRuntime *rt);
extern JSBool
js_InitPropertyTree(JSRuntime *rt);
extern void
js_FinishPropertyTree(JSRuntime *rt);
#endif /* jsscope_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,182 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsscript_h___
#define jsscript_h___
/*
* JS script descriptor.
*/
#include "jsatom.h"
#include "jsprvtd.h"
JS_BEGIN_EXTERN_C
/*
* Exception handling runtime information.
*
* All fields except length are code offsets, relative to the beginning of
* the script. If script->trynotes is not null, it points to a vector of
* these structs terminated by one with catchStart == 0.
*/
struct JSTryNote {
ptrdiff_t start; /* start of try statement */
ptrdiff_t length; /* count of try statement bytecodes */
ptrdiff_t catchStart; /* start of catch block (0 if end) */
};
#define JSTRYNOTE_GRAIN sizeof(ptrdiff_t)
#define JSTRYNOTE_ALIGNMASK (JSTRYNOTE_GRAIN - 1)
struct JSScript {
jsbytecode *code; /* bytecodes and their immediate operands */
uint32 length; /* length of code vector */
jsbytecode *main; /* main entry point, after predef'ing prolog */
uint16 version; /* JS version under which script was compiled */
uint16 numGlobalVars; /* declared global var/const/function count */
JSAtomMap atomMap; /* maps immediate index to literal struct */
const char *filename; /* source filename or null */
uintN lineno; /* base line number of script */
uintN depth; /* maximum stack depth in slots */
JSTryNote *trynotes; /* exception table for this script */
JSPrincipals *principals; /* principals for this script */
JSObject *object; /* optional Script-class object wrapper */
};
/* No need to store script->notes now that it is allocated right after code. */
#define SCRIPT_NOTES(script) ((jssrcnote*)((script)->code+(script)->length))
#define SCRIPT_FIND_CATCH_START(script, pc, catchpc) \
JS_BEGIN_MACRO \
JSTryNote *tn_ = (script)->trynotes; \
jsbytecode *catchpc_ = NULL; \
if (tn_) { \
ptrdiff_t off_ = PTRDIFF(pc, (script)->main, jsbytecode); \
if (off_ >= 0) { \
while ((jsuword)(off_ - tn_->start) >= (jsuword)tn_->length) \
++tn_; \
if (tn_->catchStart) \
catchpc_ = (script)->main + tn_->catchStart; \
} \
} \
catchpc = catchpc_; \
JS_END_MACRO
extern JS_FRIEND_DATA(JSClass) js_ScriptClass;
extern JSObject *
js_InitScriptClass(JSContext *cx, JSObject *obj);
extern JSBool
js_InitRuntimeScriptState(JSContext *cx);
extern void
js_FinishRuntimeScriptState(JSContext *cx);
extern const char *
js_SaveScriptFilename(JSContext *cx, const char *filename);
extern void
js_MarkScriptFilename(const char *filename);
extern void
js_SweepScriptFilenames(JSRuntime *rt);
/*
* Two successively less primitive ways to make a new JSScript. The first
* does *not* call a non-null cx->runtime->newScriptHook -- only the second,
* js_NewScriptFromCG, calls this optional debugger hook.
*
* The js_NewScript function can't know whether the script it creates belongs
* to a function, or is top-level or eval code, but the debugger wants access
* to the newly made script's function, if any -- so callers of js_NewScript
* are responsible for notifying the debugger after successfully creating any
* kind (function or other) of new JSScript.
*/
extern JSScript *
js_NewScript(JSContext *cx, uint32 length, uint32 snlength, uint32 tnlength);
extern JS_FRIEND_API(JSScript *)
js_NewScriptFromCG(JSContext *cx, JSCodeGenerator *cg, JSFunction *fun);
/*
* New-script-hook calling is factored from js_NewScriptFromCG so that it
* and callers of js_XDRScript can share this code. In the case of callers
* of js_XDRScript, the hook should be invoked only after successful decode
* of any owning function (the fun parameter) or script object (null fun).
*/
extern JS_FRIEND_API(void)
js_CallNewScriptHook(JSContext *cx, JSScript *script, JSFunction *fun);
extern JS_FRIEND_API(void)
js_CallDestroyScriptHook(JSContext *cx, JSScript *script);
extern void
js_DestroyScript(JSContext *cx, JSScript *script);
extern void
js_MarkScript(JSContext *cx, JSScript *script, void *arg);
extern jssrcnote *
js_GetSrcNote(JSScript *script, jsbytecode *pc);
/* XXX need cx to lock function objects declared by prolog bytecodes. */
extern uintN
js_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc);
extern jsbytecode *
js_LineNumberToPC(JSScript *script, uintN lineno);
extern uintN
js_GetScriptLineExtent(JSScript *script);
/*
* If magic is non-null, js_XDRScript succeeds on magic number mismatch but
* returns false in *magic; it reflects a match via a true *magic out param.
* If magic is null, js_XDRScript returns false on bad magic number errors,
* which it reports.
*
* NB: callers must call js_CallNewScriptHook after successful JSXDR_DECODE
* and subsequent set-up of owning function or script object, if any.
*/
extern JSBool
js_XDRScript(JSXDRState *xdr, JSScript **scriptp, JSBool *magic);
JS_END_EXTERN_C
#endif /* jsscript_h___ */

View File

@@ -1,50 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
Error messages for JSShell. See js.msg for format.
*/
MSG_DEF(JSSMSG_NOT_AN_ERROR, 0, 0, JSEXN_NONE, "<Error #0 is reserved>")
MSG_DEF(JSSMSG_CANT_OPEN, 1, 2, JSEXN_NONE, "can't open {0}: {1}")
MSG_DEF(JSSMSG_TRAP_USAGE, 2, 0, JSEXN_NONE, "usage: trap [fun] [pc] expr")
MSG_DEF(JSSMSG_LINE2PC_USAGE, 3, 0, JSEXN_NONE, "usage: line2pc [fun] line")
MSG_DEF(JSSMSG_FILE_SCRIPTS_ONLY, 4, 0, JSEXN_NONE, "only works on JS scripts read from files")
MSG_DEF(JSSMSG_UNEXPECTED_EOF, 5, 1, JSEXN_NONE, "unexpected EOF in {0}")
MSG_DEF(JSSMSG_DOEXP_USAGE, 6, 0, JSEXN_NONE, "usage: doexp obj id")

View File

@@ -1,83 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* stddef inclusion here to first declare ptrdif as a signed long instead of a
* signed int.
*/
#ifdef _WINDOWS
# ifndef XP_WIN
# define XP_WIN
# endif
#if defined(_WIN32) || defined(WIN32)
# ifndef XP_WIN32
# define XP_WIN32
# endif
#else
# ifndef XP_WIN16
# define XP_WIN16
# endif
#endif
#endif
#ifdef XP_WIN16
#ifndef _PTRDIFF_T_DEFINED
typedef long ptrdiff_t;
/*
* The Win16 compiler treats pointer differences as 16-bit signed values.
* This macro allows us to treat them as 17-bit signed values, stored in
* a 32-bit type.
*/
#define PTRDIFF(p1, p2, type) \
((((unsigned long)(p1)) - ((unsigned long)(p2))) / sizeof(type))
#define _PTRDIFF_T_DEFINED
#endif /*_PTRDIFF_T_DEFINED*/
#else /*WIN16*/
#define PTRDIFF(p1, p2, type) \
((p1) - (p2))
#endif
#include <stddef.h>

File diff suppressed because it is too large Load Diff

View File

@@ -1,462 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsstr_h___
#define jsstr_h___
/*
* JS string type implementation.
*
* A JS string is a counted array of unicode characters. To support handoff
* of API client memory, the chars are allocated separately from the length,
* necessitating a pointer after the count, to form a separately allocated
* string descriptor. String descriptors are GC'ed, while their chars are
* allocated from the malloc heap.
*
* When a string is treated as an object (by following it with . or []), the
* runtime wraps it with a JSObject whose valueOf method returns the unwrapped
* string descriptor.
*/
#include <ctype.h>
#include "jspubtd.h"
#include "jsprvtd.h"
#include "jshash.h"
JS_BEGIN_EXTERN_C
/*
* The original GC-thing "string" type, a flat character string owned by its
* GC-thing descriptor. The chars member points to a vector having byte size
* (length + 1) * sizeof(jschar), terminated at index length by a zero jschar.
* The terminator is purely a backstop, in case the chars pointer flows out to
* native code that requires \u0000 termination.
*
* NB: Always use the JSSTRING_LENGTH and JSSTRING_CHARS accessor macros,
* unless you guard str->member uses with !JSSTRING_IS_DEPENDENT(str).
*/
struct JSString {
size_t length;
jschar *chars;
};
/*
* Overlay structure for a string that depends on another string's characters.
* Distinguished by the JSSTRFLAG_DEPENDENT bit being set in length. The base
* member may point to another dependent string if JSSTRING_CHARS has not been
* called yet. The length chars in a dependent string are stored starting at
* base->chars + start, and are not necessarily zero-terminated. If start is
* 0, it is not stored, length is a full size_t (minus the JSSTRFLAG_* bits in
* the high two positions), and the JSSTRFLAG_PREFIX flag is set.
*/
struct JSDependentString {
size_t length;
JSString *base;
};
/* Definitions for flags stored in the high order bits of JSString.length. */
#define JSSTRFLAG_BITS 2
#define JSSTRFLAG_SHIFT(flg) ((size_t)(flg) << JSSTRING_LENGTH_BITS)
#define JSSTRFLAG_MASK JSSTRFLAG_SHIFT(JS_BITMASK(JSSTRFLAG_BITS))
#define JSSTRFLAG_DEPENDENT JSSTRFLAG_SHIFT(1)
#define JSSTRFLAG_PREFIX JSSTRFLAG_SHIFT(2)
/* Universal JSString type inquiry and accessor macros. */
#define JSSTRING_BIT(n) ((size_t)1 << (n))
#define JSSTRING_BITMASK(n) (JSSTRING_BIT(n) - 1)
#define JSSTRING_HAS_FLAG(str,flg) ((str)->length & (flg))
#define JSSTRING_IS_DEPENDENT(str) JSSTRING_HAS_FLAG(str, JSSTRFLAG_DEPENDENT)
#define JSSTRING_IS_PREFIX(str) JSSTRING_HAS_FLAG(str, JSSTRFLAG_PREFIX)
#define JSSTRING_CHARS(str) (JSSTRING_IS_DEPENDENT(str) \
? JSSTRDEP_CHARS(str) \
: (str)->chars)
#define JSSTRING_LENGTH(str) (JSSTRING_IS_DEPENDENT(str) \
? JSSTRDEP_LENGTH(str) \
: (str)->length)
#define JSSTRING_LENGTH_BITS (sizeof(size_t) * JS_BITS_PER_BYTE \
- JSSTRFLAG_BITS)
#define JSSTRING_LENGTH_MASK JSSTRING_BITMASK(JSSTRING_LENGTH_BITS)
/* Specific JSDependentString shift/mask accessor and mutator macros. */
#define JSSTRDEP_START_BITS (JSSTRING_LENGTH_BITS-JSSTRDEP_LENGTH_BITS)
#define JSSTRDEP_START_SHIFT JSSTRDEP_LENGTH_BITS
#define JSSTRDEP_START_MASK JSSTRING_BITMASK(JSSTRDEP_START_BITS)
#define JSSTRDEP_LENGTH_BITS (JSSTRING_LENGTH_BITS / 2)
#define JSSTRDEP_LENGTH_MASK JSSTRING_BITMASK(JSSTRDEP_LENGTH_BITS)
#define JSSTRDEP(str) ((JSDependentString *)(str))
#define JSSTRDEP_START(str) (JSSTRING_IS_PREFIX(str) ? 0 \
: ((JSSTRDEP(str)->length \
>> JSSTRDEP_START_SHIFT) \
& JSSTRDEP_START_MASK))
#define JSSTRDEP_LENGTH(str) (JSSTRDEP(str)->length \
& (JSSTRING_IS_PREFIX(str) \
? JSSTRING_LENGTH_MASK \
: JSSTRDEP_LENGTH_MASK))
#define JSSTRDEP_SET_START_AND_LENGTH(str,off,len) \
(JSSTRDEP(str)->length = JSSTRFLAG_DEPENDENT \
| ((off) << JSSTRDEP_START_SHIFT) \
| (len))
#define JSPREFIX_SET_LENGTH(str,len) \
(JSSTRDEP(str)->length = JSSTRFLAG_DEPENDENT | JSSTRFLAG_PREFIX | (len))
#define JSSTRDEP_BASE(str) (JSSTRDEP(str)->base)
#define JSSTRDEP_SET_BASE(str,bstr) (JSSTRDEP(str)->base = (bstr))
#define JSPREFIX_BASE(str) JSSTRDEP_BASE(str)
#define JSPREFIX_SET_BASE(str,bstr) JSSTRDEP_SET_BASE(str,bstr)
#define JSSTRDEP_CHARS(str) \
(JSSTRING_IS_DEPENDENT(JSSTRDEP_BASE(str)) \
? js_GetDependentStringChars(str) \
: JSSTRDEP_BASE(str)->chars + JSSTRDEP_START(str))
extern size_t
js_MinimizeDependentStrings(JSString *str, int level, JSString **basep);
extern jschar *
js_GetDependentStringChars(JSString *str);
extern jschar *
js_GetStringChars(JSString *str);
extern JSString *
js_ConcatStrings(JSContext *cx, JSString *left, JSString *right);
extern const jschar *
js_UndependString(JSContext *cx, JSString *str);
struct JSSubString {
size_t length;
const jschar *chars;
};
extern jschar js_empty_ucstr[];
extern JSSubString js_EmptySubString;
/* Unicode character attribute lookup tables. */
extern const uint8 js_X[];
extern const uint8 js_Y[];
extern const uint32 js_A[];
/* Enumerated Unicode general category types. */
typedef enum JSCharType {
JSCT_UNASSIGNED = 0,
JSCT_UPPERCASE_LETTER = 1,
JSCT_LOWERCASE_LETTER = 2,
JSCT_TITLECASE_LETTER = 3,
JSCT_MODIFIER_LETTER = 4,
JSCT_OTHER_LETTER = 5,
JSCT_NON_SPACING_MARK = 6,
JSCT_ENCLOSING_MARK = 7,
JSCT_COMBINING_SPACING_MARK = 8,
JSCT_DECIMAL_DIGIT_NUMBER = 9,
JSCT_LETTER_NUMBER = 10,
JSCT_OTHER_NUMBER = 11,
JSCT_SPACE_SEPARATOR = 12,
JSCT_LINE_SEPARATOR = 13,
JSCT_PARAGRAPH_SEPARATOR = 14,
JSCT_CONTROL = 15,
JSCT_FORMAT = 16,
JSCT_PRIVATE_USE = 18,
JSCT_SURROGATE = 19,
JSCT_DASH_PUNCTUATION = 20,
JSCT_START_PUNCTUATION = 21,
JSCT_END_PUNCTUATION = 22,
JSCT_CONNECTOR_PUNCTUATION = 23,
JSCT_OTHER_PUNCTUATION = 24,
JSCT_MATH_SYMBOL = 25,
JSCT_CURRENCY_SYMBOL = 26,
JSCT_MODIFIER_SYMBOL = 27,
JSCT_OTHER_SYMBOL = 28
} JSCharType;
/* Character classifying and mapping macros, based on java.lang.Character. */
#define JS_CCODE(c) (js_A[js_Y[(js_X[(uint16)(c)>>6]<<6)|((c)&0x3F)]])
#define JS_CTYPE(c) (JS_CCODE(c) & 0x1F)
#define JS_ISALPHA(c) ((((1 << JSCT_UPPERCASE_LETTER) | \
(1 << JSCT_LOWERCASE_LETTER) | \
(1 << JSCT_TITLECASE_LETTER) | \
(1 << JSCT_MODIFIER_LETTER) | \
(1 << JSCT_OTHER_LETTER)) \
>> JS_CTYPE(c)) & 1)
#define JS_ISALNUM(c) ((((1 << JSCT_UPPERCASE_LETTER) | \
(1 << JSCT_LOWERCASE_LETTER) | \
(1 << JSCT_TITLECASE_LETTER) | \
(1 << JSCT_MODIFIER_LETTER) | \
(1 << JSCT_OTHER_LETTER) | \
(1 << JSCT_DECIMAL_DIGIT_NUMBER)) \
>> JS_CTYPE(c)) & 1)
/* A unicode letter, suitable for use in an identifier. */
#define JS_ISLETTER(c) ((((1 << JSCT_UPPERCASE_LETTER) | \
(1 << JSCT_LOWERCASE_LETTER) | \
(1 << JSCT_TITLECASE_LETTER) | \
(1 << JSCT_MODIFIER_LETTER) | \
(1 << JSCT_OTHER_LETTER) | \
(1 << JSCT_LETTER_NUMBER)) \
>> JS_CTYPE(c)) & 1)
/*
* 'IdentifierPart' from ECMA grammar, is Unicode letter or combining mark or
* digit or connector punctuation.
*/
#define JS_ISIDPART(c) ((((1 << JSCT_UPPERCASE_LETTER) | \
(1 << JSCT_LOWERCASE_LETTER) | \
(1 << JSCT_TITLECASE_LETTER) | \
(1 << JSCT_MODIFIER_LETTER) | \
(1 << JSCT_OTHER_LETTER) | \
(1 << JSCT_LETTER_NUMBER) | \
(1 << JSCT_NON_SPACING_MARK) | \
(1 << JSCT_COMBINING_SPACING_MARK) | \
(1 << JSCT_DECIMAL_DIGIT_NUMBER) | \
(1 << JSCT_CONNECTOR_PUNCTUATION)) \
>> JS_CTYPE(c)) & 1)
/* Unicode control-format characters, ignored in input */
#define JS_ISFORMAT(c) (((1 << JSCT_FORMAT) >> JS_CTYPE(c)) & 1)
/*
* Per ECMA-262 15.10.2.6, these characters are the only ones that make up a
* "word", as far as a RegExp is concerned. If we want a Unicode-friendlier
* definition of "word", we should rename this macro to something regexp-y.
*/
#define JS_ISWORD(c) ((c) < 128 && (isalnum(c) || (c) == '_'))
#define JS_ISIDSTART(c) (JS_ISLETTER(c) || (c) == '_' || (c) == '$')
#define JS_ISIDENT(c) (JS_ISIDPART(c) || (c) == '_' || (c) == '$')
#define JS_ISXMLSPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\r' || \
(c) == '\n')
#define JS_ISXMLNSSTART(c) ((JS_CCODE(c) & 0x00000100) || (c) == '_')
#define JS_ISXMLNS(c) ((JS_CCODE(c) & 0x00000080) || (c) == '.' || \
(c) == '-' || (c) == '_')
#define JS_ISXMLNAMESTART(c) (JS_ISXMLNSSTART(c) || (c) == ':')
#define JS_ISXMLNAME(c) (JS_ISXMLNS(c) || (c) == ':')
#define JS_ISDIGIT(c) (JS_CTYPE(c) == JSCT_DECIMAL_DIGIT_NUMBER)
/* XXXbe unify on A/X/Y tbls, avoid ctype.h? */
/* XXXbe fs, etc. ? */
#define JS_ISSPACE(c) ((JS_CCODE(c) & 0x00070000) == 0x00040000)
#define JS_ISPRINT(c) ((c) < 128 && isprint(c))
#define JS_ISUPPER(c) (JS_CTYPE(c) == JSCT_UPPERCASE_LETTER)
#define JS_ISLOWER(c) (JS_CTYPE(c) == JSCT_LOWERCASE_LETTER)
#define JS_TOUPPER(c) ((jschar) ((JS_CCODE(c) & 0x00100000) \
? (c) - ((int32)JS_CCODE(c) >> 22) \
: (c)))
#define JS_TOLOWER(c) ((jschar) ((JS_CCODE(c) & 0x00200000) \
? (c) + ((int32)JS_CCODE(c) >> 22) \
: (c)))
/* Shorthands for ASCII (7-bit) decimal and hex conversion. */
#define JS7_ISDEC(c) ((c) < 128 && isdigit(c))
#define JS7_UNDEC(c) ((c) - '0')
#define JS7_ISHEX(c) ((c) < 128 && isxdigit(c))
#define JS7_UNHEX(c) (uintN)(isdigit(c) ? (c) - '0' : 10 + tolower(c) - 'a')
#define JS7_ISLET(c) ((c) < 128 && isalpha(c))
/* Initialize truly global state associated with JS strings. */
extern JSBool
js_InitStringGlobals(void);
extern void
js_FreeStringGlobals(void);
extern void
js_PurgeDeflatedStringCache(JSString *str);
/* Initialize per-runtime string state for the first context in the runtime. */
extern JSBool
js_InitRuntimeStringState(JSContext *cx);
extern void
js_FinishRuntimeStringState(JSContext *cx);
/* Initialize the String class, returning its prototype object. */
extern JSClass js_StringClass;
extern JSObject *
js_InitStringClass(JSContext *cx, JSObject *obj);
extern const char js_escape_str[];
extern const char js_unescape_str[];
extern const char js_uneval_str[];
extern const char js_decodeURI_str[];
extern const char js_encodeURI_str[];
extern const char js_decodeURIComponent_str[];
extern const char js_encodeURIComponent_str[];
/* GC-allocate a string descriptor for the given malloc-allocated chars. */
extern JSString *
js_NewString(JSContext *cx, jschar *chars, size_t length, uintN gcflag);
extern JSString *
js_NewDependentString(JSContext *cx, JSString *base, size_t start,
size_t length, uintN gcflag);
/* Copy a counted string and GC-allocate a descriptor for it. */
extern JSString *
js_NewStringCopyN(JSContext *cx, const jschar *s, size_t n, uintN gcflag);
/* Copy a C string and GC-allocate a descriptor for it. */
extern JSString *
js_NewStringCopyZ(JSContext *cx, const jschar *s, uintN gcflag);
/* Free the chars held by str when it is finalized by the GC. */
extern void
js_FinalizeString(JSContext *cx, JSString *str);
extern void
js_FinalizeStringRT(JSRuntime *rt, JSString *str);
/* Wrap a string value in a String object. */
extern JSObject *
js_StringToObject(JSContext *cx, JSString *str);
/*
* Convert a value to a printable C string.
*/
extern JS_FRIEND_API(const char *)
js_ValueToPrintableString(JSContext *cx, jsval v);
/*
* Convert a value to a string, returning null after reporting an error,
* otherwise returning a new string reference.
*/
extern JSString *
js_ValueToString(JSContext *cx, jsval v);
/*
* Convert a value to its source expression, returning null after reporting
* an error, otherwise returning a new string reference.
*/
extern JSString *
js_ValueToSource(JSContext *cx, jsval v);
#ifdef HT_ENUMERATE_NEXT /* XXX don't require jshash.h */
/*
* Compute a hash function from str.
*/
extern JSHashNumber
js_HashString(JSString *str);
#endif
/*
* Return less than, equal to, or greater than zero depending on whether
* str1 is less than, equal to, or greater than str2.
*/
extern intN
js_CompareStrings(JSString *str1, JSString *str2);
/*
* Boyer-Moore-Horspool superlinear search for pat:patlen in text:textlen.
* The patlen argument must be positive and no greater than BMH_PATLEN_MAX.
* The start argument tells where in text to begin the search.
*
* Return the index of pat in text, or -1 if not found.
*/
#define BMH_CHARSET_SIZE 256 /* ISO-Latin-1 */
#define BMH_PATLEN_MAX 255 /* skip table element is uint8 */
#define BMH_BAD_PATTERN (-2) /* return value if pat is not ISO-Latin-1 */
extern jsint
js_BoyerMooreHorspool(const jschar *text, jsint textlen,
const jschar *pat, jsint patlen,
jsint start);
extern size_t
js_strlen(const jschar *s);
extern jschar *
js_strchr(const jschar *s, jschar c);
extern jschar *
js_strchr_limit(const jschar *s, jschar c, const jschar *limit);
#define js_strncpy(t, s, n) memcpy((t), (s), (n) * sizeof(jschar))
/*
* Return s advanced past any Unicode white space characters.
*/
extern const jschar *
js_SkipWhiteSpace(const jschar *s);
/*
* Inflate bytes to JS chars and vice versa. Report out of memory via cx
* and return null on error, otherwise return the jschar or byte vector that
* was JS_malloc'ed.
*/
extern jschar *
js_InflateString(JSContext *cx, const char *bytes, size_t length);
extern char *
js_DeflateString(JSContext *cx, const jschar *chars, size_t length);
/*
* Inflate bytes to JS chars into a buffer.
* 'chars' must be large enough for 'length'+1 jschars.
*/
extern void
js_InflateStringToBuffer(jschar *chars, const char *bytes, size_t length);
/*
* Associate bytes with str in the deflated string cache, returning true on
* successful association, false on out of memory.
*/
extern JSBool
js_SetStringBytes(JSString *str, char *bytes, size_t length);
/*
* Find or create a deflated string cache entry for str that contains its
* characters chopped from Unicode code points into bytes.
*/
extern char *
js_GetStringBytes(JSString *str);
JSBool
js_str_escape(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval);
JS_END_EXTERN_C
#endif /* jsstr_h___ */

View File

@@ -1,394 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* IBM Corp.
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
** File: jstypes.h
** Description: Definitions of NSPR's basic types
**
** Prototypes and macros used to make up for deficiencies in ANSI environments
** that we have found.
**
** Since we do not wrap <stdlib.h> and all the other standard headers, authors
** of portable code will not know in general that they need these definitions.
** Instead of requiring these authors to find the dependent uses in their code
** and take the following steps only in those C files, we take steps once here
** for all C files.
**/
#ifndef jstypes_h___
#define jstypes_h___
#include <stddef.h>
/***********************************************************************
** MACROS: JS_EXTERN_API
** JS_EXPORT_API
** DESCRIPTION:
** These are only for externally visible routines and globals. For
** internal routines, just use "extern" for type checking and that
** will not export internal cross-file or forward-declared symbols.
** Define a macro for declaring procedures return types. We use this to
** deal with windoze specific type hackery for DLL definitions. Use
** JS_EXTERN_API when the prototype for the method is declared. Use
** JS_EXPORT_API for the implementation of the method.
**
** Example:
** in dowhim.h
** JS_EXTERN_API( void ) DoWhatIMean( void );
** in dowhim.c
** JS_EXPORT_API( void ) DoWhatIMean( void ) { return; }
**
**
***********************************************************************/
#ifdef WIN32
/* These also work for __MWERKS__ */
#define JS_EXTERN_API(__type) extern __declspec(dllexport) __type
#define JS_EXPORT_API(__type) __declspec(dllexport) __type
#define JS_EXTERN_DATA(__type) extern __declspec(dllexport) __type
#define JS_EXPORT_DATA(__type) __declspec(dllexport) __type
#define JS_DLL_CALLBACK
#define JS_STATIC_DLL_CALLBACK(__x) static __x
#elif defined(WIN16)
#ifdef _WINDLL
#define JS_EXTERN_API(__type) extern __type _cdecl _export _loadds
#define JS_EXPORT_API(__type) __type _cdecl _export _loadds
#define JS_EXTERN_DATA(__type) extern __type _export
#define JS_EXPORT_DATA(__type) __type _export
#define JS_DLL_CALLBACK __cdecl __loadds
#define JS_STATIC_DLL_CALLBACK(__x) static __x CALLBACK
#else /* this must be .EXE */
#define JS_EXTERN_API(__type) extern __type _cdecl _export
#define JS_EXPORT_API(__type) __type _cdecl _export
#define JS_EXTERN_DATA(__type) extern __type _export
#define JS_EXPORT_DATA(__type) __type _export
#define JS_DLL_CALLBACK __cdecl __loadds
#define JS_STATIC_DLL_CALLBACK(__x) __x JS_DLL_CALLBACK
#endif /* _WINDLL */
#elif defined(XP_MAC)
#define JS_EXTERN_API(__type) extern __declspec(export) __type
#define JS_EXPORT_API(__type) __declspec(export) __type
#define JS_EXTERN_DATA(__type) extern __declspec(export) __type
#define JS_EXPORT_DATA(__type) __declspec(export) __type
#define JS_DLL_CALLBACK
#define JS_STATIC_DLL_CALLBACK(__x) static __x
#else /* Unix */
#ifdef HAVE_VISIBILITY_PRAGMA
#define JS_EXTERNAL_VIS __attribute__((visibility ("default")))
#else
#define JS_EXTERNAL_VIS
#endif
#define JS_EXTERN_API(__type) extern JS_EXTERNAL_VIS __type
#define JS_EXPORT_API(__type) JS_EXTERNAL_VIS __type
#define JS_EXTERN_DATA(__type) extern JS_EXTERNAL_VIS __type
#define JS_EXPORT_DATA(__type) JS_EXTERNAL_VIS __type
#define JS_DLL_CALLBACK
#define JS_STATIC_DLL_CALLBACK(__x) static __x
#endif
#ifdef _WIN32
# if defined(__MWERKS__) || defined(__GNUC__)
# define JS_IMPORT_API(__x) __x
# else
# define JS_IMPORT_API(__x) __declspec(dllimport) __x
# endif
#else
# define JS_IMPORT_API(__x) JS_EXPORT_API (__x)
#endif
#if defined(_WIN32) && !defined(__MWERKS__)
# define JS_IMPORT_DATA(__x) __declspec(dllimport) __x
#else
# define JS_IMPORT_DATA(__x) JS_EXPORT_DATA (__x)
#endif
/*
* The linkage of JS API functions differs depending on whether the file is
* used within the JS library or not. Any source file within the JS
* interpreter should define EXPORT_JS_API whereas any client of the library
* should not.
*/
#ifdef EXPORT_JS_API
#define JS_PUBLIC_API(t) JS_EXPORT_API(t)
#define JS_PUBLIC_DATA(t) JS_EXPORT_DATA(t)
#else
#define JS_PUBLIC_API(t) JS_IMPORT_API(t)
#define JS_PUBLIC_DATA(t) JS_IMPORT_DATA(t)
#endif
#define JS_FRIEND_API(t) JS_PUBLIC_API(t)
#define JS_FRIEND_DATA(t) JS_PUBLIC_DATA(t)
#ifdef _WIN32
# define JS_INLINE __inline
#elif defined(__GNUC__)
# define JS_INLINE
#else
# define JS_INLINE
#endif
/***********************************************************************
** MACROS: JS_BEGIN_MACRO
** JS_END_MACRO
** DESCRIPTION:
** Macro body brackets so that macros with compound statement definitions
** behave syntactically more like functions when called.
***********************************************************************/
#define JS_BEGIN_MACRO do {
#define JS_END_MACRO } while (0)
/***********************************************************************
** MACROS: JS_BEGIN_EXTERN_C
** JS_END_EXTERN_C
** DESCRIPTION:
** Macro shorthands for conditional C++ extern block delimiters.
***********************************************************************/
#ifdef __cplusplus
#define JS_BEGIN_EXTERN_C extern "C" {
#define JS_END_EXTERN_C }
#else
#define JS_BEGIN_EXTERN_C
#define JS_END_EXTERN_C
#endif
/***********************************************************************
** MACROS: JS_BIT
** JS_BITMASK
** DESCRIPTION:
** Bit masking macros. XXX n must be <= 31 to be portable
***********************************************************************/
#define JS_BIT(n) ((JSUint32)1 << (n))
#define JS_BITMASK(n) (JS_BIT(n) - 1)
/***********************************************************************
** MACROS: JS_HOWMANY
** JS_ROUNDUP
** JS_MIN
** JS_MAX
** DESCRIPTION:
** Commonly used macros for operations on compatible types.
***********************************************************************/
#define JS_HOWMANY(x,y) (((x)+(y)-1)/(y))
#define JS_ROUNDUP(x,y) (JS_HOWMANY(x,y)*(y))
#define JS_MIN(x,y) ((x)<(y)?(x):(y))
#define JS_MAX(x,y) ((x)>(y)?(x):(y))
#if (defined(XP_MAC) || defined(XP_WIN)) && !defined(CROSS_COMPILE)
# include "jscpucfg.h" /* Use standard Mac or Windows configuration */
#elif defined(XP_UNIX) || defined(XP_BEOS) || defined(XP_OS2) || defined(CROSS_COMPILE)
# include "jsautocfg.h" /* Use auto-detected configuration */
# include "jsosdep.h" /* ...and platform-specific flags */
#else
# error "Must define one of XP_BEOS, XP_MAC, XP_OS2, XP_WIN or XP_UNIX"
#endif
JS_BEGIN_EXTERN_C
/************************************************************************
** TYPES: JSUint8
** JSInt8
** DESCRIPTION:
** The int8 types are known to be 8 bits each. There is no type that
** is equivalent to a plain "char".
************************************************************************/
#if JS_BYTES_PER_BYTE == 1
typedef unsigned char JSUint8;
typedef signed char JSInt8;
#else
#error No suitable type for JSInt8/JSUint8
#endif
/************************************************************************
** TYPES: JSUint16
** JSInt16
** DESCRIPTION:
** The int16 types are known to be 16 bits each.
************************************************************************/
#if JS_BYTES_PER_SHORT == 2
typedef unsigned short JSUint16;
typedef short JSInt16;
#else
#error No suitable type for JSInt16/JSUint16
#endif
/************************************************************************
** TYPES: JSUint32
** JSInt32
** DESCRIPTION:
** The int32 types are known to be 32 bits each.
************************************************************************/
#if JS_BYTES_PER_INT == 4
typedef unsigned int JSUint32;
typedef int JSInt32;
#define JS_INT32(x) x
#define JS_UINT32(x) x ## U
#elif JS_BYTES_PER_LONG == 4
typedef unsigned long JSUint32;
typedef long JSInt32;
#define JS_INT32(x) x ## L
#define JS_UINT32(x) x ## UL
#else
#error No suitable type for JSInt32/JSUint32
#endif
/************************************************************************
** TYPES: JSUint64
** JSInt64
** DESCRIPTION:
** The int64 types are known to be 64 bits each. Care must be used when
** declaring variables of type JSUint64 or JSInt64. Different hardware
** architectures and even different compilers have varying support for
** 64 bit values. The only guaranteed portability requires the use of
** the JSLL_ macros (see jslong.h).
************************************************************************/
#ifdef JS_HAVE_LONG_LONG
#if JS_BYTES_PER_LONG == 8
typedef long JSInt64;
typedef unsigned long JSUint64;
#elif defined(WIN16)
typedef __int64 JSInt64;
typedef unsigned __int64 JSUint64;
#elif defined(WIN32) && !defined(__GNUC__)
typedef __int64 JSInt64;
typedef unsigned __int64 JSUint64;
#else
typedef long long JSInt64;
typedef unsigned long long JSUint64;
#endif /* JS_BYTES_PER_LONG == 8 */
#else /* !JS_HAVE_LONG_LONG */
typedef struct {
#ifdef IS_LITTLE_ENDIAN
JSUint32 lo, hi;
#else
JSUint32 hi, lo;
#endif
} JSInt64;
typedef JSInt64 JSUint64;
#endif /* !JS_HAVE_LONG_LONG */
/************************************************************************
** TYPES: JSUintn
** JSIntn
** DESCRIPTION:
** The JSIntn types are most appropriate for automatic variables. They are
** guaranteed to be at least 16 bits, though various architectures may
** define them to be wider (e.g., 32 or even 64 bits). These types are
** never valid for fields of a structure.
************************************************************************/
#if JS_BYTES_PER_INT >= 2
typedef int JSIntn;
typedef unsigned int JSUintn;
#else
#error 'sizeof(int)' not sufficient for platform use
#endif
/************************************************************************
** TYPES: JSFloat64
** DESCRIPTION:
** NSPR's floating point type is always 64 bits.
************************************************************************/
typedef double JSFloat64;
/************************************************************************
** TYPES: JSSize
** DESCRIPTION:
** A type for representing the size of objects.
************************************************************************/
typedef size_t JSSize;
/************************************************************************
** TYPES: JSPtrDiff
** DESCRIPTION:
** A type for pointer difference. Variables of this type are suitable
** for storing a pointer or pointer sutraction.
************************************************************************/
typedef ptrdiff_t JSPtrdiff;
/************************************************************************
** TYPES: JSUptrdiff
** DESCRIPTION:
** A type for pointer difference. Variables of this type are suitable
** for storing a pointer or pointer sutraction.
************************************************************************/
typedef unsigned long JSUptrdiff;
/************************************************************************
** TYPES: JSBool
** DESCRIPTION:
** Use JSBool for variables and parameter types. Use JS_FALSE and JS_TRUE
** for clarity of target type in assignments and actual arguments. Use
** 'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
** just as you would C int-valued conditions.
************************************************************************/
typedef JSIntn JSBool;
#define JS_TRUE (JSIntn)1
#define JS_FALSE (JSIntn)0
/************************************************************************
** TYPES: JSPackedBool
** DESCRIPTION:
** Use JSPackedBool within structs where bitfields are not desireable
** but minimum and consistant overhead matters.
************************************************************************/
typedef JSUint8 JSPackedBool;
/*
** A JSWord is an integer that is the same size as a void*
*/
typedef long JSWord;
typedef unsigned long JSUword;
#include "jsotypes.h"
JS_END_EXTERN_C
#endif /* jstypes_h___ */

View File

@@ -1,284 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* IBM Corp.
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* PR assertion checker.
*/
#include "jsstddef.h"
#include <stdio.h>
#include <stdlib.h>
#include "jstypes.h"
#include "jsutil.h"
#ifdef WIN32
# include <windows.h>
#endif
#ifdef XP_MAC
# include <Types.h>
# include <stdarg.h>
# include "jsprf.h"
#endif
#ifdef XP_MAC
/*
* PStrFromCStr converts the source C string to a destination
* pascal string as it copies. The dest string will
* be truncated to fit into an Str255 if necessary.
* If the C String pointer is NULL, the pascal string's length is
* set to zero.
*/
static void PStrFromCStr(const char *src, Str255 dst)
{
short length = 0;
/* handle case of overlapping strings */
if ( (void*)src == (void*)dst )
{
unsigned char *curdst = &dst[1];
unsigned char thisChar;
thisChar = *(const unsigned char*)src++;
while ( thisChar != '\0' )
{
unsigned char nextChar;
/*
* Use nextChar so we don't overwrite what we
* are about to read
*/
nextChar = *(const unsigned char*)src++;
*curdst++ = thisChar;
thisChar = nextChar;
if ( ++length >= 255 )
break;
}
}
else if ( src != NULL )
{
unsigned char *curdst = &dst[1];
/* count down so test it loop is faster */
short overflow = 255;
register char temp;
/*
* Can't do the K&R C thing of while (*s++ = *t++)
* because it will copy trailing zero which might
* overrun pascal buffer. Instead we use a temp variable.
*/
while ( (temp = *src++) != 0 )
{
*(char*)curdst++ = temp;
if ( --overflow <= 0 )
break;
}
length = 255 - overflow;
}
dst[0] = length;
}
static void jsdebugstr(const char *debuggerMsg)
{
Str255 pStr;
PStrFromCStr(debuggerMsg, pStr);
DebugStr(pStr);
}
static void dprintf(const char *format, ...)
{
va_list ap;
char *buffer;
va_start(ap, format);
buffer = (char *)JS_vsmprintf(format, ap);
va_end(ap);
jsdebugstr(buffer);
JS_smprintf_free(buffer);
}
#endif /* XP_MAC */
JS_PUBLIC_API(void) JS_Assert(const char *s, const char *file, JSIntn ln)
{
#ifdef XP_MAC
dprintf("Assertion failure: %s, at %s:%d\n", s, file, ln);
#else
fprintf(stderr, "Assertion failure: %s, at %s:%d\n", s, file, ln);
#endif
#if defined(WIN32)
DebugBreak();
#endif
#if defined(XP_OS2)
asm("int $3");
#endif
#ifndef XP_MAC
abort();
#endif
}
#if defined DEBUG_notme && defined XP_UNIX
#define __USE_GNU 1
#include <dlfcn.h>
#include <setjmp.h>
#include <string.h>
#include "jshash.h"
#include "jsprf.h"
JSCallsite js_calltree_root = {0, NULL, NULL, 0, NULL, NULL, NULL, NULL};
static JSCallsite *
CallTree(uint32 *bp)
{
uint32 *bpup, *bpdown, pc;
JSCallsite *parent, *site, **csp;
Dl_info info;
int ok, offset;
const char *symbol;
char *method;
/* Reverse the stack frame list to avoid recursion. */
bpup = NULL;
for (;;) {
bpdown = (uint32*) bp[0];
bp[0] = (uint32) bpup;
if ((uint32*) bpdown[0] < bpdown)
break;
bpup = bp;
bp = bpdown;
}
/* Reverse the stack again, finding and building a path in the tree. */
parent = &js_calltree_root;
do {
bpup = (uint32*) bp[0];
bp[0] = (uint32) bpdown;
pc = bp[1];
csp = &parent->kids;
while ((site = *csp) != NULL) {
if (site->pc == pc) {
/* Put the most recently used site at the front of siblings. */
*csp = site->siblings;
site->siblings = parent->kids;
parent->kids = site;
/* Site already built -- go up the stack. */
goto upward;
}
csp = &site->siblings;
}
/* Check for recursion: see if pc is on our ancestor line. */
for (site = parent; site; site = site->parent) {
if (site->pc == pc)
goto upward;
}
/*
* Not in tree at all: let's find our symbolic callsite info.
* XXX static syms are masked by nearest lower global
*/
info.dli_fname = info.dli_sname = NULL;
ok = dladdr((void*) pc, &info);
if (ok < 0) {
fprintf(stderr, "dladdr failed!\n");
return NULL;
}
/* XXXbe sub 0x08040000? or something, see dbaron bug with tenthumbs comment */
symbol = info.dli_sname;
offset = (char*)pc - (char*)info.dli_fbase;
method = symbol
? strdup(symbol)
: JS_smprintf("%s+%X",
info.dli_fname ? info.dli_fname : "main",
offset);
if (!method)
return NULL;
/* Create a new callsite record. */
site = (JSCallsite *) malloc(sizeof(JSCallsite));
if (!site)
return NULL;
/* Insert the new site into the tree. */
site->pc = pc;
site->name = method;
site->library = info.dli_fname;
site->offset = offset;
site->parent = parent;
site->siblings = parent->kids;
parent->kids = site;
site->kids = NULL;
upward:
parent = site;
bpdown = bp;
bp = bpup;
} while (bp);
return site;
}
JSCallsite *
JS_Backtrace(int skip)
{
jmp_buf jb;
uint32 *bp, *bpdown;
setjmp(jb);
/* Stack walking code adapted from Kipp's "leaky". */
bp = (uint32*) jb[0].__jmpbuf[JB_BP];
while (--skip >= 0) {
bpdown = (uint32*) *bp++;
if (bpdown < bp)
break;
bp = bpdown;
}
return CallTree(bp);
}
#endif /* DEBUG_notme && XP_UNIX */

View File

@@ -1,94 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* PR assertion checker.
*/
#ifndef jsutil_h___
#define jsutil_h___
JS_BEGIN_EXTERN_C
#ifdef DEBUG
extern JS_PUBLIC_API(void)
JS_Assert(const char *s, const char *file, JSIntn ln);
#define JS_ASSERT(_expr) \
((_expr)?((void)0):JS_Assert(# _expr,__FILE__,__LINE__))
#define JS_NOT_REACHED(_reasonStr) \
JS_Assert(_reasonStr,__FILE__,__LINE__)
#else
#define JS_ASSERT(expr) ((void) 0)
#define JS_NOT_REACHED(reasonStr)
#endif /* defined(DEBUG) */
/*
** Abort the process in a non-graceful manner. This will cause a core file,
** call to the debugger or other moral equivalent as well as causing the
** entire process to stop.
*/
extern JS_PUBLIC_API(void) JS_Abort(void);
#ifdef XP_UNIX
typedef struct JSCallsite JSCallsite;
struct JSCallsite {
uint32 pc;
char *name;
const char *library;
int offset;
JSCallsite *parent;
JSCallsite *siblings;
JSCallsite *kids;
void *handy;
};
extern JSCallsite *JS_Backtrace(int skip);
#endif
JS_END_EXTERN_C
#endif /* jsutil_h___ */

View File

@@ -1,686 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "jsstddef.h"
#include "jsconfig.h"
#if JS_HAS_XDR
#include <string.h>
#include "jstypes.h"
#include "jsutil.h" /* Added by JSIFY */
#include "jsdhash.h"
#include "jsprf.h"
#include "jsapi.h"
#include "jscntxt.h"
#include "jsnum.h"
#include "jsobj.h" /* js_XDRObject */
#include "jsscript.h" /* js_XDRScript */
#include "jsstr.h"
#include "jsxdrapi.h"
#ifdef DEBUG
#define DBG(x) x
#else
#define DBG(x) ((void)0)
#endif
typedef struct JSXDRMemState {
JSXDRState state;
char *base;
uint32 count;
uint32 limit;
} JSXDRMemState;
#define MEM_BLOCK 8192
#define MEM_PRIV(xdr) ((JSXDRMemState *)(xdr))
#define MEM_BASE(xdr) (MEM_PRIV(xdr)->base)
#define MEM_COUNT(xdr) (MEM_PRIV(xdr)->count)
#define MEM_LIMIT(xdr) (MEM_PRIV(xdr)->limit)
#define MEM_LEFT(xdr, bytes) \
JS_BEGIN_MACRO \
if ((xdr)->mode == JSXDR_DECODE && \
MEM_COUNT(xdr) + bytes > MEM_LIMIT(xdr)) { \
JS_ReportErrorNumber((xdr)->cx, js_GetErrorMessage, NULL, \
JSMSG_END_OF_DATA); \
return 0; \
} \
JS_END_MACRO
#define MEM_NEED(xdr, bytes) \
JS_BEGIN_MACRO \
if ((xdr)->mode == JSXDR_ENCODE) { \
if (MEM_LIMIT(xdr) && \
MEM_COUNT(xdr) + bytes > MEM_LIMIT(xdr)) { \
uint32 limit_ = JS_ROUNDUP(MEM_COUNT(xdr) + bytes, MEM_BLOCK);\
void *data_ = JS_realloc((xdr)->cx, MEM_BASE(xdr), limit_); \
if (!data_) \
return 0; \
MEM_BASE(xdr) = data_; \
MEM_LIMIT(xdr) = limit_; \
} \
} else { \
MEM_LEFT(xdr, bytes); \
} \
JS_END_MACRO
#define MEM_DATA(xdr) ((void *)(MEM_BASE(xdr) + MEM_COUNT(xdr)))
#define MEM_INCR(xdr,bytes) (MEM_COUNT(xdr) += (bytes))
static JSBool
mem_get32(JSXDRState *xdr, uint32 *lp)
{
MEM_LEFT(xdr, 4);
*lp = *(uint32 *)MEM_DATA(xdr);
MEM_INCR(xdr, 4);
return JS_TRUE;
}
static JSBool
mem_set32(JSXDRState *xdr, uint32 *lp)
{
MEM_NEED(xdr, 4);
*(uint32 *)MEM_DATA(xdr) = *lp;
MEM_INCR(xdr, 4);
return JS_TRUE;
}
static JSBool
mem_getbytes(JSXDRState *xdr, char *bytes, uint32 len)
{
MEM_LEFT(xdr, len);
memcpy(bytes, MEM_DATA(xdr), len);
MEM_INCR(xdr, len);
return JS_TRUE;
}
static JSBool
mem_setbytes(JSXDRState *xdr, char *bytes, uint32 len)
{
MEM_NEED(xdr, len);
memcpy(MEM_DATA(xdr), bytes, len);
MEM_INCR(xdr, len);
return JS_TRUE;
}
static void *
mem_raw(JSXDRState *xdr, uint32 len)
{
void *data;
if (xdr->mode == JSXDR_ENCODE) {
MEM_NEED(xdr, len);
} else if (xdr->mode == JSXDR_DECODE) {
MEM_LEFT(xdr, len);
}
data = MEM_DATA(xdr);
MEM_INCR(xdr, len);
return data;
}
static JSBool
mem_seek(JSXDRState *xdr, int32 offset, JSXDRWhence whence)
{
switch (whence) {
case JSXDR_SEEK_CUR:
if ((int32)MEM_COUNT(xdr) + offset < 0) {
JS_ReportErrorNumber(xdr->cx, js_GetErrorMessage, NULL,
JSMSG_SEEK_BEYOND_START);
return JS_FALSE;
}
if (offset > 0)
MEM_NEED(xdr, offset);
MEM_COUNT(xdr) += offset;
return JS_TRUE;
case JSXDR_SEEK_SET:
if (offset < 0) {
JS_ReportErrorNumber(xdr->cx, js_GetErrorMessage, NULL,
JSMSG_SEEK_BEYOND_START);
return JS_FALSE;
}
if (xdr->mode == JSXDR_ENCODE) {
if ((uint32)offset > MEM_COUNT(xdr))
MEM_NEED(xdr, offset - MEM_COUNT(xdr));
MEM_COUNT(xdr) = offset;
} else {
if ((uint32)offset > MEM_LIMIT(xdr)) {
JS_ReportErrorNumber(xdr->cx, js_GetErrorMessage, NULL,
JSMSG_SEEK_BEYOND_END);
return JS_FALSE;
}
MEM_COUNT(xdr) = offset;
}
return JS_TRUE;
case JSXDR_SEEK_END:
if (offset >= 0 ||
xdr->mode == JSXDR_ENCODE ||
(int32)MEM_LIMIT(xdr) + offset < 0) {
JS_ReportErrorNumber(xdr->cx, js_GetErrorMessage, NULL,
JSMSG_END_SEEK);
return JS_FALSE;
}
MEM_COUNT(xdr) = MEM_LIMIT(xdr) + offset;
return JS_TRUE;
default: {
char numBuf[12];
JS_snprintf(numBuf, sizeof numBuf, "%d", whence);
JS_ReportErrorNumber(xdr->cx, js_GetErrorMessage, NULL,
JSMSG_WHITHER_WHENCE, numBuf);
return JS_FALSE;
}
}
}
static uint32
mem_tell(JSXDRState *xdr)
{
return MEM_COUNT(xdr);
}
static void
mem_finalize(JSXDRState *xdr)
{
JS_free(xdr->cx, MEM_BASE(xdr));
}
static JSXDROps xdrmem_ops = {
mem_get32, mem_set32, mem_getbytes, mem_setbytes,
mem_raw, mem_seek, mem_tell, mem_finalize
};
JS_PUBLIC_API(void)
JS_XDRInitBase(JSXDRState *xdr, JSXDRMode mode, JSContext *cx)
{
xdr->mode = mode;
xdr->cx = cx;
xdr->registry = NULL;
xdr->numclasses = xdr->maxclasses = 0;
xdr->reghash = NULL;
xdr->userdata = NULL;
}
JS_PUBLIC_API(JSXDRState *)
JS_XDRNewMem(JSContext *cx, JSXDRMode mode)
{
JSXDRState *xdr = (JSXDRState *) JS_malloc(cx, sizeof(JSXDRMemState));
if (!xdr)
return NULL;
JS_XDRInitBase(xdr, mode, cx);
if (mode == JSXDR_ENCODE) {
if (!(MEM_BASE(xdr) = JS_malloc(cx, MEM_BLOCK))) {
JS_free(cx, xdr);
return NULL;
}
} else {
/* XXXbe ok, so better not deref MEM_BASE(xdr) if not ENCODE */
MEM_BASE(xdr) = NULL;
}
xdr->ops = &xdrmem_ops;
MEM_COUNT(xdr) = 0;
MEM_LIMIT(xdr) = MEM_BLOCK;
return xdr;
}
JS_PUBLIC_API(void *)
JS_XDRMemGetData(JSXDRState *xdr, uint32 *lp)
{
if (xdr->ops != &xdrmem_ops)
return NULL;
*lp = MEM_COUNT(xdr);
return MEM_BASE(xdr);
}
JS_PUBLIC_API(void)
JS_XDRMemSetData(JSXDRState *xdr, void *data, uint32 len)
{
if (xdr->ops != &xdrmem_ops)
return;
MEM_LIMIT(xdr) = len;
MEM_BASE(xdr) = data;
MEM_COUNT(xdr) = 0;
}
JS_PUBLIC_API(uint32)
JS_XDRMemDataLeft(JSXDRState *xdr)
{
if (xdr->ops != &xdrmem_ops)
return 0;
return MEM_LIMIT(xdr) - MEM_COUNT(xdr);
}
JS_PUBLIC_API(void)
JS_XDRMemResetData(JSXDRState *xdr)
{
if (xdr->ops != &xdrmem_ops)
return;
MEM_COUNT(xdr) = 0;
}
JS_PUBLIC_API(void)
JS_XDRDestroy(JSXDRState *xdr)
{
JSContext *cx = xdr->cx;
xdr->ops->finalize(xdr);
if (xdr->registry) {
JS_free(cx, xdr->registry);
if (xdr->reghash)
JS_DHashTableDestroy(xdr->reghash);
}
JS_free(cx, xdr);
}
JS_PUBLIC_API(JSBool)
JS_XDRUint8(JSXDRState *xdr, uint8 *b)
{
uint32 l = *b;
if (!JS_XDRUint32(xdr, &l))
return JS_FALSE;
*b = (uint8) l;
return JS_TRUE;
}
JS_PUBLIC_API(JSBool)
JS_XDRUint16(JSXDRState *xdr, uint16 *s)
{
uint32 l = *s;
if (!JS_XDRUint32(xdr, &l))
return JS_FALSE;
*s = (uint16) l;
return JS_TRUE;
}
JS_PUBLIC_API(JSBool)
JS_XDRUint32(JSXDRState *xdr, uint32 *lp)
{
JSBool ok = JS_TRUE;
if (xdr->mode == JSXDR_ENCODE) {
uint32 xl = JSXDR_SWAB32(*lp);
ok = xdr->ops->set32(xdr, &xl);
} else if (xdr->mode == JSXDR_DECODE) {
ok = xdr->ops->get32(xdr, lp);
*lp = JSXDR_SWAB32(*lp);
}
return ok;
}
JS_PUBLIC_API(JSBool)
JS_XDRBytes(JSXDRState *xdr, char *bytes, uint32 len)
{
uint32 padlen;
static char padbuf[JSXDR_ALIGN-1];
if (xdr->mode == JSXDR_ENCODE) {
if (!xdr->ops->setbytes(xdr, bytes, len))
return JS_FALSE;
} else {
if (!xdr->ops->getbytes(xdr, bytes, len))
return JS_FALSE;
}
len = xdr->ops->tell(xdr);
if (len % JSXDR_ALIGN) {
padlen = JSXDR_ALIGN - (len % JSXDR_ALIGN);
if (xdr->mode == JSXDR_ENCODE) {
if (!xdr->ops->setbytes(xdr, padbuf, padlen))
return JS_FALSE;
} else {
if (!xdr->ops->seek(xdr, padlen, JSXDR_SEEK_CUR))
return JS_FALSE;
}
}
return JS_TRUE;
}
/**
* Convert between a C string and the XDR representation:
* leading 32-bit count, then counted vector of chars,
* then possibly \0 padding to multiple of 4.
*/
JS_PUBLIC_API(JSBool)
JS_XDRCString(JSXDRState *xdr, char **sp)
{
uint32 len;
if (xdr->mode == JSXDR_ENCODE)
len = strlen(*sp);
JS_XDRUint32(xdr, &len);
if (xdr->mode == JSXDR_DECODE) {
if (!(*sp = (char *) JS_malloc(xdr->cx, len + 1)))
return JS_FALSE;
}
if (!JS_XDRBytes(xdr, *sp, len)) {
if (xdr->mode == JSXDR_DECODE)
JS_free(xdr->cx, *sp);
return JS_FALSE;
}
if (xdr->mode == JSXDR_DECODE) {
(*sp)[len] = '\0';
} else if (xdr->mode == JSXDR_FREE) {
JS_free(xdr->cx, *sp);
*sp = NULL;
}
return JS_TRUE;
}
JS_PUBLIC_API(JSBool)
JS_XDRCStringOrNull(JSXDRState *xdr, char **sp)
{
uint32 null = (*sp == NULL);
if (!JS_XDRUint32(xdr, &null))
return JS_FALSE;
if (null) {
*sp = NULL;
return JS_TRUE;
}
return JS_XDRCString(xdr, sp);
}
/*
* Convert between a JS (Unicode) string and the XDR representation.
*/
JS_PUBLIC_API(JSBool)
JS_XDRString(JSXDRState *xdr, JSString **strp)
{
uint32 i, len, padlen, nbytes;
jschar *chars = NULL, *raw;
if (xdr->mode == JSXDR_ENCODE)
len = JSSTRING_LENGTH(*strp);
if (!JS_XDRUint32(xdr, &len))
return JS_FALSE;
nbytes = len * sizeof(jschar);
if (xdr->mode == JSXDR_DECODE) {
if (!(chars = (jschar *) JS_malloc(xdr->cx, nbytes + sizeof(jschar))))
return JS_FALSE;
} else {
chars = JSSTRING_CHARS(*strp);
}
padlen = nbytes % JSXDR_ALIGN;
if (padlen) {
padlen = JSXDR_ALIGN - padlen;
nbytes += padlen;
}
if (!(raw = (jschar *) xdr->ops->raw(xdr, nbytes)))
goto bad;
if (xdr->mode == JSXDR_ENCODE) {
for (i = 0; i < len; i++)
raw[i] = JSXDR_SWAB16(chars[i]);
if (padlen)
memset((char *)raw + nbytes - padlen, 0, padlen);
} else if (xdr->mode == JSXDR_DECODE) {
for (i = 0; i < len; i++)
chars[i] = JSXDR_SWAB16(raw[i]);
chars[len] = 0;
if (!(*strp = JS_NewUCString(xdr->cx, chars, len)))
goto bad;
}
return JS_TRUE;
bad:
if (xdr->mode == JSXDR_DECODE)
JS_free(xdr->cx, chars);
return JS_FALSE;
}
JS_PUBLIC_API(JSBool)
JS_XDRStringOrNull(JSXDRState *xdr, JSString **strp)
{
uint32 null = (*strp == NULL);
if (!JS_XDRUint32(xdr, &null))
return JS_FALSE;
if (null) {
*strp = NULL;
return JS_TRUE;
}
return JS_XDRString(xdr, strp);
}
JS_PUBLIC_API(JSBool)
JS_XDRDouble(JSXDRState *xdr, jsdouble **dp)
{
jsdpun u;
if (xdr->mode == JSXDR_ENCODE)
u.d = **dp;
if (!JS_XDRUint32(xdr, &u.s.lo) || !JS_XDRUint32(xdr, &u.s.hi))
return JS_FALSE;
if (xdr->mode == JSXDR_DECODE) {
*dp = JS_NewDouble(xdr->cx, u.d);
if (!*dp)
return JS_FALSE;
}
return JS_TRUE;
}
/* These are magic pseudo-tags: see jsapi.h, near the top, for real tags. */
#define JSVAL_XDRNULL 0x8
#define JSVAL_XDRVOID 0xA
JS_PUBLIC_API(JSBool)
JS_XDRValue(JSXDRState *xdr, jsval *vp)
{
uint32 type;
if (xdr->mode == JSXDR_ENCODE) {
if (JSVAL_IS_NULL(*vp))
type = JSVAL_XDRNULL;
else if (JSVAL_IS_VOID(*vp))
type = JSVAL_XDRVOID;
else
type = JSVAL_TAG(*vp);
}
if (!JS_XDRUint32(xdr, &type))
return JS_FALSE;
switch (type) {
case JSVAL_XDRNULL:
*vp = JSVAL_NULL;
break;
case JSVAL_XDRVOID:
*vp = JSVAL_VOID;
break;
case JSVAL_STRING: {
JSString *str;
if (xdr->mode == JSXDR_ENCODE)
str = JSVAL_TO_STRING(*vp);
if (!JS_XDRString(xdr, &str))
return JS_FALSE;
if (xdr->mode == JSXDR_DECODE)
*vp = STRING_TO_JSVAL(str);
break;
}
case JSVAL_DOUBLE: {
jsdouble *dp;
if (xdr->mode == JSXDR_ENCODE)
dp = JSVAL_TO_DOUBLE(*vp);
if (!JS_XDRDouble(xdr, &dp))
return JS_FALSE;
if (xdr->mode == JSXDR_DECODE)
*vp = DOUBLE_TO_JSVAL(dp);
break;
}
case JSVAL_OBJECT: {
JSObject *obj;
if (xdr->mode == JSXDR_ENCODE)
obj = JSVAL_TO_OBJECT(*vp);
if (!js_XDRObject(xdr, &obj))
return JS_FALSE;
if (xdr->mode == JSXDR_DECODE)
*vp = OBJECT_TO_JSVAL(obj);
break;
}
case JSVAL_BOOLEAN: {
uint32 b;
if (xdr->mode == JSXDR_ENCODE)
b = (uint32) JSVAL_TO_BOOLEAN(*vp);
if (!JS_XDRUint32(xdr, &b))
return JS_FALSE;
if (xdr->mode == JSXDR_DECODE)
*vp = BOOLEAN_TO_JSVAL((JSBool) b);
break;
}
default: {
uint32 i;
JS_ASSERT(type & JSVAL_INT);
if (xdr->mode == JSXDR_ENCODE)
i = (uint32) JSVAL_TO_INT(*vp);
if (!JS_XDRUint32(xdr, &i))
return JS_FALSE;
if (xdr->mode == JSXDR_DECODE)
*vp = INT_TO_JSVAL((int32) i);
break;
}
}
return JS_TRUE;
}
JS_PUBLIC_API(JSBool)
JS_XDRScript(JSXDRState *xdr, JSScript **scriptp)
{
if (!js_XDRScript(xdr, scriptp, NULL))
return JS_FALSE;
if (xdr->mode == JSXDR_DECODE)
js_CallNewScriptHook(xdr->cx, *scriptp, NULL);
return JS_TRUE;
}
#define CLASS_REGISTRY_MIN 8
#define CLASS_INDEX_TO_ID(i) ((i)+1)
#define CLASS_ID_TO_INDEX(id) ((id)-1)
typedef struct JSRegHashEntry {
JSDHashEntryHdr hdr;
const char *name;
uint32 index;
} JSRegHashEntry;
JS_PUBLIC_API(JSBool)
JS_XDRRegisterClass(JSXDRState *xdr, JSClass *clasp, uint32 *idp)
{
uintN numclasses, maxclasses;
JSClass **registry;
numclasses = xdr->numclasses;
maxclasses = xdr->maxclasses;
if (numclasses == maxclasses) {
maxclasses = (maxclasses == 0) ? CLASS_REGISTRY_MIN : maxclasses << 1;
registry = (JSClass **)
JS_realloc(xdr->cx, xdr->registry, maxclasses * sizeof(JSClass *));
if (!registry)
return JS_FALSE;
xdr->registry = registry;
xdr->maxclasses = maxclasses;
} else {
JS_ASSERT(numclasses && numclasses < maxclasses);
registry = xdr->registry;
}
registry[numclasses] = clasp;
if (xdr->reghash) {
JSRegHashEntry *entry = (JSRegHashEntry *)
JS_DHashTableOperate(xdr->reghash, clasp->name, JS_DHASH_ADD);
if (!entry) {
JS_ReportOutOfMemory(xdr->cx);
return JS_FALSE;
}
entry->name = clasp->name;
entry->index = numclasses;
}
*idp = CLASS_INDEX_TO_ID(numclasses);
xdr->numclasses = ++numclasses;
return JS_TRUE;
}
JS_PUBLIC_API(uint32)
JS_XDRFindClassIdByName(JSXDRState *xdr, const char *name)
{
uintN i, numclasses;
numclasses = xdr->numclasses;
if (numclasses >= 10) {
JSRegHashEntry *entry;
/* Bootstrap reghash from registry on first overpopulated Find. */
if (!xdr->reghash) {
xdr->reghash = JS_NewDHashTable(JS_DHashGetStubOps(), NULL,
sizeof(JSRegHashEntry),
numclasses);
if (xdr->reghash) {
for (i = 0; i < numclasses; i++) {
JSClass *clasp = xdr->registry[i];
entry = (JSRegHashEntry *)
JS_DHashTableOperate(xdr->reghash, clasp->name,
JS_DHASH_ADD);
entry->name = clasp->name;
entry->index = i;
}
}
}
/* If we managed to create reghash, use it for O(1) Find. */
if (xdr->reghash) {
entry = (JSRegHashEntry *)
JS_DHashTableOperate(xdr->reghash, name, JS_DHASH_LOOKUP);
if (JS_DHASH_ENTRY_IS_BUSY(&entry->hdr))
return CLASS_INDEX_TO_ID(entry->index);
}
}
/* Only a few classes, or we couldn't malloc reghash: use linear search. */
for (i = 0; i < numclasses; i++) {
if (!strcmp(name, xdr->registry[i]->name))
return CLASS_INDEX_TO_ID(i);
}
return 0;
}
JS_PUBLIC_API(JSClass *)
JS_XDRFindClassById(JSXDRState *xdr, uint32 id)
{
uintN i = CLASS_ID_TO_INDEX(id);
if (i >= xdr->numclasses)
return NULL;
return xdr->registry[i];
}
#endif /* JS_HAS_XDR */

View File

@@ -1,193 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsxdrapi_h___
#define jsxdrapi_h___
/*
* JS external data representation interface API.
*
* The XDR system is comprised of three major parts:
*
* - the state serialization/deserialization APIs, which allow consumers
* of the API to serialize JS runtime state (script bytecodes, atom maps,
* object graphs, etc.) for later restoration. These portions
* are implemented in various appropriate files, such as jsscript.c
* for the script portions and jsobj.c for object state.
* - the callback APIs through which the runtime requests an opaque
* representation of a native object, and through which the runtime
* constructs a live native object from an opaque representation. These
* portions are the responsibility of the native object implementor.
* - utility functions for en/decoding of primitive types, such as
* JSStrings. This portion is implemented in jsxdrapi.c.
*
* Spiritually guided by Sun's XDR, where appropriate.
*/
#include "jspubtd.h"
#include "jsprvtd.h"
JS_BEGIN_EXTERN_C
/* We use little-endian byteorder for all encoded data */
#if defined IS_LITTLE_ENDIAN
#define JSXDR_SWAB32(x) x
#define JSXDR_SWAB16(x) x
#elif defined IS_BIG_ENDIAN
#define JSXDR_SWAB32(x) (((uint32)(x) >> 24) | \
(((uint32)(x) >> 8) & 0xff00) | \
(((uint32)(x) << 8) & 0xff0000) | \
((uint32)(x) << 24))
#define JSXDR_SWAB16(x) (((uint16)(x) >> 8) | ((uint16)(x) << 8))
#else
#error "unknown byte order"
#endif
#define JSXDR_ALIGN 4
typedef enum JSXDRMode {
JSXDR_ENCODE,
JSXDR_DECODE,
JSXDR_FREE
} JSXDRMode;
typedef enum JSXDRWhence {
JSXDR_SEEK_SET,
JSXDR_SEEK_CUR,
JSXDR_SEEK_END
} JSXDRWhence;
typedef struct JSXDROps {
JSBool (*get32)(JSXDRState *, uint32 *);
JSBool (*set32)(JSXDRState *, uint32 *);
JSBool (*getbytes)(JSXDRState *, char *, uint32);
JSBool (*setbytes)(JSXDRState *, char *, uint32);
void * (*raw)(JSXDRState *, uint32);
JSBool (*seek)(JSXDRState *, int32, JSXDRWhence);
uint32 (*tell)(JSXDRState *);
void (*finalize)(JSXDRState *);
} JSXDROps;
struct JSXDRState {
JSXDRMode mode;
JSXDROps *ops;
JSContext *cx;
JSClass **registry;
uintN numclasses;
uintN maxclasses;
void *reghash;
void *userdata;
};
extern JS_PUBLIC_API(void)
JS_XDRInitBase(JSXDRState *xdr, JSXDRMode mode, JSContext *cx);
extern JS_PUBLIC_API(JSXDRState *)
JS_XDRNewMem(JSContext *cx, JSXDRMode mode);
extern JS_PUBLIC_API(void *)
JS_XDRMemGetData(JSXDRState *xdr, uint32 *lp);
extern JS_PUBLIC_API(void)
JS_XDRMemSetData(JSXDRState *xdr, void *data, uint32 len);
extern JS_PUBLIC_API(uint32)
JS_XDRMemDataLeft(JSXDRState *xdr);
extern JS_PUBLIC_API(void)
JS_XDRMemResetData(JSXDRState *xdr);
extern JS_PUBLIC_API(void)
JS_XDRDestroy(JSXDRState *xdr);
extern JS_PUBLIC_API(JSBool)
JS_XDRUint8(JSXDRState *xdr, uint8 *b);
extern JS_PUBLIC_API(JSBool)
JS_XDRUint16(JSXDRState *xdr, uint16 *s);
extern JS_PUBLIC_API(JSBool)
JS_XDRUint32(JSXDRState *xdr, uint32 *lp);
extern JS_PUBLIC_API(JSBool)
JS_XDRBytes(JSXDRState *xdr, char *bytes, uint32 len);
extern JS_PUBLIC_API(JSBool)
JS_XDRCString(JSXDRState *xdr, char **sp);
extern JS_PUBLIC_API(JSBool)
JS_XDRCStringOrNull(JSXDRState *xdr, char **sp);
extern JS_PUBLIC_API(JSBool)
JS_XDRString(JSXDRState *xdr, JSString **strp);
extern JS_PUBLIC_API(JSBool)
JS_XDRStringOrNull(JSXDRState *xdr, JSString **strp);
extern JS_PUBLIC_API(JSBool)
JS_XDRDouble(JSXDRState *xdr, jsdouble **dp);
extern JS_PUBLIC_API(JSBool)
JS_XDRValue(JSXDRState *xdr, jsval *vp);
extern JS_PUBLIC_API(JSBool)
JS_XDRScript(JSXDRState *xdr, JSScript **scriptp);
extern JS_PUBLIC_API(JSBool)
JS_XDRRegisterClass(JSXDRState *xdr, JSClass *clasp, uint32 *lp);
extern JS_PUBLIC_API(uint32)
JS_XDRFindClassIdByName(JSXDRState *xdr, const char *name);
extern JS_PUBLIC_API(JSClass *)
JS_XDRFindClassById(JSXDRState *xdr, uint32 id);
/*
* Magic numbers.
*/
#define JSXDR_MAGIC_SCRIPT_1 0xdead0001
#define JSXDR_MAGIC_SCRIPT_2 0xdead0002
#define JSXDR_MAGIC_SCRIPT_3 0xdead0003
#define JSXDR_MAGIC_SCRIPT_4 0xdead0004
#define JSXDR_MAGIC_SCRIPT_CURRENT JSXDR_MAGIC_SCRIPT_4
JS_END_EXTERN_C
#endif /* ! jsxdrapi_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,312 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is SpiderMonkey E4X code, released August, 2004.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef jsxml_h___
#define jsxml_h___
#include "jsstddef.h"
#include "jspubtd.h"
extern const char js_AnyName_str[];
extern const char js_AttributeName_str[];
extern const char js_isXMLName_str[];
extern const char js_Namespace_str[];
extern const char js_QName_str[];
extern const char js_XML_str[];
extern const char js_XMLList_str[];
extern const char js_amp_entity_str[];
extern const char js_gt_entity_str[];
extern const char js_lt_entity_str[];
extern const char js_quot_entity_str[];
struct JSXMLNamespace {
JSObject *object;
JSString *prefix;
JSString *uri;
JSBool declared; /* true if declared in its XML tag */
};
extern JSXMLNamespace *
js_NewXMLNamespace(JSContext *cx, JSString *prefix, JSString *uri,
JSBool declared);
extern void
js_MarkXMLNamespace(JSContext *cx, JSXMLNamespace *ns, void *arg);
extern void
js_FinalizeXMLNamespace(JSContext *cx, JSXMLNamespace *ns);
extern JSObject *
js_NewXMLNamespaceObject(JSContext *cx, JSString *prefix, JSString *uri,
JSBool declared);
extern JSObject *
js_GetXMLNamespaceObject(JSContext *cx, JSXMLNamespace *ns);
struct JSXMLQName {
JSObject *object;
JSString *uri;
JSString *prefix;
JSString *localName;
};
extern JSXMLQName *
js_NewXMLQName(JSContext *cx, JSString *uri, JSString *prefix,
JSString *localName);
extern void
js_MarkXMLQName(JSContext *cx, JSXMLQName *qn, void *arg);
extern void
js_FinalizeXMLQName(JSContext *cx, JSXMLQName *qn);
extern JSObject *
js_NewXMLQNameObject(JSContext *cx, JSString *uri, JSString *prefix,
JSString *localName);
extern JSObject *
js_GetXMLQNameObject(JSContext *cx, JSXMLQName *qn);
extern JSObject *
js_GetAttributeNameObject(JSContext *cx, JSXMLQName *qn);
extern JSObject *
js_ConstructXMLQNameObject(JSContext *cx, jsval nsval, jsval lnval);
typedef JSBool
(* JS_DLL_CALLBACK JSIdentityOp)(const void *a, const void *b);
struct JSXMLArray {
uint32 length;
uint32 capacity;
void **vector;
JSXMLArrayCursor *cursors;
};
struct JSXMLArrayCursor {
JSXMLArray *array;
uint32 index;
JSXMLArrayCursor *next;
JSXMLArrayCursor **prevp;
};
/*
* NB: don't reorder this enum without changing all array initializers that
* depend on it in jsxml.c.
*/
typedef enum JSXMLClass {
JSXML_CLASS_LIST,
JSXML_CLASS_ELEMENT,
JSXML_CLASS_ATTRIBUTE,
JSXML_CLASS_PROCESSING_INSTRUCTION,
JSXML_CLASS_TEXT,
JSXML_CLASS_COMMENT,
JSXML_CLASS_LIMIT
} JSXMLClass;
#define JSXML_CLASS_HAS_KIDS(class_) ((class_) < JSXML_CLASS_ATTRIBUTE)
#define JSXML_CLASS_HAS_VALUE(class_) ((class_) >= JSXML_CLASS_ATTRIBUTE)
#define JSXML_CLASS_HAS_NAME(class_) \
((uintN)((class_) - JSXML_CLASS_ELEMENT) <= \
(uintN)(JSXML_CLASS_PROCESSING_INSTRUCTION - JSXML_CLASS_ELEMENT))
#ifdef DEBUG_notme
#include "jsclist.h"
#endif
struct JSXML {
#ifdef DEBUG_notme
JSCList links;
uint32 serial;
#endif
JSObject *object;
void *domnode; /* DOM node if mapped info item */
JSXML *parent;
JSXMLQName *name;
uint16 xml_class; /* discriminates u, below */
uint16 xml_flags; /* flags, see below */
union {
struct JSXMLListVar {
JSXMLArray kids; /* NB: must come first */
JSXML *target;
JSXMLQName *targetprop;
} list;
struct JSXMLVar {
JSXMLArray kids; /* NB: must come first */
JSXMLArray namespaces;
JSXMLArray attrs;
} elem;
JSString *value;
} u;
/* Don't add anything after u -- see js_NewXML for why. */
};
/* union member shorthands */
#define xml_kids u.list.kids
#define xml_target u.list.target
#define xml_targetprop u.list.targetprop
#define xml_namespaces u.elem.namespaces
#define xml_attrs u.elem.attrs
#define xml_value u.value
/* xml_flags values */
#define XMLF_WHITESPACE_TEXT 0x1
/* xml_class-testing macros */
#define JSXML_HAS_KIDS(xml) JSXML_CLASS_HAS_KIDS((xml)->xml_class)
#define JSXML_HAS_VALUE(xml) JSXML_CLASS_HAS_VALUE((xml)->xml_class)
#define JSXML_HAS_NAME(xml) JSXML_CLASS_HAS_NAME((xml)->xml_class)
#define JSXML_LENGTH(xml) (JSXML_CLASS_HAS_KIDS((xml)->xml_class) \
? (xml)->xml_kids.length \
: 0)
extern JSXML *
js_NewXML(JSContext *cx, JSXMLClass xml_class);
extern void
js_MarkXML(JSContext *cx, JSXML *xml, void *arg);
extern void
js_FinalizeXML(JSContext *cx, JSXML *xml);
extern JSObject *
js_ParseNodeToXMLObject(JSContext *cx, JSParseNode *pn);
extern JSObject *
js_NewXMLObject(JSContext *cx, JSXMLClass xml_class);
extern JSObject *
js_GetXMLObject(JSContext *cx, JSXML *xml);
extern JS_FRIEND_DATA(JSXMLObjectOps) js_XMLObjectOps;
extern JS_FRIEND_DATA(JSClass) js_XMLClass;
extern JS_FRIEND_DATA(JSExtendedClass) js_QNameClass;
extern JS_FRIEND_DATA(JSClass) js_AttributeNameClass;
extern JS_FRIEND_DATA(JSClass) js_AnyNameClass;
extern JS_FRIEND_DATA(JSExtendedClass) js_NamespaceClass;
/*
* Macros to test whether an object or a value is of type "xml" (per typeof).
* NB: jsapi.h must be included before any call to VALUE_IS_XML.
*/
#define OBJECT_IS_XML(cx,obj) ((obj)->map->ops == &js_XMLObjectOps.base)
#define VALUE_IS_XML(cx,v) (!JSVAL_IS_PRIMITIVE(v) && \
OBJECT_IS_XML(cx, JSVAL_TO_OBJECT(v)))
extern JSObject *
js_InitNamespaceClass(JSContext *cx, JSObject *obj);
extern JSObject *
js_InitQNameClass(JSContext *cx, JSObject *obj);
extern JSObject *
js_InitXMLClass(JSContext *cx, JSObject *obj);
extern JSObject *
js_InitXMLClasses(JSContext *cx, JSObject *obj);
extern JSBool
js_GetFunctionNamespace(JSContext *cx, jsval *vp);
extern JSBool
js_GetDefaultXMLNamespace(JSContext *cx, jsval *vp);
extern JSBool
js_SetDefaultXMLNamespace(JSContext *cx, jsval v);
/*
* Return true if v is a XML QName object, or if it converts to a string that
* contains a valid XML qualified name (one containing no :), false otherwise.
* NB: This function is an infallible predicate, it hides exceptions.
*/
extern JSBool
js_IsXMLName(JSContext *cx, jsval v);
extern JSBool
js_ToAttributeName(JSContext *cx, jsval *vp);
extern JSString *
js_EscapeAttributeValue(JSContext *cx, JSString *str);
extern JSString *
js_AddAttributePart(JSContext *cx, JSBool isName, JSString *str,
JSString *str2);
extern JSString *
js_EscapeElementValue(JSContext *cx, JSString *str);
extern JSString *
js_ValueToXMLString(JSContext *cx, jsval v);
extern JSBool
js_GetAnyName(JSContext *cx, jsval *vp);
extern JSBool
js_FindXMLProperty(JSContext *cx, jsval name, JSObject **objp, jsval *namep);
extern JSBool
js_GetXMLProperty(JSContext *cx, JSObject *obj, jsval name, jsval *vp);
extern JSBool
js_SetXMLProperty(JSContext *cx, JSObject *obj, jsval name, jsval *vp);
extern JSBool
js_GetXMLDescendants(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
extern JSBool
js_DeleteXMLListElements(JSContext *cx, JSObject *listobj);
extern JSBool
js_FilterXMLList(JSContext *cx, JSObject *obj, jsbytecode *pc, jsval *vp);
extern JSObject *
js_ValueToXMLObject(JSContext *cx, jsval v);
extern JSObject *
js_ValueToXMLListObject(JSContext *cx, jsval v);
extern JSObject *
js_CloneXMLObject(JSContext *cx, JSObject *obj);
extern JSObject *
js_NewXMLSpecialObject(JSContext *cx, JSXMLClass xml_class, JSString *name,
JSString *value);
#endif /* jsxml_h___ */

View File

@@ -1,114 +0,0 @@
!
! The contents of this file are subject to the Netscape Public
! License Version 1.1 (the "License"); you may not use this file
! except in compliance with the License. You may obtain a copy of
! the License at http://www.mozilla.org/NPL/
!
! Software distributed under the License is distributed on an "AS
! IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
! implied. See the License for the specific language governing
! rights and limitations under the License.
!
! The Original Code is Mozilla Communicator client code, released
! March 31, 1998.
!
! The Initial Developer of the Original Code is Netscape
! Communications Corporation. Portions created by Netscape are
! Copyright (C) 1998-1999 Netscape Communications Corporation. All
! Rights Reserved.
!
! Contributor(s):
!
! Alternatively, the contents of this file may be used under the
! terms of the GNU Public License (the "GPL"), in which case the
! provisions of the GPL are applicable instead of those above.
! If you wish to allow use of your version of this file only
! under the terms of the GPL and not to allow others to use your
! version of this file under the NPL, indicate your decision by
! deleting the provisions above and replace them with the notice
! and other provisions required by the GPL. If you do not delete
! the provisions above, a recipient may use your version of this
! file under either the NPL or the GPL.
!
!
! atomic compare-and-swap routines for V8 sparc
! and for V8+ (ultrasparc)
!
!
! standard asm linkage macros; this module must be compiled
! with the -P option (use C preprocessor)
#include <sys/asm_linkage.h>
! ======================================================================
!
! Perform the sequence *a = b atomically with respect to previous value
! of a (a0). If *a==a0 then assign *a to b, all in one atomic operation.
! Returns 1 if assignment happened, and 0 otherwise.
!
! usage : old_val = compare_and_swap(address, oldval, newval)
!
! -----------------------
! Note on REGISTER USAGE:
! as this is a LEAF procedure, a new stack frame is not created;
! we use the caller stack frame so what would normally be %i (input)
! registers are actually %o (output registers). Also, we must not
! overwrite the contents of %l (local) registers as they are not
! assumed to be volatile during calls.
!
! So, the registers used are:
! %o0 [input] - the address of the value to increment
! %o1 [input] - the old value to compare with
! %o2 [input] - the new value to set for [%o0]
! %o3 [local] - work register
! -----------------------
#ifndef ULTRA_SPARC
! v8
ENTRY(compare_and_swap) ! standard assembler/ELF prologue
stbar
mov -1,%o3 ! busy flag
swap [%o0],%o3 ! get current value
l1: cmp %o3,-1 ! busy?
be,a l1 ! if so, spin
swap [%o0],%o3 ! using branch-delay to swap back value
cmp %o1,%o3 ! compare old with current
be,a l2 ! if equal then swap in new value
swap [%o0],%o2 ! done.
swap [%o0],%o3 ! otherwise, swap back current value
retl
mov 0,%o0 ! return false
l2: retl
mov 1,%o0 ! return true
SET_SIZE(compare_and_swap) ! standard assembler/ELF epilogue
!
! end
!
#else /* ULTRA_SPARC */
! ======================================================================
!
! v9
ENTRY(compare_and_swap) ! standard assembler/ELF prologue
stbar
cas [%o0],%o1,%o2 ! compare *w with old value and set to new if equal
cmp %o1,%o2 ! did we succeed?
be,a m1 ! yes
mov 1,%o0 ! return true (annulled when no jump)
mov 0,%o0 ! return false
m1: retl
nop
SET_SIZE(compare_and_swap) ! standard assembler/ELF epilogue
!
! end
!
! ======================================================================
!
#endif

View File

@@ -1,39 +0,0 @@
// Some simple testing of new, eval and some string stuff.
// constructor -- expression array initialization
function ExprArray(n,v)
{
// Initializes n values to v coerced to a string.
for (var i = 0; i < n; i++) {
this[i] = "" + v;
}
}
// Print the perfect numbers up to n and the sum expression for n's divisors.
function perfect(n)
{
print("The perfect numbers up to " + n + " are:");
// We build sumOfDivisors[i] to hold a string expression for
// the sum of the divisors of i, excluding i itself.
var sumOfDivisors = new ExprArray(n+1,1);
for (var divisor = 2; divisor <= n; divisor++) {
for (var j = divisor + divisor; j <= n; j += divisor) {
sumOfDivisors[j] += " + " + divisor;
}
// At this point everything up to 'divisor' has its sumOfDivisors
// expression calculated, so we can determine whether it's perfect
// already by evaluating.
if (eval(sumOfDivisors[divisor]) == divisor) {
print("" + divisor + " = " + sumOfDivisors[divisor]);
}
}
print("That's all.");
}
print("\nA number is 'perfect' if it is equal to the sum of its")
print("divisors (excluding itself).\n");
perfect(500);

Some files were not shown because too many files have changed in this diff Show More