Compare commits
9 Commits
JS_150_RC3
...
JS_150_RC2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1be2a254ab | ||
|
|
876455a0c2 | ||
|
|
21e1124549 | ||
|
|
5b9d4d00fe | ||
|
|
ec59086efc | ||
|
|
533b43cde1 | ||
|
|
fe3675bafb | ||
|
|
054615e9b5 | ||
|
|
c254065b69 |
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
@@ -42,6 +41,8 @@ include $(DEPTH)/config/autoconf.mk
|
||||
MODULE = js
|
||||
LIBRARY_NAME = mozjs
|
||||
|
||||
DIRS = fdlibm
|
||||
|
||||
CSRCS = \
|
||||
jsapi.c \
|
||||
jsarena.c \
|
||||
@@ -132,17 +133,33 @@ DASH_R = -r
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_NSPR_LIBS)
|
||||
|
||||
ifeq ($(OS_ARCH),OS2)
|
||||
EXTRA_DSO_LDOPTS += $(FDLIBM_LIBRARY)
|
||||
ifneq ($(MOZ_WIDGET_TOOLKIT),os2)
|
||||
ifndef XCFLAGS
|
||||
OS2_IMPLIB = 1
|
||||
LIBRARY = js$(MOZ_BITS)$(VERSION_NUMBER).$(LIB_SUFFIX)
|
||||
DEF_FILE = jsos2$(VERSION_NUMBER).def
|
||||
EXTRA_LIBS = $(NSPR_LIBS) $(LIBNSJAVA)
|
||||
else
|
||||
EXTRA_LIBS = $(NSPR_LIBS) $(LIBNSJAVA) libjs.lib
|
||||
endif
|
||||
OS_CFLAGS += -tm-
|
||||
endif
|
||||
endif
|
||||
|
||||
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_NSPR_LIBS)
|
||||
|
||||
# When using gcc the assembly is inlined in the C-file (see jslock.c)
|
||||
ifdef NS_USE_NATIVE
|
||||
ASFILES = $(notdir $(wildcard $(srcdir)/*_$(OS_ARCH).s))
|
||||
endif
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
|
||||
DEF_OBJS = jsapi.o jsarena.o jsdbgapi.o jsdhash.o jsdtoa.o jsgc.o jshash.o \
|
||||
jsinterp.o jslog2.o jslong.o jsprf.o jsutil.o jsxdrapi.o prmjtime.o
|
||||
#ADD_TO_DEF_FILE = cat < $(srcdir)/extradefs.os2 >>$(DEF_FILE)
|
||||
endif
|
||||
|
||||
ifndef BUILD_OPT
|
||||
MOCHAFILE = 1
|
||||
endif
|
||||
@@ -204,7 +221,8 @@ ifeq ($(OS_ARCH),FreeBSD)
|
||||
LDFLAGS += -pthread
|
||||
endif
|
||||
ifeq ($(OS_ARCH),IRIX)
|
||||
ifdef USE_N32
|
||||
ifneq ($(basename $(OS_RELEASE)),5)
|
||||
LDFLAGS += -n32
|
||||
DASH_R += -n32
|
||||
endif
|
||||
endif
|
||||
@@ -246,9 +264,9 @@ OBJS += fdlibm/*.o
|
||||
endif
|
||||
endif
|
||||
|
||||
# On OS/2 we are already linking against fdlibm, so don't bother
|
||||
# creating jsmathtemp
|
||||
ifneq ($(OS_ARCH),OS2)
|
||||
# OS/2 linkers expect to create executables or dlls, not object files
|
||||
# so we pull in what's needed from fdlibm when creating the js dll
|
||||
ifneq ($(MOZ_WIDGET_TOOLKIT),os2)
|
||||
# special rule for jsmath.o since we want to incrementally link
|
||||
# against fdlibm to pull in only what is needed
|
||||
jsmath.o: $(FDLIBM_LIBRARY) $(JSMATH_PRELINK)
|
||||
@@ -268,9 +286,6 @@ ifeq ($(OS_ARCH),WINNT)
|
||||
else
|
||||
$(CC) -o $@ -c $(COMPILE_CFLAGS) $<
|
||||
endif
|
||||
else
|
||||
# Create dependency so we build fdlibm
|
||||
jsmath.o: $(FDLIBM_LIBRARY)
|
||||
endif
|
||||
|
||||
# An AIX Optimization bug causes PR_dtoa() & JS_dtoa to produce wrong result.
|
||||
@@ -281,7 +296,9 @@ jsdtoa.o: jsdtoa.c
|
||||
endif
|
||||
|
||||
$(FDLIBM_LIBRARY):
|
||||
$(MAKE) -C $(@D) $(@F)
|
||||
@$(CONTINUE_ON_ERROR) \
|
||||
$(MAKE) -C $(@D) $(@F); \
|
||||
$(EXIT_ON_ERROR)
|
||||
|
||||
jsopcode.h jsopcode.c: jsopcode.tbl
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
@@ -53,9 +52,9 @@ ifdef JS_THREADSAFE
|
||||
DEFINES += -DJS_THREADSAFE
|
||||
INCLUDES += -I../../dist/$(OBJDIR)/include
|
||||
ifdef USE_MSVC
|
||||
OTHER_LIBS += ../../dist/$(OBJDIR)/lib/libnspr${NSPR_LIBSUFFIX}.lib
|
||||
OTHER_LIBS += ../../dist/$(OBJDIR)/lib/libnspr3.lib
|
||||
else
|
||||
OTHER_LIBS += -L../../dist/$(OBJDIR)/lib -lnspr${NSPR_LIBSUFFIX}
|
||||
OTHER_LIBS += -L../../dist/$(OBJDIR)/lib -lnspr3
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -93,8 +92,7 @@ PERLLDFLAGS := $(shell perl -MExtUtils::Embed -e ldopts)
|
||||
PERLLDFLAGS := $(subst -rdynamic,-export-dynamic,$(PERLLDFLAGS))
|
||||
|
||||
CFLAGS += $(PERLCFLAGS)
|
||||
#LDFLAGS += $(PERLLDFLAGS) #PH removed this assgnment
|
||||
INCLUDES += -I. #needed for perlconnect/jsperl.c
|
||||
LDFLAGS += $(PERLLDFLAGS)
|
||||
endif
|
||||
|
||||
#
|
||||
@@ -150,7 +148,6 @@ JS_HFILES = \
|
||||
jsparse.h \
|
||||
jsarena.h \
|
||||
jsclist.h \
|
||||
jsdhash.h \
|
||||
jsdtoa.h \
|
||||
jshash.h \
|
||||
jslong.h \
|
||||
@@ -199,7 +196,6 @@ JS_CFILES = \
|
||||
jscntxt.c \
|
||||
jsdate.c \
|
||||
jsdbgapi.c \
|
||||
jsdhash.c \
|
||||
jsdtoa.c \
|
||||
jsemit.c \
|
||||
jsexn.c \
|
||||
@@ -226,8 +222,7 @@ JS_CFILES = \
|
||||
prmjtime.c \
|
||||
$(NULL)
|
||||
|
||||
PREDIRS += fdlibm
|
||||
|
||||
PREDIRS += fdlibm
|
||||
ifdef USE_MSVC
|
||||
FDLIBM_LIBRARY = fdlibm/$(OBJDIR)/fdlibm.lib
|
||||
else
|
||||
@@ -269,9 +264,6 @@ 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
|
||||
@@ -309,8 +301,7 @@ $(OBJDIR)/jscpucfg: $(OBJDIR)/jscpucfg.o
|
||||
INCLUDES += -I$(OBJDIR)
|
||||
|
||||
# Add to TARGETS for clobber rule
|
||||
TARGETS += $(OBJDIR)/jsautocfg.h $(OBJDIR)/jscpucfg \
|
||||
$(OBJDIR)/jscpucfg.o $(OBJDIR)/jsmathtemp.o
|
||||
TARGETS += $(OBJDIR)/jsautocfg.h $(OBJDIR)/jscpucfg $(OBJDIR)/jscpucfg.o
|
||||
endif
|
||||
|
||||
|
||||
@@ -338,11 +329,6 @@ else
|
||||
$(CC) -o $@ -c $(CFLAGS) $<
|
||||
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
|
||||
#
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
@@ -123,4 +122,4 @@ VPATH = $(OBJDIR)
|
||||
# Automatic make dependencies file
|
||||
DEPENDENCIES = $(OBJDIR)/.md
|
||||
|
||||
LCJAR = js15lc30.jar
|
||||
LCJAR = js14lc30.jar
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
@@ -51,7 +50,7 @@ INLINES = js_compare_and_swap:js_fast_lock1:js_fast_unlock1:js_lock_get_slot:js_
|
||||
|
||||
#-lpthreads -lc_r
|
||||
|
||||
MKSHLIB_BIN = /usr/ibmcxx/bin/makeC++SharedLib_r
|
||||
MKSHLIB_BIN = /usr/lpp/xlC/bin/makeC++SharedLib_r
|
||||
MKSHLIB = $(MKSHLIB_BIN) -p 0 -G -berok -bM:UR
|
||||
|
||||
ifdef JS_THREADSAFE
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# 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 oqr
|
||||
# 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 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.
|
||||
#
|
||||
|
||||
#
|
||||
# Config stuff for Tru64 Unix 5.0
|
||||
#
|
||||
|
||||
#
|
||||
# Initial DG/UX port by Marc Fraioli (fraioli@dg-rtp.dg.com)
|
||||
#
|
||||
|
||||
ifndef NS_USE_NATIVE
|
||||
CC = gcc
|
||||
CCC = g++
|
||||
CFLAGS += -mieee -Wall -Wno-format
|
||||
else
|
||||
CC = cc
|
||||
CCC = cxx
|
||||
CFLAGS += -ieee -std -pthread
|
||||
# LD = cxx
|
||||
endif
|
||||
|
||||
RANLIB = echo
|
||||
MKSHLIB = $(LD) -shared -all -expect_unresolved "*"
|
||||
|
||||
#
|
||||
# _POSIX4A_DRAFT10_SOURCE is needed to pick up localtime_r, used in
|
||||
# prtime.c
|
||||
#
|
||||
OS_CFLAGS = -DXP_UNIX -DSVR4 -DSYSV -D_POSIX4A_DRAFT10_SOURCE -DOSF1
|
||||
OS_LIBS = -lsocket -lnsl
|
||||
|
||||
NOSUCHFILE = /no-such-file
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# 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 oqr
|
||||
# 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) 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.
|
||||
#
|
||||
|
||||
#
|
||||
# Config stuff for SunOS5.8
|
||||
#
|
||||
|
||||
include $(DEPTH)/config/SunOS5.5.mk
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# 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 oqr
|
||||
# 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 Simmule Turner and
|
||||
# Rich Salz. Portions created by Netscape are
|
||||
# Copyright (C) 1998 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.
|
||||
#
|
||||
|
||||
#
|
||||
# Copyright 1992,1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||
#
|
||||
# This software is not subject to any license of the American Telephone
|
||||
# and Telegraph Company or of the Regents of the University of California.
|
||||
#
|
||||
# Permission is granted to anyone to use this software for any purpose on
|
||||
# any computer system, and to alter it and redistribute it freely, subject
|
||||
# to the following restrictions:
|
||||
# 1. The authors are not responsible for the consequences of use of this
|
||||
# software, no matter how awful, even if they arise from flaws in it.
|
||||
# 2. The origin of this software must not be misrepresented, either by
|
||||
# explicit claim or by omission. Since few users ever read sources,
|
||||
# credits must appear in the documentation.
|
||||
# 3. Altered versions must be plainly marked as such, and must not be
|
||||
# misrepresented as being the original software. Since few users
|
||||
# ever read sources, credits must appear in the documentation.
|
||||
# 4. This notice may not be removed or altered.
|
||||
#
|
||||
|
||||
#
|
||||
# Unix makefile for editline library.
|
||||
#
|
||||
|
||||
## Set your options:
|
||||
## -DANSI_ARROWS ANSI arrows keys work like emacs.
|
||||
## -DHAVE_STDLIB Have <stdlib.h>.
|
||||
## -DHAVE_TCGETATTR Have tcgetattr(), tcsetattr().
|
||||
## -DHAVE_TERMIO Have "struct termio" and <termio.h>
|
||||
## (If neither of above two, we use <sgttyb.h> and BSD ioctl's)
|
||||
## -DHIDE Make static functions static (non debug).
|
||||
## -DHIST_SIZE=n History size.
|
||||
## -DNEED_STRDUP Don't have strdup().
|
||||
## -DUNIQUE_HISTORY Don't save command if same as last one.
|
||||
## -DUSE_DIRENT Use <dirent.h>, not <sys/dir.h>?
|
||||
## -DUSE_TERMCAP Use the termcap library for terminal size
|
||||
## see LDFLAGS, below, if you set this.
|
||||
## -DNEED_PERROR Don't have perror() (used in testit)
|
||||
|
||||
## If you have -DUSE_TERMCAP, set this as appropriate:
|
||||
#LDFLAGS = -ltermlib
|
||||
#LDFLAGS = -ltermcap
|
||||
|
||||
DEFS = -DANSI_ARROWS -DHAVE_TCGETATTR -DHIDE -DUSE_DIRENT -DSYS_UNIX \
|
||||
-DHAVE_STDLIB -DUNIQUE_HISTORY
|
||||
|
||||
DEPTH = ..
|
||||
|
||||
include $(DEPTH)/config.mk
|
||||
|
||||
#
|
||||
# Default IEEE libm
|
||||
#
|
||||
CFLAGS += -DXP_UNIX $(OPTIMIZER) $(OS_CFLAGS) $(DEFINES) $(INCLUDES) \
|
||||
-DJSFILE $(XCFLAGS) $(DEFS)
|
||||
|
||||
INCFILES = editline.h
|
||||
.INIT: $(INCFILES)
|
||||
.KEEP_STATE:
|
||||
EDITLINE_CFILES = editline.c sysunix.c
|
||||
|
||||
EDITLINE_OBJS = $(addprefix $(OBJDIR)/, $(EDITLINE_CFILES:.c=.o))
|
||||
|
||||
LIBRARY = $(OBJDIR)/libedit.a
|
||||
|
||||
define MAKE_OBJDIR
|
||||
if test ! -d $(@D); then rm -rf $(@D); mkdir $(@D); fi
|
||||
endef
|
||||
|
||||
all: $(LIBRARY)
|
||||
|
||||
export:
|
||||
|
||||
$(OBJDIR)/%: %.c
|
||||
@$(MAKE_OBJDIR)
|
||||
$(CC) -o $@ $(CFLAGS) $*.c $(LDFLAGS)
|
||||
|
||||
$(OBJDIR)/%.o: %.c
|
||||
@$(MAKE_OBJDIR)
|
||||
$(CC) -o $@ -c $(CFLAGS) $*.c
|
||||
|
||||
$(OBJDIR)/%.o: %.s
|
||||
@$(MAKE_OBJDIR)
|
||||
$(AS) -o $@ $(ASFLAGS) $*.s
|
||||
|
||||
$(LIBRARY): $(EDITLINE_OBJS)
|
||||
$(AR) rv $@ $?
|
||||
$(RANLIB) $@
|
||||
|
||||
#libedit.a : $(EDITLINE_OBJS)
|
||||
# $(AR) cru $(OBJDIR)/libedit.a $(EDITLINE_OBJS)
|
||||
# $(RANLIB) $(OBJDIR)/libedit.a
|
||||
|
||||
clean:
|
||||
rm -rf $(EDITLINE_OBJS)
|
||||
|
||||
clobber:
|
||||
rm -rf $(EDITLINE_OBJS) $(LIBRARY) $(DEPENDENCIES)
|
||||
|
||||
SUFFIXES: .i
|
||||
%.i: %.c
|
||||
$(CC) -C -E $(CFLAGS) $< > $*.i
|
||||
|
||||
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
The files in this directory provide simple line-editing and history
|
||||
support for the standalone javascript engine, through the 'editline'
|
||||
library.
|
||||
|
||||
editline has only been enabled for those platforms on which it is
|
||||
known to build; to try it on a different platform, define JS_EDITLINE
|
||||
before building. Line editing (and js.c) is not a supported feature
|
||||
of the javascript library, so your mileage my vary.
|
||||
|
||||
The editline API is a compatible subset of the FSF readline API; if
|
||||
you have readline installed and would like to link to that instead,
|
||||
define JS_READLINE. Note that the readline library is distributed
|
||||
under the GPL, so any resulting binaries are not legally
|
||||
distributable.
|
||||
|
||||
The editline files used here have been modified to work with the js
|
||||
build system and to quiet some compiler warnings, and also to remove
|
||||
filename-completion support.
|
||||
|
||||
If anyone knows of a more recent version of these files, or a site on
|
||||
which they are being maintained, please let me know!
|
||||
|
||||
Mike McCabe, mccabe@netscape.com
|
||||
|
||||
|
||||
The original README file distributed with the editline library follows.
|
||||
|
||||
|
||||
|
||||
This is a line-editing library. It can be linked into almost any
|
||||
program to provide command-line editing and recall.
|
||||
|
||||
It is call-compatible with the FSF readline library, but it is a
|
||||
fraction of the size (and offers fewer features). It does not use
|
||||
standard I/O. It is distributed under a "C News-like" copyright.
|
||||
|
||||
Configuration is done in the Makefile. Type "make testit" to get
|
||||
a small slow shell for testing.
|
||||
|
||||
An earlier version was distributed with Byron's rc. Principal
|
||||
changes over that version include:
|
||||
Faster.
|
||||
Is eight-bit clean (thanks to brendan@cs.widener.edu)
|
||||
Written in K&R C, but ANSI compliant (gcc all warnings)
|
||||
Propagates EOF properly; rc trip test now passes
|
||||
Doesn't need or use or provide memmove.
|
||||
More robust
|
||||
Calling sequence changed to be compatible with readline.
|
||||
Test program, new manpage, better configuration
|
||||
More system-independant; includes Unix and OS-9 support.
|
||||
|
||||
This contains some changes since the posting to comp.sources.misc:
|
||||
Bugfix for completion on absolute pathnames.
|
||||
Better handling of M-n versus showing raw 8bit chars.
|
||||
Better signal handling.
|
||||
Now supports termios/termio/sgttyb ioctl's.
|
||||
Add M-m command to toggle how 8bit data is displayed.
|
||||
|
||||
There is one known bug:
|
||||
History-searching redraws the line wrong if the text
|
||||
retrieved is shorter then the prompt.
|
||||
|
||||
Enjoy,
|
||||
Rich $alz
|
||||
<rsalz@osf.org>
|
||||
|
||||
Copyright 1992,1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||
|
||||
This software is not subject to any license of the American Telephone
|
||||
and Telegraph Company or of the Regents of the University of California.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose on
|
||||
any computer system, and to alter it and redistribute it freely, subject
|
||||
to the following restrictions:
|
||||
1. The authors are not responsible for the consequences of use of this
|
||||
software, no matter how awful, even if they arise from flaws in it.
|
||||
2. The origin of this software must not be misrepresented, either by
|
||||
explicit claim or by omission. Since few users ever read sources,
|
||||
credits must appear in the documentation.
|
||||
3. Altered versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software. Since few users
|
||||
ever read sources, credits must appear in the documentation.
|
||||
4. This notice may not be removed or altered.
|
||||
@@ -1,175 +0,0 @@
|
||||
.TH EDITLINE 3
|
||||
.SH NAME
|
||||
editline \- command-line editing library with history
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B "char *"
|
||||
.B "readline(prompt)"
|
||||
.B " char *prompt;"
|
||||
|
||||
.B "void"
|
||||
.B "add_history(line)"
|
||||
.B " char *line;"
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
.I Editline
|
||||
is a library that provides an line-editing interface with text recall.
|
||||
It is intended to be compatible with the
|
||||
.I readline
|
||||
library provided by the Free Software Foundation, but much smaller.
|
||||
The bulk of this manual page describes the user interface.
|
||||
.PP
|
||||
The
|
||||
.I readline
|
||||
routine returns a line of text with the trailing newline removed.
|
||||
The data is returned in a buffer allocated with
|
||||
.IR malloc (3),
|
||||
so the space should be released with
|
||||
.IR free (3)
|
||||
when the calling program is done with it.
|
||||
Before accepting input from the user, the specified
|
||||
.I prompt
|
||||
is displayed on the terminal.
|
||||
.PP
|
||||
The
|
||||
.I add_history
|
||||
routine makes a copy of the specified
|
||||
.I line
|
||||
and adds it to the internal history list.
|
||||
.SS "User Interface"
|
||||
A program that uses this library provides a simple emacs-like editing
|
||||
interface to its users.
|
||||
A line may be edited before it is sent to the calling program by typing either
|
||||
control characters or escape sequences.
|
||||
A control character, shown as a caret followed by a letter, is typed by
|
||||
holding down the ``control'' key while the letter is typed.
|
||||
For example, ``^A'' is a control-A.
|
||||
An escape sequence is entered by typing the ``escape'' key followed by one or
|
||||
more characters.
|
||||
The escape key is abbreviated as ``ESC.''
|
||||
Note that unlike control keys, case matters in escape sequences; ``ESC\ F''
|
||||
is not the same as ``ESC\ f''.
|
||||
.PP
|
||||
An editing command may be typed anywhere on the line, not just at the
|
||||
beginning.
|
||||
In addition, a return may also be typed anywhere on the line, not just at
|
||||
the end.
|
||||
.PP
|
||||
Most editing commands may be given a repeat count,
|
||||
.IR n ,
|
||||
where
|
||||
.I n
|
||||
is a number.
|
||||
To enter a repeat count, type the escape key, the number, and then
|
||||
the command to execute.
|
||||
For example, ``ESC\ 4\ ^f'' moves forward four characters.
|
||||
If a command may be given a repeat count then the text ``[n]'' is given at the
|
||||
end of its description.
|
||||
.PP
|
||||
The following control characters are accepted:
|
||||
.RS
|
||||
.nf
|
||||
.ta \w'ESC DEL 'u
|
||||
^A Move to the beginning of the line
|
||||
^B Move left (backwards) [n]
|
||||
^D Delete character [n]
|
||||
^E Move to end of line
|
||||
^F Move right (forwards) [n]
|
||||
^G Ring the bell
|
||||
^H Delete character before cursor (backspace key) [n]
|
||||
^I Complete filename (tab key); see below
|
||||
^J Done with line (return key)
|
||||
^K Kill to end of line (or column [n])
|
||||
^L Redisplay line
|
||||
^M Done with line (alternate return key)
|
||||
^N Get next line from history [n]
|
||||
^P Get previous line from history [n]
|
||||
^R Search backward (forward if [n]) through history for text;
|
||||
\& must start line if text begins with an uparrow
|
||||
^T Transpose characters
|
||||
^V Insert next character, even if it is an edit command
|
||||
^W Wipe to the mark
|
||||
^X^X Exchange current location and mark
|
||||
^Y Yank back last killed text
|
||||
^[ Start an escape sequence (escape key)
|
||||
^]c Move forward to next character ``c''
|
||||
^? Delete character before cursor (delete key) [n]
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
The following escape sequences are provided.
|
||||
.RS
|
||||
.nf
|
||||
.ta \w'ESC DEL 'u
|
||||
ESC\ ^H Delete previous word (backspace key) [n]
|
||||
ESC\ DEL Delete previous word (delete key) [n]
|
||||
ESC\ SP Set the mark (space key); see ^X^X and ^Y above
|
||||
ESC\ \. Get the last (or [n]'th) word from previous line
|
||||
ESC\ \? Show possible completions; see below
|
||||
ESC\ < Move to start of history
|
||||
ESC\ > Move to end of history
|
||||
ESC\ b Move backward a word [n]
|
||||
ESC\ d Delete word under cursor [n]
|
||||
ESC\ f Move forward a word [n]
|
||||
ESC\ l Make word lowercase [n]
|
||||
ESC\ m Toggle if 8bit chars display normally or with ``M\-'' prefix
|
||||
ESC\ u Make word uppercase [n]
|
||||
ESC\ y Yank back last killed text
|
||||
ESC\ v Show library version
|
||||
ESC\ w Make area up to mark yankable
|
||||
ESC\ nn Set repeat count to the number nn
|
||||
ESC\ C Read from environment variable ``_C_'', where C is
|
||||
\& an uppercase letter
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
The
|
||||
.I editline
|
||||
library has a small macro facility.
|
||||
If you type the escape key followed by an uppercase letter,
|
||||
.IR C ,
|
||||
then the contents of the environment variable
|
||||
.I _C_
|
||||
are read in as if you had typed them at the keyboard.
|
||||
For example, if the variable
|
||||
.I _L_
|
||||
contains the following:
|
||||
.RS
|
||||
^A^Kecho '^V^[[H^V^[[2J'^M
|
||||
.RE
|
||||
Then typing ``ESC L'' will move to the beginning of the line, kill the
|
||||
entire line, enter the echo command needed to clear the terminal (if your
|
||||
terminal is like a VT-100), and send the line back to the shell.
|
||||
.PP
|
||||
The
|
||||
.I editline
|
||||
library also does filename completion.
|
||||
Suppose the root directory has the following files in it:
|
||||
.RS
|
||||
.nf
|
||||
.ta \w'core 'u
|
||||
bin vmunix
|
||||
core vmunix.old
|
||||
.fi
|
||||
.RE
|
||||
If you type ``rm\ /v'' and then the tab key.
|
||||
.I Editline
|
||||
will then finish off as much of the name as possible by adding ``munix''.
|
||||
Because the name is not unique, it will then beep.
|
||||
If you type the escape key and a question mark, it will display the
|
||||
two choices.
|
||||
If you then type a period and a tab, the library will finish off the filename
|
||||
for you:
|
||||
.RS
|
||||
.nf
|
||||
.RI "rm /v[TAB]" munix .TAB old
|
||||
.fi
|
||||
.RE
|
||||
The tab key is shown by ``[TAB]'' and the automatically-entered text
|
||||
is shown in italics.
|
||||
.SH "BUGS AND LIMITATIONS"
|
||||
Cannot handle lines more than 80 columns.
|
||||
.SH AUTHORS
|
||||
Simmule R. Turner <uunet.uu.net!capitol!sysgo!simmy>
|
||||
and Rich $alz <rsalz@osf.org>.
|
||||
Original manual page by DaviD W. Sanderson <dws@ssec.wisc.edu>.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,130 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 oqr
|
||||
* 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 Simmule Turner and
|
||||
* Rich Salz. Portions created by Netscape are
|
||||
* Copyright (C) 1998 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright 1992,1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||
*
|
||||
* This software is not subject to any license of the American Telephone
|
||||
* and Telegraph Company or of the Regents of the University of California.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose on
|
||||
* any computer system, and to alter it and redistribute it freely, subject
|
||||
* to the following restrictions:
|
||||
* 1. The authors are not responsible for the consequences of use of this
|
||||
* software, no matter how awful, even if they arise from flaws in it.
|
||||
* 2. The origin of this software must not be misrepresented, either by
|
||||
* explicit claim or by omission. Since few users ever read sources,
|
||||
* credits must appear in the documentation.
|
||||
* 3. Altered versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software. Since few users
|
||||
* ever read sources, credits must appear in the documentation.
|
||||
* 4. This notice may not be removed or altered.
|
||||
*/
|
||||
|
||||
/*
|
||||
** Internal header file for editline library.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#if defined(HAVE_STDLIB)
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#endif /* defined(HAVE_STDLIB) */
|
||||
#if defined(SYS_UNIX)
|
||||
#include "unix.h"
|
||||
#endif /* defined(SYS_UNIX) */
|
||||
#if defined(SYS_OS9)
|
||||
#include "os9.h"
|
||||
#endif /* defined(SYS_OS9) */
|
||||
|
||||
#if !defined(SIZE_T)
|
||||
#define SIZE_T unsigned int
|
||||
#endif /* !defined(SIZE_T) */
|
||||
|
||||
typedef unsigned char CHAR;
|
||||
|
||||
#if defined(HIDE)
|
||||
#define STATIC static
|
||||
#else
|
||||
#define STATIC /* NULL */
|
||||
#endif /* !defined(HIDE) */
|
||||
|
||||
#if !defined(CONST)
|
||||
#if defined(__STDC__)
|
||||
#define CONST const
|
||||
#else
|
||||
#define CONST
|
||||
#endif /* defined(__STDC__) */
|
||||
#endif /* !defined(CONST) */
|
||||
|
||||
|
||||
#define MEM_INC 64
|
||||
#define SCREEN_INC 256
|
||||
|
||||
#define DISPOSE(p) free((char *)(p))
|
||||
#define NEW(T, c) \
|
||||
((T *)malloc((unsigned int)(sizeof (T) * (c))))
|
||||
#define RENEW(p, T, c) \
|
||||
(p = (T *)realloc((char *)(p), (unsigned int)(sizeof (T) * (c))))
|
||||
#define COPYFROMTO(new, p, len) \
|
||||
(void)memcpy((char *)(new), (char *)(p), (int)(len))
|
||||
|
||||
|
||||
/*
|
||||
** Variables and routines internal to this package.
|
||||
*/
|
||||
extern int rl_eof;
|
||||
extern int rl_erase;
|
||||
extern int rl_intr;
|
||||
extern int rl_kill;
|
||||
extern int rl_quit;
|
||||
extern char *rl_complete();
|
||||
extern int rl_list_possib();
|
||||
extern void rl_ttyset();
|
||||
extern void rl_add_slash();
|
||||
|
||||
#if !defined(HAVE_STDLIB)
|
||||
extern char *getenv();
|
||||
extern char *malloc();
|
||||
extern char *realloc();
|
||||
extern char *memcpy();
|
||||
extern char *strcat();
|
||||
extern char *strchr();
|
||||
extern char *strrchr();
|
||||
extern char *strcpy();
|
||||
extern char *strdup();
|
||||
extern int strcmp();
|
||||
extern int strlen();
|
||||
extern int strncmp();
|
||||
#endif /* !defined(HAVE_STDLIB) */
|
||||
|
||||
@@ -1,177 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 oqr
|
||||
* 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 Simmule Turner and
|
||||
* Rich Salz. Portions created by Netscape are
|
||||
* Copyright (C) 1998 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright 1992,1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||
*
|
||||
* This software is not subject to any license of the American Telephone
|
||||
* and Telegraph Company or of the Regents of the University of California.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose on
|
||||
* any computer system, and to alter it and redistribute it freely, subject
|
||||
* to the following restrictions:
|
||||
* 1. The authors are not responsible for the consequences of use of this
|
||||
* software, no matter how awful, even if they arise from flaws in it.
|
||||
* 2. The origin of this software must not be misrepresented, either by
|
||||
* explicit claim or by omission. Since few users ever read sources,
|
||||
* credits must appear in the documentation.
|
||||
* 3. Altered versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software. Since few users
|
||||
* ever read sources, credits must appear in the documentation.
|
||||
* 4. This notice may not be removed or altered.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** Unix system-dependant routines for editline library.
|
||||
*/
|
||||
#include "editline.h"
|
||||
|
||||
#if defined(HAVE_TCGETATTR)
|
||||
#include <termios.h>
|
||||
|
||||
void
|
||||
rl_ttyset(Reset)
|
||||
int Reset;
|
||||
{
|
||||
static struct termios old;
|
||||
struct termios new;
|
||||
|
||||
if (Reset == 0) {
|
||||
(void)tcgetattr(0, &old);
|
||||
rl_erase = old.c_cc[VERASE];
|
||||
rl_kill = old.c_cc[VKILL];
|
||||
rl_eof = old.c_cc[VEOF];
|
||||
rl_intr = old.c_cc[VINTR];
|
||||
rl_quit = old.c_cc[VQUIT];
|
||||
|
||||
new = old;
|
||||
new.c_cc[VINTR] = -1;
|
||||
new.c_cc[VQUIT] = -1;
|
||||
new.c_lflag &= ~(ECHO | ICANON);
|
||||
new.c_iflag &= ~(ISTRIP | INPCK);
|
||||
new.c_cc[VMIN] = 1;
|
||||
new.c_cc[VTIME] = 0;
|
||||
(void)tcsetattr(0, TCSADRAIN, &new);
|
||||
}
|
||||
else
|
||||
(void)tcsetattr(0, TCSADRAIN, &old);
|
||||
}
|
||||
|
||||
#else
|
||||
#if defined(HAVE_TERMIO)
|
||||
#include <termio.h>
|
||||
|
||||
void
|
||||
rl_ttyset(Reset)
|
||||
int Reset;
|
||||
{
|
||||
static struct termio old;
|
||||
struct termio new;
|
||||
|
||||
if (Reset == 0) {
|
||||
(void)ioctl(0, TCGETA, &old);
|
||||
rl_erase = old.c_cc[VERASE];
|
||||
rl_kill = old.c_cc[VKILL];
|
||||
rl_eof = old.c_cc[VEOF];
|
||||
rl_intr = old.c_cc[VINTR];
|
||||
rl_quit = old.c_cc[VQUIT];
|
||||
|
||||
new = old;
|
||||
new.c_cc[VINTR] = -1;
|
||||
new.c_cc[VQUIT] = -1;
|
||||
new.c_lflag &= ~(ECHO | ICANON);
|
||||
new.c_iflag &= ~(ISTRIP | INPCK);
|
||||
new.c_cc[VMIN] = 1;
|
||||
new.c_cc[VTIME] = 0;
|
||||
(void)ioctl(0, TCSETAW, &new);
|
||||
}
|
||||
else
|
||||
(void)ioctl(0, TCSETAW, &old);
|
||||
}
|
||||
|
||||
#else
|
||||
#include <sgtty.h>
|
||||
|
||||
void
|
||||
rl_ttyset(Reset)
|
||||
int Reset;
|
||||
{
|
||||
static struct sgttyb old_sgttyb;
|
||||
static struct tchars old_tchars;
|
||||
struct sgttyb new_sgttyb;
|
||||
struct tchars new_tchars;
|
||||
|
||||
if (Reset == 0) {
|
||||
(void)ioctl(0, TIOCGETP, &old_sgttyb);
|
||||
rl_erase = old_sgttyb.sg_erase;
|
||||
rl_kill = old_sgttyb.sg_kill;
|
||||
|
||||
(void)ioctl(0, TIOCGETC, &old_tchars);
|
||||
rl_eof = old_tchars.t_eofc;
|
||||
rl_intr = old_tchars.t_intrc;
|
||||
rl_quit = old_tchars.t_quitc;
|
||||
|
||||
new_sgttyb = old_sgttyb;
|
||||
new_sgttyb.sg_flags &= ~ECHO;
|
||||
new_sgttyb.sg_flags |= RAW;
|
||||
#if defined(PASS8)
|
||||
new_sgttyb.sg_flags |= PASS8;
|
||||
#endif /* defined(PASS8) */
|
||||
(void)ioctl(0, TIOCSETP, &new_sgttyb);
|
||||
|
||||
new_tchars = old_tchars;
|
||||
new_tchars.t_intrc = -1;
|
||||
new_tchars.t_quitc = -1;
|
||||
(void)ioctl(0, TIOCSETC, &new_tchars);
|
||||
}
|
||||
else {
|
||||
(void)ioctl(0, TIOCSETP, &old_sgttyb);
|
||||
(void)ioctl(0, TIOCSETC, &old_tchars);
|
||||
}
|
||||
}
|
||||
#endif /* defined(HAVE_TERMIO) */
|
||||
#endif /* defined(HAVE_TCGETATTR) */
|
||||
|
||||
void
|
||||
rl_add_slash(path, p)
|
||||
char *path;
|
||||
char *p;
|
||||
{
|
||||
struct stat Sb;
|
||||
|
||||
if (stat(path, &Sb) >= 0)
|
||||
(void)strcat(p, S_ISDIR(Sb.st_mode) ? "/" : " ");
|
||||
}
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 oqr
|
||||
* 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 Simmule Turner and
|
||||
* Rich Salz. Portions created by Netscape are
|
||||
* Copyright (C) 1998 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright 1992,1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||
*
|
||||
* This software is not subject to any license of the American Telephone
|
||||
* and Telegraph Company or of the Regents of the University of California.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose on
|
||||
* any computer system, and to alter it and redistribute it freely, subject
|
||||
* to the following restrictions:
|
||||
* 1. The authors are not responsible for the consequences of use of this
|
||||
* software, no matter how awful, even if they arise from flaws in it.
|
||||
* 2. The origin of this software must not be misrepresented, either by
|
||||
* explicit claim or by omission. Since few users ever read sources,
|
||||
* credits must appear in the documentation.
|
||||
* 3. Altered versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software. Since few users
|
||||
* ever read sources, credits must appear in the documentation.
|
||||
* 4. This notice may not be removed or altered.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** Editline system header file for Unix.
|
||||
*/
|
||||
|
||||
#define CRLF "\r\n"
|
||||
#define FORWARD STATIC
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if defined(USE_DIRENT)
|
||||
#include <dirent.h>
|
||||
typedef struct dirent DIRENTRY;
|
||||
#else
|
||||
#include <sys/dir.h>
|
||||
typedef struct direct DIRENTRY;
|
||||
#endif /* defined(USE_DIRENT) */
|
||||
|
||||
#if !defined(S_ISDIR)
|
||||
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||
#endif /* !defined(S_ISDIR) */
|
||||
|
||||
@@ -89,7 +89,7 @@ include $(topsrcdir)/config/rules.mk
|
||||
#
|
||||
# Default IEEE libm
|
||||
#
|
||||
CFLAGS += -D_IEEE_LIBM
|
||||
CFLAGS += -D_IEEE_LIBM -DGCC_OPT_BUG
|
||||
|
||||
ifeq ($(OS_ARCH),Linux)
|
||||
LDFLAGS += -ldl
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- Mode: makefile -*-
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
@@ -88,9 +87,7 @@ include $(DEPTH)/config.mk
|
||||
CFLAGS += -DXP_UNIX $(OPTIMIZER) $(OS_CFLAGS) $(DEFINES) $(INCLUDES) \
|
||||
-DJSFILE $(XCFLAGS) -D_IEEE_LIBM
|
||||
|
||||
# Need for jstypes.h and friends
|
||||
INCLUDES += -I..
|
||||
INCLUDES += -I../$(OBJDIR)
|
||||
|
||||
|
||||
#CC = cc
|
||||
|
||||
@@ -132,7 +129,7 @@ LIBRARY = $(OBJDIR)/libfdm.a
|
||||
endif
|
||||
|
||||
define MAKE_OBJDIR
|
||||
if test ! -d $(@D); then rm -rf $(@D); mkdir -p $(@D); fi
|
||||
if test ! -d $(@D); then rm -rf $(@D); mkdir $(@D); fi
|
||||
endef
|
||||
|
||||
all: $(LIBRARY)
|
||||
|
||||
@@ -97,15 +97,17 @@ qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
#ifdef GCC_OPT_BUG
|
||||
volatile double df;
|
||||
#else
|
||||
double df;
|
||||
#endif
|
||||
double z,p,q,r,w,s,c;
|
||||
int hx,ix;
|
||||
u.d = x;
|
||||
hx = __HI(u);
|
||||
hx = __HI(x);
|
||||
ix = hx&0x7fffffff;
|
||||
if(ix>=0x3ff00000) { /* |x| >= 1 */
|
||||
if(((ix-0x3ff00000)|__LO(u))==0) { /* |x|==1 */
|
||||
if(((ix-0x3ff00000)|__LO(x))==0) { /* |x|==1 */
|
||||
if(hx>0) return 0.0; /* acos(1) = 0 */
|
||||
else return pi+2.0*pio2_lo; /* acos(-1)= pi */
|
||||
}
|
||||
@@ -129,9 +131,8 @@ qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
|
||||
} else { /* x > 0.5 */
|
||||
z = (one-x)*0.5;
|
||||
s = fd_sqrt(z);
|
||||
u.d = s;
|
||||
__LO(u) = 0;
|
||||
df = u.d;
|
||||
df = s;
|
||||
__LO(df) = 0;
|
||||
c = (z-df*df)/(s+df);
|
||||
p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
|
||||
q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
|
||||
|
||||
@@ -76,11 +76,9 @@ ln2 = 6.93147180559945286227e-01; /* 0x3FE62E42, 0xFEFA39EF */
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
double t;
|
||||
int hx;
|
||||
u.d = x;
|
||||
hx = __HI(u);
|
||||
hx = __HI(x);
|
||||
if(hx<0x3ff00000) { /* x < 1 */
|
||||
return (x-x)/(x-x);
|
||||
} else if(hx >=0x41b00000) { /* x > 2**28 */
|
||||
@@ -88,7 +86,7 @@ ln2 = 6.93147180559945286227e-01; /* 0x3FE62E42, 0xFEFA39EF */
|
||||
return x+x;
|
||||
} else
|
||||
return __ieee754_log(x)+ln2; /* acosh(huge)=log(2x) */
|
||||
} else if(((hx-0x3ff00000)|__LO(u))==0) {
|
||||
} else if(((hx-0x3ff00000)|__LO(x))==0) {
|
||||
return 0.0; /* acosh(1) = 0 */
|
||||
} else if (hx > 0x40000000) { /* 2**28 > x > 2 */
|
||||
t=x*x;
|
||||
|
||||
@@ -106,15 +106,17 @@ qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
double w,t,p,q,c,r,s;
|
||||
#ifdef GCC_OPT_BUG
|
||||
volatile double w;
|
||||
#else
|
||||
double w;
|
||||
#endif
|
||||
double t,p,q,c,r,s;
|
||||
int hx,ix;
|
||||
u.d = x;
|
||||
hx = __HI(u);
|
||||
x = u.d;
|
||||
hx = __HI(x);
|
||||
ix = hx&0x7fffffff;
|
||||
if(ix>= 0x3ff00000) { /* |x|>= 1 */
|
||||
if(((ix-0x3ff00000)|__LO(u))==0)
|
||||
if(((ix-0x3ff00000)|__LO(x))==0)
|
||||
/* asin(1)=+-pi/2 with inexact */
|
||||
return x*pio2_hi+x*pio2_lo;
|
||||
return (x-x)/(x-x); /* asin(|x|>1) is NaN */
|
||||
@@ -138,9 +140,8 @@ qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
|
||||
w = p/q;
|
||||
t = pio2_hi-(2.0*(s+s*w)-pio2_lo);
|
||||
} else {
|
||||
u.d = s;
|
||||
__LO(u) = 0;
|
||||
w = u.d;
|
||||
w = s;
|
||||
__LO(w) = 0;
|
||||
c = (t-w*w)/(s+w);
|
||||
r = p/q;
|
||||
p = 2.0*s*r-(pio2_lo-2.0*c);
|
||||
|
||||
@@ -93,16 +93,14 @@ pi_lo = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */
|
||||
double y,x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints ux, uy, uz;
|
||||
double z;
|
||||
int k,m,hx,hy,ix,iy;
|
||||
unsigned lx,ly;
|
||||
|
||||
ux.d = x; uy.d = y;
|
||||
hx = __HI(ux); ix = hx&0x7fffffff;
|
||||
lx = __LO(ux);
|
||||
hy = __HI(uy); iy = hy&0x7fffffff;
|
||||
ly = __LO(uy);
|
||||
hx = __HI(x); ix = hx&0x7fffffff;
|
||||
lx = __LO(x);
|
||||
hy = __HI(y); iy = hy&0x7fffffff;
|
||||
ly = __LO(y);
|
||||
if(((ix|((lx|-(int)lx)>>31))>0x7ff00000)||
|
||||
((iy|((ly|-(int)ly)>>31))>0x7ff00000)) /* x or y is NaN */
|
||||
return x+y;
|
||||
@@ -149,9 +147,7 @@ pi_lo = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */
|
||||
else z=fd_atan(fd_fabs(y/x)); /* safe to do y/x */
|
||||
switch (m) {
|
||||
case 0: return z ; /* atan(+,+) */
|
||||
case 1: uz.d = z;
|
||||
__HI(uz) ^= 0x80000000;
|
||||
z = uz.d;
|
||||
case 1: __HI(z) ^= 0x80000000;
|
||||
return z ; /* atan(-,+) */
|
||||
case 2: return pi-(z-pi_lo);/* atan(+,-) */
|
||||
default: /* case 3 */
|
||||
|
||||
@@ -83,19 +83,15 @@ static double zero = 0.0;
|
||||
double t;
|
||||
int hx,ix;
|
||||
unsigned lx;
|
||||
fd_twoints u;
|
||||
u.d = x;
|
||||
hx = __HI(u); /* high word */
|
||||
lx = __LO(u); /* low word */
|
||||
hx = __HI(x); /* high word */
|
||||
lx = __LO(x); /* low word */
|
||||
ix = hx&0x7fffffff;
|
||||
if ((ix|((lx|(-(int)lx))>>31))>0x3ff00000) /* |x|>1 */
|
||||
return (x-x)/(x-x);
|
||||
if(ix==0x3ff00000)
|
||||
return x/zero;
|
||||
if(ix<0x3e300000&&(really_big+x)>zero) return x; /* x<2**-28 */
|
||||
u.d = x;
|
||||
__HI(u) = ix; /* x <- |x| */
|
||||
x = u.d;
|
||||
__HI(x) = ix; /* x <- |x| */
|
||||
if(ix<0x3fe00000) { /* x < 0.5 */
|
||||
t = x+x;
|
||||
t = 0.5*fd_log1p(t+t*x/(one-x));
|
||||
|
||||
@@ -84,14 +84,12 @@ static double one = 1.0, half=0.5, really_big = 1.0e300;
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
double t,w;
|
||||
int ix;
|
||||
unsigned lx;
|
||||
|
||||
|
||||
/* High word of |x|. */
|
||||
u.d = x;
|
||||
ix = __HI(u);
|
||||
ix = __HI(x);
|
||||
ix &= 0x7fffffff;
|
||||
|
||||
/* x is INF or NaN */
|
||||
|
||||
@@ -139,21 +139,24 @@ P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
#ifdef GCC_OPT_BUG
|
||||
volatile int xsb;
|
||||
#else
|
||||
int xsb;
|
||||
#endif
|
||||
double y,hi,lo,c,t;
|
||||
int k, xsb;
|
||||
int k;
|
||||
unsigned hx;
|
||||
|
||||
u.d = x;
|
||||
hx = __HI(u); /* high word of x */
|
||||
hx = __HI(x); /* high word of x */
|
||||
xsb = (hx>>31)&1; /* sign bit of x */
|
||||
hx &= 0x7fffffff; /* high word of |x| */
|
||||
k = 0; /* prevent warning */
|
||||
|
||||
/* filter out non-finite argument */
|
||||
if(hx >= 0x40862E42) { /* if |x|>=709.78... */
|
||||
if(hx>=0x7ff00000) {
|
||||
u.d = x;
|
||||
if(((hx&0xfffff)|__LO(u))!=0)
|
||||
if(((hx&0xfffff)|__LO(x))!=0)
|
||||
return x+x; /* NaN */
|
||||
else return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */
|
||||
}
|
||||
@@ -176,7 +179,11 @@ P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */
|
||||
else if(hx < 0x3e300000) { /* when |x|<2**-28 */
|
||||
if(really_big+x>one) return one+x;/* trigger inexact */
|
||||
}
|
||||
else k = 0;
|
||||
else {
|
||||
k = 0;
|
||||
hi = 0; /* Unused when k = 0, but prevent warning. */
|
||||
lo = 0;
|
||||
}
|
||||
|
||||
/* x is now in primary range */
|
||||
t = x*x;
|
||||
@@ -184,14 +191,10 @@ P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */
|
||||
if(k==0) return one-((x*c)/(c-2.0)-x);
|
||||
else y = one-((lo-(x*c)/(2.0-c))-hi);
|
||||
if(k >= -1021) {
|
||||
u.d = y;
|
||||
__HI(u) += (k<<20); /* add k to y's exponent */
|
||||
y = u.d;
|
||||
__HI(y) += (k<<20); /* add k to y's exponent */
|
||||
return y;
|
||||
} else {
|
||||
u.d = y;
|
||||
__HI(u) += ((k+1000)<<20);/* add k to y's exponent */
|
||||
y = u.d;
|
||||
__HI(y) += ((k+1000)<<20);/* add k to y's exponent */
|
||||
return y*twom1000;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,15 +65,13 @@ static double one = 1.0, Zero[] = {0.0, -0.0,};
|
||||
double x,y ;
|
||||
#endif
|
||||
{
|
||||
fd_twoints ux, uy;
|
||||
int n,hx,hy,hz,ix,iy,sx,i;
|
||||
unsigned lx,ly,lz;
|
||||
|
||||
ux.d = x; uy.d = y;
|
||||
hx = __HI(ux); /* high word of x */
|
||||
lx = __LO(ux); /* low word of x */
|
||||
hy = __HI(uy); /* high word of y */
|
||||
ly = __LO(uy); /* low word of y */
|
||||
hx = __HI(x); /* high word of x */
|
||||
lx = __LO(x); /* low word of x */
|
||||
hy = __HI(y); /* high word of y */
|
||||
ly = __LO(y); /* low word of y */
|
||||
sx = hx&0x80000000; /* sign of x */
|
||||
hx ^=sx; /* |x| */
|
||||
hy &= 0x7fffffff; /* |y| */
|
||||
@@ -155,10 +153,8 @@ static double one = 1.0, Zero[] = {0.0, -0.0,};
|
||||
}
|
||||
if(iy>= -1022) { /* normalize output */
|
||||
hx = ((hx-0x00100000)|((iy+1023)<<20));
|
||||
ux.d = x;
|
||||
__HI(ux) = hx|sx;
|
||||
__LO(ux) = lx;
|
||||
x = ux.d;
|
||||
__HI(x) = hx|sx;
|
||||
__LO(x) = lx;
|
||||
} else { /* subnormal output */
|
||||
n = -1022 - iy;
|
||||
if(n<=20) {
|
||||
@@ -169,10 +165,8 @@ static double one = 1.0, Zero[] = {0.0, -0.0,};
|
||||
} else {
|
||||
lx = hx>>(n-32); hx = sx;
|
||||
}
|
||||
ux.d = x;
|
||||
__HI(ux) = hx|sx;
|
||||
__LO(ux) = lx;
|
||||
x = ux.d;
|
||||
__HI(x) = hx|sx;
|
||||
__LO(x) = lx;
|
||||
x *= one; /* create necessary signal */
|
||||
}
|
||||
return x; /* exact output */
|
||||
|
||||
@@ -85,43 +85,33 @@
|
||||
double x, y;
|
||||
#endif
|
||||
{
|
||||
fd_twoints ux, uy;
|
||||
double a=x,b=y,t1,t2,y1,y2,w;
|
||||
int j,k,ha,hb;
|
||||
|
||||
ux.d = x; uy.d = y;
|
||||
ha = __HI(ux)&0x7fffffff; /* high word of x */
|
||||
hb = __HI(uy)&0x7fffffff; /* high word of y */
|
||||
|
||||
ha = __HI(x)&0x7fffffff; /* high word of x */
|
||||
hb = __HI(y)&0x7fffffff; /* high word of y */
|
||||
if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;}
|
||||
ux.d = a; uy.d = b;
|
||||
__HI(ux) = ha; /* a <- |a| */
|
||||
__HI(uy) = hb; /* b <- |b| */
|
||||
a = ux.d; b = uy.d;
|
||||
__HI(a) = ha; /* a <- |a| */
|
||||
__HI(b) = hb; /* b <- |b| */
|
||||
if((ha-hb)>0x3c00000) {return a+b;} /* x/y > 2**60 */
|
||||
k=0;
|
||||
if(ha > 0x5f300000) { /* a>2**500 */
|
||||
if(ha >= 0x7ff00000) { /* Inf or NaN */
|
||||
w = a+b; /* for sNaN */
|
||||
ux.d = a; uy.d = b;
|
||||
if(((ha&0xfffff)|__LO(ux))==0) w = a;
|
||||
if(((hb^0x7ff00000)|__LO(uy))==0) w = b;
|
||||
if(((ha&0xfffff)|__LO(a))==0) w = a;
|
||||
if(((hb^0x7ff00000)|__LO(b))==0) w = b;
|
||||
return w;
|
||||
}
|
||||
/* scale a and b by 2**-600 */
|
||||
ha -= 0x25800000; hb -= 0x25800000; k += 600;
|
||||
ux.d = a; uy.d = b;
|
||||
__HI(ux) = ha;
|
||||
__HI(uy) = hb;
|
||||
a = ux.d; b = uy.d;
|
||||
__HI(a) = ha;
|
||||
__HI(b) = hb;
|
||||
}
|
||||
if(hb < 0x20b00000) { /* b < 2**-500 */
|
||||
if(hb <= 0x000fffff) { /* subnormal b or 0 */
|
||||
uy.d = b;
|
||||
if((hb|(__LO(uy)))==0) return a;
|
||||
if((hb|(__LO(b)))==0) return a;
|
||||
t1=0;
|
||||
ux.d = t1;
|
||||
__HI(ux) = 0x7fd00000; /* t1=2^1022 */
|
||||
t1 = ux.d;
|
||||
__HI(t1) = 0x7fd00000; /* t1=2^1022 */
|
||||
b *= t1;
|
||||
a *= t1;
|
||||
k -= 1022;
|
||||
@@ -129,40 +119,30 @@
|
||||
ha += 0x25800000; /* a *= 2^600 */
|
||||
hb += 0x25800000; /* b *= 2^600 */
|
||||
k -= 600;
|
||||
ux.d = a; uy.d = b;
|
||||
__HI(ux) = ha;
|
||||
__HI(uy) = hb;
|
||||
a = ux.d; b = uy.d;
|
||||
__HI(a) = ha;
|
||||
__HI(b) = hb;
|
||||
}
|
||||
}
|
||||
/* medium size a and b */
|
||||
w = a-b;
|
||||
if (w>b) {
|
||||
t1 = 0;
|
||||
ux.d = t1;
|
||||
__HI(ux) = ha;
|
||||
t1 = ux.d;
|
||||
__HI(t1) = ha;
|
||||
t2 = a-t1;
|
||||
w = fd_sqrt(t1*t1-(b*(-b)-t2*(a+t1)));
|
||||
} else {
|
||||
a = a+a;
|
||||
y1 = 0;
|
||||
ux.d = y1;
|
||||
__HI(ux) = hb;
|
||||
y1 = ux.d;
|
||||
__HI(y1) = hb;
|
||||
y2 = b - y1;
|
||||
t1 = 0;
|
||||
ux.d = t1;
|
||||
__HI(ux) = ha+0x00100000;
|
||||
t1 = ux.d;
|
||||
__HI(t1) = ha+0x00100000;
|
||||
t2 = a - t1;
|
||||
w = fd_sqrt(t1*y1-(w*(-w)-(t1*y2+t2*b)));
|
||||
}
|
||||
if(k!=0) {
|
||||
t1 = 1.0;
|
||||
ux.d = t1;
|
||||
__HI(ux) += (k<<20);
|
||||
t1 = ux.d;
|
||||
__HI(t1) += (k<<20);
|
||||
return t1*w;
|
||||
} else return w;
|
||||
}
|
||||
|
||||
@@ -125,12 +125,10 @@ static double zero = 0.0;
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints un;
|
||||
double z, s,c,ss,cc,r,u,v;
|
||||
int hx,ix;
|
||||
|
||||
un.d = x;
|
||||
hx = __HI(un);
|
||||
hx = __HI(x);
|
||||
ix = hx&0x7fffffff;
|
||||
if(ix>=0x7ff00000) return one/(x*x);
|
||||
x = fd_fabs(x);
|
||||
@@ -196,14 +194,12 @@ v04 = 4.41110311332675467403e-10; /* 0x3DFE5018, 0x3BD6D9EF */
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints un;
|
||||
double z, s,c,ss,cc,u,v;
|
||||
int hx,ix,lx;
|
||||
|
||||
un.d = x;
|
||||
hx = __HI(un);
|
||||
hx = __HI(x);
|
||||
ix = 0x7fffffff&hx;
|
||||
lx = __LO(un);
|
||||
lx = __LO(x);
|
||||
/* Y0(NaN) is NaN, y0(-inf) is Nan, y0(inf) is 0 */
|
||||
if(ix>=0x7ff00000) return one/(x+x*x);
|
||||
if((ix|lx)==0) return -one/zero;
|
||||
@@ -366,11 +362,9 @@ static double pS2[5] = {
|
||||
#else
|
||||
double *p,*q;
|
||||
#endif
|
||||
fd_twoints u;
|
||||
double z,r,s;
|
||||
int ix;
|
||||
u.d = x;
|
||||
ix = 0x7fffffff&__HI(u);
|
||||
ix = 0x7fffffff&__HI(x);
|
||||
if(ix>=0x40200000) {p = pR8; q= pS8;}
|
||||
else if(ix>=0x40122E8B){p = pR5; q= pS5;}
|
||||
else if(ix>=0x4006DB6D){p = pR3; q= pS3;}
|
||||
@@ -503,11 +497,9 @@ static double qS2[6] = {
|
||||
#else
|
||||
double *p,*q;
|
||||
#endif
|
||||
fd_twoints u;
|
||||
double s,r,z;
|
||||
int ix;
|
||||
u.d = x;
|
||||
ix = 0x7fffffff&__HI(u);
|
||||
ix = 0x7fffffff&__HI(x);
|
||||
if(ix>=0x40200000) {p = qR8; q= qS8;}
|
||||
else if(ix>=0x40122E8B){p = qR5; q= qS5;}
|
||||
else if(ix>=0x4006DB6D){p = qR3; q= qS3;}
|
||||
|
||||
@@ -126,12 +126,10 @@ static double zero = 0.0;
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints un;
|
||||
double z, s,c,ss,cc,r,u,v,y;
|
||||
int hx,ix;
|
||||
|
||||
un.d = x;
|
||||
hx = __HI(un);
|
||||
hx = __HI(x);
|
||||
ix = hx&0x7fffffff;
|
||||
if(ix>=0x7ff00000) return one/x;
|
||||
y = fd_fabs(x);
|
||||
@@ -197,14 +195,12 @@ static double V0[5] = {
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints un;
|
||||
double z, s,c,ss,cc,u,v;
|
||||
int hx,ix,lx;
|
||||
|
||||
un.d = x;
|
||||
hx = __HI(un);
|
||||
hx = __HI(x);
|
||||
ix = 0x7fffffff&hx;
|
||||
lx = __LO(un);
|
||||
lx = __LO(x);
|
||||
/* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */
|
||||
if(ix>=0x7ff00000) return one/(x+x*x);
|
||||
if((ix|lx)==0) return -one/zero;
|
||||
@@ -364,11 +360,9 @@ static double ps2[5] = {
|
||||
#else
|
||||
double *p,*q;
|
||||
#endif
|
||||
fd_twoints un;
|
||||
double z,r,s;
|
||||
int ix;
|
||||
un.d = x;
|
||||
ix = 0x7fffffff&__HI(un);
|
||||
ix = 0x7fffffff&__HI(x);
|
||||
if(ix>=0x40200000) {p = pr8; q= ps8;}
|
||||
else if(ix>=0x40122E8B){p = pr5; q= ps5;}
|
||||
else if(ix>=0x4006DB6D){p = pr3; q= ps3;}
|
||||
@@ -502,11 +496,9 @@ static double qs2[6] = {
|
||||
#else
|
||||
double *p,*q;
|
||||
#endif
|
||||
fd_twoints un;
|
||||
double s,r,z;
|
||||
int ix;
|
||||
un.d = x;
|
||||
ix = 0x7fffffff&__HI(un);
|
||||
ix = 0x7fffffff&__HI(x);
|
||||
if(ix>=0x40200000) {p = qr8; q= qs8;}
|
||||
else if(ix>=0x40122E8B){p = qr5; q= qs5;}
|
||||
else if(ix>=0x4006DB6D){p = qr3; q= qs3;}
|
||||
|
||||
@@ -90,7 +90,6 @@ static double zero = 0.00000000000000000000e+00;
|
||||
int n; double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
int i,hx,ix,lx, sgn;
|
||||
double a, b, temp, di;
|
||||
double z, w;
|
||||
@@ -98,10 +97,9 @@ static double zero = 0.00000000000000000000e+00;
|
||||
/* J(-n,x) = (-1)^n * J(n, x), J(n, -x) = (-1)^n * J(n, x)
|
||||
* Thus, J(-n,x) = J(n,-x)
|
||||
*/
|
||||
u.d = x;
|
||||
hx = __HI(u);
|
||||
hx = __HI(x);
|
||||
ix = 0x7fffffff&hx;
|
||||
lx = __LO(u);
|
||||
lx = __LO(x);
|
||||
/* if J(n,NaN) is NaN */
|
||||
if((ix|((unsigned)(lx|-lx))>>31)>0x7ff00000) return x+x;
|
||||
if(n<0){
|
||||
@@ -253,15 +251,13 @@ static double zero = 0.00000000000000000000e+00;
|
||||
int n; double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
int i,hx,ix,lx;
|
||||
int sign;
|
||||
double a, b, temp;
|
||||
|
||||
u.d = x;
|
||||
hx = __HI(u);
|
||||
hx = __HI(x);
|
||||
ix = 0x7fffffff&hx;
|
||||
lx = __LO(u);
|
||||
lx = __LO(x);
|
||||
/* if Y(n,NaN) is NaN */
|
||||
if((ix|((unsigned)(lx|-lx))>>31)>0x7ff00000) return x+x;
|
||||
if((ix|lx)==0) return -one/zero;
|
||||
@@ -299,8 +295,7 @@ static double zero = 0.00000000000000000000e+00;
|
||||
a = __ieee754_y0(x);
|
||||
b = __ieee754_y1(x);
|
||||
/* quit if b is -inf */
|
||||
u.d = b;
|
||||
for(i=1;i<n&&(__HI(u) != 0xfff00000);i++){
|
||||
for(i=1;i<n&&(__HI(b) != 0xfff00000);i++){
|
||||
temp = b;
|
||||
b = ((double)(i+i)/x)*b - a;
|
||||
a = temp;
|
||||
|
||||
@@ -195,12 +195,10 @@ static double zero= 0.00000000000000000000e+00;
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
double y,z;
|
||||
int n,ix;
|
||||
|
||||
u.d = x;
|
||||
ix = 0x7fffffff&__HI(u);
|
||||
ix = 0x7fffffff&__HI(x);
|
||||
|
||||
if(ix<0x3fd00000) return __kernel_sin(pi*x,zero,0);
|
||||
y = -x; /* x is assume negative */
|
||||
@@ -219,8 +217,7 @@ static double zero= 0.00000000000000000000e+00;
|
||||
y = zero; n = 0; /* y must be even */
|
||||
} else {
|
||||
if(ix<0x43300000) z = y+two52; /* exact */
|
||||
u.d = z;
|
||||
n = __LO(u)&1; /* lower word of z */
|
||||
n = __LO(z)&1; /* lower word of z */
|
||||
y = n;
|
||||
n<<= 2;
|
||||
}
|
||||
@@ -246,13 +243,11 @@ static double zero= 0.00000000000000000000e+00;
|
||||
double x; int *signgamp;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
double t,y,z,nadj,p,p1,p2,p3,q,r,w;
|
||||
int i,hx,lx,ix;
|
||||
|
||||
u.d = x;
|
||||
hx = __HI(u);
|
||||
lx = __LO(u);
|
||||
hx = __HI(x);
|
||||
lx = __LO(x);
|
||||
|
||||
/* purge off +-inf, NaN, +-0, and negative arguments */
|
||||
*signgamp = 1;
|
||||
|
||||
@@ -122,14 +122,12 @@ static double zero = 0.0;
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
double hfsq,f,s,z,R,w,t1,t2,dk;
|
||||
int k,hx,i,j;
|
||||
unsigned lx;
|
||||
|
||||
u.d = x;
|
||||
hx = __HI(u); /* high word of x */
|
||||
lx = __LO(u); /* low word of x */
|
||||
hx = __HI(x); /* high word of x */
|
||||
lx = __LO(x); /* low word of x */
|
||||
|
||||
k=0;
|
||||
if (hx < 0x00100000) { /* x < 2**-1022 */
|
||||
@@ -137,16 +135,13 @@ static double zero = 0.0;
|
||||
return -two54/zero; /* log(+-0)=-inf */
|
||||
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
|
||||
k -= 54; x *= two54; /* subnormal number, scale up x */
|
||||
u.d = x;
|
||||
hx = __HI(u); /* high word of x */
|
||||
hx = __HI(x); /* high word of x */
|
||||
}
|
||||
if (hx >= 0x7ff00000) return x+x;
|
||||
k += (hx>>20)-1023;
|
||||
hx &= 0x000fffff;
|
||||
i = (hx+0x95f64)&0x100000;
|
||||
u.d = x;
|
||||
__HI(u) = hx|(i^0x3ff00000); /* normalize x or x/2 */
|
||||
x = u.d;
|
||||
__HI(x) = hx|(i^0x3ff00000); /* normalize x or x/2 */
|
||||
k += (i>>20);
|
||||
f = x-1.0;
|
||||
if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */
|
||||
|
||||
@@ -98,14 +98,12 @@ static double zero = 0.0;
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
double y,z;
|
||||
int i,k,hx;
|
||||
unsigned lx;
|
||||
|
||||
u.d = x;
|
||||
hx = __HI(u); /* high word of x */
|
||||
lx = __LO(u); /* low word of x */
|
||||
hx = __HI(x); /* high word of x */
|
||||
lx = __LO(x); /* low word of x */
|
||||
|
||||
k=0;
|
||||
if (hx < 0x00100000) { /* x < 2**-1022 */
|
||||
@@ -113,17 +111,14 @@ static double zero = 0.0;
|
||||
return -two54/zero; /* log(+-0)=-inf */
|
||||
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
|
||||
k -= 54; x *= two54; /* subnormal number, scale up x */
|
||||
u.d = x;
|
||||
hx = __HI(u); /* high word of x */
|
||||
hx = __HI(x); /* high word of x */
|
||||
}
|
||||
if (hx >= 0x7ff00000) return x+x;
|
||||
k += (hx>>20)-1023;
|
||||
i = ((unsigned)k&0x80000000)>>31;
|
||||
hx = (hx&0x000fffff)|((0x3ff-i)<<20);
|
||||
y = (double)(k+i);
|
||||
u.d = x;
|
||||
__HI(u) = hx;
|
||||
x = u.d;
|
||||
__HI(x) = hx;
|
||||
z = y*log10_2lo + ivln10*__ieee754_log(x);
|
||||
return z+y*log10_2hi;
|
||||
}
|
||||
|
||||
@@ -135,17 +135,19 @@ ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
|
||||
double x, y;
|
||||
#endif
|
||||
{
|
||||
fd_twoints ux, uy, uz;
|
||||
#ifdef GCC_OPT_BUG
|
||||
volatile double y1,t1,p_h,t,z,ax;
|
||||
#else
|
||||
double y1,t1,p_h,t,z,ax;
|
||||
#endif
|
||||
double z_h,z_l,p_l;
|
||||
double t2,r,s,u,v,w;
|
||||
int i,j,k,yisint,n;
|
||||
int hx,hy,ix,iy;
|
||||
unsigned lx,ly;
|
||||
|
||||
ux.d = x; uy.d = y;
|
||||
hx = __HI(ux); lx = __LO(ux);
|
||||
hy = __HI(uy); ly = __LO(uy);
|
||||
hx = __HI(x); lx = __LO(x);
|
||||
hy = __HI(y); ly = __LO(y);
|
||||
ix = hx&0x7fffffff; iy = hy&0x7fffffff;
|
||||
|
||||
/* y==zero: x**0 = 1 */
|
||||
@@ -212,9 +214,7 @@ ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
|
||||
z = (z-z)/(z-z); /* (-1)**non-int is NaN */
|
||||
} else if(yisint==1) {
|
||||
#ifdef HPUX
|
||||
uz.d = z;
|
||||
__HI(uz) ^= 1<<31; /* some HPUXes cannot negate 0.. */
|
||||
z = uz.d;
|
||||
__HI(z) ^= 1<<31; /* some HPUXes cannot negate 0.. */
|
||||
#else
|
||||
z = -z; /* (x<0)**odd = -(|x|**odd) */
|
||||
#endif
|
||||
@@ -243,17 +243,19 @@ ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
|
||||
u = ivln2_h*t; /* ivln2_h has 21 sig. bits */
|
||||
v = t*ivln2_l-w*ivln2;
|
||||
t1 = u+v;
|
||||
uz.d = t1;
|
||||
__LO(uz) = 0;
|
||||
t1 = uz.d;
|
||||
__LO(t1) = 0;
|
||||
t2 = v-(t1-u);
|
||||
} else {
|
||||
#ifdef GCC_OPT_BUG
|
||||
volatile double s_h,t_h;
|
||||
#else
|
||||
double s_h,t_h;
|
||||
#endif
|
||||
double s2,s_l,t_l;
|
||||
n = 0;
|
||||
/* take care subnormal number */
|
||||
if(ix<0x00100000)
|
||||
{ax *= two53; n -= 53; uz.d = ax; ix = __HI(uz); }
|
||||
if(ix<0x00100000)
|
||||
{ax *= two53; n -= 53; ix = __HI(ax); }
|
||||
n += ((ix)>>20)-0x3ff;
|
||||
j = ix&0x000fffff;
|
||||
/* determine interval */
|
||||
@@ -261,23 +263,17 @@ ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
|
||||
if(j<=0x3988E) k=0; /* |x|<sqrt(3/2) */
|
||||
else if(j<0xBB67A) k=1; /* |x|<sqrt(3) */
|
||||
else {k=0;n+=1;ix -= 0x00100000;}
|
||||
uz.d = ax;
|
||||
__HI(uz) = ix;
|
||||
ax = uz.d;
|
||||
__HI(ax) = ix;
|
||||
|
||||
/* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
|
||||
u = ax-bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
|
||||
v = one/(ax+bp[k]);
|
||||
s = u*v;
|
||||
s_h = s;
|
||||
uz.d = s_h;
|
||||
__LO(uz) = 0;
|
||||
s_h = uz.d;
|
||||
__LO(s_h) = 0;
|
||||
/* t_h=ax+bp[k] High */
|
||||
t_h = zero;
|
||||
uz.d = t_h;
|
||||
__HI(uz)=((ix>>1)|0x20000000)+0x00080000+(k<<18);
|
||||
t_h = uz.d;
|
||||
__HI(t_h)=((ix>>1)|0x20000000)+0x00080000+(k<<18);
|
||||
t_l = ax - (t_h-bp[k]);
|
||||
s_l = v*((u-s_h*t_h)-s_h*t_l);
|
||||
/* compute log(ax) */
|
||||
@@ -286,27 +282,21 @@ ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
|
||||
r += s_l*(s_h+s);
|
||||
s2 = s_h*s_h;
|
||||
t_h = 3.0+s2+r;
|
||||
uz.d = t_h;
|
||||
__LO(uz) = 0;
|
||||
t_h = uz.d;
|
||||
__LO(t_h) = 0;
|
||||
t_l = r-((t_h-3.0)-s2);
|
||||
/* u+v = s*(1+...) */
|
||||
u = s_h*t_h;
|
||||
v = s_l*t_h+t_l*s;
|
||||
/* 2/(3log2)*(s+...) */
|
||||
p_h = u+v;
|
||||
uz.d = p_h;
|
||||
__LO(uz) = 0;
|
||||
p_h = uz.d;
|
||||
__LO(p_h) = 0;
|
||||
p_l = v-(p_h-u);
|
||||
z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */
|
||||
z_l = cp_l*p_h+p_l*cp+dp_l[k];
|
||||
/* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */
|
||||
t = (double)n;
|
||||
t1 = (((z_h+z_l)+dp_h[k])+t);
|
||||
uz.d = t1;
|
||||
__LO(uz) = 0;
|
||||
t1 = uz.d;
|
||||
__LO(t1) = 0;
|
||||
t2 = z_l-(((t1-t)-dp_h[k])-z_h);
|
||||
}
|
||||
|
||||
@@ -315,15 +305,12 @@ ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
|
||||
|
||||
/* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */
|
||||
y1 = y;
|
||||
uy.d = y1;
|
||||
__LO(uy) = 0;
|
||||
y1 = uy.d;
|
||||
__LO(y1) = 0;
|
||||
p_l = (y-y1)*t1+y*t2;
|
||||
p_h = y1*t1;
|
||||
z = p_l+p_h;
|
||||
uz.d = z;
|
||||
j = __HI(uz);
|
||||
i = __LO(uz);
|
||||
j = __HI(z);
|
||||
i = __LO(z);
|
||||
|
||||
if (j>=0x40900000) { /* z >= 1024 */
|
||||
if(((j-0x40900000)|i)!=0) /* if z > 1024 */
|
||||
@@ -348,17 +335,13 @@ ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
|
||||
n = j+(0x00100000>>(k+1));
|
||||
k = ((n&0x7fffffff)>>20)-0x3ff; /* new k for n */
|
||||
t = zero;
|
||||
uz.d = t;
|
||||
__HI(uz) = (n&~(0x000fffff>>k));
|
||||
t = uz.d;
|
||||
__HI(t) = (n&~(0x000fffff>>k));
|
||||
n = ((n&0x000fffff)|0x00100000)>>(20-k);
|
||||
if(j<0) n = -n;
|
||||
p_h -= t;
|
||||
}
|
||||
t = p_l+p_h;
|
||||
uz.d = t;
|
||||
__LO(uz) = 0;
|
||||
t = uz.d;
|
||||
__LO(t) = 0;
|
||||
u = t*lg2_h;
|
||||
v = (p_l-(t-p_h))*lg2+t*lg2_l;
|
||||
z = u+v;
|
||||
@@ -367,10 +350,9 @@ ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
|
||||
t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
|
||||
r = (z*t1)/(t1-two)-(w+z*w);
|
||||
z = one-(r-z);
|
||||
uz.d = z;
|
||||
j = __HI(uz);
|
||||
j = __HI(z);
|
||||
j += (n<<20);
|
||||
if((j>>20)<=0) z = fd_scalbn(z,n); /* subnormal output */
|
||||
else { uz.d = z; __HI(uz) += (n<<20); z = uz.d; }
|
||||
else __HI(z) += (n<<20);
|
||||
return s*z;
|
||||
}
|
||||
|
||||
@@ -120,13 +120,11 @@ pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */
|
||||
double x,y[];
|
||||
#endif
|
||||
{
|
||||
fd_twoints u, ux, uz;
|
||||
double z,w,t,r,fn;
|
||||
double tx[3];
|
||||
int e0,i,j,nx,n,ix,hx;
|
||||
|
||||
u.d = x;
|
||||
hx = __HI(u); /* high word of x */
|
||||
hx = __HI(x); /* high word of x */
|
||||
ix = hx&0x7fffffff;
|
||||
if(ix<=0x3fe921fb) /* |x| ~<= pi/4 , no need for reduction */
|
||||
{y[0] = x; y[1] = 0; return 0;}
|
||||
@@ -165,17 +163,15 @@ pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */
|
||||
y[0] = r-w; /* quick check no cancellation */
|
||||
} else {
|
||||
j = ix>>20;
|
||||
y[0] = r-w;
|
||||
u.d = y[0];
|
||||
i = j-(((__HI(u))>>20)&0x7ff);
|
||||
y[0] = r-w;
|
||||
i = j-(((__HI(y[0]))>>20)&0x7ff);
|
||||
if(i>16) { /* 2nd iteration needed, good to 118 */
|
||||
t = r;
|
||||
w = fn*pio2_2;
|
||||
r = t-w;
|
||||
w = fn*pio2_2t-((t-r)-w);
|
||||
y[0] = r-w;
|
||||
u.d = y[0];
|
||||
i = j-(((__HI(u))>>20)&0x7ff);
|
||||
i = j-(((__HI(y[0]))>>20)&0x7ff);
|
||||
if(i>49) { /* 3rd iteration need, 151 bits acc */
|
||||
t = r; /* will cover all possible cases */
|
||||
w = fn*pio2_3;
|
||||
@@ -196,13 +192,9 @@ pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */
|
||||
y[0]=y[1]=x-x; return 0;
|
||||
}
|
||||
/* set z = scalbn(|x|,ilogb(x)-23) */
|
||||
ux.d = x; uz.d = z;
|
||||
__LO(uz) = __LO(ux);
|
||||
z = uz.d;
|
||||
__LO(z) = __LO(x);
|
||||
e0 = (ix>>20)-1046; /* e0 = ilogb(z)-23; */
|
||||
uz.d = z;
|
||||
__HI(uz) = ix - (e0<<20);
|
||||
z = uz.d;
|
||||
__HI(z) = ix - (e0<<20);
|
||||
for(i=0;i<2;i++) {
|
||||
tx[i] = (double)((int)(z));
|
||||
z = (z-tx[i])*two24;
|
||||
|
||||
@@ -69,17 +69,14 @@ static double zero = 0.0;
|
||||
double x,p;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
int hx,hp;
|
||||
unsigned sx,lx,lp;
|
||||
double p_half;
|
||||
|
||||
u.d = x;
|
||||
hx = __HI(u); /* high word of x */
|
||||
lx = __LO(u); /* low word of x */
|
||||
u.d = p;
|
||||
hp = __HI(u); /* high word of p */
|
||||
lp = __LO(u); /* low word of p */
|
||||
hx = __HI(x); /* high word of x */
|
||||
lx = __LO(x); /* low word of x */
|
||||
hp = __HI(p); /* high word of p */
|
||||
lp = __LO(p); /* low word of p */
|
||||
sx = hx&0x80000000;
|
||||
hp &= 0x7fffffff;
|
||||
hx &= 0x7fffffff;
|
||||
@@ -108,8 +105,6 @@ static double zero = 0.0;
|
||||
if(x>=p_half) x -= p;
|
||||
}
|
||||
}
|
||||
u.d = x;
|
||||
__HI(u) ^= sx;
|
||||
x = u.d;
|
||||
__HI(x) ^= sx;
|
||||
return x;
|
||||
}
|
||||
|
||||
@@ -77,14 +77,12 @@ static double one = 1.0, shuge = 1.0e307;
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
double t,w,h;
|
||||
int ix,jx;
|
||||
unsigned lx;
|
||||
|
||||
/* High word of |x|. */
|
||||
u.d = x;
|
||||
jx = __HI(u);
|
||||
jx = __HI(x);
|
||||
ix = jx&0x7fffffff;
|
||||
|
||||
/* x is INF or NaN */
|
||||
|
||||
@@ -128,15 +128,13 @@ static double one = 1.0, tiny=1.0e-300;
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
double z;
|
||||
int sign = (int)0x80000000;
|
||||
unsigned r,t1,s1,ix1,q1;
|
||||
int ix0,s0,q,m,t,i;
|
||||
|
||||
u.d = x;
|
||||
ix0 = __HI(u); /* high word of x */
|
||||
ix1 = __LO(u); /* low word of x */
|
||||
ix0 = __HI(x); /* high word of x */
|
||||
ix1 = __LO(x); /* low word of x */
|
||||
|
||||
/* take care of Inf and NaN */
|
||||
if((ix0&0x7ff00000)==0x7ff00000) {
|
||||
@@ -221,10 +219,8 @@ static double one = 1.0, tiny=1.0e-300;
|
||||
ix1 = q1>>1;
|
||||
if ((q&1)==1) ix1 |= sign;
|
||||
ix0 += (m <<20);
|
||||
u.d = z;
|
||||
__HI(u) = ix0;
|
||||
__LO(u) = ix1;
|
||||
z = u.d;
|
||||
__HI(z) = ix0;
|
||||
__LO(z) = ix1;
|
||||
return z;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,18 +45,12 @@
|
||||
*/
|
||||
|
||||
/* Modified defines start here.. */
|
||||
#undef __LITTLE_ENDIAN
|
||||
|
||||
#ifdef _WIN32
|
||||
#define huge myhuge
|
||||
#define __LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
#ifdef XP_OS2
|
||||
#define __LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
#if defined(linux) && defined(__i386__)
|
||||
#ifdef X86_LINUX
|
||||
#define __LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
@@ -69,19 +63,19 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef union {
|
||||
|
||||
#ifdef __LITTLE_ENDIAN
|
||||
struct { int lo, hi; } ints;
|
||||
#define __HI(x) *(1+(int*)&x)
|
||||
#define __LO(x) *(int*)&x
|
||||
#define __HIp(x) *(1+(int*)x)
|
||||
#define __LOp(x) *(int*)x
|
||||
#else
|
||||
struct { int hi, lo; } ints;
|
||||
#define __HI(x) *(int*)&x
|
||||
#define __LO(x) *(1+(int*)&x)
|
||||
#define __HIp(x) *(int*)x
|
||||
#define __LOp(x) *(1+(int*)x)
|
||||
#endif
|
||||
double d;
|
||||
} fd_twoints;
|
||||
|
||||
#define __HI(x) x.ints.hi
|
||||
#define __LO(x) x.ints.lo
|
||||
|
||||
#undef __P
|
||||
#ifdef __STDC__
|
||||
#define __P(p) p
|
||||
#else
|
||||
|
||||
@@ -101,11 +101,9 @@ C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */
|
||||
double x,y;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
double a,hz,z,r,qx;
|
||||
int ix;
|
||||
u.d = x;
|
||||
ix = __HI(u)&0x7fffffff; /* ix = |x|'s high word*/
|
||||
ix = __HI(x)&0x7fffffff; /* ix = |x|'s high word*/
|
||||
if(ix<0x3e400000) { /* if x < 2**27 */
|
||||
if(((int)x)==0) return one; /* generate inexact */
|
||||
}
|
||||
@@ -117,10 +115,8 @@ C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */
|
||||
if(ix > 0x3fe90000) { /* x > 0.78125 */
|
||||
qx = 0.28125;
|
||||
} else {
|
||||
u.d = qx;
|
||||
__HI(u) = ix-0x00200000; /* x/4 */
|
||||
__LO(u) = 0;
|
||||
qx = u.d;
|
||||
__HI(qx) = ix-0x00200000; /* x/4 */
|
||||
__LO(qx) = 0;
|
||||
}
|
||||
hz = 0.5*z-qx;
|
||||
a = one-qx;
|
||||
|
||||
@@ -94,11 +94,9 @@ S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */
|
||||
double x,y; int iy; /* iy=0 if y is zero */
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
double z,r,v;
|
||||
int ix;
|
||||
u.d = x;
|
||||
ix = __HI(u)&0x7fffffff; /* high word of x */
|
||||
ix = __HI(x)&0x7fffffff; /* high word of x */
|
||||
if(ix<0x3e400000) /* |x| < 2**-27 */
|
||||
{if((int)x==0) return x;} /* generate inexact */
|
||||
z = x*x;
|
||||
|
||||
@@ -127,11 +127,8 @@ static double zero = 0.0; /* used as const */
|
||||
#ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */
|
||||
#define HUGE_VAL inf
|
||||
double inf = 0.0;
|
||||
fd_twoints u;
|
||||
|
||||
u.d = inf;
|
||||
__HI(u) = 0x7ff00000; /* set inf to infinite */
|
||||
inf = u.d;
|
||||
__HI(inf) = 0x7ff00000; /* set inf to infinite */
|
||||
#endif
|
||||
|
||||
#ifdef _USE_WRITE
|
||||
|
||||
@@ -110,16 +110,13 @@ T[] = {
|
||||
double x,y; int iy;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
double z,r,v,w,s;
|
||||
int ix,hx;
|
||||
u.d = x;
|
||||
hx = __HI(u); /* high word of x */
|
||||
hx = __HI(x); /* high word of x */
|
||||
ix = hx&0x7fffffff; /* high word of |x| */
|
||||
if(ix<0x3e300000) /* x < 2**-28 */
|
||||
{if((int)x==0) { /* generate inexact */
|
||||
u.d =x;
|
||||
if(((ix|__LO(u))|(iy+1))==0) return one/fd_fabs(x);
|
||||
if(((ix|__LO(x))|(iy+1))==0) return one/fd_fabs(x);
|
||||
else return (iy==1)? x: -one/x;
|
||||
}
|
||||
}
|
||||
@@ -151,14 +148,10 @@ T[] = {
|
||||
/* compute -1.0/(x+r) accurately */
|
||||
double a,t;
|
||||
z = w;
|
||||
u.d = z;
|
||||
__LO(u) = 0;
|
||||
z = u.d;
|
||||
__LO(z) = 0;
|
||||
v = r-(z - x); /* z+v = r+x */
|
||||
t = a = -1.0/w; /* a = -1.0/w */
|
||||
u.d = t;
|
||||
__LO(u) = 0;
|
||||
t = u.d;
|
||||
__LO(t) = 0;
|
||||
s = 1.0+t*z;
|
||||
return t+a*(s+t*v);
|
||||
}
|
||||
|
||||
@@ -73,11 +73,9 @@ really_big= 1.00000000000000000000e+300;
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
double t,w;
|
||||
int hx,ix;
|
||||
u.d = x;
|
||||
hx = __HI(u);
|
||||
hx = __HI(x);
|
||||
ix = hx&0x7fffffff;
|
||||
if(ix>=0x7ff00000) return x+x; /* x is inf or NaN */
|
||||
if(ix< 0x3e300000) { /* |x|<2**-28 */
|
||||
|
||||
@@ -122,17 +122,14 @@ really_big = 1.0e300;
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
double w,s1,s2,z;
|
||||
int ix,hx,id;
|
||||
|
||||
u.d = x;
|
||||
hx = __HI(u);
|
||||
hx = __HI(x);
|
||||
ix = hx&0x7fffffff;
|
||||
if(ix>=0x44100000) { /* if |x| >= 2^66 */
|
||||
u.d = x;
|
||||
if(ix>0x7ff00000||
|
||||
(ix==0x7ff00000&&(__LO(u)!=0)))
|
||||
(ix==0x7ff00000&&(__LO(x)!=0)))
|
||||
return x+x; /* NaN */
|
||||
if(hx>0) return atanhi[3]+atanlo[3];
|
||||
else return -atanhi[3]-atanlo[3];
|
||||
|
||||
@@ -76,31 +76,26 @@ G = 3.57142857142857150787e-01; /* 5/14 = 0x3FD6DB6D, 0xB6DB6DB7 */
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
int hx;
|
||||
double r,s,t=0.0,w;
|
||||
unsigned sign;
|
||||
|
||||
u.d = x;
|
||||
hx = __HI(u); /* high word of x */
|
||||
|
||||
hx = __HI(x); /* high word of x */
|
||||
sign=hx&0x80000000; /* sign= sign(x) */
|
||||
hx ^=sign;
|
||||
if(hx>=0x7ff00000) return(x+x); /* cbrt(NaN,INF) is itself */
|
||||
if((hx|__LO(u))==0) {
|
||||
x = u.d;
|
||||
if((hx|__LO(x))==0)
|
||||
return(x); /* cbrt(0) is itself */
|
||||
}
|
||||
u.d = x;
|
||||
__HI(u) = hx; /* x <- |x| */
|
||||
x = u.d;
|
||||
|
||||
__HI(x) = hx; /* x <- |x| */
|
||||
/* rough cbrt to 5 bits */
|
||||
if(hx<0x00100000) /* subnormal number */
|
||||
{u.d = t; __HI(u)=0x43500000; t=u.d; /* set t= 2**54 */
|
||||
t*=x; __HI(u)=__HI(u)/3+B2;
|
||||
{__HI(t)=0x43500000; /* set t= 2**54 */
|
||||
t*=x; __HI(t)=__HI(t)/3+B2;
|
||||
}
|
||||
else {
|
||||
u.d = t; __HI(u)=hx/3+B1; t = u.d;
|
||||
}
|
||||
else
|
||||
__HI(t)=hx/3+B1;
|
||||
|
||||
|
||||
/* new cbrt to 23 bits, may be implemented in single precision */
|
||||
@@ -109,9 +104,8 @@ G = 3.57142857142857150787e-01; /* 5/14 = 0x3FD6DB6D, 0xB6DB6DB7 */
|
||||
t*=G+F/(s+E+D/s);
|
||||
|
||||
/* chopped to 20 bits and make it larger than cbrt(x) */
|
||||
u.d = t;
|
||||
__LO(u)=0; __HI(u)+=0x00000001;
|
||||
t = u.d;
|
||||
__LO(t)=0; __HI(t)+=0x00000001;
|
||||
|
||||
|
||||
/* one step newton iteration to 53 bits with error less than 0.667 ulps */
|
||||
s=t*t; /* t*t is exact */
|
||||
@@ -121,8 +115,6 @@ G = 3.57142857142857150787e-01; /* 5/14 = 0x3FD6DB6D, 0xB6DB6DB7 */
|
||||
t=t+t*r;
|
||||
|
||||
/* retore the sign bit */
|
||||
u.d = t;
|
||||
__HI(u) |= sign;
|
||||
t = u.d;
|
||||
__HI(t) |= sign;
|
||||
return(t);
|
||||
}
|
||||
|
||||
@@ -68,12 +68,10 @@ static double really_big = 1.0e300;
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
int i0,i1,j0;
|
||||
unsigned i,j;
|
||||
u.d = x;
|
||||
i0 = __HI(u);
|
||||
i1 = __LO(u);
|
||||
i0 = __HI(x);
|
||||
i1 = __LO(x);
|
||||
j0 = ((i0>>20)&0x7ff)-0x3ff;
|
||||
if(j0<20) {
|
||||
if(j0<0) { /* raise inexact if x != 0 */
|
||||
@@ -107,9 +105,7 @@ static double really_big = 1.0e300;
|
||||
i1 &= (~i);
|
||||
}
|
||||
}
|
||||
u.d = x;
|
||||
__HI(u) = i0;
|
||||
__LO(u) = i1;
|
||||
x = u.d;
|
||||
__HI(x) = i0;
|
||||
__LO(x) = i1;
|
||||
return x;
|
||||
}
|
||||
|
||||
@@ -59,9 +59,6 @@
|
||||
double x,y;
|
||||
#endif
|
||||
{
|
||||
fd_twoints ux, uy;
|
||||
ux.d = x; uy.d = y;
|
||||
__HI(ux) = (__HI(ux)&0x7fffffff)|(__HI(uy)&0x80000000);
|
||||
x = ux.d;
|
||||
__HI(x) = (__HI(x)&0x7fffffff)|(__HI(y)&0x80000000);
|
||||
return x;
|
||||
}
|
||||
|
||||
@@ -84,13 +84,11 @@
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
double y[2],z=0.0;
|
||||
int n, ix;
|
||||
|
||||
/* High word of x. */
|
||||
u.d = x;
|
||||
ix = __HI(u);
|
||||
ix = __HI(x);
|
||||
|
||||
/* |x| ~< pi/4 */
|
||||
ix &= 0x7fffffff;
|
||||
|
||||
@@ -227,11 +227,9 @@ sb7 = -2.24409524465858183362e+01; /* 0xC03670E2, 0x42712D62 */
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
int hx,ix,i;
|
||||
double R,S,P,Q,s,y,z,r;
|
||||
u.d = x;
|
||||
hx = __HI(u);
|
||||
hx = __HI(x);
|
||||
ix = hx&0x7fffffff;
|
||||
if(ix>=0x7ff00000) { /* erf(nan)=nan */
|
||||
i = ((unsigned)hx>>31)<<1;
|
||||
@@ -273,9 +271,7 @@ sb7 = -2.24409524465858183362e+01; /* 0xC03670E2, 0x42712D62 */
|
||||
sb5+s*(sb6+s*sb7))))));
|
||||
}
|
||||
z = x;
|
||||
u.d = z;
|
||||
__LO(u) = 0;
|
||||
z = u.d;
|
||||
__LO(z) = 0;
|
||||
r = __ieee754_exp(-z*z-0.5625)*__ieee754_exp((z-x)*(z+x)+R/S);
|
||||
if(hx>=0) return one-r/x; else return r/x-one;
|
||||
}
|
||||
@@ -287,11 +283,9 @@ sb7 = -2.24409524465858183362e+01; /* 0xC03670E2, 0x42712D62 */
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
int hx,ix;
|
||||
double R,S,P,Q,s,y,z,r;
|
||||
u.d = x;
|
||||
hx = __HI(u);
|
||||
hx = __HI(x);
|
||||
ix = hx&0x7fffffff;
|
||||
if(ix>=0x7ff00000) { /* erfc(nan)=nan */
|
||||
/* erfc(+-inf)=0,2 */
|
||||
@@ -339,9 +333,7 @@ sb7 = -2.24409524465858183362e+01; /* 0xC03670E2, 0x42712D62 */
|
||||
sb5+s*(sb6+s*sb7))))));
|
||||
}
|
||||
z = x;
|
||||
u.d = z;
|
||||
__LO(u) = 0;
|
||||
z = u.d;
|
||||
__LO(z) = 0;
|
||||
r = __ieee754_exp(-z*z-0.5625)*
|
||||
__ieee754_exp((z-x)*(z+x)+R/S);
|
||||
if(hx>0) return r/x; else return two-r/x;
|
||||
|
||||
@@ -167,13 +167,11 @@ Q5 = -2.01099218183624371326e-07; /* BE8AFDB7 6E09C32D */
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
double y,hi,lo,c,t,e,hxs,hfx,r1;
|
||||
int k,xsb;
|
||||
unsigned hx;
|
||||
|
||||
u.d = x;
|
||||
hx = __HI(u); /* high word of x */
|
||||
hx = __HI(x); /* high word of x */
|
||||
xsb = hx&0x80000000; /* sign bit of x */
|
||||
if(xsb==0) y=x; else y= -x; /* y = |x| */
|
||||
hx &= 0x7fffffff; /* high word of |x| */
|
||||
@@ -182,8 +180,7 @@ Q5 = -2.01099218183624371326e-07; /* BE8AFDB7 6E09C32D */
|
||||
if(hx >= 0x4043687A) { /* if |x|>=56*ln2 */
|
||||
if(hx >= 0x40862E42) { /* if |x|>=709.78... */
|
||||
if(hx>=0x7ff00000) {
|
||||
u.d = x;
|
||||
if(((hx&0xfffff)|__LO(u))!=0)
|
||||
if(((hx&0xfffff)|__LO(x))!=0)
|
||||
return x+x; /* NaN */
|
||||
else return (xsb==0)? x:-1.0;/* exp(+-inf)={inf,-1} */
|
||||
}
|
||||
@@ -233,29 +230,19 @@ Q5 = -2.01099218183624371326e-07; /* BE8AFDB7 6E09C32D */
|
||||
else return one+2.0*(x-e);
|
||||
if (k <= -2 || k>56) { /* suffice to return exp(x)-1 */
|
||||
y = one-(e-x);
|
||||
u.d = y;
|
||||
__HI(u) += (k<<20); /* add k to y's exponent */
|
||||
y = u.d;
|
||||
__HI(y) += (k<<20); /* add k to y's exponent */
|
||||
return y-one;
|
||||
}
|
||||
t = one;
|
||||
if(k<20) {
|
||||
u.d = t;
|
||||
__HI(u) = 0x3ff00000 - (0x200000>>k); /* t=1-2^-k */
|
||||
t = u.d;
|
||||
__HI(t) = 0x3ff00000 - (0x200000>>k); /* t=1-2^-k */
|
||||
y = t-(e-x);
|
||||
u.d = y;
|
||||
__HI(u) += (k<<20); /* add k to y's exponent */
|
||||
y = u.d;
|
||||
__HI(y) += (k<<20); /* add k to y's exponent */
|
||||
} else {
|
||||
u.d = t;
|
||||
__HI(u) = ((0x3ff-k)<<20); /* 2^-k */
|
||||
t = u.d;
|
||||
__HI(t) = ((0x3ff-k)<<20); /* 2^-k */
|
||||
y = x-(e+t);
|
||||
y += one;
|
||||
u.d = y;
|
||||
__HI(u) += (k<<20); /* add k to y's exponent */
|
||||
y = u.d;
|
||||
__HI(y) += (k<<20); /* add k to y's exponent */
|
||||
}
|
||||
}
|
||||
return y;
|
||||
|
||||
@@ -57,9 +57,6 @@
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
u.d = x;
|
||||
__HI(u) &= 0x7fffffff;
|
||||
x = u.d;
|
||||
__HI(x) &= 0x7fffffff;
|
||||
return x;
|
||||
}
|
||||
|
||||
@@ -58,9 +58,7 @@
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
int hx;
|
||||
u.d = x;
|
||||
hx = __HI(u);
|
||||
hx = __HI(x);
|
||||
return (unsigned)((hx&0x7fffffff)-0x7ff00000)>>31;
|
||||
}
|
||||
|
||||
@@ -68,12 +68,10 @@ static double really_big = 1.0e300;
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
int i0,i1,j0;
|
||||
unsigned i,j;
|
||||
u.d = x;
|
||||
i0 = __HI(u);
|
||||
i1 = __LO(u);
|
||||
i0 = __HI(x);
|
||||
i1 = __LO(x);
|
||||
j0 = ((i0>>20)&0x7ff)-0x3ff;
|
||||
if(j0<20) {
|
||||
if(j0<0) { /* raise inexact if x != 0 */
|
||||
@@ -108,9 +106,7 @@ static double really_big = 1.0e300;
|
||||
i1 &= (~i);
|
||||
}
|
||||
}
|
||||
u.d = x;
|
||||
__HI(u) = i0;
|
||||
__LO(u) = i1;
|
||||
x = u.d;
|
||||
__HI(x) = i0;
|
||||
__LO(x) = i1;
|
||||
return x;
|
||||
}
|
||||
|
||||
@@ -71,24 +71,19 @@ two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
|
||||
#endif
|
||||
{
|
||||
int hx, ix, lx;
|
||||
fd_twoints u;
|
||||
u.d = x;
|
||||
hx = __HI(u);
|
||||
hx = __HI(x);
|
||||
ix = 0x7fffffff&hx;
|
||||
lx = __LO(u);
|
||||
lx = __LO(x);
|
||||
*eptr = 0;
|
||||
if(ix>=0x7ff00000||((ix|lx)==0)) return x; /* 0,inf,nan */
|
||||
if (ix<0x00100000) { /* subnormal */
|
||||
x *= two54;
|
||||
u.d = x;
|
||||
hx = __HI(u);
|
||||
hx = __HI(x);
|
||||
ix = hx&0x7fffffff;
|
||||
*eptr = -54;
|
||||
}
|
||||
*eptr += (ix>>20)-1022;
|
||||
hx = (hx&0x800fffff)|0x3fe00000;
|
||||
u.d = x;
|
||||
__HI(u) = hx;
|
||||
x = u.d;
|
||||
__HI(x) = hx;
|
||||
return x;
|
||||
}
|
||||
|
||||
@@ -60,11 +60,10 @@
|
||||
#endif
|
||||
{
|
||||
int hx,lx,ix;
|
||||
fd_twoints u;
|
||||
u.d = x;
|
||||
hx = (__HI(u))&0x7fffffff; /* high word of x */
|
||||
|
||||
hx = (__HI(x))&0x7fffffff; /* high word of x */
|
||||
if(hx<0x00100000) {
|
||||
lx = __LO(u);
|
||||
lx = __LO(x);
|
||||
if((hx|lx)==0)
|
||||
return 0x80000001; /* ilogb(0) = 0x80000001 */
|
||||
else /* subnormal x */
|
||||
|
||||
@@ -58,11 +58,9 @@
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
int hx,lx;
|
||||
u.d = x;
|
||||
hx = (__HI(u)&0x7fffffff);
|
||||
lx = __LO(u);
|
||||
hx = (__HI(x)&0x7fffffff);
|
||||
lx = __LO(x);
|
||||
hx |= (unsigned)(lx|(-lx))>>31;
|
||||
hx = 0x7ff00000 - hx;
|
||||
return ((unsigned)(hx))>>31;
|
||||
|
||||
@@ -138,10 +138,8 @@ static double zero = 0.0;
|
||||
{
|
||||
double hfsq,f,c,s,z,R,u;
|
||||
int k,hx,hu,ax;
|
||||
fd_twoints un;
|
||||
|
||||
un.d = x;
|
||||
hx = __HI(un); /* high word of x */
|
||||
hx = __HI(x); /* high word of x */
|
||||
ax = hx&0x7fffffff;
|
||||
|
||||
k = 1;
|
||||
@@ -164,28 +162,22 @@ static double zero = 0.0;
|
||||
if(k!=0) {
|
||||
if(hx<0x43400000) {
|
||||
u = 1.0+x;
|
||||
un.d = u;
|
||||
hu = __HI(un); /* high word of u */
|
||||
hu = __HI(u); /* high word of u */
|
||||
k = (hu>>20)-1023;
|
||||
c = (k>0)? 1.0-(u-x):x-(u-1.0);/* correction term */
|
||||
c /= u;
|
||||
} else {
|
||||
u = x;
|
||||
un.d = u;
|
||||
hu = __HI(un); /* high word of u */
|
||||
hu = __HI(u); /* high word of u */
|
||||
k = (hu>>20)-1023;
|
||||
c = 0;
|
||||
}
|
||||
hu &= 0x000fffff;
|
||||
if(hu<0x6a09e) {
|
||||
un.d = u;
|
||||
__HI(un) = hu|0x3ff00000; /* normalize u */
|
||||
u = un.d;
|
||||
__HI(u) = hu|0x3ff00000; /* normalize u */
|
||||
} else {
|
||||
k += 1;
|
||||
un.d = u;
|
||||
__HI(un) = hu|0x3fe00000; /* normalize u/2 */
|
||||
u = un.d;
|
||||
__HI(u) = hu|0x3fe00000; /* normalize u/2 */
|
||||
hu = (0x00100000-hu)>>2;
|
||||
}
|
||||
f = u-1.0;
|
||||
|
||||
@@ -60,11 +60,8 @@
|
||||
#endif
|
||||
{
|
||||
int lx,ix;
|
||||
fd_twoints u;
|
||||
|
||||
u.d = x;
|
||||
ix = (__HI(u))&0x7fffffff; /* high |x| */
|
||||
lx = __LO(u); /* low x */
|
||||
ix = (__HI(x))&0x7fffffff; /* high |x| */
|
||||
lx = __LO(x); /* low x */
|
||||
if((ix|lx)==0) return -1.0/fd_fabs(x);
|
||||
if(ix>=0x7ff00000) return x*x;
|
||||
if((ix>>=20)==0) /* IEEE 754 logb */
|
||||
|
||||
@@ -71,56 +71,42 @@ static double one = 1.0;
|
||||
{
|
||||
int i0,i1,j0;
|
||||
unsigned i;
|
||||
fd_twoints u;
|
||||
u.d = x;
|
||||
i0 = __HI(u); /* high x */
|
||||
i1 = __LO(u); /* low x */
|
||||
i0 = __HI(x); /* high x */
|
||||
i1 = __LO(x); /* low x */
|
||||
j0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */
|
||||
if(j0<20) { /* integer part in high x */
|
||||
if(j0<0) { /* |x|<1 */
|
||||
u.d = *iptr;
|
||||
__HI(u) = i0&0x80000000;
|
||||
__LO(u) = 0; /* *iptr = +-0 */
|
||||
*iptr = u.d;
|
||||
__HIp(iptr) = i0&0x80000000;
|
||||
__LOp(iptr) = 0; /* *iptr = +-0 */
|
||||
return x;
|
||||
} else {
|
||||
i = (0x000fffff)>>j0;
|
||||
if(((i0&i)|i1)==0) { /* x is integral */
|
||||
*iptr = x;
|
||||
u.d = x;
|
||||
__HI(u) &= 0x80000000;
|
||||
__LO(u) = 0; /* return +-0 */
|
||||
x = u.d;
|
||||
__HI(x) &= 0x80000000;
|
||||
__LO(x) = 0; /* return +-0 */
|
||||
return x;
|
||||
} else {
|
||||
u.d = *iptr;
|
||||
__HI(u) = i0&(~i);
|
||||
__LO(u) = 0;
|
||||
*iptr = u.d;
|
||||
__HIp(iptr) = i0&(~i);
|
||||
__LOp(iptr) = 0;
|
||||
return x - *iptr;
|
||||
}
|
||||
}
|
||||
} else if (j0>51) { /* no fraction part */
|
||||
*iptr = x*one;
|
||||
u.d = x;
|
||||
__HI(u) &= 0x80000000;
|
||||
__LO(u) = 0; /* return +-0 */
|
||||
x = u.d;
|
||||
__HI(x) &= 0x80000000;
|
||||
__LO(x) = 0; /* return +-0 */
|
||||
return x;
|
||||
} else { /* fraction part in low x */
|
||||
i = ((unsigned)(0xffffffff))>>(j0-20);
|
||||
if((i1&i)==0) { /* x is integral */
|
||||
*iptr = x;
|
||||
u.d = x;
|
||||
__HI(u) &= 0x80000000;
|
||||
__LO(u) = 0; /* return +-0 */
|
||||
x = u.d;
|
||||
__HI(x) &= 0x80000000;
|
||||
__LO(x) = 0; /* return +-0 */
|
||||
return x;
|
||||
} else {
|
||||
u.d = *iptr;
|
||||
__HI(u) = i0;
|
||||
__LO(u) = i1&(~i);
|
||||
*iptr = u.d;
|
||||
__HIp(iptr) = i0;
|
||||
__LOp(iptr) = i1&(~i);
|
||||
return x - *iptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,13 +62,11 @@
|
||||
{
|
||||
int hx,hy,ix,iy;
|
||||
unsigned lx,ly;
|
||||
fd_twoints ux, uy;
|
||||
|
||||
ux.d = x; uy.d = y;
|
||||
hx = __HI(ux); /* high word of x */
|
||||
lx = __LO(ux); /* low word of x */
|
||||
hy = __HI(uy); /* high word of y */
|
||||
ly = __LO(uy); /* low word of y */
|
||||
hx = __HI(x); /* high word of x */
|
||||
lx = __LO(x); /* low word of x */
|
||||
hy = __HI(y); /* high word of y */
|
||||
ly = __LO(y); /* low word of y */
|
||||
ix = hx&0x7fffffff; /* |x| */
|
||||
iy = hy&0x7fffffff; /* |y| */
|
||||
|
||||
@@ -77,10 +75,8 @@
|
||||
return x+y;
|
||||
if(x==y) return x; /* x=y, return x */
|
||||
if((ix|lx)==0) { /* x == 0 */
|
||||
ux.d = x;
|
||||
__HI(ux) = hy&0x80000000; /* return +-minsubnormal */
|
||||
__LO(ux) = 1;
|
||||
x = ux.d;
|
||||
__HI(x) = hy&0x80000000; /* return +-minsubnormal */
|
||||
__LO(x) = 1;
|
||||
y = x*x;
|
||||
if(y==x) return y; else return x; /* raise underflow flag */
|
||||
}
|
||||
@@ -106,14 +102,10 @@
|
||||
if(hy<0x00100000) { /* underflow */
|
||||
y = x*x;
|
||||
if(y!=x) { /* raise underflow flag */
|
||||
uy.d = y;
|
||||
__HI(uy) = hx; __LO(uy) = lx;
|
||||
y = uy.d;
|
||||
__HI(y) = hx; __LO(y) = lx;
|
||||
return y;
|
||||
}
|
||||
}
|
||||
ux.d = x;
|
||||
__HI(ux) = hx; __LO(ux) = lx;
|
||||
x = ux.d;
|
||||
__HI(x) = hx; __LO(x) = lx;
|
||||
return x;
|
||||
}
|
||||
|
||||
@@ -76,12 +76,9 @@ TWO52[2]={
|
||||
int i0,j0,sx;
|
||||
unsigned i,i1;
|
||||
double w,t;
|
||||
fd_twoints u;
|
||||
|
||||
u.d = x;
|
||||
i0 = __HI(u);
|
||||
i0 = __HI(x);
|
||||
sx = (i0>>31)&1;
|
||||
i1 = __LO(u);
|
||||
i1 = __LO(x);
|
||||
j0 = ((i0>>20)&0x7ff)-0x3ff;
|
||||
if(j0<20) {
|
||||
if(j0<0) {
|
||||
@@ -89,15 +86,11 @@ TWO52[2]={
|
||||
i1 |= (i0&0x0fffff);
|
||||
i0 &= 0xfffe0000;
|
||||
i0 |= ((i1|-(int)i1)>>12)&0x80000;
|
||||
u.d = x;
|
||||
__HI(u)=i0;
|
||||
x = u.d;
|
||||
__HI(x)=i0;
|
||||
w = TWO52[sx]+x;
|
||||
t = w-TWO52[sx];
|
||||
u.d = t;
|
||||
i0 = __HI(u);
|
||||
__HI(u) = (i0&0x7fffffff)|(sx<<31);
|
||||
t = u.d;
|
||||
i0 = __HI(t);
|
||||
__HI(t) = (i0&0x7fffffff)|(sx<<31);
|
||||
return t;
|
||||
} else {
|
||||
i = (0x000fffff)>>j0;
|
||||
@@ -117,10 +110,8 @@ TWO52[2]={
|
||||
i>>=1;
|
||||
if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20));
|
||||
}
|
||||
u.d = x;
|
||||
__HI(u) = i0;
|
||||
__LO(u) = i1;
|
||||
x = u.d;
|
||||
__HI(x) = i0;
|
||||
__LO(x) = i1;
|
||||
w = TWO52[sx]+x;
|
||||
return w-TWO52[sx];
|
||||
}
|
||||
|
||||
@@ -70,17 +70,14 @@ tiny = 1.0e-300;
|
||||
double x; int n;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
int k,hx,lx;
|
||||
u.d = x;
|
||||
hx = __HI(u);
|
||||
lx = __LO(u);
|
||||
hx = __HI(x);
|
||||
lx = __LO(x);
|
||||
k = (hx&0x7ff00000)>>20; /* extract exponent */
|
||||
if (k==0) { /* 0 or subnormal x */
|
||||
if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
|
||||
x *= two54;
|
||||
u.d = x;
|
||||
hx = __HI(u);
|
||||
x *= two54;
|
||||
hx = __HI(x);
|
||||
k = ((hx&0x7ff00000)>>20) - 54;
|
||||
if (n< -50000) return tiny*x; /*underflow*/
|
||||
}
|
||||
@@ -88,15 +85,13 @@ tiny = 1.0e-300;
|
||||
k = k+n;
|
||||
if (k > 0x7fe) return really_big*fd_copysign(really_big,x); /* overflow */
|
||||
if (k > 0) /* normal result */
|
||||
{u.d = x; __HI(u) = (hx&0x800fffff)|(k<<20); x = u.d; return x;}
|
||||
{__HI(x) = (hx&0x800fffff)|(k<<20); return x;}
|
||||
if (k <= -54) {
|
||||
if (n > 50000) /* in case integer overflow in n+k */
|
||||
return really_big*fd_copysign(really_big,x); /*overflow*/
|
||||
else return tiny*fd_copysign(tiny,x); /*underflow*/
|
||||
}
|
||||
k += 54; /* subnormal result */
|
||||
u.d = x;
|
||||
__HI(u) = (hx&0x800fffff)|(k<<20);
|
||||
x = u.d;
|
||||
__HI(x) = (hx&0x800fffff)|(k<<20);
|
||||
return x*twom54;
|
||||
}
|
||||
|
||||
@@ -84,13 +84,11 @@
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
double y[2],z=0.0;
|
||||
int n, ix;
|
||||
|
||||
/* High word of x. */
|
||||
u.d = x;
|
||||
ix = __HI(u);
|
||||
ix = __HI(x);
|
||||
|
||||
/* |x| ~< pi/4 */
|
||||
ix &= 0x7fffffff;
|
||||
|
||||
@@ -83,13 +83,11 @@
|
||||
double x;
|
||||
#endif
|
||||
{
|
||||
fd_twoints u;
|
||||
double y[2],z=0.0;
|
||||
int n, ix;
|
||||
|
||||
/* High word of x. */
|
||||
u.d = x;
|
||||
ix = __HI(u);
|
||||
ix = __HI(x);
|
||||
|
||||
/* |x| ~< pi/4 */
|
||||
ix &= 0x7fffffff;
|
||||
|
||||
@@ -85,11 +85,9 @@ static double one=1.0, two=2.0, tiny = 1.0e-300;
|
||||
{
|
||||
double t,z;
|
||||
int jx,ix;
|
||||
fd_twoints u;
|
||||
|
||||
/* High word of |x|. */
|
||||
u.d = x;
|
||||
jx = __HI(u);
|
||||
jx = __HI(x);
|
||||
ix = jx&0x7fffffff;
|
||||
|
||||
/* x is INF or NaN */
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* 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
|
||||
@@ -113,6 +113,7 @@ char *strdup(const char *str)
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
#ifdef XP_MAC_MPW
|
||||
/* Macintosh MPW replacements for the ANSI routines. These translate LF's to CR's because
|
||||
the MPW libraries supplied by Metrowerks don't do that for some reason. */
|
||||
@@ -139,7 +140,7 @@ int fputs(const char *s, FILE *file)
|
||||
char buffer[4096];
|
||||
int n = strlen(s);
|
||||
int extra = 0;
|
||||
|
||||
|
||||
while (n > sizeof buffer) {
|
||||
memcpy(buffer, s, sizeof buffer);
|
||||
translateLFtoCR(buffer, sizeof buffer);
|
||||
@@ -206,20 +207,6 @@ static void initConsole(StringPtr consoleName, const char* startupMessage, int *
|
||||
*argc = 1;
|
||||
*argv = mac_argv;
|
||||
}
|
||||
|
||||
#ifdef LIVECONNECT
|
||||
/* Little hack to provide a default CLASSPATH on the Mac. */
|
||||
#define getenv(var) mac_getenv(var)
|
||||
static char* mac_getenv(const char* var)
|
||||
{
|
||||
if (strcmp(var, "CLASSPATH") == 0) {
|
||||
static char class_path[] = "liveconnect.jar";
|
||||
return class_path;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif /* LIVECONNECT */
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -230,7 +217,7 @@ static JSDJContext *_jsdjc;
|
||||
#endif /* JSDEBUGGER_JAVA_UI */
|
||||
#endif /* JSDEBUGGER */
|
||||
|
||||
static JSBool reportWarnings = JS_TRUE;
|
||||
static int reportWarnings;
|
||||
|
||||
typedef enum JSShellErrNum {
|
||||
#define MSG_DEF(name, number, count, exception, format) \
|
||||
@@ -327,10 +314,8 @@ Process(JSContext *cx, JSObject *obj, char *filename)
|
||||
}
|
||||
ungetc(ch, fh);
|
||||
script = JS_CompileFileHandle(cx, obj, filename, fh);
|
||||
if (script) {
|
||||
if (script)
|
||||
(void)JS_ExecuteScript(cx, obj, script, &result);
|
||||
JS_DestroyScript(cx, script);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -407,27 +392,10 @@ static int
|
||||
usage(void)
|
||||
{
|
||||
fprintf(gErrFile, "%s\n", JS_GetImplementationVersion());
|
||||
fprintf(gErrFile, "usage: js [-s] [-w] [-W] [-b branchlimit] [-c stackchunksize] [-v version] [-f scriptfile] [scriptfile] [scriptarg...]\n");
|
||||
fprintf(gErrFile, "usage: js [-s] [-w] [-c stackchunksize] [-v version] [-f scriptfile] [scriptfile] [scriptarg...]\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
static uint32 gBranchCount;
|
||||
static uint32 gBranchLimit;
|
||||
|
||||
static JSBool
|
||||
my_BranchCallback(JSContext *cx, JSScript *script)
|
||||
{
|
||||
if (++gBranchCount == gBranchLimit) {
|
||||
if (script->filename)
|
||||
fprintf(gErrFile, "%s:", script->filename);
|
||||
fprintf(gErrFile, "%u: script branches too much (%u callbacks)\n",
|
||||
script->lineno, gBranchLimit);
|
||||
gBranchCount = 0;
|
||||
return JS_FALSE;
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static int
|
||||
ProcessArgs(JSContext *cx, JSObject *obj, char **argv, int argc)
|
||||
{
|
||||
@@ -449,26 +417,17 @@ ProcessArgs(JSContext *cx, JSObject *obj, char **argv, int argc)
|
||||
i++;
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
reportWarnings = JS_TRUE;
|
||||
break;
|
||||
|
||||
case 'W':
|
||||
reportWarnings = JS_FALSE;
|
||||
case 'w':
|
||||
reportWarnings++;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
JS_ToggleOptions(cx, JSOPTION_STRICT);
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
gBranchLimit = atoi(argv[++i]);
|
||||
JS_SetBranchCallback(cx, my_BranchCallback);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
/* set stack chunk size */
|
||||
gStackChunkSize = atoi(argv[++i]);
|
||||
gStackChunkSize = atoi (argv[++i]);
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
@@ -670,7 +629,7 @@ Help(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
|
||||
static JSBool
|
||||
Quit(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
int r = 0;
|
||||
int r = 0;
|
||||
|
||||
#ifdef LIVECONNECT
|
||||
JSJ_SimpleShutdown();
|
||||
@@ -714,13 +673,13 @@ GC(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
js_DumpGCHeap = NULL;
|
||||
#endif
|
||||
fprintf(gOutFile, "before %lu, after %lu, break %08lx\n",
|
||||
(unsigned long)preBytes, (unsigned long)rt->gcBytes,
|
||||
(unsigned long)preBytes, (unsigned long)rt->gcBytes,
|
||||
#ifdef XP_UNIX
|
||||
(unsigned long)sbrk(0)
|
||||
(unsigned long)sbrk(0)
|
||||
#else
|
||||
0
|
||||
0
|
||||
#endif
|
||||
);
|
||||
);
|
||||
#ifdef JS_GCMETER
|
||||
js_DumpGCStats(rt, stdout);
|
||||
#endif
|
||||
@@ -965,7 +924,7 @@ TryNotes(JSContext *cx, JSScript *script)
|
||||
fprintf(gOutFile, "\nException table:\nstart\tend\tcatch\n");
|
||||
while (tn->start && tn->catchStart) {
|
||||
fprintf(gOutFile, " %d\t%d\t%d\n",
|
||||
tn->start, tn->start + tn->length, tn->catchStart);
|
||||
tn->start, tn->length, tn->catchStart);
|
||||
tn++;
|
||||
}
|
||||
return JS_TRUE;
|
||||
@@ -991,24 +950,6 @@ Disassemble(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
if (!script)
|
||||
continue;
|
||||
|
||||
if (JSVAL_IS_FUNCTION(cx, argv[i])) {
|
||||
JSFunction *fun = JS_ValueToFunction(cx, argv[i]);
|
||||
if (fun && (fun->flags & JSFUN_FLAGS_MASK)) {
|
||||
uint8 flags = fun->flags;
|
||||
fputs("flags:", stderr);
|
||||
|
||||
#define SHOW_FLAG(flag) if (flags & JSFUN_##flag) fputs(" " #flag, stdout);
|
||||
|
||||
SHOW_FLAG(SETTER);
|
||||
SHOW_FLAG(GETTER);
|
||||
SHOW_FLAG(BOUND_METHOD);
|
||||
SHOW_FLAG(HEAVYWEIGHT);
|
||||
|
||||
#undef SHOW_FLAG
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
js_Disassemble(cx, script, lines, stdout);
|
||||
SrcNotes(cx, script);
|
||||
TryNotes(cx, script);
|
||||
@@ -1017,8 +958,7 @@ Disassemble(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
}
|
||||
|
||||
static JSBool
|
||||
DisassWithSrc(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *rval)
|
||||
DisassWithSrc(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
#define LINE_BUF_LEN 512
|
||||
uintN i, len, line1, line2, bupline;
|
||||
@@ -1167,7 +1107,7 @@ DumpScope(JSContext *cx, JSObject *obj, JSHashEnumerator dump, FILE *fp)
|
||||
JSSymbol *sym;
|
||||
int i;
|
||||
|
||||
fprintf(fp, "\n%s scope contents:\n", JS_GET_CLASS(cx, obj)->name);
|
||||
fprintf(fp, "\n%s scope contents:\n", OBJ_GET_CLASS(cx, obj)->name);
|
||||
scope = OBJ_SCOPE(obj);
|
||||
if (!MAP_IS_NATIVE(&scope->map))
|
||||
return;
|
||||
@@ -1202,7 +1142,7 @@ DumpStats(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
return JS_FALSE;
|
||||
bytes = JS_GetStringBytes(str);
|
||||
if (strcmp(bytes, "arena") == 0) {
|
||||
#ifdef JS_ARENAMETER
|
||||
#ifdef ARENAMETER
|
||||
JS_DumpArenaStats(stdout);
|
||||
#endif
|
||||
} else if (strcmp(bytes, "atom") == 0) {
|
||||
@@ -1396,30 +1336,6 @@ BuildDate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
Clear(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
if (argc != 0 && !JS_ValueToObject(cx, argv[0], &obj))
|
||||
return JS_FALSE;
|
||||
JS_ClearScope(cx, obj);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
Intern(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
JSString *str;
|
||||
|
||||
str = JS_ValueToString(cx, argv[0]);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
if (!JS_InternUCStringN(cx, JS_GetStringChars(str),
|
||||
JS_GetStringLength(str))) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSFunctionSpec shell_functions[] = {
|
||||
{"version", Version, 0},
|
||||
{"options", Options, 0},
|
||||
@@ -1446,40 +1362,37 @@ static JSFunctionSpec shell_functions[] = {
|
||||
{"cvtargs", ConvertArgs, 0, 0, 12},
|
||||
#endif
|
||||
{"build", BuildDate, 0},
|
||||
{"clear", Clear, 0},
|
||||
{"intern", Intern, 1},
|
||||
{0}
|
||||
};
|
||||
|
||||
/* NOTE: These must be kept in sync with the above. */
|
||||
|
||||
static char *shell_help_messages[] = {
|
||||
"version([number]) Get or set JavaScript version number",
|
||||
"options([option ...]) Get or toggle JavaScript options",
|
||||
"load(['foo.js' ...]) Load files named by string arguments",
|
||||
"print([expr ...]) Evaluate and print expressions",
|
||||
"help([name ...]) Display usage and help messages",
|
||||
"quit() Quit the shell",
|
||||
"gc() Run the garbage collector",
|
||||
"trap([fun] [pc] expr) Trap bytecode execution",
|
||||
"untrap([fun] [pc]) Remove a trap",
|
||||
"line2pc([fun] line) Map line number to PC",
|
||||
"pc2line([fun] [pc]) Map PC to line number",
|
||||
"version [number] Get or set JavaScript version number",
|
||||
"options [option ...] Get or toggle JavaScript options",
|
||||
"load ['foo.js' ...] Load files named by string arguments",
|
||||
"print [expr ...] Evaluate and print expressions",
|
||||
"help [name ...] Display usage and help messages",
|
||||
"quit Quit mocha",
|
||||
"gc Run the garbage collector",
|
||||
"trap [fun] [pc] expr Trap bytecode execution",
|
||||
"untrap [fun] [pc] Remove a trap",
|
||||
"line2pc [fun] line Map line number to PC",
|
||||
"pc2line [fun] [pc] Map PC to line number",
|
||||
#ifdef DEBUG
|
||||
"dis([fun]) Disassemble functions into bytecodes",
|
||||
"dissrc([fun]) Disassemble functions with source lines",
|
||||
"notes([fun]) Show source notes for functions",
|
||||
"tracing([toggle]) Turn tracing on or off",
|
||||
"stats([string ...]) Dump 'arena', 'atom', 'global' stats",
|
||||
"dis [fun] Disassemble functions into bytecodes",
|
||||
"dissrc [fun] Disassemble functions with source lines",
|
||||
"notes [fun] Show source notes for functions",
|
||||
"tracing [toggle] Turn tracing on or off",
|
||||
"stats [string ...] Dump 'arena', 'atom', 'global' stats",
|
||||
#endif
|
||||
#ifdef TEST_EXPORT
|
||||
"doexp(obj, id) Export identified property from object",
|
||||
"doexp obj id Export identified property from object",
|
||||
#endif
|
||||
#ifdef TEST_CVTARGS
|
||||
"cvtargs(b, c, ...) Test JS_ConvertArguments",
|
||||
"cvtargs b c ... Test JS_ConvertArguments",
|
||||
#endif
|
||||
"build() Show build date and time",
|
||||
"clear([obj]) Clear properties of object",
|
||||
"build Show build date and time",
|
||||
0
|
||||
};
|
||||
|
||||
@@ -1568,19 +1481,6 @@ static JSPropertySpec its_props[] = {
|
||||
{0}
|
||||
};
|
||||
|
||||
static JSBool
|
||||
its_item(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
*rval = OBJECT_TO_JSVAL(obj);
|
||||
JS_SetCallReturnValue2(cx, argv[0]);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSFunctionSpec its_methods[] = {
|
||||
{"item", its_item, 0},
|
||||
{0}
|
||||
};
|
||||
|
||||
#ifdef JSD_LOWLEVEL_SOURCE
|
||||
/*
|
||||
* This facilitates sending source to JSD (the debugger system) in the shell
|
||||
@@ -1746,6 +1646,16 @@ my_LoadErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
|
||||
my_ErrorReporter(cx, message, report);
|
||||
}
|
||||
|
||||
static uint32 branch_count;
|
||||
|
||||
static JSBool
|
||||
my_BranchCallback(JSContext *cx, JSScript *script)
|
||||
{
|
||||
if ((++branch_count & 0x3fffff) == 0)
|
||||
return JS_FALSE;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
my_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
|
||||
{
|
||||
@@ -1817,8 +1727,7 @@ my_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
|
||||
}
|
||||
fputs("^\n", gErrFile);
|
||||
out:
|
||||
if (!JSREPORT_IS_WARNING(report->flags))
|
||||
gExitCode = EXITCODE_RUNTIME_ERROR;
|
||||
gExitCode = EXITCODE_RUNTIME_ERROR;
|
||||
JS_free(cx, prefix);
|
||||
}
|
||||
|
||||
@@ -1872,32 +1781,10 @@ Exec(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
}
|
||||
#endif
|
||||
|
||||
#define LAZY_STANDARD_CLASSES
|
||||
|
||||
static JSBool
|
||||
global_enumerate(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
#ifdef LAZY_STANDARD_CLASSES
|
||||
return JS_EnumerateStandardClasses(cx, obj);
|
||||
#else
|
||||
return JS_TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
static JSBool
|
||||
global_resolve(JSContext *cx, JSObject *obj, jsval id)
|
||||
{
|
||||
#ifdef LAZY_STANDARD_CLASSES
|
||||
JSBool resolved;
|
||||
|
||||
if (!JS_ResolveStandardClass(cx, obj, id, &resolved))
|
||||
return JS_FALSE;
|
||||
if (resolved)
|
||||
return JS_TRUE;
|
||||
#endif
|
||||
|
||||
#if defined(SHELL_HACK) && defined(DEBUG) && defined(XP_UNIX)
|
||||
{
|
||||
/*
|
||||
* Do this expensive hack only for unoptimized Unix builds, which are not
|
||||
* used for benchmarking.
|
||||
@@ -1939,7 +1826,6 @@ global_resolve(JSContext *cx, JSObject *obj, jsval id)
|
||||
}
|
||||
JS_free(cx, path);
|
||||
return ok;
|
||||
}
|
||||
#else
|
||||
return JS_TRUE;
|
||||
#endif
|
||||
@@ -1948,7 +1834,7 @@ global_resolve(JSContext *cx, JSObject *obj, jsval id)
|
||||
static JSClass global_class = {
|
||||
"global", 0,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
global_enumerate, global_resolve, JS_ConvertStub, JS_FinalizeStub
|
||||
JS_EnumerateStub, global_resolve, JS_ConvertStub, JS_FinalizeStub
|
||||
};
|
||||
|
||||
int
|
||||
@@ -2025,17 +1911,14 @@ main(int argc, char **argv)
|
||||
cx = JS_NewContext(rt, gStackChunkSize);
|
||||
if (!cx)
|
||||
return 1;
|
||||
JS_SetBranchCallback(cx, my_BranchCallback);
|
||||
JS_SetErrorReporter(cx, my_ErrorReporter);
|
||||
|
||||
glob = JS_NewObject(cx, &global_class, NULL, NULL);
|
||||
if (!glob)
|
||||
return 1;
|
||||
#ifdef LAZY_STANDARD_CLASSES
|
||||
JS_SetGlobalObject(cx, glob);
|
||||
#else
|
||||
if (!JS_InitStandardClasses(cx, glob))
|
||||
return 1;
|
||||
#endif
|
||||
if (!JS_DefineFunctions(cx, glob, shell_functions))
|
||||
return 1;
|
||||
|
||||
@@ -2048,8 +1931,6 @@ main(int argc, char **argv)
|
||||
return 1;
|
||||
if (!JS_DefineProperties(cx, it, its_props))
|
||||
return 1;
|
||||
if (!JS_DefineFunctions(cx, it, its_methods))
|
||||
return 1;
|
||||
|
||||
#ifdef PERLCONNECT
|
||||
if (!JS_InitPerlClass(cx, glob))
|
||||
|
||||
@@ -66,7 +66,6 @@ CLEAN :
|
||||
-@erase "$(INTDIR)\jscntxt.obj"
|
||||
-@erase "$(INTDIR)\jsdate.obj"
|
||||
-@erase "$(INTDIR)\jsdbgapi.obj"
|
||||
-@erase "$(INTDIR)\jsdhash.obj"
|
||||
-@erase "$(INTDIR)\jsdtoa.obj"
|
||||
-@erase "$(INTDIR)\jsemit.obj"
|
||||
-@erase "$(INTDIR)\jsexn.obj"
|
||||
@@ -156,7 +155,6 @@ LINK32_OBJS= \
|
||||
"$(INTDIR)\jscntxt.obj" \
|
||||
"$(INTDIR)\jsdate.obj" \
|
||||
"$(INTDIR)\jsdbgapi.obj" \
|
||||
"$(INTDIR)\jsdhash.obj" \
|
||||
"$(INTDIR)\jsdtoa.obj" \
|
||||
"$(INTDIR)\jsemit.obj" \
|
||||
"$(INTDIR)\jsexn.obj" \
|
||||
@@ -214,7 +212,6 @@ CLEAN :
|
||||
-@erase "$(INTDIR)\jscntxt.obj"
|
||||
-@erase "$(INTDIR)\jsdate.obj"
|
||||
-@erase "$(INTDIR)\jsdbgapi.obj"
|
||||
-@erase "$(INTDIR)\jsdhash.obj"
|
||||
-@erase "$(INTDIR)\jsdtoa.obj"
|
||||
-@erase "$(INTDIR)\jsemit.obj"
|
||||
-@erase "$(INTDIR)\jsexn.obj"
|
||||
@@ -308,7 +305,6 @@ LINK32_OBJS= \
|
||||
"$(INTDIR)\jscntxt.obj" \
|
||||
"$(INTDIR)\jsdate.obj" \
|
||||
"$(INTDIR)\jsdbgapi.obj" \
|
||||
"$(INTDIR)\jsdhash.obj" \
|
||||
"$(INTDIR)\jsdtoa.obj" \
|
||||
"$(INTDIR)\jsemit.obj" \
|
||||
"$(INTDIR)\jsexn.obj" \
|
||||
@@ -537,7 +533,7 @@ CPP=cl.exe
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_IEEE_LIBM" /YX /c
|
||||
CPP_PROJ=/nologo /MD /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D\
|
||||
"_IEEE_LIBM" /D "XP_PC" /I .\ /Fp"$(INTDIR)/fdlibm.pch" /YX /Fo"$(INTDIR)/" /c
|
||||
"_IEEE_LIBM" /Fp"$(INTDIR)/fdlibm.pch" /YX /Fo"$(INTDIR)/" /c
|
||||
CPP_OBJS=.\Release/
|
||||
CPP_SBRS=.\.
|
||||
|
||||
@@ -633,7 +629,7 @@ CPP=cl.exe
|
||||
# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
|
||||
# ADD CPP /nologo /MDd /W3 /GX /Z7 /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_IEEE_LIBM" /YX /c
|
||||
CPP_PROJ=/nologo /MDd /W3 /GX /Z7 /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D\
|
||||
"_IEEE_LIBM" /D "XP_PC" -I .\ /Fp"$(INTDIR)/fdlibm.pch" /YX /Fo"$(INTDIR)/" /c
|
||||
"_IEEE_LIBM" /Fp"$(INTDIR)/fdlibm.pch" /YX /Fo"$(INTDIR)/" /c
|
||||
CPP_OBJS=.\Debug/
|
||||
CPP_SBRS=.\.
|
||||
|
||||
@@ -1436,56 +1432,6 @@ NODEP_CPP_JSDBG=\
|
||||
"$(INTDIR)\jsdbgapi.obj" : $(SOURCE) $(DEP_CPP_JSDBG) "$(INTDIR)"
|
||||
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
################################################################################
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsdhash.c
|
||||
|
||||
!IF "$(CFG)" == "js - Win32 Release"
|
||||
|
||||
DEP_CPP_JSDHA=\
|
||||
".\jsbit.h"\
|
||||
".\jscompat.h"\
|
||||
".\jscpucfg.h"\
|
||||
".\jsdhash.h"\
|
||||
".\jslong.h"\
|
||||
".\jsosdep.h"\
|
||||
".\jsotypes.h"\
|
||||
".\jstypes.h"\
|
||||
".\jsutil.h"\
|
||||
{$(INCLUDE)}"\sys\types.h"\
|
||||
|
||||
NODEP_CPP_JSDHA=\
|
||||
".\jsautocfg.h"\
|
||||
|
||||
|
||||
"$(INTDIR)\jsdhash.obj" : $(SOURCE) $(DEP_CPP_JSDHA) "$(INTDIR)"
|
||||
|
||||
|
||||
!ELSEIF "$(CFG)" == "js - Win32 Debug"
|
||||
|
||||
DEP_CPP_JSDHA=\
|
||||
".\jsbit.h"\
|
||||
".\jscompat.h"\
|
||||
".\jscpucfg.h"\
|
||||
".\jsdhash.h"\
|
||||
".\jslong.h"\
|
||||
".\jsosdep.h"\
|
||||
".\jsotypes.h"\
|
||||
".\jstypes.h"\
|
||||
".\jsutil.h"\
|
||||
{$(INCLUDE)}"\sys\types.h"\
|
||||
|
||||
NODEP_CPP_JSDHA=\
|
||||
".\jsautocfg.h"\
|
||||
|
||||
|
||||
"$(INTDIR)\jsdhash.obj" : $(SOURCE) $(DEP_CPP_JSDHA) "$(INTDIR)"
|
||||
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
|
||||
@@ -90,7 +90,7 @@ MSG_DEF(JSMSG_TOO_MANY_LITERALS, 14, 0, JSEXN_INTERNALERR, "too many liter
|
||||
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_BAD_CASE, 18, 0, JSEXN_SYNTAXERR, "invalid case expression")
|
||||
MSG_DEF(JSMSG_BAD_CASE, 18, 2, JSEXN_SYNTAXERR, "{0}, line {1}: invalid case expression")
|
||||
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}")
|
||||
@@ -99,11 +99,11 @@ MSG_DEF(JSMSG_NOT_CONSTRUCTOR, 23, 1, JSEXN_TYPEERR, "{0} is not a const
|
||||
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_IN_NOT_OBJECT, 27, 0, JSEXN_ERR, "target of 'in' operator must be an object")
|
||||
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_INSTANCEOF_RHS, 31, 1, JSEXN_ERR, "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")
|
||||
@@ -217,7 +217,7 @@ MSG_DEF(JSMSG_UNTERMINATED_REGEXP, 141, 0, JSEXN_SYNTAXERR, "unterminated reg
|
||||
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_NONE, "{0} is not a legal ECMA-262 octal constant")
|
||||
MSG_DEF(JSMSG_BAD_OCTAL, 145, 1, JSEXN_NONE, "{0} is not a legal ECMA-262 numeric 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")
|
||||
@@ -231,10 +231,5 @@ MSG_DEF(JSMSG_REDECLARED_VAR, 155, 2, JSEXN_TYPEERR, "redeclaration of {
|
||||
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_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")
|
||||
|
||||
@@ -127,8 +127,6 @@ EXPORTS
|
||||
; JS_CallFunctionValue
|
||||
; JS_SetBranchCallback
|
||||
; JS_IsRunning
|
||||
; JS_IsConstructing
|
||||
; JS_SetCallReturnValue2
|
||||
; JS_NewString
|
||||
; JS_NewStringCopyN
|
||||
; JS_NewStringCopyZ
|
||||
@@ -615,13 +613,6 @@ EXPORTS
|
||||
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):
|
||||
|
||||
@@ -245,10 +245,8 @@ JS_ConvertArgumentsVA(JSContext *cx, uintN argc, jsval *argv,
|
||||
break;
|
||||
default:
|
||||
format--;
|
||||
if (!TryArgumentFormatter(cx, &format, JS_TRUE, &sp,
|
||||
JS_ADDRESSOF_VA_LIST(ap))) {
|
||||
if (!TryArgumentFormatter(cx, &format, JS_TRUE, &sp, JS_ADDRESSOF_VA_LIST(ap)))
|
||||
return JS_FALSE;
|
||||
}
|
||||
/* NB: the formatter already updated sp, so we continue here. */
|
||||
continue;
|
||||
}
|
||||
@@ -278,7 +276,6 @@ JS_PushArgumentsVA(JSContext *cx, void **markp, const char *format, va_list ap)
|
||||
const char *cp;
|
||||
JSString *str;
|
||||
JSFunction *fun;
|
||||
JSStackHeader *sh;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
*markp = NULL;
|
||||
@@ -348,10 +345,8 @@ JS_PushArgumentsVA(JSContext *cx, void **markp, const char *format, va_list ap)
|
||||
break;
|
||||
default:
|
||||
format--;
|
||||
if (!TryArgumentFormatter(cx, &format, JS_FALSE, &sp,
|
||||
JS_ADDRESSOF_VA_LIST(ap))) {
|
||||
if (!TryArgumentFormatter(cx, &format, JS_FALSE, &sp, JS_ADDRESSOF_VA_LIST(ap)))
|
||||
goto bad;
|
||||
}
|
||||
/* NB: the formatter already updated sp, so we continue here. */
|
||||
continue;
|
||||
}
|
||||
@@ -363,15 +358,8 @@ JS_PushArgumentsVA(JSContext *cx, void **markp, const char *format, va_list ap)
|
||||
* handled by a JSArgumentFormatter. Give back that stack space!
|
||||
*/
|
||||
JS_ASSERT(sp <= argv + argc);
|
||||
if (sp < argv + argc) {
|
||||
/* Return slots not pushed to the current stack arena. */
|
||||
if (sp < argv + argc)
|
||||
cx->stackPool.current->avail = (jsuword)sp;
|
||||
|
||||
/* Reduce the count of slots the GC will scan in this stack segment. */
|
||||
sh = cx->stackHeaders;
|
||||
JS_ASSERT(JS_STACK_SEGMENT(sh) + sh->nslots == argv + argc);
|
||||
sh->nslots -= argc - (sp - argv);
|
||||
}
|
||||
return argv;
|
||||
|
||||
bad:
|
||||
@@ -645,7 +633,7 @@ JS_NewRuntime(uint32 maxbytes)
|
||||
rt->requestDone = JS_NEW_CONDVAR(rt->gcLock);
|
||||
if (!rt->requestDone)
|
||||
goto bad;
|
||||
js_SetupLocks(20, 32); /* this is asymmetric with JS_ShutDown. */
|
||||
js_SetupLocks(20,20); /* this is asymmetric with JS_ShutDown. */
|
||||
rt->rtLock = JS_NEW_LOCK();
|
||||
if (!rt->rtLock)
|
||||
goto bad;
|
||||
@@ -655,10 +643,6 @@ JS_NewRuntime(uint32 maxbytes)
|
||||
rt->setSlotLock = JS_NEW_LOCK();
|
||||
if (!rt->setSlotLock)
|
||||
goto bad;
|
||||
rt->scopeSharingDone = JS_NEW_CONDVAR(rt->gcLock);
|
||||
if (!rt->scopeSharingDone)
|
||||
goto bad;
|
||||
rt->scopeSharingTodo = NO_SCOPE_SHARING_TODO;
|
||||
#endif
|
||||
rt->propertyCache.empty = JS_TRUE;
|
||||
JS_INIT_CLIST(&rt->contextList);
|
||||
@@ -674,20 +658,11 @@ bad:
|
||||
JS_PUBLIC_API(void)
|
||||
JS_DestroyRuntime(JSRuntime *rt)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
/* Don't hurt everyone in leaky ol' Mozilla with a fatal JS_ASSERT! */
|
||||
if (rt->contextList.next != &rt->contextList) {
|
||||
JSContext *cx, *iter = NULL;
|
||||
uintN cxcount = 0;
|
||||
while ((cx = js_ContextIterator(rt, &iter)) != NULL)
|
||||
cxcount++;
|
||||
fprintf(stderr,
|
||||
"JS API usage error: %u contexts left in runtime upon JS_DestroyRuntime.\n",
|
||||
cxcount);
|
||||
}
|
||||
#endif
|
||||
JSContext *cx, *iter;
|
||||
|
||||
js_FinishAtomState(&rt->atomState);
|
||||
iter = NULL;
|
||||
while ((cx = js_ContextIterator(rt, &iter)) != NULL)
|
||||
js_DestroyContext(cx, JS_NO_GC);
|
||||
js_FinishGC(rt);
|
||||
#ifdef JS_THREADSAFE
|
||||
if (rt->gcLock)
|
||||
@@ -702,8 +677,6 @@ JS_DestroyRuntime(JSRuntime *rt)
|
||||
JS_DESTROY_CONDVAR(rt->stateChange);
|
||||
if (rt->setSlotLock)
|
||||
JS_DESTROY_LOCK(rt->setSlotLock);
|
||||
if (rt->scopeSharingDone)
|
||||
JS_DESTROY_CONDVAR(rt->scopeSharingDone);
|
||||
#endif
|
||||
free(rt);
|
||||
}
|
||||
@@ -737,23 +710,16 @@ JS_BeginRequest(JSContext *cx)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
|
||||
JS_ASSERT(cx->thread);
|
||||
if (!cx->requestDepth) {
|
||||
/* Wait until the GC is finished. */
|
||||
rt = cx->runtime;
|
||||
JS_LOCK_GC(rt);
|
||||
|
||||
/* NB: we use cx->thread here, not js_CurrentThreadId(). */
|
||||
if (rt->gcThread != cx->thread) {
|
||||
while (rt->gcLevel > 0)
|
||||
JS_AWAIT_GC_DONE(rt);
|
||||
}
|
||||
while (rt->gcLevel > 0)
|
||||
JS_AWAIT_GC_DONE(rt);
|
||||
|
||||
/* Indicate that a request is running. */
|
||||
rt->requestCount++;
|
||||
cx->requestDepth = 1;
|
||||
JS_UNLOCK_GC(rt);
|
||||
return;
|
||||
}
|
||||
cx->requestDepth++;
|
||||
}
|
||||
@@ -762,57 +728,18 @@ JS_PUBLIC_API(void)
|
||||
JS_EndRequest(JSContext *cx)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
JSScope *scope, **todop;
|
||||
uintN nshares;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
JS_ASSERT(cx->requestDepth > 0);
|
||||
if (cx->requestDepth == 1) {
|
||||
/* Lock before clearing to interlock with ClaimScope, in jslock.c. */
|
||||
rt = cx->runtime;
|
||||
JS_LOCK_GC(rt);
|
||||
cx->requestDepth = 0;
|
||||
|
||||
/* See whether cx has any single-threaded scopes to start sharing. */
|
||||
todop = &rt->scopeSharingTodo;
|
||||
nshares = 0;
|
||||
while ((scope = *todop) != NO_SCOPE_SHARING_TODO) {
|
||||
if (scope->ownercx != cx) {
|
||||
todop = &scope->u.link;
|
||||
continue;
|
||||
}
|
||||
*todop = scope->u.link;
|
||||
scope->u.link = NULL; /* null u.link for sanity ASAP */
|
||||
|
||||
/*
|
||||
* If js_DropObjectMap returns null, we held the last ref to scope.
|
||||
* The waiting thread(s) must have been killed, after which the GC
|
||||
* collected the object that held this scope. Unlikely, because it
|
||||
* requires that the GC ran (e.g., from a branch callback) during
|
||||
* this request, but possible.
|
||||
*/
|
||||
if (js_DropObjectMap(cx, &scope->map, NULL)) {
|
||||
js_InitLock(&scope->lock);
|
||||
scope->u.count = 0; /* don't assume NULL puns as 0 */
|
||||
scope->ownercx = NULL; /* NB: set last, after lock init */
|
||||
nshares++;
|
||||
JS_RUNTIME_METER(rt, sharedScopes);
|
||||
}
|
||||
}
|
||||
if (nshares)
|
||||
JS_NOTIFY_ALL_CONDVAR(rt->scopeSharingDone);
|
||||
|
||||
/* Give the GC a chance to run if this was the last request running. */
|
||||
JS_ASSERT(rt->requestCount > 0);
|
||||
rt->requestCount--;
|
||||
if (rt->requestCount == 0)
|
||||
JS_NOTIFY_REQUEST_DONE(rt);
|
||||
|
||||
JS_UNLOCK_GC(rt);
|
||||
return;
|
||||
}
|
||||
|
||||
cx->requestDepth--;
|
||||
if (!cx->requestDepth) {
|
||||
rt = cx->runtime;
|
||||
JS_LOCK_GC(rt);
|
||||
JS_ASSERT(rt->requestCount > 0);
|
||||
rt->requestCount--;
|
||||
if (rt->requestCount == 0)
|
||||
JS_NOTIFY_REQUEST_DONE(rt);
|
||||
JS_UNLOCK_GC(rt);
|
||||
}
|
||||
}
|
||||
|
||||
/* Yield to pending GC operations, regardless of request depth */
|
||||
@@ -821,9 +748,7 @@ JS_YieldRequest(JSContext *cx)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
|
||||
JS_ASSERT(cx->thread);
|
||||
CHECK_REQUEST(cx);
|
||||
|
||||
rt = cx->runtime;
|
||||
JS_LOCK_GC(rt);
|
||||
JS_ASSERT(rt->requestCount > 0);
|
||||
@@ -838,22 +763,16 @@ JS_YieldRequest(JSContext *cx)
|
||||
JS_UNLOCK_GC(rt);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(jsrefcount)
|
||||
JS_PUBLIC_API(void)
|
||||
JS_SuspendRequest(JSContext *cx)
|
||||
{
|
||||
jsrefcount saveDepth = cx->requestDepth;
|
||||
|
||||
while (cx->requestDepth)
|
||||
JS_EndRequest(cx);
|
||||
return saveDepth;
|
||||
JS_EndRequest(cx);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_ResumeRequest(JSContext *cx, jsrefcount saveDepth)
|
||||
JS_ResumeRequest(JSContext *cx)
|
||||
{
|
||||
JS_ASSERT(!cx->requestDepth);
|
||||
while (--saveDepth >= 0)
|
||||
JS_BeginRequest(cx);
|
||||
JS_BeginRequest(cx);
|
||||
}
|
||||
|
||||
#endif /* JS_THREADSAFE */
|
||||
@@ -1010,7 +929,7 @@ JS_ToggleOptions(JSContext *cx, uint32 options)
|
||||
JS_PUBLIC_API(const char *)
|
||||
JS_GetImplementationVersion(void)
|
||||
{
|
||||
return "JavaScript-C 1.5 pre-release 3 2001-03-07";
|
||||
return "JavaScript-C 1.5 pre-release 1 1999 10 31";
|
||||
}
|
||||
|
||||
|
||||
@@ -1026,89 +945,50 @@ JS_SetGlobalObject(JSContext *cx, JSObject *obj)
|
||||
cx->globalObject = obj;
|
||||
}
|
||||
|
||||
static JSObject *
|
||||
InitFunctionAndObjectClasses(JSContext *cx, JSObject *obj)
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_InitStandardClasses(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
JSDHashTable *table;
|
||||
JSRuntime *rt;
|
||||
JSString *idstr;
|
||||
JSDHashEntryHdr *entry;
|
||||
JSObject *fun_proto, *obj_proto;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
/* If cx has no global object, use obj so prototypes can be found. */
|
||||
if (!cx->globalObject)
|
||||
cx->globalObject = obj;
|
||||
|
||||
/* Record both Function and Object in cx->resolving, if we are resolving. */
|
||||
table = cx->resolving;
|
||||
if (table) {
|
||||
rt = cx->runtime;
|
||||
idstr = ATOM_TO_STRING(rt->atomState.FunctionAtom);
|
||||
entry = JS_DHashTableOperate(table, idstr, JS_DHASH_LOOKUP);
|
||||
if (JS_DHASH_ENTRY_IS_BUSY(entry))
|
||||
idstr = ATOM_TO_STRING(rt->atomState.ObjectAtom);
|
||||
|
||||
entry = JS_DHashTableOperate(table, idstr, JS_DHASH_ADD);
|
||||
if (!entry) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return NULL;
|
||||
}
|
||||
((JSDHashEntryStub *)entry)->key = idstr;
|
||||
#if JS_HAS_UNDEFINED
|
||||
/*
|
||||
* Define a top-level property 'undefined' with the undefined value.
|
||||
* (proposed ECMA v2, now in ECMA ed3?)
|
||||
*/
|
||||
if (!OBJ_DEFINE_PROPERTY(cx, obj,
|
||||
(jsid)cx->runtime->atomState.typeAtoms[JSTYPE_VOID],
|
||||
JSVAL_VOID, NULL, NULL, JSPROP_PERMANENT, NULL)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Initialize the function class first so constructors can be made. */
|
||||
fun_proto = js_InitFunctionClass(cx, obj);
|
||||
if (!fun_proto)
|
||||
return NULL;
|
||||
return JS_FALSE;
|
||||
|
||||
/* Initialize the object class next so Object.prototype works. */
|
||||
obj_proto = js_InitObjectClass(cx, obj);
|
||||
if (!obj_proto)
|
||||
return NULL;
|
||||
return JS_FALSE;
|
||||
|
||||
/* Function.prototype and the global object delegate to Object.prototype. */
|
||||
OBJ_SET_PROTO(cx, fun_proto, obj_proto);
|
||||
if (!OBJ_GET_PROTO(cx, obj))
|
||||
OBJ_SET_PROTO(cx, obj, obj_proto);
|
||||
|
||||
/* If resolving, remove the other entry (Object or Function) from table. */
|
||||
if (table)
|
||||
JS_DHashTableRawRemove(table, entry);
|
||||
return fun_proto;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_InitStandardClasses(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
|
||||
#if JS_HAS_UNDEFINED
|
||||
{
|
||||
/* Define a top-level property 'undefined' with the undefined value. */
|
||||
JSAtom *atom = cx->runtime->atomState.typeAtoms[JSTYPE_VOID];
|
||||
if (!OBJ_DEFINE_PROPERTY(cx, obj, (jsid)atom, JSVAL_VOID, NULL, NULL,
|
||||
JSPROP_PERMANENT, NULL)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Function and Object require cooperative bootstrapping magic. */
|
||||
if (!InitFunctionAndObjectClasses(cx, obj))
|
||||
return JS_FALSE;
|
||||
|
||||
/* Initialize the rest of the standard objects and functions. */
|
||||
return js_InitArrayClass(cx, obj) &&
|
||||
return js_InitArgsAndCallClasses(cx, obj) &&
|
||||
js_InitArrayClass(cx, obj) &&
|
||||
js_InitBooleanClass(cx, obj) &&
|
||||
js_InitMathClass(cx, obj) &&
|
||||
js_InitNumberClass(cx, obj) &&
|
||||
js_InitStringClass(cx, obj) &&
|
||||
#if JS_HAS_ARGS_OBJECT
|
||||
js_InitArgumentsClass(cx, obj) &&
|
||||
#endif
|
||||
#if JS_HAS_CALL_OBJECT
|
||||
js_InitCallClass(cx, obj) &&
|
||||
#endif
|
||||
#if JS_HAS_REGEXPS
|
||||
js_InitRegExpClass(cx, obj) &&
|
||||
#endif
|
||||
@@ -1124,301 +1004,6 @@ JS_InitStandardClasses(JSContext *cx, JSObject *obj)
|
||||
js_InitDateClass(cx, obj);
|
||||
}
|
||||
|
||||
#define ATOM_OFFSET(name) offsetof(JSAtomState, name##Atom)
|
||||
#define OFFSET_TO_ATOM(rt,off) (*(JSAtom **)((char*)&(rt)->atomState + (off)))
|
||||
#define TAG_ATOM_OFFSET(name) ((const char *) ATOM_OFFSET(name))
|
||||
#define TAG_CHAR_STRING(name) name
|
||||
#define UNTAG_ATOM_OFFSET(ptr) ((size_t)(ptr))
|
||||
#define UNTAG_CHAR_STRING(ptr) ptr
|
||||
#define IS_ATOM_OFFSET(ptr) ((size_t)(ptr) < sizeof(JSAtomState))
|
||||
|
||||
/*
|
||||
* Table of class initializers and their atom offsets in rt->atomState.
|
||||
* If you add a "standard" class, remember to update this table.
|
||||
*/
|
||||
static struct {
|
||||
JSObjectOp init;
|
||||
size_t atomOffset;
|
||||
} standard_class_atoms[] = {
|
||||
{InitFunctionAndObjectClasses, ATOM_OFFSET(Function)},
|
||||
{InitFunctionAndObjectClasses, ATOM_OFFSET(Object)},
|
||||
{js_InitArrayClass, ATOM_OFFSET(Array)},
|
||||
{js_InitBooleanClass, ATOM_OFFSET(Boolean)},
|
||||
{js_InitDateClass, ATOM_OFFSET(Date)},
|
||||
{js_InitMathClass, ATOM_OFFSET(Math)},
|
||||
{js_InitNumberClass, ATOM_OFFSET(Number)},
|
||||
{js_InitStringClass, ATOM_OFFSET(String)},
|
||||
#if JS_HAS_ARGS_OBJECT
|
||||
{js_InitArgumentsClass, ATOM_OFFSET(Arguments)},
|
||||
#endif
|
||||
#if JS_HAS_CALL_OBJECT
|
||||
{js_InitCallClass, ATOM_OFFSET(Call)},
|
||||
#endif
|
||||
#if JS_HAS_ERROR_EXCEPTIONS
|
||||
{js_InitExceptionClasses, ATOM_OFFSET(Error)},
|
||||
#endif
|
||||
#if JS_HAS_REGEXPS
|
||||
{js_InitRegExpClass, ATOM_OFFSET(RegExp)},
|
||||
#endif
|
||||
#if JS_HAS_SCRIPT_OBJECT
|
||||
{js_InitScriptClass, ATOM_OFFSET(Script)},
|
||||
#endif
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
/*
|
||||
* Table of top-level function and constant names and their init functions.
|
||||
* If you add a "standard" global function or property, remember to update
|
||||
* this table.
|
||||
*/
|
||||
typedef struct JSStdName {
|
||||
JSObjectOp init;
|
||||
const char *name; /* tagged (const char *) or atom offset */
|
||||
} JSStdName;
|
||||
|
||||
static JSAtom *
|
||||
StdNameToAtom(JSContext *cx, const char *name)
|
||||
{
|
||||
if (IS_ATOM_OFFSET(name))
|
||||
return OFFSET_TO_ATOM(cx->runtime, UNTAG_ATOM_OFFSET(name));
|
||||
name = UNTAG_CHAR_STRING(name);
|
||||
return js_Atomize(cx, name, strlen(name), 0);
|
||||
}
|
||||
|
||||
static JSStdName standard_class_names[] = {
|
||||
/* ECMA requires that eval be a direct property of the global object. */
|
||||
{js_InitObjectClass, TAG_ATOM_OFFSET(eval)},
|
||||
|
||||
/* Global properties and functions defined by the Number class. */
|
||||
{js_InitNumberClass, TAG_CHAR_STRING(js_NaN_str)},
|
||||
{js_InitNumberClass, TAG_CHAR_STRING(js_Infinity_str)},
|
||||
{js_InitNumberClass, TAG_CHAR_STRING(js_isNaN_str)},
|
||||
{js_InitNumberClass, TAG_CHAR_STRING(js_isFinite_str)},
|
||||
{js_InitNumberClass, TAG_CHAR_STRING(js_parseFloat_str)},
|
||||
{js_InitNumberClass, TAG_CHAR_STRING(js_parseInt_str)},
|
||||
|
||||
/* String global functions. */
|
||||
#ifndef MOZILLA_CLIENT
|
||||
/* These two are predefined in a backward-compatible way by the DOM. */
|
||||
{js_InitStringClass, TAG_CHAR_STRING(js_escape_str)},
|
||||
{js_InitStringClass, TAG_CHAR_STRING(js_unescape_str)},
|
||||
#endif
|
||||
{js_InitStringClass, TAG_CHAR_STRING(js_decodeURI_str)},
|
||||
{js_InitStringClass, TAG_CHAR_STRING(js_encodeURI_str)},
|
||||
{js_InitStringClass, TAG_CHAR_STRING(js_decodeURIComponent_str)},
|
||||
{js_InitStringClass, TAG_CHAR_STRING(js_encodeURIComponent_str)},
|
||||
#if JS_HAS_UNEVAL
|
||||
{js_InitStringClass, TAG_CHAR_STRING(js_uneval_str)},
|
||||
#endif
|
||||
|
||||
/* Exception constructors. */
|
||||
#if JS_HAS_ERROR_EXCEPTIONS
|
||||
{js_InitExceptionClasses, TAG_ATOM_OFFSET(Error)},
|
||||
{js_InitExceptionClasses, TAG_CHAR_STRING(js_InternalError_str)},
|
||||
{js_InitExceptionClasses, TAG_CHAR_STRING(js_EvalError_str)},
|
||||
{js_InitExceptionClasses, TAG_CHAR_STRING(js_RangeError_str)},
|
||||
{js_InitExceptionClasses, TAG_CHAR_STRING(js_ReferenceError_str)},
|
||||
{js_InitExceptionClasses, TAG_CHAR_STRING(js_SyntaxError_str)},
|
||||
{js_InitExceptionClasses, TAG_CHAR_STRING(js_TypeError_str)},
|
||||
{js_InitExceptionClasses, TAG_CHAR_STRING(js_URIError_str)},
|
||||
#endif
|
||||
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static JSStdName object_prototype_names[] = {
|
||||
/* Object.prototype properties (global delegates to Object.prototype). */
|
||||
{js_InitObjectClass, TAG_ATOM_OFFSET(proto)},
|
||||
{js_InitObjectClass, TAG_ATOM_OFFSET(parent)},
|
||||
{js_InitObjectClass, TAG_ATOM_OFFSET(count)},
|
||||
#if JS_HAS_TOSOURCE
|
||||
{js_InitObjectClass, TAG_ATOM_OFFSET(toSource)},
|
||||
#endif
|
||||
{js_InitObjectClass, TAG_ATOM_OFFSET(toString)},
|
||||
{js_InitObjectClass, TAG_ATOM_OFFSET(toLocaleString)},
|
||||
{js_InitObjectClass, TAG_ATOM_OFFSET(valueOf)},
|
||||
#if JS_HAS_OBJ_WATCHPOINT
|
||||
{js_InitObjectClass, TAG_CHAR_STRING(js_watch_str)},
|
||||
{js_InitObjectClass, TAG_CHAR_STRING(js_unwatch_str)},
|
||||
#endif
|
||||
#if JS_HAS_NEW_OBJ_METHODS
|
||||
{js_InitObjectClass, TAG_CHAR_STRING(js_hasOwnProperty_str)},
|
||||
{js_InitObjectClass, TAG_CHAR_STRING(js_isPrototypeOf_str)},
|
||||
{js_InitObjectClass, TAG_CHAR_STRING(js_propertyIsEnumerable_str)},
|
||||
#endif
|
||||
#if JS_HAS_GETTER_SETTER
|
||||
{js_InitObjectClass, TAG_CHAR_STRING(js_defineGetter_str)},
|
||||
{js_InitObjectClass, TAG_CHAR_STRING(js_defineSetter_str)},
|
||||
#endif
|
||||
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_ResolveStandardClass(JSContext *cx, JSObject *obj, jsval id,
|
||||
JSBool *resolved)
|
||||
{
|
||||
JSString *idstr;
|
||||
JSDHashTable *table;
|
||||
JSDHashEntryHdr *entry;
|
||||
JSRuntime *rt;
|
||||
JSAtom *atom;
|
||||
JSObjectOp init;
|
||||
uintN i;
|
||||
JSBool ok;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
*resolved = JS_FALSE;
|
||||
|
||||
if (!JSVAL_IS_STRING(id))
|
||||
return JS_TRUE;
|
||||
idstr = JSVAL_TO_STRING(id);
|
||||
table = cx->resolving;
|
||||
if (table) {
|
||||
entry = JS_DHashTableOperate(table, idstr, JS_DHASH_LOOKUP);
|
||||
if (JS_DHASH_ENTRY_IS_BUSY(entry))
|
||||
return JS_TRUE;
|
||||
}
|
||||
rt = cx->runtime;
|
||||
|
||||
#if JS_HAS_UNDEFINED
|
||||
/* See if we're resolving 'undefined', and define it if so. */
|
||||
atom = rt->atomState.typeAtoms[JSTYPE_VOID];
|
||||
if (idstr == ATOM_TO_STRING(atom)) {
|
||||
*resolved = JS_TRUE;
|
||||
return OBJ_DEFINE_PROPERTY(cx, obj, (jsid)atom, JSVAL_VOID, NULL, NULL,
|
||||
JSPROP_PERMANENT, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Try for class constructors/prototypes named by well-known atoms. */
|
||||
init = NULL;
|
||||
for (i = 0; standard_class_atoms[i].init; i++) {
|
||||
atom = OFFSET_TO_ATOM(rt, standard_class_atoms[i].atomOffset);
|
||||
if (idstr == ATOM_TO_STRING(atom)) {
|
||||
init = standard_class_atoms[i].init;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!init) {
|
||||
/* Try less frequently used top-level functions and constants. */
|
||||
for (i = 0; standard_class_names[i].init; i++) {
|
||||
atom = StdNameToAtom(cx, standard_class_names[i].name);
|
||||
if (idstr == ATOM_TO_STRING(atom)) {
|
||||
init = standard_class_names[i].init;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!init && !OBJ_GET_PROTO(cx, obj)) {
|
||||
/*
|
||||
* Try even less frequently used names delegated from the global
|
||||
* object to Object.prototype, but only if the Object class hasn't
|
||||
* yet been initialized.
|
||||
*/
|
||||
for (i = 0; object_prototype_names[i].init; i++) {
|
||||
atom = StdNameToAtom(cx, object_prototype_names[i].name);
|
||||
if (idstr == ATOM_TO_STRING(atom)) {
|
||||
init = standard_class_names[i].init;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!init) {
|
||||
ok = JS_TRUE;
|
||||
} else {
|
||||
if (!table) {
|
||||
table = JS_NewDHashTable(JS_DHashGetStubOps(),
|
||||
NULL,
|
||||
sizeof(JSDHashEntryStub),
|
||||
JS_DHASH_MIN_SIZE);
|
||||
if (!table)
|
||||
goto outofmem;
|
||||
cx->resolving = table;
|
||||
}
|
||||
entry = JS_DHashTableOperate(table, idstr, JS_DHASH_ADD);
|
||||
if (!entry)
|
||||
goto outofmem;
|
||||
((JSDHashEntryStub *)entry)->key = idstr;
|
||||
|
||||
if (init(cx, obj))
|
||||
ok = *resolved = JS_TRUE;
|
||||
else
|
||||
ok = JS_FALSE;
|
||||
|
||||
JS_DHashTableRawRemove(table, entry);
|
||||
if (table->entryCount == 0) {
|
||||
JS_DHashTableDestroy(table);
|
||||
cx->resolving = NULL;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
|
||||
outofmem:
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
HasOwnProperty(JSContext *cx, JSObject *obj, JSAtom *atom, JSBool *ownp)
|
||||
{
|
||||
JSObject *pobj;
|
||||
JSProperty *prop;
|
||||
|
||||
if (!OBJ_LOOKUP_PROPERTY(cx, obj, (jsid)atom, &pobj, &prop))
|
||||
return JS_FALSE;
|
||||
if (prop)
|
||||
OBJ_DROP_PROPERTY(cx, pobj, prop);
|
||||
*ownp = (pobj == obj && prop);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_EnumerateStandardClasses(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
JSAtom *atom;
|
||||
JSBool found;
|
||||
uintN i;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
rt = cx->runtime;
|
||||
|
||||
#if JS_HAS_UNDEFINED
|
||||
/* See if we need to bind 'undefined' and define it if so. */
|
||||
atom = rt->atomState.typeAtoms[JSTYPE_VOID];
|
||||
if (!HasOwnProperty(cx, obj, atom, &found))
|
||||
return JS_FALSE;
|
||||
if (!found &&
|
||||
!OBJ_DEFINE_PROPERTY(cx, obj, (jsid)atom, JSVAL_VOID, NULL, NULL,
|
||||
JSPROP_PERMANENT, NULL)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Initialize any classes that have not been resolved yet. */
|
||||
for (i = 0; standard_class_atoms[i].init; i++) {
|
||||
atom = OFFSET_TO_ATOM(rt, standard_class_atoms[i].atomOffset);
|
||||
if (!HasOwnProperty(cx, obj, atom, &found))
|
||||
return JS_FALSE;
|
||||
if (!found && !standard_class_atoms[i].init(cx, obj))
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
#undef ATOM_OFFSET
|
||||
#undef OFFSET_TO_ATOM
|
||||
#undef TAG_ATOM_OFFSET
|
||||
#undef TAG_CHAR_STRING
|
||||
#undef UNTAG_ATOM_OFFSET
|
||||
#undef UNTAG_CHAR_STRING
|
||||
#undef IS_ATOM_OFFSET
|
||||
|
||||
JS_PUBLIC_API(JSObject *)
|
||||
JS_GetScopeChain(JSContext *cx)
|
||||
{
|
||||
@@ -1571,21 +1156,10 @@ JS_UnlockGCThing(JSContext *cx, void *thing)
|
||||
return ok;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_MarkGCThing(JSContext *cx, void *thing, const char *name, void *arg)
|
||||
{
|
||||
JS_ASSERT(cx->runtime->gcLevel > 0);
|
||||
#ifdef JS_THREADSAFE
|
||||
JS_ASSERT(cx->runtime->gcThread == js_CurrentThreadId());
|
||||
#endif
|
||||
|
||||
GC_MARK(cx, thing, name, arg);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_GC(JSContext *cx)
|
||||
{
|
||||
if (cx->stackPool.current == &cx->stackPool.first)
|
||||
if (!cx->fp)
|
||||
JS_FinishArenaPool(&cx->stackPool);
|
||||
JS_FinishArenaPool(&cx->codePool);
|
||||
JS_FinishArenaPool(&cx->tempPool);
|
||||
@@ -1628,41 +1202,6 @@ JS_SetGCCallbackRT(JSRuntime *rt, JSGCCallback cb)
|
||||
return oldcb;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_IsAboutToBeFinalized(JSContext *cx, void *thing)
|
||||
{
|
||||
JS_ASSERT(thing);
|
||||
return js_IsAboutToBeFinalized(cx, thing);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(intN)
|
||||
JS_AddExternalStringFinalizer(JSStringFinalizeOp finalizer)
|
||||
{
|
||||
return js_ChangeExternalStringFinalizer(NULL, finalizer);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(intN)
|
||||
JS_RemoveExternalStringFinalizer(JSStringFinalizeOp finalizer)
|
||||
{
|
||||
return js_ChangeExternalStringFinalizer(finalizer, NULL);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSString *)
|
||||
JS_NewExternalString(JSContext *cx, jschar *chars, size_t length, intN type)
|
||||
{
|
||||
JSString *str;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
JS_ASSERT(GCX_EXTERNAL_STRING <= type && type < (intN) GCX_NTYPES);
|
||||
|
||||
str = (JSString *) js_AllocGCThing(cx, (uintN) type);
|
||||
if (!str)
|
||||
return NULL;
|
||||
str->length = length;
|
||||
str->chars = chars;
|
||||
return str;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
@@ -1970,7 +1509,6 @@ DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value,
|
||||
if (attrs & JSPROP_INDEX) {
|
||||
id = INT_TO_JSVAL((jsint)name);
|
||||
atom = NULL;
|
||||
attrs &= ~JSPROP_INDEX;
|
||||
} else {
|
||||
atom = js_Atomize(cx, name, strlen(name), 0);
|
||||
if (!atom)
|
||||
@@ -2027,9 +1565,22 @@ JS_DefineConstDoubles(JSContext *cx, JSObject *obj, JSConstDoubleSpec *cds)
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
for (ok = JS_TRUE; cds->name; cds++) {
|
||||
#if JS_ALIGN_OF_DOUBLE == 8
|
||||
/*
|
||||
* The GC ignores references outside its pool such as &cds->dval,
|
||||
* so we don't need to GC-alloc constant doubles.
|
||||
*/
|
||||
jsdouble d = cds->dval;
|
||||
jsint i;
|
||||
|
||||
value = (JSDOUBLE_IS_INT(d, i) && INT_FITS_IN_JSVAL(i))
|
||||
? INT_TO_JSVAL(i)
|
||||
: DOUBLE_TO_JSVAL(&cds->dval);
|
||||
#else
|
||||
ok = js_NewNumberValue(cx, cds->dval, &value);
|
||||
if (!ok)
|
||||
break;
|
||||
#endif
|
||||
flags = cds->flags;
|
||||
if (!flags)
|
||||
flags = JSPROP_READONLY | JSPROP_PERMANENT;
|
||||
@@ -2057,12 +1608,7 @@ JS_DefineProperties(JSContext *cx, JSObject *obj, JSPropertySpec *ps)
|
||||
if (prop) {
|
||||
if (OBJ_IS_NATIVE(obj)) {
|
||||
sprop = (JSScopeProperty *)prop;
|
||||
#ifdef JS_DOUBLE_HASHING
|
||||
sprop->attrs |= JSPROP_INDEX;
|
||||
sprop->tinyid = ps->tinyid;
|
||||
#else
|
||||
sprop->id = INT_TO_JSVAL(ps->tinyid);
|
||||
#endif
|
||||
}
|
||||
OBJ_DROP_PROPERTY(cx, obj, prop);
|
||||
}
|
||||
@@ -2093,12 +1639,7 @@ JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name,
|
||||
if (ok && prop) {
|
||||
if (OBJ_IS_NATIVE(obj)) {
|
||||
sprop = (JSScopeProperty *)prop;
|
||||
#ifdef JS_DOUBLE_HASHING
|
||||
sprop->attrs |= JSPROP_INDEX;
|
||||
sprop->tinyid = tinyid;
|
||||
#else
|
||||
sprop->id = INT_TO_JSVAL(tinyid);
|
||||
#endif
|
||||
}
|
||||
OBJ_DROP_PROPERTY(cx, obj, prop);
|
||||
}
|
||||
@@ -2179,9 +1720,7 @@ LookupResult(JSContext *cx, JSObject *obj, JSObject *obj2, JSProperty *prop)
|
||||
if (OBJ_IS_NATIVE(obj2)) {
|
||||
/* Peek at the native property's slot value, without doing a Get. */
|
||||
sprop = (JSScopeProperty *)prop;
|
||||
rval = (SPROP_HAS_VALID_SLOT(sprop))
|
||||
? LOCKED_OBJ_GET_SLOT(obj2, sprop->slot)
|
||||
: JSVAL_TRUE;
|
||||
rval = LOCKED_OBJ_GET_SLOT(obj2, sprop->slot);
|
||||
} else {
|
||||
/* XXX bad API: no way to return "defined but value unknown" */
|
||||
rval = JSVAL_TRUE;
|
||||
@@ -2371,12 +1910,7 @@ JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj,
|
||||
if (ok && prop) {
|
||||
if (OBJ_IS_NATIVE(obj)) {
|
||||
sprop = (JSScopeProperty *)prop;
|
||||
#ifdef JS_DOUBLE_HASHING
|
||||
sprop->attrs |= JSPROP_INDEX;
|
||||
sprop->tinyid = tinyid;
|
||||
#else
|
||||
sprop->id = INT_TO_JSVAL(tinyid);
|
||||
#endif
|
||||
}
|
||||
OBJ_DROP_PROPERTY(cx, obj, prop);
|
||||
}
|
||||
@@ -2565,10 +2099,25 @@ JS_DeleteElement2(JSContext *cx, JSObject *obj, jsint index, jsval *rval)
|
||||
JS_PUBLIC_API(void)
|
||||
JS_ClearScope(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
JSObjectMap *map;
|
||||
JSScope *scope;
|
||||
uint32 i;
|
||||
|
||||
if (obj->map->ops->clear)
|
||||
obj->map->ops->clear(cx, obj);
|
||||
CHECK_REQUEST(cx);
|
||||
/* XXXbe push this into jsobj.c or jsscope.c */
|
||||
/* XXXbe2 worse, assumes obj is native here, before MAP_IS_NATIVE! */
|
||||
JS_LOCK_OBJ(cx, obj);
|
||||
map = obj->map;
|
||||
if (MAP_IS_NATIVE(map)) {
|
||||
scope = (JSScope *)map;
|
||||
scope->ops->clear(cx, scope);
|
||||
}
|
||||
|
||||
/* Clear slot values and reset freeslot so we're consistent. */
|
||||
map->freeslot = JSSLOT_FREE(OBJ_GET_CLASS(cx, obj));
|
||||
for (i = map->nslots-1; i >= map->freeslot; --i)
|
||||
obj->slots[i] = JSVAL_VOID;
|
||||
JS_UNLOCK_OBJ(cx, obj);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSIdArray *)
|
||||
@@ -3114,7 +2663,7 @@ JS_PUBLIC_API(JSBool)
|
||||
JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
if (!js_Execute(cx, obj, script, NULL, 0, rval)) {
|
||||
if (!js_Execute(cx, obj, script, NULL, NULL, 0, rval)) {
|
||||
#if JS_HAS_EXCEPTIONS
|
||||
js_ReportUncaughtException(cx);
|
||||
#endif
|
||||
@@ -3218,7 +2767,7 @@ JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj,
|
||||
filename, lineno);
|
||||
if (!script)
|
||||
return JS_FALSE;
|
||||
ok = js_Execute(cx, obj, script, NULL, 0, rval);
|
||||
ok = js_Execute(cx, obj, script, NULL, NULL, 0, rval);
|
||||
#if JS_HAS_EXCEPTIONS
|
||||
if (!ok)
|
||||
js_ReportUncaughtException(cx);
|
||||
@@ -3298,28 +2847,6 @@ JS_IsConstructing(JSContext *cx)
|
||||
return cx->fp && cx->fp->constructing;
|
||||
}
|
||||
|
||||
JS_FRIEND_API(JSBool)
|
||||
JS_IsAssigning(JSContext *cx)
|
||||
{
|
||||
JSStackFrame *fp;
|
||||
jsbytecode *pc;
|
||||
|
||||
for (fp = cx->fp; fp && !fp->script; fp = fp->down)
|
||||
;
|
||||
if (!fp || !(pc = fp->pc))
|
||||
return JS_FALSE;
|
||||
return (js_CodeSpec[*pc].format & JOF_SET) != 0;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_SetCallReturnValue2(JSContext *cx, jsval v)
|
||||
{
|
||||
#if JS_HAS_LVALUE_RETURN
|
||||
cx->rval2 = v;
|
||||
cx->rval2set = JS_TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
JS_PUBLIC_API(JSString *)
|
||||
@@ -3389,7 +2916,7 @@ JS_InternString(JSContext *cx, const char *s)
|
||||
JSAtom *atom;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
atom = js_Atomize(cx, s, strlen(s), ATOM_INTERNED);
|
||||
atom = js_Atomize(cx, s, strlen(s), ATOM_PINNED);
|
||||
if (!atom)
|
||||
return NULL;
|
||||
return ATOM_TO_STRING(atom);
|
||||
@@ -3424,7 +2951,7 @@ JS_InternUCStringN(JSContext *cx, const jschar *s, size_t length)
|
||||
JSAtom *atom;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
atom = js_AtomizeChars(cx, s, length, ATOM_INTERNED);
|
||||
atom = js_AtomizeChars(cx, s, length, ATOM_PINNED);
|
||||
if (!atom)
|
||||
return NULL;
|
||||
return ATOM_TO_STRING(atom);
|
||||
@@ -3547,7 +3074,7 @@ JS_ReportErrorFlagsAndNumberUC(JSContext *cx, uintN flags,
|
||||
JS_PUBLIC_API(void)
|
||||
JS_ReportOutOfMemory(JSContext *cx)
|
||||
{
|
||||
js_ReportOutOfMemory(cx, js_GetErrorMessage);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSErrorReporter)
|
||||
@@ -3701,7 +3228,8 @@ JS_ClearPendingException(JSContext *cx)
|
||||
}
|
||||
|
||||
#if JS_HAS_EXCEPTIONS
|
||||
struct JSExceptionState {
|
||||
struct JSExceptionState
|
||||
{
|
||||
JSBool throwing;
|
||||
jsval exception;
|
||||
};
|
||||
@@ -3712,13 +3240,12 @@ JS_SaveExceptionState(JSContext *cx)
|
||||
{
|
||||
#if JS_HAS_EXCEPTIONS
|
||||
JSExceptionState *state;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
state = (JSExceptionState *) JS_malloc(cx, sizeof(JSExceptionState));
|
||||
if (state) {
|
||||
state->throwing = JS_GetPendingException(cx, &state->exception);
|
||||
if (state->throwing && JSVAL_IS_GCTHING(state->exception))
|
||||
js_AddRoot(cx, &state->exception, "JSExceptionState.exception");
|
||||
JS_AddRoot(cx, &state->exception);
|
||||
}
|
||||
return state;
|
||||
#else
|
||||
@@ -3791,6 +3318,19 @@ JS_ClearContextThread(JSContext *cx)
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
JS_FRIEND_API(JSBool)
|
||||
JS_IsAssigning(JSContext *cx)
|
||||
{
|
||||
JSStackFrame *fp;
|
||||
jsbytecode *pc;
|
||||
|
||||
if (!(fp = cx->fp) || !(pc = fp->pc))
|
||||
return JS_FALSE;
|
||||
return (js_CodeSpec[*pc].format & JOF_SET) != 0;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
#ifdef XP_PC
|
||||
#if defined(XP_OS2)
|
||||
/*DSR031297 - the OS/2 equiv is dll_InitTerm, but I don't see the need for it*/
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* 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
|
||||
@@ -83,11 +83,11 @@ JS_BEGIN_EXTERN_C
|
||||
|
||||
/* Lock and unlock the GC thing held by a jsval. */
|
||||
#define JSVAL_LOCK(cx,v) (JSVAL_IS_GCTHING(v) \
|
||||
? JS_LockGCThing(cx, JSVAL_TO_GCTHING(v)) \
|
||||
: JS_TRUE)
|
||||
? JS_LockGCThing(cx, JSVAL_TO_GCTHING(v)) \
|
||||
: JS_TRUE)
|
||||
#define JSVAL_UNLOCK(cx,v) (JSVAL_IS_GCTHING(v) \
|
||||
? JS_UnlockGCThing(cx, JSVAL_TO_GCTHING(v)) \
|
||||
: JS_TRUE)
|
||||
? JS_UnlockGCThing(cx, JSVAL_TO_GCTHING(v)) \
|
||||
: JS_TRUE)
|
||||
|
||||
/* Domain limits for the jsval int type. */
|
||||
#define JSVAL_INT_POW2(n) ((jsval)1 << (n))
|
||||
@@ -100,7 +100,7 @@ JS_BEGIN_EXTERN_C
|
||||
/* Convert between boolean and jsval. */
|
||||
#define JSVAL_TO_BOOLEAN(v) ((JSBool)((v) >> JSVAL_TAGBITS))
|
||||
#define BOOLEAN_TO_JSVAL(b) JSVAL_SETTAG((jsval)(b) << JSVAL_TAGBITS, \
|
||||
JSVAL_BOOLEAN)
|
||||
JSVAL_BOOLEAN)
|
||||
|
||||
/* A private data pointer (2-byte-aligned) can be stored as an int jsval. */
|
||||
#define JSVAL_TO_PRIVATE(v) ((void *)((v) & ~JSVAL_INT))
|
||||
@@ -113,11 +113,7 @@ JS_BEGIN_EXTERN_C
|
||||
#define JSPROP_EXPORTED 0x08 /* property is exported from object */
|
||||
#define JSPROP_GETTER 0x10 /* property holds getter function */
|
||||
#define JSPROP_SETTER 0x20 /* property holds setter function */
|
||||
#define JSPROP_SHARED 0x40 /* don't allocate a value slot for this
|
||||
property; don't copy the property on
|
||||
set of the same-named property in an
|
||||
object that delegates to a prototype
|
||||
containing this property */
|
||||
#define JSPROP_SHARED 0x40 /* don't copy proto-property on set */
|
||||
#define JSPROP_INDEX 0x80 /* name is actually (jsint) index */
|
||||
|
||||
/* Function flags, set in JSFunctionSpec and passed to JS_NewFunction etc. */
|
||||
@@ -186,12 +182,12 @@ JS_GetEmptyStringValue(JSContext *cx);
|
||||
*/
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_ConvertArguments(JSContext *cx, uintN argc, jsval *argv, const char *format,
|
||||
...);
|
||||
...);
|
||||
|
||||
#ifdef va_start
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_ConvertArgumentsVA(JSContext *cx, uintN argc, jsval *argv,
|
||||
const char *format, va_list ap);
|
||||
const char *format, va_list ap);
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -258,7 +254,7 @@ JS_PopArguments(JSContext *cx, void *mark);
|
||||
*/
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_AddArgumentFormatter(JSContext *cx, const char *format,
|
||||
JSArgumentFormatter formatter);
|
||||
JSArgumentFormatter formatter);
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_RemoveArgumentFormatter(JSContext *cx, const char *format);
|
||||
@@ -357,11 +353,11 @@ JS_EndRequest(JSContext *cx);
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_YieldRequest(JSContext *cx);
|
||||
|
||||
extern JS_PUBLIC_API(jsrefcount)
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_SuspendRequest(JSContext *cx);
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_ResumeRequest(JSContext *cx, jsrefcount saveDepth);
|
||||
JS_ResumeRequest(JSContext *cx);
|
||||
|
||||
#endif /* JS_THREADSAFE */
|
||||
|
||||
@@ -410,16 +406,9 @@ JS_StringToVersion(const char *string);
|
||||
/*
|
||||
* JS options are orthogonal to version, and may be freely composed with one
|
||||
* another as well as with version.
|
||||
*
|
||||
* JSOPTION_VAROBJFIX is recommended -- see the comments associated with the
|
||||
* prototypes for JS_ExecuteScript, JS_EvaluateScript, etc.
|
||||
*/
|
||||
#define JSOPTION_STRICT JS_BIT(0) /* warn on dubious practice */
|
||||
#define JSOPTION_WERROR JS_BIT(1) /* convert warning to error */
|
||||
#define JSOPTION_VAROBJFIX JS_BIT(2) /* make JS_EvaluateScript use
|
||||
the last object on its 'obj'
|
||||
param's scope chain as the
|
||||
ECMA 'variables object' */
|
||||
|
||||
extern JS_PUBLIC_API(uint32)
|
||||
JS_GetOptions(JSContext *cx);
|
||||
@@ -439,36 +428,10 @@ JS_GetGlobalObject(JSContext *cx);
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_SetGlobalObject(JSContext *cx, JSObject *obj);
|
||||
|
||||
/*
|
||||
* Initialize standard JS class constructors, prototypes, and any top-level
|
||||
* functions and constants associated with the standard classes (e.g. isNaN
|
||||
* for Number).
|
||||
*
|
||||
* NB: This sets cx's global object to obj if it was null.
|
||||
*/
|
||||
/* NB: This sets cx's global object to obj if it was null. */
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_InitStandardClasses(JSContext *cx, JSObject *obj);
|
||||
|
||||
/*
|
||||
* Resolve id, which must contain either a string or an int, to a standard
|
||||
* class name in obj if possible, defining the class's constructor and/or
|
||||
* prototype and storing true in *resolved. If id does not name a standard
|
||||
* class or a top-level property induced by initializing a standard class,
|
||||
* store false in *resolved and just return true. Return false on error,
|
||||
* as usual for JSBool result-typed API entry points.
|
||||
*
|
||||
* This API can be called directly from a global object class's resolve op,
|
||||
* to define standard classes lazily. The class's enumerate op should call
|
||||
* JS_EnumerateStandardClasses(cx, obj), to define eagerly during for..in
|
||||
* loops any classes not yet resolved lazily.
|
||||
*/
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_ResolveStandardClass(JSContext *cx, JSObject *obj, jsval id,
|
||||
JSBool *resolved);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_EnumerateStandardClasses(JSContext *cx, JSObject *obj);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
JS_GetScopeChain(JSContext *cx);
|
||||
|
||||
@@ -524,8 +487,8 @@ JS_AddNamedRoot(JSContext *cx, void *rp, const char *name);
|
||||
#ifdef DEBUG
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_DumpNamedRoots(JSRuntime *rt,
|
||||
void (*dump)(const char *name, void *rp, void *data),
|
||||
void *data);
|
||||
void (*dump)(const char *name, void *rp, void *data),
|
||||
void *data);
|
||||
#endif
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
@@ -534,22 +497,6 @@ JS_LockGCThing(JSContext *cx, void *thing);
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_UnlockGCThing(JSContext *cx, void *thing);
|
||||
|
||||
/*
|
||||
* For implementors of JSObjectOps.mark, to mark a GC-thing reachable via a
|
||||
* property or other strong ref identified for debugging purposes by name.
|
||||
* The name argument's storage needs to live only as long as the call to
|
||||
* this routine.
|
||||
*
|
||||
* The final arg is used by GC_MARK_DEBUG code to build a ref path through
|
||||
* the GC's live thing graph. Implementors of JSObjectOps.mark should pass
|
||||
* its final arg through to this function when marking all GC-things that are
|
||||
* directly reachable from the object being marked.
|
||||
*
|
||||
* See the JSMarkOp typedef in jspubtd.h, and the JSObjectOps struct below.
|
||||
*/
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_MarkGCThing(JSContext *cx, void *thing, const char *name, void *arg);
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_GC(JSContext *cx);
|
||||
|
||||
@@ -562,55 +509,13 @@ JS_SetGCCallback(JSContext *cx, JSGCCallback cb);
|
||||
extern JS_PUBLIC_API(JSGCCallback)
|
||||
JS_SetGCCallbackRT(JSRuntime *rt, JSGCCallback cb);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_IsAboutToBeFinalized(JSContext *cx, void *thing);
|
||||
|
||||
/*
|
||||
* Add an external string finalizer, one created by JS_NewExternalString (see
|
||||
* below) using a type-code returned from this function, and that understands
|
||||
* how to free or release the memory pointed at by JS_GetStringChars(str).
|
||||
*
|
||||
* Return a nonnegative type index if there is room for finalizer in the
|
||||
* global GC finalizers table, else return -1. If the engine is compiled
|
||||
* JS_THREADSAFE and used in a multi-threaded environment, this function must
|
||||
* be invoked on the primordial thread only, at startup -- or else the entire
|
||||
* program must single-thread itself while loading a module that calls this
|
||||
* function.
|
||||
*/
|
||||
extern JS_PUBLIC_API(intN)
|
||||
JS_AddExternalStringFinalizer(JSStringFinalizeOp finalizer);
|
||||
|
||||
/*
|
||||
* Remove finalizer from the global GC finalizers table, returning its type
|
||||
* code if found, -1 if not found.
|
||||
*
|
||||
* As with JS_AddExternalStringFinalizer, there is a threading restriction
|
||||
* if you compile the engine JS_THREADSAFE: this function may be called for a
|
||||
* given finalizer pointer on only one thread; different threads may call to
|
||||
* remove distinct finalizers safely.
|
||||
*
|
||||
* You must ensure that all strings with finalizer's type have been collected
|
||||
* before calling this function. Otherwise, string data will be leaked by the
|
||||
* GC, for want of a finalizer to call.
|
||||
*/
|
||||
extern JS_PUBLIC_API(intN)
|
||||
JS_RemoveExternalStringFinalizer(JSStringFinalizeOp finalizer);
|
||||
|
||||
/*
|
||||
* Create a new JSString whose chars member refers to external memory, i.e.,
|
||||
* memory requiring special, type-specific finalization. The type code must
|
||||
* be a nonnegative return value from JS_AddExternalStringFinalizer.
|
||||
*/
|
||||
extern JS_PUBLIC_API(JSString *)
|
||||
JS_NewExternalString(JSContext *cx, jschar *chars, size_t length, intN type);
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
/*
|
||||
* Classes, objects, and properties.
|
||||
*/
|
||||
struct JSClass {
|
||||
const char *name;
|
||||
char *name;
|
||||
uint32 flags;
|
||||
|
||||
/* Mandatory non-null function pointer members. */
|
||||
@@ -630,18 +535,16 @@ struct JSClass {
|
||||
JSNative construct;
|
||||
JSXDRObjectOp xdrObject;
|
||||
JSHasInstanceOp hasInstance;
|
||||
JSMarkOp mark;
|
||||
jsword spare;
|
||||
jsword spare[2];
|
||||
};
|
||||
|
||||
#define JSCLASS_HAS_PRIVATE 0x01 /* objects have private slot */
|
||||
#define JSCLASS_NEW_ENUMERATE 0x02 /* has JSNewEnumerateOp hook */
|
||||
#define JSCLASS_NEW_RESOLVE 0x04 /* has JSNewResolveOp hook */
|
||||
#define JSCLASS_PRIVATE_IS_NSISUPPORTS 0x08 /* private is (nsISupports *) */
|
||||
#define JSCLASS_SHARE_ALL_PROPERTIES 0x10 /* all properties are SHARED */
|
||||
|
||||
/* Initializer for unused members of statically initialized JSClass structs. */
|
||||
#define JSCLASS_NO_OPTIONAL_MEMBERS 0,0,0,0,0,0,0,0
|
||||
#define JSCLASS_HAS_PRIVATE 0x01 /* class instances have private slot */
|
||||
#define JSCLASS_NEW_ENUMERATE 0x02 /* class has JSNewEnumerateOp method */
|
||||
#define JSCLASS_NEW_RESOLVE 0x04 /* class has JSNewResolveOp method */
|
||||
#define JSCLASS_PRIVATE_IS_NSISUPPORTS 0x08 /* private slot is nsISupports* */
|
||||
/* Fill in null values for unused members. */
|
||||
#define JSCLASS_NO_OPTIONAL_MEMBERS \
|
||||
0,0,0,0,0,0,{0,0}
|
||||
|
||||
struct JSObjectOps {
|
||||
/* Mandatory non-null function pointer members. */
|
||||
@@ -667,10 +570,10 @@ struct JSObjectOps {
|
||||
JSHasInstanceOp hasInstance;
|
||||
JSSetObjectSlotOp setProto;
|
||||
JSSetObjectSlotOp setParent;
|
||||
JSMarkOp mark;
|
||||
JSFinalizeOp clear;
|
||||
jsword spare1;
|
||||
jsword spare2;
|
||||
jsword spare3;
|
||||
jsword spare4;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -749,9 +652,9 @@ struct JSFunctionSpec {
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
|
||||
JSClass *clasp, JSNative constructor, uintN nargs,
|
||||
JSPropertySpec *ps, JSFunctionSpec *fs,
|
||||
JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
|
||||
JSClass *clasp, JSNative constructor, uintN nargs,
|
||||
JSPropertySpec *ps, JSFunctionSpec *fs,
|
||||
JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
extern JS_PUBLIC_API(JSClass *)
|
||||
@@ -776,7 +679,7 @@ JS_SetPrivate(JSContext *cx, JSObject *obj, void *data);
|
||||
|
||||
extern JS_PUBLIC_API(void *)
|
||||
JS_GetInstancePrivate(JSContext *cx, JSObject *obj, JSClass *clasp,
|
||||
jsval *argv);
|
||||
jsval *argv);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
JS_GetPrototype(JSContext *cx, JSObject *obj);
|
||||
@@ -798,11 +701,11 @@ JS_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
JS_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto,
|
||||
JSObject *parent);
|
||||
JSObject *parent);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, JSClass *clasp,
|
||||
JSObject *proto, uintN attrs);
|
||||
JSObject *proto, uintN attrs);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_DefineConstDoubles(JSContext *cx, JSObject *obj, JSConstDoubleSpec *cds);
|
||||
@@ -812,7 +715,7 @@ JS_DefineProperties(JSContext *cx, JSObject *obj, JSPropertySpec *ps);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value,
|
||||
JSPropertyOp getter, JSPropertyOp setter, uintN attrs);
|
||||
JSPropertyOp getter, JSPropertyOp setter, uintN attrs);
|
||||
|
||||
/*
|
||||
* Determine the attributes (JSPROP_* flags) of a property on a given object.
|
||||
@@ -822,7 +725,7 @@ JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value,
|
||||
*/
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_GetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
|
||||
uintN *attrsp, JSBool *foundp);
|
||||
uintN *attrsp, JSBool *foundp);
|
||||
|
||||
/*
|
||||
* Set the attributes of a property on a given object.
|
||||
@@ -832,17 +735,17 @@ JS_GetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
|
||||
*/
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_SetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
|
||||
uintN attrs, JSBool *foundp);
|
||||
uintN attrs, JSBool *foundp);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name,
|
||||
int8 tinyid, jsval value,
|
||||
JSPropertyOp getter, JSPropertyOp setter,
|
||||
uintN attrs);
|
||||
int8 tinyid, jsval value,
|
||||
JSPropertyOp getter, JSPropertyOp setter,
|
||||
uintN attrs);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_AliasProperty(JSContext *cx, JSObject *obj, const char *name,
|
||||
const char *alias);
|
||||
const char *alias);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
|
||||
@@ -858,13 +761,13 @@ JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char *name,
|
||||
jsval *rval);
|
||||
jsval *rval);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_DefineUCProperty(JSContext *cx, JSObject *obj,
|
||||
const jschar *name, size_t namelen, jsval value,
|
||||
JSPropertyOp getter, JSPropertyOp setter,
|
||||
uintN attrs);
|
||||
const jschar *name, size_t namelen, jsval value,
|
||||
JSPropertyOp getter, JSPropertyOp setter,
|
||||
uintN attrs);
|
||||
|
||||
/*
|
||||
* Determine the attributes (JSPROP_* flags) of a property on a given object.
|
||||
@@ -874,8 +777,8 @@ JS_DefineUCProperty(JSContext *cx, JSObject *obj,
|
||||
*/
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_GetUCPropertyAttributes(JSContext *cx, JSObject *obj,
|
||||
const jschar *name, size_t namelen,
|
||||
uintN *attrsp, JSBool *foundp);
|
||||
const jschar *name, size_t namelen,
|
||||
uintN *attrsp, JSBool *foundp);
|
||||
|
||||
/*
|
||||
* Set the attributes of a property on a given object.
|
||||
@@ -885,36 +788,36 @@ JS_GetUCPropertyAttributes(JSContext *cx, JSObject *obj,
|
||||
*/
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_SetUCPropertyAttributes(JSContext *cx, JSObject *obj,
|
||||
const jschar *name, size_t namelen,
|
||||
uintN attrs, JSBool *foundp);
|
||||
const jschar *name, size_t namelen,
|
||||
uintN attrs, JSBool *foundp);
|
||||
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj,
|
||||
const jschar *name, size_t namelen,
|
||||
int8 tinyid, jsval value,
|
||||
JSPropertyOp getter, JSPropertyOp setter,
|
||||
uintN attrs);
|
||||
const jschar *name, size_t namelen,
|
||||
int8 tinyid, jsval value,
|
||||
JSPropertyOp getter, JSPropertyOp setter,
|
||||
uintN attrs);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_LookupUCProperty(JSContext *cx, JSObject *obj,
|
||||
const jschar *name, size_t namelen,
|
||||
jsval *vp);
|
||||
const jschar *name, size_t namelen,
|
||||
jsval *vp);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_GetUCProperty(JSContext *cx, JSObject *obj,
|
||||
const jschar *name, size_t namelen,
|
||||
jsval *vp);
|
||||
const jschar *name, size_t namelen,
|
||||
jsval *vp);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_SetUCProperty(JSContext *cx, JSObject *obj,
|
||||
const jschar *name, size_t namelen,
|
||||
jsval *vp);
|
||||
const jschar *name, size_t namelen,
|
||||
jsval *vp);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_DeleteUCProperty2(JSContext *cx, JSObject *obj,
|
||||
const jschar *name, size_t namelen,
|
||||
jsval *rval);
|
||||
const jschar *name, size_t namelen,
|
||||
jsval *rval);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
JS_NewArrayObject(JSContext *cx, jsint length, jsval *vector);
|
||||
@@ -933,7 +836,7 @@ JS_HasArrayLength(JSContext *cx, JSObject *obj, jsuint *lengthp);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_DefineElement(JSContext *cx, JSObject *obj, jsint index, jsval value,
|
||||
JSPropertyOp getter, JSPropertyOp setter, uintN attrs);
|
||||
JSPropertyOp getter, JSPropertyOp setter, uintN attrs);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_AliasElement(JSContext *cx, JSObject *obj, const char *name, jsint alias);
|
||||
@@ -961,7 +864,7 @@ JS_Enumerate(JSContext *cx, JSObject *obj);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
|
||||
jsval *vp, uintN *attrsp);
|
||||
jsval *vp, uintN *attrsp);
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
@@ -982,8 +885,8 @@ typedef struct JSPrincipals {
|
||||
((principals)->refcount++)
|
||||
#define JSPRINCIPALS_DROP(cx, principals) \
|
||||
((--((principals)->refcount) == 0) \
|
||||
? (*(principals)->destroy)((cx), (principals)) \
|
||||
: (void) 0)
|
||||
? (*(principals)->destroy)((cx), (principals)) \
|
||||
: (void) 0)
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
@@ -992,7 +895,7 @@ typedef struct JSPrincipals {
|
||||
*/
|
||||
extern JS_PUBLIC_API(JSFunction *)
|
||||
JS_NewFunction(JSContext *cx, JSNative call, uintN nargs, uintN flags,
|
||||
JSObject *parent, const char *name);
|
||||
JSObject *parent, const char *name);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
JS_GetFunctionObject(JSFunction *fun);
|
||||
@@ -1005,7 +908,7 @@ JS_DefineFunctions(JSContext *cx, JSObject *obj, JSFunctionSpec *fs);
|
||||
|
||||
extern JS_PUBLIC_API(JSFunction *)
|
||||
JS_DefineFunction(JSContext *cx, JSObject *obj, const char *name, JSNative call,
|
||||
uintN nargs, uintN attrs);
|
||||
uintN nargs, uintN attrs);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent);
|
||||
@@ -1030,25 +933,25 @@ JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj,
|
||||
*/
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileScript(JSContext *cx, JSObject *obj,
|
||||
const char *bytes, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
const char *bytes, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj,
|
||||
JSPrincipals *principals,
|
||||
const char *bytes, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
JSPrincipals *principals,
|
||||
const char *bytes, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileUCScript(JSContext *cx, JSObject *obj,
|
||||
const jschar *chars, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
const jschar *chars, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj,
|
||||
JSPrincipals *principals,
|
||||
const jschar *chars, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
JSPrincipals *principals,
|
||||
const jschar *chars, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_CompileFile(JSContext *cx, JSObject *obj, const char *filename);
|
||||
@@ -1086,33 +989,33 @@ JS_DestroyScript(JSContext *cx, JSScript *script);
|
||||
|
||||
extern JS_PUBLIC_API(JSFunction *)
|
||||
JS_CompileFunction(JSContext *cx, JSObject *obj, const char *name,
|
||||
uintN nargs, const char **argnames,
|
||||
const char *bytes, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
uintN nargs, const char **argnames,
|
||||
const char *bytes, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
|
||||
extern JS_PUBLIC_API(JSFunction *)
|
||||
JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *obj,
|
||||
JSPrincipals *principals, const char *name,
|
||||
uintN nargs, const char **argnames,
|
||||
const char *bytes, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
JSPrincipals *principals, const char *name,
|
||||
uintN nargs, const char **argnames,
|
||||
const char *bytes, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
|
||||
extern JS_PUBLIC_API(JSFunction *)
|
||||
JS_CompileUCFunction(JSContext *cx, JSObject *obj, const char *name,
|
||||
uintN nargs, const char **argnames,
|
||||
const jschar *chars, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
uintN nargs, const char **argnames,
|
||||
const jschar *chars, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
|
||||
extern JS_PUBLIC_API(JSFunction *)
|
||||
JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj,
|
||||
JSPrincipals *principals, const char *name,
|
||||
uintN nargs, const char **argnames,
|
||||
const jschar *chars, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
JSPrincipals *principals, const char *name,
|
||||
uintN nargs, const char **argnames,
|
||||
const jschar *chars, size_t length,
|
||||
const char *filename, uintN lineno);
|
||||
|
||||
extern JS_PUBLIC_API(JSString *)
|
||||
JS_DecompileScript(JSContext *cx, JSScript *script, const char *name,
|
||||
uintN indent);
|
||||
uintN indent);
|
||||
|
||||
/*
|
||||
* API extension: OR this into indent to avoid pretty-printing the decompiled
|
||||
@@ -1126,41 +1029,6 @@ JS_DecompileFunction(JSContext *cx, JSFunction *fun, uintN indent);
|
||||
extern JS_PUBLIC_API(JSString *)
|
||||
JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, uintN indent);
|
||||
|
||||
/*
|
||||
* NB: JS_ExecuteScript, JS_ExecuteScriptPart, and the JS_Evaluate*Script*
|
||||
* quadruplets all use the obj parameter as the initial scope chain header,
|
||||
* the 'this' keyword value, and the variables object (ECMA parlance for where
|
||||
* 'var' and 'function' bind names) of the execution context for script.
|
||||
*
|
||||
* Using obj as the variables object is problematic if obj's parent (which is
|
||||
* the scope chain link; see JS_SetParent and JS_NewObject) is not null: in
|
||||
* this case, variables created by 'var x = 0', e.g., go in obj, but variables
|
||||
* created by assignment to an unbound id, 'x = 0', go in the last object on
|
||||
* the scope chain linked by parent.
|
||||
*
|
||||
* ECMA calls that last scoping object the "global object", but note that many
|
||||
* embeddings have several such objects. ECMA requires that "global code" be
|
||||
* executed with the variables object equal to this global object. But these
|
||||
* JS API entry points provide freedom to execute code against a "sub-global",
|
||||
* i.e., a parented or scoped object, in which case the variables object will
|
||||
* differ from the last object on the scope chain, resulting in confusing and
|
||||
* non-ECMA explicit vs. implicit variable creation.
|
||||
*
|
||||
* Caveat embedders: unless you already depend on this buggy variables object
|
||||
* binding behavior, you should call JS_SetOptions(cx, JSOPTION_VAROBJFIX) or
|
||||
* JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_VAROBJFIX) -- the latter if
|
||||
* someone may have set other options on cx already -- for each context in the
|
||||
* application, if you pass parented objects as the obj parameter, or may ever
|
||||
* pass such objects in the future.
|
||||
*
|
||||
* Why a runtime option? The alternative is to add six or so new API entry
|
||||
* points with signatures matching the following six, and that doesn't seem
|
||||
* worth the code bloat cost. Such new entry points would probably have less
|
||||
* obvious names, too, so would not tend to be used. The JS_SetOption call,
|
||||
* OTOH, can be more easily hacked into existing code that does not depend on
|
||||
* the bug; such code can continue to use the familiar JS_EvaluateScript,
|
||||
* etc., entry points.
|
||||
*/
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval);
|
||||
|
||||
@@ -1176,41 +1044,41 @@ JS_ExecuteScriptPart(JSContext *cx, JSObject *obj, JSScript *script,
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_EvaluateScript(JSContext *cx, JSObject *obj,
|
||||
const char *bytes, uintN length,
|
||||
const char *filename, uintN lineno,
|
||||
jsval *rval);
|
||||
const char *bytes, uintN length,
|
||||
const char *filename, uintN lineno,
|
||||
jsval *rval);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj,
|
||||
JSPrincipals *principals,
|
||||
const char *bytes, uintN length,
|
||||
const char *filename, uintN lineno,
|
||||
jsval *rval);
|
||||
JSPrincipals *principals,
|
||||
const char *bytes, uintN length,
|
||||
const char *filename, uintN lineno,
|
||||
jsval *rval);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_EvaluateUCScript(JSContext *cx, JSObject *obj,
|
||||
const jschar *chars, uintN length,
|
||||
const char *filename, uintN lineno,
|
||||
jsval *rval);
|
||||
const jschar *chars, uintN length,
|
||||
const char *filename, uintN lineno,
|
||||
jsval *rval);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj,
|
||||
JSPrincipals *principals,
|
||||
const jschar *chars, uintN length,
|
||||
const char *filename, uintN lineno,
|
||||
jsval *rval);
|
||||
JSPrincipals *principals,
|
||||
const jschar *chars, uintN length,
|
||||
const char *filename, uintN lineno,
|
||||
jsval *rval);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_CallFunction(JSContext *cx, JSObject *obj, JSFunction *fun, uintN argc,
|
||||
jsval *argv, jsval *rval);
|
||||
jsval *argv, jsval *rval);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, uintN argc,
|
||||
jsval *argv, jsval *rval);
|
||||
jsval *argv, jsval *rval);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, uintN argc,
|
||||
jsval *argv, jsval *rval);
|
||||
jsval *argv, jsval *rval);
|
||||
|
||||
extern JS_PUBLIC_API(JSBranchCallback)
|
||||
JS_SetBranchCallback(JSContext *cx, JSBranchCallback cb);
|
||||
@@ -1221,25 +1089,6 @@ JS_IsRunning(JSContext *cx);
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_IsConstructing(JSContext *cx);
|
||||
|
||||
/*
|
||||
* Returns true if a script is executing and its current bytecode is a set
|
||||
* (assignment) operation, even if there are native (no script) stack frames
|
||||
* between the script and the caller to JS_IsAssigning.
|
||||
*/
|
||||
extern JS_FRIEND_API(JSBool)
|
||||
JS_IsAssigning(JSContext *cx);
|
||||
|
||||
/*
|
||||
* Set the second return value, which should be a string or int jsval that
|
||||
* identifies a property in the returned object, to form an ECMA reference
|
||||
* type value (obj, id). Only native methods can return reference types,
|
||||
* and if the returned value is used on the left-hand side of an assignment
|
||||
* op, the identified property will be set. If the return value is in an
|
||||
* r-value, the interpreter just gets obj[id]'s value.
|
||||
*/
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_SetCallReturnValue2(JSContext *cx, jsval v);
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
/*
|
||||
@@ -1295,24 +1144,24 @@ JS_CompareStrings(JSString *str1, JSString *str2);
|
||||
/*
|
||||
* Locale specific string conversion callback.
|
||||
*/
|
||||
|
||||
struct JSLocaleCallbacks {
|
||||
JSLocaleToUpperCase localeToUpperCase;
|
||||
JSLocaleToLowerCase localeToLowerCase;
|
||||
JSLocaleCompare localeCompare;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Establish locale callbacks. The pointer must persist as long as the
|
||||
* JSContext. Passing NULL restores the default behaviour.
|
||||
* Establish locale callbacks. The pointer must persist as long as the JSContext.
|
||||
* Setting to NULL resorts to default behaviour.
|
||||
*/
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_SetLocaleCallbacks(JSContext *cx, JSLocaleCallbacks *callbacks);
|
||||
|
||||
/*
|
||||
* Return the address of the current locale callbacks struct, which may
|
||||
* be NULL.
|
||||
*/
|
||||
extern JS_PUBLIC_API(JSLocaleCallbacks *)
|
||||
/* Return the address of the current locale callbacks struct. May be NULL. */
|
||||
extern JS_PUBLIC_API(JSLocaleCallbacks *)
|
||||
JS_GetLocaleCallbacks(JSContext *cx);
|
||||
|
||||
/************************************************************************/
|
||||
@@ -1335,14 +1184,14 @@ JS_ReportError(JSContext *cx, const char *format, ...);
|
||||
*/
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_ReportErrorNumber(JSContext *cx, JSErrorCallback errorCallback,
|
||||
void *userRef, const uintN errorNumber, ...);
|
||||
void *userRef, const uintN errorNumber, ...);
|
||||
|
||||
/*
|
||||
* Use an errorNumber to retrieve the format string, args are jschar *
|
||||
*/
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_ReportErrorNumberUC(JSContext *cx, JSErrorCallback errorCallback,
|
||||
void *userRef, const uintN errorNumber, ...);
|
||||
void *userRef, const uintN errorNumber, ...);
|
||||
|
||||
/*
|
||||
* As above, but report a warning instead (JSREPORT_IS_WARNING(report.flags)).
|
||||
@@ -1376,7 +1225,7 @@ struct JSErrorReport {
|
||||
const char *tokenptr; /* pointer to error token in linebuf */
|
||||
const jschar *uclinebuf; /* unicode (original) line buffer */
|
||||
const jschar *uctokenptr; /* unicode (original) token pointer */
|
||||
uintN flags; /* error/warning, etc. */
|
||||
uintN flags; /* error/warning, etc. */
|
||||
uintN errorNumber; /* the error number, e.g. see js.msg */
|
||||
const jschar *ucmessage; /* the (default) error message */
|
||||
const jschar **messageArgs; /* arguments for the error message */
|
||||
@@ -1474,7 +1323,6 @@ extern JS_PUBLIC_API(JSErrorReport *)
|
||||
JS_ErrorFromException(JSContext *cx, jsval v);
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
|
||||
/*
|
||||
* Associate the current thread with the given context. This is done
|
||||
* implicitly by JS_NewContext.
|
||||
@@ -1493,11 +1341,21 @@ JS_SetContextThread(JSContext *cx);
|
||||
|
||||
extern JS_PUBLIC_API(intN)
|
||||
JS_ClearContextThread(JSContext *cx);
|
||||
|
||||
#endif /* JS_THREADSAFE */
|
||||
#endif
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
/*
|
||||
* Returns true if a script is executing and its current bytecode is a set
|
||||
* (assignment) operation.
|
||||
*
|
||||
* NOTE: Previously conditional on NETSCAPE_INTERNAL. This function may
|
||||
* be removed in the future.
|
||||
*/
|
||||
extern JS_FRIEND_API(JSBool)
|
||||
JS_IsAssigning(JSContext *cx);
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsapi_h___ */
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ JS_InitArenaPool(JSArenaPool *pool, const char *name, JSUint32 size, JSUint32 al
|
||||
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);
|
||||
(jsuword)JS_ARENA_ALIGN(pool, &pool->first + 1);
|
||||
pool->current = &pool->first;
|
||||
pool->arenasize = size;
|
||||
#ifdef JS_ARENAMETER
|
||||
@@ -103,8 +103,9 @@ JS_ArenaAllocate(JSArenaPool *pool, JSUint32 nb)
|
||||
while ((b = *ap) != NULL) { /* reclaim a free arena */
|
||||
/*
|
||||
* Insist on exact arenasize match if nb is not greater than
|
||||
* arenasize. Otherwise take any arena big enough, but not by
|
||||
* more than nb + arenasize.
|
||||
* arenasize. Otherwise take any arena big enough, but not
|
||||
* more than nb + arenasize. The JS GC counts on arenasize
|
||||
* matching to keep its thing and flags arenas parallel.
|
||||
*/
|
||||
sz = (JSUint32)(b->limit - b->base);
|
||||
if ((nb > pool->arenasize)
|
||||
@@ -131,7 +132,7 @@ JS_ArenaAllocate(JSArenaPool *pool, JSUint32 nb)
|
||||
JS_COUNT_ARENA(pool,++);
|
||||
COUNT(pool, nmallocs);
|
||||
claim:
|
||||
a->base = a->avail = JS_ARENA_ALIGN(pool, a + 1);
|
||||
a->base = a->avail = (jsuword)JS_ARENA_ALIGN(pool, a + 1);
|
||||
continue;
|
||||
}
|
||||
a = a->next; /* move to next arena */
|
||||
@@ -141,34 +142,6 @@ JS_ArenaAllocate(JSArenaPool *pool, JSUint32 nb)
|
||||
return p;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void *)
|
||||
JS_ArenaRealloc(JSArenaPool *pool, void *p, JSUint32 size, JSUint32 incr)
|
||||
{
|
||||
JSArena **ap, *a;
|
||||
jsuword aoff;
|
||||
|
||||
ap = &pool->first.next;
|
||||
while ((a = *ap) != pool->current)
|
||||
ap = &a->next;
|
||||
JS_ASSERT(a->base == (jsuword)p);
|
||||
size += incr;
|
||||
aoff = size;
|
||||
JS_ASSERT(size > pool->arenasize);
|
||||
size += sizeof *a + pool->mask; /* header and alignment slop */
|
||||
a = (JSArena *) realloc(a, size);
|
||||
if (!a)
|
||||
return NULL;
|
||||
*ap = a;
|
||||
pool->current = a;
|
||||
#ifdef JS_ARENAMETER
|
||||
pool->stats.nreallocs++;
|
||||
#endif
|
||||
a->base = JS_ARENA_ALIGN(pool, a + 1);
|
||||
a->limit = (jsuword)a + size;
|
||||
a->avail = JS_ARENA_ALIGN(pool, a->base + aoff);
|
||||
return (void *)a->base;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void *)
|
||||
JS_ArenaGrow(JSArenaPool *pool, void *p, JSUint32 size, JSUint32 incr)
|
||||
{
|
||||
@@ -232,7 +205,7 @@ JS_ArenaRelease(JSArenaPool *pool, char *mark)
|
||||
|
||||
for (a = &pool->first; a; a = a->next) {
|
||||
if (JS_UPTRDIFF(mark, a->base) <= JS_UPTRDIFF(a->avail, a->base)) {
|
||||
a->avail = JS_ARENA_ALIGN(pool, mark);
|
||||
a->avail = (jsuword)JS_ARENA_ALIGN(pool, mark);
|
||||
FreeArenaList(pool, a, JS_TRUE);
|
||||
return;
|
||||
}
|
||||
@@ -356,22 +329,14 @@ JS_PUBLIC_API(void)
|
||||
JS_DumpArenaStats(FILE *fp)
|
||||
{
|
||||
JSArenaStats *stats;
|
||||
uint32 nallocs, nbytes;
|
||||
double mean, variance, sigma;
|
||||
double mean, variance;
|
||||
|
||||
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);
|
||||
if (stats->nallocs != 0) {
|
||||
mean = (double)stats->nbytes / stats->nallocs;
|
||||
variance = fabs(stats->variance / stats->nallocs - mean * mean);
|
||||
} else {
|
||||
mean = variance = sigma = 0;
|
||||
mean = variance = 0;
|
||||
}
|
||||
|
||||
fprintf(fp, "\n%s allocation statistics:\n", stats->name);
|
||||
@@ -382,12 +347,11 @@ JS_DumpArenaStats(FILE *fp)
|
||||
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, " standard deviation: %g\n", sqrt(variance));
|
||||
fprintf(fp, " maximum allocation size: %u\n", stats->maxalloc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,6 @@ struct JSArenaStats {
|
||||
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 */
|
||||
@@ -95,8 +94,8 @@ struct JSArenaPool {
|
||||
* 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_ARENA_ALIGN(pool, n) (((jsuword)(n) + JS_ARENA_CONST_ALIGN_MASK) \
|
||||
& ~JS_ARENA_CONST_ALIGN_MASK)
|
||||
|
||||
#define JS_INIT_ARENA_POOL(pool, name, size) \
|
||||
JS_InitArenaPool(pool, name, size, JS_ARENA_CONST_ALIGN_MASK + 1)
|
||||
@@ -105,12 +104,6 @@ struct JSArenaPool {
|
||||
#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); \
|
||||
@@ -120,61 +113,54 @@ struct JSArenaPool {
|
||||
_p = (jsuword)JS_ArenaAllocate(pool, _nb); \
|
||||
else \
|
||||
_a->avail = _q; \
|
||||
p = (type) _p; \
|
||||
*(void**)&p = (void *)_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); \
|
||||
JSArena *_a = (pool)->current; \
|
||||
size_t _incr = JS_ARENA_ALIGN(pool, incr); \
|
||||
jsuword _p = _a->avail; \
|
||||
jsuword _q = _p + _incr; \
|
||||
if (_p == (jsuword)(p) + JS_ARENA_ALIGN(pool, size) && \
|
||||
_q <= _a->limit) { \
|
||||
_a->avail = _q; \
|
||||
JS_ArenaCountInplaceGrowth(pool, size, incr); \
|
||||
} else { \
|
||||
*(void**)&p = 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))
|
||||
#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_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))
|
||||
(a)->limit - (jsuword)(a))
|
||||
#else
|
||||
#define JS_CLEAR_UNUSED(a) /* nothing */
|
||||
#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_CLEAR_UNUSED(_a); \
|
||||
JS_ArenaCountRetract(pool, _m); \
|
||||
} else { \
|
||||
JS_ArenaRelease(pool, _m); \
|
||||
} \
|
||||
JS_ArenaCountRelease(pool, _m); \
|
||||
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_CLEAR_UNUSED(_a); \
|
||||
JS_ArenaCountRetract(pool, _m); \
|
||||
} else { \
|
||||
JS_ArenaRelease(pool, _m); \
|
||||
} \
|
||||
JS_ArenaCountRelease(pool, _m); \
|
||||
JS_END_MACRO
|
||||
|
||||
#ifdef JS_ARENAMETER
|
||||
@@ -185,12 +171,12 @@ struct JSArenaPool {
|
||||
|
||||
#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_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
|
||||
|
||||
/*
|
||||
@@ -199,7 +185,7 @@ struct JSArenaPool {
|
||||
*/
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_InitArenaPool(JSArenaPool *pool, const char *name, JSUint32 size,
|
||||
JSUint32 align);
|
||||
JSUint32 align);
|
||||
|
||||
/*
|
||||
* Free the arenas in pool. The user may continue to allocate from pool
|
||||
@@ -248,9 +234,6 @@ JS_ArenaShutDown(void);
|
||||
extern JS_PUBLIC_API(void *)
|
||||
JS_ArenaAllocate(JSArenaPool *pool, JSUint32 nb);
|
||||
|
||||
extern JS_PUBLIC_API(void *)
|
||||
JS_ArenaRealloc(JSArenaPool *pool, void *p, JSUint32 size, JSUint32 incr);
|
||||
|
||||
extern JS_PUBLIC_API(void *)
|
||||
JS_ArenaGrow(JSArenaPool *pool, void *p, JSUint32 size, JSUint32 incr);
|
||||
|
||||
@@ -268,7 +251,7 @@ extern JS_PUBLIC_API(void)
|
||||
JS_ArenaCountInplaceGrowth(JSArenaPool *pool, JSUint32 size, JSUint32 incr);
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_ArenaCountGrowth(JSArenaPool *pool, JSUint32 size, JSUint32 incr);
|
||||
JS_ArenaCountGrowth(JSArenaPool *pool, JSUint32 size, JSUint32incr);
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_ArenaCountRelease(JSArenaPool *pool, char *mark);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* 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
|
||||
@@ -493,8 +493,8 @@ array_toLocaleString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *rval)
|
||||
{
|
||||
/*
|
||||
* Passing comma_space here as the separator. Need a way to get a
|
||||
* locale-specific version.
|
||||
* Passing comma_space here as the separator. Need a way to get a
|
||||
* locale specific version.
|
||||
*/
|
||||
return array_join_sub(cx, obj, &comma_space, JS_FALSE, rval, JS_TRUE);
|
||||
}
|
||||
@@ -587,6 +587,9 @@ array_reverse(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
OBJ_DROP_PROPERTY(cx, obj2, prop);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
if (!OBJ_SET_PROPERTY(cx, obj, id, &v2))
|
||||
return JS_FALSE;
|
||||
if (!OBJ_SET_PROPERTY(cx, obj, id2, &v))
|
||||
@@ -605,66 +608,41 @@ typedef struct QSortArgs {
|
||||
void *arg;
|
||||
} QSortArgs;
|
||||
|
||||
static int
|
||||
sort_compare(const void *a, const void *b, void *arg);
|
||||
|
||||
static void
|
||||
js_qsort_r(QSortArgs *qa, int lo, int hi)
|
||||
{
|
||||
void *pivot, *vec, *arg, *a, *b;
|
||||
size_t elsize;
|
||||
JSComparator cmp;
|
||||
JSBool fastmove;
|
||||
int i, j, lohi, hilo;
|
||||
void *pivot, *a, *b;
|
||||
int i, j;
|
||||
|
||||
pivot = qa->pivot;
|
||||
vec = qa->vec;
|
||||
elsize = qa->elsize;
|
||||
cmp = qa->cmp;
|
||||
arg = qa->arg;
|
||||
|
||||
fastmove = (cmp == sort_compare);
|
||||
#define MEMMOVE(p,q,n) \
|
||||
(fastmove ? (void)(*(jsval*)(p) = *(jsval*)(q)) : (void)memmove(p, q, n))
|
||||
|
||||
while (lo < hi) {
|
||||
i = lo;
|
||||
j = hi;
|
||||
a = (char *)vec + i * elsize;
|
||||
MEMMOVE(pivot, a, elsize);
|
||||
while (i < j) {
|
||||
b = (char *)vec + j * elsize;
|
||||
if (cmp(b, pivot, arg) >= 0) {
|
||||
j--;
|
||||
continue;
|
||||
}
|
||||
MEMMOVE(a, b, elsize);
|
||||
while (cmp(a, pivot, arg) <= 0) {
|
||||
i++;
|
||||
a = (char *)vec + i * elsize;
|
||||
if (i == j)
|
||||
goto store_pivot;
|
||||
}
|
||||
MEMMOVE(b, a, elsize);
|
||||
}
|
||||
if (i > lo) {
|
||||
store_pivot:
|
||||
MEMMOVE(a, pivot, elsize);
|
||||
}
|
||||
if (i - lo < hi - i) {
|
||||
lohi = i - 1;
|
||||
if (lo < lohi)
|
||||
js_qsort_r(qa, lo, lohi);
|
||||
lo = i + 1;
|
||||
} else {
|
||||
hilo = i + 1;
|
||||
if (hilo < hi)
|
||||
js_qsort_r(qa, hilo, hi);
|
||||
hi = i - 1;
|
||||
}
|
||||
i = lo;
|
||||
j = hi;
|
||||
a = (char *)qa->vec + i * qa->elsize;
|
||||
memmove(pivot, a, qa->elsize);
|
||||
while (i < j) {
|
||||
do {
|
||||
b = (char *)qa->vec + j * qa->elsize;
|
||||
if ((*qa->cmp)(b, pivot, qa->arg) <= 0)
|
||||
break;
|
||||
j--;
|
||||
} while (j > i);
|
||||
memmove(a, b, qa->elsize);
|
||||
while (i < j && (*qa->cmp)(a, pivot, qa->arg) <= 0) {
|
||||
i++;
|
||||
a = (char *)qa->vec + i * qa->elsize;
|
||||
}
|
||||
memmove(b, a, qa->elsize);
|
||||
}
|
||||
memmove(a, pivot, qa->elsize);
|
||||
if (i - lo < hi - i) {
|
||||
js_qsort_r(qa, lo, i - 1);
|
||||
lo = i + 1;
|
||||
} else {
|
||||
js_qsort_r(qa, i + 1, hi);
|
||||
hi = i - 1;
|
||||
}
|
||||
}
|
||||
|
||||
#undef MEMMOVE
|
||||
}
|
||||
|
||||
JSBool
|
||||
|
||||
@@ -51,13 +51,11 @@
|
||||
#include "jsopcode.h"
|
||||
#include "jsstr.h"
|
||||
|
||||
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[] = {
|
||||
char *js_type_str[] = {
|
||||
"undefined",
|
||||
"object",
|
||||
"function",
|
||||
@@ -66,46 +64,38 @@ const char *js_type_str[] = {
|
||||
"boolean",
|
||||
};
|
||||
|
||||
const char *js_boolean_str[] = {
|
||||
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_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_parent_str[] = "__parent__";
|
||||
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";
|
||||
char js_Array_str[] = "Array";
|
||||
char js_Math_str[] = "Math";
|
||||
char js_NaN_str[] = "NaN";
|
||||
char js_Object_str[] = "Object";
|
||||
char js_anonymous_str[] = "anonymous";
|
||||
char js_arguments_str[] = "arguments";
|
||||
char js_arity_str[] = "arity";
|
||||
char js_callee_str[] = "callee";
|
||||
char js_caller_str[] = "caller";
|
||||
char js_class_prototype_str[] = "prototype";
|
||||
char js_constructor_str[] = "constructor";
|
||||
char js_count_str[] = "__count__";
|
||||
char js_eval_str[] = "eval";
|
||||
char js_getter_str[] = "getter";
|
||||
char js_get_str[] = "get";
|
||||
char js_index_str[] = "index";
|
||||
char js_input_str[] = "input";
|
||||
char js_length_str[] = "length";
|
||||
char js_name_str[] = "name";
|
||||
char js_parent_str[] = "__parent__";
|
||||
char js_proto_str[] = "__proto__";
|
||||
char js_setter_str[] = "setter";
|
||||
char js_set_str[] = "set";
|
||||
char js_toSource_str[] = "toSource";
|
||||
char js_toString_str[] = "toString";
|
||||
char js_toLocaleString_str[] = "toLocaleString";
|
||||
char js_valueOf_str[] = "valueOf";
|
||||
|
||||
#define HASH_OBJECT(o) ((JSHashNumber)(o) >> JSVAL_TAGBITS)
|
||||
#define HASH_INT(i) ((JSHashNumber)(i))
|
||||
@@ -229,7 +219,7 @@ js_InitAtomState(JSContext *cx, JSAtomState *state)
|
||||
return JS_FALSE;
|
||||
}
|
||||
#ifdef JS_THREADSAFE
|
||||
js_InitLock(&state->lock);
|
||||
js_NewLock(&state->lock);
|
||||
state->tablegen = 0;
|
||||
#endif
|
||||
|
||||
@@ -247,19 +237,10 @@ js_InitAtomState(JSContext *cx, JSAtomState *state)
|
||||
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(NaNAtom, js_NaN_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);
|
||||
@@ -268,21 +249,21 @@ js_InitAtomState(JSContext *cx, JSAtomState *state)
|
||||
FROB(classPrototypeAtom, js_class_prototype_str);
|
||||
FROB(constructorAtom, js_constructor_str);
|
||||
FROB(countAtom, js_count_str);
|
||||
FROB(evalAtom, js_eval_str);
|
||||
FROB(getAtom, js_get_str);
|
||||
FROB(getterAtom, js_getter_str);
|
||||
FROB(getAtom, js_get_str);
|
||||
FROB(indexAtom, js_index_str);
|
||||
FROB(inputAtom, js_input_str);
|
||||
FROB(lengthAtom, js_length_str);
|
||||
FROB(nameAtom, js_name_str);
|
||||
FROB(parentAtom, js_parent_str);
|
||||
FROB(protoAtom, js_proto_str);
|
||||
FROB(setAtom, js_set_str);
|
||||
FROB(setterAtom, js_setter_str);
|
||||
FROB(setAtom, js_set_str);
|
||||
FROB(toSourceAtom, js_toSource_str);
|
||||
FROB(toStringAtom, js_toString_str);
|
||||
FROB(toLocaleStringAtom, js_toLocaleString_str);
|
||||
FROB(valueOfAtom, js_valueOf_str);
|
||||
FROB(evalAtom, js_eval_str);
|
||||
|
||||
#undef FROB
|
||||
|
||||
@@ -293,99 +274,49 @@ bad:
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
/* NB: cx unused; js_FinishAtomState calls us with null cx. */
|
||||
void
|
||||
js_FreeAtomState(JSContext *cx, JSAtomState *state)
|
||||
{
|
||||
if (state->interns != 0)
|
||||
return;
|
||||
state->runtime = NULL;
|
||||
JS_HashTableDestroy(state->table);
|
||||
state->table = NULL;
|
||||
state->number = 0;
|
||||
#ifdef JS_THREADSAFE
|
||||
js_FinishLock(&state->lock);
|
||||
js_DestroyLock(&state->lock);
|
||||
#endif
|
||||
}
|
||||
|
||||
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->flags & ATOM_INTERNED) || !ATOM_IS_STRING(atom))
|
||||
args->leaks++;
|
||||
if (ATOM_IS_STRING(atom))
|
||||
js_FinalizeStringRT(args->rt, ATOM_TO_STRING(atom));
|
||||
return HT_ENUMERATE_NEXT;
|
||||
}
|
||||
|
||||
void
|
||||
js_FinishAtomState(JSAtomState *state)
|
||||
{
|
||||
UninternArgs args;
|
||||
|
||||
if (state->interns == 0)
|
||||
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
|
||||
state->interns = 0;
|
||||
js_FreeAtomState(NULL, state);
|
||||
}
|
||||
|
||||
typedef struct MarkArgs {
|
||||
uintN gcflags;
|
||||
JSRuntime *runtime;
|
||||
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;
|
||||
MarkArgs *args;
|
||||
|
||||
atom = (JSAtom *)he;
|
||||
args = (MarkArgs *)arg;
|
||||
if ((atom->flags & (ATOM_PINNED | ATOM_INTERNED)) ||
|
||||
(args->gcflags & GC_KEEP_ATOMS)) {
|
||||
if (atom->flags & ATOM_PINNED) {
|
||||
atom->flags |= ATOM_MARK;
|
||||
key = ATOM_KEY(atom);
|
||||
if (JSVAL_IS_GCTHING(key)) {
|
||||
args->mark(JSVAL_TO_GCTHING(key), args->data);
|
||||
args = (MarkArgs *) arg;
|
||||
args->mark(args->runtime, JSVAL_TO_GCTHING(key));
|
||||
}
|
||||
}
|
||||
return HT_ENUMERATE_NEXT;
|
||||
}
|
||||
|
||||
void
|
||||
js_MarkAtomState(JSAtomState *state, uintN gcflags, JSGCThingMarker mark,
|
||||
void *data)
|
||||
js_MarkAtomState(JSAtomState *state, JSGCThingMarker mark)
|
||||
{
|
||||
MarkArgs args;
|
||||
|
||||
args.gcflags = gcflags;
|
||||
args.runtime = state->runtime;
|
||||
args.mark = mark;
|
||||
args.data = data;
|
||||
JS_HashTableEnumerateEntries(state->table, js_atom_marker, &args);
|
||||
}
|
||||
|
||||
@@ -393,22 +324,26 @@ JS_STATIC_DLL_CALLBACK(intN)
|
||||
js_atom_sweeper(JSHashEntry *he, intN i, void *arg)
|
||||
{
|
||||
JSAtom *atom;
|
||||
uintN gcflags;
|
||||
|
||||
atom = (JSAtom *)he;
|
||||
if (atom->flags & ATOM_MARK) {
|
||||
atom->flags &= ~ATOM_MARK;
|
||||
return HT_ENUMERATE_NEXT;
|
||||
}
|
||||
JS_ASSERT((atom->flags & (ATOM_PINNED | ATOM_INTERNED)) == 0);
|
||||
gcflags = (uintN)arg;
|
||||
if (gcflags & GC_KEEP_ATOMS)
|
||||
return HT_ENUMERATE_NEXT;
|
||||
JS_ASSERT((atom->flags & ATOM_PINNED) == 0);
|
||||
atom->entry.key = NULL;
|
||||
atom->flags = 0;
|
||||
return HT_ENUMERATE_REMOVE;
|
||||
}
|
||||
|
||||
void
|
||||
js_SweepAtomState(JSAtomState *state)
|
||||
js_SweepAtomState(JSAtomState *state, uintN gcflags)
|
||||
{
|
||||
JS_HashTableEnumerateEntries(state->table, js_atom_sweeper, NULL);
|
||||
JS_HashTableEnumerateEntries(state->table, js_atom_sweeper, (void*)gcflags);
|
||||
}
|
||||
|
||||
JS_STATIC_DLL_CALLBACK(intN)
|
||||
@@ -595,9 +530,7 @@ js_AtomizeString(JSContext *cx, JSString *str, uintN flags)
|
||||
}
|
||||
|
||||
atom = (JSAtom *)he;
|
||||
atom->flags |= flags & (ATOM_PINNED | ATOM_INTERNED);
|
||||
if (flags & ATOM_INTERNED)
|
||||
state->interns++;
|
||||
atom->flags |= flags & ATOM_PINNED;
|
||||
out:
|
||||
JS_UNLOCK(&state->lock,cx);
|
||||
return atom;
|
||||
@@ -710,7 +643,7 @@ js_alloc_temp_entry(void *priv, const void *key)
|
||||
JSContext *cx = priv;
|
||||
JSAtomListElement *ale;
|
||||
|
||||
JS_ARENA_ALLOCATE_TYPE(ale, JSAtomListElement, &cx->tempPool);
|
||||
JS_ARENA_ALLOCATE(ale, &cx->tempPool, sizeof(JSAtomListElement));
|
||||
if (!ale) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return NULL;
|
||||
@@ -825,7 +758,7 @@ js_InitAtomMap(JSContext *cx, JSAtomMap *map, JSAtomList *al)
|
||||
uint32 count;
|
||||
|
||||
#ifdef DEBUG
|
||||
JS_ATOMIC_INCREMENT(&js_atom_map_count);
|
||||
JS_ATOMIC_ADDREF(&js_atom_map_count, 1);
|
||||
#endif
|
||||
ale = al->list;
|
||||
if (!ale && !al->table) {
|
||||
@@ -846,7 +779,7 @@ js_InitAtomMap(JSContext *cx, JSAtomMap *map, JSAtomList *al)
|
||||
|
||||
if (al->table) {
|
||||
#ifdef DEBUG
|
||||
JS_ATOMIC_INCREMENT(&js_atom_map_hash_table_count);
|
||||
JS_ATOMIC_ADDREF(&js_atom_map_hash_table_count, 1);
|
||||
#endif
|
||||
JS_HashTableEnumerateEntries(al->table, js_map_atom, vector);
|
||||
} else {
|
||||
@@ -865,7 +798,7 @@ JS_FRIEND_API(void)
|
||||
js_FreeAtomMap(JSContext *cx, JSAtomMap *map)
|
||||
{
|
||||
if (map->vector) {
|
||||
JS_free(cx, map->vector);
|
||||
free(map->vector);
|
||||
map->vector = NULL;
|
||||
}
|
||||
map->length = 0;
|
||||
|
||||
@@ -50,15 +50,14 @@
|
||||
|
||||
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_NOCOPY 0x01 /* don't copy atom string bytes */
|
||||
#define ATOM_TMPSTR 0x02 /* internal, to avoid extra string */
|
||||
#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 */
|
||||
#define ATOM_PINNED 0x08 /* atom is pinned against GC */
|
||||
|
||||
struct JSAtom {
|
||||
JSHashEntry entry; /* key is jsval, value keyword info */
|
||||
uint8 flags; /* pinned, interned, and mark flags */
|
||||
uint8 flags; /* flags, PINNED and/or MARK for now */
|
||||
int8 kwindex; /* keyword index, -1 if not keyword */
|
||||
jsatomid number; /* atom serial number and hash code */
|
||||
};
|
||||
@@ -82,12 +81,12 @@ struct JSAtomListElement {
|
||||
|
||||
#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_NODE(ale) ((JSParseNode *) (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 *)(op))
|
||||
#define ALE_SET_NODE(ale,pn) ((ale)->entry.value = (void *)(pn))
|
||||
#define ALE_SET_NEXT(ale,link) ((ale)->entry.next = (JSHashEntry *)(link))
|
||||
|
||||
struct JSAtomList {
|
||||
@@ -135,7 +134,6 @@ struct JSAtomState {
|
||||
JSRuntime *runtime; /* runtime that owns us */
|
||||
JSHashTable *table; /* hash table containing all atoms */
|
||||
jsatomid number; /* one beyond greatest atom number */
|
||||
jsatomid interns; /* number of interned strings */
|
||||
|
||||
/* Type names and value literals. */
|
||||
JSAtom *typeAtoms[JSTYPE_LIMIT];
|
||||
@@ -143,19 +141,10 @@ struct JSAtomState {
|
||||
JSAtom *nullAtom;
|
||||
|
||||
/* Various built-in or commonly-used atoms. */
|
||||
JSAtom *ArgumentsAtom;
|
||||
JSAtom *ArrayAtom;
|
||||
JSAtom *BooleanAtom;
|
||||
JSAtom *CallAtom;
|
||||
JSAtom *DateAtom;
|
||||
JSAtom *ErrorAtom;
|
||||
JSAtom *FunctionAtom;
|
||||
JSAtom *MathAtom;
|
||||
JSAtom *NumberAtom;
|
||||
JSAtom *NaNAtom;
|
||||
JSAtom *ObjectAtom;
|
||||
JSAtom *RegExpAtom;
|
||||
JSAtom *ScriptAtom;
|
||||
JSAtom *StringAtom;
|
||||
JSAtom *anonymousAtom;
|
||||
JSAtom *argumentsAtom;
|
||||
JSAtom *arityAtom;
|
||||
@@ -164,21 +153,21 @@ struct JSAtomState {
|
||||
JSAtom *classPrototypeAtom;
|
||||
JSAtom *constructorAtom;
|
||||
JSAtom *countAtom;
|
||||
JSAtom *evalAtom;
|
||||
JSAtom *getAtom;
|
||||
JSAtom *getterAtom;
|
||||
JSAtom *getAtom;
|
||||
JSAtom *indexAtom;
|
||||
JSAtom *inputAtom;
|
||||
JSAtom *lengthAtom;
|
||||
JSAtom *nameAtom;
|
||||
JSAtom *parentAtom;
|
||||
JSAtom *protoAtom;
|
||||
JSAtom *setAtom;
|
||||
JSAtom *setterAtom;
|
||||
JSAtom *toLocaleStringAtom;
|
||||
JSAtom *setAtom;
|
||||
JSAtom *toSourceAtom;
|
||||
JSAtom *toStringAtom;
|
||||
JSAtom *toLocaleStringAtom;
|
||||
JSAtom *valueOfAtom;
|
||||
JSAtom *evalAtom;
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
JSThinLock lock;
|
||||
@@ -187,44 +176,36 @@ struct JSAtomState {
|
||||
};
|
||||
|
||||
/* Well-known predefined strings and their atoms. */
|
||||
extern const char *js_type_str[];
|
||||
extern const char *js_boolean_str[];
|
||||
extern char *js_type_str[];
|
||||
extern 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_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_parent_str[];
|
||||
extern const char js_proto_str[];
|
||||
extern const char js_setter_str[];
|
||||
extern const char js_set_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 char js_Array_str[];
|
||||
extern char js_Math_str[];
|
||||
extern char js_NaN_str[];
|
||||
extern char js_Object_str[];
|
||||
extern char js_anonymous_str[];
|
||||
extern char js_arguments_str[];
|
||||
extern char js_arity_str[];
|
||||
extern char js_callee_str[];
|
||||
extern char js_caller_str[];
|
||||
extern char js_class_prototype_str[];
|
||||
extern char js_constructor_str[];
|
||||
extern char js_count_str[];
|
||||
extern char js_eval_str[];
|
||||
extern char js_getter_str[];
|
||||
extern char js_get_str[];
|
||||
extern char js_index_str[];
|
||||
extern char js_input_str[];
|
||||
extern char js_length_str[];
|
||||
extern char js_name_str[];
|
||||
extern char js_parent_str[];
|
||||
extern char js_proto_str[];
|
||||
extern char js_setter_str[];
|
||||
extern char js_set_str[];
|
||||
extern char js_toSource_str[];
|
||||
extern char js_toString_str[];
|
||||
extern char js_toLocaleString_str[];
|
||||
extern char js_valueOf_str[];
|
||||
|
||||
/*
|
||||
* Initialize atom state. Return true on success, false with an out of
|
||||
@@ -234,39 +215,22 @@ extern JSBool
|
||||
js_InitAtomState(JSContext *cx, JSAtomState *state);
|
||||
|
||||
/*
|
||||
* Free and clear atom state (except for any interned string atoms).
|
||||
* Free and clear atom state.
|
||||
*/
|
||||
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);
|
||||
(*JSGCThingMarker)(JSRuntime *rt, void *thing);
|
||||
|
||||
extern void
|
||||
js_MarkAtomState(JSAtomState *state, uintN gcflags, JSGCThingMarker mark,
|
||||
void *data);
|
||||
js_MarkAtomState(JSAtomState *state, JSGCThingMarker mark);
|
||||
|
||||
extern void
|
||||
js_SweepAtomState(JSAtomState *state);
|
||||
js_SweepAtomState(JSAtomState *state, uintN gcflags);
|
||||
|
||||
extern void
|
||||
js_UnpinPinnedAtoms(JSAtomState *state);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* 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
|
||||
@@ -51,12 +51,10 @@
|
||||
#include "jsexn.h"
|
||||
#include "jsgc.h"
|
||||
#include "jslock.h"
|
||||
#include "jsnum.h"
|
||||
#include "jsobj.h"
|
||||
#include "jsopcode.h"
|
||||
#include "jsscan.h"
|
||||
#include "jsscript.h"
|
||||
#include "jsstr.h"
|
||||
|
||||
JSContext *
|
||||
js_NewContext(JSRuntime *rt, size_t stackChunkSize)
|
||||
@@ -76,7 +74,7 @@ js_NewContext(JSRuntime *rt, size_t stackChunkSize)
|
||||
|
||||
JS_LOCK_RUNTIME(rt);
|
||||
for (;;) {
|
||||
first = (rt->contextList.next == &rt->contextList);
|
||||
first = (rt->contextList.next == (JSCList *)&rt->contextList);
|
||||
if (rt->state == JSRTS_UP) {
|
||||
JS_ASSERT(!first);
|
||||
break;
|
||||
@@ -91,13 +89,23 @@ js_NewContext(JSRuntime *rt, size_t stackChunkSize)
|
||||
JS_APPEND_LINK(&cx->links, &rt->contextList);
|
||||
JS_UNLOCK_RUNTIME(rt);
|
||||
|
||||
/*
|
||||
* First we do the infallible, every-time per-context initializations.
|
||||
* Should a later, fallible initialization (js_InitRegExpStatics, e.g.,
|
||||
* or the stuff under 'if (first)' below) fail, at least the version
|
||||
* and arena-pools will be valid and safe to use (say, from the last GC
|
||||
* done by js_DestroyContext).
|
||||
*/
|
||||
if (first) {
|
||||
/* First context on this runtime: initialize atoms and keywords. */
|
||||
ok = js_InitAtomState(cx, &rt->atomState);
|
||||
if (ok)
|
||||
ok = js_InitScanner(cx);
|
||||
|
||||
JS_LOCK_RUNTIME(rt);
|
||||
rt->state = JSRTS_UP;
|
||||
JS_NOTIFY_ALL_CONDVAR(rt->stateChange);
|
||||
JS_UNLOCK_RUNTIME(rt);
|
||||
|
||||
if (!ok) {
|
||||
free(cx);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
cx->version = JSVERSION_DEFAULT;
|
||||
cx->jsop_eq = JSOP_EQ;
|
||||
cx->jsop_ne = JSOP_NE;
|
||||
@@ -108,7 +116,7 @@ js_NewContext(JSRuntime *rt, size_t stackChunkSize)
|
||||
|
||||
#if JS_HAS_REGEXPS
|
||||
if (!js_InitRegExpStatics(cx, &cx->regExpStatics)) {
|
||||
js_DestroyContext(cx, JS_NO_GC);
|
||||
js_DestroyContext(cx, JS_FORCE_GC);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
@@ -116,33 +124,6 @@ js_NewContext(JSRuntime *rt, size_t stackChunkSize)
|
||||
cx->throwing = JS_FALSE;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If cx is the first context on this runtime, initialize well-known atoms,
|
||||
* keywords, numbers, and strings. If one of these steps should fail, the
|
||||
* runtime will be left in a partially initialized state, with zeroes and
|
||||
* nulls stored in the default-initialized remainder of the struct. We'll
|
||||
* clean the runtime up under js_DestroyContext, because cx will be "last"
|
||||
* as well as "first".
|
||||
*/
|
||||
if (first) {
|
||||
ok = js_InitAtomState(cx, &rt->atomState);
|
||||
if (ok)
|
||||
ok = js_InitScanner(cx);
|
||||
if (ok)
|
||||
ok = js_InitRuntimeNumberState(cx);
|
||||
if (ok)
|
||||
ok = js_InitRuntimeStringState(cx);
|
||||
if (!ok) {
|
||||
js_DestroyContext(cx, JS_NO_GC);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JS_LOCK_RUNTIME(rt);
|
||||
rt->state = JSRTS_UP;
|
||||
JS_NOTIFY_ALL_CONDVAR(rt->stateChange);
|
||||
JS_UNLOCK_RUNTIME(rt);
|
||||
}
|
||||
|
||||
return cx;
|
||||
}
|
||||
|
||||
@@ -157,9 +138,9 @@ js_DestroyContext(JSContext *cx, JSGCMode gcmode)
|
||||
|
||||
/* Remove cx from context list first. */
|
||||
JS_LOCK_RUNTIME(rt);
|
||||
JS_ASSERT(rt->state == JSRTS_UP || rt->state == JSRTS_LAUNCHING);
|
||||
JS_ASSERT(rt->state == JSRTS_UP);
|
||||
JS_REMOVE_LINK(&cx->links);
|
||||
last = (rt->contextList.next == &rt->contextList);
|
||||
last = (rt->contextList.next == (JSCList *)&rt->contextList);
|
||||
if (last)
|
||||
rt->state = JSRTS_LANDING;
|
||||
JS_UNLOCK_RUNTIME(rt);
|
||||
@@ -168,9 +149,20 @@ js_DestroyContext(JSContext *cx, JSGCMode gcmode)
|
||||
/* Unpin all pinned atoms before final GC. */
|
||||
js_UnpinPinnedAtoms(&rt->atomState);
|
||||
|
||||
/* Unlock and clear GC things held by runtime pointers. */
|
||||
js_FinishRuntimeNumberState(cx);
|
||||
js_FinishRuntimeStringState(cx);
|
||||
/* Unlock GC things held by runtime pointers. */
|
||||
js_UnlockGCThing(cx, rt->jsNaN);
|
||||
js_UnlockGCThing(cx, rt->jsNegativeInfinity);
|
||||
js_UnlockGCThing(cx, rt->jsPositiveInfinity);
|
||||
js_UnlockGCThing(cx, rt->emptyString);
|
||||
|
||||
/*
|
||||
* Clear these so they get recreated if the standard classes are
|
||||
* initialized again.
|
||||
*/
|
||||
rt->jsNaN = NULL;
|
||||
rt->jsNegativeInfinity = NULL;
|
||||
rt->jsPositiveInfinity = NULL;
|
||||
rt->emptyString = NULL;
|
||||
|
||||
/* Clear debugging state to remove GC roots. */
|
||||
JS_ClearAllTraps(cx);
|
||||
@@ -178,12 +170,7 @@ js_DestroyContext(JSContext *cx, JSGCMode gcmode)
|
||||
}
|
||||
|
||||
#if JS_HAS_REGEXPS
|
||||
/*
|
||||
* Remove more GC roots in regExpStatics, then collect garbage.
|
||||
* XXX anti-modularity alert: we rely on the call to js_RemoveRoot within
|
||||
* XXX this function call to wait for any racing GC to complete, in the
|
||||
* XXX case where JS_DestroyContext is called outside of a request on cx
|
||||
*/
|
||||
/* Remove more GC roots in regExpStatics, then collect garbage. */
|
||||
js_FreeRegExpStatics(cx, &cx->regExpStatics);
|
||||
#endif
|
||||
|
||||
@@ -246,19 +233,6 @@ js_DestroyContext(JSContext *cx, JSGCMode gcmode)
|
||||
free(cx);
|
||||
}
|
||||
|
||||
JSBool
|
||||
js_LiveContext(JSRuntime *rt, JSContext *cx)
|
||||
{
|
||||
JSCList *cl;
|
||||
|
||||
for (cl = rt->contextList.next; cl != &rt->contextList; cl = cl->next) {
|
||||
if (cl == &cx->links)
|
||||
return JS_TRUE;
|
||||
}
|
||||
JS_RUNTIME_METER(rt, deadContexts);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
JSContext *
|
||||
js_ContextIterator(JSRuntime *rt, JSContext **iterp)
|
||||
{
|
||||
@@ -266,11 +240,11 @@ js_ContextIterator(JSRuntime *rt, JSContext **iterp)
|
||||
|
||||
JS_LOCK_RUNTIME(rt);
|
||||
if (!cx)
|
||||
cx = (JSContext *)&rt->contextList;
|
||||
cx = (JSContext *)cx->links.next;
|
||||
if (&cx->links == &rt->contextList)
|
||||
cx = NULL;
|
||||
*iterp = cx;
|
||||
cx = (JSContext *)rt->contextList.next;
|
||||
if ((void *)cx == &rt->contextList)
|
||||
cx = NULL;
|
||||
else
|
||||
*iterp = (JSContext *)cx->links.next;
|
||||
JS_UNLOCK_RUNTIME(rt);
|
||||
return cx;
|
||||
}
|
||||
@@ -309,54 +283,6 @@ ReportError(JSContext *cx, const char *message, JSErrorReport *reportp)
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* We don't post an exception in this case, since doing so runs into
|
||||
* complications of pre-allocating an exception object which required
|
||||
* running the Exception class initializer early etc.
|
||||
* Instead we just invoke the errorReporter with an "Out Of Memory"
|
||||
* type message, and then hope the process ends swiftly.
|
||||
*/
|
||||
void
|
||||
js_ReportOutOfMemory(JSContext *cx, JSErrorCallback errorCallback)
|
||||
{
|
||||
JSStackFrame *fp = cx->fp;
|
||||
JSErrorReport report;
|
||||
JSErrorReporter onError = cx->errorReporter;
|
||||
/* Get the message for this error, but we won't expand any arguments. */
|
||||
const JSErrorFormatString *fmtData = (*errorCallback)(NULL, NULL, JSMSG_OUT_OF_MEMORY);
|
||||
const char *msg = fmtData ? fmtData->format : "Out Of Memory";
|
||||
|
||||
memset(&report, 0, sizeof (struct JSErrorReport));
|
||||
/* Fill out the report, but don't do anything that requires an allocation. */
|
||||
report.errorNumber = JSMSG_OUT_OF_MEMORY;
|
||||
report.flags = JSREPORT_ERROR;
|
||||
|
||||
/* Walk stack until we find a frame that is associated with
|
||||
some script rather than a native frame. */
|
||||
while (fp && (!fp->script || !fp->pc))
|
||||
fp = fp->down;
|
||||
|
||||
if (fp) {
|
||||
report.filename = fp->script->filename;
|
||||
report.lineno = js_PCToLineNumber(fp->script, fp->pc);
|
||||
}
|
||||
|
||||
/*
|
||||
* If debugErrorHook is present then we give it a chance to veto
|
||||
* sending the error on to the regular ErrorReporter.
|
||||
*/
|
||||
if (onError) {
|
||||
JSDebugErrorHook hook = cx->runtime->debugErrorHook;
|
||||
if (hook &&
|
||||
!hook(cx, msg, &report, cx->runtime->debugErrorHookData)) {
|
||||
onError = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (onError)
|
||||
(*onError)(cx, msg, &report);
|
||||
}
|
||||
|
||||
JSBool
|
||||
js_ReportErrorVA(JSContext *cx, uintN flags, const char *format, va_list ap)
|
||||
{
|
||||
@@ -376,8 +302,8 @@ js_ReportErrorVA(JSContext *cx, uintN flags, const char *format, va_list ap)
|
||||
memset(reportp, 0, sizeof (struct JSErrorReport));
|
||||
report.flags = flags;
|
||||
if (fp) {
|
||||
report.filename = fp->script->filename;
|
||||
report.lineno = js_PCToLineNumber(fp->script, fp->pc);
|
||||
report.filename = fp->script->filename;
|
||||
report.lineno = js_PCToLineNumber(fp->script, fp->pc);
|
||||
/* XXX should fetch line somehow */
|
||||
}
|
||||
last = JS_vsmprintf(format, ap);
|
||||
@@ -437,122 +363,99 @@ js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
|
||||
* null it out to act as the caboose when we free the
|
||||
* pointers later.
|
||||
*/
|
||||
reportp->messageArgs = (const jschar **)
|
||||
reportp->messageArgs = (const jschar **)
|
||||
JS_malloc(cx, sizeof(jschar *) * (argCount + 1));
|
||||
if (!reportp->messageArgs)
|
||||
return JS_FALSE;
|
||||
if (!reportp->messageArgs)
|
||||
return JS_FALSE;
|
||||
reportp->messageArgs[argCount] = NULL;
|
||||
for (i = 0; i < argCount; i++) {
|
||||
if (charArgs) {
|
||||
char *charArg = va_arg(ap, char *);
|
||||
reportp->messageArgs[i]
|
||||
reportp->messageArgs[i]
|
||||
= js_InflateString(cx, charArg, strlen(charArg));
|
||||
if (!reportp->messageArgs[i])
|
||||
goto error;
|
||||
}
|
||||
else
|
||||
reportp->messageArgs[i] = va_arg(ap, jschar *);
|
||||
reportp->messageArgs[i] = va_arg(ap, jschar *);
|
||||
argLengths[i] = js_strlen(reportp->messageArgs[i]);
|
||||
totalArgsLength += argLengths[i];
|
||||
}
|
||||
/* NULL-terminate for easy copying. */
|
||||
reportp->messageArgs[i] = NULL;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Parse the error format, substituting the argument X
|
||||
* for {X} in the format.
|
||||
*/
|
||||
if (argCount > 0) {
|
||||
if (fmtData->format) {
|
||||
const char *fmt;
|
||||
if (argCount > 0) {
|
||||
if (fmtData->format) {
|
||||
const char *fmt;
|
||||
const jschar *arg;
|
||||
jschar *out;
|
||||
int expandedArgs = 0;
|
||||
size_t expandedLength
|
||||
= strlen(fmtData->format)
|
||||
- (3 * argCount) /* exclude the {n} */
|
||||
+ totalArgsLength;
|
||||
jschar *out;
|
||||
int expandedArgs = 0;
|
||||
size_t expandedLength
|
||||
= strlen(fmtData->format)
|
||||
- (3 * argCount) /* exclude the {n} */
|
||||
+ totalArgsLength;
|
||||
/*
|
||||
* Note - the above calculation assumes that each argument
|
||||
* is used once and only once in the expansion !!!
|
||||
*/
|
||||
reportp->ucmessage = out = (jschar *)
|
||||
reportp->ucmessage = out = (jschar *)
|
||||
JS_malloc(cx, (expandedLength + 1) * sizeof(jschar));
|
||||
if (!out)
|
||||
goto error;
|
||||
fmt = fmtData->format;
|
||||
while (*fmt) {
|
||||
if (*fmt == '{') { /* balance} */
|
||||
if (isdigit(fmt[1])) {
|
||||
int d = JS7_UNDEC(fmt[1]);
|
||||
JS_ASSERT(expandedArgs < argCount);
|
||||
arg = reportp->messageArgs[d];
|
||||
js_strncpy(out, arg, argLengths[d]);
|
||||
out += argLengths[d];
|
||||
fmt += 3;
|
||||
expandedArgs++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!out) {
|
||||
if (reportp->messageArgs) {
|
||||
JS_free(cx, (void *)reportp->messageArgs);
|
||||
reportp->messageArgs = NULL;
|
||||
}
|
||||
return JS_FALSE;
|
||||
}
|
||||
fmt = fmtData->format;
|
||||
while (*fmt) {
|
||||
if (*fmt == '{') { /* balance} */
|
||||
if (isdigit(fmt[1])) {
|
||||
int d = JS7_UNDEC(fmt[1]);
|
||||
JS_ASSERT(expandedArgs < argCount);
|
||||
arg = reportp->messageArgs[d];
|
||||
js_strncpy(out, arg, argLengths[d]);
|
||||
out += argLengths[d];
|
||||
fmt += 3;
|
||||
expandedArgs++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* is this kosher?
|
||||
*/
|
||||
*out++ = (unsigned char)(*fmt++);
|
||||
}
|
||||
JS_ASSERT(expandedArgs == argCount);
|
||||
*out = 0;
|
||||
*out++ = (unsigned char)(*fmt++);
|
||||
}
|
||||
JS_ASSERT(expandedArgs == argCount);
|
||||
*out = 0;
|
||||
*messagep =
|
||||
js_DeflateString(cx, reportp->ucmessage,
|
||||
(size_t)(out - reportp->ucmessage));
|
||||
if (!*messagep)
|
||||
goto error;
|
||||
js_DeflateString(cx, reportp->ucmessage,
|
||||
(size_t)(out - reportp->ucmessage));
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Zero arguments: the format string (if it exists) is the
|
||||
* entire message.
|
||||
*/
|
||||
/*
|
||||
* Zero arguments: the format string (if it exists) is the
|
||||
* entire message.
|
||||
*/
|
||||
if (fmtData->format) {
|
||||
*messagep = JS_strdup(cx, fmtData->format);
|
||||
if (!*messagep)
|
||||
goto error;
|
||||
*messagep = JS_strdup(cx, fmtData->format);
|
||||
reportp->ucmessage
|
||||
= js_InflateString(cx, *messagep, strlen(*messagep));
|
||||
if (!reportp->ucmessage)
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (*messagep == NULL) {
|
||||
/* where's the right place for this ??? */
|
||||
const char *defaultErrorMessage
|
||||
= "No error message available for error number %d";
|
||||
size_t nbytes = strlen(defaultErrorMessage) + 16;
|
||||
*messagep = (char *)JS_malloc(cx, nbytes);
|
||||
if (!*messagep)
|
||||
goto error;
|
||||
JS_snprintf(*messagep, nbytes, defaultErrorMessage, errorNumber);
|
||||
/* where's the right place for this ??? */
|
||||
const char *defaultErrorMessage
|
||||
= "No error message available for error number %d";
|
||||
size_t nbytes = strlen(defaultErrorMessage) + 16;
|
||||
*messagep = (char *)JS_malloc(cx, nbytes);
|
||||
JS_snprintf(*messagep, nbytes, defaultErrorMessage, errorNumber);
|
||||
}
|
||||
return JS_TRUE;
|
||||
|
||||
error:
|
||||
if (reportp->messageArgs) {
|
||||
i = 0;
|
||||
while (reportp->messageArgs[i])
|
||||
JS_free(cx, (void *)reportp->messageArgs[i++]);
|
||||
JS_free(cx, (void *)reportp->messageArgs);
|
||||
reportp->messageArgs = NULL;
|
||||
}
|
||||
if (reportp->ucmessage) {
|
||||
JS_free(cx, (void *)reportp->ucmessage);
|
||||
reportp->ucmessage = NULL;
|
||||
}
|
||||
if (*messagep) {
|
||||
JS_free(cx, (void *)*messagep);
|
||||
*messagep = NULL;
|
||||
}
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
JSBool
|
||||
@@ -629,28 +532,29 @@ js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *reportp)
|
||||
JSErrorReporter onError;
|
||||
|
||||
if (!message)
|
||||
return;
|
||||
return;
|
||||
|
||||
if (cx->lastMessage)
|
||||
free(cx->lastMessage);
|
||||
free(cx->lastMessage);
|
||||
cx->lastMessage = JS_strdup(cx, message);
|
||||
if (!cx->lastMessage)
|
||||
return;
|
||||
return;
|
||||
onError = cx->errorReporter;
|
||||
|
||||
/*
|
||||
* If debugErrorHook is present then we give it a chance to veto
|
||||
* sending the error on to the regular ErrorReporter.
|
||||
*/
|
||||
if (onError) {
|
||||
if (cx->runtime->debugErrorHook && onError) {
|
||||
JSDebugErrorHook hook = cx->runtime->debugErrorHook;
|
||||
if (hook &&
|
||||
!hook(cx, cx->lastMessage, reportp, cx->runtime->debugErrorHookData)) {
|
||||
/* test local in case debugErrorHook changed on another thread */
|
||||
if (hook && !hook(cx, message, reportp,
|
||||
cx->runtime->debugErrorHookData)) {
|
||||
onError = NULL;
|
||||
}
|
||||
}
|
||||
if (onError)
|
||||
(*onError)(cx, cx->lastMessage, reportp);
|
||||
(*onError)(cx, cx->lastMessage, reportp);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* 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
|
||||
@@ -42,7 +42,6 @@
|
||||
#include "jslong.h"
|
||||
#include "jsatom.h"
|
||||
#include "jsconfig.h"
|
||||
#include "jsdhash.h"
|
||||
#include "jsgc.h"
|
||||
#include "jsinterp.h"
|
||||
#include "jsobj.h"
|
||||
@@ -66,17 +65,17 @@ struct JSRuntime {
|
||||
|
||||
/* Garbage collector state, used by jsgc.c. */
|
||||
JSArenaPool gcArenaPool;
|
||||
JSArenaPool gcFlagsPool;
|
||||
JSHashTable *gcRootsHash;
|
||||
JSHashTable *gcLocksHash;
|
||||
JSGCThing *gcFreeList;
|
||||
jsrefcount gcDisabled;
|
||||
jsword gcDisabled;
|
||||
uint32 gcBytes;
|
||||
uint32 gcLastBytes;
|
||||
uint32 gcMaxBytes;
|
||||
uint32 gcLevel;
|
||||
uint32 gcNumber;
|
||||
JSPackedBool gcPoke;
|
||||
JSPackedBool gcRunning;
|
||||
JSBool gcPoke;
|
||||
JSGCCallback gcCallback;
|
||||
uint32 gcMallocBytes;
|
||||
#ifdef JS_GCMETER
|
||||
@@ -157,65 +156,11 @@ struct JSRuntime {
|
||||
|
||||
/* Used to serialize cycle checks when setting __proto__ or __parent__. */
|
||||
PRLock *setSlotLock;
|
||||
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
|
||||
|
||||
#ifdef DEBUG
|
||||
/* Function invocation metering. */
|
||||
jsrefcount inlineCalls;
|
||||
jsrefcount nativeCalls;
|
||||
jsrefcount nonInlineCalls;
|
||||
jsrefcount constructs;
|
||||
|
||||
/* Scope lock metering. */
|
||||
jsrefcount claimAttempts;
|
||||
jsrefcount claimedScopes;
|
||||
jsrefcount deadContexts;
|
||||
jsrefcount deadlocksAvoided;
|
||||
jsrefcount liveScopes;
|
||||
jsrefcount sharedScopes;
|
||||
jsrefcount totalScopes;
|
||||
|
||||
/* String instrumentation. */
|
||||
jsrefcount liveStrings;
|
||||
jsrefcount totalStrings;
|
||||
double lengthSum;
|
||||
double lengthSquaredSum;
|
||||
#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_ENABLE_GC(rt) JS_ATOMIC_DECREMENT(&(rt)->gcDisabled);
|
||||
#define JS_DISABLE_GC(rt) JS_ATOMIC_INCREMENT(&(rt)->gcDisabled);
|
||||
#define JS_ENABLE_GC(rt) JS_ATOMIC_ADDREF(&(rt)->gcDisabled, -1);
|
||||
#define JS_DISABLE_GC(rt) JS_ATOMIC_ADDREF(&(rt)->gcDisabled, 1);
|
||||
|
||||
#ifdef JS_ARGUMENT_FORMATTER_DEFINED
|
||||
/*
|
||||
@@ -231,13 +176,6 @@ struct JSArgumentFormatMap {
|
||||
};
|
||||
#endif
|
||||
|
||||
struct JSStackHeader {
|
||||
uintN nslots;
|
||||
JSStackHeader *down;
|
||||
};
|
||||
|
||||
#define JS_STACK_SEGMENT(sh) ((jsval *)(sh) + 2)
|
||||
|
||||
struct JSContext {
|
||||
JSCList links;
|
||||
|
||||
@@ -294,21 +232,9 @@ struct JSContext {
|
||||
#ifdef JS_THREADSAFE
|
||||
jsword thread;
|
||||
jsrefcount requestDepth;
|
||||
JSScope *scopeToShare; /* weak reference, see jslock.c */
|
||||
#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
|
||||
|
||||
/* Exception state (NB: throwing packs with rval2set, above). */
|
||||
/* Exception state. */
|
||||
JSPackedBool throwing; /* is there a pending exception? */
|
||||
jsval exception; /* most-recently-thrown exceptin */
|
||||
|
||||
@@ -321,11 +247,6 @@ struct JSContext {
|
||||
/* Locale specific callbacks for string conversion. */
|
||||
JSLocaleCallbacks *localeCallbacks;
|
||||
|
||||
/* Non-null if init'ing standard classes lazily, to stop recursion. */
|
||||
JSDHashTable *resolving;
|
||||
|
||||
/* PDL of stack headers describing stack slots not rooted by argv, etc. */
|
||||
JSStackHeader *stackHeaders;
|
||||
};
|
||||
|
||||
/* Slightly more readable macros, also to hide bitset implementation detail. */
|
||||
@@ -338,9 +259,6 @@ js_NewContext(JSRuntime *rt, size_t stackChunkSize);
|
||||
extern void
|
||||
js_DestroyContext(JSContext *cx, JSGCMode gcmode);
|
||||
|
||||
extern JSBool
|
||||
js_LiveContext(JSRuntime *rt, JSContext *cx);
|
||||
|
||||
extern JSContext *
|
||||
js_ContextIterator(JSRuntime *rt, JSContext **iterp);
|
||||
|
||||
@@ -375,9 +293,6 @@ js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
|
||||
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
|
||||
|
||||
@@ -94,7 +94,6 @@
|
||||
#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 */
|
||||
|
||||
#elif JS_VERSION == 110
|
||||
|
||||
@@ -151,7 +150,6 @@
|
||||
#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 */
|
||||
|
||||
#elif JS_VERSION == 120
|
||||
|
||||
@@ -208,7 +206,6 @@
|
||||
#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 */
|
||||
|
||||
#elif JS_VERSION == 130
|
||||
|
||||
@@ -265,7 +262,6 @@
|
||||
#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 */
|
||||
|
||||
#elif JS_VERSION == 140
|
||||
|
||||
@@ -322,7 +318,6 @@
|
||||
#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 */
|
||||
|
||||
#elif JS_VERSION == 150
|
||||
|
||||
@@ -336,7 +331,7 @@
|
||||
#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_BUG_WITH_CLOSURE 1 /* with(o)function f(){} sets o.f */
|
||||
#define JS_BUG_SET_ENUMERATE 0 /* o.p=q flags o.p JSPROP_ENUMERATE */
|
||||
|
||||
#define JS_HAS_PROP_DELETE 1 /* delete o.p removes p from o */
|
||||
@@ -379,7 +374,6 @@
|
||||
#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 */
|
||||
|
||||
#else
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user